Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes example-41 when using OpenGL(Intel Mesa) on Linux #2358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6263,11 +6263,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 @@ -6341,17 +6342,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 @@ -6410,16 +6408,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 11
#define BGFX_SHADER_BIN_VERSION 12
#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 @@ -2445,6 +2445,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