commit 79f3e1c90927c09886464ea14853f7c07dc02363 parent 1d6644f1b2e97d0fca0c77c65028c0a069dc2aae Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Jan 18 19:50:41 +0200 u32 sizes in renderer API Diffstat:
renderer.cc | | | 26 | ++++++++++++++++++++------ |
renderer.h | | | 15 | ++++++++------- |
diff --git a/renderer.cc b/renderer.cc @@ -56,7 +56,11 @@ static GLenum textureformat_to_glenum( TextureFormat format ) { return 0; } -VB renderer_new_vb( const void * data, size_t len, BufferUsage usage ) { +VB renderer_new_vb( const void * data, u32 len, BufferUsage usage ) { + // glBufferData's length parameter is GLsizeiptr, so we need to make + // sure len fits in a signed 32bit int + ASSERT( len < S32_MAX ); + GLuint vbo; glGenBuffers( 1, &vbo ); @@ -68,7 +72,9 @@ VB renderer_new_vb( const void * data, size_t len, BufferUsage usage ) { return vbo; } -IB renderer_new_ib( const void * data, size_t len, BufferUsage usage ) { +IB renderer_new_ib( const void * data, u32 len, BufferUsage usage ) { + ASSERT( len < S32_MAX ); + GLuint ebo; glGenBuffers( 1, &ebo ); @@ -80,7 +86,9 @@ IB renderer_new_ib( const void * data, size_t len, BufferUsage usage ) { return ebo; } -UB renderer_new_ub( const void * data, size_t len ) { +UB renderer_new_ub( const void * data, u32 len ) { + ASSERT( len < S32_MAX ); + GLuint ubo; glGenBuffers( 1, &ubo ); @@ -92,7 +100,9 @@ UB renderer_new_ub( const void * data, size_t len ) { return ubo; } -TB renderer_new_tb( TextureFormat format, const void * data, size_t len, BufferUsage usage ) { +TB renderer_new_tb( TextureFormat format, const void * data, u32 len, BufferUsage usage ) { + ASSERT( len < S32_MAX ); + GLuint tbo, texture; glGenBuffers( 1, &tbo ); glGenTextures( 1, &texture ); @@ -111,12 +121,16 @@ TB renderer_new_tb( TextureFormat format, const void * data, size_t len, BufferU return tb; } -void renderer_ub_data( UB ub, const void * data, size_t len ) { +void renderer_ub_data( UB ub, const void * data, u32 len ) { + ASSERT( len < S32_MAX ); + glBindBuffer( GL_UNIFORM_BUFFER, ub ); glBufferData( GL_UNIFORM_BUFFER, len, data, GL_DYNAMIC_DRAW ); } -void renderer_tb_data( TB tb, const void * data, size_t len, BufferUsage usage ) { +void renderer_tb_data( TB tb, const void * data, u32 len, BufferUsage usage ) { + ASSERT( len < S32_MAX ); + glBindBuffer( GL_TEXTURE_BUFFER, tb.tb ); glBufferData( GL_TEXTURE_BUFFER, len, data, bufferusage_to_glenum( usage ) ); } diff --git a/renderer.h b/renderer.h @@ -135,6 +135,7 @@ enum TextureFormat { TEXFMT_R_FLOAT, TEXFMT_R_U8, TEXFMT_BC4, + TEXFMT_INVALID, }; struct TextureConfig { @@ -143,7 +144,7 @@ struct TextureConfig { TextureFormat format = TEXFMT_RGBA_FLOAT; bool srgb = false; const void * data = NULL; - size_t data_size; + u32 data_size; // TODO: internal format? // TODO: min/mag filters, wrap modes, border }; @@ -153,18 +154,18 @@ enum ClearDepthBool { CLEARDEPTH_DONT, CLEARDEPTH_DO }; void renderer_begin_frame( ClearColourBool clear_colour = CLEARCOLOUR_DO, ClearDepthBool clear_depth = CLEARDEPTH_DO ); -VB renderer_new_vb( const void * data = NULL, size_t len = 0, BufferUsage usage = BUFFERUSAGE_STATIC ); -IB renderer_new_ib( const void * data = NULL, size_t len = 0, BufferUsage usage = BUFFERUSAGE_STATIC ); -UB renderer_new_ub( const void * data = NULL, size_t len = 0 ); -TB renderer_new_tb( TextureFormat format, const void * data = NULL, size_t len = 0, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); +VB renderer_new_vb( const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_STATIC ); +IB renderer_new_ib( const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_STATIC ); +UB renderer_new_ub( const void * data = NULL, u32 len = 0 ); +TB renderer_new_tb( TextureFormat format, const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); void renderer_delete_vb( VB vb ); void renderer_delete_ib( IB ib ); void renderer_delete_ub( UB ub ); void renderer_delete_tb( TB ub ); -void renderer_ub_data( UB ub, const void * data, size_t len ); -void renderer_tb_data( TB tb, const void * data, size_t len, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); +void renderer_ub_data( UB ub, const void * data, u32 len ); +void renderer_tb_data( TB tb, const void * data, u32 len, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); Shader renderer_new_shader( ShaderConfig config ); Shader renderer_new_shader( const char * vertex_src, const char * fragment_src );