From 9536713f9db6d5ac92873dc506c249b56c2d17e3 Mon Sep 17 00:00:00 2001 From: mittorn Date: Fri, 6 Oct 2023 07:09:00 +0300 Subject: [PATCH] gl2shim: implement fallback vbo, glDrawRangeElements with non-vbo buffer works now on core contexts --- ref/gl/gl2_shim/gl2_shim.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ref/gl/gl2_shim/gl2_shim.c b/ref/gl/gl2_shim/gl2_shim.c index 9276ba407..7648ea4ee 100644 --- a/ref/gl/gl2_shim/gl2_shim.c +++ b/ref/gl/gl2_shim/gl2_shim.c @@ -920,7 +920,7 @@ typedef struct gl2wrap_arraypointer_s GLint size; GLenum type; GLsizei stride; - GLuint vbo; + GLuint vbo, vbo_fb; } gl2wrap_arraypointer_t; static struct @@ -996,8 +996,11 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) if ( fogging ) flags |= 1 << GL2_FLAG_FOG; prog = GL2_SetProg( flags );// | GL2_ATTR_TEXCOORD0 ); + if(!prog) + return; if( gl2wrap.vao ) pglBindVertexArray( gl2wrap.vao ); + for( int i = 0; i < GL2_ATTR_MAX; i++ ) { if(prog->attridx[i] < 0) @@ -1005,8 +1008,37 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) if( flags & (1 << i) ) { pglEnableVertexAttribArrayARB( prog->attridx[i] ); - rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.ptr[i].vbo ); - pglVertexAttribPointerARB( prog->attridx[i], gl2wrap_arrays.ptr[i].size, gl2wrap_arrays.ptr[i].type, i == GL2_ATTR_COLOR, gl2wrap_arrays.ptr[i].stride, gl2wrap_arrays.ptr[i].userptr ); + if( gl2wrap.vao && !gl2wrap_arrays.ptr[i].vbo ) + { + // detect stride by type + int stride = gl2wrap_arrays.ptr[i].stride; + if( stride == 0 ) + { + if( gl2wrap_arrays.ptr[i].type == GL_UNSIGNED_BYTE ) + stride = gl2wrap_arrays.ptr[i].size; + else + stride = gl2wrap_arrays.ptr[i].size * 4; + } + + if( !gl2wrap_arrays.ptr[i].vbo_fb ) + pglGenBuffersARB( 1, &gl2wrap_arrays.ptr[i].vbo_fb ); + rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.ptr[i].vbo_fb ); + if(!end) + { + pglDisableVertexAttribArrayARB( prog->attridx[i] ); + gEngfuncs.Con_Printf(S_ERROR "NON-vbo array for DrawElements call, SKIPPING!\n"); + continue; + } + + pglBufferDataARB( GL_ARRAY_BUFFER_ARB, end * stride, gl2wrap_arrays.ptr[i].userptr, GL_STREAM_DRAW_ARB ); + pglVertexAttribPointerARB( prog->attridx[i], gl2wrap_arrays.ptr[i].size, gl2wrap_arrays.ptr[i].type, i == GL2_ATTR_COLOR, gl2wrap_arrays.ptr[i].stride, 0 ); + + } + else + { + rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.ptr[i].vbo ); + pglVertexAttribPointerARB( prog->attridx[i], gl2wrap_arrays.ptr[i].size, gl2wrap_arrays.ptr[i].type, i == GL2_ATTR_COLOR, gl2wrap_arrays.ptr[i].stride, gl2wrap_arrays.ptr[i].userptr ); + } /* if(i == GL2_ATTR_TEXCOORD0) pglUniform1iARB( prog->utex0, 0 );