summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2011-12-17 01:06:55 -0600
committerRyan Houdek <Sonicadvance1@gmail.com>2011-12-17 01:06:55 -0600
commitb837ae25fc9db2ae2fa9708038b1db8733a13020 (patch)
treefafb26096616ed13df6c2ef5db2b5e42af585df4 /Source
parent73c3f198f4188629eb3bcac123f8516135a86a4c (diff)
Set Sampler values at program make time instead of every frame. Fix an issue when The user had UBO support but not Binding support.
Diffstat (limited to 'Source')
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp217
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h4
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp10
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp3
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp2
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp19
6 files changed, 79 insertions, 176 deletions
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
index 9556c12995..6b171a3f03 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
@@ -119,141 +119,81 @@ void PixelShaderCache::Init()
if(g_ActiveConfig.bUseGLSL)
{
char pmatrixprog[2048];
- if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
- {
- sprintf(pmatrixprog, "#version 330 compatibility\n"
- "#extension GL_ARB_texture_rectangle : enable\n"
- "#extension GL_ARB_shading_language_420pack : enable\n"
- "layout(binding = 0) uniform sampler2DRect samp0;\n"
- "%s\n"
- "%svec4 "I_COLORS"[7];\n"
- "%s\n"
- "void main(){\n"
- "vec4 Temp0, Temp1;\n"
- "vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
- "Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
- "Temp0 = Temp0 * "I_COLORS"[%d];\n"
- "Temp0 = Temp0 + K0;\n"
- "Temp0 = floor(Temp0);\n"
- "Temp0 = Temp0 * "I_COLORS"[%d];\n"
- "Temp1.x = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.y = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.z = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
- "gl_FragData[0] = Temp1 + "I_COLORS"[%d];\n"
- "}\n",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140, binding = 1) uniform PSBlock {" : "",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
- C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- }
- else
- {
- sprintf(pmatrixprog, "#version 120\n"
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect samp0;\n"
- "%s\n"
- "%svec4 "I_COLORS"[7];\n"
- "%s\n"
- "void main(){\n"
- "vec4 Temp0, Temp1;\n"
- "vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
- "Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
- "Temp0 = Temp0 * "I_COLORS"[%d];\n"
- "Temp0 = Temp0 + K0;\n"
- "Temp0 = floor(Temp0);\n"
- "Temp0 = Temp0 * "I_COLORS"[%d];\n"
- "Temp1.x = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.y = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.z = dot(Temp0, "I_COLORS"[%d]);\n"
- "Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
- "gl_FragData[0] = Temp1 + "I_COLORS"[%d];\n"
- "}\n",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
- C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- }
+ sprintf(pmatrixprog, "#version %s\n"
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "%s\n"
+ "%suniform sampler2DRect samp0;\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[7];\n"
+ "%s\n"
+ "void main(){\n"
+ "vec4 Temp0, Temp1;\n"
+ "vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
+ "Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
+ "Temp0 = Temp0 * "I_COLORS"[%d];\n"
+ "Temp0 = Temp0 + K0;\n"
+ "Temp0 = floor(Temp0);\n"
+ "Temp0 = Temp0 * "I_COLORS"[%d];\n"
+ "Temp1.x = dot(Temp0, "I_COLORS"[%d]);\n"
+ "Temp1.y = dot(Temp0, "I_COLORS"[%d]);\n"
+ "Temp1.z = dot(Temp0, "I_COLORS"[%d]);\n"
+ "Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
+ "gl_FragData[0] = Temp1 + "I_COLORS"[%d];\n"
+ "}\n",
+ (g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
+ g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+
+
if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
- if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
- {
- sprintf(pmatrixprog, "#version 330 compatibility\n"
- "#extension GL_ARB_texture_rectangle : enable\n"
- "#extension GL_ARB_shading_language_420pack : enable\n"
- "layout(binding = 0) uniform sampler2DRect samp0;\n"
- "%s\n"
- "%svec4 "I_COLORS"[5];\n"
- "%s\n"
- "void main(){\n"
- "vec4 R0, R1, R2;\n"
- "vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
- "vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
- "R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
- "R0.x = R2.x * K0.x;\n"
- "R0.x = floor(R0).x;\n"
- "R0.yzw = (R0 - R0.x).yzw;\n"
- "R0.yzw = (R0 * K0.z).yzw;\n"
- "R0.y = floor(R0).y;\n"
- "R0.zw = (R0 - R0.y).zw;\n"
- "R0.zw = (R0 * K0.z).zw;\n"
- "R0.z = floor(R0).z;\n"
- "R0.w = R0.x;\n"
- "R0 = R0 * K0.y;\n"
- "R0.w = (R0 * K1.x).w;\n"
- "R0.w = floor(R0).w;\n"
- "R0.w = (R0 * K1.y).w;\n"
- "R1.x = dot(R0, "I_COLORS"[%d]);\n"
- "R1.y = dot(R0, "I_COLORS"[%d]);\n"
- "R1.z = dot(R0, "I_COLORS"[%d]);\n"
- "R1.w = dot(R0, "I_COLORS"[%d]);\n"
- "gl_FragData[0] = R1 * "I_COLORS"[%d];\n"
- "}\n",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140, binding = 1) uniform PSBlock {" : "",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
- C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- }
- else
- {
- sprintf(pmatrixprog, "#version 120\n"
- "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect samp0;\n"
- "%s\n"
- "%svec4 "I_COLORS"[5];\n"
- "%s\n"
- "void main(){\n"
- "vec4 R0, R1, R2;\n"
- "vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
- "vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
- "R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
- "R0.x = R2.x * K0.x;\n"
- "R0.x = floor(R0).x;\n"
- "R0.yzw = (R0 - R0.x).yzw;\n"
- "R0.yzw = (R0 * K0.z).yzw;\n"
- "R0.y = floor(R0).y;\n"
- "R0.zw = (R0 - R0.y).zw;\n"
- "R0.zw = (R0 * K0.z).zw;\n"
- "R0.z = floor(R0).z;\n"
- "R0.w = R0.x;\n"
- "R0 = R0 * K0.y;\n"
- "R0.w = (R0 * K1.x).w;\n"
- "R0.w = floor(R0).w;\n"
- "R0.w = (R0 * K1.y).w;\n"
- "R1.x = dot(R0, "I_COLORS"[%d]);\n"
- "R1.y = dot(R0, "I_COLORS"[%d]);\n"
- "R1.z = dot(R0, "I_COLORS"[%d]);\n"
- "R1.w = dot(R0, "I_COLORS"[%d]);\n"
- "gl_FragData[0] = R1 * "I_COLORS"[%d];\n"
- "}\n",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
- g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
- C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- }
+
+ sprintf(pmatrixprog, "#version %s\n"
+ "#extension GL_ARB_texture_rectangle : enable\n"
+ "%s\n"
+ "%suniform sampler2DRect samp0;\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[5];\n"
+ "%s\n"
+ "void main(){\n"
+ "vec4 R0, R1, R2;\n"
+ "vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
+ "vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
+ "R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
+ "R0.x = R2.x * K0.x;\n"
+ "R0.x = floor(R0).x;\n"
+ "R0.yzw = (R0 - R0.x).yzw;\n"
+ "R0.yzw = (R0 * K0.z).yzw;\n"
+ "R0.y = floor(R0).y;\n"
+ "R0.zw = (R0 - R0.y).zw;\n"
+ "R0.zw = (R0 * K0.z).zw;\n"
+ "R0.z = floor(R0).z;\n"
+ "R0.w = R0.x;\n"
+ "R0 = R0 * K0.y;\n"
+ "R0.w = (R0 * K1.x).w;\n"
+ "R0.w = floor(R0).w;\n"
+ "R0.w = (R0 * K1.y).w;\n"
+ "R1.x = dot(R0, "I_COLORS"[%d]);\n"
+ "R1.y = dot(R0, "I_COLORS"[%d]);\n"
+ "R1.z = dot(R0, "I_COLORS"[%d]);\n"
+ "R1.w = dot(R0, "I_COLORS"[%d]);\n"
+ "gl_FragData[0] = R1 * "I_COLORS"[%d];\n"
+ "}\n",
+ (g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
+ g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+
if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
@@ -492,23 +432,6 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
ps.bGLSL = true;
return true;
}
-void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
-{
- if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
- 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;
- }
- }
-}
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
{
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
index 6547b95234..b0328f336c 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
@@ -78,8 +78,6 @@ class PixelShaderCache
public:
static void Init();
static void Shutdown();
- // This is a GLSL only function
- static void SetPSSampler(const char * name, unsigned int Tex);
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
@@ -88,8 +86,6 @@ public:
static GLuint GetDepthMatrixProgram();
- static bool SupportsBinding();
-
static void SetCurrentShader(GLuint Shader);
static void DisableShader();
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
index c90f151421..14542bf68f 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
@@ -114,9 +114,17 @@ namespace OGL
//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)
+ if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for(int a = 0; a < NUM_UNIFORMS; ++a)
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
+ else if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ for(int a = 0; a < 8; ++a)
+ {
+ // Still need to get sampler locations since we aren't binding them statically in the shaders
+ entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
+ if(entry.program.UniformLocations[a] != -1)
+ glUniform1i(entry.program.UniformLocations[a], a);
+ }
// Need to get some attribute locations
if(uid.uid.vsid != 0) // We have no vertex Shader
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
index 2fc02d867a..1a4b8bb55f 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp
@@ -298,10 +298,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
glViewport(0, 0, virtualW, virtualH);
if(g_ActiveConfig.bUseGLSL)
- {
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
- PixelShaderCache::SetPSSampler("samp0", 0);
- }
else
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
PixelShaderManager::SetColorMatrix(colmat); // set transformation
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
index 213d92098a..0b0cae3aa3 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
@@ -314,8 +314,6 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
}
GL_REPORT_ERRORD();
- if(g_ActiveConfig.bUseGLSL)
- PixelShaderCache::SetPSSampler("samp0", 0);
glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
index fff8263569..cb8e010794 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp
@@ -219,16 +219,6 @@ void VertexManager::vFlush()
if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();
GL_REPORT_ERRORD();
- if(g_ActiveConfig.bUseGLSL)
- for (int i = 0; i < 8; i++)
- {
- if (usedtextures & (1 << i))
- {
- char tmp[16];
- sprintf(tmp, "samp%d", i); // Bake this in to something so we don't have to sprintf?
- PixelShaderCache::SetPSSampler(tmp, i);
- }
- }
Draw();
@@ -243,15 +233,6 @@ void VertexManager::vFlush()
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
if (g_nativeVertexFmt)
g_nativeVertexFmt->SetupVertexPointers();
- for (int i = 0; i < 8; i++)
- {
- if (usedtextures & (1 << i))
- {
- char tmp[16];
- sprintf(tmp, "samp%d", i); // Bake this in to something so we don't have to sprintf?
- PixelShaderCache::SetPSSampler(tmp, i);
- }
- }
}
else
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);