MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / Initialize

Method Initialize

BindlessDeferred/MeshRenderer.cpp:150–337  ·  view source on GitHub ↗

Loads resources

Source from the content-addressed store, hash-verified

148
149// Loads resources
150void MeshRenderer::Initialize(const Model* model_)
151{
152 model = model_;
153
154 const uint64 numMeshes = model->Meshes().Size();
155 meshBoundingBoxes.Init(numMeshes);
156 meshDrawIndices.Init(numMeshes, uint32(-1));
157 meshZDepths.Init(numMeshes, FloatMax);
158 for(uint64 i = 0; i < numMeshes; ++i)
159 {
160 const Mesh& mesh = model->Meshes()[i];
161 DirectX::BoundingBox& boundingBox = meshBoundingBoxes[i];
162 Float3 extents = (mesh.AABBMax() - mesh.AABBMin()) / 2.0f;
163 Float3 center = mesh.AABBMin() + extents;
164 boundingBox.Center = center.ToXMFLOAT3();
165 boundingBox.Extents = extents.ToXMFLOAT3();
166 }
167
168 meshVSConstants.Initialize(BufferLifetime::Temporary);
169 meshPSConstants.Initialize(BufferLifetime::Temporary);
170 sunShadowConstants.Initialize(BufferLifetime::Temporary);
171
172 LoadShaders();
173
174 sunShadowMap.Initialize(SunShadowMapSize, SunShadowMapSize, DXGI_FORMAT_D32_FLOAT, 1, NumCascades);
175 sunShadowMap.MakeReadable(DX12::CmdList);
176
177 const uint64 numSpotLights = model->SpotLights().Size();
178 spotLightShadowMap.Initialize(SpotLightShadowMapSize, SpotLightShadowMapSize, DXGI_FORMAT_D24_UNORM_S8_UINT, 1, numSpotLights);
179 spotLightShadowMap.MakeReadable(DX12::CmdList);
180
181 {
182 // Spot light shadow matrix buffer
183 StructuredBufferInit sbInit;
184 sbInit.Stride = sizeof(Float4x4);
185 sbInit.NumElements = numSpotLights;
186 sbInit.Dynamic = true;
187 sbInit.Lifetime = BufferLifetime::Persistent;
188 spotLightShadowMatrices.Initialize(sbInit);
189 }
190
191 {
192 // Create a structured buffer containing texture indices per-material
193 const Array<MeshMaterial>& materials = model->Materials();
194 const uint64 numMaterials = materials.Size();
195 Array<MaterialTextureIndices> textureIndices(numMaterials);
196 for(uint64 i = 0; i < numMaterials; ++i)
197 {
198 MaterialTextureIndices& matIndices = textureIndices[i];
199 const MeshMaterial& material = materials[i];
200
201 matIndices.Albedo = material.TextureIndices[uint64(MaterialTextures::Albedo)];
202 matIndices.Normal = material.TextureIndices[uint64(MaterialTextures::Normal)];
203 matIndices.Roughness = material.TextureIndices[uint64(MaterialTextures::Roughness)];
204 matIndices.Metallic = material.TextureIndices[uint64(MaterialTextures::Metallic)];
205 }
206
207 StructuredBufferInit sbInit;

Callers 2

InitializeFunction · 0.45

Calls 7

GetStaticSamplerStateFunction · 0.85
CreateRootSignatureFunction · 0.85
ToXMFLOAT3Method · 0.80
MakeReadableMethod · 0.80
SizeMethod · 0.45
InitMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected