mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
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.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user