fix formatting uglies introduced in glsl-master branch

This commit is contained in:
Shawn Hoffman
2011-12-26 00:15:54 -05:00
committed by Sonicadvance1
parent 4a4833e617
commit 31a8424bcc
15 changed files with 1061 additions and 1051 deletions

View File

@ -511,23 +511,25 @@ static void BuildSwapModeTable()
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
return ""; // Nothing to do here
static char result[64];
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)
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)
{
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return "";
static char result[64];
sprintf(result, "uniform ");
@ -559,7 +561,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -573,7 +575,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
else
WRITE(p, "#version 120\n");
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
@ -602,7 +604,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{
// Declare samplers
if(ApiType != API_D3D11)
if (ApiType != API_D3D11)
{
WRITE(p, "uniform sampler2D ");
}
@ -618,7 +620,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
bfirst = false;
}
WRITE(p, ";\n");
if(ApiType == API_D3D11)
if (ApiType == API_D3D11)
{
WRITE(p, "Texture2D ");
bfirst = true;
@ -632,7 +634,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
WRITE(p, "\n");
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform PSBlock {\n");
WRITE(p, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
@ -648,13 +650,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "%sfloat4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS));
WRITE(p, "%sfloat4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
if(ApiType != API_GLSL)
if (ApiType != API_GLSL)
{
WRITE(p, "void main(\n");
if(ApiType != API_D3D11)
if (ApiType != API_D3D11)
{
WRITE(p, " out float4 ocol0 : COLOR0,%s%s\n in float4 rawpos : %s,\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : COLOR1," : "",
@ -702,7 +704,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// Once we switch to GLSL 1.3 we will bind a lot of these.
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{
// This won't get hit unless we support GL 3.3
WRITE(p, " layout(location = 0) out float4 ocol0;\n");
@ -712,7 +714,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{
WRITE(p, " float4 ocol0;\n");
}
if(DepthTextureEnable)
if (DepthTextureEnable)
WRITE(p, " float depth;\n"); // TODO: Passed to Vertex Shader right?
WRITE(p, " float4 rawpos = gl_FragCoord;\n");
@ -725,13 +727,13 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numTexgen; ++i)
WRITE(p, " float3 uv%d = gl_TexCoord[%d].xyz;\n", i, i);
WRITE(p, " float4 clipPos = gl_TexCoord[%d];\n", numTexgen);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " float4 Normal = gl_TexCoord[%d];\n", numTexgen + 1);
}
else
{
// wpos is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " float4 uv%d = gl_TexCoord[%d];\n", i, i);
@ -783,7 +785,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
" float4 cc2=float4(0.0f,0.0f,0.0f,0.0f), cprev=float4(0.0f,0.0f,0.0f,0.0f);\n"
" float4 crastemp=float4(0.0f,0.0f,0.0f,0.0f),ckonsttemp=float4(0.0f,0.0f,0.0f,0.0f);\n\n");
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
if (xfregs.numTexGen.numTexGens < 7)
{
@ -830,7 +832,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
// indirect texture map lookup
for(u32 i = 0; i < bpmem.genMode.numindstages; ++i)
for (u32 i = 0; i < bpmem.genMode.numindstages; ++i)
{
if (nIndirectStagesUsed & (1<<i))
{
@ -860,7 +862,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
for (int i = 0; i < numStages; i++)
WriteStage(p, i, ApiType); //build the equation for this stage
if(numStages)
if (numStages)
{
// The results of the last texenv stage are put onto the screen,
// regardless of the used destination register
@ -889,15 +891,15 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "ocol0 = 0;\n");
if(DepthTextureEnable)
WRITE(p, "depth = 1.f;\n");
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = vec4(0.0f);\n");
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
// Once we switch to GLSL 1.3 and bind variables, we won't need to do this
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n");
if(DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
}
WRITE(p, "discard;\n");
if(ApiType != API_D3D11)
@ -945,9 +947,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// ...and the alpha from ocol0 will be written to the framebuffer.
WRITE(p, " ocol0.a = " I_ALPHA"[0].a;\n");
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
if(DepthTextureEnable)
if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n");
@ -1109,10 +1111,10 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (bpmem.tevorders[n/2].getEnable(n&1))
{
if(!bHasIndStage)
if (!bHasIndStage)
{
// calc tevcord
if(bHasTexCoord)
if (bHasTexCoord)
WRITE(p, "tevcoord.xy = uv%d.xy;\n", texcoord);
else
WRITE(p, "tevcoord.xy = float2(0.0f, 0.0f);\n");
@ -1132,7 +1134,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
int kc = bpmem.tevksel[n / 2].getKC(n & 1);
int ka = bpmem.tevksel[n / 2].getKA(n & 1);
WRITE(p, "konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]);
if(kc > 7 || ka > 7)
if (kc > 7 || ka > 7)
{
WRITE(p, "ckonsttemp = frac(konsttemp * (255.0f/256.0f)) * (256.0f/255.0f);\n");
}
@ -1231,7 +1233,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (cc.shift > TEVSCALE_1)
WRITE(p, "%s*(", tevScaleTable[cc.shift]);
if(!(cc.d == TEVCOLORARG_ZERO && cc.op == TEVOP_ADD))
if (!(cc.d == TEVCOLORARG_ZERO && cc.op == TEVOP_ADD))
WRITE(p, "%s%s", tevCInputTable[cc.d], tevOpTable[cc.op]);
if (cc.a == cc.b)
@ -1281,7 +1283,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
if (ac.shift > TEVSCALE_1)
WRITE(p, "%s*(", tevScaleTable[ac.shift]);
if(!(ac.d == TEVALPHAARG_ZERO && ac.op == TEVOP_ADD))
if (!(ac.d == TEVALPHAARG_ZERO && ac.op == TEVOP_ADD))
WRITE(p, "%s.a%s", tevAInputTable[ac.d], tevOpTable[ac.op]);
if (ac.a == ac.b)
@ -1297,7 +1299,7 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
WRITE(p, "%s",tevBiasTable[ac.bias]);
if (ac.shift>0)
if (ac.shift > 0)
WRITE(p, ")");
}
@ -1386,6 +1388,7 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
I_ALPHA"[0].g"
};
// using discard then return works the same in cg and dx9 but not in dx11
WRITE(p, "if(!( ");
@ -1399,9 +1402,9 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
<<<<<<< HEAD
WRITE(p, ")) {\n");
WRITE(p, "ocol0 = float4(0);\n");
WRITE(p, "ocol0 = float4(0.0f);\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = 0;\n");
WRITE(p, "ocol1 = float4(0.0f);\n");
if (DepthTextureEnable)
WRITE(p, "depth = 1.f;\n");
@ -1426,13 +1429,6 @@ static void WriteAlphaTest(char *&p, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode
WRITE(p, "}\n");
=======
WRITE(p, ")){ocol0 = float4(0.0f);%s%s discard;%s}\n",
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "ocol1 = vec4(0.0f);" : "",
DepthTextureEnable ? "depth = 1.f;" : "",
(ApiType != API_D3D11) ? "return;" : "");
return true;
>>>>>>> Few compiler errors that got exposed once I got Dual Source Blending working. Seems it isn't working quite 100% either. Good chance I missed something anyway.
}
static const char *tevFogFuncsTable[] =
@ -1449,7 +1445,8 @@ static const char *tevFogFuncsTable[] =
static void WriteFog(char *&p)
{
if(bpmem.fog.c_proj_fsel.fsel == 0)return;//no Fog
if (bpmem.fog.c_proj_fsel.fsel == 0)
return; // no Fog
if (bpmem.fog.c_proj_fsel.proj == 0)
{
@ -1467,7 +1464,7 @@ static void WriteFog(char *&p)
// x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust
//this is complitly teorical as the real hard seems to use a table intead of calculate the values.
if(bpmem.fogRange.Base.Enabled)
if (bpmem.fogRange.Base.Enabled)
{
WRITE (p, " float x_adjust = (2.0f * (clipPos.x / " I_FOG"[2].y)) - 1.0f - " I_FOG"[2].x;\n");
WRITE (p, " x_adjust = sqrt(x_adjust * x_adjust + " I_FOG"[2].z * " I_FOG"[2].z) / " I_FOG"[2].z;\n");
@ -1476,17 +1473,15 @@ static void WriteFog(char *&p)
WRITE (p, " float fog = saturate(ze - " I_FOG"[1].z);\n");
if(bpmem.fog.c_proj_fsel.fsel > 3)
if (bpmem.fog.c_proj_fsel.fsel > 3)
{
WRITE(p, "%s", tevFogFuncsTable[bpmem.fog.c_proj_fsel.fsel]);
}
else
{
if(bpmem.fog.c_proj_fsel.fsel != 2)
if (bpmem.fog.c_proj_fsel.fsel != 2)
WARN_LOG(VIDEO, "Unknown Fog Type! %08x", bpmem.fog.c_proj_fsel.fsel);
}
WRITE(p, " prev.rgb = lerp(prev.rgb," I_FOG"[0].rgb,fog);\n");
}

View File

@ -66,17 +66,19 @@ u16 GetEncodedSampleCount(u32 format)
default: return 1;
}
}
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{
if(ApiType == API_GLSL)
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)
{
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return "";
static char result[64];
sprintf(result, "uniform ");
@ -90,12 +92,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
@ -122,7 +124,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
}
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -131,7 +133,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
else
{
WRITE(p,"void main(\n");
if(ApiType != API_D3D11)
if (ApiType != API_D3D11)
{
WRITE(p," out float4 ocol0 : COLOR0,\n");
}
@ -163,12 +165,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
if(ApiType == API_OPENGL || ApiType == API_GLSL)
if (ApiType == API_OPENGL || ApiType == API_GLSL)
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
if(ApiType != API_OPENGL && ApiType != API_GLSL)
if (ApiType != API_OPENGL && ApiType != API_GLSL)
{
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
@ -182,17 +184,17 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
// 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
if(ApiType == API_OPENGL)
if (ApiType == API_OPENGL)
{
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
}
@ -212,7 +214,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, "Texture2D Tex0 : register(t0);\n");
}
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -249,18 +251,17 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " float xl = floor(x2 / %f);\n", blkW);
WRITE(p, " float xib = x2 - (xl * %f);\n", blkW);
WRITE(p, " float halfxb = floor(xb / 2);\n");
WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW);
WRITE(p, " sampleUv.y = yb + xoff;\n");
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
if(ApiType == API_OPENGL || ApiType == API_GLSL)
if (ApiType == API_OPENGL || ApiType == API_GLSL)
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
if(ApiType != API_OPENGL && ApiType != API_GLSL)
if (ApiType != API_OPENGL && ApiType != API_GLSL)
{
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
@ -281,7 +282,7 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
// the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX.
const char* texSampleIncrementUnit;
if(ApiType != API_OPENGL || ApiType != API_GLSL)
if (ApiType != API_OPENGL || ApiType != API_GLSL)
texSampleIncrementUnit = I_COLORS"[0].x / "I_COLORS"[0].z";
else
texSampleIncrementUnit = I_COLORS"[0].x";
@ -292,7 +293,7 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
void WriteColorToIntensity(char*& p, const char* src, const char* dest)
{
if(!IntensityConstantAdded)
if (!IntensityConstantAdded)
{
WRITE(p, " float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n");
IntensityConstantAdded = true;
@ -328,7 +329,7 @@ void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
void WriteEncoderEnd(char* p, API_TYPE ApiType)
{
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
WRITE(p, "gl_FragData[0] = ocol0;\n");
WRITE(p, "}\n");
IntensityConstantAdded = false;
@ -337,22 +338,22 @@ void WriteEncoderEnd(char* p, API_TYPE ApiType)
void WriteI8Encoder(char* p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_I8,ApiType);
WriteSwizzler(p, GX_TF_I8, ApiType);
WRITE(p, " float3 texSample;\n");
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.b");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.r");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.a");
WRITE(p, " ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity
@ -362,40 +363,40 @@ void WriteI8Encoder(char* p, API_TYPE ApiType)
void WriteI4Encoder(char* p, API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_I4,ApiType);
WriteSwizzler(p, GX_TF_I4, ApiType);
WRITE(p, " float3 texSample;\n");
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.b");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.r");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color0.a");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample",ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteColorToIntensity(p, "texSample", "color1.a");
WRITE(p, " color0.rgba += IntensityConst.aaaa;\n");
@ -410,15 +411,15 @@ void WriteI4Encoder(char* p, API_TYPE ApiType)
void WriteIA8Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_IA8,ApiType);
WriteSwizzler(p, GX_TF_IA8, ApiType);
WRITE(p, " float4 texSample;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " ocol0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " ocol0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.a");
@ -429,27 +430,27 @@ void WriteIA8Encoder(char* p,API_TYPE ApiType)
void WriteIA4Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_IA4,ApiType);
WriteSwizzler(p, GX_TF_IA4, ApiType);
WRITE(p, " float4 texSample;\n");
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.g = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.a = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.a");
@ -464,11 +465,11 @@ void WriteIA4Encoder(char* p,API_TYPE ApiType)
void WriteRGB565Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB565,ApiType);
WriteSwizzler(p, GX_TF_RGB565, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1",ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1", ApiType);
WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n");
WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\n");
WRITE(p, " float2 texBs = float2(texSample0.b, texSample1.b);\n");
@ -488,14 +489,14 @@ void WriteRGB565Encoder(char* p,API_TYPE ApiType)
void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB5A3,ApiType);
WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
WRITE(p, " float4 texSample;\n");
WRITE(p, " float color0;\n");
WRITE(p, " float gUpper;\n");
WRITE(p, " float gLower;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
// 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -522,9 +523,9 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
WRITE(p, "}\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -555,21 +556,21 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB5A3,ApiType);
WriteSwizzler(p, GX_TF_RGB5A3, ApiType);
WRITE(p, " float4 texSample;\n");
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.b");
WriteToBitDepth(p, 4, "texSample.r", "color1.b");
WriteToBitDepth(p, 4, "texSample.g", "color0.g");
WriteToBitDepth(p, 4, "texSample.b", "color1.g");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.r");
WriteToBitDepth(p, 4, "texSample.r", "color1.r");
WriteToBitDepth(p, 4, "texSample.g", "color0.a");
@ -581,7 +582,7 @@ void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
{
Write32BitSwizzler(p, GX_TF_RGBA8,ApiType);
Write32BitSwizzler(p, GX_TF_RGBA8, ApiType);
WRITE(p, " float cl1 = xb - (halfxb * 2);\n");
WRITE(p, " float cl0 = 1.0f - cl1;\n");
@ -590,15 +591,15 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.b = texSample.a;\n");
WRITE(p, " color0.g = texSample.r;\n");
WRITE(p, " color1.b = texSample.g;\n");
WRITE(p, " color1.g = texSample.b;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample",ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WRITE(p, " color0.r = texSample.a;\n");
WRITE(p, " color0.a = texSample.r;\n");
WRITE(p, " color1.r = texSample.g;\n");
@ -611,32 +612,32 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_R4,ApiType);
WriteSwizzler(p, GX_CTF_R4, ApiType);
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "color0.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color1.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.a",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "color0.a", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.a",ApiType);
WriteSampleColor(p, comp, "color1.a", ApiType);
WriteToBitDepth(p, 4, "color0", "color0");
WriteToBitDepth(p, 4, "color1", "color1");
@ -647,45 +648,45 @@ void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_R8,ApiType);
WriteSwizzler(p, GX_CTF_R8, ApiType);
WriteSampleColor(p, comp, "ocol0.b",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.g",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.r",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.a",ApiType);
WriteSampleColor(p, comp, "ocol0.a", ApiType);
WriteEncoderEnd(p, ApiType);
}
void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_RA4,ApiType);
WriteSwizzler(p, GX_CTF_RA4, ApiType);
WRITE(p, " float2 texSample;\n");
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "texSample",ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.b = texSample.x;\n");
WRITE(p, " color1.b = texSample.y;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.g = texSample.x;\n");
WRITE(p, " color1.g = texSample.y;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.r = texSample.x;\n");
WRITE(p, " color1.r = texSample.y;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample",ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WRITE(p, " color0.a = texSample.x;\n");
WRITE(p, " color1.a = texSample.y;\n");
@ -698,35 +699,35 @@ void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_RA8,ApiType);
WriteSwizzler(p, GX_CTF_RA8, ApiType);
WriteSampleColor(p, comp, "ocol0.bg",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, comp, "ocol0.bg", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.ra",ApiType);
WriteSampleColor(p, comp, "ocol0.ra", ApiType);
WriteEncoderEnd(p, ApiType);
}
void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_Z8M,ApiType);
WriteSwizzler(p, GX_CTF_Z8M, ApiType);
WRITE(p, " float depth;\n");
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);
WriteEncoderEnd(p, ApiType);
@ -734,14 +735,14 @@ void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
void WriteZ16Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_Z16,ApiType);
WriteSwizzler(p, GX_TF_Z16, ApiType);
WRITE(p, " float depth;\n");
WRITE(p, " float3 expanded;\n");
// byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -751,9 +752,9 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.g / 255;\n");
WRITE(p, " ocol0.g = expanded.r / 255;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -768,14 +769,14 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
void WriteZ16LEncoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_Z16L,ApiType);
WriteSwizzler(p, GX_CTF_Z16L, ApiType);
WRITE(p, " float depth;\n");
WRITE(p, " float3 expanded;\n");
// byte order is reversed
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -787,9 +788,9 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.b / 255;\n");
WRITE(p, " ocol0.g = expanded.g / 255;\n");
WriteIncrementSampleX(p,ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth",ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WRITE(p, " depth *= 16777215.0f;\n");
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
@ -806,7 +807,7 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
void WriteZ24Encoder(char* p, API_TYPE ApiType)
{
Write32BitSwizzler(p, GX_TF_Z24X8,ApiType);
Write32BitSwizzler(p, GX_TF_Z24X8, ApiType);
WRITE(p, " float cl = xb - (halfxb * 2);\n");
@ -815,19 +816,19 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
WRITE(p, " float3 expanded0;\n");
WRITE(p, " float3 expanded1;\n");
WriteSampleColor(p, "b", "depth0",ApiType);
WriteIncrementSampleX(p,ApiType);
WriteSampleColor(p, "b", "depth1",ApiType);
WriteSampleColor(p, "b", "depth0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth1", 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");
@ -854,7 +855,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
char *p = text;
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -881,76 +882,76 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n");
}
switch(format)
switch (format)
{
case GX_TF_I4:
WriteI4Encoder(p,ApiType);
WriteI4Encoder(p, ApiType);
break;
case GX_TF_I8:
WriteI8Encoder(p,ApiType);
WriteI8Encoder(p, ApiType);
break;
case GX_TF_IA4:
WriteIA4Encoder(p,ApiType);
WriteIA4Encoder(p, ApiType);
break;
case GX_TF_IA8:
WriteIA8Encoder(p,ApiType);
WriteIA8Encoder(p, ApiType);
break;
case GX_TF_RGB565:
WriteRGB565Encoder(p,ApiType);
WriteRGB565Encoder(p, ApiType);
break;
case GX_TF_RGB5A3:
WriteRGB5A3Encoder(p,ApiType);
WriteRGB5A3Encoder(p, ApiType);
break;
case GX_TF_RGBA8:
WriteRGBA8Encoder(p,ApiType);
WriteRGBA8Encoder(p, ApiType);
break;
case GX_CTF_R4:
WriteC4Encoder(p, "r",ApiType);
WriteC4Encoder(p, "r", ApiType);
break;
case GX_CTF_RA4:
WriteCC4Encoder(p, "ar",ApiType);
WriteCC4Encoder(p, "ar", ApiType);
break;
case GX_CTF_RA8:
WriteCC8Encoder(p, "ar",ApiType);
WriteCC8Encoder(p, "ar", ApiType);
break;
case GX_CTF_A8:
WriteC8Encoder(p, "a",ApiType);
WriteC8Encoder(p, "a", ApiType);
break;
case GX_CTF_R8:
WriteC8Encoder(p, "r",ApiType);
WriteC8Encoder(p, "r", ApiType);
break;
case GX_CTF_G8:
WriteC8Encoder(p, "g",ApiType);
WriteC8Encoder(p, "g", ApiType);
break;
case GX_CTF_B8:
WriteC8Encoder(p, "b",ApiType);
WriteC8Encoder(p, "b", ApiType);
break;
case GX_CTF_RG8:
WriteCC8Encoder(p, "rg",ApiType);
WriteCC8Encoder(p, "rg", ApiType);
break;
case GX_CTF_GB8:
WriteCC8Encoder(p, "gb",ApiType);
WriteCC8Encoder(p, "gb", ApiType);
break;
case GX_TF_Z8:
WriteC8Encoder(p, "b",ApiType);
WriteC8Encoder(p, "b", ApiType);
break;
case GX_TF_Z16:
WriteZ16Encoder(p,ApiType);
WriteZ16Encoder(p, ApiType);
break;
case GX_TF_Z24X8:
WriteZ24Encoder(p,ApiType);
WriteZ24Encoder(p, ApiType);
break;
case GX_CTF_Z4:
WriteC4Encoder(p, "b",ApiType);
WriteC4Encoder(p, "b", ApiType);
break;
case GX_CTF_Z8M:
WriteZ8Encoder(p, "256.0f",ApiType);
WriteZ8Encoder(p, "256.0f", ApiType);
break;
case GX_CTF_Z8L:
WriteZ8Encoder(p, "65536.0f" ,ApiType);
WriteZ8Encoder(p, "65536.0f" , ApiType);
break;
case GX_CTF_Z16L:
WriteZ16LEncoder(p,ApiType);
WriteZ16LEncoder(p, ApiType);
break;
default:
PanicAlert("Unknown texture copy format: 0x%x\n", format);

View File

@ -185,65 +185,64 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
if(ApiType == API_GLSL)
if (ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
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.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n");
}
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
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.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n");
}
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
WRITE(p, "#define float4 vec4\n");
// cg to glsl function translation
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");
// cg to glsl function translation
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");
}
// uniforms
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform VSBlock {\n");
WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType),WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION));
WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS));
WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS));
WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices
WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType),WriteRegister(ApiType, "c", C_TRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES));
WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
p = GenerateVSOutputStruct(p, components, ApiType);
if(ApiType == API_GLSL)
if(ApiType == API_GLSL)
{
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
if(g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{
if (components & VB_HAS_POSMTXIDX)
WRITE(p, "layout(location = %d) ATTRIN float fposmtx;\n", SHADER_POSMTX_ATTRIB);
@ -277,7 +276,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
else
{
WRITE(p, "VS_OUTPUT main(\n");
// inputs
@ -306,9 +304,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
if (components & VB_HAS_POSMTXIDX) {
if (is_d3d)
{
WRITE(p, " float4 blend_indices : BLENDINDICES,\n");
}
else
WRITE(p, " float fposmtx : ATTR%d,\n", SHADER_POSMTX_ATTRIB);
}
@ -369,7 +365,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
"float3 ldir, h;\n"
"float dist, dist2, attn;\n");
if(xfregs.numChan.numColorChans == 0)
if (xfregs.numChan.numColorChans == 0)
{
if (components & VB_HAS_COL0)
WRITE(p, "o.colors_0 = color0;\n");
@ -380,7 +376,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
// TODO: This probably isn't necessary if pixel lighting is enabled.
p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
if(xfregs.numChan.numColorChans < 2)
if (xfregs.numChan.numColorChans < 2)
{
if (components & VB_HAS_COL1)
WRITE(p, "o.colors_1 = color1;\n");
@ -584,23 +580,23 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
// clipPos/w needs to be done in pixel shader, not here
if (xfregs.numTexGen.numTexGens < 7) {
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d].xyz = o.tex%d;\n", i, i);
WRITE(p, " gl_TexCoord[%d] = o.clipPos;\n", xfregs.numTexGen.numTexGens);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d].xyz = o.tex%d;\n", i, i);
WRITE(p, " gl_TexCoord[%d] = o.clipPos;\n", xfregs.numTexGen.numTexGens);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " gl_TexCoord[%d] = o.Normal;\n", xfregs.numTexGen.numTexGens + 1);
} else {
// clip position is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
}
else
{
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d]%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
}
// clip position is in w of first 4 texcoords
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " gl_TexCoord[%d] = o.tex%d;\n", i, i);
}
else
{
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " gl_TexCoord[%d]%s = o.tex%d;\n", i, i < 4 ? ".xyzw" : ".xyz" , i);
}
}
WRITE(p, "gl_FrontColor = o.colors_0;\n");
WRITE(p, "gl_FrontSecondaryColor = o.colors_1;\n");
@ -608,7 +604,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "}\n");
}
else
WRITE(p, "return o;\n}\n");
WRITE(p, "return o;\n}\n");
if (text[sizeof(text) - 1] != 0x7C)
PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");