Paletted texture support (GL_EXT_paletted_texture, r_textureBits 8, expects gfx/palette.lmp)

Quarter-broken texture resampling from Darkplaces
Half-broken otherblendmodes=alpha fixes for Pvr
Postprocess Bloom works on S3TC and texturebits 0
Fix memory allocation typo with postprocess
This commit is contained in:
leilei-
2014-03-18 08:06:20 -04:00
parent b37a522057
commit f9d4ebbb40
6 changed files with 1076 additions and 20 deletions

View File

@@ -224,6 +224,96 @@ void GL_TexEnv( int env )
} }
} }
extern cvar_t *r_mockvr;
/*
** GL_StatePVR
**
** A bit slimmed down
**
*/
void GL_StatePCX( unsigned long stateBits )
{
unsigned long diff = stateBits ^ glState.glStateBits;
if ( !diff )
{
return;
}
//
// check depthFunc bits
//
if ( diff & GLS_DEPTHFUNC_EQUAL )
{
if ( stateBits & GLS_DEPTHFUNC_EQUAL )
{
qglDepthFunc( GL_EQUAL );
}
else
{
qglDepthFunc( GL_LEQUAL );
}
}
//
// check blend bits
//
if ( diff & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) )
{
GLenum srcFactor, dstFactor;
if ( stateBits & ( GLS_SRCBLEND_BITS | GLS_DSTBLEND_BITS ) )
{
srcFactor = GL_SRC_ALPHA;
dstFactor = GL_ONE_MINUS_SRC_ALPHA; // leilei - for pvr debug only!
qglEnable( GL_BLEND );
qglBlendFunc( srcFactor, dstFactor );
}
else
{
qglDisable( GL_BLEND );
}
}
//
// check depthmask
//
if ( diff & GLS_DEPTHMASK_TRUE )
{
if ( stateBits & GLS_DEPTHMASK_TRUE )
{
qglDepthMask( GL_TRUE );
}
else
{
qglDepthMask( GL_FALSE );
}
}
//
// depthtest
//
if ( diff & GLS_DEPTHTEST_DISABLE )
{
if ( stateBits & GLS_DEPTHTEST_DISABLE )
{
qglDisable( GL_DEPTH_TEST );
}
else
{
qglEnable( GL_DEPTH_TEST );
}
}
glState.glStateBits = stateBits;
}
/* /*
** GL_State ** GL_State
** **
@@ -233,7 +323,9 @@ void GL_TexEnv( int env )
void GL_State( unsigned long stateBits ) void GL_State( unsigned long stateBits )
{ {
unsigned long diff = stateBits ^ glState.glStateBits; unsigned long diff = stateBits ^ glState.glStateBits;
if (r_mockvr->integer){
GL_StatePCX (stateBits);
return;}
if ( !diff ) if ( !diff )
{ {
return; return;

View File

@@ -38,7 +38,8 @@ static cvar_t *r_bloom_dry;
static cvar_t *r_bloom_reflection; // LEILEI static cvar_t *r_bloom_reflection; // LEILEI
static cvar_t *r_bloom_sky_only; // LEILEI static cvar_t *r_bloom_sky_only; // LEILEI
cvar_t *r_film; cvar_t *r_film;
extern int force32upload;
int fakeit = 0; int fakeit = 0;
/* /*
@@ -227,14 +228,8 @@ static void R_Bloom_InitTextures( void )
return; return;
} }
// LEILEI // leilei - let's not do that bloom disabling anymore
// Disable bloom if we can't get a 32-bit texture force32upload = 1;
// disable blooms if we can't handle a texture of that size
if( r_texturebits->integer < 32 ) {
ri.Cvar_Set( "r_bloom", "0" );
Com_Printf( S_COLOR_YELLOW"WARNING: 'R_InitBloomTextures' no support for 32-bit textures, effect disabled\n" );
return;
}
data = ri.Hunk_AllocateTempMemory( bloom.screen.width * bloom.screen.height * 4 ); data = ri.Hunk_AllocateTempMemory( bloom.screen.width * bloom.screen.height * 4 );
Com_Memset( data, 0, bloom.screen.width * bloom.screen.height * 4 ); Com_Memset( data, 0, bloom.screen.width * bloom.screen.height * 4 );
@@ -247,6 +242,7 @@ static void R_Bloom_InitTextures( void )
bloom.effect2.texture = R_CreateImage( "***bloom effect texture 2***", data, bloom.effect.width, bloom.effect.height, qfalse, qfalse, GL_CLAMP_TO_EDGE ); bloom.effect2.texture = R_CreateImage( "***bloom effect texture 2***", data, bloom.effect.width, bloom.effect.height, qfalse, qfalse, GL_CLAMP_TO_EDGE );
ri.Hunk_FreeTempMemory( data ); ri.Hunk_FreeTempMemory( data );
bloom.started = qtrue; bloom.started = qtrue;
force32upload = 0;
} }
/* /*
@@ -286,6 +282,8 @@ static void R_Postprocess_InitTextures( void )
return; return;
} }
force32upload = 1;
data = ri.Hunk_AllocateTempMemory( postproc.screen.width * postproc.screen.height * 4 ); data = ri.Hunk_AllocateTempMemory( postproc.screen.width * postproc.screen.height * 4 );
Com_Memset( data, 0, postproc.screen.width * postproc.screen.height * 4 ); Com_Memset( data, 0, postproc.screen.width * postproc.screen.height * 4 );
postproc.screen.texture = R_CreateImage( "***postproc screen texture***", data, postproc.screen.width, postproc.screen.height, qfalse, qfalse, GL_CLAMP_TO_EDGE ); postproc.screen.texture = R_CreateImage( "***postproc screen texture***", data, postproc.screen.width, postproc.screen.height, qfalse, qfalse, GL_CLAMP_TO_EDGE );
@@ -293,14 +291,15 @@ static void R_Postprocess_InitTextures( void )
// GLSL Depth Buffer // GLSL Depth Buffer
data = ri.Hunk_AllocateTempMemory( postproc.screen.width * postproc.screen.height *34); data = ri.Hunk_AllocateTempMemory( postproc.screen.width * postproc.screen.height *4);
Com_Memset( data, 0, postproc.screen.width * postproc.screen.height * 34 ); Com_Memset( data, 0, postproc.screen.width * postproc.screen.height * 4 );
depthimage=1; depthimage=1;
postproc.depth.texture = R_CreateImage( "***depthbuffer texture***", data, postproc.screen.width, postproc.screen.height, qfalse, qfalse, GL_CLAMP_TO_EDGE ); postproc.depth.texture = R_CreateImage( "***depthbuffer texture***", data, postproc.screen.width, postproc.screen.height, qfalse, qfalse, GL_CLAMP_TO_EDGE );
depthimage=0; depthimage=0;
ri.Hunk_FreeTempMemory( data ); ri.Hunk_FreeTempMemory( data );
postproc.started = qtrue; postproc.started = qtrue;
force32upload = 0;
} }

View File

@@ -103,6 +103,11 @@ GLvoid (APIENTRYP qglGetVertexAttribfvARB) (GLuint index, GLenum pname, GLfloat
GLvoid (APIENTRYP qglGetVertexAttribivARB) (GLuint index, GLenum pname, GLint *params); GLvoid (APIENTRYP qglGetVertexAttribivARB) (GLuint index, GLenum pname, GLint *params);
GLvoid (APIENTRYP qglGetVertexAttribPointervARB) (GLuint index, GLenum pname, GLvoid **pointer); GLvoid (APIENTRYP qglGetVertexAttribPointervARB) (GLuint index, GLenum pname, GLvoid **pointer);
// leilei - paletted texture
GLvoid (APIENTRYP qglColorTableEXT)( GLint, GLint, GLint, GLint, GLint, const GLvoid *);
GLvoid (APIENTRYP qglColorTableSGI)( GLint, GLint, GLint, GLint, GLint, const GLvoid *);
/** From renderer_opengl2 (v28) */ /** From renderer_opengl2 (v28) */
static qboolean GLimp_HaveExtension(const char *ext) static qboolean GLimp_HaveExtension(const char *ext)
{ {
@@ -223,6 +228,31 @@ void GLimp_InitExtraExtensions()
ri.Printf( PRINT_ALL, "...GL_ARB_vertex_shader not found\n" ); ri.Printf( PRINT_ALL, "...GL_ARB_vertex_shader not found\n" );
} }
// leilei - paletted texturing
palettedTextureSupport = qfalse;
if ( GLimp_HaveExtension( "GL_EXT_paletted_texture" ) )
{
if ( r_ext_paletted_texture->integer ) {
//qglCompressedTexImage2DARB = (GLvoid (APIENTRYP)(GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *)) SDL_GL_GetProcAddress("glCompressedTexImage2DARB");
qglColorTableEXT = (GLvoid (APIENTRYP)(GLint, GLint, GLint, GLint, GLint, const GLvoid *)) SDL_GL_GetProcAddress("glColorTableEXT");
// SGI
qglColorTableSGI = (GLvoid (APIENTRYP)(GLint, GLint, GLint, GLint, GLint, const GLvoid *)) SDL_GL_GetProcAddress("glColorTableSGI");
//qglColorTableEXT = ( void ( APIENTRY * ) ( int, int, int, int, int, const void * ) ) qwglGetProcAddress( "glColorTableEXT" );
{
ri.Printf( PRINT_ALL, "...using GL_EXT_paletted_texture\n");
palettedTextureSupport = qtrue;
}
}
else
{
ri.Printf( PRINT_ALL, "...ignoring GL_EXT_paletted_texture\n" );
}
}
else
{
ri.Printf( PRINT_ALL, "...GL_EXT_paletted_texture not found\n" );
}
// XXX This is likely too late to check the com_abnormalExit cvar // XXX This is likely too late to check the com_abnormalExit cvar
if( ri.Cvar_VariableIntegerValue( "com_abnormalExit" ) ) if( ri.Cvar_VariableIntegerValue( "com_abnormalExit" ) )
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,7 @@ int maxAnisotropy = 0;
float displayAspect = 0.0f; float displayAspect = 0.0f;
qboolean vertexShaders = qfalse; qboolean vertexShaders = qfalse;
qboolean postprocess = qfalse; qboolean postprocess = qfalse;
qboolean palettedTextureSupport = qfalse; // leilei - paletted textures
char depthimage; char depthimage;
glstate_t glState; glstate_t glState;
@@ -98,6 +99,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_vertex_shader; cvar_t *r_ext_vertex_shader;
cvar_t *r_ext_paletted_texture; // leilei - Paletted Texture
cvar_t *r_postprocess; cvar_t *r_postprocess;
cvar_t *r_ignoreGLErrors; cvar_t *r_ignoreGLErrors;
@@ -189,6 +191,8 @@ cvar_t *r_envMode;
cvar_t *r_flaresDlight; cvar_t *r_flaresDlight;
//cvar_t *r_flaresSurfradii; //cvar_t *r_flaresSurfradii;
cvar_t *r_alternateBrightness; // leilei - linux overbright fix cvar_t *r_alternateBrightness; // leilei - linux overbright fix
cvar_t *r_mockvr; // Leilei - for debugging PVR only!
/* /*
** InitOpenGL ** InitOpenGL
@@ -1040,6 +1044,7 @@ void R_Register( void )
r_ext_texture_filter_anisotropic = ri.Cvar_Get( "r_ext_texture_filter_anisotropic", r_ext_texture_filter_anisotropic = ri.Cvar_Get( "r_ext_texture_filter_anisotropic",
"0", CVAR_ARCHIVE | CVAR_LATCH ); "0", CVAR_ARCHIVE | CVAR_LATCH );
r_ext_max_anisotropy = ri.Cvar_Get( "r_ext_max_anisotropy", "2", CVAR_ARCHIVE | CVAR_LATCH ); r_ext_max_anisotropy = ri.Cvar_Get( "r_ext_max_anisotropy", "2", CVAR_ARCHIVE | CVAR_LATCH );
r_ext_paletted_texture = ri.Cvar_Get( "r_ext_paletted_texture", "0", CVAR_ARCHIVE | CVAR_LATCH ); // leilei - paletted texture support
r_postprocess = ri.Cvar_Get( "r_postprocess", "none", CVAR_ARCHIVE|CVAR_LATCH ); r_postprocess = ri.Cvar_Get( "r_postprocess", "none", CVAR_ARCHIVE|CVAR_LATCH );
r_ext_vertex_shader = ri.Cvar_Get( "r_ext_vertex_shader", "0", CVAR_ARCHIVE|CVAR_LATCH ); r_ext_vertex_shader = ri.Cvar_Get( "r_ext_vertex_shader", "0", CVAR_ARCHIVE|CVAR_LATCH );
@@ -1183,6 +1188,8 @@ void R_Register( void )
r_flaresDlight = ri.Cvar_Get( "r_flaresDlight", "0" , CVAR_ARCHIVE ); // dynamic light flares r_flaresDlight = ri.Cvar_Get( "r_flaresDlight", "0" , CVAR_ARCHIVE ); // dynamic light flares
r_flareSun = ri.Cvar_Get( "r_flareSun", "0" , CVAR_ARCHIVE); // it's 0 because mappers expect 0. r_flareSun = ri.Cvar_Get( "r_flareSun", "0" , CVAR_ARCHIVE); // it's 0 because mappers expect 0.
r_mockvr = ri.Cvar_Get( "r_mockvr", "0" , CVAR_ARCHIVE | CVAR_CHEAT);
// make sure all the commands added here are also // make sure all the commands added here are also
// removed in R_Shutdown // removed in R_Shutdown
ri.Cmd_AddCommand( "imagelist", R_ImageList_f ); ri.Cmd_AddCommand( "imagelist", R_ImageList_f );

View File

@@ -41,7 +41,7 @@ typedef unsigned int glIndex_t;
#define SHADERNUM_BITS 14 #define SHADERNUM_BITS 14
#define MAX_SHADERS (1<<SHADERNUM_BITS) #define MAX_SHADERS (1<<SHADERNUM_BITS)
extern qboolean palettedTextureSupport; // leilei - paletted texture
typedef struct dlight_s { typedef struct dlight_s {
vec3_t origin; vec3_t origin;
@@ -269,6 +269,11 @@ typedef struct {
int videoMapHandle; int videoMapHandle;
qboolean isLightmap; qboolean isLightmap;
qboolean isVideoMap; qboolean isVideoMap;
// leilei - alphahack
char *texname;
int alphahack;
} textureBundle_t; } textureBundle_t;
#define NUM_TEXTURE_BUNDLES 8 #define NUM_TEXTURE_BUNDLES 8
@@ -1200,7 +1205,7 @@ extern cvar_t *r_lensReflection1;
extern cvar_t *r_lensReflection2; extern cvar_t *r_lensReflection2;
extern cvar_t *r_lensReflectionBrightness; extern cvar_t *r_lensReflectionBrightness;
extern cvar_t *r_ext_paletted_texture; // leilei - Paletted Texture
extern cvar_t *r_envMode; extern cvar_t *r_envMode;
extern cvar_t *r_specMode; extern cvar_t *r_specMode;
//extern cvar_t *r_waveMode; //extern cvar_t *r_waveMode;