From: havoc Date: Thu, 12 Sep 2002 14:55:25 +0000 (+0000) Subject: manually inlined GL_LockArray and GL_UnlockArray in the only places they were used X-Git-Tag: RELEASE_0_2_0_RC1~240 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=df6b5bf1045cb7b7e3384e1a1eb2e312b4c090f3;p=xonotic%2Fdarkplaces.git manually inlined GL_LockArray and GL_UnlockArray in the only places they were used RGB fragment textures are no longer aligned on 3 pixel boundaries, changed UNPACK_ALIGNMENT to allow this git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2371 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_backend.c b/gl_backend.c index ad6f24c9..10acf3f0 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -213,28 +213,6 @@ void gl_backend_init(void) R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap); } -int arraylocked = false; - -void GL_LockArray(int first, int count) -{ - if (!arraylocked && gl_supportslockarrays && gl_lockarrays.integer && gl_mesh_drawmode.integer > 0) - { - qglLockArraysEXT(first, count); - CHECKGLERROR - arraylocked = true; - } -} - -void GL_UnlockArray(void) -{ - if (arraylocked) - { - qglUnlockArraysEXT(); - CHECKGLERROR - arraylocked = false; - } -} - /* ============= GL_SetupFrame @@ -549,7 +527,13 @@ void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *in unsigned int i, j, in; qbyte *c; float *v; - GL_LockArray(firstvert, endvert - firstvert); + int arraylocked = false; + if (gl_supportslockarrays && gl_lockarrays.integer && gl_mesh_drawmode.integer > 0) + { + qglLockArraysEXT(firstvert, endvert - firstvert); + CHECKGLERROR + arraylocked = true; + } if (gl_mesh_drawmode.integer >= 3/* && (endvert - firstvert) <= gl_maxdrawrangeelementsvertices && (indexcount) <= gl_maxdrawrangeelementsindices*/) { // GL 1.2 or GL 1.1 with extension @@ -616,7 +600,12 @@ void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, GLuint *in qglEnd(); CHECKGLERROR } - GL_UnlockArray(); + if (arraylocked) + { + qglUnlockArraysEXT(); + CHECKGLERROR + arraylocked = false; + } } // enlarges geometry buffers if they are too small diff --git a/gl_backend.h b/gl_backend.h index 1752635f..7190e0c2 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -4,6 +4,8 @@ #define MAX_TEXTUREUNITS 8 +extern cvar_t gl_lockarrays; + extern int c_meshtris, c_meshs; typedef struct diff --git a/gl_draw.c b/gl_draw.c index d9292885..66fc741d 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -371,6 +371,7 @@ void R_DrawQueue(void) int batch, batchcount, additive; unsigned int color; drawqueuemesh_t *mesh; + int arraylocked = false; if (!r_render.integer) return; @@ -571,34 +572,34 @@ void R_DrawQueue(void) qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR } + if (gl_supportslockarrays && gl_lockarrays.integer && gl_mesh_drawmode.integer > 0) + { + qglLockArraysEXT(0, mesh->numvertices); + CHECKGLERROR + arraylocked = true; + } if (gl_mesh_drawmode.integer >= 3/* && (mesh->numvertices) <= gl_maxdrawrangeelementsvertices && (mesh->numindices) <= gl_maxdrawrangeelementsindices*/) { // GL 1.2 or GL 1.1 with extension - GL_LockArray(0, mesh->numvertices); qglDrawRangeElements(GL_TRIANGLES, 0, mesh->numvertices, mesh->numindices, GL_UNSIGNED_INT, mesh->indices); CHECKGLERROR - GL_UnlockArray(); } else if (gl_mesh_drawmode.integer >= 2) { // GL 1.1 - GL_LockArray(0, mesh->numvertices); qglDrawElements(GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT, mesh->indices); CHECKGLERROR - GL_UnlockArray(); } else if (gl_mesh_drawmode.integer >= 1) { int i; // GL 1.1 // feed it manually using glArrayElement - GL_LockArray(0, mesh->numvertices); qglBegin(GL_TRIANGLES); for (i = 0;i < mesh->numindices;i++) qglArrayElement(mesh->indices[i]); qglEnd(); CHECKGLERROR - GL_UnlockArray(); } else { @@ -616,6 +617,12 @@ void R_DrawQueue(void) qglEnd(); CHECKGLERROR } + if (arraylocked) + { + qglUnlockArraysEXT(); + CHECKGLERROR + arraylocked = false; + } if (gl_mesh_drawmode.integer > 0) { qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR diff --git a/gl_textures.c b/gl_textures.c index 8aa0457f..a9842972 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -45,7 +45,7 @@ typedef struct textypeinfo_t; static textypeinfo_t textype_qpalette = {TEXTYPE_QPALETTE, 1, 4, GL_RGBA, 3, 1}; -static textypeinfo_t textype_rgb = {TEXTYPE_RGB , 3, 3, GL_RGB , 3, 3}; +static textypeinfo_t textype_rgb = {TEXTYPE_RGB , 3, 3, GL_RGB , 3, 1}; static textypeinfo_t textype_rgba = {TEXTYPE_RGBA , 4, 4, GL_RGBA, 3, 1}; static textypeinfo_t textype_qpalette_alpha = {TEXTYPE_QPALETTE, 1, 4, GL_RGBA, 4, 1}; static textypeinfo_t textype_rgba_alpha = {TEXTYPE_RGBA , 4, 4, GL_RGBA, 4, 1}; @@ -446,6 +446,9 @@ static void r_textures_start(void) // deal with size limits of various drivers (3dfx in particular) qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &realmaxsize); CHECKGLERROR + // LordHavoc: allow any alignment + qglPixelStorei(GL_UNPACK_ALIGNMENT, 1); + CHECKGLERROR // use the largest scrap texture size we can (not sure if this is really a good idea) for (block_size = 1;block_size < realmaxsize && block_size < r_max_scrapsize.integer;block_size <<= 1); diff --git a/glquake.h b/glquake.h index bf362edc..d9ce90ee 100644 --- a/glquake.h +++ b/glquake.h @@ -115,6 +115,7 @@ typedef double GLclampd; #define GL_TEXTURE_WRAP_T 0x2803 #define GL_TEXTURE_MAG_FILTER 0x2800 #define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_UNPACK_ALIGNMENT 0x0CF5 #define GL_NEAREST 0x2600 #define GL_LINEAR 0x2601 @@ -362,6 +363,8 @@ extern void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture); extern void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); extern void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); extern void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures); +extern void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param); +extern void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param); #if WIN32 extern int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *); diff --git a/render.h b/render.h index 05dcd5f7..426893c8 100644 --- a/render.h +++ b/render.h @@ -162,10 +162,6 @@ extern cvar_t r_render; extern cvar_t r_textureunits; extern cvar_t gl_dither; -// FIXME: this should live in the backend only -void GL_LockArray(int first, int count); -void GL_UnlockArray(void); - #include "gl_backend.h" #include "r_light.h" diff --git a/vid_shared.c b/vid_shared.c index a35bb1ed..ad8e0d34 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -143,6 +143,8 @@ void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture); void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures); +void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param); +void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param); void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); @@ -257,6 +259,8 @@ static gl_extensionfunctionlist_t opengl110funcs[] = {"glTexImage2D", (void **) &qglTexImage2D}, {"glTexSubImage2D", (void **) &qglTexSubImage2D}, {"glDeleteTextures", (void **) &qglDeleteTextures}, + {"glPixelStoref", (void **) &qglPixelStoref}, + {"glPixelStorei", (void **) &qglPixelStorei}, {NULL, NULL} };