mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Fix] (MG_Util/ShaderTranspiler): process shader version directive correctly when it is not the first line
This commit is contained in:
@@ -34,6 +34,8 @@ namespace MobileGL {
|
|||||||
} else {
|
} else {
|
||||||
m_compileStatus = false;
|
m_compileStatus = false;
|
||||||
m_infoLog = result.error().log;
|
m_infoLog = result.error().log;
|
||||||
|
MGLOG_D("ShaderObject::Compile: Shader %d compilation failed.\nSource:\n%s\nInfoLog:\n%s\nSetting m_compileStatus = false as a result.",
|
||||||
|
m_externalIndex, m_source.c_str(), m_infoLog.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace MobileGL {
|
|||||||
void PreprocessShaderSource(ShaderStage stage, String& source) {
|
void PreprocessShaderSource(ShaderStage stage, String& source) {
|
||||||
// remove multi-line comment
|
// remove multi-line comment
|
||||||
size_t commentStartPos = source.find("/*");
|
size_t commentStartPos = source.find("/*");
|
||||||
while (commentStartPos != std::string::npos) {
|
while (commentStartPos != String::npos) {
|
||||||
size_t commentEndPos = source.find("*/", commentStartPos);
|
size_t commentEndPos = source.find("*/", commentStartPos);
|
||||||
// + length of "*/"
|
// + length of "*/"
|
||||||
source = source.replace(commentStartPos, commentEndPos - commentStartPos + 2, "");
|
source = source.replace(commentStartPos, commentEndPos - commentStartPos + 2, "");
|
||||||
@@ -15,7 +15,7 @@ namespace MobileGL {
|
|||||||
|
|
||||||
// remove #line directives
|
// remove #line directives
|
||||||
SizeT linedirPos = source.find("#line");
|
SizeT linedirPos = source.find("#line");
|
||||||
while (linedirPos != std::string::npos) {
|
while (linedirPos != String::npos) {
|
||||||
SizeT newlinePos = source.find('\n', linedirPos);
|
SizeT newlinePos = source.find('\n', linedirPos);
|
||||||
// + length of "\n"
|
// + length of "\n"
|
||||||
source = source.replace(linedirPos, newlinePos - linedirPos + 1, "");
|
source = source.replace(linedirPos, newlinePos - linedirPos + 1, "");
|
||||||
@@ -26,7 +26,7 @@ namespace MobileGL {
|
|||||||
const char* str_np = "noperspective";
|
const char* str_np = "noperspective";
|
||||||
const SizeT len_np = strlen(str_np);
|
const SizeT len_np = strlen(str_np);
|
||||||
SizeT noperspectivePos = source.find(str_np);
|
SizeT noperspectivePos = source.find(str_np);
|
||||||
while (noperspectivePos != std::string::npos) {
|
while (noperspectivePos != String::npos) {
|
||||||
// + length of "\n"
|
// + length of "\n"
|
||||||
source = source.replace(noperspectivePos, len_np, "");
|
source = source.replace(noperspectivePos, len_np, "");
|
||||||
noperspectivePos = source.find(str_np);
|
noperspectivePos = source.find(str_np);
|
||||||
@@ -35,9 +35,9 @@ namespace MobileGL {
|
|||||||
// force #version
|
// force #version
|
||||||
ShaderProfile profile = ShaderProfile::Core;
|
ShaderProfile profile = ShaderProfile::Core;
|
||||||
SizeT versionPos = source.find("#version");
|
SizeT versionPos = source.find("#version");
|
||||||
|
SizeT lineEnd = source.find('\n', versionPos);
|
||||||
|
|
||||||
if (versionPos != String::npos) {
|
if (versionPos != String::npos) {
|
||||||
SizeT lineEnd = source.find('\n', versionPos);
|
|
||||||
String versionLine = source.substr(versionPos, lineEnd - versionPos);
|
String versionLine = source.substr(versionPos, lineEnd - versionPos);
|
||||||
|
|
||||||
if (versionLine.find("ES") != String::npos)
|
if (versionLine.find("ES") != String::npos)
|
||||||
@@ -52,7 +52,7 @@ namespace MobileGL {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SizeT firstLineEnd = source.find('\n');
|
SizeT firstLineEnd = lineEnd;
|
||||||
|
|
||||||
if (profile != ShaderProfile::ES) {
|
if (profile != ShaderProfile::ES) {
|
||||||
constexpr const char* versionDirectiveCore = "#version 460 core\n";
|
constexpr const char* versionDirectiveCore = "#version 460 core\n";
|
||||||
@@ -61,8 +61,8 @@ namespace MobileGL {
|
|||||||
const char* replacement =
|
const char* replacement =
|
||||||
(profile == ShaderProfile::Compatibility) ? versionDirectiveCompat : versionDirectiveCore;
|
(profile == ShaderProfile::Compatibility) ? versionDirectiveCompat : versionDirectiveCore;
|
||||||
|
|
||||||
if (firstLineEnd != std::string::npos) {
|
if (firstLineEnd != String::npos) {
|
||||||
source.replace(0, firstLineEnd + 1, replacement);
|
source.replace(versionPos, firstLineEnd - versionPos + 1, replacement);
|
||||||
} else {
|
} else {
|
||||||
source = replacement;
|
source = replacement;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user