MCPcopy Create free account
hub / github.com/MethanePowered/MethaneKit / Init

Method Init

Apps/04-ShadowCube/ShadowCubeApp.cpp:84–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84void ShadowCubeApp::Init()
85{
86 UserInterfaceApp::Init();
87
88 const rhi::RenderContext& render_context = GetRenderContext();
89 const rhi::CommandQueue render_cmd_queue = render_context.GetRenderCommandKit().GetQueue();
90 const rhi::RenderContextSettings& context_settings = render_context.GetSettings();
91 m_view_camera.Resize(context_settings.frame_size);
92
93 const gfx::Mesh::VertexLayout mesh_layout(Vertex::layout);
94 const gfx::CubeMesh<Vertex> cube_mesh(mesh_layout, 1.F, 1.F, 1.F);
95 const gfx::QuadMesh<Vertex> floor_mesh(mesh_layout, 7.F, 7.F, 0.F, 0, gfx::QuadMesh<Vertex>::FaceType::XZ);
96
97 // Load textures, vertex and index buffers for cube and floor meshes
98 constexpr gfx::ImageOptionMask image_options({ gfx::ImageOption::Mipmapped, gfx::ImageOption::SrgbColorSpace });
99
100 m_cube_buffers_ptr = std::make_unique<TexturedMeshBuffers>(render_cmd_queue, cube_mesh, "Cube");
101 m_cube_buffers_ptr->SetTexture(GetImageLoader().LoadImageToTexture2D(render_cmd_queue, "MethaneBubbles.jpg", image_options, "Cube Face Texture"));
102
103 m_floor_buffers_ptr = std::make_unique<TexturedMeshBuffers>(render_cmd_queue, floor_mesh, "Floor");
104 m_floor_buffers_ptr->SetTexture(GetImageLoader().LoadImageToTexture2D(render_cmd_queue, "MarbleWhite.jpg", image_options, "Floor Texture"));
105
106 // Create sampler for cube and floor textures sampling
107 m_texture_sampler = render_context.CreateSampler(
108 rhi::Sampler::Settings
109 {
110 .filter = rhi::Sampler::Filter { rhi::Sampler::Filter::MinMag::Linear },
111 .address = rhi::Sampler::Address { rhi::Sampler::Address::Mode::ClampToEdge }
112 }
113 );
114 m_texture_sampler.SetName("Texture Sampler");
115
116 // Create sampler for shadow-map texture
117 m_shadow_sampler = render_context.CreateSampler(
118 rhi::Sampler::Settings
119 {
120 .filter = rhi::Sampler::Filter { rhi::Sampler::Filter::MinMag::Linear },
121 .address = rhi::Sampler::Address { rhi::Sampler::Address::Mode::ClampToEdge }
122 }
123 );
124 m_shadow_sampler.SetName("Shadow Map Sampler");
125
126 // ========= Final Pass Render & View States =========
127
128 const rhi::Shader::EntryFunction vs_main{ "ShadowCube", "CubeVS" };
129 const rhi::Shader::EntryFunction ps_main{ "ShadowCube", "CubePS" };
130 const rhi::Shader::MacroDefinitions textured_shadows_definitions{ { "ENABLE_SHADOWS", "" }, { "ENABLE_TEXTURING", "" } };
131
132 // Create final pass rendering state with program
133 rhi::RenderState::Settings final_state_settings
134 {
135 .program = render_context.CreateProgram(
136 rhi::Program::Settings
137 {
138 .shader_set = rhi::Program::ShaderSet
139 {
140 { rhi::ShaderType::Vertex, { Data::ShaderProvider::Get(), vs_main, textured_shadows_definitions } },
141 { rhi::ShaderType::Pixel, { Data::ShaderProvider::Get(), ps_main, textured_shadows_definitions } },

Callers

nothing calls this directly

Calls 15

GetFrameViewportFunction · 0.85
GetFrameScissorRectFunction · 0.85
RootConstantClass · 0.85
GetQueueMethod · 0.80
GetRenderCommandKitMethod · 0.80
LoadImageToTexture2DMethod · 0.80
GetSemanticsMethod · 0.80
ProgramBindingsClass · 0.70
ViewStateClass · 0.50
CommandListSetClass · 0.50
ResizeMethod · 0.45
SetTextureMethod · 0.45

Tested by

no test coverage detected