188 if (handle ==
nullptr)
return;
191 auto position = handle->AttributeLocation(
"att.position");
192 auto normal = handle->AttributeLocation(
"att.normal");
193 auto jointId = handle->AttributeLocation(
"att.joint_indices");
194 auto weight = handle->AttributeLocation(
"att.weight");
195 auto textureCoord = handle->AttributeLocation(
"att.tex_uv");
196 auto color = handle->AttributeLocation(
"att.color");
198 auto view = handle->UniformLocation(
"matrix.view");
199 auto model = handle->UniformLocation(
"matrix.model");
200 auto cameraPosition = handle->UniformLocation(
"vec3.camera");
201 auto projection = handle->UniformLocation(
"matrix.projection");
202 auto projectionInv = handle->UniformLocation(
"matrix.projection.inv");
203 auto viewInv = handle->UniformLocation(
"matrix.view.inv");
204 auto skinningMode = handle->UniformLocation(
"matrix.skinning_mode");
205 auto jointMatrix = handle->UniformLocation(
"matrix.joint");
206 auto lightPosition = handle->UniformLocation(
"light.position");
207 auto lightType = handle->UniformLocation(
"light.type");
208 auto lightRadius = handle->UniformLocation(
"light.radius");
209 auto lightColor = handle->UniformLocation(
"light.color");
210 auto lightShadowMap = handle->UniformLocation(
"light.shadow_map");
211 auto lightMatrix = handle->UniformLocation(
"light.matrix");
212 auto lightShadowMode = handle->UniformLocation(
"light.shadow_mode");
213 auto lightSize = handle->UniformLocation(
"light.size");
214 auto lightIrradiance = handle->UniformLocation(
"light.irradiance");
215 auto lightPrefilter = handle->UniformLocation(
"light.prefilter");
216 auto lightBrdf = handle->UniformLocation(
"light.brdf");
217 auto srcBuffer = handle->UniformLocation(
"buffer.source");
218 auto srcBufferSize = handle->UniformLocation(
"buffer.source.size");
219 auto sdfEnvSize = handle->UniformLocation(
"sdf.env.size");
220 auto sdfCellSize = handle->UniformLocation(
"sdf.cell.size");
221 auto sdfNodeSize = handle->UniformLocation(
"sdf.node.size");
222 auto sdfNodeSpace = handle->UniformLocation(
"sdf.node.space");
223 auto sdfFrameCount = handle->UniformLocation(
"sdf.frame.count");
224 auto sdfMap = handle->UniformLocation(
"texture.sdfmap");
226 handle->Attributes.Position = position !=
nullptr ? position->id : HANDLE_NULL;
227 handle->Attributes.Normal = normal !=
nullptr ? normal->id : HANDLE_NULL;
228 handle->Attributes.JointId = jointId !=
nullptr ? jointId->id : HANDLE_NULL;
229 handle->Attributes.Weight = weight !=
nullptr ? weight->id : HANDLE_NULL;
230 handle->Attributes.TextureCoord = textureCoord !=
nullptr ? textureCoord->id : HANDLE_NULL;
231 handle->Attributes.Color = color !=
nullptr ? color->id : HANDLE_NULL;
233 handle->Uniforms.ViewMatrix = view !=
nullptr ? view->id : HANDLE_NULL;
234 handle->Uniforms.ModelMatrix = model !=
nullptr ? model->id : HANDLE_NULL;
235 handle->Uniforms.CameraPosition = cameraPosition !=
nullptr ? cameraPosition->id : HANDLE_NULL;
236 handle->Uniforms.ProjectionMatrix = projection !=
nullptr ? projection->id : HANDLE_NULL;
237 handle->Uniforms.ProjectionInvMatrix = projectionInv !=
nullptr ? projectionInv->id : HANDLE_NULL;
238 handle->Uniforms.ViewInvMatrix = viewInv !=
nullptr ? viewInv->id : HANDLE_NULL;
239 handle->Uniforms.SkinningMode = skinningMode !=
nullptr ? skinningMode->id : HANDLE_NULL;
240 handle->Uniforms.JointMatrix = jointMatrix !=
nullptr ? jointMatrix->id : HANDLE_NULL;
241 handle->Uniforms.LightPosition = lightPosition !=
nullptr ? lightPosition->id : HANDLE_NULL;
242 handle->Uniforms.LightType = lightType !=
nullptr ? lightType->id : HANDLE_NULL;
243 handle->Uniforms.LightRadius = lightRadius !=
nullptr ? lightRadius->id : HANDLE_NULL;
244 handle->Uniforms.LightColor = lightColor !=
nullptr ? lightColor->id : HANDLE_NULL;
245 handle->Uniforms.LightShadowMap = lightShadowMap !=
nullptr ? lightShadowMap->id : HANDLE_NULL;
246 handle->Uniforms.LightMatrix = lightMatrix !=
nullptr ? lightMatrix->id : HANDLE_NULL;
247 handle->Uniforms.LightShadowMode = lightShadowMode !=
nullptr ? lightShadowMode->id : HANDLE_NULL;
248 handle->Uniforms.LightSize = lightSize !=
nullptr ? lightSize->id : HANDLE_NULL;
249 handle->Uniforms.LightIrradiance = lightIrradiance !=
nullptr ? lightIrradiance->id : HANDLE_NULL;
250 handle->Uniforms.LightPrefilter = lightPrefilter !=
nullptr ? lightPrefilter->id : HANDLE_NULL;
251 handle->Uniforms.LightBrdfLut = lightBrdf !=
nullptr ? lightBrdf->id : HANDLE_NULL;
252 handle->Uniforms.SourceBuffer = srcBuffer !=
nullptr ? srcBuffer->id : HANDLE_NULL;
253 handle->Uniforms.SourceBufferSize = srcBufferSize !=
nullptr ? srcBufferSize->id : HANDLE_NULL;
254 handle->Uniforms.SdfEnvSize = sdfEnvSize !=
nullptr ? sdfEnvSize->id : HANDLE_NULL;
255 handle->Uniforms.SdfCellSize = sdfCellSize !=
nullptr ? sdfCellSize->id : HANDLE_NULL;
256 handle->Uniforms.SdfNodeSize = sdfNodeSize !=
nullptr ? sdfNodeSize->id : HANDLE_NULL;
257 handle->Uniforms.SdfNodeSpace = sdfNodeSpace !=
nullptr ? sdfNodeSpace->id : HANDLE_NULL;
258 handle->Uniforms.SdfFrameCount = sdfFrameCount !=
nullptr ? sdfFrameCount->id : HANDLE_NULL;
259 handle->Uniforms.SdfMap = sdfMap !=
nullptr ? sdfMap->id : HANDLE_NULL;
263 const mat4& projection,
const mat4& transform) {
264 if(handle.Uniforms.ViewMatrix >= 0)
265 glUniformMatrix4fv(handle.Uniforms.ViewMatrix, 1, 0, view.Pointer());
266 if(handle.Uniforms.ModelMatrix >= 0)
267 glUniformMatrix4fv(handle.Uniforms.ModelMatrix, 1, 0, transform.Pointer());
268 if(handle.Uniforms.ProjectionMatrix >= 0)
269 glUniformMatrix4fv(handle.Uniforms.ProjectionMatrix, 1, 0, projection.Pointer());
270 if(handle.Uniforms.CameraPosition >= 0)
271 glUniform3fv(handle.Uniforms.CameraPosition, 1, cameraPosition.Pointer());
273 if(handle.Uniforms.ProjectionInvMatrix >= 0)
274 glUniformMatrix4fv(handle.Uniforms.ProjectionInvMatrix, 1, 0, mat4::Invert(projection).Pointer());
275 if(handle.Uniforms.ViewInvMatrix >= 0)
276 glUniformMatrix4fv(handle.Uniforms.ViewInvMatrix, 1, 0, mat4::Invert(view).Pointer());
281 int stride = 4 *
sizeof(
vec3) +
sizeof(
vec2);
290 const std::vector<Attribute> attributes = {
291 { handle.Attributes.Position, 0, 3 },
292 { handle.Attributes.Normal,
sizeof(
vec3), 3 },
293 { handle.Attributes.TextureCoord, 2 *
sizeof(
vec3), 2 },
294 { handle.Attributes.Weight, 2 *
sizeof(
vec3) +
sizeof(
vec2), 3 },
295 { handle.Attributes.JointId, 3 *
sizeof(
vec3) +
sizeof(
vec2), 3 },
299 glBindVertexArray(meshId.m_vertexArray);
300 glBindBuffer(GL_ARRAY_BUFFER, meshId.m_vertexBuffer);
301 for (
const auto& attribute: attributes) {
302 if (attribute.id < 0)
continue;
303 glEnableVertexAttribArray(attribute.id);
304 glVertexAttribPointer(attribute.id, attribute.size, GL_FLOAT, GL_FALSE, stride, (GLvoid*) attribute.offset);
308 if (meshId.m_indexSize < 0) {
309 glDrawArrays(GL_TRIANGLES, 0, meshId.m_vertexSize);
311 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshId.m_indexBuffer);
312 glDrawElements(GL_TRIANGLES, meshId.m_indexSize * 3, GL_UNSIGNED_SHORT,
nullptr);
315 for (
const auto& attribute: attributes) {
316 if (attribute.id < 0)
continue;
317 glDisableVertexAttribArray(attribute.id);
319 glBindVertexArray(0);