Skip to content

Commit

Permalink
gl2shim: implement fallback vbo, glDrawRangeElements with non-vbo buf…
Browse files Browse the repository at this point in the history
…fer works now on core contexts
  • Loading branch information
mittorn committed Oct 6, 2023
1 parent ee5191e commit 9536713
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions ref/gl/gl2_shim/gl2_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -996,17 +996,49 @@ 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)
continue;
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 );
Expand Down

0 comments on commit 9536713

Please sign in to comment.