OpenGL2: Misc fixes and cleanup

Fix two constants in GLSL shaders. Remove f suffix from float and fix
int to float assignment. They were causing shader compile errors in
OpenGL ES 2 context.

Remove disabling clip plane. Clip plane is unused and never enabled in
the opengl2 renderer. Remove disabling it to avoid causing a GL error
when using OpenGL 3.2 core profile or OpenGL ES.

Make VAO cache vertex stride be size of srfVert_t since that is what
is uploaded to the GPU. No behavior change. There is a disabled debug
id in srfVert_t though which if enabled changes srfVert_t size.
This commit is contained in:
Zack Middleton 2018-07-20 23:40:35 -05:00
parent 14cc4cc6cb
commit 39e2113c73
11 changed files with 28 additions and 53 deletions

View file

@ -56,5 +56,5 @@ void main()
current.y *= 0.0625; current.y *= 0.0625;
#endif #endif
gl_FragColor = vec4(current, 1.0f); gl_FragColor = vec4(current, 1.0);
} }

View file

@ -61,7 +61,7 @@ float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZN
poissonDisc[7] = vec2(-0.5579782, 0.7491854); poissonDisc[7] = vec2(-0.5579782, 0.7491854);
poissonDisc[8] = vec2(0.7320465, 0.6317794); poissonDisc[8] = vec2(0.7320465, 0.6317794);
float result = 0; float result = 0.0;
float sampleZ = getLinearDepth(depthMap, tex, zFarDivZNear); float sampleZ = getLinearDepth(depthMap, tex, zFarDivZNear);
float scaleZ = zFarDivZNear * sampleZ; float scaleZ = zFarDivZNear * sampleZ;

View file

@ -58,7 +58,7 @@ void GL_BindToTMU( image_t *image, int tmu )
ri.Printf(PRINT_WARNING, "GL_BindToTMU: NULL image\n"); ri.Printf(PRINT_WARNING, "GL_BindToTMU: NULL image\n");
} }
GL_BindMultiTexture(GL_TEXTURE0_ARB + tmu, target, texture); GL_BindMultiTexture(GL_TEXTURE0 + tmu, target, texture);
} }
@ -435,7 +435,6 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
int oldSort; int oldSort;
double originalTime; double originalTime;
FBO_t* fbo = NULL; FBO_t* fbo = NULL;
qboolean inQuery = qfalse;
// save original time for entity shader offsets // save original time for entity shader offsets
originalTime = backEnd.refdef.floatTime; originalTime = backEnd.refdef.floatTime;
@ -593,10 +592,6 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
RB_EndSurface(); RB_EndSurface();
} }
if (inQuery) {
qglEndQuery(GL_SAMPLES_PASSED);
}
if (glRefConfig.framebufferObject) if (glRefConfig.framebufferObject)
FBO_Bind(fbo); FBO_Bind(fbo);
@ -657,7 +652,6 @@ void RB_SetGL2D (void) {
GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA ); GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
GL_Cull( CT_TWO_SIDED ); GL_Cull( CT_TWO_SIDED );
qglDisable( GL_CLIP_PLANE0 );
// set time for 2D shaders // set time for 2D shaders
backEnd.refdef.time = ri.Milliseconds(); backEnd.refdef.time = ri.Milliseconds();

View file

