Use GL_EXT_draw_range_elements

This commit is contained in:
James Canete 2012-04-16 09:04:26 +00:00
parent f66030f1ac
commit 13d224cfc6
7 changed files with 56 additions and 12 deletions

View file

@ -1,3 +1,4 @@
- Use GL_ext_draw_range_elements
- Reserve FBOs before shaders, as recommended in nvidia docs - Reserve FBOs before shaders, as recommended in nvidia docs
- Minor tweak in VBO allocation. - Minor tweak in VBO allocation.
- Update tr_font.c to ioq3 latest (r2232) - Update tr_font.c to ioq3 latest (r2232)

View file

@ -39,6 +39,9 @@ extern void (APIENTRYP qglMultiTexCoord2fARB) (GLenum target, GLfloat s, GLfloat
extern void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count); extern void (APIENTRYP qglLockArraysEXT) (GLint first, GLsizei count);
extern void (APIENTRYP qglUnlockArraysEXT) (void); extern void (APIENTRYP qglUnlockArraysEXT) (void);
// GL_EXT_draw_range_elements
extern void (APIENTRY * qglDrawRangeElementsEXT) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
// GL_EXT_multi_draw_arrays // GL_EXT_multi_draw_arrays
extern void (APIENTRY * qglMultiDrawArraysEXT) (GLenum, GLint *, GLsizei *, GLsizei); extern void (APIENTRY * qglMultiDrawArraysEXT) (GLenum, GLint *, GLsizei *, GLsizei);
extern void (APIENTRY * qglMultiDrawElementsEXT) (GLenum, const GLsizei *, GLenum, const GLvoid **, GLsizei); extern void (APIENTRY * qglMultiDrawElementsEXT) (GLenum, const GLsizei *, GLenum, const GLvoid **, GLsizei);

View file

@ -29,7 +29,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h" #include "tr_local.h"
// GL_EXT_draw_range_elements
void (APIENTRY * qglDrawRangeElementsEXT) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
// GL_EXT_multi_draw_arrays // GL_EXT_multi_draw_arrays
void (APIENTRY * qglMultiDrawArraysEXT) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); void (APIENTRY * qglMultiDrawArraysEXT) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount);
void (APIENTRY * qglMultiDrawElementsEXT) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount); void (APIENTRY * qglMultiDrawElementsEXT) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);
@ -187,6 +189,25 @@ void GLimp_InitExtraExtensions()
char *extension; char *extension;
const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" }; const char* result[3] = { "...ignoring %s\n", "...using %s\n", "...%s not found\n" };
// GL_EXT_draw_range_elements
extension = "GL_EXT_draw_range_elements";
glRefConfig.drawRangeElements = qfalse;
qglMultiDrawArraysEXT = NULL;
qglMultiDrawElementsEXT = NULL;
if( GLimp_HaveExtension( extension ) )
{
qglDrawRangeElementsEXT = (PFNGLMULTIDRAWARRAYSEXTPROC) SDL_GL_GetProcAddress("glDrawRangeElementsEXT");
if ( r_ext_draw_range_elements->integer)
glRefConfig.drawRangeElements = qtrue;
ri.Printf(PRINT_ALL, result[glRefConfig.drawRangeElements], extension);
}
else
{
ri.Printf(PRINT_ALL, result[2], extension);
}
// GL_EXT_multi_draw_arrays // GL_EXT_multi_draw_arrays
extension = "GL_EXT_multi_draw_arrays"; extension = "GL_EXT_multi_draw_arrays";
glRefConfig.multiDrawArrays = qfalse; glRefConfig.multiDrawArrays = qfalse;

View file

@ -96,6 +96,7 @@ cvar_t *r_ext_texture_env_add;
cvar_t *r_ext_texture_filter_anisotropic; cvar_t *r_ext_texture_filter_anisotropic;
cvar_t *r_ext_max_anisotropy; cvar_t *r_ext_max_anisotropy;
cvar_t *r_ext_draw_range_elements;
cvar_t *r_ext_multi_draw_arrays; cvar_t *r_ext_multi_draw_arrays;
cvar_t *r_ext_framebuffer_object; cvar_t *r_ext_framebuffer_object;
cvar_t *r_ext_texture_float; cvar_t *r_ext_texture_float;
@ -893,7 +894,7 @@ void GL_SetDefaultState( void )
GL_TextureMode( r_textureMode->string ); GL_TextureMode( r_textureMode->string );
GL_TexEnv( GL_MODULATE ); GL_TexEnv( GL_MODULATE );
qglShadeModel( GL_SMOOTH ); //qglShadeModel( GL_SMOOTH );
qglDepthFunc( GL_LEQUAL ); qglDepthFunc( GL_LEQUAL );
// //
@ -1088,6 +1089,7 @@ void R_Register( void )
r_ext_compiled_vertex_array = ri.Cvar_Get( "r_ext_compiled_vertex_array", "1", CVAR_ARCHIVE | CVAR_LATCH); r_ext_compiled_vertex_array = ri.Cvar_Get( "r_ext_compiled_vertex_array", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_texture_env_add = ri.Cvar_Get( "r_ext_texture_env_add", "1", CVAR_ARCHIVE | CVAR_LATCH); r_ext_texture_env_add = ri.Cvar_Get( "r_ext_texture_env_add", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_draw_range_elements = ri.Cvar_Get( "r_ext_draw_range_elements", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_multi_draw_arrays = ri.Cvar_Get( "r_ext_multi_draw_arrays", "1", CVAR_ARCHIVE | CVAR_LATCH); r_ext_multi_draw_arrays = ri.Cvar_Get( "r_ext_multi_draw_arrays", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_framebuffer_object = ri.Cvar_Get( "r_ext_framebuffer_object", "1", CVAR_ARCHIVE | CVAR_LATCH); r_ext_framebuffer_object = ri.Cvar_Get( "r_ext_framebuffer_object", "1", CVAR_ARCHIVE | CVAR_LATCH);
r_ext_texture_float = ri.Cvar_Get( "r_ext_texture_float", "1", CVAR_ARCHIVE | CVAR_LATCH); r_ext_texture_float = ri.Cvar_Get( "r_ext_texture_float", "1", CVAR_ARCHIVE | CVAR_LATCH);

View file

@ -1602,6 +1602,7 @@ typedef enum {
// We can't change glConfig_t without breaking DLL/vms compatibility, so // We can't change glConfig_t without breaking DLL/vms compatibility, so
// store extensions we have here. // store extensions we have here.
typedef struct { typedef struct {
qboolean drawRangeElements;
qboolean multiDrawArrays; qboolean multiDrawArrays;
qboolean occlusionQuery; qboolean occlusionQuery;
@ -1930,6 +1931,7 @@ extern cvar_t *r_ext_texture_env_add;
extern cvar_t *r_ext_texture_filter_anisotropic; extern cvar_t *r_ext_texture_filter_anisotropic;
extern cvar_t *r_ext_max_anisotropy; extern cvar_t *r_ext_max_anisotropy;
extern cvar_t *r_ext_draw_range_elements;
extern cvar_t *r_ext_multi_draw_arrays; extern cvar_t *r_ext_multi_draw_arrays;
extern cvar_t *r_ext_framebuffer_object; extern cvar_t *r_ext_framebuffer_object;
extern cvar_t *r_ext_texture_float; extern cvar_t *r_ext_texture_float;
@ -2268,6 +2270,7 @@ void RB_EndSurface(void);
void RB_CheckOverflow( int verts, int indexes ); void RB_CheckOverflow( int verts, int indexes );
#define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);} #define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);}
void R_DrawElementsVBO( int numIndexes, int firstIndex );
void RB_StageIteratorGeneric( void ); void RB_StageIteratorGeneric( void );
void RB_StageIteratorSky( void ); void RB_StageIteratorSky( void );
void RB_StageIteratorVertexLitTexture( void ); void RB_StageIteratorVertexLitTexture( void );

View file

@ -38,15 +38,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
================== ==================
R_DrawElements R_DrawElements
Optionally performs our own glDrawElements that looks for strip conditions
instead of using the single glDrawElements call that may be inefficient
without compiled vertex arrays.
================== ==================
*/ */
static void R_DrawElementsVBO( int numIndexes, int firstIndex ) void R_DrawElementsVBO( int numIndexes, int firstIndex )
{ {
qglDrawElements(GL_TRIANGLES, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE))); if (glRefConfig.drawRangeElements)
qglDrawRangeElementsEXT(GL_TRIANGLES, 0, numIndexes, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)));
else
qglDrawElements(GL_TRIANGLES, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)));
} }
@ -60,9 +61,19 @@ static void R_DrawMultiElementsVBO( int multiDrawPrimitives, const GLvoid **mult
{ {
int i; int i;
for (i = 0; i < multiDrawPrimitives; i++) if (glRefConfig.drawRangeElements)
{ {
qglDrawElements(GL_TRIANGLES, multiDrawNumIndexes[i], GL_INDEX_TYPE, multiDrawFirstIndex[i]); for (i = 0; i < multiDrawPrimitives; i++)
{
qglDrawRangeElementsEXT(GL_TRIANGLES, 0, multiDrawNumIndexes[i], multiDrawNumIndexes[i], GL_INDEX_TYPE, multiDrawFirstIndex[i]);
}
}
else
{
for (i = 0; i < multiDrawPrimitives; i++)
{
qglDrawElements(GL_TRIANGLES, multiDrawNumIndexes[i], GL_INDEX_TYPE, multiDrawFirstIndex[i]);
}
} }
} }
} }

View file

@ -77,7 +77,8 @@ void RB_CheckVBOandIBO(VBO_t *vbo, IBO_t *ibo)
R_BindIBO(ibo); R_BindIBO(ibo);
} }
tess.useInternalVBO = qfalse; if (vbo != tess.vbo && ibo != tess.ibo)
tess.useInternalVBO = qfalse;
} }
@ -224,7 +225,7 @@ void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4], vec4_t color, sha
GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes); GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes);
GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.autoExposureMinMax); GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.autoExposureMinMax);
qglDrawElements(GL_TRIANGLES, tess.numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(0)); R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
tess.numIndexes = 0; tess.numIndexes = 0;
tess.numVertexes = 0; tess.numVertexes = 0;
@ -363,6 +364,8 @@ static void RB_SurfaceHelper( int numVerts, srfVert_t *verts, int numTriangles,
glIndex_t *index; glIndex_t *index;
float *color; float *color;
RB_CheckVBOandIBO(tess.vbo, tess.ibo);
RB_CHECKOVERFLOW( numVerts, numTriangles * 3 ); RB_CHECKOVERFLOW( numVerts, numTriangles * 3 );
tri = triangles; tri = triangles;
@ -647,7 +650,7 @@ static void RB_SurfaceBeam( void )
GLSL_SetUniformVec4(sp, TEXTURECOLOR_UNIFORM_COLOR, color); GLSL_SetUniformVec4(sp, TEXTURECOLOR_UNIFORM_COLOR, color);
} }
qglDrawElements(GL_TRIANGLES, tess.numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(tess.firstIndex)); R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
tess.numIndexes = 0; tess.numIndexes = 0;
tess.numVertexes = 0; tess.numVertexes = 0;