Skip to content

Commit

Permalink
Fixes example-41 when using OpenGL(Intel Mesa) on Linux
Browse files Browse the repository at this point in the history
The Intel Mesa driver doesn't support ARB_compatibility, which means deprecated glsl keywords
like gl_FragColor don't work with a shader version larger than 3.30.
  • Loading branch information
kingscallop committed Jan 16, 2021
1 parent eab0833 commit ee73356
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
37 changes: 13 additions & 24 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6162,11 +6162,12 @@ namespace bgfx { namespace gl
: 120
;

version = 0 == bx::strCmp(code, "#version 430", 12) ? 430 : version;

bx::write(&writer, &err, "#version %d\n", version);
if (0 != version)
{
bx::write(&writer, &err, "#version %d\n", version);
}

if (430 > version && usesTextureLod)
if (usesTextureLod)
{
if (m_type == GL_FRAGMENT_SHADER)
{
Expand Down Expand Up @@ -6235,17 +6236,14 @@ namespace bgfx { namespace gl

if (130 <= version)
{
if (430 > version)
if (m_type == GL_FRAGMENT_SHADER)
{
if (m_type == GL_FRAGMENT_SHADER)
{
bx::write(&writer, "#define varying in\n");
}
else
{
bx::write(&writer, "#define attribute in\n");
bx::write(&writer, "#define varying out\n");
}
bx::write(&writer, "#define varying in\n");
}
else
{
bx::write(&writer, "#define attribute in\n");
bx::write(&writer, "#define varying out\n");
}

uint32_t fragData = 0;
Expand Down Expand Up @@ -6304,16 +6302,7 @@ namespace bgfx { namespace gl
);
}

if (version == 430)
{
int32_t verLen = bx::strLen("#version 430\n");
bx::write(&writer, code.getPtr()+verLen, code.getLength()-verLen);
}
else
{
bx::write(&writer, code);
}

bx::write(&writer, code);
bx::write(&writer, '\0');
}
else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 31)
Expand Down
36 changes: 34 additions & 2 deletions tools/shaderc/shaderc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ extern "C"
#include <fpp.h>
} // extern "C"

#define BGFX_SHADER_BIN_VERSION 9
#define BGFX_SHADER_BIN_VERSION 10
#define BGFX_CHUNK_MAGIC_CSH BX_MAKEFOURCC('C', 'S', 'H', BGFX_SHADER_BIN_VERSION)
#define BGFX_CHUNK_MAGIC_FSH BX_MAKEFOURCC('F', 'S', 'H', BGFX_SHADER_BIN_VERSION)
#define BGFX_CHUNK_MAGIC_VSH BX_MAKEFOURCC('V', 'S', 'H', BGFX_SHADER_BIN_VERSION)

#define BGFX_SHADERC_VERSION_MAJOR 1
#define BGFX_SHADERC_VERSION_MINOR 18
#define BGFX_SHADERC_VERSION_MINOR 19

namespace bgfx
{
Expand Down Expand Up @@ -2437,6 +2437,38 @@ namespace bgfx
, "#define bgfxShadow2D(_sampler, _coord) vec4_splat(texture(_sampler, _coord))\n"
"#define bgfxShadow2DProj(_sampler, _coord) vec4_splat(textureProj(_sampler, _coord))\n"
);

const bool hasFragColor = !bx::findIdentifierMatch(input, "gl_FragColor").isEmpty();
const bool hasFragData = !bx::findIdentifierMatch(input, "gl_FragData").isEmpty();

const uint32_t maxFragData = 8;
uint32_t fragData = 0;

if (hasFragData)
{
for (uint32_t ii = 0; ii < maxFragData; ++ii)
{
char temp[32];
bx::snprintf(temp, BX_COUNTOF(temp), "gl_FragData[%d]", ii);
if (!bx::strFind(input, temp).isEmpty())
{
fragData = bx::uint32_max(fragData, ii);
}
}

BX_ASSERT(0 != fragData, "Unable to find and patch gl_FragData!");
}

if (0 != fragData)
{
bx::stringPrintf(code, "out vec4 bgfx_FragData[%d];\n", fragData);
bx::stringPrintf(code, "#define gl_FragData bgfx_FragData\n");
}
else if (hasFragColor)
{
bx::stringPrintf(code, "out vec4 bgfx_FragColor;\n");
bx::stringPrintf(code, "#define gl_FragColor bgfx_FragColor\n");
}
}

if ( (profile->lang == ShadingLang::GLSL && glsl_profile > 400)
Expand Down

0 comments on commit ee73356

Please sign in to comment.