From 7a781f51801a3c1573f5e3e857cd5bdcf32dd4aa Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 16 Jan 2017 15:15:10 -0700 Subject: [PATCH] Change lightmap format to GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV on OpenGL >= 1.2 This is reported to be the best performing format on Intel: http://forums.insideqc.com/viewtopic.php?f=3&t=3115&start=0 --- quakespasm/Quake/gl_texmgr.c | 2 +- quakespasm/Quake/gl_vidsdl.c | 14 ++++++++ quakespasm/Quake/glquake.h | 2 +- quakespasm/Quake/r_brush.c | 63 ++++++++++++++++++++++++++++++------ 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/quakespasm/Quake/gl_texmgr.c b/quakespasm/Quake/gl_texmgr.c index eacc7ebb..7ecf3e6e 100644 --- a/quakespasm/Quake/gl_texmgr.c +++ b/quakespasm/Quake/gl_texmgr.c @@ -1178,7 +1178,7 @@ static void TexMgr_LoadLightmap (gltexture_t *glt, byte *data) { // upload it GL_Bind (glt); - glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, glt->width, glt->height, 0, gl_lightmap_format, GL_UNSIGNED_BYTE, data); + glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, glt->width, glt->height, 0, gl_lightmap_format, gl_lightmap_type, data); // set filter modes TexMgr_SetFilterModes (glt); diff --git a/quakespasm/Quake/gl_vidsdl.c b/quakespasm/Quake/gl_vidsdl.c index 00a62a94..2b9b674d 100644 --- a/quakespasm/Quake/gl_vidsdl.c +++ b/quakespasm/Quake/gl_vidsdl.c @@ -1199,6 +1199,20 @@ static void GL_CheckExtensions (void) { Con_Warning ("GLSL alias model rendering not available, using Fitz renderer\n"); } + + // Lightmap format + // GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV are only available on Open GL >= 1.2 + if (gl_version_major > 1 + || (gl_version_major == 1 && gl_version_minor >= 2)) + { + gl_lightmap_format = GL_BGRA;//FIXME: hardcoded for now! + gl_lightmap_type = GL_UNSIGNED_INT_8_8_8_8_REV; + } + else + { + gl_lightmap_format = GL_RGBA; + gl_lightmap_type = GL_UNSIGNED_BYTE; + } } /* diff --git a/quakespasm/Quake/glquake.h b/quakespasm/Quake/glquake.h index ff61cb11..800a4c42 100644 --- a/quakespasm/Quake/glquake.h +++ b/quakespasm/Quake/glquake.h @@ -289,7 +289,7 @@ extern overflowtimes_t dev_overflows; //this stores the last time overflow messa #define CONSOLE_RESPAM_TIME 3 // seconds between repeated warning messages //johnfitz -- moved here from r_brush.c -extern int gl_lightmap_format, lightmap_bytes; +extern int gl_lightmap_format, gl_lightmap_type, lightmap_bytes; #define MAX_LIGHTMAPS 512 //johnfitz -- was 64 extern gltexture_t *lightmap_textures[MAX_LIGHTMAPS]; //johnfitz -- changed to an array diff --git a/quakespasm/Quake/r_brush.c b/quakespasm/Quake/r_brush.c index d9bde1ef..2d537a19 100644 --- a/quakespasm/Quake/r_brush.c +++ b/quakespasm/Quake/r_brush.c @@ -28,6 +28,7 @@ extern cvar_t gl_fullbrights, r_drawflat, gl_overbright, r_oldwater; //johnfitz extern cvar_t gl_zfix; // QuakeSpasm z-fighting fix int gl_lightmap_format; +int gl_lightmap_type; int lightmap_bytes; #define BLOCK_WIDTH 128 @@ -890,8 +891,8 @@ void GL_BuildLightmaps (void) lightmap_textures[i] = NULL; //johnfitz - gl_lightmap_format = GL_RGBA;//FIXME: hardcoded for now! - + //ericw -- gl_lightmap_format is now set in GL_CheckExtensions + switch (gl_lightmap_format) { case GL_RGBA: @@ -1184,9 +1185,8 @@ void R_BuildLightMap (msurface_t *surf, byte *dest, int stride) // bound, invert, and shift // store: - switch (gl_lightmap_format) + if (gl_lightmap_format == GL_RGBA && gl_lightmap_type == GL_UNSIGNED_BYTE) { - case GL_RGBA: stride -= smax * 4; bl = blocklights; for (i=0 ; i> 8; + g = *bl++ >> 8; + b = *bl++ >> 8; + } + else + { + r = *bl++ >> 7; + g = *bl++ >> 7; + b = *bl++ >> 7; + } + + // GL_UNSIGNED_INT_8_8_8_8_REV means "first element" is packed in to the least-significant byte of the uint32 + // On little-endian this gives a byte ordering of "first element", "second element", etc., so GL_BGRA is ordered B,G,R,A + // On big-endian it's "fourth element", "third element", etc., so GL_BGRA is ordered A,R,G,B + if (host_bigendian) + { + *dest++ = 255; + *dest++ = (r > 255)? 255 : r; + *dest++ = (g > 255)? 255 : g; + *dest++ = (b > 255)? 255 : b; + } + else + { + *dest++ = (b > 255)? 255 : b; + *dest++ = (g > 255)? 255 : g; + *dest++ = (r > 255)? 255 : r; + *dest++ = 255; + } + } + } + } + else + { Sys_Error ("R_BuildLightMap: bad lightmap format"); } } @@ -1261,7 +1304,7 @@ static void R_UploadLightmap(int lmap) theRect = &lightmap_rectchange[lmap]; glTexSubImage2D(GL_TEXTURE_2D, 0, 0, theRect->t, BLOCK_WIDTH, theRect->h, gl_lightmap_format, - GL_UNSIGNED_BYTE, lightmaps+(lmap* BLOCK_HEIGHT + theRect->t) *BLOCK_WIDTH*lightmap_bytes); + gl_lightmap_type, lightmaps+(lmap* BLOCK_HEIGHT + theRect->t) *BLOCK_WIDTH*lightmap_bytes); theRect->l = BLOCK_WIDTH; theRect->t = BLOCK_HEIGHT; theRect->h = 0; @@ -1322,6 +1365,6 @@ void R_RebuildAllLightmaps (void) break; GL_Bind (lightmap_textures[i]); glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT, gl_lightmap_format, - GL_UNSIGNED_BYTE, lightmaps+i*BLOCK_WIDTH*BLOCK_HEIGHT*lightmap_bytes); + gl_lightmap_type, lightmaps+i*BLOCK_WIDTH*BLOCK_HEIGHT*lightmap_bytes); } }