shader prog

This commit is contained in:
2026-03-17 17:05:39 -05:00
parent ff92a78dda
commit 66ebcb1608
11 changed files with 303 additions and 140 deletions

View File

@@ -21,7 +21,74 @@ errorret_t meshInitGL(
mesh->primitiveType = primitiveType;
mesh->vertexCount = vertexCount;
mesh->vertices = vertices;
#ifdef DUSK_OPENGL_LEGACY
mesh->vertices = vertices;
#else
// Generate Vertex Buffer Object
glGenBuffers(1, &mesh->vboId);
errorChain(errorGLCheck());
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
glBufferData(
GL_ARRAY_BUFFER,
vertexCount * sizeof(meshvertex_t),
vertices,
GL_STATIC_DRAW
);
errorChain(errorGLCheck());
// Generate Vertex Array Object
glGenVertexArrays(1, &mesh->vaoId);
errorChain(errorGLCheck());
glBindVertexArray(mesh->vaoId);
errorChain(errorGLCheck());
glBindBuffer(GL_ARRAY_BUFFER, mesh->vboId);
errorChain(errorGLCheck());
// Set up vertex attribute pointers
glVertexAttribPointer(
0,
MESH_VERTEX_POS_SIZE,
GL_FLOAT,
GL_FALSE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, pos)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(0);
errorChain(errorGLCheck());
glVertexAttribPointer(
1,
MESH_VERTEX_UV_SIZE,
GL_FLOAT,
GL_FALSE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, uv)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(1);
errorChain(errorGLCheck());
glVertexAttribPointer(
2,
sizeof(color_t) / sizeof(GLubyte),
GL_UNSIGNED_BYTE,
GL_TRUE,
sizeof(meshvertex_t),
(const GLvoid*)offsetof(meshvertex_t, color)
);
errorChain(errorGLCheck());
glEnableVertexAttribArray(2);
errorChain(errorGLCheck());
// Unbind VAO and VBO to prevent accidental modification
glBindBuffer(GL_ARRAY_BUFFER, 0);
errorChain(errorGLCheck());
glBindVertexArray(0);
errorChain(errorGLCheck());
#endif
errorOk();
}
@@ -31,30 +98,40 @@ errorret_t meshDrawGL(
const int32_t offset,
const int32_t count
) {
// PSP style pointer legacy OpenGL
const GLsizei stride = sizeof(meshvertex_t);
#ifdef DUSK_OPENGL_LEGACY
// Legacy pointer style rendering
const GLsizei stride = sizeof(meshvertex_t);
// glColorPointer(
// sizeof(color4b_t),
// GL_UNSIGNED_BYTE,
// stride,
// (const GLvoid*)&mesh->vertices[offset].color
// );
// glTexCoordPointer(
// MESH_VERTEX_UV_SIZE,
// GL_FLOAT,
// stride,
// (const GLvoid*)&mesh->vertices[offset].uv
// );
// glVertexPointer(
// MESH_VERTEX_POS_SIZE,
// GL_FLOAT,
// stride,
// (const GLvoid*)&mesh->vertices[offset].pos
// );
glColorPointer(
sizeof(color4b_t),
GL_UNSIGNED_BYTE,
stride,
(const GLvoid*)&mesh->vertices[offset].color
);
glTexCoordPointer(
MESH_VERTEX_UV_SIZE,
GL_FLOAT,
stride,
(const GLvoid*)&mesh->vertices[offset].uv
);
glVertexPointer(
MESH_VERTEX_POS_SIZE,
GL_FLOAT,
stride,
(const GLvoid*)&mesh->vertices[offset].pos
);
// glDrawArrays(mesh->primitiveType, offset, count);
// errorChain(errorGLCheck());
glDrawArrays(mesh->primitiveType, offset, count);
errorChain(errorGLCheck());
#else
// Modern VAO/VBO rendering
glBindVertexArray(mesh->vaoId);
errorChain(errorGLCheck());
glDrawArrays(mesh->primitiveType, offset, count);
errorChain(errorGLCheck());
glBindVertexArray(0);
errorChain(errorGLCheck());
#endif
errorOk();
}
@@ -64,6 +141,13 @@ int32_t meshGetVertexCountGL(const meshgl_t *mesh) {
}
errorret_t meshDisposeGL(meshgl_t *mesh) {
// No dynamic resources to free for this mesh implementation
#ifdef DUSK_OPENGL_LEGACY
// No dynamic resources to free for this mesh implementation
#else
glDeleteBuffers(1, &mesh->vboId);
errorChain(errorGLCheck());
glDeleteVertexArrays(1, &mesh->vaoId);
errorChain(errorGLCheck());
#endif
errorOk();
}