From 5d1310364a9918d3aba1ad33fc6fc09e39134d87 Mon Sep 17 00:00:00 2001 From: g-cont Date: Sun, 8 Dec 2013 00:00:00 +0400 Subject: [PATCH] 08 Dec 2013 --- common/render_api.h | 18 ++++++++------ engine/client/gl_backend.c | 49 ++++++++++++++++++++++++++++++-------- engine/client/gl_draw.c | 2 +- engine/client/gl_image.c | 8 ++++--- engine/client/gl_local.h | 7 ++++-- engine/client/gl_rmain.c | 5 ++++ engine/client/gl_vidnt.c | 1 + 7 files changed, 67 insertions(+), 23 deletions(-) diff --git a/common/render_api.h b/common/render_api.h index 32508d0f..35e0b4ed 100644 --- a/common/render_api.h +++ b/common/render_api.h @@ -27,8 +27,8 @@ GNU General Public License for more details. // move misc functions at end of the interface // added new export for clearing studio decals -#define CL_RENDER_INTERFACE_VERSION 30 -#define MAX_STUDIO_DECALS 4096 // + unused space of BSP decals +#define CL_RENDER_INTERFACE_VERSION 31 +#define MAX_STUDIO_DECALS 4096 // + unused space of BSP decals #define SURF_INFO( surf, mod ) ((mextrasurf_t *)mod->cache.data + (surf - mod->surfaces)) #define INFO_SURF( surf, mod ) (mod->surfaces + (surf - (mextrasurf_t *)mod->cache.data)) @@ -197,14 +197,19 @@ typedef struct render_api_s int (*AVI_IsActive)( void *Avi ); // glState related calls (must use this instead of normal gl-calls to prevent de-synchornize local states between engine and the client) - void (*GL_Bind)( unsigned int tmu, unsigned int texnum ); - void (*GL_SelectTexture)( unsigned int texture ); + void (*GL_Bind)( int tmu, unsigned int texnum ); + void (*GL_SelectTexture)( int tmu ); void (*GL_LoadTextureMatrix)( const float *glmatrix ); void (*GL_TexMatrixIdentity)( void ); void (*GL_CleanUpTextureUnits)( int last ); // pass 0 for clear all the texture units void (*GL_TexGen)( unsigned int coord, unsigned int mode ); void (*GL_TextureTarget)( unsigned int target ); // change texture unit mode without bind texture - + void (*GL_TexCoordArrayMode)( unsigned int texmode ); + void (*GL_Reserved0)( void ); // for potential interface expansion without broken compatibility + void (*GL_Reserved1)( void ); + void (*GL_Reserved2)( void ); + void (*GL_Reserved3)( void ); + // Misc renderer functions void (*GL_DrawParticles)( const float *vieworg, const float *fwd, const float *rt, const float *up, unsigned int clipFlags ); void (*EnvShot)( const float *vieworg, const char *name, qboolean skyshot ); // creates a cubemap or skybox into gfx\env folder @@ -218,13 +223,12 @@ typedef struct render_api_s void (*S_FadeMusicVolume)( float fadePercent ); // fade background track (0-100 percents) void (*SetRandomSeed)( long lSeed ); // set custom seed for RANDOM_FLOAT\RANDOM_LONG for predictable random wadlist_t *(*COM_GetWadsList)( void ); // returns a wadlist for the given map -// ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 30 - // static allocations void *(*pfnMemAlloc)( size_t cb, const char *filename, const int fileline ); void (*pfnMemFree)( void *mem, const char *filename, const int fileline ); // find in files char **(*pfnGetFilesList)( const char *pattern, int *numFiles, int gamedironly ); + // ONLY ADD NEW FUNCTIONS TO THE END OF THIS STRUCT. INTERFACE VERSION IS FROZEN AT 31 } render_api_t; // render callbacks diff --git a/engine/client/gl_backend.c b/engine/client/gl_backend.c index 27d2c9ad..71a74ab6 100644 --- a/engine/client/gl_backend.c +++ b/engine/client/gl_backend.c @@ -156,33 +156,33 @@ void GL_LoadIdentityTexMatrix( void ) GL_SelectTexture ================= */ -void GL_SelectTexture( GLenum texture ) +void GL_SelectTexture( GLint tmu ) { if( !GL_Support( GL_ARB_MULTITEXTURE )) return; // don't allow negative texture units - if((GLint)texture < 0 ) texture = 0; + if( tmu < 0 ) return; - if( texture >= GL_MaxTextureUnits( )) + if( tmu >= GL_MaxTextureUnits( )) { - MsgDev( D_ERROR, "GL_SelectTexture: bad tmu state %i\n", texture ); + MsgDev( D_ERROR, "GL_SelectTexture: bad tmu state %i\n", tmu ); return; } - if( glState.activeTMU == texture ) + if( glState.activeTMU == tmu ) return; - glState.activeTMU = texture; + glState.activeTMU = tmu; if( pglActiveTextureARB ) { - pglActiveTextureARB( texture + GL_TEXTURE0_ARB ); - pglClientActiveTextureARB( texture + GL_TEXTURE0_ARB ); + pglActiveTextureARB( tmu + GL_TEXTURE0_ARB ); + pglClientActiveTextureARB( tmu + GL_TEXTURE0_ARB ); } else if( pglSelectTextureSGIS ) { - pglSelectTextureSGIS( texture + GL_TEXTURE0_SGIS ); + pglSelectTextureSGIS( tmu + GL_TEXTURE0_SGIS ); } } @@ -218,6 +218,7 @@ void GL_CleanUpTextureUnits( int last ) glState.currentTextures[i] = -1; // unbind texture } + GL_SetTexCoordArrayMode( GL_NONE ); GL_LoadIdentityTexMatrix(); GL_DisableAllTexGens(); GL_SelectTexture( i - 1 ); @@ -297,7 +298,7 @@ void GL_TexGen( GLenum coord, GLenum mode ) if( mode ) { - if(!( glState.genSTEnabled[tmu] & bit )) + if( !( glState.genSTEnabled[tmu] & bit )) { pglEnable( gen ); glState.genSTEnabled[tmu] |= bit; @@ -314,6 +315,34 @@ void GL_TexGen( GLenum coord, GLenum mode ) } } +/* +================= +GL_SetTexCoordArrayMode +================= +*/ +void GL_SetTexCoordArrayMode( GLenum mode ) +{ + int tmu = glState.activeTMU; + int bit, cmode = glState.texCoordArrayMode[tmu]; + + if( mode == GL_TEXTURE_COORD_ARRAY ) + bit = 1; + else if( mode == GL_TEXTURE_CUBE_MAP_ARB ) + bit = 2; + else bit = 0; + + if( cmode != bit ) + { + if( cmode == 1 ) pglDisableClientState( GL_TEXTURE_COORD_ARRAY ); + else if( cmode == 2 ) pglDisable( GL_TEXTURE_CUBE_MAP_ARB ); + + if( bit == 1 ) pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); + else if( bit == 2 ) pglEnable( GL_TEXTURE_CUBE_MAP_ARB ); + + glState.texCoordArrayMode[tmu] = bit; + } +} + /* ================= GL_Cull diff --git a/engine/client/gl_draw.c b/engine/client/gl_draw.c index 7d7ff88a..96b269fd 100644 --- a/engine/client/gl_draw.c +++ b/engine/client/gl_draw.c @@ -226,7 +226,7 @@ void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, Host_Error( "R_UploadStretchRaw: size %i exceeds hardware limits\n", rows ); tex = R_GetTexture( texture ); - GL_Bind( GL_TEXTURE0, texture ); + GL_Bind( GL_KEEP_UNIT, texture ); tex->width = cols; tex->height = rows; diff --git a/engine/client/gl_image.c b/engine/client/gl_image.c index a7583bd6..439cbf0a 100644 --- a/engine/client/gl_image.c +++ b/engine/client/gl_image.c @@ -67,7 +67,7 @@ const char *GL_Target( GLenum target ) GL_Bind ================= */ -void GL_Bind( GLenum tmu, GLenum texnum ) +void GL_Bind( GLint tmu, GLenum texnum ) { gltexture_t *texture; @@ -75,7 +75,9 @@ void GL_Bind( GLenum tmu, GLenum texnum ) if( texnum <= 0 ) texnum = tr.defaultTexture; ASSERT( texnum > 0 && texnum < MAX_TEXTURES ); - GL_SelectTexture( tmu ); + if( tmu != GL_KEEP_UNIT ) + GL_SelectTexture( tmu ); + else tmu = glState.activeTMU; texture = &r_textures[texnum]; @@ -90,8 +92,8 @@ void GL_Bind( GLenum tmu, GLenum texnum ) if( glState.currentTextures[tmu] == texture->texnum ) return; - glState.currentTextures[tmu] = texture->texnum; pglBindTexture( texture->target, texture->texnum ); + glState.currentTextures[tmu] = texture->texnum; } /* diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index 5b9c37e1..39c1e412 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -253,13 +253,14 @@ extern struct particle_s *cl_free_trails; void GL_BackendStartFrame( void ); void GL_BackendEndFrame( void ); void GL_CleanUpTextureUnits( int last ); -void GL_Bind( GLenum tmu, GLenum texnum ); +void GL_Bind( GLint tmu, GLenum texnum ); void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t ); +void GL_SetTexCoordArrayMode( GLenum mode ); void GL_LoadTexMatrix( const matrix4x4 m ); void GL_LoadTexMatrixExt( const float *glmatrix ); void GL_LoadMatrix( const matrix4x4 source ); void GL_TexGen( GLenum coord, GLenum mode ); -void GL_SelectTexture( GLenum texture ); +void GL_SelectTexture( GLint texture ); void GL_LoadIdentityTexMatrix( void ); void GL_DisableAllTexGens( void ); void GL_SetRenderMode( int mode ); @@ -525,6 +526,7 @@ enum enum { + GL_KEEP_UNIT = -1, GL_TEXTURE0 = 0, GL_TEXTURE1, GL_TEXTURE2, @@ -577,6 +579,7 @@ typedef struct GLuint currentTextureTargets[MAX_TEXTURE_UNITS]; GLboolean texIdentityMatrix[MAX_TEXTURE_UNITS]; GLint genSTEnabled[MAX_TEXTURE_UNITS]; // 0 - disabled, OR 1 - S, OR 2 - T, OR 4 - R + GLint texCoordArrayMode[MAX_TEXTURE_UNITS]; // 0 - disabled, 1 - enabled, 2 - cubemap int faceCull; int frontFace; diff --git a/engine/client/gl_rmain.c b/engine/client/gl_rmain.c index a27486d2..82e687c8 100644 --- a/engine/client/gl_rmain.c +++ b/engine/client/gl_rmain.c @@ -1671,6 +1671,11 @@ static render_api_t gRenderAPI = GL_CleanUpTextureUnits, GL_TexGen, GL_TextureTarget, + GL_SetTexCoordArrayMode, + NULL, + NULL, + NULL, + NULL, CL_DrawParticlesExternal, R_EnvShot, COM_CompareFileTime, diff --git a/engine/client/gl_vidnt.c b/engine/client/gl_vidnt.c index d40baf98..0b686f82 100644 --- a/engine/client/gl_vidnt.c +++ b/engine/client/gl_vidnt.c @@ -629,6 +629,7 @@ static void GL_SetDefaultTexState( void ) int i; Q_memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures )); + Q_memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode )); Q_memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled )); for( i = 0; i < MAX_TEXTURE_UNITS; i++ )