Browse Source

Check if gl_Frag[Data/Color] are not already patched (#2661)

Christophe Dehais 4 years ago
parent
commit
08cd17e3b8
2 changed files with 19 additions and 11 deletions
  1. 17 9
      src/renderer_gl.cpp
  2. 2 2
      tools/shaderc/shaderc.cpp

+ 17 - 9
src/renderer_gl.cpp

@@ -6509,7 +6509,9 @@ namespace bgfx { namespace gl
 
 
 						uint32_t fragData = 0;
 						uint32_t fragData = 0;
 
 
-						if (!bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
+						bool patchedFragData = s_renderGL->m_gles3 && !bx::findIdentifierMatch(code, "bgfx_FragData").isEmpty();
+
+						if (!patchedFragData && !bx::findIdentifierMatch(code, "gl_FragData").isEmpty() )
 						{
 						{
 							for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
 							for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii)
 							{
 							{
@@ -6540,16 +6542,22 @@ namespace bgfx { namespace gl
 
 
 						if (0 != fragData)
 						if (0 != fragData)
 						{
 						{
-							bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData);
-							bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err);
+							if (!patchedFragData)
+							{
+								bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData);
+								bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err);
+							}
 						}
 						}
-						else
+						else if (!patchedFragData)
 						{
 						{
-							bx::write(&writer
-								, "out vec4 bgfx_FragColor;\n"
-								  "#define gl_FragColor bgfx_FragColor\n"
-								, &err
-								);
+							if (bx::findIdentifierMatch(code, "bgfx_FragColor").isEmpty() )
+							{
+								bx::write(&writer
+									, "out vec4 bgfx_FragColor;\n"
+									  "#define gl_FragColor bgfx_FragColor\n"
+									, &err
+									);
+							}
 						}
 						}
 					}
 					}
 					else
 					else

+ 2 - 2
tools/shaderc/shaderc.cpp

@@ -1728,8 +1728,8 @@ namespace bgfx
 						}
 						}
 						if (hasFragColor)
 						if (hasFragColor)
 						{
 						{
-							preprocessor.writef("#define gl_FragColor bgfx_FragData0\n");
-							preprocessor.writef("out mediump vec4 bgfx_FragData0;\n");
+							preprocessor.writef("#define gl_FragColor bgfx_FragColor\n");
+							preprocessor.writef("out mediump vec4 bgfx_FragColor;\n");
 						}
 						}
 						else if (numFragData)
 						else if (numFragData)
 						{
 						{