diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..f813867
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,373 @@
+root = true
+
+[*.cs]
+
+#### Core EditorConfig Options ####
+
+# Indentation and spacing
+indent_size = 4
+indent_style = space
+tab_width = 4
+
+# New line preferences
+end_of_line = crlf
+insert_final_newline = true
+
+#### .NET Coding Conventions ####
+
+# Organize usings
+dotnet_separate_import_directive_groups = false
+dotnet_sort_system_directives_first = false
+
+dotnet_style_qualification_for_event = false:suggestion
+dotnet_style_qualification_for_field = false
+dotnet_style_qualification_for_method = false:suggestion
+dotnet_style_qualification_for_property = false:suggestion
+
+# Language keywords vs BCL types preferences
+dotnet_style_predefined_type_for_locals_parameters_members = true:warning
+dotnet_style_predefined_type_for_member_access = true:warning
+
+# Parentheses preferences
+dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
+dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
+dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
+dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
+
+# Modifier preferences
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
+
+# Expression-level preferences
+dotnet_style_namespace_match_folder = true
+
+# Field preferences
+dotnet_style_readonly_field = true
+
+# Parameter preferences
+dotnet_code_quality_unused_parameters = all
+
+# Suppression preferences
+dotnet_remove_unnecessary_suppression_exclusions = 0
+
+# New line preferences
+dotnet_style_allow_multiple_blank_lines_experimental = true
+dotnet_style_allow_statement_immediately_after_block_experimental = true
+
+#### C# Coding Conventions ####
+
+# var preferences
+csharp_style_var_elsewhere = true:warning
+csharp_style_var_for_built_in_types = true:warning
+csharp_style_var_when_type_is_apparent = true:warning
+
+# Expression-bodied members
+csharp_style_expression_bodied_constructors = false:silent
+
+# Pattern matching preferences
+csharp_style_pattern_matching_over_as_with_null_check = true
+csharp_style_pattern_matching_over_is_with_cast_check = true
+csharp_style_prefer_extended_property_pattern = true
+csharp_style_prefer_not_pattern = true
+csharp_style_prefer_pattern_matching = true:suggestion
+csharp_style_prefer_switch_expression = true
+
+# Null-checking preferences
+csharp_style_conditional_delegate_call = true
+
+# Modifier preferences
+csharp_prefer_static_local_function = true
+csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async
+
+# Code-block preferences
+csharp_prefer_braces = true:warning
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_style_namespace_declarations = file_scoped:suggestion
+
+# Expression-level preferences
+csharp_prefer_simple_default_expression = true:suggestion
+csharp_style_deconstructed_variable_declaration = true
+csharp_style_implicit_object_creation_when_type_is_apparent = true
+csharp_style_inlined_variable_declaration = true:suggestion
+csharp_style_prefer_index_operator = true
+csharp_style_prefer_local_over_anonymous_function = true:suggestion
+csharp_style_prefer_null_check_over_type_check = true:suggestion
+csharp_style_prefer_range_operator = true
+csharp_style_prefer_tuple_swap = true
+csharp_style_throw_expression = true:suggestion
+csharp_style_unused_value_assignment_preference = discard_variable
+csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
+
+# 'using' directive preferences
+csharp_using_directive_placement = inside_namespace:silent
+
+# New line preferences
+csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
+csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
+csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
+
+#### C# Formatting Rules ####
+
+# New line preferences
+csharp_new_line_before_catch = true
+csharp_new_line_before_else = true
+csharp_new_line_before_finally = true
+csharp_new_line_before_members_in_anonymous_types = true
+csharp_new_line_before_members_in_object_initializers = true
+csharp_new_line_before_open_brace = all
+csharp_new_line_between_query_expression_clauses = true
+
+# Indentation preferences
+csharp_indent_block_contents = true
+csharp_indent_braces = false
+csharp_indent_case_contents = true
+csharp_indent_case_contents_when_block = true
+csharp_indent_labels = one_less_than_current
+csharp_indent_switch_labels = true
+
+# Space preferences
+csharp_space_after_cast = false
+csharp_space_after_colon_in_inheritance_clause = true
+csharp_space_after_comma = true
+csharp_space_after_dot = false
+csharp_space_after_keywords_in_control_flow_statements = false
+csharp_space_after_semicolon_in_for_statement = true
+csharp_space_around_binary_operators = before_and_after
+csharp_space_around_declaration_statements = false
+csharp_space_before_colon_in_inheritance_clause = true
+csharp_space_before_comma = false
+csharp_space_before_dot = false
+csharp_space_before_open_square_brackets = false
+csharp_space_before_semicolon_in_for_statement = false
+csharp_space_between_empty_square_brackets = false
+csharp_space_between_method_call_empty_parameter_list_parentheses = false
+csharp_space_between_method_call_name_and_opening_parenthesis = false
+csharp_space_between_method_call_parameter_list_parentheses = false
+csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
+csharp_space_between_method_declaration_name_and_open_parenthesis = false
+csharp_space_between_method_declaration_parameter_list_parentheses = false
+csharp_space_between_parentheses = false
+csharp_space_between_square_brackets = false
+
+# Wrapping preferences
+csharp_preserve_single_line_blocks = true
+csharp_preserve_single_line_statements = true
+
+#### Naming styles ####
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+# ReSharper properties
+resharper_align_first_arg_by_paren = true
+resharper_align_linq_query = true
+resharper_align_multiline_argument = true
+resharper_align_multiline_array_and_object_initializer = true
+resharper_align_multiline_binary_patterns = true
+resharper_align_multiline_calls_chain = true
+resharper_align_multiline_expression = true
+resharper_align_multiline_extends_list = true
+resharper_align_multiline_property_pattern = true
+resharper_align_multiline_switch_expression = true
+resharper_align_multline_type_parameter_constrains = true
+resharper_align_multline_type_parameter_list = true
+resharper_align_tuple_components = true
+resharper_apply_on_completion = true
+resharper_arguments_named = unset
+resharper_can_use_global_alias = false
+resharper_csharp_align_multiline_parameter = true
+resharper_csharp_align_multiple_declaration = true
+resharper_csharp_empty_block_style = together
+resharper_csharp_stick_comment = false
+resharper_indent_anonymous_method_block = true
+resharper_indent_preprocessor_if = usual_indent
+resharper_int_align = true
+resharper_keep_existing_enum_arrangement = false
+resharper_outdent_commas = true
+resharper_place_accessorholder_attribute_on_same_line = false
+resharper_place_accessor_attribute_on_same_line = false
+resharper_use_roslyn_logic_for_evident_types = true
+
+# ReSharper inspection severities
+resharper_arguments_style_named_expression_highlighting = error
+
+[*.{appxmanifest,axml,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,proto,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}]
+indent_style = space
+indent_size = 4
+tab_width = 4
+
+[*.{asax,ascx,aspx,axaml,cs,cshtml,css,htm,html,js,jsx,master,paml,razor,skin,ts,tsx,vb,xaml,xamlx,xoml}]
+indent_style = space
+indent_size = 4
+tab_width = 4
+
+[*.{json,resjson}]
+indent_style = space
+indent_size = 4
+tab_width = 4
+
+[*]
+
+# ReSharper properties
+resharper_arguments_anonymous_function = unset
+resharper_arguments_literal = unset
+resharper_arguments_other = unset
+resharper_arguments_string_literal = unset
+resharper_blank_lines_after_control_transfer_statements = 1
+resharper_blank_lines_after_multiline_statements = 1
+resharper_blank_lines_around_single_line_auto_property = 1
+resharper_blank_lines_around_single_line_property = 1
+resharper_blank_lines_before_block_statements = 1
+resharper_blank_lines_before_control_transfer_statements = 1
+resharper_blank_lines_before_multiline_statements = 1
+resharper_csharp_align_multiline_argument = false
+resharper_csharp_allow_far_alignment = true
+resharper_csharp_blank_lines_around_field = 0
+resharper_csharp_keep_blank_lines_in_code = 1
+resharper_csharp_keep_blank_lines_in_declarations = 1
+resharper_csharp_max_line_length = 400
+resharper_csharp_use_indent_from_vs = false
+resharper_csharp_wrap_arguments_style = chop_if_long
+resharper_csharp_wrap_chained_method_calls = chop_if_long
+resharper_csharp_wrap_extends_list_style = chop_if_long
+resharper_csharp_wrap_lines = true
+resharper_csharp_wrap_parameters_style = chop_always
+resharper_csharp_wrap_ternary_expr_style = chop_always
+resharper_indent_nested_fixed_stmt = true
+resharper_indent_nested_foreach_stmt = true
+resharper_indent_nested_for_stmt = true
+resharper_indent_nested_lock_stmt = true
+resharper_indent_nested_usings_stmt = true
+resharper_indent_nested_while_stmt = true
+resharper_indent_preprocessor_other = usual_indent
+resharper_int_align_assignments = false
+resharper_int_align_binary_expressions = false
+resharper_int_align_fields = false
+resharper_int_align_invocations = false
+resharper_int_align_methods = false
+resharper_int_align_nested_ternary = false
+resharper_int_align_parameters = false
+resharper_int_align_properties = false
+resharper_int_align_variables = false
+resharper_keep_existing_attribute_arrangement = true
+resharper_keep_existing_declaration_block_arrangement = false
+resharper_keep_existing_declaration_parens_arrangement = false
+resharper_keep_existing_embedded_arrangement = false
+resharper_keep_existing_embedded_block_arrangement = false
+resharper_keep_existing_expr_member_arrangement = false
+resharper_keep_existing_invocation_parens_arrangement = false
+resharper_max_array_initializer_elements_on_line = 1
+resharper_max_enum_members_on_line = 1
+resharper_max_formal_parameters_on_line = 2
+resharper_max_invocation_arguments_on_line = 10
+resharper_place_attribute_on_same_line = false
+resharper_place_constructor_initializer_on_same_line = false
+resharper_place_simple_accessor_on_single_line = false
+resharper_place_simple_switch_expression_on_single_line = true
+resharper_qualified_using_at_nested_scope = true
+resharper_use_continuous_indent_inside_parens = true
+resharper_wrap_array_initializer_style = chop_always
+resharper_wrap_before_first_type_parameter_constraint = true
+resharper_wrap_multiple_type_parameter_constraints_style = chop_always
+resharper_wrap_switch_expression = chop_if_long
+
+# ReSharper inspection severities
+resharper_arguments_style_anonymous_function_highlighting = warning
+resharper_arguments_style_literal_highlighting = warning
+resharper_arguments_style_named_expression_highlighting = warning
+resharper_arguments_style_other_highlighting = warning
+resharper_arguments_style_string_literal_highlighting = warning
+resharper_arrange_attributes_highlighting = warning
+resharper_arrange_modifiers_order_highlighting = hint
+resharper_arrange_object_creation_when_type_not_evident_highlighting = suggestion
+resharper_arrange_redundant_parentheses_highlighting = warning
+resharper_arrange_this_qualifier_highlighting = hint
+resharper_arrange_type_member_modifiers_highlighting = error
+resharper_arrange_type_modifiers_highlighting = error
+resharper_arrange_var_keywords_in_deconstructing_declaration_highlighting = warning
+resharper_built_in_type_reference_style_for_member_access_highlighting = hint
+resharper_built_in_type_reference_style_highlighting = hint
+resharper_redundant_base_qualifier_highlighting = warning
+resharper_suggest_var_or_type_built_in_types_highlighting = warning
+resharper_suggest_var_or_type_elsewhere_highlighting = warning
+resharper_suggest_var_or_type_simple_types_highlighting = warning
+resharper_use_await_using_highlighting = none
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+end_of_line = crlf
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_auto_properties = true:suggestion
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:silent
+dotnet_style_prefer_conditional_expression_over_return = true:silent
+dotnet_style_explicit_tuple_names = true:warning
+dotnet_style_prefer_inferred_tuple_names = false:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_namespace_match_folder = true:suggestion
+csharp_style_prefer_method_group_conversion = true:silent
+csharp_style_expression_bodied_methods = false:none
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_lambdas = true:suggestion
+csharp_style_expression_bodied_local_functions = true:suggestion
+dotnet_style_allow_multiple_blank_lines_experimental = true:warning
+dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
+resharper_method_supports_cancellation_highlighting = hint
+
+[*.{cs,vb,cshtml,vbhtml}]
+# For variables
+dotnet_naming_symbols.local_symbol.applicable_kinds = local
+dotnet_naming_style.local_style.capitalization = camel_case
+dotnet_naming_rule.variables_are_camel_case.severity = suggestion
+dotnet_naming_rule.variables_are_camel_case.symbols = local_symbol
+dotnet_naming_rule.variables_are_camel_case.style = local_style
+
+# for parameters
+dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
+dotnet_naming_style.parameter_style.capitalization = camel_case
+dotnet_naming_rule.parameters_are_camel_case.severity = suggestion
+dotnet_naming_rule.parameters_are_camel_case.symbols = parameter_symbol
+dotnet_naming_rule.parameters_are_camel_case.style = parameter_style
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
index 08a1f71..ff652c5 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,8 @@
- net8.0
+ net9.0
disable
enable
+ true
-
\ No newline at end of file
+
diff --git a/Directory.Packages.props b/Directory.Packages.props
new file mode 100644
index 0000000..a9a15e5
--- /dev/null
+++ b/Directory.Packages.props
@@ -0,0 +1,40 @@
+
+
+ true
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
\ No newline at end of file
diff --git a/EngineKit.sln b/EngineKit.sln
index cf5f7db..fc999a3 100644
--- a/EngineKit.sln
+++ b/EngineKit.sln
@@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_items", "_items", "{7641AC
.github\workflows\cd.yml = .github\workflows\cd.yml
Directory.Build.props = Directory.Build.props
EngineKit.sln.DotSettings = EngineKit.sln.DotSettings
+ .editorconfig = .editorconfig
+ Directory.Packages.props = Directory.Packages.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EngineKit", "src\EngineKit\EngineKit.csproj", "{8E305337-228C-4930-B355-91F1E82C64C8}"
@@ -49,6 +51,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Complex.Assets", "examples\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Complex", "examples\Complex\Complex\Complex.csproj", "{2BDAC710-9074-441E-8AF3-4D50B2C37EE7}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Complex.Engine", "examples\Complex\Complex.Engine\Complex.Engine.csproj", "{08D90EF4-115E-4969-8149-DEB681FEEF5D}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Complex.Game", "examples\Complex\Complex.Game\Complex.Game.csproj", "{C4B24C11-BE84-4AFD-9335-129CF467808B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Complex.Game.Assets", "examples\Complex\Complex.Game.Assets\Complex.Game.Assets.csproj", "{DD5FA21A-C190-4F31-9F05-F081862F3465}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -72,6 +80,9 @@ Global
{7E9EF27C-3748-4782-959F-3AEBF26416F2} = {1E1BD9CA-189A-45FD-8A36-A57C836C6BB6}
{3D623AB0-0EB7-4DD9-9C27-04819106A57F} = {7E9EF27C-3748-4782-959F-3AEBF26416F2}
{2BDAC710-9074-441E-8AF3-4D50B2C37EE7} = {7E9EF27C-3748-4782-959F-3AEBF26416F2}
+ {08D90EF4-115E-4969-8149-DEB681FEEF5D} = {7E9EF27C-3748-4782-959F-3AEBF26416F2}
+ {C4B24C11-BE84-4AFD-9335-129CF467808B} = {7E9EF27C-3748-4782-959F-3AEBF26416F2}
+ {DD5FA21A-C190-4F31-9F05-F081862F3465} = {7E9EF27C-3748-4782-959F-3AEBF26416F2}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8E305337-228C-4930-B355-91F1E82C64C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -118,5 +129,17 @@ Global
{2BDAC710-9074-441E-8AF3-4D50B2C37EE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BDAC710-9074-441E-8AF3-4D50B2C37EE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BDAC710-9074-441E-8AF3-4D50B2C37EE7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08D90EF4-115E-4969-8149-DEB681FEEF5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08D90EF4-115E-4969-8149-DEB681FEEF5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08D90EF4-115E-4969-8149-DEB681FEEF5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08D90EF4-115E-4969-8149-DEB681FEEF5D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C4B24C11-BE84-4AFD-9335-129CF467808B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C4B24C11-BE84-4AFD-9335-129CF467808B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C4B24C11-BE84-4AFD-9335-129CF467808B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C4B24C11-BE84-4AFD-9335-129CF467808B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DD5FA21A-C190-4F31-9F05-F081862F3465}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DD5FA21A-C190-4F31-9F05-F081862F3465}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DD5FA21A-C190-4F31-9F05-F081862F3465}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DD5FA21A-C190-4F31-9F05-F081862F3465}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/EngineKit.sln.DotSettings b/EngineKit.sln.DotSettings
index fa718bb..252f750 100644
--- a/EngineKit.sln.DotSettings
+++ b/EngineKit.sln.DotSettings
@@ -1,6 +1,19 @@
+ False
+ True
+ True
+ 1
+ 10000
+ False
+ False
+ 140
+ CHOP_IF_LONG
GL
UI
+ True
+ True
+ True
+ True
True
8
diff --git a/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.bin b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.bin
new file mode 100644
index 0000000..8ea3435
Binary files /dev/null and b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.bin differ
diff --git a/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.glb b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.glb
new file mode 100644
index 0000000..494c0ea
Binary files /dev/null and b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.glb differ
diff --git a/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.gltf b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.gltf
new file mode 100644
index 0000000..4eb7209
--- /dev/null
+++ b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10.gltf
@@ -0,0 +1,117 @@
+{
+ "asset":{
+ "generator":"Khronos glTF Blender I/O v4.1.63",
+ "version":"2.0"
+ },
+ "scene":0,
+ "scenes":[
+ {
+ "name":"Scene",
+ "nodes":[
+ 0
+ ]
+ }
+ ],
+ "nodes":[
+ {
+ "mesh":0,
+ "name":"Cube"
+ }
+ ],
+ "meshes":[
+ {
+ "name":"Cube",
+ "primitives":[
+ {
+ "attributes":{
+ "POSITION":0,
+ "NORMAL":1,
+ "TEXCOORD_0":2,
+ "TANGENT":3
+ },
+ "indices":4
+ }
+ ]
+ }
+ ],
+ "accessors":[
+ {
+ "bufferView":0,
+ "componentType":5126,
+ "count":24,
+ "max":[
+ 1,
+ 1,
+ 1
+ ],
+ "min":[
+ -1,
+ -1,
+ -1
+ ],
+ "type":"VEC3"
+ },
+ {
+ "bufferView":1,
+ "componentType":5126,
+ "count":24,
+ "type":"VEC3"
+ },
+ {
+ "bufferView":2,
+ "componentType":5126,
+ "count":24,
+ "type":"VEC2"
+ },
+ {
+ "bufferView":3,
+ "componentType":5126,
+ "count":24,
+ "type":"VEC4"
+ },
+ {
+ "bufferView":4,
+ "componentType":5123,
+ "count":36,
+ "type":"SCALAR"
+ }
+ ],
+ "bufferViews":[
+ {
+ "buffer":0,
+ "byteLength":288,
+ "byteOffset":0,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":288,
+ "byteOffset":288,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":192,
+ "byteOffset":576,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":384,
+ "byteOffset":768,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":72,
+ "byteOffset":1152,
+ "target":34963
+ }
+ ],
+ "buffers":[
+ {
+ "byteLength":1224,
+ "uri":"SM_Cubes_10by10by10.bin"
+ }
+ ]
+}
diff --git a/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.bin b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.bin
new file mode 100644
index 0000000..80d7ff3
Binary files /dev/null and b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.bin differ
diff --git a/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.gltf b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.gltf
new file mode 100644
index 0000000..dbfd2be
--- /dev/null
+++ b/examples/Complex/Complex.Assets/Data/Props/SM_Cubes_10by10by10_i.gltf
@@ -0,0 +1,117 @@
+{
+ "asset":{
+ "generator":"Khronos glTF Blender I/O v4.1.63",
+ "version":"2.0"
+ },
+ "scene":0,
+ "scenes":[
+ {
+ "name":"Scene",
+ "nodes":[
+ 0
+ ]
+ }
+ ],
+ "nodes":[
+ {
+ "mesh":0,
+ "name":"Cube.001"
+ }
+ ],
+ "meshes":[
+ {
+ "name":"Cube",
+ "primitives":[
+ {
+ "attributes":{
+ "POSITION":0,
+ "NORMAL":1,
+ "TEXCOORD_0":2,
+ "TANGENT":3
+ },
+ "indices":4
+ }
+ ]
+ }
+ ],
+ "accessors":[
+ {
+ "bufferView":0,
+ "componentType":5126,
+ "count":24000,
+ "max":[
+ 73,
+ 73,
+ 1
+ ],
+ "min":[
+ -1,
+ -1,
+ -73
+ ],
+ "type":"VEC3"
+ },
+ {
+ "bufferView":1,
+ "componentType":5126,
+ "count":24000,
+ "type":"VEC3"
+ },
+ {
+ "bufferView":2,
+ "componentType":5126,
+ "count":24000,
+ "type":"VEC2"
+ },
+ {
+ "bufferView":3,
+ "componentType":5126,
+ "count":24000,
+ "type":"VEC4"
+ },
+ {
+ "bufferView":4,
+ "componentType":5123,
+ "count":36000,
+ "type":"SCALAR"
+ }
+ ],
+ "bufferViews":[
+ {
+ "buffer":0,
+ "byteLength":288000,
+ "byteOffset":0,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":288000,
+ "byteOffset":288000,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":192000,
+ "byteOffset":576000,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":384000,
+ "byteOffset":768000,
+ "target":34962
+ },
+ {
+ "buffer":0,
+ "byteLength":72000,
+ "byteOffset":1152000,
+ "target":34963
+ }
+ ],
+ "buffers":[
+ {
+ "byteLength":1224000,
+ "uri":"SM_Cubes_10by10by10_i.bin"
+ }
+ ]
+}
diff --git a/examples/Complex/Complex.Assets/Data/Props/SimpleInstancing.glb b/examples/Complex/Complex.Assets/Data/Props/SimpleInstancing.glb
new file mode 100644
index 0000000..0b717bd
Binary files /dev/null and b/examples/Complex/Complex.Assets/Data/Props/SimpleInstancing.glb differ
diff --git a/examples/Complex/Complex.Engine/Complex.Engine.csproj b/examples/Complex/Complex.Engine/Complex.Engine.csproj
new file mode 100644
index 0000000..b0940f3
--- /dev/null
+++ b/examples/Complex/Complex.Engine/Complex.Engine.csproj
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/Complex/Complex/Ecs/Components/ColliderComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/ColliderComponent.cs
similarity index 73%
rename from examples/Complex/Complex/Ecs/Components/ColliderComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/ColliderComponent.cs
index 84c22b0..865074c 100644
--- a/examples/Complex/Complex/Ecs/Components/ColliderComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/ColliderComponent.cs
@@ -1,6 +1,6 @@
using BepuPhysics.Collidables;
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class ColliderComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/Component.cs b/examples/Complex/Complex.Engine/Ecs/Components/Component.cs
similarity index 94%
rename from examples/Complex/Complex/Ecs/Components/Component.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/Component.cs
index 7fcb293..29544d3 100644
--- a/examples/Complex/Complex/Ecs/Components/Component.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/Component.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public abstract class Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/GlobalLightComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/GlobalLightComponent.cs
similarity index 55%
rename from examples/Complex/Complex/Ecs/Components/GlobalLightComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/GlobalLightComponent.cs
index 348872b..f71fb91 100644
--- a/examples/Complex/Complex/Ecs/Components/GlobalLightComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/GlobalLightComponent.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class GlobalLightComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/MaterialComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/MaterialComponent.cs
similarity index 85%
rename from examples/Complex/Complex/Ecs/Components/MaterialComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/MaterialComponent.cs
index 5fb42de..3dfd1d3 100644
--- a/examples/Complex/Complex/Ecs/Components/MaterialComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/MaterialComponent.cs
@@ -1,6 +1,6 @@
using EngineKit.Graphics;
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class MaterialComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/ModelComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/ModelComponent.cs
similarity index 79%
rename from examples/Complex/Complex/Ecs/Components/ModelComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/ModelComponent.cs
index c5613b7..d6e1d12 100644
--- a/examples/Complex/Complex/Ecs/Components/ModelComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/ModelComponent.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class ModelComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/ModelMeshComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/ModelMeshComponent.cs
similarity index 86%
rename from examples/Complex/Complex/Ecs/Components/ModelMeshComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/ModelMeshComponent.cs
index d55f29f..80302e8 100644
--- a/examples/Complex/Complex/Ecs/Components/ModelMeshComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/ModelMeshComponent.cs
@@ -1,6 +1,6 @@
using EngineKit.Graphics;
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class ModelMeshComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/NameComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/NameComponent.cs
similarity index 78%
rename from examples/Complex/Complex/Ecs/Components/NameComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/NameComponent.cs
index a7fc69f..be5cea2 100644
--- a/examples/Complex/Complex/Ecs/Components/NameComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/NameComponent.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class NameComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/PhysicsBodyComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/PhysicsBodyComponent.cs
similarity index 82%
rename from examples/Complex/Complex/Ecs/Components/PhysicsBodyComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/PhysicsBodyComponent.cs
index 95ad18f..c317cab 100644
--- a/examples/Complex/Complex/Ecs/Components/PhysicsBodyComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/PhysicsBodyComponent.cs
@@ -1,6 +1,6 @@
using BepuPhysics;
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class PhysicsBodyComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/RootComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/RootComponent.cs
similarity index 51%
rename from examples/Complex/Complex/Ecs/Components/RootComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/RootComponent.cs
index 3e37e81..a736d8f 100644
--- a/examples/Complex/Complex/Ecs/Components/RootComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/RootComponent.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class RootComponent : Component
{
diff --git a/examples/Complex/Complex/Ecs/Components/TagComponent.cs b/examples/Complex/Complex.Engine/Ecs/Components/TagComponent.cs
similarity index 80%
rename from examples/Complex/Complex/Ecs/Components/TagComponent.cs
rename to examples/Complex/Complex.Engine/Ecs/Components/TagComponent.cs
index 6d53842..f0fb06d 100644
--- a/examples/Complex/Complex/Ecs/Components/TagComponent.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Components/TagComponent.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Components;
+namespace Complex.Engine.Ecs.Components;
public class TagComponent : Component where TTag : struct
{
diff --git a/examples/Complex/Complex/Ecs/Entity.cs b/examples/Complex/Complex.Engine/Ecs/Entity.cs
similarity index 91%
rename from examples/Complex/Complex/Ecs/Entity.cs
rename to examples/Complex/Complex.Engine/Ecs/Entity.cs
index 38e7565..beed4d2 100644
--- a/examples/Complex/Complex/Ecs/Entity.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Entity.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Numerics;
-using Complex.Ecs.Components;
+using Complex.Engine.Ecs.Components;
-namespace Complex.Ecs;
+namespace Complex.Engine.Ecs;
public class Entity
{
@@ -19,14 +19,13 @@ public class Entity
private Entity? _parent;
- public EntityId Id;
+ private bool _isDirty;
- public string Name;
+ public EntityId Id;
public Entity(string name,
Entity? parent)
{
- Name = name;
Components = new Dictionary();
Parent = parent;
Children = new List();
@@ -37,6 +36,7 @@ public Entity(string name,
LocalMatrix = Matrix4x4.Identity;
_globalMatrix = Matrix4x4.Identity;
+ _isDirty = true;
}
public Vector3 Position
@@ -110,7 +110,11 @@ public void RemoveChild(Entity child)
public Matrix4x4 GetGlobalMatrix()
{
- UpdateGlobalMatrix();
+ if(_isDirty)
+ {
+ UpdateGlobalMatrix();
+ _isDirty = false;
+ }
return _globalMatrix;
}
@@ -133,5 +137,7 @@ private void UpdateLocalMatrix()
_localRotation.Y,
_localRotation.Z) *
Matrix4x4.CreateTranslation(_localPosition);
+
+ _isDirty = true;
}
}
diff --git a/examples/Complex/Complex.Engine/Ecs/EntityId.cs b/examples/Complex/Complex.Engine/Ecs/EntityId.cs
new file mode 100644
index 0000000..c591f25
--- /dev/null
+++ b/examples/Complex/Complex.Engine/Ecs/EntityId.cs
@@ -0,0 +1,3 @@
+namespace Complex.Engine.Ecs;
+
+public readonly record struct EntityId(int Id);
diff --git a/examples/Complex/Complex/Ecs/EntityWorld.cs b/examples/Complex/Complex.Engine/Ecs/EntityRegistry.cs
similarity index 88%
rename from examples/Complex/Complex/Ecs/EntityWorld.cs
rename to examples/Complex/Complex.Engine/Ecs/EntityRegistry.cs
index 7c7a35a..fa795c2 100644
--- a/examples/Complex/Complex/Ecs/EntityWorld.cs
+++ b/examples/Complex/Complex.Engine/Ecs/EntityRegistry.cs
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Complex.Ecs.Components;
+using Complex.Engine.Ecs.Components;
-namespace Complex.Ecs;
+namespace Complex.Engine.Ecs;
-public class EntityWorld : IEntityWorld
+public class EntityRegistry : IEntityRegistry
{
private readonly IDictionary> _componentsByType;
@@ -13,7 +13,7 @@ public class EntityWorld : IEntityWorld
private int _nextEntityId;
- public EntityWorld()
+ public EntityRegistry()
{
_componentsByType = new Dictionary>();
_entities = new Dictionary();
@@ -63,11 +63,13 @@ public void AddComponent(EntityId entityId,
component.Entity = entity;
entity.Components.Add(componentType, component);
- if (!_componentsByType.ContainsKey(componentType))
+ if (!_componentsByType.TryGetValue(componentType, out var components))
{
- _componentsByType[componentType] = new List();
+ components = new List();
+ _componentsByType[componentType] = components;
}
- _componentsByType[componentType].Add(component);
+
+ components.Add(component);
var componentAdded = ComponentAdded;
componentAdded?.Invoke(component);
@@ -102,7 +104,10 @@ public List GetEntitiesWithComponents()
foreach (var component in components)
{
- if (component.Entity != null && !entities.Contains(component.Entity)) entities.Add(component.Entity);
+ if(component.Entity != null && !entities.Contains(component.Entity))
+ {
+ entities.Add(component.Entity);
+ }
}
return entities;
@@ -115,13 +120,11 @@ public List GetEntitiesWithComponents()
if (!_componentsByType.TryGetValue(typeof(TComponent1), out var components1))
{
return Enumerable.Empty().ToList();
- ;
}
if (!_componentsByType.TryGetValue(typeof(TComponent2), out var components2))
{
return Enumerable.Empty().ToList();
- ;
}
var entities = new List(256);
@@ -151,7 +154,7 @@ public List GetEntitiesWithComponents()
return null;
}
- public IList GetComponents() where T : Component
+ public List GetComponents() where T : Component
{
var components = new List();
diff --git a/examples/Complex/Complex/Ecs/IEntityWorld.cs b/examples/Complex/Complex.Engine/Ecs/IEntityRegistry.cs
similarity index 85%
rename from examples/Complex/Complex/Ecs/IEntityWorld.cs
rename to examples/Complex/Complex.Engine/Ecs/IEntityRegistry.cs
index aa5c789..a5af1fd 100644
--- a/examples/Complex/Complex/Ecs/IEntityWorld.cs
+++ b/examples/Complex/Complex.Engine/Ecs/IEntityRegistry.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
-using Complex.Ecs.Components;
+using Complex.Engine.Ecs.Components;
-namespace Complex.Ecs;
+namespace Complex.Engine.Ecs;
-public interface IEntityWorld
+public interface IEntityRegistry
{
event Action? ComponentAdded;
@@ -31,7 +31,7 @@ List GetEntitiesWithComponents()
T? GetComponent(EntityId entityId) where T : Component;
- IList GetComponents() where T : Component;
+ List GetComponents() where T : Component;
Dictionary.ValueCollection GetAllComponents(EntityId entityId);
}
diff --git a/examples/Complex/Complex/Ecs/Systems/IPreRenderSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/IPreRenderSystem.cs
similarity index 60%
rename from examples/Complex/Complex/Ecs/Systems/IPreRenderSystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/IPreRenderSystem.cs
index c0f89eb..d91acc7 100644
--- a/examples/Complex/Complex/Ecs/Systems/IPreRenderSystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/IPreRenderSystem.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
public interface IPreRenderSystem
{
diff --git a/examples/Complex/Complex/Ecs/Systems/ISystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/ISystem.cs
similarity index 62%
rename from examples/Complex/Complex/Ecs/Systems/ISystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/ISystem.cs
index 742de8b..4713f2e 100644
--- a/examples/Complex/Complex/Ecs/Systems/ISystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/ISystem.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
public interface ISystem
{
diff --git a/examples/Complex/Complex/Ecs/Systems/ISystemsUpdater.cs b/examples/Complex/Complex.Engine/Ecs/Systems/ISystemsUpdater.cs
similarity index 65%
rename from examples/Complex/Complex/Ecs/Systems/ISystemsUpdater.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/ISystemsUpdater.cs
index 9298e9c..87a374f 100644
--- a/examples/Complex/Complex/Ecs/Systems/ISystemsUpdater.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/ISystemsUpdater.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
public interface ISystemsUpdater
{
diff --git a/examples/Complex/Complex/Ecs/Systems/ITransformSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/ITransformSystem.cs
similarity index 65%
rename from examples/Complex/Complex/Ecs/Systems/ITransformSystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/ITransformSystem.cs
index df1bd9a..f911005 100644
--- a/examples/Complex/Complex/Ecs/Systems/ITransformSystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/ITransformSystem.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
public interface ITransformSystem
{
diff --git a/examples/Complex/Complex/Ecs/Systems/IUpdateCameraSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/IUpdateCameraSystem.cs
similarity index 66%
rename from examples/Complex/Complex/Ecs/Systems/IUpdateCameraSystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/IUpdateCameraSystem.cs
index b568d10..7f12874 100644
--- a/examples/Complex/Complex/Ecs/Systems/IUpdateCameraSystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/IUpdateCameraSystem.cs
@@ -1,4 +1,4 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
public interface IUpdateCameraSystem
{
diff --git a/examples/Complex/Complex/Ecs/Systems/PreRenderSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/PreRenderSystem.cs
similarity index 65%
rename from examples/Complex/Complex/Ecs/Systems/PreRenderSystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/PreRenderSystem.cs
index fac7c15..f7a3531 100644
--- a/examples/Complex/Complex/Ecs/Systems/PreRenderSystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/PreRenderSystem.cs
@@ -1,26 +1,26 @@
using System.Runtime.InteropServices;
-using Complex.Ecs.Components;
+using Complex.Engine.Ecs.Components;
using EngineKit;
using EngineKit.Graphics;
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
-internal class PreRenderSystem : IPreRenderSystem
+public class PreRenderSystem : IPreRenderSystem
{
private readonly ICamera _camera;
- private readonly IEntityWorld _entityWorld;
+ private readonly IEntityRegistry _entityRegistry;
private readonly IMaterialLibrary _materialLibrary;
- private readonly IRenderer _renderer;
+ private readonly IRenderer2 _renderer;
- public PreRenderSystem(IEntityWorld entityWorld,
- IRenderer renderer,
+ public PreRenderSystem(IEntityRegistry entityRegistry,
+ IRenderer2 renderer,
IMaterialLibrary materialLibrary,
ICamera camera)
{
- _entityWorld = entityWorld;
+ _entityRegistry = entityRegistry;
_renderer = renderer;
_materialLibrary = materialLibrary;
_camera = camera;
@@ -28,17 +28,20 @@ public PreRenderSystem(IEntityWorld entityWorld,
public void Update()
{
- var globalLightEntities = _entityWorld.GetEntitiesWithComponents();
+ var globalLightEntities = _entityRegistry.GetEntitiesWithComponents();
var globalLightEntitiesSpan = CollectionsMarshal.AsSpan(globalLightEntities);
for (var i = 0; i < globalLightEntities.Count; i++)
{
ref var globalLightEntity = ref globalLightEntitiesSpan[i];
}
- var meshEntities = _entityWorld.GetEntitiesWithComponents();
+ var meshEntities = _entityRegistry.GetEntitiesWithComponents();
var meshEntitiesSpan = CollectionsMarshal.AsSpan(meshEntities);
- if (meshEntities.Count > 0) _renderer.Clear();
+ if(meshEntities.Count > 0)
+ {
+ _renderer.Clear();
+ }
var cameraFrustum = _camera.GetViewFrustum();
@@ -46,8 +49,8 @@ public void Update()
{
ref var meshEntity = ref meshEntitiesSpan[i];
- var meshComponent = _entityWorld.GetComponent(meshEntity.Id);
- var materialComponent = _entityWorld.GetComponent(meshEntity.Id);
+ var meshComponent = _entityRegistry.GetComponent(meshEntity.Id);
+ var materialComponent = _entityRegistry.GetComponent(meshEntity.Id);
var material = materialComponent == null
? _materialLibrary.GetMaterialByName("M_Default") //TODO(deccer): add a GetDefaultMaterial()
: materialComponent.Material;
diff --git a/examples/Complex/Complex/Ecs/Systems/SystemsUpdater.cs b/examples/Complex/Complex.Engine/Ecs/Systems/SystemsUpdater.cs
similarity index 89%
rename from examples/Complex/Complex/Ecs/Systems/SystemsUpdater.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/SystemsUpdater.cs
index e81211d..b2e617e 100644
--- a/examples/Complex/Complex/Ecs/Systems/SystemsUpdater.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/SystemsUpdater.cs
@@ -1,6 +1,6 @@
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
-internal class SystemsUpdater : ISystemsUpdater
+public class SystemsUpdater : ISystemsUpdater
{
private readonly IPreRenderSystem _preRenderSystem;
diff --git a/examples/Complex/Complex/Ecs/Systems/TransformSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/TransformSystem.cs
similarity index 55%
rename from examples/Complex/Complex/Ecs/Systems/TransformSystem.cs
rename to examples/Complex/Complex.Engine/Ecs/Systems/TransformSystem.cs
index 3dd3237..135607a 100644
--- a/examples/Complex/Complex/Ecs/Systems/TransformSystem.cs
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/TransformSystem.cs
@@ -1,31 +1,31 @@
using System.Runtime.InteropServices;
-using Complex.Ecs.Components;
-using Complex.Physics;
+using Complex.Engine.Ecs.Components;
+using Complex.Engine.Physics;
-namespace Complex.Ecs.Systems;
+namespace Complex.Engine.Ecs.Systems;
-internal class TransformSystem : ITransformSystem
+public class TransformSystem : ITransformSystem
{
- private readonly IEntityWorld _entityWorld;
+ private readonly IEntityRegistry _entityRegistry;
private readonly IPhysicsWorld _physicsWorld;
- public TransformSystem(IEntityWorld entityWorld,
+ public TransformSystem(IEntityRegistry entityRegistry,
IPhysicsWorld physicsWorld)
{
- _entityWorld = entityWorld;
+ _entityRegistry = entityRegistry;
_physicsWorld = physicsWorld;
}
public void Update(float deltaTime)
{
- var entities = _entityWorld.GetEntitiesWithComponents();
+ var entities = _entityRegistry.GetEntitiesWithComponents();
var entitiesSpan = CollectionsMarshal.AsSpan(entities);
for (var i = 0; i < entitiesSpan.Length; i++)
{
ref var entity = ref entitiesSpan[i];
- var physicsBody = _entityWorld.GetComponent(entity.Id);
+ var physicsBody = _entityRegistry.GetComponent(entity.Id);
if (physicsBody != null)
{
entity.LocalMatrix = _physicsWorld.GetBodyPoseByBodyHandle(physicsBody.Handle);
diff --git a/examples/Complex/Complex.Engine/Ecs/Systems/UpdateCameraSystem.cs b/examples/Complex/Complex.Engine/Ecs/Systems/UpdateCameraSystem.cs
new file mode 100644
index 0000000..7d8e5c1
--- /dev/null
+++ b/examples/Complex/Complex.Engine/Ecs/Systems/UpdateCameraSystem.cs
@@ -0,0 +1,21 @@
+using EngineKit;
+
+namespace Complex.Engine.Ecs.Systems;
+
+public class UpdateCameraSystem : IUpdateCameraSystem
+{
+ private readonly ICamera _camera;
+
+ private readonly IEntityRegistry _entityRegistry;
+
+ public UpdateCameraSystem(IEntityRegistry entityRegistry,
+ ICamera camera)
+ {
+ _entityRegistry = entityRegistry;
+ _camera = camera;
+ }
+
+ public void Update(float deltaTime)
+ {
+ }
+}
diff --git a/examples/Complex/Complex.Engine/GameApplication.cs b/examples/Complex/Complex.Engine/GameApplication.cs
new file mode 100644
index 0000000..38b8e13
--- /dev/null
+++ b/examples/Complex/Complex.Engine/GameApplication.cs
@@ -0,0 +1,50 @@
+using EngineKit;
+using EngineKit.Core;
+using EngineKit.Graphics;
+using EngineKit.Input;
+using Microsoft.Extensions.Options;
+using Serilog;
+
+namespace Complex.Engine;
+
+public class GameApplication : GraphicsApplication where TGame : IGame
+{
+ private readonly TGame _game;
+
+ public GameApplication(ILogger logger,
+ IOptions windowSettings,
+ IOptions contextSettings,
+ IMessageBus messageBus,
+ IApplicationContext applicationContext,
+ ICapabilities capabilities,
+ IMetrics metrics,
+ IInputProvider inputProvider,
+ IGraphicsContext graphicsContext,
+ IRenderer renderer,
+ IUIRenderer uiRenderer,
+ TGame game) : base(logger, windowSettings, contextSettings, messageBus, applicationContext, capabilities, metrics, inputProvider, graphicsContext, renderer, uiRenderer)
+ {
+ _game = game;
+ }
+
+ protected override bool OnLoad()
+ {
+ if (!base.OnLoad())
+ {
+ return false;
+ }
+
+ if (!_game.Load())
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ protected override void OnUnload()
+ {
+ _game.Unload();
+ base.OnUnload();
+ }
+}
diff --git a/examples/Complex/Complex/GpuGlobals.cs b/examples/Complex/Complex.Engine/GpuGlobals.cs
similarity index 83%
rename from examples/Complex/Complex/GpuGlobals.cs
rename to examples/Complex/Complex.Engine/GpuGlobals.cs
index af7e6be..62fcff0 100644
--- a/examples/Complex/Complex/GpuGlobals.cs
+++ b/examples/Complex/Complex.Engine/GpuGlobals.cs
@@ -1,6 +1,6 @@
using System.Numerics;
-namespace Complex;
+namespace Complex.Engine;
public struct GpuGlobals
{
diff --git a/examples/Complex/Complex/GpuInstance.cs b/examples/Complex/Complex.Engine/GpuInstance.cs
similarity index 85%
rename from examples/Complex/Complex/GpuInstance.cs
rename to examples/Complex/Complex.Engine/GpuInstance.cs
index 76332fd..8004a3b 100644
--- a/examples/Complex/Complex/GpuInstance.cs
+++ b/examples/Complex/Complex.Engine/GpuInstance.cs
@@ -1,7 +1,7 @@
using System.Numerics;
using EngineKit.Mathematics;
-namespace Complex;
+namespace Complex.Engine;
public struct GpuInstance
{
diff --git a/examples/Complex/Complex/IRenderer.cs b/examples/Complex/Complex.Engine/IRenderer2.cs
similarity index 83%
rename from examples/Complex/Complex/IRenderer.cs
rename to examples/Complex/Complex.Engine/IRenderer2.cs
index 0b848ce..0ca8b1b 100644
--- a/examples/Complex/Complex/IRenderer.cs
+++ b/examples/Complex/Complex.Engine/IRenderer2.cs
@@ -4,9 +4,9 @@
using EngineKit.Graphics;
using EngineKit.Mathematics;
-namespace Complex;
+namespace Complex.Engine;
-public interface IRenderer : IDisposable
+public interface IRenderer2 : IDisposable
{
void Clear();
@@ -22,6 +22,4 @@ void AddMeshInstance(MeshPrimitive meshPrimitive,
void RenderUI();
FramebufferDescriptor GetMainFramebufferDescriptor();
-
- void ResizeIfNecessary();
}
diff --git a/examples/Complex/Complex/IScene.cs b/examples/Complex/Complex.Engine/IScene.cs
similarity index 91%
rename from examples/Complex/Complex/IScene.cs
rename to examples/Complex/Complex.Engine/IScene.cs
index c005f18..14d806d 100644
--- a/examples/Complex/Complex/IScene.cs
+++ b/examples/Complex/Complex.Engine/IScene.cs
@@ -1,9 +1,9 @@
using System;
using System.Numerics;
-using Complex.Ecs;
+using Complex.Engine.Ecs;
using EngineKit.Graphics;
-namespace Complex;
+namespace Complex.Engine;
public interface IScene : IDisposable
{
diff --git a/examples/Complex/Complex/Physics/IPhysicsWorld.cs b/examples/Complex/Complex.Engine/Physics/IPhysicsWorld.cs
similarity index 84%
rename from examples/Complex/Complex/Physics/IPhysicsWorld.cs
rename to examples/Complex/Complex.Engine/Physics/IPhysicsWorld.cs
index 072ef7b..9debef2 100644
--- a/examples/Complex/Complex/Physics/IPhysicsWorld.cs
+++ b/examples/Complex/Complex.Engine/Physics/IPhysicsWorld.cs
@@ -2,7 +2,7 @@
using System.Numerics;
using BepuPhysics;
-namespace Complex.Physics;
+namespace Complex.Engine.Physics;
public interface IPhysicsWorld : IDisposable
{
diff --git a/examples/Complex/Complex/Physics/NarrowPhaseCallbacks.cs b/examples/Complex/Complex.Engine/Physics/NarrowPhaseCallbacks.cs
similarity index 98%
rename from examples/Complex/Complex/Physics/NarrowPhaseCallbacks.cs
rename to examples/Complex/Complex.Engine/Physics/NarrowPhaseCallbacks.cs
index bc23f4d..5957282 100644
--- a/examples/Complex/Complex/Physics/NarrowPhaseCallbacks.cs
+++ b/examples/Complex/Complex.Engine/Physics/NarrowPhaseCallbacks.cs
@@ -4,7 +4,7 @@
using BepuPhysics.CollisionDetection;
using BepuPhysics.Constraints;
-namespace Complex.Physics;
+namespace Complex.Engine.Physics;
internal struct NarrowPhaseCallbacks : INarrowPhaseCallbacks
{
diff --git a/examples/Complex/Complex/Physics/PhysicsWorld.cs b/examples/Complex/Complex.Engine/Physics/PhysicsWorld.cs
similarity index 93%
rename from examples/Complex/Complex/Physics/PhysicsWorld.cs
rename to examples/Complex/Complex.Engine/Physics/PhysicsWorld.cs
index 72b9d6f..19db277 100644
--- a/examples/Complex/Complex/Physics/PhysicsWorld.cs
+++ b/examples/Complex/Complex.Engine/Physics/PhysicsWorld.cs
@@ -4,9 +4,9 @@
using BepuUtilities;
using BepuUtilities.Memory;
-namespace Complex.Physics;
+namespace Complex.Engine.Physics;
-internal class PhysicsWorld : IPhysicsWorld
+public class PhysicsWorld : IPhysicsWorld
{
private readonly BufferPool _bufferPool;
diff --git a/examples/Complex/Complex/Physics/PoseIntegratorCallbacks.cs b/examples/Complex/Complex.Engine/Physics/PoseIntegratorCallbacks.cs
similarity index 96%
rename from examples/Complex/Complex/Physics/PoseIntegratorCallbacks.cs
rename to examples/Complex/Complex.Engine/Physics/PoseIntegratorCallbacks.cs
index f239e89..c80a8e5 100644
--- a/examples/Complex/Complex/Physics/PoseIntegratorCallbacks.cs
+++ b/examples/Complex/Complex.Engine/Physics/PoseIntegratorCallbacks.cs
@@ -2,7 +2,7 @@
using BepuPhysics;
using BepuUtilities;
-namespace Complex.Physics;
+namespace Complex.Engine.Physics;
public struct PoseIntegratorCallbacks : IPoseIntegratorCallbacks
{
diff --git a/examples/Complex/Complex/ForwardRenderer.cs b/examples/Complex/Complex.Engine/Renderer.cs
similarity index 71%
rename from examples/Complex/Complex/ForwardRenderer.cs
rename to examples/Complex/Complex.Engine/Renderer.cs
index d4f6f2f..8ef099e 100644
--- a/examples/Complex/Complex/ForwardRenderer.cs
+++ b/examples/Complex/Complex.Engine/Renderer.cs
@@ -1,13 +1,14 @@
using System.Numerics;
using EngineKit;
using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
using ImGuiNET;
using Serilog;
-namespace Complex;
+namespace Complex.Engine;
-internal class ForwardRenderer : IRenderer
+public class Renderer : IRenderer2
{
private readonly IApplicationContext _applicationContext;
@@ -61,14 +62,13 @@ internal class ForwardRenderer : IRenderer
public bool ShowAaBb;
- private bool _isEditor;
+ private bool _isEditor = true;
- public ForwardRenderer(
- ILogger logger,
- IGraphicsContext graphicsContext,
- ISamplerLibrary samplerLibrary,
- IApplicationContext applicationContext,
- ICamera camera)
+ public Renderer(ILogger logger,
+ IGraphicsContext graphicsContext,
+ ISamplerLibrary samplerLibrary,
+ IApplicationContext applicationContext,
+ ICamera camera)
{
_logger = logger;
_graphicsContext = graphicsContext;
@@ -108,7 +108,7 @@ public bool Load()
_cameraInformationBuffer = _graphicsContext.CreateTypedBuffer("GpuGlobals",
1,
BufferStorageFlags.DynamicStorage);
- _indirectBuffer = _graphicsContext.CreateTypedBuffer("GpuIndirectElements",
+ _indirectBuffer = _graphicsContext.CreateTypedBuffer("GpuIndirectElements",
20_480u,
BufferStorageFlags.DynamicStorage);
_instanceBuffer = _graphicsContext.CreateTypedBuffer("GpuInstances",
@@ -116,7 +116,7 @@ public bool Load()
BufferStorageFlags.DynamicStorage);
//TODO: refactor this out into some LineRenderer
- _lineVertexBuffer = _graphicsContext.CreateTypedBuffer("Debug-Aabb-Lines",
+ _lineVertexBuffer = _graphicsContext.CreateTypedBuffer("Debug-Aabb-Lines",
_maxAabbCount,
BufferStorageFlags.DynamicStorage);
@@ -130,7 +130,7 @@ public bool Load()
.AddAttribute(0, Format.R32G32B32Float, 12)
.AddAttribute(0, Format.R32G32Float, 24)
.AddAttribute(0, Format.R32G32B32A32Float, 30)
- .Build(nameof(VertexPositionNormalUvTangent)))
+ .Build(nameof(GpuVertexPositionNormalUvTangent)))
.WithDepthTestEnabled(CompareFunction.Greater)
.WithClipControlDepth(ClipControlDepth.ZeroToOne)
.WithCullingEnabled(CullMode.Back)
@@ -154,7 +154,7 @@ public bool Load()
new VertexInputDescriptorBuilder()
.AddAttribute(0, Format.R32G32B32Float, 0)
.AddAttribute(0, Format.R32G32B32Float, 12)
- .Build(nameof(VertexPositionColor)))
+ .Build(nameof(GpuVertexPositionColor)))
.WithTopology(PrimitiveTopology.Lines)
.WithFaceWinding(FaceWinding.Clockwise)
.WithClipControlDepth(ClipControlDepth.ZeroToOne)
@@ -171,7 +171,7 @@ public bool Load()
_lineRendererGraphicsPipeline = lineRendererGraphicsPipelineResult.Value;
- CreateFramebufferDependentResources();
+ CreateFramebufferDependentResources(_applicationContext.ScaledWindowFramebufferSize);
_isLoaded = true;
@@ -192,7 +192,7 @@ public void AddMeshInstance(MeshPrimitive meshPrimitive,
var meshId = _meshPool!.GetOrAdd(meshPrimitive);
var materialId = _materialPool!.GetOrAdd(material);
- _indirectBuffer!.UpdateElement(new DrawElementIndirectCommand
+ _indirectBuffer!.UpdateElement(new GpuDrawElementIndirectCommand
{
BaseInstance = 0,
BaseVertex = meshId.VertexOffset,
@@ -221,6 +221,16 @@ public void AddMeshInstance(MeshPrimitive meshPrimitive,
public void Render(ICamera camera)
{
+ if(ResizeIfNecessary())
+ {
+ var scaledViewSize = _isEditor
+ ? _applicationContext.ScaledSceneViewSize
+ : _applicationContext.ScaledWindowFramebufferSize;
+ _camera.Resize(scaledViewSize.X, scaledViewSize.Y);
+ //_forwardRenderPass.ResizeViewport(scaledViewSize.X, scaledViewSize.Y);
+
+ }
+
_gpuGlobals.ProjectionMatrix = camera.ProjectionMatrix;
_gpuGlobals.ViewMatrix = camera.ViewMatrix;
_cameraInformationBuffer!.UpdateElement(_gpuGlobals, 0);
@@ -243,7 +253,7 @@ public void Render(ICamera camera)
{
//TODO(deccer) refactor out into some sort of LineRenderer
_graphicsContext.BindGraphicsPipeline(_lineRendererGraphicsPipeline!);
- _lineRendererGraphicsPipeline!.BindAsVertexBuffer(_lineVertexBuffer!, 0, VertexPositionColor.Stride, Offset.Zero);
+ _lineRendererGraphicsPipeline!.BindAsVertexBuffer(_lineVertexBuffer!, 0, GpuVertexPositionColor.Stride, Offset.Zero);
_lineRendererGraphicsPipeline.BindAsUniformBuffer(_cameraInformationBuffer, 0, Offset.Zero, SizeInBytes.Whole);
_lineRendererGraphicsPipeline.DrawArrays(24 * _aabbCounter, Offset.Zero);
}
@@ -251,8 +261,8 @@ public void Render(ICamera camera)
if (!_isEditor)
{
_graphicsContext.BlitFramebufferToSwapchain(
- _applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y,
+ _applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y,
_applicationContext.WindowFramebufferSize.X,
_applicationContext.WindowFramebufferSize.Y);
}
@@ -307,108 +317,90 @@ private void AddDebugLinesForBoundingBox(BoundingBox boundingBox)
var farTopLeft = bbCorners[6];
var farBottomLeft = bbCorners[7];
- VertexPositionColor[] vertices =
+ GpuVertexPositionColor[] vertices =
[
- new VertexPositionColor(nearBottomRight, nearColor),
- new VertexPositionColor(nearTopRight, nearColor),
+ new GpuVertexPositionColor(nearBottomRight, nearColor),
+ new GpuVertexPositionColor(nearTopRight, nearColor),
- new VertexPositionColor(nearTopRight, nearColor),
- new VertexPositionColor(nearTopLeft, nearColor),
+ new GpuVertexPositionColor(nearTopRight, nearColor),
+ new GpuVertexPositionColor(nearTopLeft, nearColor),
- new VertexPositionColor(nearTopLeft, nearColor),
- new VertexPositionColor(nearBottomLeft, nearColor),
+ new GpuVertexPositionColor(nearTopLeft, nearColor),
+ new GpuVertexPositionColor(nearBottomLeft, nearColor),
- new VertexPositionColor(nearBottomLeft, nearColor),
- new VertexPositionColor(nearBottomRight, nearColor),
+ new GpuVertexPositionColor(nearBottomLeft, nearColor),
+ new GpuVertexPositionColor(nearBottomRight, nearColor),
- new VertexPositionColor(nearBottomRight, nearColor),
- new VertexPositionColor(farBottomRight, farColor),
+ new GpuVertexPositionColor(nearBottomRight, nearColor),
+ new GpuVertexPositionColor(farBottomRight, farColor),
- new VertexPositionColor(nearTopRight, nearColor),
- new VertexPositionColor(farTopRight, farColor),
+ new GpuVertexPositionColor(nearTopRight, nearColor),
+ new GpuVertexPositionColor(farTopRight, farColor),
- new VertexPositionColor(nearTopLeft, nearColor),
- new VertexPositionColor(farTopLeft, farColor),
+ new GpuVertexPositionColor(nearTopLeft, nearColor),
+ new GpuVertexPositionColor(farTopLeft, farColor),
- new VertexPositionColor(nearBottomLeft, nearColor),
- new VertexPositionColor(farBottomLeft, farColor),
+ new GpuVertexPositionColor(nearBottomLeft, nearColor),
+ new GpuVertexPositionColor(farBottomLeft, farColor),
- new VertexPositionColor(farBottomRight, farColor),
- new VertexPositionColor(farTopRight, farColor),
+ new GpuVertexPositionColor(farBottomRight, farColor),
+ new GpuVertexPositionColor(farTopRight, farColor),
- new VertexPositionColor(farTopRight, farColor),
- new VertexPositionColor(farTopLeft, farColor),
+ new GpuVertexPositionColor(farTopRight, farColor),
+ new GpuVertexPositionColor(farTopLeft, farColor),
- new VertexPositionColor(farTopLeft, farColor),
- new VertexPositionColor(farBottomLeft, farColor),
+ new GpuVertexPositionColor(farTopLeft, farColor),
+ new GpuVertexPositionColor(farBottomLeft, farColor),
- new VertexPositionColor(farBottomLeft, farColor),
- new VertexPositionColor(farBottomRight, farColor)
+ new GpuVertexPositionColor(farBottomLeft, farColor),
+ new GpuVertexPositionColor(farBottomRight, farColor)
];
_lineVertexBuffer!.UpdateElements(vertices, _aabbCounter * 24);
_aabbCounter++;
}
- public void ResizeIfNecessary()
+ public bool ResizeIfNecessary()
{
- if (!_applicationContext.HasWindowFramebufferSizeChanged && !_applicationContext.HasSceneViewSizeChanged)
+ if(_applicationContext.HasWindowFramebufferSizeChanged || _applicationContext.HasSceneViewSizeChanged)
{
- return;
- }
-
- ResizeFramebufferDependentResources();
+ var scaledFramebufferSize = _isEditor
+ ? _applicationContext.ScaledSceneViewSize
+ : _applicationContext.ScaledWindowFramebufferSize;
- if (!_isEditor)
- {
- _camera.Resize(_applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y);
- _forwardRenderPass.ResizeViewport(_applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y);
- }
- else
- {
- _camera.Resize(_applicationContext.SceneViewSize.X, _applicationContext.SceneViewSize.Y);
- _forwardRenderPass.ResizeViewport(_applicationContext.SceneViewSize.X, _applicationContext.SceneViewSize.Y);
- }
+ if((scaledFramebufferSize.X * scaledFramebufferSize.Y) > 0)
+ {
- }
+ DestroyFramebufferDependentResources();
+ CreateFramebufferDependentResources(scaledFramebufferSize);
- private void ResizeFramebufferDependentResources()
- {
- if (_applicationContext.HasWindowFramebufferSizeChanged || _applicationContext.HasSceneViewSizeChanged)
- {
- DestroyFramebufferDependentResources();
- CreateFramebufferDependentResources();
+ _applicationContext.HasSceneViewSizeChanged = false;
+ _applicationContext.HasWindowFramebufferSizeChanged = false;
- _applicationContext.HasSceneViewSizeChanged = false;
- _applicationContext.HasWindowFramebufferSizeChanged = false;
+ return true;
+ }
}
+
+ return false;
}
- private void CreateFramebufferDependentResources()
+ private void CreateFramebufferDependentResources(Int2 scaledFramebufferSize)
{
- _forwardRenderPassColorAttachment = _graphicsContext.CreateTexture2D(_isEditor
- ? _applicationContext.SceneViewScaledSize
- : _applicationContext.WindowScaledFramebufferSize,
+ _forwardRenderPassColorAttachment = _graphicsContext.CreateTexture2D(scaledFramebufferSize,
Format.R8G8B8A8Srgb,
"ForwardColorAttachment");
- _forwardRenderPassDepthAttachment = _graphicsContext.CreateTexture2D(_isEditor
- ? _applicationContext.SceneViewScaledSize
- : _applicationContext.WindowScaledFramebufferSize,
+ _forwardRenderPassDepthAttachment = _graphicsContext.CreateTexture2D(scaledFramebufferSize,
Format.D32Float,
"ForwardDepthAttachment");
- var viewport = _isEditor
- ? _applicationContext.SceneViewScaledSize
- : _applicationContext.WindowFramebufferSize;
-
_forwardRenderPass = _graphicsContext.GetFramebufferDescriptorBuilder()
.WithColorAttachment(_forwardRenderPassColorAttachment,
true,
- Colors.DarkSlateBlue) //MathHelper.GammaToLinear(Colors.DarkSlateBlue))
+ MathHelper.GammaToLinear(Colors.DarkSlateBlue))
.WithDepthAttachment(_forwardRenderPassDepthAttachment,
true,
0)
- .WithViewport(viewport.X, viewport.Y)
+ //.WithViewport(framebufferSize.X, framebufferSize.Y)
.Build("ForwardRenderPass");
}
diff --git a/examples/Complex/Complex/Ecs/Scene.cs b/examples/Complex/Complex.Engine/Scene.cs
similarity index 55%
rename from examples/Complex/Complex/Ecs/Scene.cs
rename to examples/Complex/Complex.Engine/Scene.cs
index 3fb810d..1b15463 100644
--- a/examples/Complex/Complex/Ecs/Scene.cs
+++ b/examples/Complex/Complex.Engine/Scene.cs
@@ -1,12 +1,13 @@
using System;
using System.Numerics;
-using Complex.Ecs.Components;
-using Complex.Ecs.Systems;
+using Complex.Engine.Ecs;
+using Complex.Engine.Ecs.Components;
+using Complex.Engine.Ecs.Systems;
using EngineKit.Graphics;
-namespace Complex.Ecs;
+namespace Complex.Engine;
-internal class Scene : IScene
+public class Scene : IScene
{
private readonly IMaterialLibrary _materialLibrary;
@@ -16,21 +17,21 @@ internal class Scene : IScene
private readonly ISystemsUpdater _systemsUpdater;
- private readonly IEntityWorld _world;
+ private readonly IEntityRegistry _registry;
private bool _isDisposed;
- public Scene(IEntityWorld world,
+ public Scene(IEntityRegistry registry,
IModelLibrary modelLibrary,
IMaterialLibrary materialLibrary,
ISystemsUpdater systemsUpdater)
{
- _world = world;
+ _registry = registry;
_modelLibrary = modelLibrary;
_materialLibrary = materialLibrary;
_systemsUpdater = systemsUpdater;
- _rootEntity = _world.CreateEntity("Root");
- _world.AddComponent(_rootEntity, new NameComponent("Root"));
+ _rootEntity = _registry.CreateEntity("Root");
+ _registry.AddComponent(_rootEntity, new NameComponent("Root"));
}
public void Update(float deltaTime)
@@ -57,14 +58,14 @@ public void AddEntityWithModelMeshRenderer(string name,
Matrix4x4 startWorldMatrix)
{
var parentEntity = parent ?? _rootEntity;
- var modelEntityId = _world.CreateEntity(name, parentEntity);
- var modelEntity = _world.GetEntity(modelEntityId);
+ var modelEntityId = _registry.CreateEntity(name, parentEntity);
+ var modelEntity = _registry.GetEntity(modelEntityId);
modelEntity!.LocalMatrix = modelMesh.MeshPrimitive.Transform;
- _world.AddComponent(modelEntityId, new NameComponent(name));
- _world.AddComponent(modelEntityId, new ModelMeshComponent(modelMesh.MeshPrimitive));
- _world.AddComponent(modelEntityId, new MaterialComponent(_materialLibrary.GetMaterialByName(modelMesh.MeshPrimitive.MaterialName)));
+ _registry.AddComponent(modelEntityId, new NameComponent(name));
+ _registry.AddComponent(modelEntityId, new ModelMeshComponent(modelMesh.MeshPrimitive));
+ _registry.AddComponent(modelEntityId, new MaterialComponent(_materialLibrary.GetMaterialByName(modelMesh.MeshPrimitive.MaterialName)));
}
public void AddEntityWithModelRenderer(string name,
@@ -73,24 +74,24 @@ public void AddEntityWithModelRenderer(string name,
Matrix4x4 startWorldMatrix)
{
var parentEntity = parent ?? _rootEntity;
- var modelEntityId = _world.CreateEntity(name, parentEntity);
- var modelEntity = _world.GetEntity(modelEntityId);
+ var modelEntityId = _registry.CreateEntity(name, parentEntity);
+ var modelEntity = _registry.GetEntity(modelEntityId);
modelEntity!.LocalMatrix = startWorldMatrix;
- _world.AddComponent(modelEntityId, new NameComponent(name));
+ _registry.AddComponent(modelEntityId, new NameComponent(name));
foreach (var modelMesh in model.ModelMeshes)
{
var modelMeshName = string.IsNullOrEmpty(modelMesh.Name)
? $"Mesh-{Guid.NewGuid().ToString()}"
: modelMesh.Name;
- var modelMeshEntityId = _world.CreateEntity(modelMeshName, modelEntityId);
- var modelMeshEntity = _world.GetEntity(modelMeshEntityId);
+ var modelMeshEntityId = _registry.CreateEntity(modelMeshName, modelEntityId);
+ var modelMeshEntity = _registry.GetEntity(modelMeshEntityId);
modelMeshEntity!.LocalMatrix = modelMesh.MeshPrimitive.Transform;
- _world.AddComponent(modelMeshEntityId, new NameComponent(modelMeshName));
- _world.AddComponent(modelMeshEntityId, new ModelMeshComponent(modelMesh.MeshPrimitive));
- _world.AddComponent(modelMeshEntityId, new MaterialComponent(_materialLibrary.GetMaterialByName(modelMesh.MeshPrimitive.MaterialName)));
+ _registry.AddComponent(modelMeshEntityId, new NameComponent(modelMeshName));
+ _registry.AddComponent(modelMeshEntityId, new ModelMeshComponent(modelMesh.MeshPrimitive));
+ _registry.AddComponent(modelMeshEntityId, new MaterialComponent(_materialLibrary.GetMaterialByName(modelMesh.MeshPrimitive.MaterialName)));
}
}
}
diff --git a/examples/Complex/Complex.Engine/ServiceCollectionExtensions.cs b/examples/Complex/Complex.Engine/ServiceCollectionExtensions.cs
new file mode 100644
index 0000000..fc63da5
--- /dev/null
+++ b/examples/Complex/Complex.Engine/ServiceCollectionExtensions.cs
@@ -0,0 +1,50 @@
+using System.Numerics;
+using Complex.Engine.Ecs;
+using Complex.Engine.Ecs.Systems;
+using Complex.Engine.Physics;
+using EngineKit;
+using EngineKit.Extensions;
+using EngineKit.Input;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Serilog;
+
+namespace Complex.Engine;
+
+public static class ServiceProviderFactory
+{
+ public static ServiceProvider Create() where TGame : class, IGame
+ {
+ var configuration = new ConfigurationBuilder()
+ .AddJsonFile("appsettings.json", false)
+ .Build();
+
+ Log.Logger = new LoggerConfiguration()
+ .ReadFrom.Configuration(configuration)
+ .CreateLogger();
+
+ var services = new ServiceCollection();
+ services.AddSingleton(configuration);
+ services.AddSingleton(Log.Logger);
+ services.Configure(configuration.GetSection(nameof(WindowSettings)));
+ services.Configure(configuration.GetSection(nameof(ContextSettings)));
+
+ services.AddSingleton();
+ services.AddSingleton>();
+ services.AddSingleton(provider => new Camera(
+ provider.GetRequiredService(),
+ provider.GetRequiredService(), new Vector3(0, 2, 10), Vector3.UnitY));
+
+ services.AddEngineKit();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+
+ return services.BuildServiceProvider();
+ }
+}
diff --git a/examples/Complex/Complex.Game.Assets/Complex.Game.Assets.csproj b/examples/Complex/Complex.Game.Assets/Complex.Game.Assets.csproj
new file mode 100644
index 0000000..c793c3f
--- /dev/null
+++ b/examples/Complex/Complex.Game.Assets/Complex.Game.Assets.csproj
@@ -0,0 +1,9 @@
+
+
+
+
+ PreserveNewest
+
+
+
+
diff --git a/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Light.ttf b/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Light.ttf
new file mode 100644
index 0000000..67e8408
Binary files /dev/null and b/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Light.ttf differ
diff --git a/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Regular.ttf b/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Regular.ttf
new file mode 100644
index 0000000..533e399
Binary files /dev/null and b/examples/Complex/Complex.Game.Assets/Fonts/RobotoCondensed-Regular.ttf differ
diff --git a/examples/Complex/Complex.Game/Complex.Game.csproj b/examples/Complex/Complex.Game/Complex.Game.csproj
new file mode 100644
index 0000000..b64daca
--- /dev/null
+++ b/examples/Complex/Complex.Game/Complex.Game.csproj
@@ -0,0 +1,24 @@
+
+
+
+ Exe
+
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+
+ enginekit-icon.png
+ PreserveNewest
+
+
+
diff --git a/examples/Complex/Complex.Game/ComplexGame.cs b/examples/Complex/Complex.Game/ComplexGame.cs
new file mode 100644
index 0000000..dbccfe9
--- /dev/null
+++ b/examples/Complex/Complex.Game/ComplexGame.cs
@@ -0,0 +1,25 @@
+using Complex.Engine;
+using EngineKit;
+
+namespace Complex.Game;
+
+// ReSharper disable once ClassNeverInstantiated.Global
+internal sealed class ComplexGame : IGame
+{
+ private readonly IScene _scene;
+
+ public ComplexGame(IScene scene)
+ {
+ _scene = scene;
+ }
+
+ public bool Load()
+ {
+ return true;
+ }
+
+ public void Unload()
+ {
+ }
+}
+
diff --git a/examples/Complex/Complex.Game/Program.cs b/examples/Complex/Complex.Game/Program.cs
new file mode 100644
index 0000000..cae1d18
--- /dev/null
+++ b/examples/Complex/Complex.Game/Program.cs
@@ -0,0 +1,15 @@
+using Complex.Engine;
+using EngineKit;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Complex.Game;
+
+internal static class Program
+{
+ public static void Main(string[] args)
+ {
+ using var serviceProvider = ServiceProviderFactory.Create();
+ var application = serviceProvider.GetRequiredService();
+ application.Run();
+ }
+}
diff --git a/examples/Complex/Complex.Game/appsettings.json b/examples/Complex/Complex.Game/appsettings.json
new file mode 100644
index 0000000..4c85b95
--- /dev/null
+++ b/examples/Complex/Complex.Game/appsettings.json
@@ -0,0 +1,31 @@
+{
+ "Serilog": {
+ "Using": [
+ "Serilog.Sinks.Console"
+ ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "Console"
+ }
+ ],
+ "Enrich": [
+ "FromLogContext"
+ ],
+ "Properties": {
+ "Application": "HelloWindow"
+ }
+ },
+ "WindowSettings": {
+ "ResolutionWidth": 1680,
+ "ResolutionHeight": 1050,
+ "ResolutionScale": 1.0,
+ "WindowMode": "Windowed",
+ "IsVsyncEnabled": true,
+ "Title": "Complex"
+ },
+ "ContextSettings": {
+ "TargetGLVersion": "4.6",
+ "IsDebugContext": true
+ }
+}
diff --git a/examples/Complex/Complex/Complex.csproj b/examples/Complex/Complex/Complex.csproj
index 6036698..b364710 100644
--- a/examples/Complex/Complex/Complex.csproj
+++ b/examples/Complex/Complex/Complex.csproj
@@ -7,18 +7,16 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
@@ -34,4 +32,4 @@
-
\ No newline at end of file
+
diff --git a/examples/Complex/Complex/ComplexApplication.cs b/examples/Complex/Complex/ComplexApplication.cs
index 8f98a7b..9f619d9 100644
--- a/examples/Complex/Complex/ComplexApplication.cs
+++ b/examples/Complex/Complex/ComplexApplication.cs
@@ -1,8 +1,9 @@
using System.Threading.Tasks;
using EngineKit;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
using EngineKit.Graphics;
using EngineKit.Input;
-using EngineKit.Messages;
using EngineKit.Native.OpenGL;
using Microsoft.Extensions.Options;
using Serilog;
@@ -30,17 +31,20 @@ public ComplexApplication(ILogger logger,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
IUIRenderer uiRenderer,
+ IRenderer renderer,
IMessageBus messageBus,
Game game,
Editor editor)
: base(logger,
windowSettings,
contextSettings,
+ messageBus,
applicationContext,
capabilities,
metrics,
inputProvider,
graphicsContext,
+ renderer,
uiRenderer)
{
_logger = logger;
@@ -95,10 +99,6 @@ protected override void OnRender(float deltaTime,
{
_game.Render(deltaTime, elapsedSeconds);
_editor.Render(deltaTime, elapsedSeconds);
- if (_applicationContext.IsLaunchedByNSightGraphicsOnLinux)
- {
- GL.Finish();
- }
}
protected override void OnUnload()
diff --git a/examples/Complex/Complex/Ecs/Components/TransformComponent.cs b/examples/Complex/Complex/Ecs/Components/TransformComponent.cs
deleted file mode 100644
index a45e5f0..0000000
--- a/examples/Complex/Complex/Ecs/Components/TransformComponent.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System.Numerics;
-
-namespace Complex.Ecs.Components;
-
-public class XTransformComponent : Component
-{
- public Matrix4x4 GlobalWorldMatrix;
-
- public bool IsSrt;
-
- public Vector3 LocalPosition = Vector3.Zero;
-
- public Quaternion LocalRotation = Quaternion.Identity;
-
- public Vector3 LocalScale = Vector3.One;
-
- public Matrix4x4 LocalWorldMatrix;
-
- public static XTransformComponent CreateFromMatrix(Matrix4x4 worldMatrix)
- {
- /*
- scale.X = 1.0f / scale.X;
- scale.Y = 1.0f / scale.Y;
- scale.Z = 1.0f / scale.Z;
- */
- Matrix4x4.Decompose(worldMatrix,
- out var scale,
- out var rotation,
- out var translation);
- return new XTransformComponent
- {
- LocalPosition = translation,
- LocalRotation = rotation,
- LocalScale = scale,
- LocalWorldMatrix = worldMatrix
- };
- }
-
- public static XTransformComponent CreateFromPosition(Vector3 position)
- {
- return new XTransformComponent
- {
- LocalPosition = position,
- LocalRotation = Quaternion.Identity,
- LocalScale = Vector3.One
- };
- }
-
- public void UpdateLocalMatrix()
- {
- var translationMatrix = Matrix4x4.CreateTranslation(LocalPosition);
- var rotationMatrix = Matrix4x4.CreateFromQuaternion(LocalRotation);
- var scaleMatrix = Matrix4x4.CreateScale(LocalScale);
-
- LocalWorldMatrix = scaleMatrix * rotationMatrix * translationMatrix;
- }
-}
diff --git a/examples/Complex/Complex/Ecs/EntityId.cs b/examples/Complex/Complex/Ecs/EntityId.cs
deleted file mode 100644
index 84cb88b..0000000
--- a/examples/Complex/Complex/Ecs/EntityId.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-
-namespace Complex.Ecs;
-
-public readonly struct EntityId : IEquatable
-{
- private readonly int _entityId;
-
- public EntityId(int entityId)
- {
- _entityId = entityId;
- }
-
- public bool Equals(EntityId other)
- {
- return _entityId == other._entityId;
- }
-
- public override bool Equals(object? obj)
- {
- return obj is EntityId other && Equals(other);
- }
-
- public override int GetHashCode()
- {
- return _entityId;
- }
-}
diff --git a/examples/Complex/Complex/Ecs/Systems/UpdateCameraSystem.cs b/examples/Complex/Complex/Ecs/Systems/UpdateCameraSystem.cs
deleted file mode 100644
index f06a637..0000000
--- a/examples/Complex/Complex/Ecs/Systems/UpdateCameraSystem.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using EngineKit;
-
-namespace Complex.Ecs.Systems;
-
-internal class UpdateCameraSystem : IUpdateCameraSystem
-{
- private readonly ICamera _camera;
-
- private readonly IEntityWorld _entityWorld;
-
- public UpdateCameraSystem(IEntityWorld entityWorld,
- ICamera camera)
- {
- _entityWorld = entityWorld;
- _camera = camera;
- }
-
- public void Update(float deltaTime)
- {
- }
-}
diff --git a/examples/Complex/Complex/Editor.cs b/examples/Complex/Complex/Editor.cs
index b133894..0f2efbe 100644
--- a/examples/Complex/Complex/Editor.cs
+++ b/examples/Complex/Complex/Editor.cs
@@ -1,8 +1,10 @@
using System.Numerics;
+using Complex.Engine;
using Complex.Windows;
using EngineKit;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
using EngineKit.Graphics;
-using EngineKit.Messages;
using EngineKit.UI;
using ImGuiNET;
using Microsoft.Extensions.Options;
@@ -30,7 +32,7 @@ internal sealed class Editor
private readonly PropertyWindow _propertyWindow;
- private readonly IRenderer _renderer;
+ private readonly IRenderer2 _renderer;
private readonly SceneHierarchyWindow _sceneHierarchyWindow;
@@ -46,7 +48,7 @@ public Editor(ILogger logger,
ICapabilities capabilities,
IMetrics metrics,
IGraphicsContext graphicsContext,
- IRenderer renderer,
+ IRenderer2 renderer,
IUIRenderer uiRenderer,
IMessageBus messageBus,
AssetWindow assetWindow,
@@ -85,9 +87,9 @@ public bool Load()
public void Render(float deltaTime,
float elapsedSeconds)
{
- if (_applicationContext.HasSceneViewSizeChanged)
+ //if (_applicationContext.HasWindowFramebufferSizeChanged)
{
- _swapchainDescriptor = CreateSwapchainDescriptor(_applicationContext.WindowScaledFramebufferSize.X, _applicationContext.WindowScaledFramebufferSize.Y);
+ _swapchainDescriptor = CreateSwapchainDescriptor(_applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y);
}
_graphicsContext.BeginRenderPass(_swapchainDescriptor);
diff --git a/examples/Complex/Complex/Game.cs b/examples/Complex/Complex/Game.cs
index 8716c3b..675bfe6 100644
--- a/examples/Complex/Complex/Game.cs
+++ b/examples/Complex/Complex/Game.cs
@@ -1,8 +1,10 @@
using System.Numerics;
+using Complex.Engine;
using EngineKit;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
using EngineKit.Graphics;
using EngineKit.Input;
-using EngineKit.Messages;
using EngineKit.Native.Glfw;
using Serilog;
@@ -13,17 +15,17 @@ internal class Game
private readonly ILogger _logger;
private readonly IMessageBus _messageBus;
private readonly IApplicationContext _applicationContext;
- private readonly IGraphicsContext _context;
+ private readonly IGraphicsContext _graphicsContext;
private readonly ICamera _camera;
private readonly IInputProvider _inputProvider;
private readonly IModelLibrary _modelLibrary;
- private readonly IRenderer _renderer;
+ private readonly IRenderer2 _renderer;
private readonly IScene _scene;
public Game(ILogger logger,
- IGraphicsContext context,
- IRenderer renderer,
+ IGraphicsContext graphicsContext,
+ IRenderer2 renderer,
ICamera camera,
IScene scene,
IInputProvider inputProvider,
@@ -32,7 +34,7 @@ public Game(ILogger logger,
IApplicationContext applicationContext)
{
_logger = logger.ForContext();
- _context = context;
+ _graphicsContext = graphicsContext;
_renderer = renderer;
_camera = camera;
_scene = scene;
@@ -57,12 +59,17 @@ public bool Load()
_modelLibrary.AddModelFromFile("SM_Deccer_Cubes_WR", "Data/Default/SM_Deccer_Cubes_With_Rotation.glb");
*/
+
_modelLibrary.AddModelFromFile("SM_Deccer_Cubes_Complex", "Data/Default/SM_Deccer_Cubes_Textured_Complex.gltf");
- _modelLibrary.AddModelFromFile("Nasa1", "Data/Props/Asteroids/nasa1.glb");
- _modelLibrary.AddModelFromFile("Nasa2", "Data/Props/Asteroids/nasa2.glb");
- _modelLibrary.AddModelFromFile("Nasa3", "Data/Props/Asteroids/nasa3.glb");
- _modelLibrary.AddModelFromFile("Nasa4", "Data/Props/Asteroids/nasa4.glb");
- _modelLibrary.AddModelFromFile("SF", "Data/Props/Test5.gltf");
+ /*
+ _modelLibrary.AddModelFromFile("Nasa1", "Data/Props/Asteroids/nasa1.glb");
+ _modelLibrary.AddModelFromFile("Nasa2", "Data/Props/Asteroids/nasa2.glb");
+ _modelLibrary.AddModelFromFile("Nasa3", "Data/Props/Asteroids/nasa3.glb");
+ _modelLibrary.AddModelFromFile("Nasa4", "Data/Props/Asteroids/nasa4.glb");
+ _modelLibrary.AddModelFromFile("SF", "Data/Props/Test5.gltf");
+ */
+ //_modelLibrary.AddModelFromFile("SM_Deccer_Cubes_Complex", "/home/deccer/Code/Caldera/SM_Airfield_Ground_mi.glb");
+ //_modelLibrary.AddModelFromFile("SM_Deccer_Cubes_Complex", "Data/Props/SimpleInstancing.glb");
//_modelLibrary.AddModelFromFile("FromSpace", "Data/Props/Asteroids/rock_from_space.glb");
//_modelLibrary.AddModelFromFile("E1M1", "Data/Scenes/E1M1/E1M1.gltf");
//_modelLibrary.AddModelFromFile("SmallCity", "Data/Scenes/small_city/small_city.gltf");
@@ -81,13 +88,15 @@ public bool Load()
return true;
}
- public void Render(float deltaTime,
+ public void Render(
+ float deltaTime,
float elapsedSeconds)
{
_renderer.Render(_camera);
}
- public void Update(float deltaTime,
+ public void Update(
+ float deltaTime,
float elapsedSeconds)
{
if (_inputProvider.KeyboardState.IsKeyPressed(Glfw.Key.KeyEscape))
@@ -95,8 +104,6 @@ public void Update(float deltaTime,
_messageBus.PublishWait(new CloseWindowMessage());
}
- _renderer.ResizeIfNecessary();
-
_scene.Update(deltaTime);
if (_inputProvider.MouseState.IsButtonDown(Glfw.MouseButton.ButtonRight))
diff --git a/examples/Complex/Complex/Program.cs b/examples/Complex/Complex/Program.cs
index 63edcef..ef67533 100644
--- a/examples/Complex/Complex/Program.cs
+++ b/examples/Complex/Complex/Program.cs
@@ -1,7 +1,4 @@
using System.Numerics;
-using Complex.Ecs;
-using Complex.Ecs.Systems;
-using Complex.Physics;
using Complex.Windows;
using EngineKit;
using EngineKit.Extensions;
@@ -12,6 +9,13 @@
namespace Complex;
+using Complex.Engine;
+using Complex.Engine.Ecs;
+using Complex.Engine.Ecs.Systems;
+using Complex.Engine.Physics;
+using EngineKit.Graphics;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
internal static class Program
{
public static void Main(string[] args)
@@ -35,31 +39,35 @@ private static ServiceProvider CreateServiceProvider()
var services = new ServiceCollection();
services.AddSingleton(configuration);
services.AddSingleton(Log.Logger);
+
services.Configure(configuration.GetSection(nameof(WindowSettings)));
services.Configure(configuration.GetSection(nameof(ContextSettings)));
- services.AddEngine();
services.AddSingleton();
services.AddSingleton(provider => new Camera(
provider.GetRequiredService(),
provider.GetRequiredService(), new Vector3(0, 2, 10), Vector3.UnitY));
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
- services.AddSingleton();
+
+ services.AddEngineKit();
+
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
- services.AddSingleton();
-
- services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
return services.BuildServiceProvider();
}
diff --git a/examples/Complex/Complex/Windows/AssetWindow.cs b/examples/Complex/Complex/Windows/AssetWindow.cs
index 1657813..b017050 100644
--- a/examples/Complex/Complex/Windows/AssetWindow.cs
+++ b/examples/Complex/Complex/Windows/AssetWindow.cs
@@ -1,4 +1,5 @@
using System.Numerics;
+using Complex.Engine;
using EngineKit;
using EngineKit.Graphics;
using EngineKit.UI;
diff --git a/examples/Complex/Complex/Windows/PropertyWindow.cs b/examples/Complex/Complex/Windows/PropertyWindow.cs
index 1fc89e4..eb134f0 100644
--- a/examples/Complex/Complex/Windows/PropertyWindow.cs
+++ b/examples/Complex/Complex/Windows/PropertyWindow.cs
@@ -1,6 +1,5 @@
-using Complex.Ecs;
-using Complex.Ecs.Components;
-using EngineKit.Mathematics;
+using Complex.Engine.Ecs;
+using Complex.Engine.Ecs.Components;
using EngineKit.UI;
using ImGuiNET;
@@ -8,15 +7,15 @@ namespace Complex.Windows;
public class PropertyWindow : Window
{
- private readonly IEntityWorld _world;
+ private readonly IEntityRegistry _registry;
private Entity? _selectedEntity;
private EntityId? _selectedEntityId;
- public PropertyWindow(IEntityWorld world)
+ public PropertyWindow(IEntityRegistry registry)
{
- _world = world;
+ _registry = registry;
Caption = $"{MaterialDesignIcons.Cards} Properties";
_selectedEntityId = null;
@@ -33,7 +32,7 @@ public EntityId? SelectedEntityId
_selectedEntityId = value;
if (_selectedEntityId.HasValue)
{
- _selectedEntity = _world.GetEntity(_selectedEntityId.Value);
+ _selectedEntity = _registry.GetEntity(_selectedEntityId.Value);
}
}
}
@@ -48,7 +47,7 @@ protected override void DrawInternal()
var transformShown = false;
- var components = _world.GetAllComponents(_selectedEntityId.Value);
+ var components = _registry.GetAllComponents(_selectedEntityId.Value);
foreach (var component in components)
{
var componentType = component.GetType();
@@ -71,7 +70,7 @@ protected override void DrawInternal()
{
if (!transformShown)
{
- ImGui.PushID(_selectedEntity.Name);
+ ImGui.PushID(_selectedEntity.Id.GetHashCode());
if (ImGui.CollapsingHeader($"{MaterialDesignIcons.Compass} Transform"))
{
diff --git a/examples/Complex/Complex/Windows/SceneHierarchyWindow.cs b/examples/Complex/Complex/Windows/SceneHierarchyWindow.cs
index fde5b1d..800448f 100644
--- a/examples/Complex/Complex/Windows/SceneHierarchyWindow.cs
+++ b/examples/Complex/Complex/Windows/SceneHierarchyWindow.cs
@@ -1,6 +1,7 @@
using System.Numerics;
-using Complex.Ecs;
-using Complex.Ecs.Components;
+using Complex.Engine;
+using Complex.Engine.Ecs;
+using Complex.Engine.Ecs.Components;
using EngineKit.UI;
using ImGuiNET;
@@ -16,15 +17,15 @@ public class SceneHierarchyWindow : Window
private readonly IScene _scene;
- private readonly IEntityWorld _world;
+ private readonly IEntityRegistry _registry;
private EntityId? _selectedEntityId;
- public SceneHierarchyWindow(IEntityWorld world,
+ public SceneHierarchyWindow(IEntityRegistry registry,
IScene scene,
PropertyWindow propertyWindow)
{
- _world = world;
+ _registry = registry;
_scene = scene;
_propertyWindow = propertyWindow;
@@ -32,7 +33,7 @@ public SceneHierarchyWindow(IEntityWorld world,
OverwriteStyle = true;
_rootEntityId = _scene.GetRoot();
- _rootEntity = _world.GetEntity(_rootEntityId);
+ _rootEntity = _registry.GetEntity(_rootEntityId);
}
public EntityId? SelectedEntityId
@@ -40,7 +41,7 @@ public EntityId? SelectedEntityId
get => _selectedEntityId;
set
{
- if (!_selectedEntityId.Equals(value))
+ if(!_selectedEntityId.Equals(value))
{
_selectedEntityId = value;
_propertyWindow.SelectedEntityId = value;
@@ -50,23 +51,14 @@ public EntityId? SelectedEntityId
protected override void DrawInternal()
{
- if (_rootEntity == null) return;
-
- var isOpen = ImGui.TreeNodeEx(_rootEntity.Name, ImGuiTreeNodeFlags.SpanFullWidth);
-
- if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
+ if(_rootEntity == null)
{
- SelectedEntityId = _rootEntityId;
+ return;
}
- if (isOpen)
+ foreach(var child in _rootEntity.Children)
{
- foreach (var child in _rootEntity.Children)
- {
- DrawChild(child);
- }
-
- ImGui.TreePop();
+ DrawChild(child);
}
}
@@ -83,26 +75,28 @@ protected override void UnsetStyleInternal()
private void DrawChild(Entity child)
{
var nodeFlags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.SpanFullWidth;
- if (SelectedEntityId.Equals(child.Id))
+
+ if(SelectedEntityId.Equals(child.Id))
{
nodeFlags |= ImGuiTreeNodeFlags.Selected;
}
ImGui.PushID(child.ToString());
- var nameComponent = _world.GetComponent(child.Id);
+ var nameComponent = _registry.GetComponent(child.Id);
var name = nameComponent?.Name ?? "UnnamedEntity";
ImGui.PushID(name + child);
var isOpen = ImGui.TreeNodeEx(name, nodeFlags);
- if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
+
+ if(ImGui.IsItemClicked(ImGuiMouseButton.Left))
{
SelectedEntityId = child.Id;
}
- if (isOpen)
+ if(isOpen)
{
- foreach (var grandChild in child.Children)
+ foreach(var grandChild in child.Children)
{
DrawChild(grandChild);
}
diff --git a/examples/Complex/Complex/Windows/SceneViewWindow.cs b/examples/Complex/Complex/Windows/SceneViewWindow.cs
index b0ac9fd..94d25f9 100644
--- a/examples/Complex/Complex/Windows/SceneViewWindow.cs
+++ b/examples/Complex/Complex/Windows/SceneViewWindow.cs
@@ -1,5 +1,7 @@
using System.Numerics;
+using Complex.Engine;
using EngineKit;
+using EngineKit.Core;
using EngineKit.UI;
using ImGuiNET;
@@ -9,11 +11,11 @@ public class SceneViewWindow : Window
{
private readonly IApplicationContext _applicationContext;
- private readonly IRenderer _renderer;
+ private readonly IRenderer2 _renderer;
private Vector2 _oldAvailableSize;
- public SceneViewWindow(IRenderer renderer,
+ public SceneViewWindow(IRenderer2 renderer,
IApplicationContext applicationContext,
IMessageBus messageBus)
{
diff --git a/examples/ComputeConvolution/ComputeConvolution/ComputeConvolution.csproj b/examples/ComputeConvolution/ComputeConvolution/ComputeConvolution.csproj
index fa2bc30..52e7acb 100644
--- a/examples/ComputeConvolution/ComputeConvolution/ComputeConvolution.csproj
+++ b/examples/ComputeConvolution/ComputeConvolution/ComputeConvolution.csproj
@@ -6,17 +6,16 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
diff --git a/examples/ComputeConvolution/ComputeConvolution/ComputeConvolutionApplication.cs b/examples/ComputeConvolution/ComputeConvolution/ComputeConvolutionApplication.cs
index ee9c964..bbd8a65 100644
--- a/examples/ComputeConvolution/ComputeConvolution/ComputeConvolutionApplication.cs
+++ b/examples/ComputeConvolution/ComputeConvolution/ComputeConvolutionApplication.cs
@@ -1,6 +1,8 @@
using System;
using EngineKit;
+using EngineKit.Core;
using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using EngineKit.Input;
using EngineKit.Native.Glfw;
using ImGuiNET;
@@ -28,21 +30,25 @@ public ComputeConvolutionApplication(
ILogger logger,
IOptions windowSettings,
IOptions contextSettings,
+ IMessageBus messageBus,
IApplicationContext applicationContext,
ICapabilities capabilities,
IMetrics metrics,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
+ IRenderer renderer,
IUIRenderer uiRenderer)
: base(
logger,
windowSettings,
contextSettings,
+ messageBus,
applicationContext,
capabilities,
metrics,
inputProvider,
graphicsContext,
+ renderer,
uiRenderer)
{
_logger = logger;
@@ -130,7 +136,7 @@ protected override void OnUpdate(float deltaTime, float elapsedSeconds)
private void RenderUi()
{
UIRenderer.BeginLayout();
- ImGui.DockSpaceOverViewport(null, ImGuiDockNodeFlags.PassthruCentralNode);
+ ImGui.DockSpaceOverViewport(0, null, ImGuiDockNodeFlags.PassthruCentralNode);
if (ImGui.BeginMainMenuBar())
{
if (ImGui.BeginMenuBar())
@@ -172,7 +178,7 @@ private bool LoadPipelines()
.WithVertexAttributesFromDescriptor(new VertexInputDescriptorBuilder()
.AddAttribute(0, Format.R32G32B32Float, 0)
.AddAttribute(0, Format.R32G32Float, 12)
- .Build(nameof(VertexPositionUv)))
+ .Build(nameof(GpuVertexPositionUv)))
.WithTopology(PrimitiveTopology.Triangles)
.WithFaceWinding(FaceWinding.Clockwise)
.WithCullingEnabled(CullMode.Back)
@@ -200,7 +206,7 @@ private bool LoadResources()
var skyboxTextureCreateDescriptor = new TextureCreateDescriptor
{
- ImageType = ImageType.TextureCube,
+ TextureType = TextureType.TextureCube,
Format = Format.R16G16B16A16Float,
Label = "ConvolvedSkybox",
Size = new Int3(_skyboxTexture!.TextureCreateDescriptor.Size.X, _skyboxTexture.TextureCreateDescriptor.Size.Y, 1),
@@ -280,7 +286,7 @@ private bool LoadSkybox(string skyboxName)
{
var skyboxTextureCreateDescriptor = new TextureCreateDescriptor
{
- ImageType = ImageType.TextureCube,
+ TextureType = TextureType.TextureCube,
Format = Format.R8G8B8A8UNorm,
Label = $"Skybox_{skyboxName}",
Size = new Int3(image.Width, image.Height, 1),
diff --git a/examples/ComputeConvolution/ComputeConvolution/Program.cs b/examples/ComputeConvolution/ComputeConvolution/Program.cs
index 0a99f7a..c3959f9 100644
--- a/examples/ComputeConvolution/ComputeConvolution/Program.cs
+++ b/examples/ComputeConvolution/ComputeConvolution/Program.cs
@@ -31,7 +31,7 @@ private static ServiceProvider CreateServiceProvider()
services.AddSingleton(Log.Logger);
services.Configure(configuration.GetSection(nameof(WindowSettings)));
services.Configure(configuration.GetSection(nameof(ContextSettings)));
- services.AddEngine();
+ services.AddEngineKit();
services.AddSingleton();
return services.BuildServiceProvider();
}
diff --git a/examples/DeferredRendering/DeferredRendering/DeferredRendering.csproj b/examples/DeferredRendering/DeferredRendering/DeferredRendering.csproj
index ab3fd23..5828f93 100644
--- a/examples/DeferredRendering/DeferredRendering/DeferredRendering.csproj
+++ b/examples/DeferredRendering/DeferredRendering/DeferredRendering.csproj
@@ -6,17 +6,16 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
diff --git a/examples/DeferredRendering/DeferredRendering/DeferredRenderingApplication.cs b/examples/DeferredRendering/DeferredRendering/DeferredRenderingApplication.cs
index f9c66db..c9df133 100644
--- a/examples/DeferredRendering/DeferredRendering/DeferredRenderingApplication.cs
+++ b/examples/DeferredRendering/DeferredRendering/DeferredRenderingApplication.cs
@@ -4,7 +4,10 @@
using System.Linq;
using System.Numerics;
using EngineKit;
+using EngineKit.Core;
using EngineKit.Graphics;
+using EngineKit.Graphics.Assets;
+using EngineKit.Graphics.RHI;
using EngineKit.Input;
using EngineKit.Native.Glfw;
using EngineKit.Native.OpenGL;
@@ -64,11 +67,13 @@ public DeferredRenderingApplication(
ILogger logger,
IOptions windowSettings,
IOptions contextSettings,
+ IMessageBus messageBus,
IApplicationContext applicationContext,
ICapabilities capabilities,
IMetrics metrics,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
+ IRenderer renderer,
IUIRenderer uiRenderer,
ICamera camera,
IMeshLoader meshLoader,
@@ -77,11 +82,13 @@ public DeferredRenderingApplication(
logger,
windowSettings,
contextSettings,
+ messageBus,
applicationContext,
capabilities,
metrics,
inputProvider,
graphicsContext,
+ renderer,
uiRenderer)
{
_logger = logger;
@@ -174,7 +181,7 @@ protected override void OnRender(float deltaTime, float elapsedSeconds)
_gBufferGraphicsPipeline!.BindAsUniformBuffer(_gpuCameraConstantsBuffer, 0, Offset.Zero, SizeInBytes.Whole);
_gBufferGraphicsPipeline.BindAsShaderStorageBuffer(_gpuModelMeshInstanceBuffer, 1, Offset.Zero, SizeInBytes.Whole);
_gBufferGraphicsPipeline.BindAsShaderStorageBuffer(_gpuMaterialBuffer!, 2, Offset.Zero, SizeInBytes.Whole);
- _gBufferGraphicsPipeline.BindAsVertexBuffer(_gpuVertexBuffer!, 0, VertexPositionNormalUvTangent.Stride, Offset.Zero);
+ _gBufferGraphicsPipeline.BindAsVertexBuffer(_gpuVertexBuffer!, 0, GpuVertexPositionNormalUvTangent.Stride, Offset.Zero);
_gBufferGraphicsPipeline.BindAsIndexBuffer(_gpuIndexBuffer!);
for (var i = 0; i < _drawCommands.Count; i++)
@@ -198,8 +205,8 @@ protected override void OnRender(float deltaTime, float elapsedSeconds)
GraphicsContext.BeginRenderPass(_swapchainDescriptor);
GraphicsContext.BlitFramebufferToSwapchain(
- _applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y,
+ _applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y,
_applicationContext.WindowFramebufferSize.X,
_applicationContext.WindowFramebufferSize.Y);
@@ -433,25 +440,25 @@ private void CreateSamplers()
private void CreateResolutionDependentResources()
{
- _gBufferBaseColorTexture = GraphicsContext.CreateTexture2D(_applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y, Format.R8G8B8A8UNorm, "BaseColor");
- _gBufferNormalTexture = GraphicsContext.CreateTexture2D(_applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y, Format.R16G16B16Float, "Normals");
- _gBufferDepthTexture = GraphicsContext.CreateTexture2D(_applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y, Format.D32UNorm, "Depth");
+ _gBufferBaseColorTexture = GraphicsContext.CreateTexture2D(_applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y, Format.R8G8B8A8UNorm, "BaseColor");
+ _gBufferNormalTexture = GraphicsContext.CreateTexture2D(_applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y, Format.R16G16B16Float, "Normals");
+ _gBufferDepthTexture = GraphicsContext.CreateTexture2D(_applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y, Format.D32UNorm, "Depth");
_gBufferFramebufferDescriptor = GraphicsContext.GetFramebufferDescriptorBuilder()
.WithColorAttachment(_gBufferBaseColorTexture, true, Colors.DarkSlateBlue)
.WithColorAttachment(_gBufferNormalTexture, true, Vector4.Zero)
.WithDepthAttachment(_gBufferDepthTexture, true)
- .WithViewport(_applicationContext.WindowScaledFramebufferSize.X, _applicationContext.WindowScaledFramebufferSize.Y)
+ .WithViewport(_applicationContext.ScaledWindowFramebufferSize.X, _applicationContext.ScaledWindowFramebufferSize.Y)
.Build("GBuffer");
- _finalTexture = GraphicsContext.CreateTexture2D(_applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y, Format.R8G8B8A8UNorm, "Final");
+ _finalTexture = GraphicsContext.CreateTexture2D(_applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y, Format.R8G8B8A8UNorm, "Final");
_finalFramebufferDescriptor = GraphicsContext.GetFramebufferDescriptorBuilder()
.WithColorAttachment(_finalTexture, true, new Vector4(0.2f, 0.2f, 0.2f, 1.0f))
- .WithViewport(_applicationContext.WindowScaledFramebufferSize.X, _applicationContext.WindowScaledFramebufferSize.Y)
+ .WithViewport(_applicationContext.ScaledWindowFramebufferSize.X, _applicationContext.ScaledWindowFramebufferSize.Y)
.Build("Final");
}
diff --git a/examples/DeferredRendering/DeferredRendering/Program.cs b/examples/DeferredRendering/DeferredRendering/Program.cs
index 35bd4c0..04030c3 100644
--- a/examples/DeferredRendering/DeferredRendering/Program.cs
+++ b/examples/DeferredRendering/DeferredRendering/Program.cs
@@ -33,7 +33,7 @@ private static ServiceProvider CreateServiceProvider()
services.AddSingleton(Log.Logger);
services.Configure(configuration.GetSection(nameof(WindowSettings)));
services.Configure(configuration.GetSection(nameof(ContextSettings)));
- services.AddEngine();
+ services.AddEngineKit();
services.AddSingleton(provider => new Camera(
provider.GetRequiredService(),
provider.GetRequiredService(), new Vector3(0, 0, 10), Vector3.UnitY));
diff --git a/examples/ForwardRendering/ForwardRendering/ForwardRenderer.cs b/examples/ForwardRendering/ForwardRendering/ForwardRenderer.cs
new file mode 100644
index 0000000..222ad2e
--- /dev/null
+++ b/examples/ForwardRendering/ForwardRendering/ForwardRenderer.cs
@@ -0,0 +1,394 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Numerics;
+using EngineKit;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
+using EngineKit.Graphics;
+using EngineKit.Graphics.Assets;
+using EngineKit.Graphics.RHI;
+using EngineKit.Mathematics;
+using EngineKit.UI;
+using ImGuiNET;
+using Serilog;
+
+namespace ForwardRendering;
+
+internal class ForwardRenderer : IRenderer
+{
+ private readonly ILogger _logger;
+ private readonly IGraphicsContext _graphicsContext;
+ private readonly IApplicationContext _applicationContext;
+ private readonly IMessageBus _messageBus;
+ private readonly ICapabilities _capabilities;
+ private readonly IMetrics _metrics;
+ private readonly ICamera _camera;
+ private readonly IMeshLoader _meshLoader;
+ private readonly IUIRenderer _uiRenderer;
+
+ private IGraphicsPipeline? _sceneGraphicsPipeline;
+
+ private GpuConstants _gpuConstants;
+ private IBuffer? _gpuConstantsBuffer;
+ private IBuffer? _gpuModelMeshInstanceBuffer;
+ private IBuffer? _gpuMaterialBuffer;
+
+ private IBuffer? _skullVertexBuffer;
+ private IBuffer? _skullIndexBuffer;
+
+ private ISampler? _linearMipmapNearestSampler;
+ private ISampler? _linearMipmapLinear;
+
+ private readonly List _modelMeshes;
+ private List _gpuModelMeshInstances;
+ private readonly List _gpuIndirectElements;
+ private IBuffer? _gpuIndirectElementDataBuffer;
+
+ private readonly List _modelMeshInstances;
+ private readonly List _gpuMaterials;
+
+ private ITexture? _skullBaseColorTexture;
+
+ private SwapchainDescriptor _swapchainDescriptor;
+
+ public ForwardRenderer(ILogger logger,
+ IGraphicsContext graphicsContext,
+ IApplicationContext applicationContext,
+ IMessageBus messageBus,
+ ICapabilities capabilities,
+ IMetrics metrics,
+ ICamera camera,
+ IMeshLoader meshLoader,
+ IUIRenderer uiRenderer)
+ {
+ _logger = logger.ForContext();
+ _graphicsContext = graphicsContext;
+ _applicationContext = applicationContext;
+ _messageBus = messageBus;
+ _capabilities = capabilities;
+ _metrics = metrics;
+ _camera = camera;
+ _meshLoader = meshLoader;
+ _uiRenderer = uiRenderer;
+
+ _gpuConstants = new GpuConstants();
+ _gpuMaterials = new List();
+ _modelMeshes = new List();
+ _modelMeshInstances = new List();
+ _gpuModelMeshInstances = new List();
+ _gpuIndirectElements = new List();
+ }
+
+ public void Dispose()
+ {
+ _linearMipmapNearestSampler?.Dispose();
+ _linearMipmapLinear?.Dispose();
+ _skullBaseColorTexture?.Dispose();
+ _skullVertexBuffer?.Dispose();
+ _skullIndexBuffer?.Dispose();
+ _sceneGraphicsPipeline?.Dispose();
+ _gpuConstantsBuffer?.Dispose();
+ _gpuMaterialBuffer?.Dispose();
+ _gpuModelMeshInstanceBuffer?.Dispose();
+ }
+
+ public bool Load()
+ {
+ if (!LoadMeshes())
+ {
+ return false;
+ }
+
+ if (!LoadResources())
+ {
+ return false;
+ }
+
+ if (!LoadRenderDescriptors())
+ {
+ return false;
+ }
+
+ if (!LoadPipelines())
+ {
+ return false;
+ }
+
+ _modelMeshInstances.Add(new ModelMeshInstance
+ {
+ ModelMesh = _modelMeshes.First(),
+ World = Matrix4x4.CreateTranslation(-5, 0, 0)
+ });
+ _modelMeshInstances.Add(new ModelMeshInstance
+ {
+ ModelMesh = _modelMeshes.First(),
+ World = Matrix4x4.CreateTranslation(0, 0, 0)
+ });
+ _modelMeshInstances.Add(new ModelMeshInstance
+ {
+ ModelMesh = _modelMeshes.First(),
+ World = Matrix4x4.CreateTranslation(+5, 0, 0)
+ });
+ _gpuMaterials.Add(new GpuMaterial
+ {
+ BaseColor = new Vector4(1.1f, 0.2f, 0.3f, 1.0f),
+ BaseColorTextureHandle = _skullBaseColorTexture!.TextureHandle
+ });
+ _gpuMaterials.Add(new GpuMaterial
+ {
+ BaseColor = new Vector4(0.2f, 0.3f, 1.5f, 1.0f),
+ BaseColorTextureHandle = _skullBaseColorTexture.TextureHandle
+ });
+ _gpuMaterials.Add(new GpuMaterial
+ {
+ BaseColor = new Vector4(0.3f, 1.4f, 0.5f, 1.0f),
+ BaseColorTextureHandle = _skullBaseColorTexture.TextureHandle
+ });
+
+ _gpuConstantsBuffer = _graphicsContext.CreateTypedBuffer("Camera", 1, BufferStorageFlags.DynamicStorage);
+ _gpuMaterialBuffer = _graphicsContext.CreateTypedBuffer("Materials", (uint)_gpuMaterials.Count, BufferStorageFlags.DynamicStorage);
+ _gpuMaterialBuffer.UpdateElements(_gpuMaterials.ToArray(), 0);
+
+ _gpuModelMeshInstanceBuffer =
+ _graphicsContext.CreateTypedBuffer("ModelMeshInstances", 3, BufferStorageFlags.DynamicStorage);
+ _gpuIndirectElementDataBuffer =
+ _graphicsContext.CreateTypedBuffer("MeshIndirectDrawElement", 3,
+ BufferStorageFlags.DynamicStorage);
+ return true;
+ }
+
+ public void Render(float deltaTime,
+ float elapsedTime)
+ {
+ _gpuModelMeshInstances = _modelMeshInstances.Select((mm,
+ index) =>
+ {
+ var rotationMatrix = index switch
+ {
+ 0 => Matrix4x4.CreateRotationX(1.0f * elapsedTime),
+ 1 => Matrix4x4.CreateRotationZ(0.5f * elapsedTime),
+ 2 => Matrix4x4.CreateRotationY(2.0f * elapsedTime),
+ _ => Matrix4x4.Identity
+ };
+
+ return new GpuModelMeshInstance
+ {
+ World = rotationMatrix * mm.World
+ };
+ }).ToList();
+ _gpuModelMeshInstanceBuffer!.UpdateElements(_gpuModelMeshInstances.ToArray(), 0);
+
+ _gpuIndirectElements.Clear();
+ foreach (var modelMeshInstance in _modelMeshInstances)
+ {
+ var gpuIndirectElement = new GpuDrawElementIndirectCommand
+ {
+ IndexCount = (uint)modelMeshInstance.ModelMesh.IndexCount,
+ BaseInstance = 0,
+ BaseVertex = (uint)modelMeshInstance.ModelMesh.VertexOffset,
+ FirstIndex = (uint)modelMeshInstance.ModelMesh.IndexOffset,
+ InstanceCount = 1
+ };
+ _gpuIndirectElements.Add(gpuIndirectElement);
+ }
+
+ _gpuIndirectElementDataBuffer!.UpdateElements(_gpuIndirectElements.ToArray(), 0);
+
+ _gpuConstants.ViewProjection = _camera.ViewMatrix * _camera.ProjectionMatrix;
+ _gpuConstantsBuffer!.UpdateElement(_gpuConstants, 0);
+
+ _graphicsContext.BeginRenderPass(_swapchainDescriptor);
+ _graphicsContext.BindGraphicsPipeline(_sceneGraphicsPipeline!);
+ _sceneGraphicsPipeline!.BindAsVertexBuffer(_skullVertexBuffer!, 0, GpuVertexPositionNormalUvTangent.Stride, 0);
+ _sceneGraphicsPipeline.BindAsIndexBuffer(_skullIndexBuffer!);
+
+ _sceneGraphicsPipeline.BindAsUniformBuffer(_gpuConstantsBuffer, 0, Offset.Zero, SizeInBytes.Whole);
+ _sceneGraphicsPipeline.BindAsShaderStorageBuffer(_gpuModelMeshInstanceBuffer!, 1, Offset.Zero, SizeInBytes.Whole);
+ _sceneGraphicsPipeline.BindAsShaderStorageBuffer(_gpuMaterialBuffer!, 2, Offset.Zero, SizeInBytes.Whole);
+ _sceneGraphicsPipeline.BindSampledTexture(_linearMipmapLinear!, _skullBaseColorTexture!, 0);
+
+ _sceneGraphicsPipeline.MultiDrawElementsIndirect(_gpuIndirectElementDataBuffer, (uint)_gpuIndirectElements.Count);
+
+ _graphicsContext.EndRenderPass();
+ }
+
+ public void RenderUi(float deltaTime,
+ float elapsedTime)
+ {
+ if (ImGui.BeginMainMenuBar())
+ {
+ if (ImGui.BeginMenuBar())
+ {
+ if (ImGui.BeginMenu("File"))
+ {
+ if (ImGui.MenuItem("Quit"))
+ {
+ _messageBus.PublishWait(new CloseWindowMessage());
+ }
+
+ ImGui.EndMenu();
+ }
+
+ var isNvidia = _capabilities.SupportsNvx;
+ if (isNvidia)
+ {
+ ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 416, 0));
+ ImGui.TextUnformatted($"video memory: {_capabilities.GetCurrentAvailableGpuMemoryInMebiBytes()} MiB");
+ ImGui.SameLine();
+ }
+ else
+ {
+ ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 256, 0));
+ }
+
+ ImGui.TextUnformatted($"avg frame time: {_metrics.AverageFrameTime:F2} ms");
+ ImGui.SameLine();
+ ImGui.Button(MaterialDesignIcons.WindowMinimize);
+ ImGui.SameLine();
+ if (ImGui.Button(_applicationContext.IsWindowMaximized
+ ? MaterialDesignIcons.WindowRestore
+ : MaterialDesignIcons.WindowMaximize))
+ {
+ if (_applicationContext.IsWindowMaximized)
+ {
+ _messageBus.PublishWait(new RestoreWindowMessage());
+ }
+ else
+ {
+ _messageBus.PublishWait(new MaximizeWindowMessage());
+ }
+ }
+
+ ImGui.SameLine();
+ if (ImGui.Button(MaterialDesignIcons.WindowClose))
+ {
+ _messageBus.PublishWait(new CloseWindowMessage());
+ }
+
+ ImGui.EndMainMenuBar();
+ }
+
+ if (ImGui.Begin("Debug"))
+ {
+ var sensitivity = _camera.Sensitivity;
+ ImGui.SliderFloat("Camera Sensitivity", ref sensitivity, 0.01f, 1.0f);
+ _camera.Sensitivity = sensitivity;
+
+ ImGui.End();
+ }
+ }
+
+ _uiRenderer.ShowDemoWindow();
+ }
+
+ public void WindowFramebufferResized()
+ {
+ _swapchainDescriptor = _graphicsContext.GetSwapchainDescriptorBuilder()
+ .ClearColor(MathHelper.GammaToLinear(Colors.DarkSlateBlue))
+ .ClearDepth(1.0f)
+ .WithFramebufferSizeAsViewport()
+ .Build("Swapchain");
+ }
+
+ private bool LoadRenderDescriptors()
+ {
+ _swapchainDescriptor = _graphicsContext.GetSwapchainDescriptorBuilder()
+ .ClearColor(MathHelper.GammaToLinear(Colors.DarkSlateBlue))
+ .ClearDepth(1.0f)
+ .WithFramebufferSizeAsViewport()
+ .Build("Swapchain");
+
+ return true;
+ }
+
+ private bool LoadPipelines()
+ {
+ var graphicsPipelineResult = _graphicsContext.CreateGraphicsPipelineBuilder()
+ .WithShadersFromFiles("Shaders/Scene.vs.glsl", "Shaders/Scene.fs.glsl")
+ .WithVertexAttributesFromDescriptor(new VertexInputDescriptorBuilder()
+ .AddAttribute(0, Format.R32G32B32Float, 0)
+ .AddAttribute(0, Format.R32G32B32Float, 12)
+ .AddAttribute(0, Format.R32G32Float, 24)
+ .AddAttribute(0, Format.R32G32B32A32Float, 32)
+ .Build(nameof(GpuVertexPositionNormalUvTangent)))
+ .WithTopology(PrimitiveTopology.Triangles)
+ .WithFaceWinding(FaceWinding.CounterClockwise)
+ .WithCullingEnabled(CullMode.Back)
+ .WithDepthTestEnabled(CompareFunction.Less)
+ .Build("ScenePipeline");
+
+ if (graphicsPipelineResult.IsFailure)
+ {
+ _logger.Error("App: Unable to build graphics pipeline {PipelineName}. {Details}",
+ graphicsPipelineResult.Error, "ScenePipeline");
+ return false;
+ }
+
+ _sceneGraphicsPipeline = graphicsPipelineResult.Value;
+
+ return true;
+ }
+
+ private bool LoadMeshes()
+ {
+ var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
+ var meshDates = _meshLoader
+ .LoadMeshPrimitivesFromFile("Data/Props/Skull/SM_Skull_Optimized_point2.gltf")
+ .ToArray();
+
+ var indexOffset = 0;
+ var vertexOffset = 0;
+ foreach (var meshData in meshDates)
+ {
+ meshData.IndexOffset = indexOffset;
+ meshData.VertexOffset = vertexOffset;
+
+ var obj = new ModelMesh
+ {
+ IndexCount = meshData.IndexCount,
+ IndexOffset = meshData.IndexOffset,
+ VertexCount = meshData.VertexCount,
+ VertexOffset = meshData.VertexOffset,
+ MeshName = meshData.MeshName
+ };
+ _modelMeshes.Add(obj);
+
+ indexOffset += meshData.IndexCount;
+ vertexOffset += meshData.VertexCount;
+ }
+
+ _skullVertexBuffer = _graphicsContext.CreateVertexBuffer("SkullVertices", meshDates);
+ _skullIndexBuffer = _graphicsContext.CreateIndexBuffer("SkullIndices", meshDates);
+
+ return true;
+ }
+
+ private bool LoadResources()
+ {
+ _skullBaseColorTexture = _graphicsContext.CreateTextureFromFile(
+ "Data/Props/Skull/TD_Checker_Base_Color.png",
+ Format.R8G8B8A8Srgb,
+ true,
+ false,
+ false);
+ if (_skullBaseColorTexture == null)
+ {
+ return false;
+ }
+
+ _linearMipmapNearestSampler = _graphicsContext.CreateSamplerBuilder()
+ .WithInterpolationFilter(TextureInterpolationFilter.Linear)
+ .WithMipmapFilter(TextureMipmapFilter.LinearMipmapNearest)
+ .WithAddressMode(TextureAddressMode.Repeat)
+ .Build("LinearMipmapNearest");
+
+ _linearMipmapLinear = _graphicsContext.CreateSamplerBuilder()
+ .WithInterpolationFilter(TextureInterpolationFilter.Linear)
+ .WithMipmapFilter(TextureMipmapFilter.LinearMipmapLinear)
+ .Build("LinearMipmapLinear");
+
+ return true;
+ }
+}
diff --git a/examples/ForwardRendering/ForwardRendering/ForwardRendererApplication.cs b/examples/ForwardRendering/ForwardRendering/ForwardRendererApplication.cs
index 65343da..259e93d 100644
--- a/examples/ForwardRendering/ForwardRendering/ForwardRendererApplication.cs
+++ b/examples/ForwardRendering/ForwardRendering/ForwardRendererApplication.cs
@@ -1,15 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Numerics;
using EngineKit;
+using EngineKit.Core;
using EngineKit.Graphics;
using EngineKit.Input;
using EngineKit.Mathematics;
using EngineKit.Native.Glfw;
-using EngineKit.UI;
-using ImGuiNET;
using Microsoft.Extensions.Options;
using Serilog;
@@ -18,73 +12,36 @@ namespace ForwardRendering;
internal sealed class ForwardRendererApplication : GraphicsApplication
{
private readonly ILogger _logger;
- private readonly IApplicationContext _applicationContext;
- private readonly ICapabilities _capabilities;
- private readonly IMetrics _metrics;
- private readonly IMeshLoader _meshLoader;
private readonly ICamera _camera;
- private readonly List _modelMeshInstances;
- private readonly List _gpuMaterials;
- private ITexture? _skullBaseColorTexture;
- private SwapchainDescriptor _swapchainDescriptor;
-
- private IGraphicsPipeline? _sceneGraphicsPipeline;
-
- private GpuConstants _gpuConstants;
- private IBuffer? _gpuConstantsBuffer;
- private IBuffer? _gpuModelMeshInstanceBuffer;
- private IBuffer? _gpuMaterialBuffer;
-
- private IBuffer? _skullVertexBuffer;
- private IBuffer? _skullIndexBuffer;
-
- private ISampler? _linearMipmapNearestSampler;
- private ISampler? _linearMipmapLinear;
-
- private readonly List _modelMeshes;
- private List _gpuModelMeshInstances;
- private readonly List _gpuIndirectElements;
- private IBuffer? _gpuIndirectElementDataBuffer;
-
- public ForwardRendererApplication(
- ILogger logger,
+ public ForwardRendererApplication(ILogger logger,
IOptions windowSettings,
IOptions contextSettings,
+ IMessageBus messageBus,
IApplicationContext applicationContext,
ICapabilities capabilities,
IMetrics metrics,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
+ IRenderer renderer,
IUIRenderer uiRenderer,
- IMeshLoader meshLoader,
ICamera camera)
: base(
logger,
windowSettings,
contextSettings,
+ messageBus,
applicationContext,
capabilities,
metrics,
inputProvider,
graphicsContext,
+ renderer,
uiRenderer)
{
_logger = logger;
- _applicationContext = applicationContext;
- _capabilities = capabilities;
- _metrics = metrics;
- _meshLoader = meshLoader;
_camera = camera;
-
- _gpuConstants = new GpuConstants();
- _gpuMaterials = new List();
_camera.Sensitivity = 0.125f;
-
- _modelMeshes = new List();
- _modelMeshInstances = new List();
- _gpuModelMeshInstances = new List();
- _gpuIndirectElements = new List();
}
protected override bool OnInitialize()
@@ -107,147 +64,18 @@ protected override bool OnLoad()
return false;
}
- if (!LoadMeshes())
- {
- return false;
- }
-
- if (!LoadResources())
- {
- return false;
- }
-
- if (!LoadRenderDescriptors())
- {
- return false;
- }
-
- if (!LoadPipelines())
- {
- return false;
- }
-
- _gpuConstantsBuffer = GraphicsContext.CreateTypedBuffer("Camera", 1, BufferStorageFlags.DynamicStorage);
-
- _modelMeshInstances.Add(new ModelMeshInstance
- {
- ModelMesh = _modelMeshes.First(),
- World = Matrix4x4.CreateTranslation(-5, 0, 0)
- });
- _modelMeshInstances.Add(new ModelMeshInstance
- {
- ModelMesh = _modelMeshes.First(),
- World = Matrix4x4.CreateTranslation(0, 0, 0)
- });
- _modelMeshInstances.Add(new ModelMeshInstance
- {
- ModelMesh = _modelMeshes.First(),
- World = Matrix4x4.CreateTranslation(+5, 0, 0)
- });
-
- _gpuModelMeshInstanceBuffer = GraphicsContext.CreateTypedBuffer("ModelMeshInstances", 3, BufferStorageFlags.DynamicStorage);
- _gpuIndirectElementDataBuffer = GraphicsContext.CreateTypedBuffer("MeshIndirectDrawElement", 3, BufferStorageFlags.DynamicStorage);
-
- _gpuMaterials.Add(new GpuMaterial
- {
- BaseColor = new Vector4(1.1f, 0.2f, 0.3f, 1.0f),
- BaseColorTextureHandle = _skullBaseColorTexture!.TextureHandle
- });
- _gpuMaterials.Add(new GpuMaterial
- {
- BaseColor = new Vector4(0.2f, 0.3f, 1.5f, 1.0f),
- BaseColorTextureHandle = _skullBaseColorTexture.TextureHandle
- });
- _gpuMaterials.Add(new GpuMaterial
- {
- BaseColor = new Vector4(0.3f, 1.4f, 0.5f, 1.0f),
- BaseColorTextureHandle = _skullBaseColorTexture.TextureHandle
- });
-
- _gpuMaterialBuffer = GraphicsContext.CreateTypedBuffer("Materials", (uint)_gpuMaterials.Count, BufferStorageFlags.DynamicStorage);
- _gpuMaterialBuffer.UpdateElements(_gpuMaterials.ToArray(), 0);
-
_camera.AdvanceSimulation(0.0f);
return true;
}
- protected override void OnRender(float deltaTime, float elapsedSeconds)
- {
- _gpuModelMeshInstances = _modelMeshInstances.Select((mm, index) =>
- {
- var rotationMatrix = index switch
- {
- 0 => Matrix4x4.CreateRotationX(1.0f * elapsedSeconds),
- 1 => Matrix4x4.CreateRotationZ(0.5f * elapsedSeconds),
- 2 => Matrix4x4.CreateRotationY(2.0f * elapsedSeconds),
- _ => Matrix4x4.Identity
- };
-
- return new GpuModelMeshInstance
- {
- World = rotationMatrix * mm.World
- };
- }).ToList();
- _gpuModelMeshInstanceBuffer!.UpdateElements(_gpuModelMeshInstances.ToArray(), 0);
-
- _gpuIndirectElements.Clear();
- foreach (var modelMeshInstance in _modelMeshInstances)
- {
- var gpuIndirectElement = new DrawElementIndirectCommand
- {
- IndexCount = (uint)modelMeshInstance.ModelMesh.IndexCount,
- BaseInstance = 0,
- BaseVertex = (uint)modelMeshInstance.ModelMesh.VertexOffset,
- FirstIndex = (uint)modelMeshInstance.ModelMesh.IndexOffset,
- InstanceCount = 1
- };
- _gpuIndirectElements.Add(gpuIndirectElement);
- }
-
- _gpuIndirectElementDataBuffer!.UpdateElements(_gpuIndirectElements.ToArray(), 0);
-
- _gpuConstants.ViewProjection = _camera.ViewMatrix * _camera.ProjectionMatrix;
- _gpuConstantsBuffer!.UpdateElement(_gpuConstants, 0);
-
- GraphicsContext.BeginRenderPass(_swapchainDescriptor);
- GraphicsContext.BindGraphicsPipeline(_sceneGraphicsPipeline!);
- _sceneGraphicsPipeline!.BindAsVertexBuffer(_skullVertexBuffer!, 0, VertexPositionNormalUvTangent.Stride, 0);
- _sceneGraphicsPipeline.BindAsIndexBuffer(_skullIndexBuffer!);
-
- _sceneGraphicsPipeline.BindAsUniformBuffer(_gpuConstantsBuffer, 0, Offset.Zero, SizeInBytes.Whole);
- _sceneGraphicsPipeline.BindAsShaderStorageBuffer(_gpuModelMeshInstanceBuffer!, 1, Offset.Zero, SizeInBytes.Whole);
- _sceneGraphicsPipeline.BindAsShaderStorageBuffer(_gpuMaterialBuffer!, 2, Offset.Zero, SizeInBytes.Whole);
- _sceneGraphicsPipeline.BindSampledTexture(_linearMipmapLinear!, _skullBaseColorTexture!, 0);
-
- _sceneGraphicsPipeline.MultiDrawElementsIndirect(_gpuIndirectElementDataBuffer, (uint)_gpuIndirectElements.Count);
-
- GraphicsContext.EndRenderPass();
-
- RenderUi();
- }
-
- protected override void OnUnload()
- {
- _linearMipmapNearestSampler?.Dispose();
- _linearMipmapLinear?.Dispose();
- _skullBaseColorTexture?.Dispose();
- _skullVertexBuffer?.Dispose();
- _skullIndexBuffer?.Dispose();
- _sceneGraphicsPipeline?.Dispose();
- _gpuConstantsBuffer?.Dispose();
- _gpuMaterialBuffer?.Dispose();
- _gpuModelMeshInstanceBuffer?.Dispose();
-
- base.OnUnload();
- }
-
protected override void OnHandleDebugger(out bool breakOnError)
{
breakOnError = true;
}
- protected override void OnUpdate(float deltaTime, float elapsedSeconds)
+ protected override void OnUpdate(float deltaTime,
+ float elapsedSeconds)
{
base.OnUpdate(deltaTime, elapsedSeconds);
@@ -255,6 +83,7 @@ protected override void OnUpdate(float deltaTime, float elapsedSeconds)
{
_camera.ProcessMouseMovement();
}
+
_camera.ProcessKeyboard();
if (IsKeyPressed(Glfw.Key.KeyEscape))
@@ -277,177 +106,4 @@ protected override void OnUpdate(float deltaTime, float elapsedSeconds)
ShowCursor();
}
}
-
- protected override void OnWindowResized()
- {
- base.OnWindowResized();
- _swapchainDescriptor = GraphicsContext.GetSwapchainDescriptorBuilder()
- .ClearColor(MathHelper.GammaToLinear(Colors.DarkSlateBlue))
- .ClearDepth(1.0f)
- .WithFramebufferSizeAsViewport()
- .Build("Swapchain");
- }
-
- private void RenderUi()
- {
- UIRenderer.BeginLayout();
- if (ImGui.BeginMainMenuBar())
- {
- if (ImGui.BeginMenuBar())
- {
- if (ImGui.BeginMenu("File"))
- {
- if (ImGui.MenuItem("Quit"))
- {
- Close();
- }
- ImGui.EndMenu();
- }
-
- var isNvidia = _capabilities.SupportsNvx;
- if (isNvidia)
- {
- ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 416, 0));
- ImGui.TextUnformatted($"video memory: {_capabilities.GetCurrentAvailableGpuMemoryInMebiBytes()} MiB");
- ImGui.SameLine();
- }
- else
- {
- ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 256, 0));
- }
-
- ImGui.TextUnformatted($"avg frame time: {_metrics.AverageFrameTime:F2} ms");
- ImGui.SameLine();
- ImGui.Button(MaterialDesignIcons.WindowMinimize);
- ImGui.SameLine();
- if (ImGui.Button(_applicationContext.IsWindowMaximized ? MaterialDesignIcons.WindowRestore : MaterialDesignIcons.WindowMaximize))
- {
- if (_applicationContext.IsWindowMaximized)
- {
- RestoreWindow();
- }
- else
- {
- MaximizeWindow();
- }
- }
- ImGui.SameLine();
- if (ImGui.Button(MaterialDesignIcons.WindowClose))
- {
- Close();
- }
-
- ImGui.EndMainMenuBar();
- }
-
- if (ImGui.Begin("Debug"))
- {
- var sensitivity = _camera.Sensitivity;
- ImGui.SliderFloat("Camera Sensitivity", ref sensitivity, 0.01f, 1.0f);
- _camera.Sensitivity = sensitivity;
-
- ImGui.End();
- }
- }
- UIRenderer.ShowDemoWindow();
- UIRenderer.EndLayout();
- }
-
- private bool LoadRenderDescriptors()
- {
- _swapchainDescriptor = GraphicsContext.GetSwapchainDescriptorBuilder()
- .ClearColor(MathHelper.GammaToLinear(Colors.DarkSlateBlue))
- .ClearDepth(1.0f)
- .WithFramebufferSizeAsViewport()
- .Build("Swapchain");
-
- return true;
- }
-
- private bool LoadPipelines()
- {
- var graphicsPipelineResult = GraphicsContext.CreateGraphicsPipelineBuilder()
- .WithShadersFromFiles("Shaders/Scene.vs.glsl", "Shaders/Scene.fs.glsl")
- .WithVertexAttributesFromDescriptor(new VertexInputDescriptorBuilder()
- .AddAttribute(0, Format.R32G32B32Float, 0)
- .AddAttribute(0, Format.R32G32B32Float, 12)
- .AddAttribute(0, Format.R32G32Float, 24)
- .AddAttribute(0, Format.R32G32B32A32Float, 32)
- .Build(nameof(VertexPositionNormalUvTangent)))
- .WithTopology(PrimitiveTopology.Triangles)
- .WithFaceWinding(FaceWinding.CounterClockwise)
- .WithCullingEnabled(CullMode.Back)
- .WithDepthTestEnabled(CompareFunction.Less)
- .Build("ScenePipeline");
-
- if (graphicsPipelineResult.IsFailure)
- {
- _logger.Error("App: Unable to build graphics pipeline {PipelineName}. {Details}",
- graphicsPipelineResult.Error, "ScenePipeline");
- return false;
- }
-
- _sceneGraphicsPipeline = graphicsPipelineResult.Value;
-
- return true;
- }
-
- private bool LoadMeshes()
- {
- var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
- var meshDates = _meshLoader.LoadMeshPrimitivesFromFile(Path.Combine(baseDirectory, "Data/Props/Skull/SM_Skull_Optimized_point2.gltf")).ToArray();
-
- var indexOffset = 0;
- var vertexOffset = 0;
- foreach (var meshData in meshDates)
- {
- meshData.IndexOffset = indexOffset;
- meshData.VertexOffset = vertexOffset;
-
- var obj = new ModelMesh
- {
- IndexCount = meshData.IndexCount,
- IndexOffset = meshData.IndexOffset,
- VertexCount = meshData.VertexCount,
- VertexOffset = meshData.VertexOffset,
- MeshName = meshData.MeshName
- };
- _modelMeshes.Add(obj);
-
- indexOffset += meshData.IndexCount;
- vertexOffset += meshData.VertexCount;
- }
-
- _skullVertexBuffer = GraphicsContext.CreateVertexBuffer("SkullVertices", meshDates);
- _skullIndexBuffer = GraphicsContext.CreateIndexBuffer("SkullIndices", meshDates);
-
- return true;
- }
-
- private bool LoadResources()
- {
- _skullBaseColorTexture = GraphicsContext.CreateTextureFromFile(
- "Data/Props/Skull/TD_Checker_Base_Color.png",
- Format.R8G8B8A8Srgb,
- true,
- false,
- false);
- if (_skullBaseColorTexture == null)
- {
- return false;
- }
-
- _linearMipmapNearestSampler = GraphicsContext.CreateSamplerBuilder()
- .WithInterpolationFilter(TextureInterpolationFilter.Linear)
- .WithMipmapFilter(TextureMipmapFilter.LinearMipmapNearest)
- .WithAddressMode(TextureAddressMode.Repeat)
- .Build("LinearMipmapNearest");
-
- _linearMipmapLinear = GraphicsContext.CreateSamplerBuilder()
- .WithInterpolationFilter(TextureInterpolationFilter.Linear)
- .WithMipmapFilter(TextureMipmapFilter.LinearMipmapLinear)
- .Build("LinearMipmapLinear");
-
- return true;
- }
}
diff --git a/examples/ForwardRendering/ForwardRendering/ForwardRendering.csproj b/examples/ForwardRendering/ForwardRendering/ForwardRendering.csproj
index 1aea111..0fe96cb 100644
--- a/examples/ForwardRendering/ForwardRendering/ForwardRendering.csproj
+++ b/examples/ForwardRendering/ForwardRendering/ForwardRendering.csproj
@@ -6,17 +6,16 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
diff --git a/examples/ForwardRendering/ForwardRendering/Program.cs b/examples/ForwardRendering/ForwardRendering/Program.cs
index 69b469d..57d64e1 100644
--- a/examples/ForwardRendering/ForwardRendering/Program.cs
+++ b/examples/ForwardRendering/ForwardRendering/Program.cs
@@ -1,6 +1,7 @@
using System.Numerics;
using EngineKit;
using EngineKit.Extensions;
+using EngineKit.Graphics;
using EngineKit.Input;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -33,11 +34,12 @@ private static ServiceProvider CreateServiceProvider()
services.AddSingleton(Log.Logger);
services.Configure(configuration.GetSection(nameof(WindowSettings)));
services.Configure(configuration.GetSection(nameof(ContextSettings)));
- services.AddEngine();
+ services.AddEngineKit();
services.AddSingleton(provider => new Camera(
provider.GetRequiredService(),
provider.GetRequiredService(), new Vector3(0, 0, 10), Vector3.UnitY));
services.AddSingleton();
+ services.AddSingleton();
return services.BuildServiceProvider();
}
}
diff --git a/examples/ForwardRendering/ForwardRendering/appsettings.json b/examples/ForwardRendering/ForwardRendering/appsettings.json
index cf5a04b..637c5c7 100644
--- a/examples/ForwardRendering/ForwardRendering/appsettings.json
+++ b/examples/ForwardRendering/ForwardRendering/appsettings.json
@@ -1,31 +1,31 @@
{
- "Serilog": {
- "Using": [
- "Serilog.Sinks.Console"
- ],
- "MinimumLevel": "Debug",
- "WriteTo": [
- {
- "Name": "Console"
- }
- ],
- "Enrich": [
- "FromLogContext"
- ],
- "Properties": {
- "Application": "ForwardRendering"
+ "Serilog": {
+ "Using": [
+ "Serilog.Sinks.Console"
+ ],
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "Console"
+ }
+ ],
+ "Enrich": [
+ "FromLogContext"
+ ],
+ "Properties": {
+ "Application": "ForwardRendering"
+ }
+ },
+ "WindowSettings": {
+ "ResolutionWidth": 1920,
+ "ResolutionHeight": 1080,
+ "ResolutionScale": 1.0,
+ "WindowMode": "WindowedBorderless",
+ "IsVsyncEnabled": true,
+ "Title": "ForwardRendering"
+ },
+ "ContextSettings": {
+ "TargetGLVersion": "4.6",
+ "IsDebugContext": true
}
- },
- "WindowSettings": {
- "ResolutionWidth": 1920,
- "ResolutionHeight": 1080,
- "ResolutionScale": 1.0,
- "WindowMode": "WindowedBorderless",
- "IsVsyncEnabled": true,
- "Title": "ForwardRendering"
- },
- "ContextSettings": {
- "TargetGLVersion": "4.6",
- "IsDebugContext": true
- }
-}
\ No newline at end of file
+}
diff --git a/examples/HelloWindow/HelloWindow/HelloWindow.csproj b/examples/HelloWindow/HelloWindow/HelloWindow.csproj
index 8a7a445..3c250b1 100644
--- a/examples/HelloWindow/HelloWindow/HelloWindow.csproj
+++ b/examples/HelloWindow/HelloWindow/HelloWindow.csproj
@@ -11,12 +11,11 @@
-
-
-
-
-
-
+
+
+
+
+
diff --git a/examples/HelloWindow/HelloWindow/HelloWindowApplication.cs b/examples/HelloWindow/HelloWindow/HelloWindowApplication.cs
index b2b3e55..14041cb 100644
--- a/examples/HelloWindow/HelloWindow/HelloWindowApplication.cs
+++ b/examples/HelloWindow/HelloWindow/HelloWindowApplication.cs
@@ -1,12 +1,10 @@
-using System.Numerics;
using EngineKit;
+using EngineKit.Core;
using EngineKit.Graphics;
using EngineKit.Input;
using EngineKit.Mathematics;
using EngineKit.Native.Glfw;
using EngineKit.Native.OpenGL;
-using EngineKit.UI;
-using ImGuiNET;
using Microsoft.Extensions.Options;
using Serilog;
@@ -27,20 +25,24 @@ internal sealed class HelloWindowApplication : GraphicsApplication
public HelloWindowApplication(ILogger logger,
IOptions windowSettings,
IOptions contextSettings,
+ IMessageBus messageBus,
IApplicationContext applicationContext,
ICapabilities capabilities,
IMetrics metrics,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
+ IRenderer renderer,
IUIRenderer uiRenderer)
: base(logger,
windowSettings,
contextSettings,
+ messageBus,
applicationContext,
capabilities,
metrics,
inputProvider,
graphicsContext,
+ renderer,
uiRenderer)
{
_logger = logger;
@@ -77,76 +79,6 @@ protected override bool OnLoad()
return true;
}
- protected override void OnRender(float deltaTime,
- float elapsedSeconds)
- {
- GL.Clear(GL.FramebufferBit.ColorBufferBit | GL.FramebufferBit.DepthBufferBit);
-
- UIRenderer.BeginLayout();
- if (ImGui.BeginMainMenuBar())
- {
- if (ImGui.BeginMenuBar())
- {
- if (ImGui.BeginMenu("File"))
- {
- if (ImGui.MenuItem("Quit"))
- {
- Close();
- }
- ImGui.EndMenu();
- }
-
- var isNvidia = _capabilities.SupportsNvx;
- if (isNvidia)
- {
- ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 416, 0));
- ImGui.TextUnformatted($"video memory: {_capabilities.GetCurrentAvailableGpuMemoryInMebiBytes()} MiB");
- ImGui.SameLine();
- }
- else
- {
- ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 256, 0));
- }
-
- ImGui.TextUnformatted($"avg frame time: {_metrics.AverageFrameTime:F2} ms");
- ImGui.SameLine();
- ImGui.Button(MaterialDesignIcons.WindowMinimize);
- ImGui.SameLine();
- if (ImGui.Button(_applicationContext.IsWindowMaximized
- ? MaterialDesignIcons.WindowRestore
- : MaterialDesignIcons.WindowMaximize))
- {
- if (_applicationContext.IsWindowMaximized)
- {
- RestoreWindow();
- }
- else
- {
- MaximizeWindow();
- }
- }
-
- ImGui.SameLine();
- if (ImGui.Button(MaterialDesignIcons.WindowClose))
- {
- Close();
- }
-
- ImGui.EndMenuBar();
- }
-
- ImGui.EndMainMenuBar();
- }
-
- UIRenderer.ShowDemoWindow();
- UIRenderer.EndLayout();
-
- if (_applicationContext.IsLaunchedByNSightGraphicsOnLinux)
- {
- GL.Finish();
- }
- }
-
protected override void OnUnload()
{
base.OnUnload();
@@ -156,6 +88,9 @@ protected override void OnUpdate(float deltaTime,
float elapsedSeconds)
{
base.OnUpdate(deltaTime, elapsedSeconds);
- if (IsKeyPressed(Glfw.Key.KeyEscape)) Close();
+ if (IsKeyPressed(Glfw.Key.KeyEscape))
+ {
+ Close();
+ }
}
}
diff --git a/examples/HelloWindow/HelloWindow/HelloWindowRenderer.cs b/examples/HelloWindow/HelloWindow/HelloWindowRenderer.cs
new file mode 100644
index 0000000..bf88696
--- /dev/null
+++ b/examples/HelloWindow/HelloWindow/HelloWindowRenderer.cs
@@ -0,0 +1,112 @@
+using System.Numerics;
+using EngineKit;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
+using EngineKit.Graphics;
+using EngineKit.Native.OpenGL;
+using EngineKit.UI;
+using ImGuiNET;
+
+namespace HelloWindow;
+
+internal sealed class HelloWindowRenderer : IRenderer
+{
+ private readonly IApplicationContext _applicationContext;
+ private readonly IMessageBus _messageBus;
+ private readonly IUIRenderer _uiRenderer;
+ private readonly ICapabilities _capabilities;
+ private readonly IMetrics _metrics;
+
+ public HelloWindowRenderer(
+ IApplicationContext applicationContext,
+ IMessageBus messageBus,
+ IUIRenderer uiRenderer,
+ ICapabilities capabilities,
+ IMetrics metrics)
+ {
+ _applicationContext = applicationContext;
+ _messageBus = messageBus;
+ _uiRenderer = uiRenderer;
+ _capabilities = capabilities;
+ _metrics = metrics;
+ }
+
+ public void Dispose()
+ {
+ }
+
+ public bool Load()
+ {
+ return true;
+ }
+
+ public void Render(float deltaTime, float elapsedTime)
+ {
+ GL.Clear(GL.FramebufferBit.ColorBufferBit | GL.FramebufferBit.DepthBufferBit);
+ }
+
+ public void RenderUi(float deltaTime,
+ float elapsedTime)
+ {
+ if (ImGui.BeginMainMenuBar())
+ {
+ if (ImGui.BeginMenuBar())
+ {
+ if (ImGui.BeginMenu("File"))
+ {
+ if (ImGui.MenuItem("Quit"))
+ {
+ _messageBus.PublishWait(new CloseWindowMessage());
+ }
+ ImGui.EndMenu();
+ }
+
+ var isNvidia = _capabilities.SupportsNvx;
+ if (isNvidia)
+ {
+ ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 416, 0));
+ ImGui.TextUnformatted($"video memory: {_capabilities.GetCurrentAvailableGpuMemoryInMebiBytes()} MiB");
+ ImGui.SameLine();
+ }
+ else
+ {
+ ImGui.SetCursorPos(new Vector2(ImGui.GetWindowViewport().Size.X - 256, 0));
+ }
+
+ ImGui.TextUnformatted($"avg frame time: {_metrics.AverageFrameTime:F2} ms");
+ ImGui.SameLine();
+ ImGui.Button(MaterialDesignIcons.WindowMinimize);
+ ImGui.SameLine();
+ if (ImGui.Button(_applicationContext.IsWindowMaximized
+ ? MaterialDesignIcons.WindowRestore
+ : MaterialDesignIcons.WindowMaximize))
+ {
+ if (_applicationContext.IsWindowMaximized)
+ {
+ _messageBus.PublishWait(new RestoreWindowMessage());
+ }
+ else
+ {
+ _messageBus.PublishWait(new MaximizeWindowMessage());
+ }
+ }
+
+ ImGui.SameLine();
+ if (ImGui.Button(MaterialDesignIcons.WindowClose))
+ {
+ _messageBus.PublishWait(new CloseWindowMessage());
+ }
+
+ ImGui.EndMenuBar();
+ }
+
+ ImGui.EndMainMenuBar();
+ }
+
+ _uiRenderer.ShowDemoWindow();
+ }
+
+ public void WindowFramebufferResized()
+ {
+ }
+}
diff --git a/examples/HelloWindow/HelloWindow/Program.cs b/examples/HelloWindow/HelloWindow/Program.cs
index 47937f5..7190dc8 100644
--- a/examples/HelloWindow/HelloWindow/Program.cs
+++ b/examples/HelloWindow/HelloWindow/Program.cs
@@ -1,5 +1,6 @@
using EngineKit;
using EngineKit.Extensions;
+using EngineKit.Graphics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
@@ -31,7 +32,8 @@ private static ServiceProvider CreateServiceProvider()
services.AddSingleton(Log.Logger);
services.Configure(configuration.GetSection(nameof(WindowSettings)));
services.Configure(configuration.GetSection(nameof(ContextSettings)));
- services.AddEngine();
+ services.AddEngineKit();
+ services.AddSingleton();
services.AddSingleton();
return services.BuildServiceProvider();
}
diff --git a/src/EngineKit.UnitTests/Buffers/VertexBufferShould.cs b/src/EngineKit.UnitTests/Buffers/VertexBufferShould.cs
index 76cb164..fce72b9 100644
--- a/src/EngineKit.UnitTests/Buffers/VertexBufferShould.cs
+++ b/src/EngineKit.UnitTests/Buffers/VertexBufferShould.cs
@@ -34,18 +34,18 @@ public void BeInstantiable()
public void BeAbleToUpdateDynamicBuffer()
{
// Arrange
- var vertexBuffer = new TypedBuffer("Label", 100);
+ var vertexBuffer = new TypedBuffer("Label", 100);
// Act
- var vertexElements = new VertexPositionNormalUvTangent[]
+ var vertexElements = new GpuVertexPositionNormalUvTangent[]
{
- new VertexPositionNormalUvTangent(),
- new VertexPositionNormalUvTangent()
+ new GpuVertexPositionNormalUvTangent(),
+ new GpuVertexPositionNormalUvTangent()
};
vertexBuffer.UpdateElements(in vertexElements, 0);
// Assert
- vertexBuffer.SizeInBytes.Should().Be(100 * (uint)Marshal.SizeOf());
+ vertexBuffer.SizeInBytes.Should().Be(100 * (uint)Marshal.SizeOf());
_glfwOpenGLDummyWindow.ErrorMessages.Should().HaveCount(0);
}
}
\ No newline at end of file
diff --git a/src/EngineKit.UnitTests/DependenciesShould.cs b/src/EngineKit.UnitTests/DependenciesShould.cs
index cb13e36..6413431 100644
--- a/src/EngineKit.UnitTests/DependenciesShould.cs
+++ b/src/EngineKit.UnitTests/DependenciesShould.cs
@@ -24,7 +24,7 @@ public void Resolve()
.CreateLogger();
services.AddSingleton(configuration);
services.AddSingleton(Log.Logger);
- services.AddEngine();
+ services.AddEngineKit();
var serviceProvider = services.BuildServiceProvider();
// Act
diff --git a/src/EngineKit.UnitTests/EngineKit.UnitTests.csproj b/src/EngineKit.UnitTests/EngineKit.UnitTests.csproj
index bc40c5d..771751a 100644
--- a/src/EngineKit.UnitTests/EngineKit.UnitTests.csproj
+++ b/src/EngineKit.UnitTests/EngineKit.UnitTests.csproj
@@ -1,5 +1,5 @@
-
+
preview
false
@@ -7,26 +7,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/src/EngineKit/Application.cs b/src/EngineKit/Application.cs
index c75ff59..56567a2 100644
--- a/src/EngineKit/Application.cs
+++ b/src/EngineKit/Application.cs
@@ -4,6 +4,9 @@
using System.Numerics;
using System.Runtime.InteropServices;
using System.Threading;
+using System.Threading.Tasks;
+using EngineKit.Core;
+using EngineKit.Core.Messages;
using EngineKit.Input;
using EngineKit.Mathematics;
using EngineKit.Native.Glfw;
@@ -44,14 +47,14 @@ public class Application : IApplication
private readonly FrameTimeAverager _frameTimeAverager;
private long _previousFrameTicks;
- protected Application(
- ILogger logger,
- IOptions windowSettings,
- IOptions contextSettings,
- IApplicationContext applicationContext,
- ICapabilities capabilities,
- IMetrics metrics,
- IInputProvider inputProvider)
+ protected Application(ILogger logger,
+ IOptions windowSettings,
+ IOptions contextSettings,
+ IApplicationContext applicationContext,
+ IMessageBus messageBus,
+ ICapabilities capabilities,
+ IMetrics metrics,
+ IInputProvider inputProvider)
{
_logger = logger.ForContext();
_windowSettings = windowSettings;
@@ -61,7 +64,11 @@ protected Application(
_metrics = metrics;
_inputProvider = inputProvider;
_windowHandle = nint.Zero;
- _frameTimeAverager = new FrameTimeAverager(50);
+ _frameTimeAverager = new FrameTimeAverager(60);
+
+ messageBus.Subscribe(OnMessageCloseWindow);
+ messageBus.Subscribe(OnMessageRestoreWindow);
+ messageBus.Subscribe(OnMessageMaximizeWindow);
}
public void Dispose()
@@ -71,44 +78,47 @@ public void Dispose()
public void Run()
{
- if (!OnInitialize())
+ if(!OnInitialize())
{
return;
}
- if (!Ktx.Init())
+ if(!Ktx.Init())
{
_logger.Debug("{Category}: Unable to initialize Ktx2", "App");
+
return;
}
_logger.Debug("{Category}: Initialized", "App");
- if (!OnLoad())
+ if(!OnLoad())
{
return;
}
_logger.Debug("{Category}: Loaded", "App");
- if (Glfw.IsRawMouseMotionSupported())
+ if(Glfw.IsRawMouseMotionSupported())
{
Glfw.SetInputMode(_windowHandle, Glfw.InputMode.RawMouseMotion, Glfw.True);
}
var stopwatch = Stopwatch.StartNew();
- while (!Glfw.ShouldWindowClose(_windowHandle))
+
+ while(!Glfw.ShouldWindowClose(_windowHandle))
{
var desiredFrameTime = 1000.0 / _applicationContext.DesiredFramerate;
var currentFrameTicks = stopwatch.ElapsedTicks;
var deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);
- while (_applicationContext.IsFrameRateLimited && deltaMilliseconds < desiredFrameTime)
+ while(_applicationContext.IsFrameRateLimited && deltaMilliseconds < desiredFrameTime)
{
Thread.Sleep(0);
currentFrameTicks = stopwatch.ElapsedTicks;
- deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);
+ deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0f / Stopwatch.Frequency);
}
+
_previousFrameTicks = currentFrameTicks;
var deltaSeconds = (float)deltaMilliseconds / 1000.0f;
_frameTimeAverager.AddTime(deltaMilliseconds);
@@ -131,9 +141,8 @@ public void Run()
OnUnload();
Glfw.DestroyWindow(_windowHandle);
-
- _logger.Debug("{Category}: Unloaded", "App");
Glfw.Terminate();
+ _logger.Debug("{Category}: Unloaded", "App");
}
protected void CenterMouseCursor()
@@ -159,16 +168,16 @@ protected void ShowCursor()
}
protected virtual void OnFixedUpdate()
- {
- }
+ { }
protected virtual bool OnInitialize()
{
PrintSystemInformation();
- if (!Glfw.Init())
+ if(!Glfw.Init())
{
_logger.Error("{Category}: Unable to initialize", "Glfw");
+
return false;
}
@@ -183,6 +192,8 @@ protected virtual bool OnInitialize()
Glfw.WindowHint(Glfw.WindowInitHint.IsMaximized, !windowResizable);
Glfw.WindowHint(Glfw.WindowInitHint.IsFloating, !windowResizable);
Glfw.WindowHint(Glfw.WindowInitHint.IsFocused, true);
+
+ Glfw.WindowHint(Glfw.FramebufferInitHint.SrgbCapable, true);
/*
Glfw.WindowHint(Glfw.FramebufferInitHint.RedBits, 10);
Glfw.WindowHint(Glfw.FramebufferInitHint.GreenBits, 10);
@@ -195,31 +206,33 @@ protected virtual bool OnInitialize()
var screenHeight = videoMode.Height;
_applicationContext.DesiredFramerate = videoMode.RefreshRate;
- Glfw.GetMonitorPos(
- monitorHandle,
- out var monitorLeft,
- out var monitorTop);
+ Glfw.GetMonitorPos(monitorHandle,
+ out var monitorLeft,
+ out var monitorTop);
_applicationContext.ScreenSize = new Int2(screenWidth, screenHeight);
+
_applicationContext.WindowSize = windowResizable
- ? new Int2(_windowSettings.Value.ResolutionWidth, _windowSettings.Value.ResolutionHeight)
- : new Int2((int)(screenWidth * 0.9f), (int)(screenHeight * 0.9f));
+ ? new Int2(_windowSettings.Value.ResolutionWidth, _windowSettings.Value.ResolutionHeight)
+ : new Int2((int)(screenWidth * 0.9f), (int)(screenHeight * 0.9f));
- if (!windowResizable)
+ if(!windowResizable)
{
_applicationContext.WindowSize = new Int2(screenWidth, screenHeight);
}
+
monitorHandle = windowResizable || windowSettings.WindowMode == WindowMode.WindowedFullscreen
- ? nint.Zero
- : monitorHandle;
+ ? nint.Zero
+ : monitorHandle;
+
+ var glVersion = new Version(4, 6);
- var glVersion = new Version(4, 5);
- if (!string.IsNullOrEmpty(_contextSettings.Value.TargetGLVersion))
+ if(!string.IsNullOrEmpty(_contextSettings.Value.TargetGLVersion))
{
- if (!Version.TryParse(_contextSettings.Value.TargetGLVersion, out glVersion))
+ if(!Version.TryParse(_contextSettings.Value.TargetGLVersion, out glVersion))
{
- _logger.Error("{Category}: Unable to detect context version. Assuming 4.5", "App");
- glVersion = new Version(4, 5);
+ _logger.Error("{Category}: Unable to detect context version. Assuming 4.6", "App");
+ glVersion = new Version(4, 6);
}
}
@@ -231,39 +244,41 @@ protected virtual bool OnInitialize()
// show MESA overrides - useful for windows on intel iGPU
var environmentVariables = Environment.GetEnvironmentVariables();
- if (environmentVariables.Contains("LIBGL_DEBUG"))
+
+ if(environmentVariables.Contains("LIBGL_DEBUG"))
{
var libGlDebug = environmentVariables["LIBGL_DEBUG"];
_logger.Information("{Category}: LIBGL_DEBUG={LibGlDebug}", "Environment", libGlDebug);
}
- if (environmentVariables.Contains("MESA_GL_VERSION_OVERRIDE"))
+ if(environmentVariables.Contains("MESA_GL_VERSION_OVERRIDE"))
{
var mesaGlVersionOverride = environmentVariables["MESA_GL_VERSION_OVERRIDE"];
_logger.Information("{Category}: MESA_GL_VERSION_OVERRIDE={MesaGlVersionOverride}", "Environment", mesaGlVersionOverride);
}
- if (environmentVariables.Contains("MESA_GLSL_VERSION_OVERRIDE"))
+ if(environmentVariables.Contains("MESA_GLSL_VERSION_OVERRIDE"))
{
var mesaGlslVersionOverride = environmentVariables["MESA_GLSL_VERSION_OVERRIDE"];
_logger.Information("{Category}: MESA_GLSL_VERSION_OVERRIDE={MesaGlVersionOverride}", "Environment", mesaGlslVersionOverride);
}
- _windowHandle = Glfw.CreateWindow(
- _applicationContext.WindowSize.X,
- _applicationContext.WindowSize.Y,
- _windowSettings.Value.Title,
- monitorHandle,
- nint.Zero);
- if (_windowHandle == nint.Zero)
+ _windowHandle = Glfw.CreateWindow(_applicationContext.WindowSize.X,
+ _applicationContext.WindowSize.Y,
+ _windowSettings.Value.Title,
+ monitorHandle,
+ nint.Zero);
+
+ if(_windowHandle == nint.Zero)
{
_logger.Error("{Category}: Unable to create window", "Glfw");
+
return false;
}
Glfw.SwapBuffers(_windowHandle);
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
/* From GLFW: Due to the asynchronous nature of X11, it may take
* a moment for a window to reach its requested state. This means you may not
@@ -277,34 +292,33 @@ protected virtual bool OnInitialize()
Glfw.WaitEventsTimeout(0.25);
}
- if (windowResizable)
+ if(windowResizable)
{
- Glfw.SetWindowPos(
- _windowHandle,
- screenWidth / 2 - _applicationContext.WindowSize.X / 2 + monitorLeft,
- screenHeight / 2 - _applicationContext.WindowSize.Y / 2 + monitorTop);
+ Glfw.SetWindowPos(_windowHandle,
+ screenWidth / 2 - _applicationContext.WindowSize.X / 2 + monitorLeft,
+ screenHeight / 2 - _applicationContext.WindowSize.Y / 2 + monitorTop);
}
else
{
Glfw.SetWindowPos(_windowHandle, monitorLeft, monitorTop);
}
+ Glfw.GetFramebufferSize(_windowHandle,
+ out var framebufferWidth,
+ out var framebufferHeight);
- Glfw.GetFramebufferSize(
- _windowHandle,
- out var framebufferWidth,
- out var framebufferHeight);
_applicationContext.ResizeWindowFramebuffer(framebufferWidth, framebufferHeight);
+ _applicationContext.ResizeSceneView(framebufferWidth, framebufferHeight);
_applicationContext.IsWindowMaximized = false;
- if (Glfw.IsRawMouseMotionSupported())
+ if(Glfw.IsRawMouseMotionSupported())
{
Glfw.SetInputMode(_windowHandle, Glfw.InputMode.RawMouseMotion, Glfw.True);
}
Glfw.MakeContextCurrent(_windowHandle);
- if (!_capabilities.Load())
+ if(!_capabilities.Load())
{
return false;
}
@@ -314,20 +328,17 @@ protected virtual bool OnInitialize()
_logger.Information("{Category}: Version - {Version}", "GL", GL.GetString(GL.StringName.Version));
_logger.Information("{Category}: Shading Language Version - {ShadingLanguageVersion}", "GL", GL.GetString(GL.StringName.ShadingLanguageVersion));
- if (_capabilities.SupportsSwapControl)
- {
- Glfw.SwapInterval(_windowSettings.Value.IsVsyncEnabled ? 1 : -1);
- }
- else
- {
- Glfw.SwapInterval(_windowSettings.Value.IsVsyncEnabled ? 1 : 0);
- }
+ Glfw.SwapInterval(_windowSettings.Value.IsVsyncEnabled
+ ? 1
+ : _capabilities.SupportsSwapControl
+ ? -1
+ : 0);
_applicationContext.IsFrameRateLimited = _windowSettings.Value.IsVsyncEnabled;
- BindCallbacks();
+ BindGlfwCallbacks();
- if (_contextSettings.Value.IsDebugContext && _debugProcCallback != null)
+ if(_contextSettings.Value.IsDebugContext && _debugProcCallback != null)
{
_logger.Debug("{Category}: Debug callback enabled", "GL");
GL.DebugMessageCallback(_debugProcCallback, nint.Zero);
@@ -349,18 +360,18 @@ protected virtual bool OnLoad()
return true;
}
- protected virtual void OnRender(float deltaTime, float elapsedSeconds)
- {
- }
+ protected virtual void OnRender(float deltaTime,
+ float elapsedSeconds)
+ { }
protected virtual void OnUnload()
{
- UnbindCallbacks();
+ UnbindGlfwCallbacks();
}
- protected virtual void OnUpdate(float deltaTime, float elapsedSeconds)
- {
- }
+ protected virtual void OnUpdate(float deltaTime,
+ float elapsedSeconds)
+ { }
protected virtual void OnHandleDebugger(out bool breakOnError)
{
@@ -368,62 +379,43 @@ protected virtual void OnHandleDebugger(out bool breakOnError)
}
protected virtual void OnWindowResized()
- {
- }
+ { }
protected virtual void OnCharacterInput(char codePoint)
- {
- }
+ { }
protected virtual void OnMouseEnter()
- {
- }
+ { }
protected virtual void OnMouseLeave()
- {
- }
+ { }
- protected virtual void OnMouseScrolled(double scrollX, double scrollY)
- {
- }
+ protected virtual void OnMouseScrolled(double scrollX,
+ double scrollY)
+ { }
protected void SetWindowIcon(Image image)
{
unsafe
{
- if (image.DangerousTryGetSinglePixelMemory(out var memory))
+ if(image.DangerousTryGetSinglePixelMemory(out var memory))
{
- Glfw.SetWindowIcon(_windowHandle, new Glfw.Image
- {
- Width = image.Width,
- Height = image.Height,
- PixelPtr = (byte*)memory.Pin().Pointer
- });
+ Glfw.SetWindowIcon(_windowHandle, new Glfw.Image { Width = image.Width, Height = image.Height, PixelPtr = (byte*)memory.Pin().Pointer });
}
}
}
protected void SetWindowIcon(string fileName)
{
- if (!File.Exists(fileName))
+ if(!File.Exists(fileName))
{
_logger.Error("{Category}: Window icon file {FilePath} not found", "App", fileName);
+
return;
}
- unsafe
- {
- using var image = Image.Load(fileName);
- if (image.DangerousTryGetSinglePixelMemory(out var memory))
- {
- Glfw.SetWindowIcon(_windowHandle, new Glfw.Image
- {
- Width = image.Width,
- Height = image.Height,
- PixelPtr = (byte*)memory.Pin().Pointer
- });
- }
- }
+ using var image = Image.Load(fileName);
+ SetWindowIcon(image);
}
protected bool IsKeyPressed(Glfw.Key key)
@@ -455,7 +447,7 @@ protected void RestoreWindow()
_applicationContext.IsWindowMaximized = false;
}
- private void BindCallbacks()
+ private void BindGlfwCallbacks()
{
_debugProcCallback = DebugCallback;
_cursorEnterLeaveCallback = OnMouseEnterLeave;
@@ -477,7 +469,7 @@ private void BindCallbacks()
Glfw.SetCharCallback(_windowHandle, _windowCharCallback);
}
- private void UnbindCallbacks()
+ private void UnbindGlfwCallbacks()
{
_debugProcCallback = null;
Glfw.SetCharCallback(_windowHandle, null);
@@ -491,25 +483,23 @@ private void UnbindCallbacks()
Glfw.SetCharCallback(_windowHandle, null);
}
- private void OnKey(
- nint windowHandle,
- Glfw.Key key,
- Glfw.Scancode scancode,
- Glfw.KeyAction action,
- Glfw.KeyModifiers modifiers)
+ private void OnKey(nint windowHandle,
+ Glfw.Key key,
+ Glfw.Scancode scancode,
+ Glfw.KeyAction action,
+ Glfw.KeyModifiers modifiers)
{
- if (key != Glfw.Key.Unknown)
+ if(key != Glfw.Key.Unknown)
{
_inputProvider.KeyboardState.SetKeyState(key, action is Glfw.KeyAction.Pressed or Glfw.KeyAction.Repeat);
}
}
- private void OnMouseMove(
- nint windowHandle,
- double currentCursorX,
- double currentCursorY)
+ private void OnMouseMove(nint windowHandle,
+ double currentCursorX,
+ double currentCursorY)
{
- if (_isFirstFrame)
+ if(_isFirstFrame)
{
_inputProvider.MouseState.PreviousX = (float)currentCursorX;
_inputProvider.MouseState.PreviousY = (float)currentCursorY;
@@ -526,11 +516,10 @@ private void OnMouseMove(
//_logger.Verbose("{Category}: MouseMove: {MouseState}", "Glfw", _inputProvider.MouseState);
}
- private void OnMouseEnterLeave(
- nint windowHandle,
- Glfw.CursorEnterMode cursorEnterMode)
+ private void OnMouseEnterLeave(nint windowHandle,
+ Glfw.CursorEnterMode cursorEnterMode)
{
- if (cursorEnterMode == Glfw.CursorEnterMode.Entered)
+ if(cursorEnterMode == Glfw.CursorEnterMode.Entered)
{
OnMouseEnter();
}
@@ -540,47 +529,48 @@ private void OnMouseEnterLeave(
}
}
- private void OnMouseButton(
- nint windowHandle,
- Glfw.MouseButton mouseButton,
- Glfw.KeyAction action,
- Glfw.KeyModifiers modifiers)
+ private void OnMouseButton(nint windowHandle,
+ Glfw.MouseButton mouseButton,
+ Glfw.KeyAction action,
+ Glfw.KeyModifiers modifiers)
{
_inputProvider.MouseState[mouseButton] = action is Glfw.KeyAction.Pressed or Glfw.KeyAction.Repeat;
+
_logger.Verbose("{Category}: Button: {MouseButton} Action: {Action} Modifiers: {Modifiers}",
- "Glfw",
- mouseButton,
- action,
- modifiers);
+ "Glfw",
+ mouseButton,
+ action,
+ modifiers);
}
- private void OnMouseScroll(
- nint windowHandle,
- double scrollX,
- double scrollY)
+ private void OnMouseScroll(nint windowHandle,
+ double scrollX,
+ double scrollY)
{
_inputProvider.MouseState.Scroll += new Vector2((float)scrollX, (float)scrollY);
OnMouseScrolled(scrollX, scrollY);
}
- private void OnWindowSize(
- nint windowHandle,
- int width,
- int height)
+ private void OnWindowSize(nint windowHandle,
+ int width,
+ int height)
{
_applicationContext.WindowSize = new Int2(width, height);
OnWindowResized();
}
- private void OnWindowFramebufferSizeChanged(nint windowHandle, int width, int height)
+ private void OnWindowFramebufferSizeChanged(nint windowHandle,
+ int width,
+ int height)
{
- if (width * height != 0)
+ if(width * height != 0)
{
_applicationContext.ResizeWindowFramebuffer(width, height);
}
}
- private void OnInputCharacter(nint windowHandle, uint codePoint)
+ private void OnInputCharacter(nint windowHandle,
+ uint codePoint)
{
OnCharacterInput((char)codePoint);
}
@@ -595,52 +585,78 @@ private void PrintSystemInformation()
_logger.Debug("{Category}: Process Architecture - {@ProcessArchitecture}", "RT", RuntimeInformation.ProcessArchitecture);
}
- private void DebugCallback(
- GL.DebugSource source,
- GL.DebugType type,
- uint id,
- GL.DebugSeverity severity,
- int length,
- nint messagePtr,
- nint userParam)
+ private void DebugCallback(GL.DebugSource source,
+ GL.DebugType type,
+ uint id,
+ GL.DebugSeverity severity,
+ int length,
+ nint messagePtr,
+ nint userParam)
{
- if (type is GL.DebugType.Portability or GL.DebugType.Other or GL.DebugType.PushGroup or GL.DebugType.PopGroup)
+ if(type is GL.DebugType.Portability or GL.DebugType.Other or GL.DebugType.PushGroup or GL.DebugType.PopGroup)
{
return;
}
var message = Marshal.PtrToStringAnsi(messagePtr, length);
- switch (severity)
+ switch(severity)
{
case GL.DebugSeverity.Notification or GL.DebugSeverity.DontCare:
_logger.Debug("{Category}: {@Type} | {@MessageString}", "GL", type, message);
+
break;
case GL.DebugSeverity.High:
_logger.Error("{Category}: {@Type} | {@MessageString}", "GL", type, message);
+
break;
case GL.DebugSeverity.Medium:
_logger.Warning("{Category}: {@Type} | {@MessageString}", "GL", type, message);
+
break;
case GL.DebugSeverity.Low:
_logger.Information("{Category}: {@Type} | {@MessageString}", "GL", type, message);
+
break;
}
- if (type == GL.DebugType.Error)
+ if(type == GL.DebugType.Error)
{
_logger.Error("{@MessageString}", message);
OnHandleDebugger(out var breakOnError);
- if (breakOnError)
+
+ if(breakOnError)
{
Debugger.Break();
}
}
}
- private void ErrorCallback(Glfw.ErrorCode errorCode, string errorDescription)
+ private void ErrorCallback(Glfw.ErrorCode errorCode,
+ string errorDescription)
{
_logger.Error("{Category}: {ErrorCode} - {ErrorDescription}", "Glfw", errorCode, errorDescription);
}
+
+ private Task OnMessageCloseWindow(CloseWindowMessage message)
+ {
+ Close();
+
+ return Task.CompletedTask;
+ }
+
+ private Task OnMessageRestoreWindow(RestoreWindowMessage message)
+ {
+ RestoreWindow();
+
+ return Task.CompletedTask;
+ }
+
+ private Task OnMessageMaximizeWindow(MaximizeWindowMessage message)
+ {
+ MaximizeWindow();
+
+ return Task.CompletedTask;
+ }
}
diff --git a/src/EngineKit/ApplicationContext.cs b/src/EngineKit/ApplicationContext.cs
index aefb923..baeda83 100644
--- a/src/EngineKit/ApplicationContext.cs
+++ b/src/EngineKit/ApplicationContext.cs
@@ -37,13 +37,13 @@ public ApplicationContext(IOptions windowSettings)
public Int2 WindowFramebufferSize { get; private set; }
- public Int2 WindowScaledFramebufferSize { get; private set; }
+ public Int2 ScaledWindowFramebufferSize { get; private set; }
public bool HasWindowFramebufferSizeChanged { get; set; }
public Int2 SceneViewSize { get; private set; }
- public Int2 SceneViewScaledSize { get; private set; }
+ public Int2 ScaledSceneViewSize { get; private set; }
public bool HasSceneViewSizeChanged { get; set; }
@@ -56,7 +56,7 @@ public ApplicationContext(IOptions windowSettings)
public void ResizeWindowFramebuffer(int width, int height)
{
WindowFramebufferSize = new Int2(width, height);
- WindowScaledFramebufferSize = new Int2(new Double2(
+ ScaledWindowFramebufferSize = new Int2(new Double2(
width * _windowSettings.ResolutionScale,
height * _windowSettings.ResolutionScale));
HasWindowFramebufferSizeChanged = true;
@@ -65,7 +65,7 @@ public void ResizeWindowFramebuffer(int width, int height)
public void ResizeSceneView(int width, int height)
{
SceneViewSize = new Int2(width, height);
- SceneViewScaledSize = new Int2(new Double2(
+ ScaledSceneViewSize = new Int2(new Double2(
width * _windowSettings.ResolutionScale,
height * _windowSettings.ResolutionScale));
HasSceneViewSizeChanged = true;
diff --git a/src/EngineKit/Camera.cs b/src/EngineKit/Camera.cs
index bbce93b..934452f 100644
--- a/src/EngineKit/Camera.cs
+++ b/src/EngineKit/Camera.cs
@@ -12,7 +12,7 @@ public sealed class Camera : ICamera
private readonly IInputProvider _inputProvider;
private readonly Vector3 _worldUp;
- private Vector3 _position = Vector3.Zero;
+ private Vector3 _position;
private Vector3 _front;
private Vector3 _up;
private Vector3 _right;
@@ -101,8 +101,8 @@ public Camera(
_aspectRatio = 16.0f / 9.0f;
FieldOfView = 60.0f;
- NearPlane = 0.1f;
- FarPlane = 1024f;
+ NearPlane = 1f;
+ FarPlane = 32768f;
UpdateCameraVectors();
}
@@ -224,7 +224,7 @@ private void UpdateCameraVectorsForPerspective()
NearPlane,
FarPlane);
}
- else if (_cameraMode == CameraMode.PerspectiveInfinity)
+ else if (_cameraMode == CameraMode.InfinitePerspective)
{
ProjectionMatrix = CreateInfiniteReverseZPerspectiveRh(MathHelper.ToRadians(FieldOfView),
_aspectRatio,
@@ -247,8 +247,8 @@ private void UpdateCameraVectorsForOrthogonal()
ViewMatrix = Matrix4x4.CreateLookAt(_position, _position + _front, _up);
ProjectionMatrix = Matrix4x4.CreateOrthographic(
- _applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y,
+ _applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y,
NearPlane,
FarPlane);
}
diff --git a/src/EngineKit/CameraMode.cs b/src/EngineKit/CameraMode.cs
index e55ceae..4f82990 100644
--- a/src/EngineKit/CameraMode.cs
+++ b/src/EngineKit/CameraMode.cs
@@ -3,6 +3,6 @@
public enum CameraMode
{
Perspective,
- PerspectiveInfinity,
+ InfinitePerspective,
Orthogonal
}
\ No newline at end of file
diff --git a/src/EngineKit/Core/Hasher.cs b/src/EngineKit/Core/Hasher.cs
new file mode 100644
index 0000000..936b387
--- /dev/null
+++ b/src/EngineKit/Core/Hasher.cs
@@ -0,0 +1,19 @@
+namespace EngineKit.Core;
+
+public static class HashHelper
+{
+ public static uint XxHash(uint value)
+ {
+ const uint prime32One = 2246822519U;
+ const uint prime32Three = 3266489917U;
+ const uint prime32Four = 668265263U;
+ const uint prime32Five = 374761393U;
+
+ var h32 = value + prime32Five;
+ h32 = prime32Four * ((h32 << 17) | (h32 >> (32 - 17)));
+ h32 = prime32One * (h32 ^ (h32 >> 15));
+ h32 = prime32Three * (h32 ^ (h32 >> 13));
+
+ return h32 ^ (h32 >> 16);
+ }
+}
diff --git a/src/EngineKit/IMessageBus.cs b/src/EngineKit/Core/IMessageBus.cs
similarity index 93%
rename from src/EngineKit/IMessageBus.cs
rename to src/EngineKit/Core/IMessageBus.cs
index 9eb5b68..633be83 100644
--- a/src/EngineKit/IMessageBus.cs
+++ b/src/EngineKit/Core/IMessageBus.cs
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
-namespace EngineKit;
+namespace EngineKit.Core;
public interface IMessageBus
{
diff --git a/src/EngineKit/Label.cs b/src/EngineKit/Core/Label.cs
similarity index 94%
rename from src/EngineKit/Label.cs
rename to src/EngineKit/Core/Label.cs
index 451510c..5096a1d 100644
--- a/src/EngineKit/Label.cs
+++ b/src/EngineKit/Core/Label.cs
@@ -1,4 +1,4 @@
-namespace EngineKit;
+namespace EngineKit.Core;
public readonly struct Label
{
diff --git a/src/EngineKit/MessageBus.cs b/src/EngineKit/Core/MessageBus.cs
similarity index 99%
rename from src/EngineKit/MessageBus.cs
rename to src/EngineKit/Core/MessageBus.cs
index 267c2cb..aa5a236 100644
--- a/src/EngineKit/MessageBus.cs
+++ b/src/EngineKit/Core/MessageBus.cs
@@ -4,7 +4,7 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
-namespace EngineKit;
+namespace EngineKit.Core;
public sealed class MessageBus : IMessageBus
{
@@ -121,4 +121,4 @@ public void PublishWait(TMessage message)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Core/Messages/CloseWindowMessage.cs b/src/EngineKit/Core/Messages/CloseWindowMessage.cs
new file mode 100644
index 0000000..eba9359
--- /dev/null
+++ b/src/EngineKit/Core/Messages/CloseWindowMessage.cs
@@ -0,0 +1,3 @@
+namespace EngineKit.Core.Messages;
+
+public struct CloseWindowMessage;
\ No newline at end of file
diff --git a/src/EngineKit/Messages/MaximizeWindowMessage.cs b/src/EngineKit/Core/Messages/MaximizeWindowMessage.cs
similarity index 51%
rename from src/EngineKit/Messages/MaximizeWindowMessage.cs
rename to src/EngineKit/Core/Messages/MaximizeWindowMessage.cs
index 3ba7123..6a19817 100644
--- a/src/EngineKit/Messages/MaximizeWindowMessage.cs
+++ b/src/EngineKit/Core/Messages/MaximizeWindowMessage.cs
@@ -1,3 +1,3 @@
-namespace EngineKit.Messages;
+namespace EngineKit.Core.Messages;
public struct MaximizeWindowMessage;
\ No newline at end of file
diff --git a/src/EngineKit/Messages/RestoreWindowMessage.cs b/src/EngineKit/Core/Messages/RestoreWindowMessage.cs
similarity index 50%
rename from src/EngineKit/Messages/RestoreWindowMessage.cs
rename to src/EngineKit/Core/Messages/RestoreWindowMessage.cs
index 4040ea4..52da9ad 100644
--- a/src/EngineKit/Messages/RestoreWindowMessage.cs
+++ b/src/EngineKit/Core/Messages/RestoreWindowMessage.cs
@@ -1,3 +1,3 @@
-namespace EngineKit.Messages;
+namespace EngineKit.Core.Messages;
public struct RestoreWindowMessage;
\ No newline at end of file
diff --git a/src/EngineKit/EngineKit.csproj b/src/EngineKit/EngineKit.csproj
index df7f57f..0aaeab0 100644
--- a/src/EngineKit/EngineKit.csproj
+++ b/src/EngineKit/EngineKit.csproj
@@ -3,7 +3,7 @@
true
latest
- true
+
@@ -20,18 +20,18 @@
-
-
-
-
-
-
+
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
+
+
+
@@ -58,4 +58,10 @@
+
+
+
+ ..\..\..\..\..\.nuget\packages\microsoft.extensions.configuration.abstractions\8.0.0\lib\net8.0\Microsoft.Extensions.Configuration.Abstractions.dll
+
+
diff --git a/src/EngineKit/Extensions/FormatExtensions.cs b/src/EngineKit/Extensions/FormatExtensions.cs
index dfd6da8..a0268ab 100644
--- a/src/EngineKit/Extensions/FormatExtensions.cs
+++ b/src/EngineKit/Extensions/FormatExtensions.cs
@@ -1,5 +1,5 @@
using System;
-using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
//using Ktx2Sharp;
using EngineKit.Native.Ktx;
diff --git a/src/EngineKit/Extensions/ServiceCollectionExtensions.cs b/src/EngineKit/Extensions/ServiceCollectionExtensions.cs
index 79bf91d..ac70bac 100644
--- a/src/EngineKit/Extensions/ServiceCollectionExtensions.cs
+++ b/src/EngineKit/Extensions/ServiceCollectionExtensions.cs
@@ -1,7 +1,8 @@
+using EngineKit.Core;
using EngineKit.Graphics;
+using EngineKit.Graphics.Assets;
using EngineKit.Graphics.Shaders;
using EngineKit.Input;
-using EngineKit.MeshLoaders;
using EngineKit.UI;
using Microsoft.Extensions.DependencyInjection;
using SixLabors.ImageSharp;
@@ -10,7 +11,7 @@ namespace EngineKit.Extensions;
public static class ServiceCollectionExtensions
{
- public static void AddEngine(this IServiceCollection services)
+ public static void AddEngineKit(this IServiceCollection services)
{
Configuration.Default.StreamProcessingBufferSize = 16384;
Configuration.Default.PreferContiguousImageBuffers = true;
@@ -29,6 +30,7 @@ public static void AddEngine(this IServiceCollection services)
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
diff --git a/src/EngineKit/Extensions/SharpGltfExtensions.cs b/src/EngineKit/Extensions/SharpGltfExtensions.cs
index 619745e..179906c 100644
--- a/src/EngineKit/Extensions/SharpGltfExtensions.cs
+++ b/src/EngineKit/Extensions/SharpGltfExtensions.cs
@@ -1,7 +1,7 @@
using System;
-using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using SharpGLTF.Schema2;
-using TextureInterpolationFilter = EngineKit.Graphics.TextureInterpolationFilter;
+using TextureInterpolationFilter = EngineKit.Graphics.RHI.TextureInterpolationFilter;
namespace EngineKit.Extensions;
diff --git a/src/EngineKit/Extensions/ToGLExtensions.cs b/src/EngineKit/Extensions/ToGLExtensions.cs
index a6580e1..0f8ac82 100644
--- a/src/EngineKit/Extensions/ToGLExtensions.cs
+++ b/src/EngineKit/Extensions/ToGLExtensions.cs
@@ -1,5 +1,5 @@
using System;
-using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Extensions;
@@ -108,18 +108,18 @@ public static GL.DataType ToGL(this DataType dataType)
};
}
- public static GL.TextureTarget ToGL(this ImageType imageType)
+ public static GL.TextureTarget ToGL(this TextureType textureType)
{
- return imageType switch
+ return textureType switch
{
- ImageType.Texture1D => GL.TextureTarget.Texture1d,
- ImageType.Texture1DArray => GL.TextureTarget.Texture1dArray,
- ImageType.Texture2D => GL.TextureTarget.Texture2d,
- ImageType.Texture2DArray => GL.TextureTarget.Texture2dArray,
- ImageType.TextureCube => GL.TextureTarget.TextureCubeMap,
- ImageType.Texture2DMultisample => GL.TextureTarget.Texture2dMultisample,
- ImageType.Texture2DArrayMultisample => GL.TextureTarget.Texture2dMultisampleArray,
- _ => throw new ArgumentOutOfRangeException(nameof(imageType), imageType, null)
+ TextureType.Texture1D => GL.TextureTarget.Texture1d,
+ TextureType.Texture1DArray => GL.TextureTarget.Texture1dArray,
+ TextureType.Texture2D => GL.TextureTarget.Texture2d,
+ TextureType.Texture2DArray => GL.TextureTarget.Texture2dArray,
+ TextureType.TextureCube => GL.TextureTarget.TextureCubeMap,
+ TextureType.Texture2DMultisample => GL.TextureTarget.Texture2dMultisample,
+ TextureType.Texture2DArrayMultisample => GL.TextureTarget.Texture2dMultisampleArray,
+ _ => throw new ArgumentOutOfRangeException(nameof(textureType), textureType, null)
};
}
diff --git a/src/EngineKit/FrameTimeAverager.cs b/src/EngineKit/FrameTimeAverager.cs
index 0b36d4d..10cacd2 100644
--- a/src/EngineKit/FrameTimeAverager.cs
+++ b/src/EngineKit/FrameTimeAverager.cs
@@ -2,19 +2,20 @@ namespace EngineKit;
internal class FrameTimeAverager
{
- private const double _decayRate = .3;
- private readonly double _timeLimit = 666;
+ private readonly double _decayRate;
+ private readonly double _timeLimit;
private double _accumulatedTime = 0;
private int _frameCount = 0;
public double CurrentAverageFrameTime { get; private set; }
-
- public double CurrentAverageFramesPerSecond { get { return 1000 / CurrentAverageFrameTime; } }
+
+ public double CurrentAverageFramesPerSecond => 1000.0 / CurrentAverageFrameTime;
public FrameTimeAverager(double maxTimeMilliseconds)
{
_timeLimit = maxTimeMilliseconds;
+ _decayRate = 0.3;
}
public void Reset()
@@ -40,4 +41,4 @@ private void Average()
_accumulatedTime = 0;
_frameCount = 0;
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/MeshLoaders/AccessorExtensions.cs b/src/EngineKit/Graphics/Assets/AccessorExtensions.cs
similarity index 92%
rename from src/EngineKit/MeshLoaders/AccessorExtensions.cs
rename to src/EngineKit/Graphics/Assets/AccessorExtensions.cs
index d05c48a..4074f9c 100644
--- a/src/EngineKit/MeshLoaders/AccessorExtensions.cs
+++ b/src/EngineKit/Graphics/Assets/AccessorExtensions.cs
@@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
using SharpGLTF.Schema2;
-namespace EngineKit.MeshLoaders;
+namespace EngineKit.Graphics.Assets;
public static class AccessorExtensions
{
diff --git a/src/EngineKit/Graphics/IImageLoader.cs b/src/EngineKit/Graphics/Assets/IImageLoader.cs
similarity index 91%
rename from src/EngineKit/Graphics/IImageLoader.cs
rename to src/EngineKit/Graphics/Assets/IImageLoader.cs
index 331559d..079b7a6 100644
--- a/src/EngineKit/Graphics/IImageLoader.cs
+++ b/src/EngineKit/Graphics/Assets/IImageLoader.cs
@@ -2,11 +2,11 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Assets;
public interface IImageLoader
{
Image? LoadImageFromFile(string filePath, bool flipVertical = true, bool flipHorizontal = false) where TPixel: IPixel;
Image? LoadImageFromMemory(ReadOnlySpan pixelBytes, bool flipVertical = true, bool flipHorizontal = false) where TPixel : IPixel;
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/IKtxImageLoader.cs b/src/EngineKit/Graphics/Assets/IKtxImageLoader.cs
similarity index 85%
rename from src/EngineKit/Graphics/IKtxImageLoader.cs
rename to src/EngineKit/Graphics/Assets/IKtxImageLoader.cs
index 5a1146b..09ee4cf 100644
--- a/src/EngineKit/Graphics/IKtxImageLoader.cs
+++ b/src/EngineKit/Graphics/Assets/IKtxImageLoader.cs
@@ -1,8 +1,8 @@
using System;
-//using Ktx2Sharp;
using EngineKit.Native.Ktx;
+//using Ktx2Sharp;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Assets;
internal interface IKtxImageLoader
{
diff --git a/src/EngineKit/Graphics/IMeshLoader.cs b/src/EngineKit/Graphics/Assets/IMeshLoader.cs
similarity index 78%
rename from src/EngineKit/Graphics/IMeshLoader.cs
rename to src/EngineKit/Graphics/Assets/IMeshLoader.cs
index 38bd2a1..7cb56a2 100644
--- a/src/EngineKit/Graphics/IMeshLoader.cs
+++ b/src/EngineKit/Graphics/Assets/IMeshLoader.cs
@@ -1,7 +1,8 @@
using System.Collections.Generic;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Assets;
+
public interface IMeshLoader
{
IReadOnlyCollection LoadMeshPrimitivesFromFile(string filePath);
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/KtxImageLoader.cs b/src/EngineKit/Graphics/Assets/KtxImageLoader.cs
similarity index 97%
rename from src/EngineKit/Graphics/KtxImageLoader.cs
rename to src/EngineKit/Graphics/Assets/KtxImageLoader.cs
index 6a99a30..14b693a 100644
--- a/src/EngineKit/Graphics/KtxImageLoader.cs
+++ b/src/EngineKit/Graphics/Assets/KtxImageLoader.cs
@@ -1,10 +1,10 @@
using System;
using System.IO;
-//using Ktx2Sharp;
using EngineKit.Native.Ktx;
using Serilog;
+//using Ktx2Sharp;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Assets;
internal sealed class KtxImageLoader : IKtxImageLoader
{
diff --git a/src/EngineKit/MeshLoaders/SharpGltfMeshLoader.cs b/src/EngineKit/Graphics/Assets/SharpGltfMeshLoader.cs
similarity index 96%
rename from src/EngineKit/MeshLoaders/SharpGltfMeshLoader.cs
rename to src/EngineKit/Graphics/Assets/SharpGltfMeshLoader.cs
index 98703d1..0f9a25c 100644
--- a/src/EngineKit/MeshLoaders/SharpGltfMeshLoader.cs
+++ b/src/EngineKit/Graphics/Assets/SharpGltfMeshLoader.cs
@@ -4,15 +4,12 @@
using System.IO;
using System.Linq;
using System.Numerics;
-using EngineKit.Graphics;
using EngineKit.Mathematics;
using Serilog;
using SharpGLTF.Schema2;
using SharpGLTF.Validation;
-using Material = EngineKit.Graphics.Material;
-using MeshPrimitive = EngineKit.Graphics.MeshPrimitive;
-namespace EngineKit.MeshLoaders;
+namespace EngineKit.Graphics.Assets;
internal sealed class SharpGltfMeshLoader : IMeshLoader
{
@@ -35,12 +32,18 @@ public SharpGltfMeshLoader(
ILogger logger,
IMaterialLibrary materialLibrary)
{
- _logger = logger;
+ _logger = logger.ForContext();
_materialLibrary = materialLibrary;
}
public IReadOnlyCollection LoadMeshPrimitivesFromFile(string filePath)
{
+ if(!File.Exists(filePath))
+ {
+ _logger.Error($"File {filePath} does not exist");
+ return Array.Empty();
+ }
+
var readSettings = new ReadSettings
{
Validation = ValidationMode.Skip,
@@ -99,12 +102,9 @@ public IReadOnlyCollection LoadMeshPrimitivesFromFile(string file
var localModelMatrix = node.WorldMatrix;
var globalModelMatrix = localModelMatrix * globalParentTransform;
- if (node.VisualChildren.Any())
+ foreach (var childNode in node.VisualChildren)
{
- foreach (var childNode in node.VisualChildren)
- {
- nodeStack.Push((childNode, globalModelMatrix));
- }
+ nodeStack.Push((childNode, globalModelMatrix));
}
if (node.Mesh != null)
@@ -308,7 +308,7 @@ private void ProcessNode(List meshPrimitives, Node node, ICollect
for (var i = 0; i < positions.Length; i++)
{
ref var position = ref positions[i];
- ref var normal = ref normals[normals.Length == 1 ? 0 : i];
+ var normal = Vector3.UnitY; //ref normals[normals.Length == 1 ? 0 : i];
var realTangentXyz = new Vector3(realTangents[i].X, realTangents[i].Y, realTangents[i].Z);
var realTangent = new Vector4(realTangentXyz, realTangents[i].W);
diff --git a/src/EngineKit/Graphics/Assets/SharpGltfMeshLoader2.cs b/src/EngineKit/Graphics/Assets/SharpGltfMeshLoader2.cs
new file mode 100644
index 0000000..76ec79a
--- /dev/null
+++ b/src/EngineKit/Graphics/Assets/SharpGltfMeshLoader2.cs
@@ -0,0 +1,35 @@
+namespace EngineKit.Graphics.Assets;
+
+using Serilog;
+using SharpGLTF.Schema2;
+using SharpGLTF.Validation;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using MeshPrimitive = EngineKit.Graphics.MeshPrimitive;
+
+internal sealed class SharpGltfMeshLoader2 : IMeshLoader
+{
+ private readonly ILogger _logger;
+
+ public SharpGltfMeshLoader2(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ public IReadOnlyCollection LoadMeshPrimitivesFromFile(string filePath)
+ {
+ if(!File.Exists(filePath))
+ {
+ _logger.Error($"File {filePath} does not exist");
+
+ return Array.Empty();
+ }
+
+ var readSettings = new ReadSettings { Validation = ValidationMode.Skip, };
+
+ var model = ModelRoot.Load(filePath, readSettings);
+
+ return new List();
+ }
+}
diff --git a/src/EngineKit/Graphics/SixLaborsImageLoader.cs b/src/EngineKit/Graphics/Assets/SixLaborsImageLoader.cs
similarity index 98%
rename from src/EngineKit/Graphics/SixLaborsImageLoader.cs
rename to src/EngineKit/Graphics/Assets/SixLaborsImageLoader.cs
index c5275b2..3b2bb91 100644
--- a/src/EngineKit/Graphics/SixLaborsImageLoader.cs
+++ b/src/EngineKit/Graphics/Assets/SixLaborsImageLoader.cs
@@ -5,7 +5,7 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Assets;
internal sealed class SixLaborsImageLoader : IImageLoader
{
diff --git a/src/EngineKit/Graphics/Buffer.cs b/src/EngineKit/Graphics/Buffer.cs
index 4c169d1..14d37d6 100644
--- a/src/EngineKit/Graphics/Buffer.cs
+++ b/src/EngineKit/Graphics/Buffer.cs
@@ -1,6 +1,8 @@
using System;
using System.Runtime.CompilerServices;
+using EngineKit.Core;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/ClearValue.cs b/src/EngineKit/Graphics/ClearValue.cs
index 77a87a8..27e3d14 100644
--- a/src/EngineKit/Graphics/ClearValue.cs
+++ b/src/EngineKit/Graphics/ClearValue.cs
@@ -2,9 +2,9 @@
public record struct ClearValue
{
- public static ClearValue Zero = new ClearValue(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0);
- public static ClearValue White = new ClearValue(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0);
- public static ClearValue DarkGray = new ClearValue(0.1f, 0.1f, 0.1f, 1.0f, 1.0f, 0);
+ public static readonly ClearValue Zero = new ClearValue(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0);
+ public static readonly ClearValue White = new ClearValue(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0);
+ public static readonly ClearValue DarkGray = new ClearValue(0.1f, 0.1f, 0.1f, 1.0f, 1.0f, 0);
public ClearValue(float x, float y, float z, float w, float depth = 1.0f, int stencil = 0)
{
@@ -39,4 +39,4 @@ public ClearValue(uint x, uint y, uint z, uint w, float depth = 1.0f, int stenci
public ClearColorValue Color { get; }
public ClearDepthStencilValue DepthStencil { get; }
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/ColorBlendAttachmentDescriptor.cs b/src/EngineKit/Graphics/ColorBlendAttachmentDescriptor.cs
index 5034d70..7ccecc5 100644
--- a/src/EngineKit/Graphics/ColorBlendAttachmentDescriptor.cs
+++ b/src/EngineKit/Graphics/ColorBlendAttachmentDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public record struct ColorBlendAttachmentDescriptor(
diff --git a/src/EngineKit/Graphics/ComputePipeline.cs b/src/EngineKit/Graphics/ComputePipeline.cs
index b260885..562aa37 100644
--- a/src/EngineKit/Graphics/ComputePipeline.cs
+++ b/src/EngineKit/Graphics/ComputePipeline.cs
@@ -1,6 +1,6 @@
using System.Numerics;
using EngineKit.Extensions;
-using EngineKit.Graphics.Shaders;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/ComputePipelineBuilder.cs b/src/EngineKit/Graphics/ComputePipelineBuilder.cs
index b192feb..cf06662 100644
--- a/src/EngineKit/Graphics/ComputePipelineBuilder.cs
+++ b/src/EngineKit/Graphics/ComputePipelineBuilder.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using CSharpFunctionalExtensions;
+using EngineKit.Core;
using EngineKit.Graphics.Shaders;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/ComputePipelineDescriptor.cs b/src/EngineKit/Graphics/ComputePipelineDescriptor.cs
index b519911..ed1dd22 100644
--- a/src/EngineKit/Graphics/ComputePipelineDescriptor.cs
+++ b/src/EngineKit/Graphics/ComputePipelineDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Core;
+
namespace EngineKit.Graphics;
internal record struct ComputePipelineDescriptor
diff --git a/src/EngineKit/Graphics/DepthStencilDescriptor.cs b/src/EngineKit/Graphics/DepthStencilDescriptor.cs
index db03396..af74b43 100644
--- a/src/EngineKit/Graphics/DepthStencilDescriptor.cs
+++ b/src/EngineKit/Graphics/DepthStencilDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
internal record struct DepthStencilDescriptor(
diff --git a/src/EngineKit/Graphics/FramebufferDescriptor.cs b/src/EngineKit/Graphics/FramebufferDescriptor.cs
index 5d1650a..2fd9e82 100644
--- a/src/EngineKit/Graphics/FramebufferDescriptor.cs
+++ b/src/EngineKit/Graphics/FramebufferDescriptor.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Linq;
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/DrawElementIndirectCommand.cs b/src/EngineKit/Graphics/GpuDrawElementIndirectCommand.cs
similarity index 87%
rename from src/EngineKit/Graphics/DrawElementIndirectCommand.cs
rename to src/EngineKit/Graphics/GpuDrawElementIndirectCommand.cs
index 0d16e3b..4016eae 100644
--- a/src/EngineKit/Graphics/DrawElementIndirectCommand.cs
+++ b/src/EngineKit/Graphics/GpuDrawElementIndirectCommand.cs
@@ -3,7 +3,7 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = sizeof(uint) * 5)]
-public struct DrawElementIndirectCommand
+public struct GpuDrawElementIndirectCommand
{
public uint IndexCount; // count
diff --git a/src/EngineKit/Graphics/DrawIndirectCommand.cs b/src/EngineKit/Graphics/GpuDrawIndirectCommand.cs
similarity index 75%
rename from src/EngineKit/Graphics/DrawIndirectCommand.cs
rename to src/EngineKit/Graphics/GpuDrawIndirectCommand.cs
index 826623a..010bf28 100644
--- a/src/EngineKit/Graphics/DrawIndirectCommand.cs
+++ b/src/EngineKit/Graphics/GpuDrawIndirectCommand.cs
@@ -1,12 +1,12 @@
namespace EngineKit.Graphics;
-public struct DrawIndirectCommand
+public struct GpuDrawIndirectCommand
{
public uint VertexCount;
-
+
public uint InstanceCount;
-
+
public uint FirstVertex;
-
+
public uint FirstInstance;
-};
\ No newline at end of file
+};
diff --git a/src/EngineKit/Graphics/VertexPosition.cs b/src/EngineKit/Graphics/GpuVertexPosition.cs
similarity index 57%
rename from src/EngineKit/Graphics/VertexPosition.cs
rename to src/EngineKit/Graphics/GpuVertexPosition.cs
index 0a86317..309261f 100644
--- a/src/EngineKit/Graphics/VertexPosition.cs
+++ b/src/EngineKit/Graphics/GpuVertexPosition.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPosition
+public readonly struct GpuVertexPosition
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPosition);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPosition);
- public VertexPosition(Vector3 position)
+ public GpuVertexPosition(Vector3 position)
{
Position = position;
}
diff --git a/src/EngineKit/Graphics/VertexPositionColor.cs b/src/EngineKit/Graphics/GpuVertexPositionColor.cs
similarity index 58%
rename from src/EngineKit/Graphics/VertexPositionColor.cs
rename to src/EngineKit/Graphics/GpuVertexPositionColor.cs
index 1023f83..c651e2c 100644
--- a/src/EngineKit/Graphics/VertexPositionColor.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionColor.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential)]
-public readonly struct VertexPositionColor
+public readonly struct GpuVertexPositionColor
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionColor);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionColor);
- public VertexPositionColor(Vector3 position, Vector3 color)
+ public GpuVertexPositionColor(Vector3 position, Vector3 color)
{
Position = position;
Color = color;
diff --git a/src/EngineKit/Graphics/VertexPositionColorUv.cs b/src/EngineKit/Graphics/GpuVertexPositionColorUv.cs
similarity index 60%
rename from src/EngineKit/Graphics/VertexPositionColorUv.cs
rename to src/EngineKit/Graphics/GpuVertexPositionColorUv.cs
index 5e89fe9..166c3ef 100644
--- a/src/EngineKit/Graphics/VertexPositionColorUv.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionColorUv.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPositionColorUv
+public readonly struct GpuVertexPositionColorUv
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionColorUv);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionColorUv);
- public VertexPositionColorUv(Vector3 position, Vector3 color, Vector2 uv)
+ public GpuVertexPositionColorUv(Vector3 position, Vector3 color, Vector2 uv)
{
Position = position;
Color = color;
diff --git a/src/EngineKit/Graphics/VertexPositionNormal.cs b/src/EngineKit/Graphics/GpuVertexPositionNormal.cs
similarity index 58%
rename from src/EngineKit/Graphics/VertexPositionNormal.cs
rename to src/EngineKit/Graphics/GpuVertexPositionNormal.cs
index b0ffcfc..c654634 100644
--- a/src/EngineKit/Graphics/VertexPositionNormal.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionNormal.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPositionNormal
+public readonly struct GpuVertexPositionNormal
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionNormal);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionNormal);
- public VertexPositionNormal(Vector3 position, Vector3 normal)
+ public GpuVertexPositionNormal(Vector3 position, Vector3 normal)
{
Position = position;
Normal = normal;
diff --git a/src/EngineKit/Graphics/VertexPositionNormalUv.cs b/src/EngineKit/Graphics/GpuVertexPositionNormalUv.cs
similarity index 70%
rename from src/EngineKit/Graphics/VertexPositionNormalUv.cs
rename to src/EngineKit/Graphics/GpuVertexPositionNormalUv.cs
index c5a6dab..e16a5e0 100644
--- a/src/EngineKit/Graphics/VertexPositionNormalUv.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionNormalUv.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPositionNormalUv
+public readonly struct GpuVertexPositionNormalUv
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionNormalUv);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionNormalUv);
- public VertexPositionNormalUv(
+ public GpuVertexPositionNormalUv(
Vector3 position,
Vector3 normal,
Vector2 uv)
diff --git a/src/EngineKit/Graphics/VertexPositionNormalUvTangent.cs b/src/EngineKit/Graphics/GpuVertexPositionNormalUvTangent.cs
similarity index 71%
rename from src/EngineKit/Graphics/VertexPositionNormalUvTangent.cs
rename to src/EngineKit/Graphics/GpuVertexPositionNormalUvTangent.cs
index ccb156b..eb0b40f 100644
--- a/src/EngineKit/Graphics/VertexPositionNormalUvTangent.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionNormalUvTangent.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPositionNormalUvTangent
+public readonly struct GpuVertexPositionNormalUvTangent
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionNormalUvTangent);
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionNormalUvTangent);
- public VertexPositionNormalUvTangent(
+ public GpuVertexPositionNormalUvTangent(
Vector3 position,
Vector3 normal,
Vector2 uv,
diff --git a/src/EngineKit/Graphics/VertexPositionUv.cs b/src/EngineKit/Graphics/GpuVertexPositionUv.cs
similarity index 58%
rename from src/EngineKit/Graphics/VertexPositionUv.cs
rename to src/EngineKit/Graphics/GpuVertexPositionUv.cs
index 151c44f..734c3d6 100644
--- a/src/EngineKit/Graphics/VertexPositionUv.cs
+++ b/src/EngineKit/Graphics/GpuVertexPositionUv.cs
@@ -4,11 +4,11 @@
namespace EngineKit.Graphics;
[StructLayout(LayoutKind.Sequential, Pack = 1)]
-public readonly struct VertexPositionUv
+public readonly struct GpuVertexPositionUv
{
- public static readonly unsafe uint Stride = (uint)sizeof(VertexPositionUv);
-
- public VertexPositionUv(Vector3 position, Vector2 uv)
+ public static readonly unsafe uint Stride = (uint)sizeof(GpuVertexPositionUv);
+
+ public GpuVertexPositionUv(Vector3 position, Vector2 uv)
{
Position = position;
Uv = uv;
@@ -17,4 +17,4 @@ public VertexPositionUv(Vector3 position, Vector2 uv)
public readonly Vector3 Position;
public readonly Vector2 Uv;
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/Context.cs b/src/EngineKit/Graphics/GraphicsContext.cs
similarity index 98%
rename from src/EngineKit/Graphics/Context.cs
rename to src/EngineKit/Graphics/GraphicsContext.cs
index afd9243..9aad8ef 100644
--- a/src/EngineKit/Graphics/Context.cs
+++ b/src/EngineKit/Graphics/GraphicsContext.cs
@@ -3,7 +3,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using EngineKit.Core;
using EngineKit.Extensions;
+using EngineKit.Graphics.Assets;
+using EngineKit.Graphics.RHI;
using EngineKit.Graphics.Shaders;
using EngineKit.Mathematics;
using EngineKit.Native.Ktx;
@@ -184,7 +187,7 @@ public IBuffer CreateVertexBuffer(
MeshPrimitive[] meshPrimitives)
{
var vertexCount = meshPrimitives.Sum(mp => mp.Positions.Count);
- var bufferData = new VertexPositionNormalUvTangent[vertexCount];
+ var bufferData = new GpuVertexPositionNormalUvTangent[vertexCount];
var bufferDataIndex = 0;
foreach (var meshPrimitive in meshPrimitives)
@@ -196,7 +199,7 @@ public IBuffer CreateVertexBuffer(
for (var i = 0; i < meshPrimitive.Positions.Count; ++i)
{
- bufferData[bufferDataIndex++] = new VertexPositionNormalUvTangent(
+ bufferData[bufferDataIndex++] = new GpuVertexPositionNormalUvTangent(
meshPrimitive.Positions[i],
meshPrimitive.Normals[i],
meshPrimitive.Uvs[i],
@@ -204,7 +207,7 @@ public IBuffer CreateVertexBuffer(
}
}
- return new TypedBuffer(label, in bufferData);
+ return new TypedBuffer(label, in bufferData);
}
public IBuffer CreateIndexBuffer(Label label, MeshPrimitive[] meshPrimitives)
@@ -251,7 +254,7 @@ public ITexture CreateTexture2D(
Label = string.IsNullOrEmpty(label) ? $"Texture-{width}x{height}-{format}" : $"Texture-{width}x{height}-{format}-{label}",
ArrayLayers = 0,
MipLevels = 1,
- ImageType = ImageType.Texture2D,
+ TextureType = TextureType.Texture2D,
TextureSampleCount = TextureSampleCount.OneSample
};
return CreateTexture(textureCreateDescriptor);
@@ -364,7 +367,7 @@ public ITexture CreateTexture2D(
var format = Format.R16G16B16A16Float;
var skyboxTextureCreateDescriptor = new TextureCreateDescriptor
{
- ImageType = ImageType.TextureCube,
+ TextureType = TextureType.TextureCube,
Format = format,
Label = string.IsNullOrEmpty(label)
? $"Texture-{image.Width}x{image.Height}-{format}"
@@ -845,7 +848,7 @@ private unsafe ITexture CreateTextureFromKtxTexture(Ktx.KtxTexture* ktxTexture,
{
var textureCreateDescriptor = new TextureCreateDescriptor
{
- ImageType = ImageType.Texture2D,
+ TextureType = TextureType.Texture2D,
Format = ktxTexture->VulkanFormat.ToFormat(),
Label = label,
Size = new Int3((int)ktxTexture->BaseWidth, (int)ktxTexture->BaseHeight, (int)ktxTexture->BaseDepth),
@@ -884,7 +887,7 @@ private ITexture CreateTextureFromImage(Image image, Label label, Format
var calculatedMipLevels = (uint)(1 + MathF.Floor(MathF.Log2(MathF.Min(image.Width, image.Height))));
var textureCreateDescriptor = new TextureCreateDescriptor
{
- ImageType = ImageType.Texture2D,
+ TextureType = TextureType.Texture2D,
Format = format,
Label = label,
Size = new Int3(image.Width, image.Height, 1),
diff --git a/src/EngineKit/Graphics/GraphicsPipeline.cs b/src/EngineKit/Graphics/GraphicsPipeline.cs
index 5e5cb95..f935a68 100644
--- a/src/EngineKit/Graphics/GraphicsPipeline.cs
+++ b/src/EngineKit/Graphics/GraphicsPipeline.cs
@@ -1,6 +1,6 @@
using System.Numerics;
using EngineKit.Extensions;
-using EngineKit.Graphics.Shaders;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
@@ -60,7 +60,7 @@ public void BindAsIndexBuffer(IBuffer indexBuffer)
_currentIndexBuffer = indexBuffer;
}
}
-
+
public void DrawArraysInstanced(
int vertexCount,
int vertexOffset,
@@ -146,7 +146,7 @@ public unsafe void DrawElementsIndirect(
GL.DrawElementsIndirect(
_graphicsPipelineDescriptor.InputAssembly.PrimitiveTopology.ToGL(),
GL.IndexElementType.UnsignedInt,
- indirectElementIndex * sizeof(DrawElementIndirectCommand));
+ indirectElementIndex * sizeof(GpuDrawElementIndirectCommand));
}
public unsafe void MultiDrawElementsIndirect(
@@ -159,7 +159,7 @@ public unsafe void MultiDrawElementsIndirect(
GL.IndexElementType.UnsignedInt,
nint.Zero,
drawCount,
- (uint)sizeof(DrawElementIndirectCommand));
+ (uint)sizeof(GpuDrawElementIndirectCommand));
}
public unsafe void MultiDrawElementsIndirectCount(
@@ -174,31 +174,31 @@ public unsafe void MultiDrawElementsIndirectCount(
GL.IndexElementType.UnsignedInt,
nint.Zero,
maxDrawCount,
- (uint)sizeof(DrawElementIndirectCommand));
+ (uint)sizeof(GpuDrawElementIndirectCommand));
}
-
+
public void VertexUniform(int location, float value)
{
GL.ProgramUniform(ShaderProgram!.VertexShader!.Id, location, value);
}
-
+
public void VertexUniform(int location, int value)
{
GL.ProgramUniform(ShaderProgram!.VertexShader!.Id, location, value);
}
-
+
public void VertexUniform(int location, Vector3 value)
{
GL.ProgramUniform(ShaderProgram!.VertexShader!.Id, location, value);
}
-
+
public void FragmentUniform(int location, float value)
{
GL.ProgramUniform(ShaderProgram!.FragmentShader!.Id, location, value);
}
-
+
public void FragmentUniform(int location, int value)
{
GL.ProgramUniform(ShaderProgram!.FragmentShader!.Id, location, value);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/GraphicsPipelineBuilder.cs b/src/EngineKit/Graphics/GraphicsPipelineBuilder.cs
index 657795f..a0f62c0 100644
--- a/src/EngineKit/Graphics/GraphicsPipelineBuilder.cs
+++ b/src/EngineKit/Graphics/GraphicsPipelineBuilder.cs
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.IO;
using CSharpFunctionalExtensions;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
using EngineKit.Graphics.Shaders;
namespace EngineKit.Graphics;
@@ -273,6 +275,6 @@ public Result Build(Label label)
inputLayout);
_graphicsPipelineCache[graphicsPipeline] = _graphicsPipelineDescriptor;
- return Result.Success(graphicsPipeline);
+ return Result.Success(graphicsPipeline);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/GraphicsPipelineDescriptor.cs b/src/EngineKit/Graphics/GraphicsPipelineDescriptor.cs
index 7380bfa..0ae151a 100644
--- a/src/EngineKit/Graphics/GraphicsPipelineDescriptor.cs
+++ b/src/EngineKit/Graphics/GraphicsPipelineDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Core;
+
namespace EngineKit.Graphics;
internal record struct GraphicsPipelineDescriptor
diff --git a/src/EngineKit/Graphics/IBuffer.cs b/src/EngineKit/Graphics/IBuffer.cs
index 9bc0cca..9abe6c6 100644
--- a/src/EngineKit/Graphics/IBuffer.cs
+++ b/src/EngineKit/Graphics/IBuffer.cs
@@ -1,4 +1,5 @@
using System;
+using EngineKit.Core;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/IComputePipelineBuilder.cs b/src/EngineKit/Graphics/IComputePipelineBuilder.cs
index bbb3a40..a36639a 100644
--- a/src/EngineKit/Graphics/IComputePipelineBuilder.cs
+++ b/src/EngineKit/Graphics/IComputePipelineBuilder.cs
@@ -1,4 +1,5 @@
using CSharpFunctionalExtensions;
+using EngineKit.Core;
namespace EngineKit.Graphics;
@@ -9,5 +10,6 @@ public interface IComputePipelineBuilder
IComputePipelineBuilder WithShaderFromFile(string computeShaderFilePath);
IComputePipelineBuilder WithShaderFromSource(string computeShaderSource);
+
IComputePipelineBuilder ClearResourceBindingsOnBind();
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/IContext.cs b/src/EngineKit/Graphics/IGraphicsContext.cs
similarity index 97%
rename from src/EngineKit/Graphics/IContext.cs
rename to src/EngineKit/Graphics/IGraphicsContext.cs
index 5254274..b5ca675 100644
--- a/src/EngineKit/Graphics/IContext.cs
+++ b/src/EngineKit/Graphics/IGraphicsContext.cs
@@ -1,4 +1,6 @@
using System;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
@@ -97,7 +99,8 @@ ITexture CreateTexture2D(
bool flipVertical,
bool flipHorizontal);
- ITexture? CreateTextureFromMemory(ImageInformation image,
+ ITexture? CreateTextureFromMemory(
+ ImageInformation image,
Format format,
Label label,
bool generateMipmaps,
diff --git a/src/EngineKit/Graphics/IGraphicsPipelineBuilder.cs b/src/EngineKit/Graphics/IGraphicsPipelineBuilder.cs
index d956839..b242ca0 100644
--- a/src/EngineKit/Graphics/IGraphicsPipelineBuilder.cs
+++ b/src/EngineKit/Graphics/IGraphicsPipelineBuilder.cs
@@ -1,4 +1,6 @@
using CSharpFunctionalExtensions;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/IMeshPool.cs b/src/EngineKit/Graphics/IMeshPool.cs
index adf1b7f..83ec8eb 100644
--- a/src/EngineKit/Graphics/IMeshPool.cs
+++ b/src/EngineKit/Graphics/IMeshPool.cs
@@ -5,9 +5,10 @@ namespace EngineKit.Graphics;
public interface IMeshPool : IDisposable
{
IBuffer VertexBuffer { get; }
-
+
IBuffer IndexBuffer { get; }
+
uint VertexBufferStride { get; }
PooledMesh GetOrAdd(MeshPrimitive meshPrimitive);
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/IPipeline.cs b/src/EngineKit/Graphics/IPipeline.cs
index 4eb1b51..aa9ed19 100644
--- a/src/EngineKit/Graphics/IPipeline.cs
+++ b/src/EngineKit/Graphics/IPipeline.cs
@@ -1,4 +1,6 @@
using System;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/IRenderer.cs b/src/EngineKit/Graphics/IRenderer.cs
new file mode 100644
index 0000000..041907b
--- /dev/null
+++ b/src/EngineKit/Graphics/IRenderer.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace EngineKit.Graphics;
+
+public interface IRenderer : IDisposable
+{
+ bool Load();
+
+ void Render(float deltaTime, float elapsedTime);
+
+ void RenderUi(float deltaTime, float elapsedTime);
+
+ void WindowFramebufferResized();
+}
diff --git a/src/EngineKit/Graphics/ISwapchainDescriptorBuilder.cs b/src/EngineKit/Graphics/ISwapchainDescriptorBuilder.cs
index 9bc1302..7fd91df 100644
--- a/src/EngineKit/Graphics/ISwapchainDescriptorBuilder.cs
+++ b/src/EngineKit/Graphics/ISwapchainDescriptorBuilder.cs
@@ -1,3 +1,4 @@
+using EngineKit.Core;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
@@ -5,19 +6,26 @@ namespace EngineKit.Graphics;
public interface ISwapchainDescriptorBuilder
{
ISwapchainDescriptorBuilder EnableSrgb();
-
- ISwapchainDescriptorBuilder WithViewport(int width, int height);
-
- ISwapchainDescriptorBuilder WithScissorRectangle(int left, int top, int width, int height);
-
+
+ ISwapchainDescriptorBuilder WithViewport(int width,
+ int height);
+
+ ISwapchainDescriptorBuilder WithScissorRectangle(int left,
+ int top,
+ int width,
+ int height);
+
ISwapchainDescriptorBuilder ClearColor(Color4 clearValue);
-
+
ISwapchainDescriptorBuilder ClearDepth(float clearValue);
-
+
ISwapchainDescriptorBuilder ClearStencil(int clearValue);
-
- SwapchainDescriptor Build(Label label);
+
ISwapchainDescriptorBuilder WithFramebufferSizeAsViewport();
+
ISwapchainDescriptorBuilder WithScaledFramebufferSizeAsViewport();
+
ISwapchainDescriptorBuilder WithWindowSizeAsViewport();
-}
\ No newline at end of file
+
+ SwapchainDescriptor Build(Label label);
+}
diff --git a/src/EngineKit/Graphics/IUIRendererLoader.cs b/src/EngineKit/Graphics/IUIRendererLoader.cs
index 4f3af76..f1bf851 100644
--- a/src/EngineKit/Graphics/IUIRendererLoader.cs
+++ b/src/EngineKit/Graphics/IUIRendererLoader.cs
@@ -2,5 +2,5 @@ namespace EngineKit.Graphics;
public interface IUIRendererLoader
{
- bool Load(int width, int height);
-}
\ No newline at end of file
+ bool Load();
+}
diff --git a/src/EngineKit/Graphics/InputAssemblyDescriptor.cs b/src/EngineKit/Graphics/InputAssemblyDescriptor.cs
index 374bcab..6066029 100644
--- a/src/EngineKit/Graphics/InputAssemblyDescriptor.cs
+++ b/src/EngineKit/Graphics/InputAssemblyDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
internal record struct InputAssemblyDescriptor(
diff --git a/src/EngineKit/Graphics/Material.cs b/src/EngineKit/Graphics/Material.cs
index 61dc24f..1b4ebdb 100644
--- a/src/EngineKit/Graphics/Material.cs
+++ b/src/EngineKit/Graphics/Material.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
using Serilog;
using Vector3 = System.Numerics.Vector3;
@@ -25,6 +26,7 @@ public record Material(string Name) : IDisposable
private ImageInformation? _metalnessRoughnessImage;
private ImageInformation? _occlusionImage;
private ImageInformation? _emissiveImage;
+ private bool _isDirty;
public SamplerInformation? BaseColorTextureSamplerInformation;
public SamplerInformation? NormalTextureSamplerInformation;
@@ -33,7 +35,6 @@ public record Material(string Name) : IDisposable
public SamplerInformation? OcclusionTextureSamplerInformation;
public SamplerInformation? EmissiveTextureSamplerInformation;
- private bool _isDirty;
public string Name { get; set; } = Name;
public bool TexturesLoaded { get; private set; }
@@ -45,7 +46,7 @@ public float OcclusionStrength
get => _occlusionStrength;
set
{
- if (MathF.Abs(_occlusionStrength - value) > 0.0001f)
+ if (MathF.Abs(_occlusionStrength - value) < float.Epsilon)
{
_occlusionStrength = value;
_isDirty = true;
@@ -58,7 +59,7 @@ public float GlossinessFactor
get => _glossinessFactor;
set
{
- if (MathF.Abs(_glossinessFactor - value) > 0.0001f)
+ if (MathF.Abs(_glossinessFactor - value) < float.Epsilon)
{
_glossinessFactor = value;
_isDirty = true;
@@ -71,7 +72,7 @@ public float MetallicFactor
get => _metallicFactor;
set
{
- if (MathF.Abs(_metallicFactor - value) > 0.0001f)
+ if (MathF.Abs(_metallicFactor - value) < float.Epsilon)
{
_metallicFactor = value;
_isDirty = true;
@@ -84,7 +85,7 @@ public float RoughnessFactor
get => _roughnessFactor;
set
{
- if (MathF.Abs(_roughnessFactor - value) > 0.0001f)
+ if (MathF.Abs(_roughnessFactor - value) < float.Epsilon)
{
_roughnessFactor = value;
_isDirty = true;
diff --git a/src/EngineKit/Graphics/MaterialLibrary.cs b/src/EngineKit/Graphics/MaterialLibrary.cs
index 3f6045d..fdee25d 100644
--- a/src/EngineKit/Graphics/MaterialLibrary.cs
+++ b/src/EngineKit/Graphics/MaterialLibrary.cs
@@ -6,7 +6,7 @@
namespace EngineKit.Graphics;
-internal sealed class MaterialLibrary : IMaterialLibrary
+public sealed class MaterialLibrary : IMaterialLibrary
{
private readonly ISamplerLibrary _samplerLibrary;
private readonly ILogger _logger;
diff --git a/src/EngineKit/Graphics/MaterialPool.cs b/src/EngineKit/Graphics/MaterialPool.cs
index f13bcb5..0448d2b 100644
--- a/src/EngineKit/Graphics/MaterialPool.cs
+++ b/src/EngineKit/Graphics/MaterialPool.cs
@@ -1,4 +1,6 @@
using System.Collections.Generic;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
using Serilog;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/MeshPool.cs b/src/EngineKit/Graphics/MeshPool.cs
index 7a11a12..b864e8b 100644
--- a/src/EngineKit/Graphics/MeshPool.cs
+++ b/src/EngineKit/Graphics/MeshPool.cs
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
namespace EngineKit.Graphics;
@@ -16,7 +18,7 @@ public MeshPool(
{
_pooledMeshes = new Dictionary(1024);
- VertexBuffer = graphicsContext.CreateUntypedBuffer(label + "Vertices", (nuint)(maxVertexCount * Unsafe.SizeOf()), BufferStorageFlags.DynamicStorage);
+ VertexBuffer = graphicsContext.CreateUntypedBuffer(label + "Vertices", (nuint)(maxVertexCount * Unsafe.SizeOf()), BufferStorageFlags.DynamicStorage);
IndexBuffer = graphicsContext.CreateUntypedBuffer(label + "Indices", (nuint)(maxIndexCount * Unsafe.SizeOf()), BufferStorageFlags.DynamicStorage);
}
@@ -24,7 +26,7 @@ public MeshPool(
public IBuffer IndexBuffer { get; }
- public uint VertexBufferStride => VertexPositionNormalUvTangent.Stride;
+ public uint VertexBufferStride => GpuVertexPositionNormalUvTangent.Stride;
public void Dispose()
{
diff --git a/src/EngineKit/Graphics/MeshPrimitive.cs b/src/EngineKit/Graphics/MeshPrimitive.cs
index 0b56211..caaaa0d 100644
--- a/src/EngineKit/Graphics/MeshPrimitive.cs
+++ b/src/EngineKit/Graphics/MeshPrimitive.cs
@@ -77,17 +77,17 @@ public MeshPrimitive(string meshName)
HasIndices = false;
}
- public VertexPositionNormalUvTangent[] GetVertices()
+ public GpuVertexPositionNormalUvTangent[] GetVertices()
{
if (!RealTangents.Any())
{
CalculateTangents();
}
- var bufferData = new List(1_024_000);
+ var bufferData = new List(1_024_000);
for (var i = 0; i < Positions.Count; ++i)
{
- bufferData.Add(new VertexPositionNormalUvTangent(
+ bufferData.Add(new GpuVertexPositionNormalUvTangent(
Positions[i],
Normals[i],
Uvs[i],
diff --git a/src/EngineKit/Graphics/ModelLibrary.cs b/src/EngineKit/Graphics/ModelLibrary.cs
index 29db606..ba480e7 100644
--- a/src/EngineKit/Graphics/ModelLibrary.cs
+++ b/src/EngineKit/Graphics/ModelLibrary.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using EngineKit.Graphics.Assets;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/NullRenderer.cs b/src/EngineKit/Graphics/NullRenderer.cs
new file mode 100644
index 0000000..ca69591
--- /dev/null
+++ b/src/EngineKit/Graphics/NullRenderer.cs
@@ -0,0 +1,29 @@
+namespace EngineKit.Graphics;
+
+internal sealed class NullRenderer : IRenderer
+{
+ public void Dispose()
+ {
+ }
+
+ public bool Load()
+ {
+ return true;
+ }
+
+ public void Render(
+ float deltaTime,
+ float elapsedTime)
+ {
+ }
+
+ public void RenderUi(
+ float deltaTime,
+ float elapsedTime)
+ {
+ }
+
+ public void WindowFramebufferResized()
+ {
+ }
+}
diff --git a/src/EngineKit/Graphics/Pipeline.cs b/src/EngineKit/Graphics/Pipeline.cs
index ee75321..aeebdb5 100644
--- a/src/EngineKit/Graphics/Pipeline.cs
+++ b/src/EngineKit/Graphics/Pipeline.cs
@@ -1,6 +1,7 @@
using System;
+using EngineKit.Core;
using EngineKit.Extensions;
-using EngineKit.Graphics.Shaders;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
@@ -8,7 +9,7 @@ namespace EngineKit.Graphics;
public abstract class Pipeline : IPipeline
{
protected ShaderProgram? ShaderProgram;
-
+
public Label Label { get; protected set; }
public virtual void Bind()
@@ -58,7 +59,7 @@ public void BindAsUniformBuffer(
return;
}
}
-
+
GL.BindBufferRange(BufferTarget.UniformBuffer.ToGL(), bindingIndex, uniformBuffer.Id, offsetInBytes, (nint)sizeInBytes);
}
@@ -105,4 +106,4 @@ public void BindSampledTexture(
GL.BindTextureUnit(bindingIndex, textureId);
GL.BindSampler(bindingIndex, sampler.Id);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/PooledMesh.cs b/src/EngineKit/Graphics/PooledMesh.cs
index 2444d8a..4f026b2 100644
--- a/src/EngineKit/Graphics/PooledMesh.cs
+++ b/src/EngineKit/Graphics/PooledMesh.cs
@@ -2,7 +2,7 @@
namespace EngineKit.Graphics;
-public readonly struct PooledMesh
+public readonly record struct PooledMesh
{
public PooledMesh(uint indexCount, uint indexOffset, int vertexCount, uint vertexOffset, Vector3 aabbMax, Vector3 aabbMin, string? materialName)
{
@@ -28,4 +28,4 @@ public PooledMesh(uint indexCount, uint indexOffset, int vertexCount, uint verte
public readonly uint VertexOffset;
public readonly string? MaterialName;
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/BarrierMask.cs b/src/EngineKit/Graphics/RHI/BarrierMask.cs
similarity index 93%
rename from src/EngineKit/Graphics/BarrierMask.cs
rename to src/EngineKit/Graphics/RHI/BarrierMask.cs
index efd46f5..955b162 100644
--- a/src/EngineKit/Graphics/BarrierMask.cs
+++ b/src/EngineKit/Graphics/RHI/BarrierMask.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum BarrierMask : uint
diff --git a/src/EngineKit/Graphics/Blend.cs b/src/EngineKit/Graphics/RHI/Blend.cs
similarity index 92%
rename from src/EngineKit/Graphics/Blend.cs
rename to src/EngineKit/Graphics/RHI/Blend.cs
index ae6f99a..b62dc73 100644
--- a/src/EngineKit/Graphics/Blend.cs
+++ b/src/EngineKit/Graphics/RHI/Blend.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum Blend
{
diff --git a/src/EngineKit/Graphics/BlendFunction.cs b/src/EngineKit/Graphics/RHI/BlendFunction.cs
similarity index 71%
rename from src/EngineKit/Graphics/BlendFunction.cs
rename to src/EngineKit/Graphics/RHI/BlendFunction.cs
index 22a3a31..6cc8f8a 100644
--- a/src/EngineKit/Graphics/BlendFunction.cs
+++ b/src/EngineKit/Graphics/RHI/BlendFunction.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum BlendFunction
{
diff --git a/src/EngineKit/Graphics/BlitFramebufferFilter.cs b/src/EngineKit/Graphics/RHI/BlitFramebufferFilter.cs
similarity index 64%
rename from src/EngineKit/Graphics/BlitFramebufferFilter.cs
rename to src/EngineKit/Graphics/RHI/BlitFramebufferFilter.cs
index 0c29487..629bd65 100644
--- a/src/EngineKit/Graphics/BlitFramebufferFilter.cs
+++ b/src/EngineKit/Graphics/RHI/BlitFramebufferFilter.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum BlitFramebufferFilter
{
diff --git a/src/EngineKit/Graphics/BufferStorageFlags.cs b/src/EngineKit/Graphics/RHI/BufferStorageFlags.cs
similarity index 82%
rename from src/EngineKit/Graphics/BufferStorageFlags.cs
rename to src/EngineKit/Graphics/RHI/BufferStorageFlags.cs
index e02c389..4dc5faf 100644
--- a/src/EngineKit/Graphics/BufferStorageFlags.cs
+++ b/src/EngineKit/Graphics/RHI/BufferStorageFlags.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum BufferStorageFlags
diff --git a/src/EngineKit/Graphics/BufferTarget.cs b/src/EngineKit/Graphics/RHI/BufferTarget.cs
similarity index 84%
rename from src/EngineKit/Graphics/BufferTarget.cs
rename to src/EngineKit/Graphics/RHI/BufferTarget.cs
index e03409e..6bc67a5 100644
--- a/src/EngineKit/Graphics/BufferTarget.cs
+++ b/src/EngineKit/Graphics/RHI/BufferTarget.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum BufferTarget
{
diff --git a/src/EngineKit/Graphics/ClipControl.cs b/src/EngineKit/Graphics/RHI/ClipControl.cs
similarity index 66%
rename from src/EngineKit/Graphics/ClipControl.cs
rename to src/EngineKit/Graphics/RHI/ClipControl.cs
index 6e7444c..9bc7fa2 100644
--- a/src/EngineKit/Graphics/ClipControl.cs
+++ b/src/EngineKit/Graphics/RHI/ClipControl.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum ClipControlDepth
{
diff --git a/src/EngineKit/Graphics/ColorMask.cs b/src/EngineKit/Graphics/RHI/ColorMask.cs
similarity index 83%
rename from src/EngineKit/Graphics/ColorMask.cs
rename to src/EngineKit/Graphics/RHI/ColorMask.cs
index c2d09f3..74c7861 100644
--- a/src/EngineKit/Graphics/ColorMask.cs
+++ b/src/EngineKit/Graphics/RHI/ColorMask.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum ColorMask : uint
diff --git a/src/EngineKit/Graphics/CompareFunction.cs b/src/EngineKit/Graphics/RHI/CompareFunction.cs
similarity index 78%
rename from src/EngineKit/Graphics/CompareFunction.cs
rename to src/EngineKit/Graphics/RHI/CompareFunction.cs
index 9909962..991d6fc 100644
--- a/src/EngineKit/Graphics/CompareFunction.cs
+++ b/src/EngineKit/Graphics/RHI/CompareFunction.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum CompareFunction
{
diff --git a/src/EngineKit/Graphics/CullMode.cs b/src/EngineKit/Graphics/RHI/CullMode.cs
similarity index 63%
rename from src/EngineKit/Graphics/CullMode.cs
rename to src/EngineKit/Graphics/RHI/CullMode.cs
index f054e3f..3f81f2c 100644
--- a/src/EngineKit/Graphics/CullMode.cs
+++ b/src/EngineKit/Graphics/RHI/CullMode.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum CullMode
{
diff --git a/src/EngineKit/Graphics/DataType.cs b/src/EngineKit/Graphics/RHI/DataType.cs
similarity index 78%
rename from src/EngineKit/Graphics/DataType.cs
rename to src/EngineKit/Graphics/RHI/DataType.cs
index 6281dba..3a1e918 100644
--- a/src/EngineKit/Graphics/DataType.cs
+++ b/src/EngineKit/Graphics/RHI/DataType.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum DataType
{
diff --git a/src/EngineKit/Graphics/FaceWinding.cs b/src/EngineKit/Graphics/RHI/FaceWinding.cs
similarity index 63%
rename from src/EngineKit/Graphics/FaceWinding.cs
rename to src/EngineKit/Graphics/RHI/FaceWinding.cs
index def59fd..6c33f63 100644
--- a/src/EngineKit/Graphics/FaceWinding.cs
+++ b/src/EngineKit/Graphics/RHI/FaceWinding.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum FaceWinding
{
diff --git a/src/EngineKit/Graphics/FillMode.cs b/src/EngineKit/Graphics/RHI/FillMode.cs
similarity index 60%
rename from src/EngineKit/Graphics/FillMode.cs
rename to src/EngineKit/Graphics/RHI/FillMode.cs
index e6c390e..190154a 100644
--- a/src/EngineKit/Graphics/FillMode.cs
+++ b/src/EngineKit/Graphics/RHI/FillMode.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum FillMode
{
diff --git a/src/EngineKit/Graphics/Format.cs b/src/EngineKit/Graphics/RHI/Format.cs
similarity index 98%
rename from src/EngineKit/Graphics/Format.cs
rename to src/EngineKit/Graphics/RHI/Format.cs
index 685a48f..4123c29 100644
--- a/src/EngineKit/Graphics/Format.cs
+++ b/src/EngineKit/Graphics/RHI/Format.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum Format
{
@@ -103,4 +103,4 @@ public enum Format
default: FWOG_UNREACHABLE; return {};
}
}
-*/
\ No newline at end of file
+*/
diff --git a/src/EngineKit/Graphics/FormatBaseType.cs b/src/EngineKit/Graphics/RHI/FormatBaseType.cs
similarity index 68%
rename from src/EngineKit/Graphics/FormatBaseType.cs
rename to src/EngineKit/Graphics/RHI/FormatBaseType.cs
index b9db069..af8acfb 100644
--- a/src/EngineKit/Graphics/FormatBaseType.cs
+++ b/src/EngineKit/Graphics/RHI/FormatBaseType.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum FormatBaseType
{
diff --git a/src/EngineKit/Graphics/FramebufferBit.cs b/src/EngineKit/Graphics/RHI/FramebufferBit.cs
similarity index 79%
rename from src/EngineKit/Graphics/FramebufferBit.cs
rename to src/EngineKit/Graphics/RHI/FramebufferBit.cs
index 755c004..e793fc7 100644
--- a/src/EngineKit/Graphics/FramebufferBit.cs
+++ b/src/EngineKit/Graphics/RHI/FramebufferBit.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum FramebufferBit
diff --git a/src/EngineKit/Graphics/MapFlags.cs b/src/EngineKit/Graphics/RHI/MapFlags.cs
similarity index 79%
rename from src/EngineKit/Graphics/MapFlags.cs
rename to src/EngineKit/Graphics/RHI/MapFlags.cs
index 1176a93..65ec972 100644
--- a/src/EngineKit/Graphics/MapFlags.cs
+++ b/src/EngineKit/Graphics/RHI/MapFlags.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum MapFlags
diff --git a/src/EngineKit/Graphics/MemoryAccess.cs b/src/EngineKit/Graphics/RHI/MemoryAccess.cs
similarity index 67%
rename from src/EngineKit/Graphics/MemoryAccess.cs
rename to src/EngineKit/Graphics/RHI/MemoryAccess.cs
index d3b029d..7fd4636 100644
--- a/src/EngineKit/Graphics/MemoryAccess.cs
+++ b/src/EngineKit/Graphics/RHI/MemoryAccess.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum MemoryAccess
{
diff --git a/src/EngineKit/Graphics/PrimitiveTopology.cs b/src/EngineKit/Graphics/RHI/PrimitiveTopology.cs
similarity index 80%
rename from src/EngineKit/Graphics/PrimitiveTopology.cs
rename to src/EngineKit/Graphics/RHI/PrimitiveTopology.cs
index c7089ae..73e5b62 100644
--- a/src/EngineKit/Graphics/PrimitiveTopology.cs
+++ b/src/EngineKit/Graphics/RHI/PrimitiveTopology.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum PrimitiveTopology
{
diff --git a/src/EngineKit/Graphics/Shaders/Shader.cs b/src/EngineKit/Graphics/RHI/Shader.cs
similarity index 97%
rename from src/EngineKit/Graphics/Shaders/Shader.cs
rename to src/EngineKit/Graphics/RHI/Shader.cs
index a9f8eb8..09643ea 100644
--- a/src/EngineKit/Graphics/Shaders/Shader.cs
+++ b/src/EngineKit/Graphics/RHI/Shader.cs
@@ -3,7 +3,7 @@
using EngineKit.Extensions;
using EngineKit.Native.OpenGL;
-namespace EngineKit.Graphics.Shaders;
+namespace EngineKit.Graphics.RHI;
public sealed class Shader : IDisposable
{
@@ -52,4 +52,4 @@ internal Result Compile()
return Result.Success();
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/Shaders/ShaderProgram.cs b/src/EngineKit/Graphics/RHI/ShaderProgram.cs
similarity index 78%
rename from src/EngineKit/Graphics/Shaders/ShaderProgram.cs
rename to src/EngineKit/Graphics/RHI/ShaderProgram.cs
index e9db1df..1ab1a4c 100644
--- a/src/EngineKit/Graphics/Shaders/ShaderProgram.cs
+++ b/src/EngineKit/Graphics/RHI/ShaderProgram.cs
@@ -1,8 +1,9 @@
using System;
using CSharpFunctionalExtensions;
+using EngineKit.Core;
using EngineKit.Native.OpenGL;
-namespace EngineKit.Graphics.Shaders;
+namespace EngineKit.Graphics.RHI;
public sealed class ShaderProgram : IDisposable
{
@@ -11,7 +12,7 @@ public sealed class ShaderProgram : IDisposable
private readonly string? _fragmentShaderSource;
private readonly Label _label;
- public uint ProgramPipelineId;
+ public uint Id;
public Shader? VertexShader { get; private set; }
@@ -19,7 +20,9 @@ public sealed class ShaderProgram : IDisposable
public Shader? ComputeShader { get; private set; }
- public ShaderProgram(Label label, string computeShaderSource)
+ public ShaderProgram(
+ Label label,
+ string computeShaderSource)
{
if (string.IsNullOrEmpty(computeShaderSource))
{
@@ -45,7 +48,7 @@ public ShaderProgram(
{
throw new ArgumentNullException(nameof(fragmentShaderSource));
}
-
+
_label = label;
_computeShaderSource = null!;
_vertexShaderSource = vertexShaderSource;
@@ -54,8 +57,8 @@ public ShaderProgram(
public Result Link()
{
- ProgramPipelineId = GL.CreateProgramPipeline();
- GL.ObjectLabel(GL.ObjectIdentifier.ProgramPipeline, ProgramPipelineId, $"ProgramPipeline-{_label}");
+ Id = GL.CreateProgramPipeline();
+ GL.ObjectLabel(GL.ObjectIdentifier.ProgramPipeline, Id, $"ProgramPipeline-{_label}");
var compilationResult = CreateShaders();
if (compilationResult.IsFailure)
@@ -72,7 +75,7 @@ public Result Link()
}
GL.UseProgramStages(
- ProgramPipelineId,
+ Id,
GL.UseProgramStageMask.ComputeShaderBit,
ComputeShader.Id);
@@ -101,8 +104,8 @@ public Result Link()
return compilationResult;
}
- GL.UseProgramStages(ProgramPipelineId, GL.UseProgramStageMask.VertexShaderBit, VertexShader.Id);
- GL.UseProgramStages(ProgramPipelineId, GL.UseProgramStageMask.FragmentShaderBit, FragmentShader.Id);
+ GL.UseProgramStages(Id, GL.UseProgramStageMask.VertexShaderBit, VertexShader.Id);
+ GL.UseProgramStages(Id, GL.UseProgramStageMask.FragmentShaderBit, FragmentShader.Id);
return Result.Success();
}
@@ -111,15 +114,15 @@ public void Use()
{
if (ComputeShader != null)
{
- GL.UseProgramStages(ProgramPipelineId, GL.UseProgramStageMask.ComputeShaderBit, ComputeShader.Id);
+ GL.UseProgramStages(Id, GL.UseProgramStageMask.ComputeShaderBit, ComputeShader.Id);
}
else
{
- GL.UseProgramStages(ProgramPipelineId, GL.UseProgramStageMask.VertexShaderBit, VertexShader!.Id);
- GL.UseProgramStages(ProgramPipelineId, GL.UseProgramStageMask.FragmentShaderBit, FragmentShader!.Id);
+ GL.UseProgramStages(Id, GL.UseProgramStageMask.VertexShaderBit, VertexShader!.Id);
+ GL.UseProgramStages(Id, GL.UseProgramStageMask.FragmentShaderBit, FragmentShader!.Id);
}
- GL.BindProgramPipeline(ProgramPipelineId);
+ GL.BindProgramPipeline(Id);
}
public void Dispose()
@@ -127,7 +130,7 @@ public void Dispose()
ComputeShader?.Dispose();
VertexShader?.Dispose();
FragmentShader?.Dispose();
- GL.DeleteProgramPipeline(ProgramPipelineId);
+ GL.DeleteProgramPipeline(Id);
}
private Result CreateShaders()
@@ -155,4 +158,4 @@ private Result CreateShaders()
return Result.Success();
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/ShaderType.cs b/src/EngineKit/Graphics/RHI/ShaderType.cs
similarity index 77%
rename from src/EngineKit/Graphics/ShaderType.cs
rename to src/EngineKit/Graphics/RHI/ShaderType.cs
index e42bff6..5faaca6 100644
--- a/src/EngineKit/Graphics/ShaderType.cs
+++ b/src/EngineKit/Graphics/RHI/ShaderType.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum ShaderType
{
diff --git a/src/EngineKit/Graphics/StorageAllocationFlags.cs b/src/EngineKit/Graphics/RHI/StorageAllocationFlags.cs
similarity index 78%
rename from src/EngineKit/Graphics/StorageAllocationFlags.cs
rename to src/EngineKit/Graphics/RHI/StorageAllocationFlags.cs
index 2144c7c..99cae7c 100644
--- a/src/EngineKit/Graphics/StorageAllocationFlags.cs
+++ b/src/EngineKit/Graphics/RHI/StorageAllocationFlags.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
[Flags]
public enum StorageAllocationFlags
diff --git a/src/EngineKit/Graphics/Swizzle.cs b/src/EngineKit/Graphics/RHI/Swizzle.cs
similarity index 70%
rename from src/EngineKit/Graphics/Swizzle.cs
rename to src/EngineKit/Graphics/RHI/Swizzle.cs
index a0a801d..39b8fd7 100644
--- a/src/EngineKit/Graphics/Swizzle.cs
+++ b/src/EngineKit/Graphics/RHI/Swizzle.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum Swizzle
{
diff --git a/src/EngineKit/Graphics/TextureAddressMode.cs b/src/EngineKit/Graphics/RHI/TextureAddressMode.cs
similarity index 75%
rename from src/EngineKit/Graphics/TextureAddressMode.cs
rename to src/EngineKit/Graphics/RHI/TextureAddressMode.cs
index e4bcb45..22c546a 100644
--- a/src/EngineKit/Graphics/TextureAddressMode.cs
+++ b/src/EngineKit/Graphics/RHI/TextureAddressMode.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum TextureAddressMode
{
diff --git a/src/EngineKit/Graphics/TextureBorderColor.cs b/src/EngineKit/Graphics/RHI/TextureBorderColor.cs
similarity index 83%
rename from src/EngineKit/Graphics/TextureBorderColor.cs
rename to src/EngineKit/Graphics/RHI/TextureBorderColor.cs
index 20c5480..c9a2c12 100644
--- a/src/EngineKit/Graphics/TextureBorderColor.cs
+++ b/src/EngineKit/Graphics/RHI/TextureBorderColor.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum TextureBorderColor
{
diff --git a/src/EngineKit/Graphics/TextureInterpolationFilter.cs b/src/EngineKit/Graphics/RHI/TextureInterpolationFilter.cs
similarity index 70%
rename from src/EngineKit/Graphics/TextureInterpolationFilter.cs
rename to src/EngineKit/Graphics/RHI/TextureInterpolationFilter.cs
index 9dd6b92..9f9faad 100644
--- a/src/EngineKit/Graphics/TextureInterpolationFilter.cs
+++ b/src/EngineKit/Graphics/RHI/TextureInterpolationFilter.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum TextureInterpolationFilter
{
diff --git a/src/EngineKit/Graphics/TextureMipmapFilter.cs b/src/EngineKit/Graphics/RHI/TextureMipmapFilter.cs
similarity index 83%
rename from src/EngineKit/Graphics/TextureMipmapFilter.cs
rename to src/EngineKit/Graphics/RHI/TextureMipmapFilter.cs
index d397458..7b1d1ac 100644
--- a/src/EngineKit/Graphics/TextureMipmapFilter.cs
+++ b/src/EngineKit/Graphics/RHI/TextureMipmapFilter.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum TextureMipmapFilter
{
diff --git a/src/EngineKit/Graphics/TextureSampleCount.cs b/src/EngineKit/Graphics/RHI/TextureSampleCount.cs
similarity index 77%
rename from src/EngineKit/Graphics/TextureSampleCount.cs
rename to src/EngineKit/Graphics/RHI/TextureSampleCount.cs
index a582961..cea37b8 100644
--- a/src/EngineKit/Graphics/TextureSampleCount.cs
+++ b/src/EngineKit/Graphics/RHI/TextureSampleCount.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum TextureSampleCount
{
diff --git a/src/EngineKit/Graphics/ImageType.cs b/src/EngineKit/Graphics/RHI/TextureType.cs
similarity index 72%
rename from src/EngineKit/Graphics/ImageType.cs
rename to src/EngineKit/Graphics/RHI/TextureType.cs
index 8225de5..6b60bac 100644
--- a/src/EngineKit/Graphics/ImageType.cs
+++ b/src/EngineKit/Graphics/RHI/TextureType.cs
@@ -1,6 +1,6 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
-public enum ImageType
+public enum TextureType
{
Texture1D,
Texture1DArray,
@@ -10,4 +10,4 @@ public enum ImageType
TextureCube,
Texture2DMultisample,
Texture2DArrayMultisample
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/UploadDimension.cs b/src/EngineKit/Graphics/RHI/UploadDimension.cs
similarity index 63%
rename from src/EngineKit/Graphics/UploadDimension.cs
rename to src/EngineKit/Graphics/RHI/UploadDimension.cs
index 56c6b48..169f698 100644
--- a/src/EngineKit/Graphics/UploadDimension.cs
+++ b/src/EngineKit/Graphics/RHI/UploadDimension.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum UploadDimension
{
diff --git a/src/EngineKit/Graphics/UploadFormat.cs b/src/EngineKit/Graphics/RHI/UploadFormat.cs
similarity index 84%
rename from src/EngineKit/Graphics/UploadFormat.cs
rename to src/EngineKit/Graphics/RHI/UploadFormat.cs
index f372b05..9fb5b78 100644
--- a/src/EngineKit/Graphics/UploadFormat.cs
+++ b/src/EngineKit/Graphics/RHI/UploadFormat.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum UploadFormat
{
diff --git a/src/EngineKit/Graphics/UploadType.cs b/src/EngineKit/Graphics/RHI/UploadType.cs
similarity index 89%
rename from src/EngineKit/Graphics/UploadType.cs
rename to src/EngineKit/Graphics/RHI/UploadType.cs
index 770fc8f..d3baffc 100644
--- a/src/EngineKit/Graphics/UploadType.cs
+++ b/src/EngineKit/Graphics/RHI/UploadType.cs
@@ -1,4 +1,4 @@
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.RHI;
public enum UploadType
{
diff --git a/src/EngineKit/Graphics/RasterizationDescriptor.cs b/src/EngineKit/Graphics/RasterizationDescriptor.cs
index 45c7c20..b93c783 100644
--- a/src/EngineKit/Graphics/RasterizationDescriptor.cs
+++ b/src/EngineKit/Graphics/RasterizationDescriptor.cs
@@ -1,3 +1,5 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public record struct RasterizationDescriptor(
diff --git a/src/EngineKit/Graphics/Sampler.cs b/src/EngineKit/Graphics/Sampler.cs
index 6cfc674..faaddc3 100644
--- a/src/EngineKit/Graphics/Sampler.cs
+++ b/src/EngineKit/Graphics/Sampler.cs
@@ -1,5 +1,6 @@
using System;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/SamplerBuilder.cs b/src/EngineKit/Graphics/SamplerBuilder.cs
index 063b3fb..7b209be 100644
--- a/src/EngineKit/Graphics/SamplerBuilder.cs
+++ b/src/EngineKit/Graphics/SamplerBuilder.cs
@@ -1,3 +1,6 @@
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public class SamplerBuilder
diff --git a/src/EngineKit/Graphics/SamplerDescriptor.cs b/src/EngineKit/Graphics/SamplerDescriptor.cs
index 3a244e8..1511a8b 100644
--- a/src/EngineKit/Graphics/SamplerDescriptor.cs
+++ b/src/EngineKit/Graphics/SamplerDescriptor.cs
@@ -1,3 +1,6 @@
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public struct SamplerDescriptor
diff --git a/src/EngineKit/Graphics/SamplerInformation.cs b/src/EngineKit/Graphics/SamplerInformation.cs
index 3620529..40ca4f9 100644
--- a/src/EngineKit/Graphics/SamplerInformation.cs
+++ b/src/EngineKit/Graphics/SamplerInformation.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/SamplerLibrary.cs b/src/EngineKit/Graphics/SamplerLibrary.cs
index 8a2c9a3..83a405a 100644
--- a/src/EngineKit/Graphics/SamplerLibrary.cs
+++ b/src/EngineKit/Graphics/SamplerLibrary.cs
@@ -1,8 +1,9 @@
using System.Collections.Generic;
+using EngineKit.Graphics.RHI;
namespace EngineKit.Graphics;
-internal sealed class SamplerLibrary : ISamplerLibrary
+public sealed class SamplerLibrary : ISamplerLibrary
{
private readonly IGraphicsContext _graphicsContext;
private IDictionary _samplers;
diff --git a/src/EngineKit/Graphics/CompositeShaderIncludeHandler.cs b/src/EngineKit/Graphics/Shaders/CompositeShaderIncludeHandler.cs
similarity index 91%
rename from src/EngineKit/Graphics/CompositeShaderIncludeHandler.cs
rename to src/EngineKit/Graphics/Shaders/CompositeShaderIncludeHandler.cs
index e91527f..bdd11d2 100644
--- a/src/EngineKit/Graphics/CompositeShaderIncludeHandler.cs
+++ b/src/EngineKit/Graphics/Shaders/CompositeShaderIncludeHandler.cs
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Linq;
-using EngineKit.Graphics.Shaders;
-namespace EngineKit.Graphics;
+namespace EngineKit.Graphics.Shaders;
public class CompositeShaderIncludeHandler : IShaderIncludeHandler
{
diff --git a/src/EngineKit/Graphics/Shaders/IShaderProgramFactory.cs b/src/EngineKit/Graphics/Shaders/IShaderProgramFactory.cs
index 79d6433..12d494e 100644
--- a/src/EngineKit/Graphics/Shaders/IShaderProgramFactory.cs
+++ b/src/EngineKit/Graphics/Shaders/IShaderProgramFactory.cs
@@ -1,3 +1,6 @@
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics.Shaders;
internal interface IShaderProgramFactory
@@ -5,4 +8,4 @@ internal interface IShaderProgramFactory
ShaderProgram CreateShaderProgram(Label label, string computeShaderSource);
ShaderProgram CreateShaderProgram(Label label, string vertexShaderSource, string fragmentShaderSource);
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/Shaders/ShaderProgramFactory.cs b/src/EngineKit/Graphics/Shaders/ShaderProgramFactory.cs
index fca3400..d350240 100644
--- a/src/EngineKit/Graphics/Shaders/ShaderProgramFactory.cs
+++ b/src/EngineKit/Graphics/Shaders/ShaderProgramFactory.cs
@@ -1,3 +1,5 @@
+using EngineKit.Core;
+using EngineKit.Graphics.RHI;
using Serilog;
namespace EngineKit.Graphics.Shaders;
@@ -24,8 +26,8 @@ public ShaderProgram CreateShaderProgram(Label label, string vertexShaderSource,
var parsedVertexShaderSource = _shaderParser.ParseShader(vertexShaderSource);
var parsedFragmentShaderSource = _shaderParser.ParseShader(fragmentShaderSource);
return new ShaderProgram(
- label,
+ label,
parsedVertexShaderSource,
parsedFragmentShaderSource);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/SwapchainDescriptor.cs b/src/EngineKit/Graphics/SwapchainDescriptor.cs
index 3a57cf6..fe3fea6 100644
--- a/src/EngineKit/Graphics/SwapchainDescriptor.cs
+++ b/src/EngineKit/Graphics/SwapchainDescriptor.cs
@@ -1,3 +1,4 @@
+using EngineKit.Core;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/SwapchainDescriptorBuilder.cs b/src/EngineKit/Graphics/SwapchainDescriptorBuilder.cs
index ed19b86..97338b7 100644
--- a/src/EngineKit/Graphics/SwapchainDescriptorBuilder.cs
+++ b/src/EngineKit/Graphics/SwapchainDescriptorBuilder.cs
@@ -1,3 +1,4 @@
+using EngineKit.Core;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
@@ -54,8 +55,8 @@ public ISwapchainDescriptorBuilder WithScaledFramebufferSizeAsViewport()
_swapchainDescriptor.Viewport = new Viewport(
0,
0,
- _applicationContext.WindowScaledFramebufferSize.X,
- _applicationContext.WindowScaledFramebufferSize.Y);
+ _applicationContext.ScaledWindowFramebufferSize.X,
+ _applicationContext.ScaledWindowFramebufferSize.Y);
return this;
}
diff --git a/src/EngineKit/Graphics/SwizzleMapping.cs b/src/EngineKit/Graphics/SwizzleMapping.cs
index 9312acd..cd06e43 100644
--- a/src/EngineKit/Graphics/SwizzleMapping.cs
+++ b/src/EngineKit/Graphics/SwizzleMapping.cs
@@ -1,3 +1,5 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public readonly record struct SwizzleMapping
diff --git a/src/EngineKit/Graphics/Texture.cs b/src/EngineKit/Graphics/Texture.cs
index 7c8dc26..d8837e1 100644
--- a/src/EngineKit/Graphics/Texture.cs
+++ b/src/EngineKit/Graphics/Texture.cs
@@ -1,6 +1,7 @@
using System;
using System.Buffers;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
@@ -45,23 +46,23 @@ public void MakeNonResident()
internal Texture(TextureCreateDescriptor textureCreateDescriptor)
{
_textureCreateDescriptor = textureCreateDescriptor;
- _id = GL.CreateTexture(_textureCreateDescriptor.ImageType.ToGL());
+ _id = GL.CreateTexture(_textureCreateDescriptor.TextureType.ToGL());
if (!string.IsNullOrEmpty(textureCreateDescriptor.Label))
{
GL.ObjectLabel(GL.ObjectIdentifier.Texture, _id, textureCreateDescriptor.Label);
}
- switch (textureCreateDescriptor.ImageType)
+ switch (textureCreateDescriptor.TextureType)
{
- case ImageType.Texture1D:
+ case TextureType.Texture1D:
GL.TextureStorage1D(
_id,
textureCreateDescriptor.MipLevels,
textureCreateDescriptor.Format.ToGL(),
textureCreateDescriptor.Size.X);
break;
- case ImageType.Texture2D:
+ case TextureType.Texture2D:
GL.TextureStorage2D(
_id,
textureCreateDescriptor.MipLevels,
@@ -69,7 +70,7 @@ internal Texture(TextureCreateDescriptor textureCreateDescriptor)
textureCreateDescriptor.Size.X,
textureCreateDescriptor.Size.Y);
break;
- case ImageType.TextureCube:
+ case TextureType.TextureCube:
GL.TextureStorage2D(
_id,
textureCreateDescriptor.MipLevels,
@@ -77,7 +78,7 @@ internal Texture(TextureCreateDescriptor textureCreateDescriptor)
textureCreateDescriptor.Size.X,
textureCreateDescriptor.Size.Y);
break;
- case ImageType.Texture3D:
+ case TextureType.Texture3D:
GL.TextureStorage3D(
_id,
textureCreateDescriptor.MipLevels,
@@ -86,7 +87,7 @@ internal Texture(TextureCreateDescriptor textureCreateDescriptor)
textureCreateDescriptor.Size.Y,
textureCreateDescriptor.Size.Z);
break;
- case ImageType.Texture2DArray:
+ case TextureType.Texture2DArray:
GL.TextureStorage3D(
_id,
textureCreateDescriptor.MipLevels,
@@ -97,7 +98,7 @@ internal Texture(TextureCreateDescriptor textureCreateDescriptor)
break;
default:
throw new NotImplementedException(
- $"ImageType {textureCreateDescriptor.ImageType} is not implemented yet");
+ $"ImageType {textureCreateDescriptor.TextureType} is not implemented yet");
}
}
@@ -107,7 +108,7 @@ public TextureView CreateTextureView()
{
Format = _textureCreateDescriptor.Format,
Label = _textureCreateDescriptor.Label + "-View",
- ImageType = _textureCreateDescriptor.ImageType,
+ TextureType = _textureCreateDescriptor.TextureType,
MinLayer = 0,
NumLayers = _textureCreateDescriptor.ArrayLayers + 1,
MinLevel = 0,
@@ -122,7 +123,7 @@ public TextureView CreateTextureView(SwizzleMapping swizzleMapping)
{
Format = _textureCreateDescriptor.Format,
Label = _textureCreateDescriptor.Label + "-View",
- ImageType = _textureCreateDescriptor.ImageType,
+ TextureType = _textureCreateDescriptor.TextureType,
MinLayer = 0,
NumLayers = _textureCreateDescriptor.ArrayLayers + 1,
MinLevel = 0,
diff --git a/src/EngineKit/Graphics/TextureCreateDescriptor.cs b/src/EngineKit/Graphics/TextureCreateDescriptor.cs
index 5711657..c1872b6 100644
--- a/src/EngineKit/Graphics/TextureCreateDescriptor.cs
+++ b/src/EngineKit/Graphics/TextureCreateDescriptor.cs
@@ -1,20 +1,13 @@
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
-public record struct TextureCreateDescriptor
-{
- public ImageType ImageType;
-
- public Format Format;
-
- public Int3 Size;
-
- public uint MipLevels;
-
- public uint ArrayLayers;
-
- public TextureSampleCount TextureSampleCount;
-
- public string? Label;
-}
\ No newline at end of file
+public record struct TextureCreateDescriptor(
+ TextureType TextureType,
+ Format Format,
+ Int3 Size,
+ uint MipLevels,
+ uint ArrayLayers,
+ TextureSampleCount TextureSampleCount,
+ string? Label);
diff --git a/src/EngineKit/Graphics/TextureUpdateDescriptor.cs b/src/EngineKit/Graphics/TextureUpdateDescriptor.cs
index 3e185a2..3cdf795 100644
--- a/src/EngineKit/Graphics/TextureUpdateDescriptor.cs
+++ b/src/EngineKit/Graphics/TextureUpdateDescriptor.cs
@@ -1,3 +1,4 @@
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/TextureView.cs b/src/EngineKit/Graphics/TextureView.cs
index 4292c64..db9bcc2 100644
--- a/src/EngineKit/Graphics/TextureView.cs
+++ b/src/EngineKit/Graphics/TextureView.cs
@@ -1,5 +1,6 @@
using System;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
@@ -19,7 +20,7 @@ internal TextureView(
Depth = texture.TextureCreateDescriptor.Size.Z;
GL.TextureView(
_id,
- textureViewDescriptor.ImageType.ToGL(),
+ textureViewDescriptor.TextureType.ToGL(),
texture.Id,
textureViewDescriptor.Format.ToGL(),
textureViewDescriptor.MinLevel,
diff --git a/src/EngineKit/Graphics/TextureViewDescriptor.cs b/src/EngineKit/Graphics/TextureViewDescriptor.cs
index b016e9d..fe2b929 100644
--- a/src/EngineKit/Graphics/TextureViewDescriptor.cs
+++ b/src/EngineKit/Graphics/TextureViewDescriptor.cs
@@ -1,8 +1,10 @@
+using EngineKit.Graphics.RHI;
+
namespace EngineKit.Graphics;
public record struct TextureViewDescriptor
{
- public ImageType ImageType;
+ public TextureType TextureType;
public Format Format;
diff --git a/src/EngineKit/Graphics/TypedBuffer.cs b/src/EngineKit/Graphics/TypedBuffer.cs
index f3ec49d..8bba006 100644
--- a/src/EngineKit/Graphics/TypedBuffer.cs
+++ b/src/EngineKit/Graphics/TypedBuffer.cs
@@ -1,4 +1,6 @@
+using EngineKit.Core;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/Graphics/VertexInputDescriptor.cs b/src/EngineKit/Graphics/VertexInputDescriptor.cs
index fef006d..7745f1f 100644
--- a/src/EngineKit/Graphics/VertexInputDescriptor.cs
+++ b/src/EngineKit/Graphics/VertexInputDescriptor.cs
@@ -4,7 +4,9 @@
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
+using EngineKit.Core;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using ImGuiNET;
namespace EngineKit.Graphics;
@@ -15,7 +17,7 @@ public readonly record struct VertexInputDescriptor(VertexInputBindingDescriptor
private static readonly IDictionary _fieldTypeToNormalizedMapping;
private static readonly IDictionary _fieldTypeToComponentCountMapping;
private static readonly IDictionary _fieldTypeToDataTypeMapping;
-
+
public readonly VertexInputBindingDescriptor[]? VertexBindingDescriptors = VertexBindingDescriptors;
public readonly Label Label = Label;
@@ -48,13 +50,13 @@ static VertexInputDescriptor()
};
_vertexTypeToVertexInputDescriptorMapping = new Dictionary
{
- { VertexType.Position, BuildVertexInputDescriptorFor() },
- { VertexType.PositionColor, BuildVertexInputDescriptorFor() },
- { VertexType.PositionColorUv, BuildVertexInputDescriptorFor() },
- { VertexType.PositionNormal, BuildVertexInputDescriptorFor() },
- { VertexType.PositionNormalUv, BuildVertexInputDescriptorFor() },
- { VertexType.PositionNormalUvTangent, BuildVertexInputDescriptorFor() },
- { VertexType.Default, BuildVertexInputDescriptorFor() },
+ { VertexType.Position, BuildVertexInputDescriptorFor() },
+ { VertexType.PositionColor, BuildVertexInputDescriptorFor() },
+ { VertexType.PositionColorUv, BuildVertexInputDescriptorFor() },
+ { VertexType.PositionNormal, BuildVertexInputDescriptorFor() },
+ { VertexType.PositionNormalUv, BuildVertexInputDescriptorFor() },
+ { VertexType.PositionNormalUvTangent, BuildVertexInputDescriptorFor() },
+ { VertexType.Default, BuildVertexInputDescriptorFor() },
{ VertexType.ImGui, BuildVertexInputDescriptorFor() }
};
}
@@ -76,7 +78,7 @@ public override int GetHashCode()
{
return hashCode;
}
-
+
foreach (var vertexBindingDescriptor in VertexBindingDescriptors)
{
hashCode = HashCode.Combine(
@@ -140,7 +142,7 @@ private static bool GetNormalizedFromFieldType(Type fieldType)
{
return isNormalized;
}
-
+
throw new ArgumentOutOfRangeException($"FieldType {fieldType.Name} has no normalized mapping");
}
@@ -150,7 +152,7 @@ private static DataType GetDataTypeFromFieldType(Type fieldType)
{
return dataType;
}
-
+
throw new ArgumentOutOfRangeException($"FieldType {fieldType.Name} has no data type mapping");
}
@@ -163,4 +165,4 @@ private static int GetComponentCountFromFieldType(Type fieldType)
throw new ArgumentOutOfRangeException($"FieldType {fieldType.Name} has no component count mapping");
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Graphics/VertexInputDescriptorBuilder.cs b/src/EngineKit/Graphics/VertexInputDescriptorBuilder.cs
index 59425fc..c2f488b 100644
--- a/src/EngineKit/Graphics/VertexInputDescriptorBuilder.cs
+++ b/src/EngineKit/Graphics/VertexInputDescriptorBuilder.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using EngineKit.Core;
using EngineKit.Extensions;
+using EngineKit.Graphics.RHI;
using EngineKit.Native.OpenGL;
namespace EngineKit.Graphics;
diff --git a/src/EngineKit/GraphicsApplication.cs b/src/EngineKit/GraphicsApplication.cs
index 8b044a3..0f84e83 100644
--- a/src/EngineKit/GraphicsApplication.cs
+++ b/src/EngineKit/GraphicsApplication.cs
@@ -1,4 +1,5 @@
using System.Numerics;
+using EngineKit.Core;
using EngineKit.Graphics;
using EngineKit.Input;
using EngineKit.Native.OpenGL;
@@ -17,22 +18,27 @@ protected GraphicsApplication(
ILogger logger,
IOptions windowSettings,
IOptions contextSettings,
+ IMessageBus messageBus,
IApplicationContext applicationContext,
ICapabilities capabilities,
IMetrics metrics,
IInputProvider inputProvider,
IGraphicsContext graphicsContext,
+ IRenderer renderer,
IUIRenderer uiRenderer)
- : base(logger, windowSettings, contextSettings, applicationContext, capabilities, metrics, inputProvider)
+ : base(logger, windowSettings, contextSettings, applicationContext, messageBus, capabilities, metrics, inputProvider)
{
_logger = logger;
_applicationContext = applicationContext;
+ Renderer = renderer;
GraphicsContext = graphicsContext;
UIRenderer = uiRenderer;
}
protected IGraphicsContext GraphicsContext { get; }
+ protected IRenderer Renderer { get; }
+
protected IUIRenderer UIRenderer { get; }
protected override bool OnLoad()
@@ -43,7 +49,12 @@ protected override bool OnLoad()
return false;
}
- if (!UIRenderer.Load(_applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y))
+ if (!Renderer.Load())
+ {
+ return false;
+ }
+
+ if (!UIRenderer.Load())
{
return false;
}
@@ -64,17 +75,28 @@ protected override bool OnLoad()
protected override void OnUnload()
{
+ Renderer.Dispose();
UIRenderer.Dispose();
GraphicsContext.Dispose();
base.OnUnload();
}
+ protected override void OnRender(float deltaTime, float elapsedSeconds)
+ {
+ Renderer.Render(deltaTime, elapsedSeconds);
+
+ UIRenderer.BeginLayout();
+ Renderer.RenderUi(deltaTime, elapsedSeconds);
+ UIRenderer.EndLayout();
+ }
+
protected override void OnUpdate(float deltaTime, float elapsedSeconds)
{
if (_applicationContext.HasWindowFramebufferSizeChanged)
{
UIRenderer.ResizeWindow(_applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y);
}
+
UIRenderer.Update(deltaTime);
}
@@ -87,4 +109,10 @@ protected override void OnCharacterInput(char codePoint)
{
UIRenderer.CharacterInput(codePoint);
}
+
+ protected override void OnWindowResized()
+ {
+ base.OnWindowResized();
+ Renderer.WindowFramebufferResized();
+ }
}
diff --git a/src/EngineKit/HashHelper.cs b/src/EngineKit/HashHelper.cs
deleted file mode 100644
index 5a88e9b..0000000
--- a/src/EngineKit/HashHelper.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace EngineKit;
-
-public static class HashHelper
-{
- public static uint XxHash(uint p)
- {
- const uint PRIME32_2 = 2246822519U, PRIME32_3 = 3266489917U;
- const uint PRIME32_4 = 668265263U, PRIME32_5 = 374761393U;
-
- uint h32 = p + PRIME32_5;
- h32 = PRIME32_4 * ((h32 << 17) | (h32 >> (32 - 17)));
- h32 = PRIME32_2 * (h32 ^ (h32 >> 15));
- h32 = PRIME32_3 * (h32 ^ (h32 >> 13));
-
- return h32 ^ (h32 >> 16);
- }
-}
\ No newline at end of file
diff --git a/src/EngineKit/IApplicationContext.cs b/src/EngineKit/IApplicationContext.cs
index f75c107..c3d47dc 100644
--- a/src/EngineKit/IApplicationContext.cs
+++ b/src/EngineKit/IApplicationContext.cs
@@ -14,13 +14,13 @@ public interface IApplicationContext
Int2 WindowFramebufferSize { get; }
- Int2 WindowScaledFramebufferSize { get; }
+ Int2 ScaledWindowFramebufferSize { get; }
bool HasWindowFramebufferSizeChanged { get; set; }
Int2 SceneViewSize { get; }
- Int2 SceneViewScaledSize { get; }
+ Int2 ScaledSceneViewSize { get; }
bool HasSceneViewSizeChanged { get; set; }
diff --git a/src/EngineKit/ICapabilities.cs b/src/EngineKit/ICapabilities.cs
index 4ba37be..f549b55 100644
--- a/src/EngineKit/ICapabilities.cs
+++ b/src/EngineKit/ICapabilities.cs
@@ -8,6 +8,8 @@ public interface ICapabilities
bool SupportsMeshShader { get; }
+ bool SupportsNvx { get; }
+
bool IsIntelRenderer { get; }
bool IsNvidiaRenderer { get; }
@@ -30,7 +32,5 @@ public interface ICapabilities
int GetCurrentAvailableGpuMemoryInMebiBytes();
- bool SupportsNvx { get; }
-
bool Load();
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/IGame.cs b/src/EngineKit/IGame.cs
new file mode 100644
index 0000000..58cd0b7
--- /dev/null
+++ b/src/EngineKit/IGame.cs
@@ -0,0 +1,8 @@
+namespace EngineKit;
+
+public interface IGame
+{
+ bool Load();
+
+ void Unload();
+}
diff --git a/src/EngineKit/InterpolationHelper.cs b/src/EngineKit/Mathematics/Interpolation.cs
similarity index 94%
rename from src/EngineKit/InterpolationHelper.cs
rename to src/EngineKit/Mathematics/Interpolation.cs
index 28d58e1..d989b1d 100644
--- a/src/EngineKit/InterpolationHelper.cs
+++ b/src/EngineKit/Mathematics/Interpolation.cs
@@ -2,15 +2,15 @@
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace EngineKit;
+namespace EngineKit.Mathematics;
-public static class InterpolationHelper
+public static class Interpolation
{
public static float Fade(float t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
-
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Lerp(float a, float b, float t)
{
@@ -39,7 +39,7 @@ public static float Step(float edge, float value)
{
return value < edge ? 0.0f : (float)1.0;
}
-
+
public static Vector3 Step(float edge, Vector3 value)
{
return new Vector3(
@@ -47,4 +47,4 @@ public static Vector3 Step(float edge, Vector3 value)
value.Y < edge ? 0.0f : 1.0f,
value.Z < edge ? 0.0f : 1.0f);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/MathUtils.cs b/src/EngineKit/Mathematics/MathUtils.cs
similarity index 98%
rename from src/EngineKit/MathUtils.cs
rename to src/EngineKit/Mathematics/MathUtils.cs
index 216db00..6bbf0c0 100755
--- a/src/EngineKit/MathUtils.cs
+++ b/src/EngineKit/Mathematics/MathUtils.cs
@@ -2,7 +2,7 @@
using System.Numerics;
using System.Runtime.CompilerServices;
-namespace EngineKit;
+namespace EngineKit.Mathematics;
public static class MathUtils
{
@@ -79,7 +79,7 @@ public static float RemapAndClamp(float value, float inMin, float inMax, float o
var v = factor * (outMax - outMin) + outMin;
if (outMin > outMax)
{
- Helper.Swap(ref outMin, ref outMax);
+ Swapper.Swap(ref outMin, ref outMax);
}
return v.Clamp(outMin, outMax);
}
diff --git a/src/EngineKit/NoiseHelper.cs b/src/EngineKit/Mathematics/Noise/NoiseHelper.cs
similarity index 78%
rename from src/EngineKit/NoiseHelper.cs
rename to src/EngineKit/Mathematics/Noise/NoiseHelper.cs
index 81c2b2e..69a504d 100644
--- a/src/EngineKit/NoiseHelper.cs
+++ b/src/EngineKit/Mathematics/Noise/NoiseHelper.cs
@@ -1,6 +1,6 @@
using System;
-namespace EngineKit;
+namespace EngineKit.Mathematics.Noise;
public static class NoiseHelper
{
@@ -15,8 +15,8 @@ public static float PerlinNoise(float value, float period, int octaves, int seed
var v = value * frequency + seed * 12.468f;
var a = Noise((int)v, seed);
var b = Noise((int)v + 1, seed);
- var t = InterpolationHelper.Fade(v - (float)Math.Floor(v));
- noiseSum += InterpolationHelper.Lerp(a, b, t) * amplitude;
+ var t = Interpolation.Fade(v - (float)Math.Floor(v));
+ noiseSum += Interpolation.Lerp(a, b, t) * amplitude;
frequency *= 2;
amplitude *= 0.5f;
}
@@ -26,9 +26,8 @@ public static float PerlinNoise(float value, float period, int octaves, int seed
private static float Noise(int x, int seed)
{
- int n = x + seed * 137;
+ var n = x + seed * 137;
n = (n << 13) ^ n;
return (float)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
-
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Helper.cs b/src/EngineKit/Mathematics/Swapper.cs
similarity index 57%
rename from src/EngineKit/Helper.cs
rename to src/EngineKit/Mathematics/Swapper.cs
index 5c9bb5a..6840297 100755
--- a/src/EngineKit/Helper.cs
+++ b/src/EngineKit/Mathematics/Swapper.cs
@@ -1,9 +1,9 @@
-namespace EngineKit;
+namespace EngineKit.Mathematics;
-public static class Helper
+public static class Swapper
{
public static void Swap(ref T a, ref T b)
{
(a, b) = (b, a);
}
-}
\ No newline at end of file
+}
diff --git a/src/EngineKit/Messages/CloseWindowMessage.cs b/src/EngineKit/Messages/CloseWindowMessage.cs
deleted file mode 100644
index e20cb7d..0000000
--- a/src/EngineKit/Messages/CloseWindowMessage.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace EngineKit.Messages;
-
-public struct CloseWindowMessage;
\ No newline at end of file
diff --git a/src/EngineKit/Native/OpenGL/GL.cs b/src/EngineKit/Native/OpenGL/GL.cs
index 5335553..ea98865 100644
--- a/src/EngineKit/Native/OpenGL/GL.cs
+++ b/src/EngineKit/Native/OpenGL/GL.cs
@@ -2,7 +2,7 @@
using System.Numerics;
using System.Runtime.InteropServices;
using EngineKit.Extensions;
-using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using EngineKit.Mathematics;
// ReSharper disable InconsistentNaming
diff --git a/src/EngineKit/UI/CurvePlot.cs b/src/EngineKit/UI/CurvePlot.cs
index 03745fd..aa66f9a 100644
--- a/src/EngineKit/UI/CurvePlot.cs
+++ b/src/EngineKit/UI/CurvePlot.cs
@@ -1,4 +1,5 @@
-using ImGuiNET;
+using EngineKit.Mathematics;
+using ImGuiNET;
namespace EngineKit.UI;
@@ -28,7 +29,7 @@ public void Draw(float value)
_graphValues[_sampleOffset] = value;
if (Damping)
{
- _dampedValue = InterpolationHelper.Lerp(_dampedValue, value, 0.01f);
+ _dampedValue = Interpolation.Lerp(_dampedValue, value, 0.01f);
value = _dampedValue;
}
diff --git a/src/EngineKit/UI/UIRenderer.cs b/src/EngineKit/UI/UIRenderer.cs
index 5416a4c..dd5da3f 100644
--- a/src/EngineKit/UI/UIRenderer.cs
+++ b/src/EngineKit/UI/UIRenderer.cs
@@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using EngineKit.Graphics;
+using EngineKit.Graphics.RHI;
using EngineKit.Input;
using EngineKit.Mathematics;
using EngineKit.Native.Glfw;
@@ -65,6 +66,7 @@ void main()
private static readonly unsafe uint ImDrawVertStride = (uint)sizeof(ImDrawVert);
private readonly ILogger _logger;
+ private readonly IApplicationContext _applicationContext;
private readonly IGraphicsContext _graphicsContext;
private readonly IInputProvider _inputProvider;
@@ -97,10 +99,12 @@ void main()
public UIRenderer(
ILogger logger,
+ IApplicationContext applicationContext,
IGraphicsContext graphicsContext,
IInputProvider inputProvider)
{
_logger = logger.ForContext();
+ _applicationContext = applicationContext;
_graphicsContext = graphicsContext;
_inputProvider = inputProvider;
_keyValues = Array.Empty();
@@ -129,10 +133,10 @@ public bool AddFont(string name, string filePath, float fontSize)
return true;
}
- public bool Load(int width, int height)
+ public bool Load()
{
- _framebufferWidth = width;
- _framebufferHeight = height;
+ _framebufferWidth = _applicationContext.WindowFramebufferSize.X;
+ _framebufferHeight = _applicationContext.WindowFramebufferSize.Y;
_keyValues = Enum.GetValuesAsUnderlyingType();
@@ -274,7 +278,7 @@ public void BeginLayout()
{
_frameBegun = true;
ImGui.NewFrame();
- ImGui.DockSpaceOverViewport(null, ImGuiDockNodeFlags.PassthruCentralNode);
+ ImGui.DockSpaceOverViewport(0, null, ImGuiDockNodeFlags.PassthruCentralNode);
}
public void EndLayout()
@@ -284,6 +288,7 @@ public void EndLayout()
_frameBegun = false;
ImGui.Render();
GL.Disable(GL.EnableType.FramebufferSrgb);
+ GL.Viewport(new Int4(0, 0, _applicationContext.WindowFramebufferSize.X, _applicationContext.WindowFramebufferSize.Y));
RenderDrawData(ImGui.GetDrawData());
GL.Enable(GL.EnableType.FramebufferSrgb);
}
@@ -309,7 +314,7 @@ private void RecreateFontDeviceTexture()
{
Size = new Int3(width, height, 1),
Format = Format.R8G8B8A8UNorm,
- ImageType = ImageType.Texture2D,
+ TextureType = TextureType.Texture2D,
Label = "ImGuiFontAtlas",
ArrayLayers = 0,
MipLevels = 1,
@@ -577,7 +582,7 @@ public void Dispose()
DestroyDeviceObjects();
}
- private void SetStyleBlack(ImGuiStylePtr style)
+ private static void SetStyleBlack(ImGuiStylePtr style)
{
ImGui.StyleColorsDark();
style.Colors[(int)ImGuiCol.Text] = new Vector4(1.00f, 1.00f, 1.00f, 1.00f);
@@ -615,9 +620,9 @@ private void SetStyleBlack(ImGuiStylePtr style)
style.Colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.40f, 0.44f, 0.47f, 1.00f);
style.Colors[(int)ImGuiCol.Tab] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
style.Colors[(int)ImGuiCol.TabHovered] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
- style.Colors[(int)ImGuiCol.TabActive] = new Vector4(0.20f, 0.20f, 0.20f, 0.36f);
- style.Colors[(int)ImGuiCol.TabUnfocused] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
- style.Colors[(int)ImGuiCol.TabUnfocusedActive] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
+ style.Colors[(int)ImGuiCol.TabSelected] = new Vector4(0.20f, 0.20f, 0.20f, 0.36f);
+ style.Colors[(int)ImGuiCol.TabDimmedSelected] = new Vector4(0.00f, 0.00f, 0.00f, 0.52f);
+ style.Colors[(int)ImGuiCol.TabDimmed] = new Vector4(0.14f, 0.14f, 0.14f, 1.00f);
style.Colors[(int)ImGuiCol.DockingPreview] = new Vector4(0.33f, 0.67f, 0.86f, 1.00f);
style.Colors[(int)ImGuiCol.DockingEmptyBg] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
style.Colors[(int)ImGuiCol.PlotLines] = new Vector4(1.00f, 0.00f, 0.00f, 1.00f);
@@ -637,7 +642,7 @@ private void SetStyleBlack(ImGuiStylePtr style)
style.Colors[(int)ImGuiCol.ModalWindowDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.35f);
}
- private void SetStylePurple(ImGuiStylePtr style)
+ private static void SetStylePurple(ImGuiStylePtr style)
{
style.Colors[(int)ImGuiCol.Text] = new Vector4(1.00f, 1.00f, 1.00f, 1.00f);
style.Colors[(int)ImGuiCol.TextDisabled] = new Vector4(0.50f, 0.50f, 0.50f, 1.00f);
@@ -674,9 +679,9 @@ private void SetStylePurple(ImGuiStylePtr style)
style.Colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.35f, 0.33f, 0.41f, 0.74f);
style.Colors[(int)ImGuiCol.Tab] = new Vector4(0.24f, 0.22f, 0.33f, 1.00f);
style.Colors[(int)ImGuiCol.TabHovered] = new Vector4(0.38f, 0.34f, 0.53f, 1.00f);
- style.Colors[(int)ImGuiCol.TabActive] = new Vector4(0.24f, 0.22f, 0.33f, 1.00f);
- style.Colors[(int)ImGuiCol.TabUnfocused] = new Vector4(0.27f, 0.26f, 0.32f, 0.40f);
- style.Colors[(int)ImGuiCol.TabUnfocusedActive] = new Vector4(0.42f, 0.39f, 0.57f, 0.40f);
+ style.Colors[(int)ImGuiCol.TabSelected] = new Vector4(0.24f, 0.22f, 0.33f, 1.00f);
+ style.Colors[(int)ImGuiCol.TabDimmed] = new Vector4(0.27f, 0.26f, 0.32f, 0.40f);
+ style.Colors[(int)ImGuiCol.TabDimmedSelected] = new Vector4(0.42f, 0.39f, 0.57f, 0.40f);
//style.Colors[(int)ImGuiCol.TabUnfocusedBorder] = new Vector4(0.11f, 0.09f, 0.17f, 1.00f);
style.Colors[(int)ImGuiCol.DockingPreview] = new Vector4(0.58f, 0.54f, 0.80f, 0.78f);
style.Colors[(int)ImGuiCol.DockingEmptyBg] = new Vector4(0.12f, 0.11f, 0.14f, 1.00f);
@@ -702,7 +707,7 @@ private void SetStylePurple(ImGuiStylePtr style)
style.AntiAliasedLinesUseTex = false;
}
- private void SetStyleDarker(ImGuiStylePtr style)
+ private static void SetStyleDarker(ImGuiStylePtr style)
{
style.WindowPadding = new Vector2(12, 12);
style.WindowRounding = 5.0f;
diff --git a/src/EngineKit/WindowSettings.cs b/src/EngineKit/WindowSettings.cs
index 56a5233..aaa3ff2 100644
--- a/src/EngineKit/WindowSettings.cs
+++ b/src/EngineKit/WindowSettings.cs
@@ -13,4 +13,4 @@ public class WindowSettings
public bool IsVsyncEnabled { get; set; }
public string Title { get; set; } = "EngineKit";
-}
\ No newline at end of file
+}