diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index b32b7408c3..3228d50b99 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -49,16 +49,16 @@ // Annoying sure, can be removed once we get up to GLSL ~1.3 const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 }, - {I_KCOLORS, C_KCOLORS, 4 }, - {I_ALPHA, C_ALPHA, 1 }, - {I_TEXDIMS, C_TEXDIMS, 8 }, - {I_ZBIAS , C_ZBIAS, 2 }, - {I_INDTEXSCALE , C_INDTEXSCALE, 2 }, - {I_INDTEXMTX, C_INDTEXMTX, 6 }, - {I_FOG, C_FOG, 3 }, - {I_PLIGHTS, C_PLIGHTS, 40 }, - {I_PMATERIALS, C_PMATERIALS, 4 }, - }; + {I_KCOLORS, C_KCOLORS, 4 }, + {I_ALPHA, C_ALPHA, 1 }, + {I_TEXDIMS, C_TEXDIMS, 8 }, + {I_ZBIAS , C_ZBIAS, 2 }, + {I_INDTEXSCALE , C_INDTEXSCALE, 2 }, + {I_INDTEXMTX, C_INDTEXMTX, 6 }, + {I_FOG, C_FOG, 3 }, + {I_PLIGHTS, C_PLIGHTS, 40 }, + {I_PMATERIALS, C_PMATERIALS, 4 }, + }; // DO NOT make anything in this class virtual. template diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 262b2cee87..2f21c816b7 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -68,11 +68,11 @@ u16 GetEncodedSampleCount(u32 format) } const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num) { - if(ApiType == API_GLSL) - return ""; // Once we switch to GLSL 1.3 we can do something here - static char result[64]; - sprintf(result, " : register(%s%d)", prefix, num); - return result; + if(ApiType == API_GLSL) + return ""; // Once we switch to GLSL 1.3 we can do something here + static char result[64]; + sprintf(result, " : register(%s%d)", prefix, num); + return result; } const char *WriteLocation(API_TYPE ApiType) { @@ -821,13 +821,13 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType) for (int i = 0; i < 2; i++) { - WRITE(p, " depth%i *= 16777215.0f;\n", i); + WRITE(p, " depth%i *= 16777215.0f;\n", i); - WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i); - WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i); - WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i); - WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i); - WRITE(p, " expanded%i.b = depth%i;\n", i, i); + WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i); + WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i); + WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i); + WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i); + WRITE(p, " expanded%i.b = depth%i;\n", i, i); } WRITE(p, " if(cl > 0.5f) {\n"); diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index c711aa7876..5cfb9f801d 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -48,15 +48,15 @@ #define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64) #define C_VENVCONST_END (C_DEPTHPARAMS + 1) const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 }, - {I_PROJECTION , C_PROJECTION, 4 }, - {I_MATERIALS, C_MATERIALS, 4 }, - {I_LIGHTS, C_LIGHTS, 40 }, - {I_TEXMATRICES, C_TEXMATRICES, 24 }, - {I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 }, - {I_NORMALMATRICES , C_NORMALMATRICES, 32 }, - {I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 }, - {I_DEPTHPARAMS, C_DEPTHPARAMS, 1 }, - }; + {I_PROJECTION , C_PROJECTION, 4 }, + {I_MATERIALS, C_MATERIALS, 4 }, + {I_LIGHTS, C_LIGHTS, 40 }, + {I_TEXMATRICES, C_TEXMATRICES, 24 }, + {I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 }, + {I_NORMALMATRICES , C_NORMALMATRICES, 32 }, + {I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 }, + {I_DEPTHPARAMS, C_DEPTHPARAMS, 1 }, + }; template class _VERTEXSHADERUID { diff --git a/Source/Core/VideoCommon/Src/VideoCommon.h b/Source/Core/VideoCommon/Src/VideoCommon.h index f87cb7e9b1..9d9148ec7b 100644 --- a/Source/Core/VideoCommon/Src/VideoCommon.h +++ b/Source/Core/VideoCommon/Src/VideoCommon.h @@ -154,9 +154,9 @@ inline unsigned int GetPow2(unsigned int val) } struct s_svar { - const char *name; - const unsigned int reg; - const unsigned int size; + const char *name; + const unsigned int reg; + const unsigned int size; }; #endif // _VIDEOCOMMON_H diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 47df4bb6d7..db41f34024 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -74,12 +74,12 @@ void PixelShaderCache::Init() if(g_ActiveConfig.bUseGLSL) { - pSetPSConstant4f = SetGLSLPSConstant4f; - pSetPSConstant4fv = SetGLSLPSConstant4fv; - pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv; - pCompilePixelShader = CompileGLSLPixelShader; - // Should this be set here? - if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL) + pSetPSConstant4f = SetGLSLPSConstant4f; + pSetPSConstant4fv = SetGLSLPSConstant4fv; + pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv; + pCompilePixelShader = CompileGLSLPixelShader; + // Should this be set here? + if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL) g_Config.backend_info.bSupportsGLSLBinding = true; if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL) g_Config.backend_info.bSupportsGLSLUBO = true; @@ -88,22 +88,22 @@ void PixelShaderCache::Init() } else { - pSetPSConstant4f = SetCGPSConstant4f; - pSetPSConstant4fv = SetCGPSConstant4fv; - pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv; - pCompilePixelShader = CompileCGPixelShader; - glEnable(GL_FRAGMENT_PROGRAM_ARB); + pSetPSConstant4f = SetCGPSConstant4f; + pSetPSConstant4fv = SetCGPSConstant4fv; + pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv; + pCompilePixelShader = CompileCGPixelShader; + glEnable(GL_FRAGMENT_PROGRAM_ARB); } glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions); if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason. - s_nMaxPixelInstructions = 4096; + s_nMaxPixelInstructions = 4096; if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096; #if CG_VERSION_NUM == 2100 if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL) { - s_nMaxPixelInstructions = 4096; + s_nMaxPixelInstructions = 4096; } #endif @@ -347,7 +347,7 @@ void PixelShaderCache::Shutdown() s_DepthMatrixProgram.Destroy(); PSCache::iterator iter = PixelShaders.begin(); for (; iter != PixelShaders.end(); iter++) - iter->second.Destroy(); + iter->second.Destroy(); PixelShaders.clear(); } @@ -359,12 +359,12 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp // Check if the shader is already set if (last_entry) { - if (uid == last_uid) - { - GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); - ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components); - return &last_entry->shader; - } + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); + ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components); + return &last_entry->shader; + } } last_uid = uid; @@ -372,12 +372,12 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp PSCache::iterator iter = PixelShaders.find(uid); if (iter != PixelShaders.end()) { - PSCacheEntry &entry = iter->second; - last_entry = &entry; + PSCacheEntry &entry = iter->second; + last_entry = &entry; - GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); - ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components); - return &last_entry->shader; + GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); + ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components); + return &last_entry->shader; } // Make an entry in the table @@ -387,23 +387,23 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp if (g_ActiveConfig.bEnableShaderDebugging && code) { - GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components); - newentry.shader.strprog = code; + GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components); + newentry.shader.strprog = code; } #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) { - static int counter = 0; - char szTemp[MAX_PATH]; - sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); + static int counter = 0; + char szTemp[MAX_PATH]; + sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); - SaveData(szTemp, code); + SaveData(szTemp, code); } #endif if (!code || !CompilePixelShader(newentry.shader, code)) { - GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); - return NULL; + GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); + return NULL; } INCSTAT(stats.numPixelShadersCreated); @@ -424,8 +424,8 @@ void PixelShaderCache::DisableShader() assert(true); if(ShaderEnabled) { - glDisable(GL_FRAGMENT_PROGRAM_ARB); - ShaderEnabled = false; + glDisable(GL_FRAGMENT_PROGRAM_ARB); + ShaderEnabled = false; } } @@ -436,14 +436,14 @@ void PixelShaderCache::SetCurrentShader(GLuint Shader) assert(true); if(!ShaderEnabled) { - glEnable(GL_FRAGMENT_PROGRAM_ARB); - ShaderEnabled = true; + glEnable(GL_FRAGMENT_PROGRAM_ARB); + ShaderEnabled = true; } if(CurrentShader != Shader) { - if(Shader != 0) - CurrentShader = Shader; - glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); + if(Shader != 0) + CurrentShader = Shader; + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); } } // GLSL Specific @@ -493,31 +493,31 @@ void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex) return; PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); for (int a = 0; a < NUM_UNIFORMS; ++a) - if (!strcmp(name, UniformNames[a])) - { - if(tmp.UniformLocations[a] == -1) - return; - else - { - glUniform1i(tmp.UniformLocations[a], Tex); - return; - } - } + if (!strcmp(name, UniformNames[a])) + { + if(tmp.UniformLocations[a] == -1) + return; + else + { + glUniform1i(tmp.UniformLocations[a], Tex); + return; + } + } } void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1) { PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); for (int a = 0; a < NUM_UNIFORMS; ++a) - if (!strcmp(name, UniformNames[a])) - { - if(tmp.UniformLocations[a] == -1) - return; - else - { - glUniform4fv(tmp.UniformLocations[a] + offset, count, f); - return; - } - } + if (!strcmp(name, UniformNames[a])) + { + if(tmp.UniformLocations[a] == -1) + return; + else + { + glUniform4fv(tmp.UniformLocations[a] + offset, count, f); + return; + } + } } void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) @@ -531,12 +531,12 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3 } for (unsigned int a = 0; a < 10; ++a) { - if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); - return; - } + if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) + { + unsigned int offset = const_number - PSVar_Loc[a].reg; + SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); + return; + } } } @@ -549,12 +549,12 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f) } for (unsigned int a = 0; a < 10; ++a) { - if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); - return; - } + if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) + { + unsigned int offset = const_number - PSVar_Loc[a].reg; + SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f); + return; + } } } @@ -567,12 +567,12 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co } for (unsigned int a = 0; a < 10; ++a) { - if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) - { - unsigned int offset = const_number - PSVar_Loc[a].reg; - SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count); - return; - } + if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size)) + { + unsigned int offset = const_number - PSVar_Loc[a].reg; + SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count); + return; + } } } // CG Specific @@ -582,7 +582,7 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) GLenum err = GL_REPORT_ERROR(); if (err != GL_NO_ERROR) { - ERROR_LOG(VIDEO, "glError %08x before PS!", err); + ERROR_LOG(VIDEO, "glError %08x before PS!", err); } #if defined HAVE_CG && HAVE_CG @@ -591,28 +591,28 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) // handle errors if (!cgIsProgram(tempprog)) { - cgDestroyProgram(tempprog); + cgDestroyProgram(tempprog); - static int num_failures = 0; - char szTemp[MAX_PATH]; - sprintf(szTemp, "bad_ps_%04i.txt", num_failures++); - std::ofstream file(szTemp); - file << pstrprogram; - file.close(); + static int num_failures = 0; + char szTemp[MAX_PATH]; + sprintf(szTemp, "bad_ps_%04i.txt", num_failures++); + std::ofstream file(szTemp); + file << pstrprogram; + file.close(); - PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", - num_failures - 1, szTemp, - g_cgfProf, - cgGetLastListing(g_cgcontext)); + PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", + num_failures - 1, szTemp, + g_cgfProf, + cgGetLastListing(g_cgcontext)); - return false; + return false; } // handle warnings if (cgGetError() != CG_NO_ERROR) { - WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext)); - WARN_LOG(VIDEO, "%s", pstrprogram); + WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext)); + WARN_LOG(VIDEO, "%s", pstrprogram); } // This looks evil - we modify the program through the const char * we got from cgGetProgramString! @@ -621,9 +621,9 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) char *plocal = strstr(pcompiledprog, "program.local"); while (plocal != NULL) { - const char *penv = " program.env"; - memcpy(plocal, penv, 13); - plocal = strstr(plocal+13, "program.local"); + const char *penv = " program.env"; + memcpy(plocal, penv, 13); + plocal = strstr(plocal+13, "program.local"); } glGenProgramsARB(1, &ps.glprogid); @@ -634,23 +634,23 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) err = GL_REPORT_ERROR(); if (err != GL_NO_ERROR) { - GLint error_pos, native_limit; - glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); - glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit); - // Error occur - if (error_pos != -1) { - const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB); - char line[256]; - strncpy(line, (const char *)pcompiledprog + error_pos, 255); - line[255] = 0; - ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error); - ERROR_LOG(VIDEO, "Line dump: \n%s", line); - } else if (native_limit != -1) { - ERROR_LOG(VIDEO, "Hit limit? %i", native_limit); - // TODO - } - ERROR_LOG(VIDEO, "%s", pstrprogram); - ERROR_LOG(VIDEO, "%s", pcompiledprog); + GLint error_pos, native_limit; + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); + glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit); + // Error occur + if (error_pos != -1) { + const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB); + char line[256]; + strncpy(line, (const char *)pcompiledprog + error_pos, 255); + line[255] = 0; + ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error); + ERROR_LOG(VIDEO, "Line dump: \n%s", line); + } else if (native_limit != -1) { + ERROR_LOG(VIDEO, "Hit limit? %i", native_limit); + // TODO + } + ERROR_LOG(VIDEO, "%s", pstrprogram); + ERROR_LOG(VIDEO, "%s", pcompiledprog); } cgDestroyProgram(tempprog); @@ -672,21 +672,21 @@ void SetCGPSConstant4fv(unsigned int const_number, const float *f) void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { for (unsigned int i = 0; i < count; i++,f+=4) - glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f); + glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f); } // Renderer functions void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - pSetPSConstant4f(const_number, f1, f2, f3, f4); + pSetPSConstant4f(const_number, f1, f2, f3, f4); } void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f) { - pSetPSConstant4fv(const_number, f); + pSetPSConstant4fv(const_number, f); } void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { - pSetMultiPSConstant4fv(const_number, count, f); + pSetMultiPSConstant4fv(const_number, count, f); } } // namespace OGL diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index d66fd9ec19..15a5ff42a8 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -21,123 +21,123 @@ #include namespace OGL { - GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0; - ProgramShaderCache::PCache ProgramShaderCache::pshaders; - GLuint ProgramShaderCache::UBOBuffers[2]; + GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0; + ProgramShaderCache::PCache ProgramShaderCache::pshaders; + GLuint ProgramShaderCache::UBOBuffers[2]; - std::pair ProgramShaderCache::CurrentShaderProgram; - const char *UniformNames[NUM_UNIFORMS] = { - // SAMPLERS - "samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7", - // PIXEL SHADER UNIFORMS - I_COLORS, - I_KCOLORS, - I_ALPHA, - I_TEXDIMS, - I_ZBIAS , - I_INDTEXSCALE , - I_INDTEXMTX, - I_FOG, - I_PLIGHTS, - I_PMATERIALS, - // VERTEX SHADER UNIFORMS - I_POSNORMALMATRIX, - I_PROJECTION , - I_MATERIALS, - I_LIGHTS, - I_TEXMATRICES, - I_TRANSFORMMATRICES , - I_NORMALMATRICES , - I_POSTTRANSFORMMATRICES, - I_DEPTHPARAMS, - }; + std::pair ProgramShaderCache::CurrentShaderProgram; + const char *UniformNames[NUM_UNIFORMS] = { + // SAMPLERS + "samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7", + // PIXEL SHADER UNIFORMS + I_COLORS, + I_KCOLORS, + I_ALPHA, + I_TEXDIMS, + I_ZBIAS , + I_INDTEXSCALE , + I_INDTEXMTX, + I_FOG, + I_PLIGHTS, + I_PMATERIALS, + // VERTEX SHADER UNIFORMS + I_POSNORMALMATRIX, + I_PROJECTION , + I_MATERIALS, + I_LIGHTS, + I_TEXMATRICES, + I_TRANSFORMMATRICES , + I_NORMALMATRICES , + I_POSTTRANSFORMMATRICES, + I_DEPTHPARAMS, + }; - void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS) - { - PROGRAMUID uid; - CurrentFShader = PS; - CurrentVShader = VS; + void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS) + { + PROGRAMUID uid; + CurrentFShader = PS; + CurrentVShader = VS; - GetProgramShaderId(&uid, CurrentVShader, CurrentFShader); + GetProgramShaderId(&uid, CurrentVShader, CurrentFShader); - if(uid.uid.id == 0) - { - CurrentProgram = 0; - glUseProgram(0); - return; - } + if(uid.uid.id == 0) + { + CurrentProgram = 0; + glUseProgram(0); + return; + } - // Fragment shaders can survive without Vertex Shaders - // We have a valid fragment shader, let's create our program - std::pair ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid); - PCache::iterator iter = pshaders.find(ShaderPair); - if (iter != pshaders.end()) - { - PCacheEntry &entry = iter->second; - glUseProgram(entry.program.glprogid); - CurrentShaderProgram = ShaderPair; - CurrentProgram = entry.program.glprogid; - return; - } - PCacheEntry entry; - entry.program.vsid = CurrentVShader; - entry.program.psid = CurrentFShader; - entry.program.glprogid = glCreateProgram(); + // Fragment shaders can survive without Vertex Shaders + // We have a valid fragment shader, let's create our program + std::pair ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid); + PCache::iterator iter = pshaders.find(ShaderPair); + if (iter != pshaders.end()) + { + PCacheEntry &entry = iter->second; + glUseProgram(entry.program.glprogid); + CurrentShaderProgram = ShaderPair; + CurrentProgram = entry.program.glprogid; + return; + } + PCacheEntry entry; + entry.program.vsid = CurrentVShader; + entry.program.psid = CurrentFShader; + entry.program.glprogid = glCreateProgram(); - // Right, the program is created now - // Let's attach everything - if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out - glAttachShader(entry.program.glprogid, entry.program.vsid); - - glAttachShader(entry.program.glprogid, entry.program.psid); - - glLinkProgram(entry.program.glprogid); - - glUseProgram(entry.program.glprogid); + // Right, the program is created now + // Let's attach everything + if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out + glAttachShader(entry.program.glprogid, entry.program.vsid); + + glAttachShader(entry.program.glprogid, entry.program.psid); + + glLinkProgram(entry.program.glprogid); + + glUseProgram(entry.program.glprogid); - // Dunno why this is needed when I have the binding - // points statically set in the shader source - // We should only need these two functions when we don't support binding but do support UBO - // Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64 - //if(!g_ActiveConfig.backend_info.bSupportsGLSLBinding) - { + // Dunno why this is needed when I have the binding + // points statically set in the shader source + // We should only need these two functions when we don't support binding but do support UBO + // Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64 + //if(!g_ActiveConfig.backend_info.bSupportsGLSLBinding) + { glUniformBlockBinding( entry.program.glprogid, 0, 1 ); glUniformBlockBinding( entry.program.glprogid, 1, 2 ); } - // We cache our uniform locations for now - // Once we move up to a newer version of GLSL, ~1.30 - // We can remove this - - //For some reason this fails on my hardware - //glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations); - //Got to do it this crappy way. - if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO) + // We cache our uniform locations for now + // Once we move up to a newer version of GLSL, ~1.30 + // We can remove this + + //For some reason this fails on my hardware + //glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations); + //Got to do it this crappy way. + if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO) for(int a = 0; a < NUM_UNIFORMS; ++a) entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]); - // Need to get some attribute locations - if(uid.uid.vsid != 0) // We have no vertex Shader - { - entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1"); - entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2"); - entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx"); - if(entry.program.attrLoc[0] > 0) - glEnableVertexAttribArray(entry.program.attrLoc[0]); - if(entry.program.attrLoc[1] > 0) - glEnableVertexAttribArray(entry.program.attrLoc[1]); - if(entry.program.attrLoc[2] > 0) - glEnableVertexAttribArray(entry.program.attrLoc[2]); - } - else - entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0; + // Need to get some attribute locations + if(uid.uid.vsid != 0) // We have no vertex Shader + { + entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1"); + entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2"); + entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx"); + if(entry.program.attrLoc[0] > 0) + glEnableVertexAttribArray(entry.program.attrLoc[0]); + if(entry.program.attrLoc[1] > 0) + glEnableVertexAttribArray(entry.program.attrLoc[1]); + if(entry.program.attrLoc[2] > 0) + glEnableVertexAttribArray(entry.program.attrLoc[2]); + } + else + entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0; - pshaders[ShaderPair] = entry; - CurrentShaderProgram = ShaderPair; - CurrentProgram = entry.program.glprogid; - } + pshaders[ShaderPair] = entry; + CurrentShaderProgram = ShaderPair; + CurrentProgram = entry.program.glprogid; + } void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count) { assert(Buffer > 1); @@ -154,16 +154,16 @@ namespace OGL glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f); } - GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } + GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } - GLint ProgramShaderCache::GetAttr(int num) - { - return pshaders[CurrentShaderProgram].program.attrLoc[num]; - } - PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void) - { - return pshaders[CurrentShaderProgram].program; - } + GLint ProgramShaderCache::GetAttr(int num) + { + return pshaders[CurrentShaderProgram].program.attrLoc[num]; + } + PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void) + { + return pshaders[CurrentShaderProgram].program; + } void ProgramShaderCache::Init(void) { // We have to get the UBO alignment here because @@ -188,18 +188,18 @@ namespace OGL glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_VENVCONST_END * 4 * 4, Align), NULL, GL_DYNAMIC_DRAW); glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]); } - void ProgramShaderCache::Shutdown(void) - { - PCache::iterator iter = pshaders.begin(); - for (; iter != pshaders.end(); iter++) - iter->second.Destroy(); - pshaders.clear(); - glDeleteBuffers(2, UBOBuffers); - } + void ProgramShaderCache::Shutdown(void) + { + PCache::iterator iter = pshaders.begin(); + for (; iter != pshaders.end(); iter++) + iter->second.Destroy(); + pshaders.clear(); + glDeleteBuffers(2, UBOBuffers); + } } void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p) { - uid->uid.vsid = _v; - uid->uid.psid = _p; + uid->uid.vsid = _v; + uid->uid.psid = _p; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h index a5ff097af6..1c114551b8 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h @@ -25,39 +25,39 @@ #include "PixelShaderGen.h" #include "VertexShaderGen.h" - union PID - { - struct { - GLuint vsid, psid; - }; - u64 id; - }; + union PID + { + struct { + GLuint vsid, psid; + }; + u64 id; + }; class PROGRAMUID { public: - PID uid; + PID uid; - PROGRAMUID() - { - uid.id = 0; - } + PROGRAMUID() + { + uid.id = 0; + } - PROGRAMUID(const PROGRAMUID& r) - { - uid.id = r.uid.id; - } - PROGRAMUID(GLuint _v, GLuint _p) - { - uid.vsid = _v; - uid.psid = _p; - } + PROGRAMUID(const PROGRAMUID& r) + { + uid.id = r.uid.id; + } + PROGRAMUID(GLuint _v, GLuint _p) + { + uid.vsid = _v; + uid.psid = _p; + } - int GetNumValues() const - { - return uid.id; - } + int GetNumValues() const + { + return uid.id; + } }; void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p); @@ -69,43 +69,43 @@ extern const char *UniformNames[NUM_UNIFORMS]; struct PROGRAMSHADER { - PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){} - GLuint glprogid; // opengl program id - GLuint vsid, psid; - GLint attrLoc[3]; - GLint UniformLocations[NUM_UNIFORMS]; + PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){} + GLuint glprogid; // opengl program id + GLuint vsid, psid; + GLint attrLoc[3]; + GLint UniformLocations[NUM_UNIFORMS]; }; class ProgramShaderCache { - struct PCacheEntry - { - PROGRAMSHADER program; - int frameCount; - PCacheEntry() : frameCount(0) {} - void Destroy() { - glDeleteProgram(program.glprogid); - program.glprogid = 0; - } - }; - typedef std::map, PCacheEntry> PCache; + struct PCacheEntry + { + PROGRAMSHADER program; + int frameCount; + PCacheEntry() : frameCount(0) {} + void Destroy() { + glDeleteProgram(program.glprogid); + program.glprogid = 0; + } + }; + typedef std::map, PCacheEntry> PCache; - static PCache pshaders; - static GLuint CurrentFShader, CurrentVShader, CurrentProgram; - static std::pair CurrentShaderProgram; + static PCache pshaders; + static GLuint CurrentFShader, CurrentVShader, CurrentProgram; + static std::pair CurrentShaderProgram; - // For UBOS - static GLuint UBOBuffers[2]; // PS is 0, VS is 1 + // For UBOS + static GLuint UBOBuffers[2]; // PS is 0, VS is 1 public: - static PROGRAMSHADER GetShaderProgram(void); - static GLint GetAttr(int num); - static void SetBothShaders(GLuint PS, GLuint VS); - static GLuint GetCurrentProgram(void); - static void SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1); - - static void Init(void); - static void Shutdown(void); + static PROGRAMSHADER GetShaderProgram(void); + static GLint GetAttr(int num); + static void SetBothShaders(GLuint PS, GLuint VS); + static GLuint GetCurrentProgram(void); + static void SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1); + + static void Init(void); + static void Shutdown(void); }; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index d3a1283627..2fc02d867a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -208,7 +208,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, if (pcfmt != PC_TEX_FMT_DXT1) { if (expanded_width != width) - glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width); + glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width); if (bHaveMipMaps && autogen_mips) { @@ -222,7 +222,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, } if (expanded_width != width) - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } else { @@ -385,8 +385,8 @@ TextureCache::~TextureCache() { if (s_TempFramebuffer) { - glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); - s_TempFramebuffer = 0; + glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); + s_TempFramebuffer = 0; } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index f89ca38b05..ff4ecab624 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -407,7 +407,7 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf scaledSource.right = expandedWidth / samples; int cacheBytes = 32; if ((format & 0x0f) == 6) - cacheBytes = 64; + cacheBytes = 64; int readStride = (expandedWidth * cacheBytes) / TexDecoder_GetBlockWidthInTexels(format); g_renderer->ResetAPIState(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index 97dfc9a3bb..b665aeae98 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -61,20 +61,20 @@ void VertexShaderCache::Init() if(g_ActiveConfig.bUseGLSL) { - pSetVSConstant4f = SetGLSLVSConstant4f; - pSetVSConstant4fv = SetGLSLVSConstant4fv; - pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv; - pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv; - pCompileVertexShader = CompileGLSLVertexShader; + pSetVSConstant4f = SetGLSLVSConstant4f; + pSetVSConstant4fv = SetGLSLVSConstant4fv; + pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv; + pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv; + pCompileVertexShader = CompileGLSLVertexShader; } else { - pSetVSConstant4f = SetCGVSConstant4f; - pSetVSConstant4fv = SetCGVSConstant4fv; - pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv; - pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv; - pCompileVertexShader = CompileCGVertexShader; - glEnable(GL_VERTEX_PROGRAM_ARB); + pSetVSConstant4f = SetCGVSConstant4f; + pSetVSConstant4fv = SetCGVSConstant4fv; + pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv; + pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv; + pCompileVertexShader = CompileCGVertexShader; + glEnable(GL_VERTEX_PROGRAM_ARB); } glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions); @@ -82,7 +82,7 @@ void VertexShaderCache::Init() #if CG_VERSION_NUM == 2100 if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL) { - s_nMaxVertexInstructions = 4096; + s_nMaxVertexInstructions = 4096; } #endif } @@ -90,7 +90,7 @@ void VertexShaderCache::Init() void VertexShaderCache::Shutdown() { for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter) - iter->second.Destroy(); + iter->second.Destroy(); vshaders.clear(); } @@ -101,12 +101,12 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components) GetVertexShaderId(&uid, components); if (last_entry) { - if (uid == last_uid) - { - GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); - ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components); - return &last_entry->shader; - } + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); + ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components); + return &last_entry->shader; + } } last_uid = uid; @@ -114,12 +114,12 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components) VSCache::iterator iter = vshaders.find(uid); if (iter != vshaders.end()) { - VSCacheEntry &entry = iter->second; - last_entry = &entry; + VSCacheEntry &entry = iter->second; + last_entry = &entry; - GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); - ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components); - return &last_entry->shader; + GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); + ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components); + return &last_entry->shader; } // Make an entry in the table @@ -130,17 +130,17 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components) #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) { - static int counter = 0; - char szTemp[MAX_PATH]; - sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); + static int counter = 0; + char szTemp[MAX_PATH]; + sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); - SaveData(szTemp, code); + SaveData(szTemp, code); } #endif if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) { - GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); - return NULL; + GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); + return NULL; } INCSTAT(stats.numVertexShadersCreated); @@ -160,8 +160,8 @@ void VertexShaderCache::DisableShader() assert(true); if (ShaderEnabled) { - glDisable(GL_VERTEX_PROGRAM_ARB); - ShaderEnabled = false; + glDisable(GL_VERTEX_PROGRAM_ARB); + ShaderEnabled = false; } } @@ -172,14 +172,14 @@ void VertexShaderCache::SetCurrentShader(GLuint Shader) assert(true); if (!ShaderEnabled) { - glEnable(GL_VERTEX_PROGRAM_ARB); - ShaderEnabled= true; + glEnable(GL_VERTEX_PROGRAM_ARB); + ShaderEnabled= true; } if (CurrentShader != Shader) { - if(Shader != 0) - CurrentShader = Shader; - glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); + if(Shader != 0) + CurrentShader = Shader; + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); } } // GLSL Specific @@ -227,16 +227,16 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float { PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram(); for(int a = 0; a < NUM_UNIFORMS; ++a) - if(!strcmp(name, UniformNames[a])) - { - if(tmp.UniformLocations[a] == -1) - return; - else - { - glUniform4fv(tmp.UniformLocations[a] + offset, count, f); - return; - } - } + if(!strcmp(name, UniformNames[a])) + { + if(tmp.UniformLocations[a] == -1) + return; + else + { + glUniform4fv(tmp.UniformLocations[a] + offset, count, f); + return; + } + } } void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { @@ -252,12 +252,12 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3 } for( unsigned int a = 0; a < 9; ++a) { - if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf); - return; - } + if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) + { + unsigned int offset = const_number - VSVar_Loc[a].reg; + SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf); + return; + } } } @@ -270,12 +270,12 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f) } for( unsigned int a = 0; a < 9; ++a) { - if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f); - return; - } + if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) + { + unsigned int offset = const_number - VSVar_Loc[a].reg; + SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f); + return; + } } } @@ -288,12 +288,12 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co } for( unsigned int a = 0; a < 9; ++a) { - if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count); - return; - } + if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) + { + unsigned int offset = const_number - VSVar_Loc[a].reg; + SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count); + return; + } } } @@ -302,10 +302,10 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co float buf[4 * C_VENVCONST_END]; for (unsigned int i = 0; i < count; i++) { - buf[4*i ] = *f++; - buf[4*i+1] = *f++; - buf[4*i+2] = *f++; - buf[4*i+3] = 0.f; + buf[4*i ] = *f++; + buf[4*i+1] = *f++; + buf[4*i+2] = *f++; + buf[4*i+3] = 0.f; } if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { @@ -314,12 +314,12 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co } for( unsigned int a = 0; a < 9; ++a) { - if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) - { - unsigned int offset = const_number - VSVar_Loc[a].reg; - SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count); - return; - } + if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size)) + { + unsigned int offset = const_number - VSVar_Loc[a].reg; + SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count); + return; + } } } @@ -330,34 +330,34 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram) GLenum err = GL_REPORT_ERROR(); if (err != GL_NO_ERROR) { - ERROR_LOG(VIDEO, "glError %08x before VS!", err); + ERROR_LOG(VIDEO, "glError %08x before VS!", err); } #if defined HAVE_CG && HAVE_CG CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL); if (!cgIsProgram(tempprog)) { - static int num_failures = 0; - char szTemp[MAX_PATH]; - sprintf(szTemp, "bad_vs_%04i.txt", num_failures++); - std::ofstream file(szTemp); - file << pstrprogram; - file.close(); + static int num_failures = 0; + char szTemp[MAX_PATH]; + sprintf(szTemp, "bad_vs_%04i.txt", num_failures++); + std::ofstream file(szTemp); + file << pstrprogram; + file.close(); - PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", - num_failures - 1, szTemp, - g_cgfProf, - cgGetLastListing(g_cgcontext)); + PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", + num_failures - 1, szTemp, + g_cgfProf, + cgGetLastListing(g_cgcontext)); - cgDestroyProgram(tempprog); - ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); - ERROR_LOG(VIDEO, "%s", pstrprogram); - return false; + cgDestroyProgram(tempprog); + ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); + ERROR_LOG(VIDEO, "%s", pstrprogram); + return false; } if (cgGetError() != CG_NO_ERROR) { - WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); - WARN_LOG(VIDEO, "%s", pstrprogram); + WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); + WARN_LOG(VIDEO, "%s", pstrprogram); } // This looks evil - we modify the program through the const char * we got from cgGetProgramString! @@ -365,9 +365,9 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram) char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM); char *plocal = strstr(pcompiledprog, "program.local"); while (plocal != NULL) { - const char* penv = " program.env"; - memcpy(plocal, penv, 13); - plocal = strstr(plocal + 13, "program.local"); + const char* penv = " program.env"; + memcpy(plocal, penv, 13); + plocal = strstr(plocal + 13, "program.local"); } glGenProgramsARB(1, &vs.glprogid); vs.bGLSL = false; @@ -376,15 +376,15 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram) glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog); err = GL_REPORT_ERROR(); if (err != GL_NO_ERROR) { - ERROR_LOG(VIDEO, "%s", pstrprogram); - ERROR_LOG(VIDEO, "%s", pcompiledprog); + ERROR_LOG(VIDEO, "%s", pstrprogram); + ERROR_LOG(VIDEO, "%s", pcompiledprog); } cgDestroyProgram(tempprog); #endif if (g_ActiveConfig.bEnableShaderDebugging) - vs.strprog = pstrprogram; + vs.strprog = pstrprogram; return true; } @@ -402,12 +402,12 @@ void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, cons { if(GLEW_EXT_gpu_program_parameters) { - glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f); + glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f); } else { - for (unsigned int i = 0; i < count; i++,f+=4) - glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f); + for (unsigned int i = 0; i < count; i++,f+=4) + glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f); } } @@ -415,49 +415,49 @@ void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, cons { if(GLEW_EXT_gpu_program_parameters) { - float buf[4 * C_VENVCONST_END]; - for (unsigned int i = 0; i < count; i++) - { - buf[4*i ] = *f++; - buf[4*i+1] = *f++; - buf[4*i+2] = *f++; - buf[4*i+3] = 0.f; - } - glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf); + float buf[4 * C_VENVCONST_END]; + for (unsigned int i = 0; i < count; i++) + { + buf[4*i ] = *f++; + buf[4*i+1] = *f++; + buf[4*i+2] = *f++; + buf[4*i+3] = 0.f; + } + glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf); } else { - for (unsigned int i = 0; i < count; i++) - { - float buf[4]; - buf[0] = *f++; - buf[1] = *f++; - buf[2] = *f++; - buf[3] = 0.f; - glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf); - } + for (unsigned int i = 0; i < count; i++) + { + float buf[4]; + buf[0] = *f++; + buf[1] = *f++; + buf[2] = *f++; + buf[3] = 0.f; + glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf); + } } } // Renderer Functions void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { - pSetVSConstant4f(const_number, f1, f2, f3, f4); + pSetVSConstant4f(const_number, f1, f2, f3, f4); } void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f) { - pSetVSConstant4fv(const_number, f); + pSetVSConstant4fv(const_number, f); } void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) { - pSetMultiVSConstant4fv(const_number, count, f); + pSetMultiVSConstant4fv(const_number, count, f); } void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) { - pSetMultiVSConstant3fv(const_number, count, f); + pSetMultiVSConstant3fv(const_number, count, f); } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index c4e2a8f0ea..8b25d5c47c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -109,23 +109,23 @@ std::string VideoBackend::GetName() void GetShaders(std::vector &shaders) { - shaders.clear(); - if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX))) - { - File::FSTEntry entry; - File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry); - for (u32 i = 0; i < entry.children.size(); i++) - { - std::string name = entry.children[i].virtualName.c_str(); - if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt")) - name = name.substr(0, name.size() - 4); - shaders.push_back(name); - } - } - else - { - File::CreateDir(File::GetUserPath(D_SHADERS_IDX).c_str()); - } + shaders.clear(); + if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX))) + { + File::FSTEntry entry; + File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry); + for (u32 i = 0; i < entry.children.size(); i++) + { + std::string name = entry.children[i].virtualName.c_str(); + if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt")) + name = name.substr(0, name.size() - 4); + shaders.push_back(name); + } + } + else + { + File::CreateDir(File::GetUserPath(D_SHADERS_IDX).c_str()); + } } void InitBackendInfo()