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:
Ryan Houdek
2011-12-08 01:51:08 -06:00
parent f77d54ff52
commit 1201988fe4
7 changed files with 252 additions and 91 deletions

View File

@ -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