MCPcopy Create free account
hub / github.com/defold/defold / CreateVertexDeclarations

Function CreateVertexDeclarations

engine/render/src/render/material.cpp:138–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 static void CreateVertexDeclarations(dmGraphics::HContext graphics_context, Material* m)
139 {
140 if (m->m_VertexDeclarationShared != 0)
141 {
142 dmGraphics::DeleteVertexDeclaration(m->m_VertexDeclarationShared);
143 m->m_VertexDeclarationShared = 0;
144 }
145 if (m->m_VertexDeclarationPerVertex != 0)
146 {
147 dmGraphics::DeleteVertexDeclaration(m->m_VertexDeclarationPerVertex);
148 m->m_VertexDeclarationPerVertex = 0;
149 }
150 if (m->m_VertexDeclarationPerInstance != 0)
151 {
152 dmGraphics::DeleteVertexDeclaration(m->m_VertexDeclarationPerInstance);
153 m->m_VertexDeclarationPerInstance = 0;
154 }
155
156 uint32_t num_material_attributes = m->m_MaterialAttributes.Size();
157 bool use_secondary_vertex_declarations = false;
158 bool has_skin_attributes = false;
159
160 // 1. Find out if we need to use secondary vertex and instance declarations
161 for (int i = 0; i < num_material_attributes; ++i)
162 {
163 const dmGraphics::VertexAttributeInfo& graphics_attribute = m->m_VertexAttributeInfos[i];
164 use_secondary_vertex_declarations |= graphics_attribute.m_StepFunction == dmGraphics::VERTEX_STEP_FUNCTION_INSTANCE;
165 has_skin_attributes |= graphics_attribute.m_NameHash == VERTEX_STREAM_BONE_WEIGHTS || graphics_attribute.m_NameHash == VERTEX_STREAM_BONE_INDICES;
166 }
167
168 dmGraphics::HVertexStreamDeclaration sd_shared = dmGraphics::NewVertexStreamDeclaration(graphics_context);
169 dmGraphics::HVertexStreamDeclaration sd_vertex = 0;
170 dmGraphics::HVertexStreamDeclaration sd_instance = 0;
171
172 if (use_secondary_vertex_declarations)
173 {
174 sd_vertex = dmGraphics::NewVertexStreamDeclaration(graphics_context, dmGraphics::VERTEX_STEP_FUNCTION_VERTEX);
175 sd_instance = dmGraphics::NewVertexStreamDeclaration(graphics_context, dmGraphics::VERTEX_STEP_FUNCTION_INSTANCE);
176 }
177
178 m->m_VertexAttributeInfoMetadata = {};
179
180 // 2. Construct all vertex declarations
181 for (int i = 0; i < num_material_attributes; ++i)
182 {
183 const dmGraphics::VertexAttributeInfo& graphics_attribute = m->m_VertexAttributeInfos[i];
184
185 dmGraphics::VertexAttributeInfoMetadataMember(m->m_VertexAttributeInfoMetadata, graphics_attribute.m_SemanticType, graphics_attribute.m_CoordinateSpace);
186
187 #define ADD_VERTEX_STREAM(sd, graphics_attribute) \
188 dmGraphics::AddVertexStream(sd, \
189 graphics_attribute.m_NameHash, \
190 graphics_attribute.m_ElementCount, \
191 dmGraphics::GetGraphicsType(graphics_attribute.m_DataType), \
192 graphics_attribute.m_Normalize);
193
194 ADD_VERTEX_STREAM(sd_shared, graphics_attribute);
195 if (use_secondary_vertex_declarations)

Callers 2

NewMaterialFunction · 0.85

Calls 6

DeleteVertexDeclarationFunction · 0.85
NewVertexDeclarationFunction · 0.85
SizeMethod · 0.45

Tested by

no test coverage detected