opengl_learn

Step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl_learn.git
Log | Files | Refs | README | LICENSE

commit 109a302eeb2c5173976521e1b7e3089df0b35be7
parent 070a197bf5ffbcdb33ef200696b0b7524d005fa3
Author: David DiPaola <DavidDiPaola@users.noreply.github.com>
Date:   Sun, 10 Jun 2018 11:14:43 -0400

ogl: made arraybuffer:load() exit() on error to simplify caller code

Diffstat:
M00-triangle.c | 6+-----
M01-perspective.c | 6+-----
M02-cube.c | 12++----------
Mogl/ogl.h | 7++-----
Mogl/ogl_arraybuffer_load.c | 10+++-------
5 files changed, 9 insertions(+), 32 deletions(-)

diff --git a/00-triangle.c b/00-triangle.c @@ -49,11 +49,7 @@ main() { }; const size_t triangle_vertexbuffer_data_size = sizeof(triangle_vertexbuffer_data); const size_t triangle_vertexbuffer_data_vertexes = (sizeof(triangle_vertexbuffer_data) / sizeof(*triangle_vertexbuffer_data)) / 3; - GLuint triangle_vertexbuffer_ID = 0; - status = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); - if (status < 0) { - return status; - } + GLuint triangle_vertexbuffer_ID = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size); do { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/01-perspective.c b/01-perspective.c @@ -72,11 +72,7 @@ main() { }; const size_t triangle_vertexbuffer_data_size = sizeof(triangle_vertexbuffer_data); const size_t triangle_vertexbuffer_data_vertexes = (sizeof(triangle_vertexbuffer_data) / sizeof(*triangle_vertexbuffer_data)) / 3; - GLuint triangle_vertexbuffer_ID = 0; - status = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size, &triangle_vertexbuffer_ID); - if (status < 0) { - return status; - } + GLuint triangle_vertexbuffer_ID = ogl_arraybuffer_load(triangle_vertexbuffer_data, triangle_vertexbuffer_data_size); do { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/02-cube.c b/02-cube.c @@ -88,11 +88,7 @@ main() { }; static const size_t cube_vertexbuffer_data_size = sizeof(cube_vertexbuffer_data); static const size_t cube_vertexbuffer_data_vertexes = (sizeof(cube_vertexbuffer_data) / sizeof(*cube_vertexbuffer_data)) / 3; - GLuint cube_vertexbuffer_ID = 0; - status = ogl_arraybuffer_load(cube_vertexbuffer_data, cube_vertexbuffer_data_size, &cube_vertexbuffer_ID); - if (status < 0) { - return status; - } + GLuint cube_vertexbuffer_ID = ogl_arraybuffer_load(cube_vertexbuffer_data, cube_vertexbuffer_data_size); static const GLfloat cube_colorbuffer_data[] = { 0.583f,0.771f,0.014f, 0.609f,0.115f,0.436f, 0.327f,0.483f,0.844f, @@ -109,11 +105,7 @@ main() { 0.673f,0.211f,0.457f, 0.820f,0.883f,0.371f, 0.982f,0.099f,0.879f, }; static const size_t cube_colorbuffer_data_size = sizeof(cube_colorbuffer_data); - GLuint cube_colorbuffer_ID = 0; - status = ogl_arraybuffer_load(cube_colorbuffer_data, cube_colorbuffer_data_size, &cube_colorbuffer_ID); - if (status < 0) { - return status; - } + GLuint cube_colorbuffer_ID = ogl_arraybuffer_load(cube_colorbuffer_data, cube_colorbuffer_data_size); do { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/ogl/ogl.h b/ogl/ogl.h @@ -51,11 +51,8 @@ ogl_program_uniform_set_mat4f( -int -ogl_arraybuffer_load( - const GLvoid * data, GLsizeiptr data_size, - GLuint * out_bufferID -); +GLuint +ogl_arraybuffer_load(const GLvoid * data, GLsizeiptr data_size); diff --git a/ogl/ogl_arraybuffer_load.c b/ogl/ogl_arraybuffer_load.c @@ -5,18 +5,14 @@ licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/ #include <GL/glew.h> -int -ogl_arraybuffer_load( - const GLvoid * data, GLsizeiptr data_size, - GLuint * out_buffer_ID -) { +GLuint +ogl_arraybuffer_load(const GLvoid * data, GLsizeiptr data_size) { GLuint buffer_ID; glGenBuffers(1, &buffer_ID); glBindBuffer(GL_ARRAY_BUFFER, buffer_ID); glBufferData(GL_ARRAY_BUFFER, data_size, data, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); - (*out_buffer_ID) = buffer_ID; - return 0; + return buffer_ID; }