diff --git a/Src/Graphics/Legacy3D/Legacy3D.cpp b/Src/Graphics/Legacy3D/Legacy3D.cpp index 360b181..efa1b07 100644 --- a/Src/Graphics/Legacy3D/Legacy3D.cpp +++ b/Src/Graphics/Legacy3D/Legacy3D.cpp @@ -162,11 +162,6 @@ #include #include -#ifdef DEBUG -extern bool g_forceFlushModels; -#endif - - namespace Legacy3D { // Microsoft doesn't provide isnan() and isinf() @@ -668,9 +663,13 @@ void CLegacy3D::DescendCullingNode(UINT32 addr) m_colorTableAddr &= 0x000FFFFF; // clamp to 4MB (in words) range } -//printf("%08x NODE %d\n", addr, stackDepth); -//for (int i = 0; i < 8; i++) -// printf(" %08x\n", node[i]); +#ifdef DEBUG + bool oldDebugHighlightAll = m_debugHighlightAll; + m_debugHighlightAll = (m_debugHighlightCullingNodeIdx >= 0) && (node[m_debugHighlightCullingNodeIdx] & m_debugHighlightCullingNodeMask) != 0; +#endif + //printf("%08x NODE %d\n", addr, stackDepth); + //for (int i = 0; i < 8; i++) + // printf(" %08x\n", node[i]); // Debug: texture offset? (NOTE: offsets 1 and 2 don't exist on step 1.0) //if (node[0x02]&0xFFFF) @@ -716,6 +715,9 @@ void CLegacy3D::DescendCullingNode(UINT32 addr) // Proceed to second link glPopMatrix(); +#ifdef DEBUG + m_debugHighlightAll = oldDebugHighlightAll; +#endif if ((node[0x00] & 0x07) != 0x06) // seems to indicate second link is invalid (fixes circular references) DescendNodePtr(node2Ptr); --stackDepth; @@ -1001,7 +1003,11 @@ void CLegacy3D::RenderFrame(void) // Draw #ifdef DEBUG - if (g_forceFlushModels) + m_debugHighlightPolyHeaderIdx = m_config["Debug/HighlightPolyHeaderIdx"].ValueAsDefault(-1); + m_debugHighlightPolyHeaderMask = m_config["Debug/HighlightPolyHeaderMask"].ValueAsDefault(0); + m_debugHighlightCullingNodeIdx = m_config["Debug/HighlightCullingNodeIdx"].ValueAsDefault(-1); + m_debugHighlightCullingNodeMask = m_config["Debug/HighlightCullingNodeMask"].ValueAsDefault(0); + if (m_config["Debug/ForceFlushModels"].ValueAsDefault(false)) ClearModelCache(&VROMCache); #endif ClearModelCache(&PolyCache); diff --git a/Src/Graphics/Legacy3D/Legacy3D.h b/Src/Graphics/Legacy3D/Legacy3D.h index 0e113e1..9185b6c 100644 --- a/Src/Graphics/Legacy3D/Legacy3D.h +++ b/Src/Graphics/Legacy3D/Legacy3D.h @@ -390,6 +390,15 @@ private: const Util::Config::Node &m_config; +#ifdef DEBUG + // Debug + int m_debugHighlightPolyHeaderIdx = -1; + uint32_t m_debugHighlightPolyHeaderMask = 0; + int m_debugHighlightCullingNodeIdx = -1; + uint32_t m_debugHighlightCullingNodeMask = 0; + bool m_debugHighlightAll = false; +#endif + // Stepping int step; int offset; // offset to subtract for words 3 and higher of culling nodes diff --git a/Src/Graphics/Legacy3D/Models.cpp b/Src/Graphics/Legacy3D/Models.cpp index 3d952d2..16521a7 100644 --- a/Src/Graphics/Legacy3D/Models.cpp +++ b/Src/Graphics/Legacy3D/Models.cpp @@ -754,9 +754,9 @@ void CLegacy3D::InsertVertex(ModelCache *Cache, const Vertex *V, const Poly *P, contourProcessing = 1.0f; #ifdef DEBUG - if (g_testPolyHeaderIdx >= 0) + if (m_debugHighlightPolyHeaderIdx >= 0 || m_debugHighlightAll) { - if ((P->header[g_testPolyHeaderIdx] & g_testPolyHeaderMask)) + if ((P->header[m_debugHighlightPolyHeaderIdx] & m_debugHighlightPolyHeaderMask) || m_debugHighlightAll) { r = 0.; g = 1.; diff --git a/Src/OSD/SDL/Main.cpp b/Src/OSD/SDL/Main.cpp index 3cb5089..a20b90d 100644 --- a/Src/OSD/SDL/Main.cpp +++ b/Src/OSD/SDL/Main.cpp @@ -410,9 +410,6 @@ static void SaveFrameBuffer(const std::string &file) Util::WriteSurfaceToBMP(file, pixels.get(), totalXRes, totalYRes, true); } -bool g_forceFlushModels = false; -int g_testPolyHeaderIdx = -1; -uint32_t g_testPolyHeaderMask = 0; static std::string s_gfxStatePath; static std::string GetFileBaseName(const std::string &file) @@ -439,24 +436,54 @@ static void TestPolygonHeaderBits(IEmulator *Emu) 0xffffff60, 0xff0300ff // contour, luminous, etc. }; + + const std::vector unknownCullingNodeBits + { + 0xffffffff, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000 + }; GLint readBuffer; glGetIntegerv(GL_READ_BUFFER, &readBuffer); glReadBuffer(GL_FRONT); // Render separate image for each unknown bit - g_forceFlushModels = true; + s_runtime_config.Set("Debug/ForceFlushModels", true); for (int idx = 0; idx < 7; idx++) { for (int bit = 0; bit < 32; bit++) { uint32_t mask = 1 << bit; - g_testPolyHeaderIdx = idx; - g_testPolyHeaderMask = mask; + s_runtime_config.Set("Debug/HighlightPolyHeaderIdx", idx); + s_runtime_config.Set("Debug/HighlightPolyHeaderMask", mask); if ((unknownPolyBits[idx] & mask)) { Emu->RenderFrame(); - std::string file = Util::Format() << "Analysis/" << GetFileBaseName(s_gfxStatePath) << "." << idx << "_" << Util::Hex(mask) << ".bmp"; + std::string file = Util::Format() << "Analysis/" << GetFileBaseName(s_gfxStatePath) << "." << "poly" << "." << idx << "_" << Util::Hex(mask) << ".bmp"; + SaveFrameBuffer(file); + } + } + } + + for (int idx = 0; idx < 10; idx++) + { + for (int bit = 0; bit < 32; bit++) + { + uint32_t mask = 1 << bit; + s_runtime_config.Set("Debug/HighlightCullingNodeIdx", idx); + s_runtime_config.Set("Debug/HighlightCullingNodeMask", mask); + if ((unknownCullingNodeBits[idx] & mask)) + { + Emu->RenderFrame(); + std::string file = Util::Format() << "Analysis/" << GetFileBaseName(s_gfxStatePath) << "." << "culling" << "." << idx << "_" << Util::Hex(mask) << ".bmp"; SaveFrameBuffer(file); } } @@ -473,7 +500,8 @@ static void TestPolygonHeaderBits(IEmulator *Emu) { std::string contents = s_polyAnalysisHTMLPrologue; contents += " var g_file_base_name = '" + GetFileBaseName(s_gfxStatePath) + "';\n"; - contents += " var g_unknown_bits = [" + std::string(Util::Format(",").Join(unknownPolyBits)) + "];\n"; + contents += " var g_unknown_poly_bits = [" + std::string(Util::Format(",").Join(unknownPolyBits)) + "];\n"; + contents += " var g_unknown_culling_bits = [" + std::string(Util::Format(",").Join(unknownCullingNodeBits)) + "];\n"; contents += s_polyAnalysisHTMLEpilogue; fs << contents; printf("Produced: %s\n", file.c_str()); diff --git a/Src/OSD/SDL/PolyAnalysis.h b/Src/OSD/SDL/PolyAnalysis.h index ffc1a14..5156824 100644 --- a/Src/OSD/SDL/PolyAnalysis.h +++ b/Src/OSD/SDL/PolyAnalysis.h @@ -33,6 +33,7 @@ static const char s_polyAnalysisHTMLPrologue[] = "\n" "\n" "