mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Chore] (MG_Util/ShaderSourceProcessor): trim unnecessary part of shader source
This commit is contained in:
@@ -363,8 +363,12 @@ namespace MobileGL {
|
|||||||
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader failed for shader[%zu], aborting "
|
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader failed for shader[%zu], aborting "
|
||||||
"binary generation",
|
"binary generation",
|
||||||
m_externalIndex, i);
|
m_externalIndex, i);
|
||||||
assert(res); // keep original assert but log first
|
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader return code %d, log:\n%s",
|
||||||
|
m_externalIndex, res.error().errc, res.error().log.c_str());
|
||||||
|
MGLOG_E("ProgramObject %u: GenerateBinary - last compiled shader src: \n%s",
|
||||||
|
m_externalIndex, m_shaders[i]->GetShaderSource().c_str());
|
||||||
}
|
}
|
||||||
|
assert(res); // keep original assert but log first
|
||||||
shaders[i] = res.value();
|
shaders[i] = res.value();
|
||||||
MGLOG_D("ProgramObject %u: GenerateBinary - compiled shader[%zu] -> TShader ptr %p",
|
MGLOG_D("ProgramObject %u: GenerateBinary - compiled shader[%zu] -> TShader ptr %p",
|
||||||
m_externalIndex, i, shaders[i].get());
|
m_externalIndex, i, shaders[i].get());
|
||||||
|
|||||||
@@ -4,6 +4,24 @@ namespace MobileGL {
|
|||||||
namespace MG_Util {
|
namespace MG_Util {
|
||||||
namespace ShaderTranspiler {
|
namespace ShaderTranspiler {
|
||||||
void PreprocessShaderSource(ShaderStage stage, String& source) {
|
void PreprocessShaderSource(ShaderStage stage, String& source) {
|
||||||
|
// remove #line directives
|
||||||
|
SizeT linedirPos = source.find("#line");
|
||||||
|
while (linedirPos != std::string::npos) {
|
||||||
|
SizeT newlinePos = source.find('\n', linedirPos);
|
||||||
|
source = source.replace(linedirPos, newlinePos - linedirPos, "");
|
||||||
|
linedirPos = source.find("#line", linedirPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove multi-line comment
|
||||||
|
size_t commentStartPos = source.find("/*");
|
||||||
|
while (commentStartPos != std::string::npos) {
|
||||||
|
size_t commentEndPos = source.find("*/", commentStartPos);
|
||||||
|
// + length of "*/"
|
||||||
|
source = source.replace(commentStartPos, commentEndPos - commentStartPos + 2, "");
|
||||||
|
commentStartPos = source.find("/*", commentStartPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// force #version
|
||||||
ShaderProfile profile = ShaderProfile::Core;
|
ShaderProfile profile = ShaderProfile::Core;
|
||||||
SizeT versionPos = source.find("#version");
|
SizeT versionPos = source.find("#version");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user