Skip to content

Commit

Permalink
fix specification constant injection in glsl
Browse files Browse the repository at this point in the history
- boolean where handled as int
- always cast float to float()
  • Loading branch information
pixelflinger authored and bejado committed Apr 17, 2023
1 parent 89dc43f commit 6623dcb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion filament/backend/src/opengl/OpenGLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ static void logCompilationError(utils::io::ostream& out,
static void logProgramLinkError(utils::io::ostream& out,
const char* name, GLuint program) noexcept;

static inline std::string to_string(bool b) noexcept {
return b ? "true" : "false";
}

static inline std::string to_string(int i) noexcept {
return std::to_string(i);
}

static inline std::string to_string(float f) noexcept {
return "float(" + std::to_string(f) + ")";
}

OpenGLProgram::OpenGLProgram() noexcept
: mInitialized(false), mValid(true), mLazyInitializationData(nullptr) {
}
Expand Down Expand Up @@ -109,7 +121,7 @@ void OpenGLProgram::compileShaders(OpenGLContext& context,
for (auto const& sc : specializationConstants) {
specializationConstantString += "#define SPIRV_CROSS_CONSTANT_ID_" + std::to_string(sc.id) + ' ';
specializationConstantString += std::visit([](auto&& arg) {
return std::to_string(arg);
return to_string(arg);
}, sc.value);
specializationConstantString += '\n';
}
Expand Down

0 comments on commit 6623dcb

Please sign in to comment.