mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-09 04:38: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 "
|
||||
"binary generation",
|
||||
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();
|
||||
MGLOG_D("ProgramObject %u: GenerateBinary - compiled shader[%zu] -> TShader ptr %p",
|
||||
m_externalIndex, i, shaders[i].get());
|
||||
|
||||
@@ -4,6 +4,24 @@ namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
namespace ShaderTranspiler {
|
||||
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;
|
||||
SizeT versionPos = source.find("#version");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user