Skip to content

Commit

Permalink
UPBGE: Fix shader recompilation after error.
Browse files Browse the repository at this point in the history
Previously when a filter failed its compilation, it was
impossible to recompile new sources.
This was caused by the fact that in RAS_Shader::LinkProgram
the variable m_error was first checked and if it was true
when we discard shader compilation. But this variable was
set when the shader failed for the first time. At the end
the shader always discarded the next compilation.

To fix this issue the compilation discard is removed.

In the same time the 0 and 1 are replaced by true or false for
boolean variable.

Bug reported by TwisterGE.
  • Loading branch information
panzergame committed Sep 9, 2017
1 parent 665106f commit 6926baf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
4 changes: 2 additions & 2 deletions source/gameengine/Ketsji/BL_Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ KX_PYMETHODDEF_DOC(BL_Shader, setSource, " setSource(vertexProgram, fragmentProg

m_progs[VERTEX_PROGRAM] = "";
m_progs[FRAGMENT_PROGRAM] = "";
m_use = 0;
m_use = false;
Py_RETURN_NONE;
}
return nullptr;
Expand Down Expand Up @@ -320,7 +320,7 @@ KX_PYMETHODDEF_DOC(BL_Shader, setSourceList, " setSourceList(sources, apply)")
for (unsigned short i = 0; i < MAX_PROGRAM; ++i) {
m_progs[i] = "";
}
m_use = 0;
m_use = false;
return nullptr;
}

Expand Down
10 changes: 4 additions & 6 deletions source/gameengine/Ketsji/KX_BlenderMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,12 +868,10 @@ KX_PYMETHODDEF_DOC(KX_BlenderMaterial, getShader, "getShader()")

if (!m_shader) {
m_shader = new BL_Shader();
if (!m_shader->GetError()) {
// Set the material to use custom shader.
m_flag &= ~RAS_BLENDERGLSL;
m_shader->InitTexCo(m_textures);
m_scene->GetBucketManager()->UpdateShaders(this);
}
// Set the material to use custom shader.
m_flag &= ~RAS_BLENDERGLSL;
m_shader->InitTexCo(m_textures);
m_scene->GetBucketManager()->UpdateShaders(this);
}

if (!m_shader->GetError()) {
Expand Down
20 changes: 5 additions & 15 deletions source/gameengine/Rasterizer/RAS_Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ bool RAS_Shader::Ok() const

RAS_Shader::RAS_Shader()
:m_shader(nullptr),
m_use(0),
m_error(0),
m_use(false),
m_error(false),
m_dirty(true)
{
for (unsigned short i = 0; i < MAX_PROGRAM; ++i) {
Expand Down Expand Up @@ -300,10 +300,6 @@ bool RAS_Shader::LinkProgram()
std::string frag;
std::string geom;

if (m_error) {
goto program_error;
}

if (m_progs[VERTEX_PROGRAM].empty() || m_progs[FRAGMENT_PROGRAM].empty()) {
CM_Error("invalid GLSL sources.");
return false;
Expand All @@ -315,18 +311,12 @@ bool RAS_Shader::LinkProgram()
m_shader = GPU_shader_create(vert.c_str(), frag.c_str(), geom.empty() ? nullptr : geom.c_str(),
nullptr, nullptr, 0, 0, 0);
if (!m_shader) {
goto program_error;
m_error = true;
return false;
}

m_error = 0;
m_error = false;
return true;

program_error:
{
m_use = 0;
m_error = 1;
return false;
}
}

void RAS_Shader::ValidateProgram()
Expand Down

0 comments on commit 6926baf

Please sign in to comment.