- Backend update from GZDoom.

This is mainly bringing the GLES backend up to date.
This commit is contained in:
Christoph Oelckers 2021-09-22 10:20:39 +02:00
parent 61ba58c529
commit 49e0c461c2
42 changed files with 139 additions and 3007 deletions

View file

@ -92,11 +92,16 @@ bool FGLRenderState::ApplyShader()
{
static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f };
ShaderFlavourData flavour;
// Need to calc light data now in order to select correct shader
float* lightPtr = NULL;
int modLights = 0;
int subLights = 0;
int addLights = 0;
int totalLights = 0;
flavour.hasSpotLight = false;
if (mLightIndex >= 0)
{
@ -119,21 +124,35 @@ bool FGLRenderState::ApplyShader()
if (modLights + subLights + addLights > gles.maxlights)
addLights = gles.maxlights - modLights - subLights;
totalLights = modLights + subLights + addLights;
// Skip passed the first 4 floats so the upload below only contains light data
lightPtr += 4;
float* findSpotsPtr = lightPtr + 11; // The 11th float contains '1' if the light is a spot light, see hw_dynlightdata.cpp
for (int n = 0; n < totalLights; n++)
{
if (*findSpotsPtr > 0) // This is a spot light
{
flavour.hasSpotLight = true;
break;
}
findSpotsPtr += LIGHT_VEC4_NUM * 4;
}
}
ShaderFlavourData flavour;
flavour.textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode);
int tm = GetTextureModeAndFlags(mTempTM);
flavour.textureMode = tm & 0xffff;
flavour.texFlags = tm >> 16; //Move flags to start of word
if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = TM_CLAMPY; // fixme. Clamp can now be combined with all modes.
if (flavour.textureMode == -1)
flavour.textureMode = 0;
flavour.texFlags = mTextureModeFlags; if (!mBrightmapEnabled) flavour.texFlags &= ~(TEXF_Brightmap | TEXF_Glowmap);
flavour.texFlags >>= 16; //Move flags to start of word
flavour.blendFlags = (int)(mStreamData.uTextureAddColor.a + 0.01);
@ -198,14 +217,10 @@ bool FGLRenderState::ApplyShader()
if (mHwUniforms)
{
//matrixToGL(mHwUniforms->mProjectionMatrix, activeShader->cur->ProjectionMatrix_index);
activeShader->cur->muProjectionMatrix.Set(&mHwUniforms->mProjectionMatrix);
activeShader->cur->muViewMatrix.Set(&mHwUniforms->mViewMatrix);
activeShader->cur->muNormalViewMatrix.Set(&mHwUniforms->mNormalViewMatrix);
//matrixToGL(mHwUniforms->mViewMatrix, activeShader->cur->ViewMatrix_index);
//matrixToGL(mHwUniforms->mNormalViewMatrix, activeShader->cur->NormalViewMatrix_index);
activeShader->cur->muCameraPos.Set(&mHwUniforms->mCameraPos.X);
activeShader->cur->muClipLine.Set(&mHwUniforms->mClipLine.X);
@ -224,9 +239,6 @@ bool FGLRenderState::ApplyShader()
activeShader->cur->muDesaturation.Set(mStreamData.uDesaturationFactor);
//activeShader->cur->muFogEnabled.Set(fogset);
int f = mTextureModeFlags;
if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap);
//activeShader->cur->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f);
activeShader->cur->muLightParms.Set(mLightParms);
activeShader->cur->muFogColor.Set(mStreamData.uFogColor);
activeShader->cur->muObjectColor.Set(mStreamData.uObjectColor);
@ -317,13 +329,9 @@ bool FGLRenderState::ApplyShader()
// Upload the light data
if (mLightIndex >= 0)
{
int totalLights = modLights + subLights + addLights;
// Calculate the total number of vec4s we need
int totalVectors = totalLights * LIGHT_VEC4_NUM;
// TODO!!! If there are too many lights we need to remove some of the lights and modify the data
// At the moment the shader will just try to read off the end of the array...
if (totalVectors > gles.numlightvectors)
totalVectors = gles.numlightvectors;