summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2011-12-08 01:51:08 -0600
committerRyan Houdek <Sonicadvance1@gmail.com>2011-12-08 01:51:08 -0600
commit1201988fe4e94720f32f2165ee03d5debf957cd7 (patch)
treec6190f131699fa161e0856db3e764f2a5b80ee15 /Source
parentf77d54ff52c19ae7b61e2bc7e59d5de1a6e22722 (diff)
Add support for GL_ARB_shading_language_420pack so we don't have to binding sampler locations. Also add support for GL_ARB_separate_shader_objects which doesn't currently work for some reason....investigating.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/VideoCommon/Src/PixelShaderGen.cpp93
-rw-r--r--Source/Core/VideoCommon/Src/TextureConversionShader.cpp13
-rw-r--r--Source/Core/VideoCommon/Src/VertexShaderGen.cpp34
-rw-r--r--Source/Core/VideoCommon/Src/VideoConfig.h2
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp179
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h2
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp20
7 files changed, 252 insertions, 91 deletions
diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
index dcfa2da05d..3d328ed70c 100644
--- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp
@@ -508,6 +508,22 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
sprintf(result, " : register(%s%d)", prefix, num);
return result;
}
+const char* WriteBinding(API_TYPE ApiType, const u32 num)
+{
+ if(ApiType != API_GLSL || !g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ return "";
+ static char result[64];
+ sprintf(result, "layout(binding = %d) ", num);
+ return result;
+}
+const char* WriteLocation(API_TYPE ApiType, const u32 num)
+{
+ if(ApiType != API_GLSL || !g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ return "";
+ static char result[64];
+ sprintf(result, "layout(location = %d) ", num);
+ return result;
+}
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
{
@@ -537,7 +553,16 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if(ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
- WRITE(p, "#version 120\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ WRITE(p, "#version 330 compatibility\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
+ }
+ else
+ WRITE(p, "#version 120\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
@@ -547,52 +572,58 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "#define frac(x) fract(x)\n");
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
- }
- // Declare samplers
-
- if(ApiType != API_D3D11)
- {
- WRITE(p, "uniform sampler2D ");
+
+ for (int i = 0; i < 8; ++i)
+ WRITE(p, "%suniform sampler2D samp%d;\n", WriteBinding(ApiType, i), i);
}
else
{
- WRITE(p, "sampler ");
- }
+ // Declare samplers
- bool bfirst = true;
- for (int i = 0; i < 8; ++i)
- {
- WRITE(p, "%s samp%d %s", bfirst?"":",", i, WriteRegister(ApiType, "s", i));
- bfirst = false;
- }
- WRITE(p, ";\n");
- if(ApiType == API_D3D11)
- {
- WRITE(p, "Texture2D ");
- bfirst = true;
+ if(ApiType != API_D3D11)
+ {
+ WRITE(p, "uniform sampler2D ");
+ }
+ else
+ {
+ WRITE(p, "sampler ");
+ }
+
+ bool bfirst = true;
for (int i = 0; i < 8; ++i)
{
- WRITE(p, "%s Tex%d : register(t%d)", bfirst?"":",", i, i);
+ WRITE(p, "%s samp%d %s", bfirst?"":",", i, WriteRegister(ApiType, "s", i));
bfirst = false;
}
WRITE(p, ";\n");
+ if(ApiType == API_D3D11)
+ {
+ WRITE(p, "Texture2D ");
+ bfirst = true;
+ for (int i = 0; i < 8; ++i)
+ {
+ WRITE(p, "%s Tex%d : register(t%d)", bfirst?"":",", i, i);
+ bfirst = false;
+ }
+ WRITE(p, ";\n");
+ }
}
WRITE(p, "\n");
- WRITE(p, "uniform float4 "I_COLORS"[4] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
- WRITE(p, "uniform float4 "I_KCOLORS"[4] %s;\n", WriteRegister(ApiType, "c", C_KCOLORS));
- WRITE(p, "uniform float4 "I_ALPHA"[1] %s;\n", WriteRegister(ApiType, "c", C_ALPHA));
- WRITE(p, "uniform float4 "I_TEXDIMS"[8] %s;\n", WriteRegister(ApiType, "c", C_TEXDIMS));
- WRITE(p, "uniform float4 "I_ZBIAS"[2] %s;\n", WriteRegister(ApiType, "c", C_ZBIAS));
- WRITE(p, "uniform float4 "I_INDTEXSCALE"[2] %s;\n", WriteRegister(ApiType, "c", C_INDTEXSCALE));
- WRITE(p, "uniform float4 "I_INDTEXMTX"[6] %s;\n", WriteRegister(ApiType, "c", C_INDTEXMTX));
- WRITE(p, "uniform float4 "I_FOG"[3] %s;\n", WriteRegister(ApiType, "c", C_FOG));
+ WRITE(p, "%suniform float4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType, C_COLORS), WriteRegister(ApiType, "c", C_COLORS));
+ WRITE(p, "%suniform float4 "I_KCOLORS"[4] %s;\n", WriteLocation(ApiType, C_KCOLORS), WriteRegister(ApiType, "c", C_KCOLORS));
+ WRITE(p, "%suniform float4 "I_ALPHA"[1] %s;\n", WriteLocation(ApiType, C_ALPHA), WriteRegister(ApiType, "c", C_ALPHA));
+ WRITE(p, "%suniform float4 "I_TEXDIMS"[8] %s;\n", WriteLocation(ApiType, C_TEXDIMS), WriteRegister(ApiType, "c", C_TEXDIMS));
+ WRITE(p, "%suniform float4 "I_ZBIAS"[2] %s;\n", WriteLocation(ApiType, C_ZBIAS), WriteRegister(ApiType, "c", C_ZBIAS));
+ WRITE(p, "%suniform float4 "I_INDTEXSCALE"[2] %s;\n", WriteLocation(ApiType, C_INDTEXSCALE), WriteRegister(ApiType, "c", C_INDTEXSCALE));
+ WRITE(p, "%suniform float4 "I_INDTEXMTX"[6] %s;\n", WriteLocation(ApiType, C_INDTEXMTX), WriteRegister(ApiType, "c", C_INDTEXMTX));
+ WRITE(p, "%suniform float4 "I_FOG"[3] %s;\n", WriteLocation(ApiType, C_FOG), WriteRegister(ApiType, "c", C_FOG));
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
- WRITE(p, "uniform float4 "I_PLIGHTS"[40] %s;\n", WriteRegister(ApiType, "c", C_PLIGHTS));
- WRITE(p, "uniform float4 "I_PMATERIALS"[4] %s;\n", WriteRegister(ApiType, "c", C_PMATERIALS));
+ WRITE(p, "%suniform float4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType, C_PLIGHTS), WriteRegister(ApiType, "c", C_PLIGHTS));
+ WRITE(p, "%suniform float4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType, C_PMATERIALS), WriteRegister(ApiType, "c", C_PMATERIALS));
}
if(ApiType != API_GLSL)
diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
index bf45484850..1be760a608 100644
--- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
+++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
@@ -26,6 +26,7 @@
#include "PixelShaderGen.h"
#include "BPMemory.h"
#include "RenderBase.h"
+#include "VideoConfig.h"
#define WRITE p+=sprintf
@@ -92,6 +93,8 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
}
else if (ApiType == API_GLSL)
{
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ WRITE(p, "layout(binding = 0) ");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
@@ -177,6 +180,8 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
}
else if (ApiType == API_GLSL)
{
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ WRITE(p, "layout(binding = 0) ");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
@@ -834,7 +839,13 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
if(ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
- WRITE(p, "#version 120\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ {
+ WRITE(p, "#version 330 compatibility\n");
+ WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
+ }
+ else
+ WRITE(p, "#version 120\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
index 9a6a220979..78feff6541 100644
--- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp
@@ -164,7 +164,8 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType)
}
extern const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num);
-
+extern const char* WriteBinding(API_TYPE ApiType, const u32 num);
+extern const char* WriteLocation(API_TYPE ApiType, const u32 num);
const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
{
@@ -187,7 +188,16 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if(ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
- WRITE(p, "#version 120\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ WRITE(p, "#version 330 compatibility\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ WRITE(p, "#extension GL_ARB_separate_shader_objects : enable\n");
+ }
+ else
+ WRITE(p, "#version 120\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
@@ -199,15 +209,15 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
}
// uniforms
- WRITE(p, "uniform float4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
- WRITE(p, "uniform float4 "I_TEXMATRICES"[24] %s;\n", WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
- WRITE(p, "uniform float4 "I_NORMALMATRICES"[32] %s;\n", WriteRegister(ApiType, "c", C_NORMALMATRICES));
- WRITE(p, "uniform float4 "I_POSNORMALMATRIX"[6] %s;\n", WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
- WRITE(p, "uniform float4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
- WRITE(p, "uniform float4 "I_LIGHTS"[40] %s;\n", WriteRegister(ApiType, "c", C_LIGHTS));
- WRITE(p, "uniform float4 "I_MATERIALS"[4] %s;\n", WriteRegister(ApiType, "c", C_MATERIALS));
- WRITE(p, "uniform float4 "I_PROJECTION"[4] %s;\n", WriteRegister(ApiType, "c", C_PROJECTION));
- WRITE(p, "uniform float4 "I_DEPTHPARAMS" %s;\n", WriteRegister(ApiType, "c", C_DEPTHPARAMS));
+ WRITE(p, "%suniform float4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType, C_TRANSFORMMATRICES), WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
+ WRITE(p, "%suniform float4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType, C_TEXMATRICES), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
+ WRITE(p, "%suniform float4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType, C_NORMALMATRICES), WriteRegister(ApiType, "c", C_NORMALMATRICES));
+ WRITE(p, "%suniform float4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType, C_POSNORMALMATRIX), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
+ WRITE(p, "%suniform float4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType, C_POSTTRANSFORMMATRICES), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
+ WRITE(p, "%suniform float4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType, C_LIGHTS), WriteRegister(ApiType, "c", C_LIGHTS));
+ WRITE(p, "%suniform float4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType, C_MATERIALS), WriteRegister(ApiType, "c", C_MATERIALS));
+ WRITE(p, "%suniform float4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType, C_PROJECTION), WriteRegister(ApiType, "c", C_PROJECTION));
+ WRITE(p, "%suniform float4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType, C_DEPTHPARAMS), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
p = GenerateVSOutputStruct(p, components, ApiType);
@@ -403,7 +413,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (components & (VB_HAS_NRM1|VB_HAS_NRM2)) {
// transform the light dir into tangent space
- WRITE(p, "ldir = normalize("I_LIGHTS".lights[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift);
+ WRITE(p, "ldir = normalize("I_LIGHTS"[%d + 3].xyz - pos.xyz);\n", texinfo.embosslightshift);
WRITE(p, "o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift);
}
else
diff --git a/Source/Core/VideoCommon/Src/VideoConfig.h b/Source/Core/VideoCommon/Src/VideoConfig.h
index 63df7e0ded..414086ed15 100644
--- a/Source/Core/VideoCommon/Src/VideoConfig.h
+++ b/Source/Core/VideoCommon/Src/VideoConfig.h
@@ -168,6 +168,8 @@ struct VideoConfig
bool bSupportsFormatReinterpretation;
bool bSupportsPixelLighting;
bool bSupportsGLSL;
+ bool bSupportsGLSLBinding;
+ bool bSupportsGLSLLocation;
} backend_info;
};
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
index b3e8b09b18..5ee839676c 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
@@ -63,7 +63,6 @@ GLuint PixelShaderCache::GetColorMatrixProgram()
{
return s_ColorMatrixProgram.glprogid;
}
-
void PixelShaderCache::Init()
{
ShaderEnabled = true;
@@ -79,6 +78,12 @@ void PixelShaderCache::Init()
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_ActiveConfig.backend_info.bSupportsGLSLBinding = true;
+ // This bit doesn't quite work yet, always set to false
+ //if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_separate_shader_objects") != NULL)
+ g_ActiveConfig.backend_info.bSupportsGLSLLocation = false;
}
else
{
@@ -108,56 +113,118 @@ void PixelShaderCache::Init()
if(g_ActiveConfig.bUseGLSL)
{
char pmatrixprog[2048];
- sprintf(pmatrixprog, "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[7];\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", C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- if(!pCompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
+ 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"
+ "uniform vec4 "I_COLORS"[7];\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", 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"
+ "uniform vec4 "I_COLORS"[7];\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", C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ }
+ if (!pCompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
}
- sprintf(pmatrixprog, "#extension GL_ARB_texture_rectangle : enable\n"
- "uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[5];\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", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
- if(!pCompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
+ 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"
+ "uniform vec4 "I_COLORS"[5];\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", 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"
+ "uniform vec4 "I_COLORS"[5];\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", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ }
+ if (!pCompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
s_DepthMatrixProgram.Destroy();
@@ -398,6 +465,8 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
}
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]))
@@ -429,6 +498,12 @@ void SetPSConstant4fvByName(const char * name, unsigned int offset, const float
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
float f[4] = { f1, f2, f3, f4 };
+
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, 1, f);
+ return;
+ }
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))
@@ -442,6 +517,11 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
{
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, 1, f);
+ return;
+ }
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))
@@ -455,6 +535,11 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, count, f);
+ return;
+ }
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))
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
index d5e2cae6bc..6547b95234 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h
@@ -88,6 +88,8 @@ public:
static GLuint GetDepthMatrixProgram();
+ static bool SupportsBinding();
+
static void SetCurrentShader(GLuint Shader);
static void DisableShader();
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp
index e51e70d9eb..143340277e 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp
@@ -247,6 +247,11 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
buf[1] = f2;
buf[2] = f3;
buf[3] = f4;
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, 1, buf);
+ return;
+ }
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))
@@ -260,6 +265,11 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
{
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, 1, f);
+ return;
+ }
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))
@@ -273,6 +283,11 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, count, f);
+ return;
+ }
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))
@@ -294,6 +309,11 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
buf[4*i+2] = *f++;
buf[4*i+3] = 0.f;
}
+ if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
+ {
+ glUniform4fv(const_number, count, buf);
+ return;
+ }
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))