@ -203,11 +203,11 @@ void R_AddCapShadowmapCmd( int map, int cubeSide ) {
/* /*
============= =============
R_PostProcessingCmd R_AddPostProcessCmd
============= =============
*/ */
void R_AddPostProcessCmd( ) { void R_AddPostProcessCmd( void ) {
postProcessCommand_t *cmd; postProcessCommand_t *cmd;
cmd = R_GetCommandBuffer( sizeof( *cmd ) ); cmd = R_GetCommandBuffer( sizeof( *cmd ) );

View file

@ -35,7 +35,7 @@ static struct
} }
glDsaState; glDsaState;
void GL_BindNullTextures() void GL_BindNullTextures(void)
{ {
int i; int i;
@ -141,7 +141,7 @@ GLvoid APIENTRY GLDSA_GenerateTextureMipmapEXT(GLuint texture, GLenum target)
qglGenerateMipmap(target); qglGenerateMipmap(target);
} }
void GL_BindNullProgram() void GL_BindNullProgram(void)
{ {
qglUseProgram(0); qglUseProgram(0);
glDsaState.program = 0; glDsaState.program = 0;
@ -205,7 +205,7 @@ GLvoid APIENTRY GLDSA_ProgramUniformMatrix4fvEXT(GLuint program, GLint location,
qglUniformMatrix4fv(location, count, transpose, value); qglUniformMatrix4fv(location, count, transpose, value);
} }
void GL_BindNullFramebuffers() void GL_BindNullFramebuffers(void)
{ {
qglBindFramebuffer(GL_FRAMEBUFFER, 0); qglBindFramebuffer(GL_FRAMEBUFFER, 0);
glDsaState.drawFramebuffer = glDsaState.readFramebuffer = 0; glDsaState.drawFramebuffer = glDsaState.readFramebuffer = 0;

View file

@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h" #include "tr_local.h"
#include "tr_dsa.h" #include "tr_dsa.h"
void GLimp_InitExtraExtensions() void GLimp_InitExtraExtensions(void)
{ {
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" };

View file

@ -526,10 +526,6 @@ void RB_RenderFlares (void) {
return; // none visible return; // none visible
} }
if ( backEnd.viewParms.isPortal ) {
qglDisable (GL_CLIP_PLANE0);
}
Mat4Copy(glState.projection, oldprojection); Mat4Copy(glState.projection, oldprojection);
Mat4Copy(glState.modelview, oldmodelview); Mat4Copy(glState.modelview, oldmodelview);
Mat4Identity(matrix); Mat4Identity(matrix);

View file

@ -331,17 +331,6 @@ static void GLSL_GetShaderHeader( GLenum shaderType, const GLchar *extra, char *
AGEN_LIGHTING_SPECULAR, AGEN_LIGHTING_SPECULAR,
AGEN_PORTAL)); AGEN_PORTAL));
Q_strcat(dest, size,
va("#ifndef texenv_t\n"
"#define texenv_t\n"
"#define TEXENV_MODULATE %i\n"
"#define TEXENV_ADD %i\n"
"#define TEXENV_REPLACE %i\n"
"#endif\n",
GL_MODULATE,
GL_ADD,
GL_REPLACE));
fbufWidthScale = 1.0f / ((float)glConfig.vidWidth); fbufWidthScale = 1.0f / ((float)glConfig.vidWidth);
fbufHeightScale = 1.0f / ((float)glConfig.vidHeight); fbufHeightScale = 1.0f / ((float)glConfig.vidHeight);
Q_strcat(dest, size, Q_strcat(dest, size,

View file

@ -435,7 +435,7 @@ void RE_BeginScene(const refdef_t *fd)
} }
void RE_EndScene() void RE_EndScene(void)
{ {
// the next scene rendered in this frame will tack on after this one // the next scene rendered in this frame will tack on after this one
r_firstSceneDrawSurf = tr.refdef.numDrawSurfs; r_firstSceneDrawSurf = tr.refdef.numDrawSurfs;

View file

@ -261,7 +261,6 @@ void RB_ShadowFinish( void ) {
qglEnable( GL_STENCIL_TEST ); qglEnable( GL_STENCIL_TEST );
qglStencilFunc( GL_NOTEQUAL, 0, 255 ); qglStencilFunc( GL_NOTEQUAL, 0, 255 );
qglDisable (GL_CLIP_PLANE0);
GL_Cull( CT_TWO_SIDED ); GL_Cull( CT_TWO_SIDED );
GL_BindToTMU( tr.whiteImage, TB_COLORMAP ); GL_BindToTMU( tr.whiteImage, TB_COLORMAP );

View file

@ -751,7 +751,7 @@ void VaoCache_Commit(void)
if (indexSet < vc.surfaceIndexSets + vc.numSurfaces) if (indexSet < vc.surfaceIndexSets + vc.numSurfaces)
{ {
tess.firstIndex = indexSet->bufferOffset / sizeof(glIndex_t); tess.firstIndex = indexSet->bufferOffset / sizeof(glIndex_t);
//ri.Printf(PRINT_ALL, "firstIndex %d numIndexes %d as %d\n", tess.firstIndex, tess.numIndexes, batchLength - vc.batchLengths); //ri.Printf(PRINT_ALL, "firstIndex %d numIndexes %d as %d\n", tess.firstIndex, tess.numIndexes, (int)(batchLength - vc.batchLengths));
//ri.Printf(PRINT_ALL, "vc.numSurfaces %d vc.numBatches %d\n", vc.numSurfaces, vc.numBatches); //ri.Printf(PRINT_ALL, "vc.numSurfaces %d vc.numBatches %d\n", vc.numSurfaces, vc.numBatches);
} }
// If not, rebuffer the batch // If not, rebuffer the batch
@ -792,7 +792,7 @@ void VaoCache_Commit(void)
vcq.indexCommitSize += indexesSize; vcq.indexCommitSize += indexesSize;
} }
//ri.Printf(PRINT_ALL, "committing %d to %d, %d to %d as %d\n", vcq.vertexCommitSize, vc.vertexOffset, vcq.indexCommitSize, vc.indexOffset, batchLength - vc.batchLengths); //ri.Printf(PRINT_ALL, "committing %d to %d, %d to %d as %d\n", vcq.vertexCommitSize, vc.vertexOffset, vcq.indexCommitSize, vc.indexOffset, (int)(batchLength - vc.batchLengths));
if (vcq.vertexCommitSize) if (vcq.vertexCommitSize)
{ {
@ -812,9 +812,6 @@ void VaoCache_Commit(void)
void VaoCache_Init(void) void VaoCache_Init(void)
{ {
srfVert_t vert;
int dataSize;
vc.vao = R_CreateVao("VaoCache", NULL, VAOCACHE_VERTEX_BUFFER_SIZE, NULL, VAOCACHE_INDEX_BUFFER_SIZE, VAO_USAGE_DYNAMIC); vc.vao = R_CreateVao("VaoCache", NULL, VAOCACHE_VERTEX_BUFFER_SIZE, NULL, VAOCACHE_INDEX_BUFFER_SIZE, VAO_USAGE_DYNAMIC);
vc.vao->attribs[ATTR_INDEX_POSITION].enabled = 1; vc.vao->attribs[ATTR_INDEX_POSITION].enabled = 1;
@ -849,21 +846,21 @@ void VaoCache_Init(void)
vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].normalized = GL_TRUE; vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].normalized = GL_TRUE;
vc.vao->attribs[ATTR_INDEX_COLOR].normalized = GL_TRUE; vc.vao->attribs[ATTR_INDEX_COLOR].normalized = GL_TRUE;
vc.vao->attribs[ATTR_INDEX_POSITION].offset = 0; dataSize = sizeof(vert.xyz); vc.vao->attribs[ATTR_INDEX_POSITION].offset = offsetof(srfVert_t, xyz);
vc.vao->attribs[ATTR_INDEX_TEXCOORD].offset = dataSize; dataSize += sizeof(vert.st); vc.vao->attribs[ATTR_INDEX_TEXCOORD].offset = offsetof(srfVert_t, st);
vc.vao->attribs[ATTR_INDEX_LIGHTCOORD].offset = dataSize; dataSize += sizeof(vert.lightmap); vc.vao->attribs[ATTR_INDEX_LIGHTCOORD].offset = offsetof(srfVert_t, lightmap);
vc.vao->attribs[ATTR_INDEX_NORMAL].offset = dataSize; dataSize += sizeof(vert.normal); vc.vao->attribs[ATTR_INDEX_NORMAL].offset = offsetof(srfVert_t, normal);
vc.vao->attribs[ATTR_INDEX_TANGENT].offset = dataSize; dataSize += sizeof(vert.tangent); vc.vao->attribs[ATTR_INDEX_TANGENT].offset = offsetof(srfVert_t, tangent);
vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].offset = dataSize; dataSize += sizeof(vert.lightdir); vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].offset = offsetof(srfVert_t, lightdir);
vc.vao->attribs[ATTR_INDEX_COLOR].offset = dataSize; dataSize += sizeof(vert.color); vc.vao->attribs[ATTR_INDEX_COLOR].offset = offsetof(srfVert_t, color);
vc.vao->attribs[ATTR_INDEX_POSITION].stride = dataSize; vc.vao->attribs[ATTR_INDEX_POSITION].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_TEXCOORD].stride = dataSize; vc.vao->attribs[ATTR_INDEX_TEXCOORD].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_LIGHTCOORD].stride = dataSize; vc.vao->attribs[ATTR_INDEX_LIGHTCOORD].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_NORMAL].stride = dataSize; vc.vao->attribs[ATTR_INDEX_NORMAL].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_TANGENT].stride = dataSize; vc.vao->attribs[ATTR_INDEX_TANGENT].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].stride = dataSize; vc.vao->attribs[ATTR_INDEX_LIGHTDIRECTION].stride = sizeof(srfVert_t);
vc.vao->attribs[ATTR_INDEX_COLOR].stride = dataSize; vc.vao->attribs[ATTR_INDEX_COLOR].stride = sizeof(srfVert_t);
Vao_SetVertexPointers(vc.vao); Vao_SetVertexPointers(vc.vao);
@ -888,7 +885,7 @@ void VaoCache_CheckAdd(qboolean *endSurface, qboolean *recycleVertexBuffer, qboo
if (vc.vao->vertexesSize < vc.vertexOffset + vcq.vertexCommitSize + vertexesSize) if (vc.vao->vertexesSize < vc.vertexOffset + vcq.vertexCommitSize + vertexesSize)
{ {
//ri.Printf(PRINT_ALL, "out of space in vertex cache: %d < %d + %d + %d\n", vc.vao->vertexesSize, vc.vertexOffset, vc.vertexCommitSize, vertexesSize); //ri.Printf(PRINT_ALL, "out of space in vertex cache: %d < %d + %d + %d\n", vc.vao->vertexesSize, vc.vertexOffset, vcq.vertexCommitSize, vertexesSize);
*recycleVertexBuffer = qtrue; *recycleVertexBuffer = qtrue;
*recycleIndexBuffer = qtrue; *recycleIndexBuffer = qtrue;
*endSurface = qtrue; *endSurface = qtrue;
@ -966,6 +963,6 @@ void VaoCache_AddSurface(srfVert_t *verts, int numVerts, glIndex_t *indexes, int
queueEntry->numIndexes = numIndexes; queueEntry->numIndexes = numIndexes;
vcq.numSurfaces++; vcq.numSurfaces++;
vcq.vertexCommitSize += sizeof(srfVert_t) * numVerts;; vcq.vertexCommitSize += sizeof(srfVert_t) * numVerts;
vcq.indexCommitSize += sizeof(glIndex_t) * numIndexes; vcq.indexCommitSize += sizeof(glIndex_t) * numIndexes;
} }