commit e6789fad605b89775038314ea35828f43a39f6ee parent 92c62510e7171936e378388024fd176fcdd90776 Author: Michael Savage <mikejsavage@gmail.com> Date: Sat Nov 5 12:42:40 +0200 Allow creation of empty VB/IBs Diffstat:
renderer.cc | | | 14 | ++++++++++---- |
renderer.h | | | 4 | ++-- |
diff --git a/renderer.cc b/renderer.cc @@ -66,8 +66,11 @@ static GLenum bufferusage_to_glenum( BufferUsage usage ) { VB renderer_new_vb( const void * data, size_t len, BufferUsage usage ) { GLuint vbo; glGenBuffers( 1, &vbo ); - glBindBuffer( GL_ARRAY_BUFFER, vbo ); - glBufferData( GL_ARRAY_BUFFER, len, data, bufferusage_to_glenum( usage ) ); + + if( data != NULL ) { + glBindBuffer( GL_ARRAY_BUFFER, vbo ); + glBufferData( GL_ARRAY_BUFFER, len, data, bufferusage_to_glenum( usage ) ); + } return checked_cast< VB >( vbo ); } @@ -75,8 +78,11 @@ VB renderer_new_vb( const void * data, size_t len, BufferUsage usage ) { IB renderer_new_ib( const void * data, size_t len, BufferUsage usage ) { GLuint ebo; glGenBuffers( 1, &ebo ); - glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ebo ); - glBufferData( GL_ELEMENT_ARRAY_BUFFER, len, data, bufferusage_to_glenum( usage ) ); + + if( data != NULL ) { + glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ebo ); + glBufferData( GL_ELEMENT_ARRAY_BUFFER, len, data, bufferusage_to_glenum( usage ) ); + } return checked_cast< IB >( ebo ); } diff --git a/renderer.h b/renderer.h @@ -107,8 +107,8 @@ 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, size_t len, BufferUsage usage = BUFFERUSAGE_STATIC ); // specify type/layout -IB renderer_new_ib( const void * data, size_t len, BufferUsage usage = BUFFERUSAGE_STATIC ); // specify u16/u32 +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 ); void renderer_delete_vb( VB vb );