Skip to content

Commit

Permalink
Fix to allow simply using the glslang_shader_parse from C API without…
Browse files Browse the repository at this point in the history
… preprocess
  • Loading branch information
antaalt committed Nov 28, 2024
1 parent 0099ed6 commit acd8900
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions glslang/CInterface/glslang_c_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,30 @@ GLSLANG_EXPORT int glslang_shader_preprocess(glslang_shader_t* shader, const gls

GLSLANG_EXPORT int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input)
{
const char* preprocessedCStr = shader->preprocessedGLSL.c_str();
shader->shader->setStrings(&preprocessedCStr, 1);

return shader->shader->parse(
reinterpret_cast<const TBuiltInResource*>(input->resource),
input->default_version,
input->forward_compatible != 0,
(EShMessages)c_shader_messages(input->messages)
);
if (shader->preprocessedGLSL.length() > 0) {
const char* preprocessedCStr = shader->preprocessedGLSL.c_str();
shader->shader->setStrings(&preprocessedCStr, 1);

return shader->shader->parse(
reinterpret_cast<const TBuiltInResource*>(input->resource),
input->default_version,
input->forward_compatible != 0,
(EShMessages)c_shader_messages(input->messages)
);
} else {
DirStackFileIncluder dirStackFileIncluder;
CallbackIncluder callbackIncluder(input->callbacks, input->callbacks_ctx);
glslang::TShader::Includer& Includer = (input->callbacks.include_local||input->callbacks.include_system)
? static_cast<glslang::TShader::Includer&>(callbackIncluder)
: static_cast<glslang::TShader::Includer&>(dirStackFileIncluder);
return shader->shader->parse(
reinterpret_cast<const TBuiltInResource*>(input->resource),
input->default_version,
input->forward_compatible != 0,
(EShMessages)c_shader_messages(input->messages),
Includer
);
}
}

GLSLANG_EXPORT const char* glslang_shader_get_info_log(glslang_shader_t* shader) { return shader->shader->getInfoLog(); }
Expand Down

0 comments on commit acd8900

Please sign in to comment.