diff --git a/android/app/src/main/cpp/code/renderergl2/tr_flares.c b/android/app/src/main/cpp/code/renderergl2/tr_flares.c index 1dbcaddf..bb9d696c 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_flares.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_flares.c @@ -149,7 +149,7 @@ void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t // if the point is off the screen, don't bother adding it // calculate screen coordinates and depth - R_TransformModelToClip( point, backEnd.or.eyeViewMatrix[2], + R_TransformModelToClip( point, backEnd.or.modelView, backEnd.viewParms.projectionMatrix, eye, clip ); // check to see if the point is completely off screen diff --git a/android/app/src/main/cpp/code/renderergl2/tr_glsl.c b/android/app/src/main/cpp/code/renderergl2/tr_glsl.c index 1aae6b29..eb9d5128 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_glsl.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_glsl.c @@ -64,7 +64,7 @@ uniformInfo_t; #define ORTHO_PROJECTION 0 #define NORMAL_PROJECTION 1 -GLuint viewMatricesBuffer; +GLuint viewMatricesBuffer[2]; GLuint projectionMatricesBuffer[2]; @@ -175,24 +175,36 @@ GLSL_ViewMatricesUniformBuffer */ static void GLSL_ViewMatricesUniformBuffer(const float value[32]) { - // Update the scene matrices. - qglBindBuffer(GL_UNIFORM_BUFFER, viewMatricesBuffer); - float* viewMatrices = (float*)qglMapBufferRange( - GL_UNIFORM_BUFFER, - 0, - 2 * 16 * sizeof(float), - GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); - - if (viewMatrices == NULL) + for (int i = 0; i < 2; ++i) { - ri.Error(ERR_DROP, "View Matrices Uniform Buffer is NULL"); - return; + // Update the scene matrices for when we are using a normal projection + qglBindBuffer(GL_UNIFORM_BUFFER, viewMatricesBuffer[i]); + float *viewMatrices = (float *) qglMapBufferRange( + GL_UNIFORM_BUFFER, + 0, + 2 * 16 * sizeof(float), + GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + + if (viewMatrices == NULL) + { + ri.Error(ERR_DROP, "View Matrices Uniform Buffer is NULL"); + return; + } + + if (i == ORTHO_PROJECTION) + { + //For now just set identity matrices + Mat4Identity(viewMatrices); + Mat4Identity(viewMatrices + (16 * sizeof(float))); + } + else + { + memcpy((char *) viewMatrices, value, 32 * sizeof(float)); + } + + qglUnmapBuffer(GL_UNIFORM_BUFFER); + qglBindBuffer(GL_UNIFORM_BUFFER, 0); } - - memcpy((char*)viewMatrices, value, 32 * sizeof(float)); - - qglUnmapBuffer(GL_UNIFORM_BUFFER); - qglBindBuffer(GL_UNIFORM_BUFFER, 0); } /* @@ -1036,18 +1048,18 @@ void GLSL_InitGPUShaders(void) ri.Printf(PRINT_ALL, "------- GLSL_InitGPUShaders -------\n"); - //Generate buffer for 2 * view matrices - qglGenBuffers(1, &viewMatricesBuffer); - qglBindBuffer(GL_UNIFORM_BUFFER, viewMatricesBuffer); - qglBufferData( - GL_UNIFORM_BUFFER, - 2 * 16 * sizeof(float), - NULL, - GL_STATIC_DRAW); - qglBindBuffer(GL_UNIFORM_BUFFER, 0); - for (int i = 0; i < 2; ++i) { + //Generate buffer for 2 * view matrices + qglGenBuffers(1, &viewMatricesBuffer[i]); + qglBindBuffer(GL_UNIFORM_BUFFER, viewMatricesBuffer[i]); + qglBufferData( + GL_UNIFORM_BUFFER, + 2 * 16 * sizeof(float), + NULL, + GL_STATIC_DRAW); + qglBindBuffer(GL_UNIFORM_BUFFER, 0); + qglGenBuffers(1, &projectionMatricesBuffer[i]); qglBindBuffer(GL_UNIFORM_BUFFER, projectionMatricesBuffer[i]); qglBufferData( @@ -1695,25 +1707,9 @@ void GLSL_BindProgram(shaderProgram_t * program) } - static GLuint GLSL_CalculateProjection() { GLuint result = NORMAL_PROJECTION; - - int width, height; - if (glState.currentFBO) - { - width = glState.currentFBO->width; - height = glState.currentFBO->height; - } - else - { - width = glConfig.vidWidth; - height = glConfig.vidHeight; - } - - mat4_t matrix; - Mat4Ortho(0, width, height, 0, 0, 1, matrix); - if (memcmp(glState.projection, matrix, sizeof(float) * 16) == 0) + if (backEnd.projection2D) { result = ORTHO_PROJECTION; } @@ -1723,15 +1719,16 @@ static GLuint GLSL_CalculateProjection() { void GLSL_BindBuffers( shaderProgram_t * program ) { + GLuint projection = GLSL_CalculateProjection(); qglBindBufferBase( GL_UNIFORM_BUFFER, program->viewMatricesBinding, - viewMatricesBuffer); + viewMatricesBuffer[projection]); qglBindBufferBase( GL_UNIFORM_BUFFER, program->projectionMatrixBinding, - projectionMatricesBuffer[GLSL_CalculateProjection()]); + projectionMatricesBuffer[projection]); } diff --git a/android/app/src/main/cpp/code/renderergl2/tr_local.h b/android/app/src/main/cpp/code/renderergl2/tr_local.h index 0474755c..027d15cd 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_local.h +++ b/android/app/src/main/cpp/code/renderergl2/tr_local.h @@ -108,7 +108,8 @@ typedef struct { vec3_t axis[3]; // orientation in world vec3_t viewOrigin; // viewParms->or.origin in local coordinates float modelMatrix[16]; - float eyeViewMatrix[3][16]; + float modelView[16]; + float eyeViewMatrix[2][16]; } orientationr_t; // Ensure this is >= the ATTR_INDEX_COUNT enum below diff --git a/android/app/src/main/cpp/code/renderergl2/tr_main.c b/android/app/src/main/cpp/code/renderergl2/tr_main.c index e92503cb..ce636275 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_main.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_main.c @@ -536,10 +536,8 @@ void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms, glMatrix[11] = 0; glMatrix[15] = 1; - Mat4Copy(glMatrix, or->modelMatrix); - for (int eye = 0; eye <= 2; ++eye) { - myGlMultMatrix( glMatrix, viewParms->world.eyeViewMatrix[eye], or->eyeViewMatrix[eye] ); - } + myGlMultMatrix( glMatrix, viewParms->world.modelMatrix, or->modelMatrix ); + myGlMultMatrix( glMatrix, viewParms->world.modelView, or->modelView ); // calculate the viewer origin in the model's space // needed for fog, specular, and environment mapping @@ -585,7 +583,7 @@ void R_RotateForViewer (void) vec3_t origin; VectorCopy(tr.viewParms.or.origin, origin); - if (eye < 2 && !VR_useScreenLayer()) + if ((eye < 2) && !VR_useScreenLayer()) { float scale = ((r_stereoSeparation->value / 1000.0f) / 2.0f) * vr_worldscale->value * vr_worldscaleScaler->value; VectorMA(origin, (eye == 0 ? 1.0f : -1.0f) * scale, tr.viewParms.or.axis[1], origin); @@ -616,8 +614,16 @@ void R_RotateForViewer (void) // convert from our coordinate system (looking down X) // to OpenGL's coordinate system (looking down -Z) - Mat4Copy(viewerMatrix, tr.or.modelMatrix); - myGlMultMatrix(viewerMatrix, s_flipMatrix, tr.or.eyeViewMatrix[eye]); + if (eye < 2) + { + myGlMultMatrix(viewerMatrix, s_flipMatrix, tr.or.eyeViewMatrix[eye]); + } + else + { + //World Model View + Mat4Copy(viewerMatrix, tr.or.modelMatrix); + myGlMultMatrix(viewerMatrix, s_flipMatrix, tr.or.modelView); + } } tr.viewParms.world = tr.or; @@ -1165,7 +1171,7 @@ static qboolean SurfIsOffscreen( const drawSurf_t *drawSurf, vec4_t clipDest[128 int j; unsigned int pointFlags = 0; - R_TransformModelToClip( tess.xyz[i], tr.or.eyeViewMatrix[2], tr.viewParms.projectionMatrix, eye, clip ); + R_TransformModelToClip( tess.xyz[i], tr.or.modelView, tr.viewParms.projectionMatrix, eye, clip ); for ( j = 0; j < 3; j++ ) { @@ -2490,7 +2496,7 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level) R_SortDrawSurfs( tr.refdef.drawSurfs + firstDrawSurf, tr.refdef.numDrawSurfs - firstDrawSurf ); } - Mat4Multiply(tr.viewParms.projectionMatrix, tr.viewParms.world.eyeViewMatrix[2], tr.refdef.sunShadowMvp[level]); + Mat4Multiply(tr.viewParms.projectionMatrix, tr.viewParms.world.modelView, tr.refdef.sunShadowMvp[level]); } } diff --git a/android/app/src/main/cpp/code/renderergl2/tr_postprocess.c b/android/app/src/main/cpp/code/renderergl2/tr_postprocess.c index 7b9b6412..8292ae08 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_postprocess.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_postprocess.c @@ -318,7 +318,7 @@ void RB_SunRays(FBO_t *srcFbo, ivec4_t srcBox, FBO_t *dstFbo, ivec4_t dstBox) mat4_t trans, model; Mat4Translation( backEnd.viewParms.or.origin, trans ); - Mat4Multiply( backEnd.viewParms.world.eyeViewMatrix[2], trans, model ); + Mat4Multiply( backEnd.viewParms.world.modelView, trans, model ); Mat4Multiply(backEnd.viewParms.projectionMatrix, model, mvp); dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3) @@ -327,7 +327,6 @@ void RB_SunRays(FBO_t *srcFbo, ivec4_t srcBox, FBO_t *dstFbo, ivec4_t dstBox) } // project sun point - //Mat4Multiply(backEnd.viewParms.projectionMatrix, backEnd.viewParms.world.eyeViewMatrix[2], mvp); Mat4Transform(mvp, pos, hpos); // transform to UV coords diff --git a/android/app/src/main/cpp/code/renderergl2/tr_shade.c b/android/app/src/main/cpp/code/renderergl2/tr_shade.c index a3bbe941..8bab6cf7 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_shade.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_shade.c @@ -583,9 +583,9 @@ static void ComputeFogValues(vec4_t fogDistanceVector, vec4_t fogDepthVector, fl fog = tr.world->fogs + tess.fogNum; VectorSubtract( backEnd.or.origin, backEnd.viewParms.or.origin, local ); - fogDistanceVector[0] = -backEnd.or.eyeViewMatrix[2][2]; - fogDistanceVector[1] = -backEnd.or.eyeViewMatrix[2][6]; - fogDistanceVector[2] = -backEnd.or.eyeViewMatrix[2][10]; + fogDistanceVector[0] = -backEnd.or.modelView[2]; + fogDistanceVector[1] = -backEnd.or.modelView[6]; + fogDistanceVector[2] = -backEnd.or.modelView[10]; fogDistanceVector[3] = DotProduct( local, backEnd.viewParms.or.axis[0] ); // scale the fog vectors based on the fog's thickness diff --git a/android/app/src/main/cpp/code/renderergl2/tr_shade_calc.c b/android/app/src/main/cpp/code/renderergl2/tr_shade_calc.c index cd124bec..6c6d3364 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_shade_calc.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_shade_calc.c @@ -686,9 +686,9 @@ void RB_CalcFogTexCoords( float *st ) { // all fogging distance is based on world Z units VectorSubtract( backEnd.or.origin, backEnd.viewParms.or.origin, local ); - fogDistanceVector[0] = -backEnd.or.eyeViewMatrix[2][2]; - fogDistanceVector[1] = -backEnd.or.eyeViewMatrix[2][6]; - fogDistanceVector[2] = -backEnd.or.eyeViewMatrix[2][10]; + fogDistanceVector[0] = -backEnd.or.modelView[2]; + fogDistanceVector[1] = -backEnd.or.modelView[6]; + fogDistanceVector[2] = -backEnd.or.modelView[10]; fogDistanceVector[3] = DotProduct( local, backEnd.viewParms.or.axis[0] ); // scale the fog vectors based on the fog's thickness diff --git a/android/app/src/main/cpp/code/renderergl2/tr_sky.c b/android/app/src/main/cpp/code/renderergl2/tr_sky.c index 15bc5897..b0beafa7 100644 --- a/android/app/src/main/cpp/code/renderergl2/tr_sky.c +++ b/android/app/src/main/cpp/code/renderergl2/tr_sky.c @@ -783,8 +783,6 @@ void RB_DrawSun( float scale, shader_t *shader ) { return; } - //qglLoadMatrixf( backEnd.viewParms.world.eyeViewMatrix[2] ); - //qglTranslatef (backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2]); { // FIXME: this could be a lot cleaner mat4_t translation, modelmatrix;