diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index ca654a9aef..3929f80183 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -926,7 +926,8 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if(ApiType == API_GLSL) { if(DepthTextureEnable) - WRITE(p, "gl_FragDepth = depth;\n"); + WRITE(p, "gl_FragDepth = depth;\n"); + WRITE(p, "gl_FragData[0] = ocol0;\n"); } } diff --git a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp index 8b5627c5fa..f0ad446449 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderManager.cpp @@ -85,37 +85,39 @@ void PixelShaderManager::Shutdown() void PixelShaderManager::SetConstants() { + if (g_ActiveConfig.bUseGLSL) + Dirty(); for (int i = 0; i < 2; ++i) { - if (s_nColorsChanged[i] || g_ActiveConfig.bUseGLSL) + if (s_nColorsChanged[i]) { int baseind = i ? C_KCOLORS : C_COLORS; for (int j = 0; j < 4; ++j) { - if (s_nColorsChanged[i] & (1 << j) || g_ActiveConfig.bUseGLSL) + if (s_nColorsChanged[i] & (1 << j)) SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]); } s_nColorsChanged[i] = 0; } } - if (s_nTexDimsChanged || g_ActiveConfig.bUseGLSL) + if (s_nTexDimsChanged) { for (int i = 0; i < 8; ++i) { - if (s_nTexDimsChanged & (1<>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f); s_bAlphaChanged = false; } - if (s_bZTextureTypeChanged || g_ActiveConfig.bUseGLSL) + if (s_bZTextureTypeChanged) { float ftemp[4]; switch (bpmem.ztex2.type) @@ -137,7 +139,7 @@ void PixelShaderManager::SetConstants() s_bZTextureTypeChanged = false; } - if (s_bZBiasChanged || s_bDepthRangeChanged || g_ActiveConfig.bUseGLSL) + if (s_bZBiasChanged || s_bDepthRangeChanged) { // reversed gxsetviewport(xorig, yorig, width, height, nearz, farz) // [0] = width/2 @@ -153,12 +155,12 @@ void PixelShaderManager::SetConstants() } // indirect incoming texture scales - if (s_nIndTexScaleChanged || g_ActiveConfig.bUseGLSL) + if (s_nIndTexScaleChanged) { // set as two sets of vec4s, each containing S and T of two ind stages. float f[8]; - if (s_nIndTexScaleChanged & 0x03 || g_ActiveConfig.bUseGLSL) + if (s_nIndTexScaleChanged & 0x03) { for (u32 i = 0; i < 2; ++i) { @@ -169,7 +171,7 @@ void PixelShaderManager::SetConstants() SetPSConstant4fv(C_INDTEXSCALE, f); } - if (s_nIndTexScaleChanged & 0x0c || g_ActiveConfig.bUseGLSL) { + if (s_nIndTexScaleChanged & 0x0c) { for (u32 i = 2; i < 4; ++i) { f[2 * i] = bpmem.texscale[1].getScaleS(i & 1); f[2 * i + 1] = bpmem.texscale[1].getScaleT(i & 1); @@ -181,11 +183,11 @@ void PixelShaderManager::SetConstants() s_nIndTexScaleChanged = 0; } - if (s_nIndTexMtxChanged || g_ActiveConfig.bUseGLSL) + if (s_nIndTexMtxChanged) { for (int i = 0; i < 3; ++i) { - if (s_nIndTexMtxChanged & (1 << i) || g_ActiveConfig.bUseGLSL) + if (s_nIndTexMtxChanged & (1 << i)) { int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) | ((u32)bpmem.indmtx[i].col1.s1 << 2) | @@ -215,13 +217,13 @@ void PixelShaderManager::SetConstants() s_nIndTexMtxChanged = 0; } - if (s_bFogColorChanged || g_ActiveConfig.bUseGLSL) + if (s_bFogColorChanged) { SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0); s_bFogColorChanged = false; } - if (s_bFogParamChanged || g_ActiveConfig.bUseGLSL) + if (s_bFogParamChanged) { if(!g_ActiveConfig.bDisableFog) { @@ -237,7 +239,7 @@ void PixelShaderManager::SetConstants() s_bFogParamChanged = false; } - if (s_bFogRangeAdjustChanged || g_ActiveConfig.bUseGLSL) + if (s_bFogRangeAdjustChanged) { if(!g_ActiveConfig.bDisableFog && bpmem.fogRange.Base.Enabled == 1) { @@ -261,7 +263,7 @@ void PixelShaderManager::SetConstants() if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) // config check added because the code in here was crashing for me inside SetPSConstant4f { - if (nLightsChanged[0] >= 0 || g_ActiveConfig.bUseGLSL) + if (nLightsChanged[0] >= 0) { // lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats int istart = nLightsChanged[0] / 0x10; @@ -297,14 +299,14 @@ void PixelShaderManager::SetConstants() nLightsChanged[0] = nLightsChanged[1] = -1; } - if (nMaterialsChanged || g_ActiveConfig.bUseGLSL) + if (nMaterialsChanged) { float GC_ALIGNED16(material[4]); float NormalizationCoef = 1 / 255.0f; for (int i = 0; i < 4; ++i) { - if (nMaterialsChanged & (1 << i) || g_ActiveConfig.bUseGLSL) + if (nMaterialsChanged & (1 << i)) { u32 data = *(xfregs.ambColor + i); diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 8e45955d4a..e4638f8b16 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -149,12 +149,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n"); - if(ApiType == API_OPENGL) + 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) + 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"); @@ -237,12 +237,12 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType) WRITE(p, " sampleUv.y = yb + xoff;\n"); WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n"); - if(ApiType == API_OPENGL) + 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) + 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"); @@ -263,7 +263,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) + if(ApiType != API_OPENGL || ApiType != API_GLSL) texSampleIncrementUnit = I_COLORS"[0].x / "I_COLORS"[0].z"; else texSampleIncrementUnit = I_COLORS"[0].x"; diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 8093a865a4..8709e44e21 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -195,9 +195,15 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) 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"); + 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"); + } // Silly differences WRITE(p, "#define float2 vec2\n"); WRITE(p, "#define float3 vec3\n"); @@ -227,11 +233,11 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n"); if (components & VB_HAS_POSMTXIDX) - WRITE(p, "attribute float fposmtx; // ATTR%d,\n", SHADER_POSMTX_ATTRIB); + WRITE(p, "ATTRIN float fposmtx; // ATTR%d,\n", SHADER_POSMTX_ATTRIB); if (components & VB_HAS_NRM1) - WRITE(p, "attribute float3 rawnorm1; // ATTR%d,\n", SHADER_NORM1_ATTRIB); + WRITE(p, "ATTRIN float3 rawnorm1; // ATTR%d,\n", SHADER_NORM1_ATTRIB); if (components & VB_HAS_NRM2) - WRITE(p, "attribute float3 rawnorm2; // ATTR%d,\n", SHADER_NORM2_ATTRIB); + WRITE(p, "ATTRIN float3 rawnorm2; // ATTR%d,\n", SHADER_NORM2_ATTRIB); if (components & VB_HAS_COL0) WRITE(p, " float4 color0 = gl_Color; // COLOR0,\n"); diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index c251ddc732..52b267224f 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -184,7 +184,9 @@ void VertexShaderManager::Dirty() // TODO: A cleaner way to control the matricies without making a mess in the parameters field void VertexShaderManager::SetConstants() { - if (nTransformMatricesChanged[0] >= 0 || g_ActiveConfig.bUseGLSL) + if (g_ActiveConfig.bUseGLSL) + Dirty(); + if (nTransformMatricesChanged[0] >= 0) { int startn = nTransformMatricesChanged[0] / 4; int endn = (nTransformMatricesChanged[1] + 3) / 4; @@ -192,7 +194,7 @@ void VertexShaderManager::SetConstants() SetMultiVSConstant4fv(C_TRANSFORMMATRICES + startn, endn - startn, pstart); nTransformMatricesChanged[0] = nTransformMatricesChanged[1] = -1; } - if (nNormalMatricesChanged[0] >= 0 || g_ActiveConfig.bUseGLSL) + if (nNormalMatricesChanged[0] >= 0) { int startn = nNormalMatricesChanged[0] / 3; int endn = (nNormalMatricesChanged[1] + 2) / 3; @@ -201,7 +203,7 @@ void VertexShaderManager::SetConstants() nNormalMatricesChanged[0] = nNormalMatricesChanged[1] = -1; } - if (nPostTransformMatricesChanged[0] >= 0 || g_ActiveConfig.bUseGLSL) + if (nPostTransformMatricesChanged[0] >= 0) { int startn = nPostTransformMatricesChanged[0] / 4; int endn = (nPostTransformMatricesChanged[1] + 3 ) / 4; @@ -209,7 +211,7 @@ void VertexShaderManager::SetConstants() SetMultiVSConstant4fv(C_POSTTRANSFORMMATRICES + startn, endn - startn, pstart); } - if (nLightsChanged[0] >= 0 || g_ActiveConfig.bUseGLSL) + if (nLightsChanged[0] >= 0) { // lights don't have a 1 to 1 mapping, the color component needs to be converted to 4 floats int istart = nLightsChanged[0] / 0x10; @@ -245,14 +247,14 @@ void VertexShaderManager::SetConstants() nLightsChanged[0] = nLightsChanged[1] = -1; } - if (nMaterialsChanged || g_ActiveConfig.bUseGLSL) + if (nMaterialsChanged) { float GC_ALIGNED16(material[4]); float NormalizationCoef = 1 / 255.0f; for (int i = 0; i < 4; ++i) { - if (nMaterialsChanged & (1 << i) || g_ActiveConfig.bUseGLSL) + if (nMaterialsChanged & (1 << i)) { u32 data = *(xfregs.ambColor + i); @@ -268,7 +270,7 @@ void VertexShaderManager::SetConstants() nMaterialsChanged = 0; } - if (bPosNormalMatrixChanged || g_ActiveConfig.bUseGLSL) + if (bPosNormalMatrixChanged) { bPosNormalMatrixChanged = false; @@ -279,7 +281,7 @@ void VertexShaderManager::SetConstants() SetMultiVSConstant3fv(C_POSNORMALMATRIX + 3, 3, norm); } - if (bTexMatricesChanged[0] || g_ActiveConfig.bUseGLSL) + if (bTexMatricesChanged[0]) { bTexMatricesChanged[0] = false; const float *fptrs[] = @@ -294,7 +296,7 @@ void VertexShaderManager::SetConstants() } } - if (bTexMatricesChanged[1] || g_ActiveConfig.bUseGLSL) + if (bTexMatricesChanged[1]) { bTexMatricesChanged[1] = false; const float *fptrs[] = { @@ -308,7 +310,7 @@ void VertexShaderManager::SetConstants() } } - if (bViewportChanged || g_ActiveConfig.bUseGLSL) + if (bViewportChanged) { bViewportChanged = false; SetVSConstant4f(C_DEPTHPARAMS, @@ -321,7 +323,7 @@ void VertexShaderManager::SetConstants() bProjectionChanged = true; } - if (bProjectionChanged || g_ActiveConfig.bUseGLSL) + if (bProjectionChanged) { bProjectionChanged = false; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 1434853dd2..6b5705179a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -80,10 +80,11 @@ void PixelShaderCache::Init() 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; + g_Config.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; + g_Config.backend_info.bSupportsGLSLLocation = false; + UpdateActiveConfig(); } else {