]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Fix glBufferData size
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 28 Mar 2021 11:11:39 +0000 (13:11 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 28 Mar 2021 11:11:39 +0000 (13:11 +0200)
src/mesh.c
src/mesh.h

index 19102ab09ec741744efc7fb46708266eb92c111f..a4a7ff0a2a0da0085065e343d321ffb6386ce44c 100644 (file)
@@ -12,13 +12,13 @@ Mesh *mesh_create(Vertex *vertices, GLsizei count)
        mesh->VAO = 0;
        mesh->VBO = 0;
        mesh->remove = false;
-       mesh->vertices = (GLfloat *) vertices;
+       mesh->vertices = vertices;
        mesh->count = count;
        return mesh;
 }
 
 #pragma GCC diagnostic push
-#pragma GCC diagnostic warning "-Wpedantic"
+#pragma GCC diagnostic ignored "-Wpedantic"
 
 void mesh_transform(Mesh *mesh)
 {
@@ -48,13 +48,11 @@ static void mesh_configure(Mesh *mesh)
        glBindVertexArray(mesh->VAO);
        glBindBuffer(GL_ARRAY_BUFFER, mesh->VBO);
 
-       glBufferData(GL_ARRAY_BUFFER, mesh->count * 6, mesh->vertices, GL_STATIC_DRAW);
+       glBufferData(GL_ARRAY_BUFFER, mesh->count * sizeof(Vertex), mesh->vertices, GL_STATIC_DRAW);
 
-       GLsizei stride = 6 * sizeof(GLfloat);
-
-       glVertexAttribPointer(0, 3, GL_FLOAT, false, stride, (GLvoid *)(0 * sizeof(GLfloat)));
+       glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(Vertex), (GLvoid *)(0 * sizeof(GLfloat)));
        glEnableVertexAttribArray(0);
-       glVertexAttribPointer(1, 3, GL_FLOAT, false, stride, (GLvoid *)(3 * sizeof(GLfloat)));
+       glVertexAttribPointer(1, 3, GL_FLOAT, false, sizeof(Vertex), (GLvoid *)(3 * sizeof(GLfloat)));
        glEnableVertexAttribArray(1);
 
        glBindBuffer(GL_ARRAY_BUFFER, 0);
index 255070165de85b075aac849ce09580b6eb754dbe..b5422ff093a1709d97b70d415be1189b29ffaec6 100644 (file)
@@ -8,6 +8,12 @@
 #include "shaders.h"
 #include "types.h"
 
+typedef struct
+{
+       GLfloat x, y, z;
+       GLfloat r, g, b;
+} __attribute__((packed, aligned(4))) Vertex;
+
 typedef struct
 {
        v3f pos, rot, scale;
@@ -15,16 +21,10 @@ typedef struct
        mat4x4 transform;
        GLuint VAO, VBO;
        bool remove;
-       GLfloat *vertices;
+       Vertex *vertices;
        GLsizei count;
 } Mesh;
 
-typedef struct
-{
-       GLfloat x, y, z;
-       GLfloat r, g, b;
-} __attribute__((packed, aligned(4))) Vertex;
-
 Mesh *mesh_create(Vertex *vertices, GLsizei count);
 void mesh_delete(Mesh *mesh);
 void mesh_transform(Mesh *mesh);