diff options
Diffstat (limited to 'src/render/gl_batch.h')
| -rw-r--r-- | src/render/gl_batch.h | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/render/gl_batch.h b/src/render/gl_batch.h index 12b512f..04f72a7 100644 --- a/src/render/gl_batch.h +++ b/src/render/gl_batch.h @@ -79,12 +79,16 @@ inline GL_BATCH<VERTEX>* gl_batch_create( template <typename VERTEX> inline void gl_batch_destroy( GL_BATCH<VERTEX>* batch ) { - glDeleteBuffers( &batch->vbuffer ); + glDeleteBuffers( 1, &batch->vbuffer ); + for( auto& it : batch->calls ) + it.textures.clear(); delete batch; } template <typename VERTEX> inline void gl_batch_empty( GL_BATCH<VERTEX>* batch ) { + for( auto& it : batch->calls ) + it.textures.clear(); batch->calls.clear(); } @@ -119,6 +123,19 @@ inline void gl_batch_draw( GL_BATCH<VERTEX>* batch ) { gl_set_clip( batch->gl, clip_start, clip_dim ); } +inline U8 gl_batch_is_allowed_primitive( U16 primitive ) { + switch( primitive ) { + case GL_TRIANGLE_FAN: + case GL_TRIANGLE_STRIP: + case GL_QUAD_STRIP: + case GL_LINE_STRIP: + case GL_LINE_LOOP: + return 0; + default: + return 1; + } +} + template <typename VERTEX> inline GL_BATCH_CALL<VERTEX>* gl_batch_get_call( GL_BATCH<VERTEX>* batch, GL_TEX2D* tex, U16 primitive, I32* texid ) { U32 n = batch->calls.size; @@ -127,7 +144,7 @@ inline GL_BATCH_CALL<VERTEX>* gl_batch_get_call( GL_BATCH<VERTEX>* batch, GL_TEX VEC2 clip_start = batch->clip_start; VEC2 clip_dim = batch->clip_dim; - if( n ) { + if( gl_batch_is_allowed_primitive( primitive ) && n ) { GL_BATCH_CALL<VERTEX>* last = &batch->calls.data[n - 1]; if( last->primitive == primitive && vp_start == last->clip_start && vp_dim == last->viewport_dim @@ -162,8 +179,11 @@ inline GL_BATCH_CALL<VERTEX>* gl_batch_get_call( GL_BATCH<VERTEX>* batch, GL_TEX .textures = {}, }; - *texid = 0; - call.textures.push( tex ); + if( tex ) { + *texid = 0; + call.textures.push( tex ); + } else *texid = SAMPLER_ID_NONE; + return batch->calls.push( call ); } @@ -191,8 +211,11 @@ inline void gl_batch_insert( call = gl_batch_get_call( batch, tex, primitive, &texid ); - for( U32 i = 0; i < count; ++i ) { + for( U32 i = 0; i < count; ++i ) vertices[i].sampler = texid; - call->vertices.push( vertices[i] ); - } + + if( call->vertices.capacity < call->vertices.size + count ) + call->vertices.reserve( (call->vertices.size + count) * 4 ); + memcpy( &call->vertices.data[call->vertices.size], vertices, sizeof( VERTEX ) * count ); + call->vertices.size += count; } |
