From cd213e655b7614b04a59aaead57f23f41bf3904c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 22 Jun 2013 10:35:34 -0700 Subject: [PATCH] Add some debug code for finding textures. --- GPU/GLES/FragmentShaderGenerator.cpp | 1 + GPU/GLES/TextureCache.cpp | 50 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 6ce57a7b89..3fb06b1df8 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -302,6 +302,7 @@ void GenerateFragmentShader(char *buffer) { #ifdef DEBUG_SHADER if (doTexture) { WRITE(p, " gl_FragColor = texture2D(tex, v_texcoord.xy);\n"); + WRITE(p, " gl_FragColor += vec4(0.3,0,0.3,0.3);\n"); } else { WRITE(p, " gl_FragColor = vec4(1,0,1,1);\n"); } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 87cdf9cb54..c613c6f269 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -866,7 +866,57 @@ inline u32 TextureCache::GetCurrentClutHash() { return clutHash_; } +// #define DEBUG_TEXTURES + +#ifdef DEBUG_TEXTURES +bool SetDebugTexture() { + static const int highlightFrames = 30; + + static int numTextures = 0; + static int lastFrames = 0; + static int mostTextures = 1; + + if (lastFrames != gpuStats.numFrames) { + mostTextures = std::max(mostTextures, numTextures); + numTextures = 0; + lastFrames = gpuStats.numFrames; + } + + static GLuint solidTexture = 0; + + bool changed = false; + if (((gpuStats.numFrames / highlightFrames) % mostTextures) == numTextures) { + if (gpuStats.numFrames % highlightFrames == 0) { + NOTICE_LOG(HLE, "Highlighting texture # %d / %d", numTextures, mostTextures); + } + static const u32 solidTextureData[] = {0x99AA99FF}; + + if (solidTexture == 0) { + glGenTextures(1, &solidTexture); + glBindTexture(GL_TEXTURE_2D, solidTexture); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, solidTextureData); + } else { + glBindTexture(GL_TEXTURE_2D, solidTexture); + } + changed = true; + } + + ++numTextures; + return changed; +} +#endif + void TextureCache::SetTexture() { +#ifdef DEBUG_TEXTURES + if (SetDebugTexture()) { + // A different texture was bound, let's rebind next time. + lastBoundTexture = -1; + return; + } +#endif + u32 texaddr = (gstate.texaddr[0] & 0xFFFFF0) | ((gstate.texbufwidth[0]<<8) & 0x0F000000); if (!Memory::IsValidAddress(texaddr)) { // Bind a null texture and return.