update
This commit is contained in:
parent
71b06fbb0e
commit
0c374728fd
1 changed files with 13 additions and 8 deletions
21
skr/skr.h
21
skr/skr.h
|
|
@ -1206,20 +1206,28 @@ static inline int SkrShouldClose(SkrState* s) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void m_skr_gl_mesh_init(SkrMesh* m, SkrVertex* vertices,
|
static inline void m_skr_gl_mesh_init(SkrMesh* m) {
|
||||||
size_t size) {
|
if (!m) {
|
||||||
if (!vertices || size == 0) {
|
|
||||||
m_skr_last_error_set("missing vertices or size");
|
m_skr_last_error_set("missing vertices or size");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenVertexArrays(1, &m->VAO);
|
glGenVertexArrays(1, &m->VAO);
|
||||||
glGenBuffers(1, &m->VBO);
|
glGenBuffers(1, &m->VBO);
|
||||||
|
glGenBuffers(1, &m->EBO);
|
||||||
|
|
||||||
glBindVertexArray(m->VAO);
|
glBindVertexArray(m->VAO);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m->VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, m->VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, m->VertexCount * sizeof(SkrVertex),
|
||||||
|
m->Vertices, GL_STATIC_DRAW);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->EBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
|
||||||
|
m->IndexCount * sizeof(unsigned int), m->Indices,
|
||||||
|
GL_STATIC_DRAW);
|
||||||
|
|
||||||
// position
|
// position
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SkrVertex),
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(SkrVertex),
|
||||||
(void*)0);
|
(void*)0);
|
||||||
|
|
@ -1252,10 +1260,7 @@ static inline void m_skr_gl_renderer_init(SkrState* s) {
|
||||||
SkrModel* model = &s->Models[i];
|
SkrModel* model = &s->Models[i];
|
||||||
for (int j = 0; j < model->MeshCount; j++) {
|
for (int j = 0; j < model->MeshCount; j++) {
|
||||||
SkrMesh* mesh = &model->Meshes[j];
|
SkrMesh* mesh = &model->Meshes[j];
|
||||||
|
m_skr_gl_mesh_init(mesh);
|
||||||
m_skr_gl_mesh_init(mesh, mesh->Vertices,
|
|
||||||
mesh->VertexCount *
|
|
||||||
sizeof(SkrVertex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue