From dcf8784dca047b347d8ec4fc8a0d88dd8ab9b081 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Tue, 31 Oct 2017 17:42:48 +0700 Subject: [PATCH] Disable hardware lighting for ucodes with custom lighting methods. Fixed #1542 Turok 2/Turok 3 Per Pixel Lighting Rainbow Weapons. --- src/Config.cpp | 8 ++++++++ src/Config.h | 2 ++ src/GBI.cpp | 14 +++++++++++--- src/GBI.h | 7 ++++--- .../GLSL/glsl_CombinerProgramBuilder.cpp | 3 +-- .../OpenGLContext/opengl_BufferedDrawer.cpp | 2 +- .../OpenGLContext/opengl_UnbufferedDrawer.cpp | 2 +- src/gSP.cpp | 2 +- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 76470568..6b0855e8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -6,6 +6,7 @@ #include "RSP.h" #include "PluginAPI.h" #include "Config.h" +#include "GBI.h" #include "wst.h" void Config::resetToDefaults() @@ -112,3 +113,10 @@ void Config::resetToDefaults() debug.dumpMode = 0; } + +bool isHWLightingAllowed() +{ + if (config.generalEmulation.enableHWLighting == 0) + return false; + return GBI.isHWLSupported(); +} diff --git a/src/Config.h b/src/Config.h index ca3ce864..ae20b3d5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -200,4 +200,6 @@ void Config_LoadConfig(); void Config_DoConfig(/*HWND hParent*/); #endif +bool isHWLightingAllowed(); + #endif // CONFIG_H diff --git a/src/GBI.cpp b/src/GBI.cpp index 1a4367e6..db777c49 100644 --- a/src/GBI.cpp +++ b/src/GBI.cpp @@ -60,7 +60,7 @@ SpecialMicrocodeInfo specialMicrocodes[] = { Turbo3D, false, true, 0x2bdcfc8a, "Turbo3D" }, { F3DEX2CBFD, true, true, 0x1b4ace88, "Conker's Bad Fur Day" }, { F3DSWRS, false, false, 0xda51ccdb, "Star Wars RS" }, - { F3DZEX2, true, true, 0xd39a0d4f, "Animal Forest" }, + { F3DZEX2MM, true, true, 0xd39a0d4f, "Animal Forest" }, { S2DEX2, false, true, 0x2c399dd, "Animal Forest" }, { T3DUX, false, true, 0xbad437f2, "T3DUX vers 0.83 for Toukon Road" }, { T3DUX, false, true, 0xd0a1aa3d, "T3DUX vers 0.85 for Toukon Road 2" }, @@ -141,10 +141,14 @@ bool GBIInfo::isHWLSupported() const if (m_pCurrent == nullptr) return false; switch (m_pCurrent->type) { + case L3D: + case L3DEX: + case L3DEX2: case S2DEX: case S2DEX2: case F3DDKR: case F3DJFG: + case F3DZEX2MM: case F3DEX2CBFD: case F3DEX2ACCLAIM: return false; @@ -191,7 +195,8 @@ void GBIInfo::_makeCurrent(MicrocodeInfo * _pCurrent) case F3DEX2CBFD: F3DEX2CBFD_Init(); break; case F3DSETA: F3DSETA_Init(); break; case F3DGOLDEN: F3DGOLDEN_Init(); break; - case F3DZEX2: F3DZEX2_Init(); break; + case F3DZEX2OOT: + case F3DZEX2MM: F3DZEX2_Init(); break; case F3DTEXA: F3DTEXA_Init(); break; case T3DUX: F3D_Init(); break; case F3DEX2ACCLAIM: F3DEX2ACCLAIM_Init(); break; @@ -304,7 +309,10 @@ void GBIInfo::loadMicrocode(u32 uc_start, u32 uc_dstart, u16 uc_dsize) type = F3DFLX2; else if (strncmp(&uc_str[14], "F3DZEX", 6) == 0) { // Zelda games - type = F3DZEX2; + if (uc_str[34] == '6') + type = F3DZEX2OOT; + else + type = F3DZEX2MM; current.combineMatrices = false; } else if (strncmp(&uc_str[14], "F3DTEX/A", 8) == 0) type = F3DTEXA; diff --git a/src/GBI.h b/src/GBI.h index 7fb37575..5c24a47a 100644 --- a/src/GBI.h +++ b/src/GBI.h @@ -23,9 +23,10 @@ #define Turbo3D 14 #define ZSortp 15 #define F3DSETA 16 -#define F3DZEX2 17 -#define F3DTEXA 18 -#define T3DUX 19 +#define F3DZEX2OOT 17 +#define F3DZEX2MM 18 +#define F3DTEXA 19 +#define T3DUX 20 #define F3DEX2ACCLAIM 21 #define F3DAM 22 #define F3DSWRS 23 diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 69ec0659..d40ce641 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -1873,8 +1873,7 @@ graphics::CombinerProgram * CombinerProgramBuilder::buildCombinerProgram(Combine const bool bUseTextures = combinerInputs.usesTexture(); const bool bIsRect = _key.isRectKey(); const bool bUseHWLight = !bIsRect && // Rects not use lighting - config.generalEmulation.enableHWLighting != 0 && - GBI.isHWLSupported() && + isHWLightingAllowed() && combinerInputs.usesShadeColor(); if (bUseHWLight) diff --git a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp index c39364de..bba71e99 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp @@ -195,7 +195,7 @@ void BufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParamete { _updateTrianglesBuffers(_params); - if (config.generalEmulation.enableHWLighting != 0) + if (isHWLightingAllowed()) glVertexAttrib1f(triangleAttrib::numlights, GLfloat(_params.vertices[0].HWLight)); if (_params.elements == nullptr) { diff --git a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp index 5ac9c32c..65a0d713 100644 --- a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp @@ -69,7 +69,7 @@ void UnbufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParame glVertexAttribPointer(triangleAttrib::modify, 4, GL_BYTE, GL_FALSE, sizeof(SPVertex), ptr); } - if (config.generalEmulation.enableHWLighting != 0) + if (isHWLightingAllowed()) glVertexAttrib1f(triangleAttrib::numlights, GLfloat(_params.vertices[0].HWLight)); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false); diff --git a/src/gSP.cpp b/src/gSP.cpp index b68b6dc9..2075961e 100644 --- a/src/gSP.cpp +++ b/src/gSP.cpp @@ -477,7 +477,7 @@ template void gSPLightVertexStandard(u32 v, SPVertex * spVtx) { #ifndef __NEON_OPT - if (config.generalEmulation.enableHWLighting == 0) { + if (!isHWLightingAllowed()) { for(int j = 0; j < VNUM; ++j) { SPVertex & vtx = spVtx[v+j]; vtx.r = gSP.lights.rgb[gSP.numLights][R];