mirror of https://github.com/bkaradzic/bgfx
shaderc: Normalize EOL before processing shader.
This commit is contained in:
parent
30b7d5dc26
commit
930fbe9e1a
|
@ -293,14 +293,14 @@ private:
|
|||
uint32_t m_size;
|
||||
};
|
||||
|
||||
void strins(char* _str, const char* _insert)
|
||||
void strInsert(char* _str, const char* _insert)
|
||||
{
|
||||
size_t len = strlen(_insert);
|
||||
memmove(&_str[len], _str, strlen(_str) );
|
||||
memcpy(_str, _insert, len);
|
||||
}
|
||||
|
||||
void strreplace(char* _str, const char* _find, const char* _replace)
|
||||
void strReplace(char* _str, const char* _find, const char* _replace)
|
||||
{
|
||||
const size_t len = strlen(_find);
|
||||
|
||||
|
@ -319,6 +319,12 @@ void strreplace(char* _str, const char* _find, const char* _replace)
|
|||
}
|
||||
}
|
||||
|
||||
void strNormalizeEol(char* _str)
|
||||
{
|
||||
strReplace(_str, "\r\n", "\n");
|
||||
strReplace(_str, "\r", "\n");
|
||||
}
|
||||
|
||||
void printCode(const char* _code, int32_t _line, int32_t _start, int32_t _end)
|
||||
{
|
||||
fprintf(stderr, "Code:\n---\n");
|
||||
|
@ -587,7 +593,7 @@ void addFragData(Preprocessor& _preprocessor, char* _data, uint32_t _idx, bool _
|
|||
char replace[32];
|
||||
bx::snprintf(replace, sizeof(replace), "gl_FragData_%d_", _idx);
|
||||
|
||||
strreplace(_data, find, replace);
|
||||
strReplace(_data, find, replace);
|
||||
|
||||
_preprocessor.writef(
|
||||
" \\\n\t%sout vec4 gl_FragData_%d_ : SV_TARGET%d"
|
||||
|
@ -602,7 +608,7 @@ void voidFragData(char* _data, uint32_t _idx)
|
|||
char find[32];
|
||||
bx::snprintf(find, sizeof(find), "gl_FragData[%d]", _idx);
|
||||
|
||||
strreplace(_data, find, "bgfx_VoidFrag");
|
||||
strReplace(_data, find, "bgfx_VoidFrag");
|
||||
}
|
||||
|
||||
// c - compute
|
||||
|
@ -1015,6 +1021,8 @@ int main(int _argc, const char* _argv[])
|
|||
memset(&data[size+1], 0, padding);
|
||||
fclose(file);
|
||||
|
||||
strNormalizeEol(data);
|
||||
|
||||
input = const_cast<char*>(bx::strws(data) );
|
||||
while (input[0] == '$')
|
||||
{
|
||||
|
@ -1408,7 +1416,7 @@ int main(int _argc, const char* _argv[])
|
|||
const char* brace = strstr(entry, "{");
|
||||
if (NULL != brace)
|
||||
{
|
||||
strins(const_cast<char*>(brace+1), "\nvec4 bgfx_VoidFrag;\n");
|
||||
strInsert(const_cast<char*>(brace+1), "\nvec4 bgfx_VoidFrag;\n");
|
||||
}
|
||||
|
||||
const bool hasFragCoord = NULL != strstr(input, "gl_FragCoord") || hlsl > 3 || hlsl == 2;
|
||||
|
@ -1540,7 +1548,7 @@ int main(int _argc, const char* _argv[])
|
|||
const char* end = bx::strmb(brace, '{', '}');
|
||||
if (NULL != end)
|
||||
{
|
||||
strins(const_cast<char*>(end), "__RETURN__;\n");
|
||||
strInsert(const_cast<char*>(end), "__RETURN__;\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ struct Uniform
|
|||
typedef std::vector<Uniform> UniformArray;
|
||||
|
||||
void printCode(const char* _code, int32_t _line = 0, int32_t _start = 0, int32_t _end = INT32_MAX);
|
||||
void strreplace(char* _str, const char* _find, const char* _replace);
|
||||
void strReplace(char* _str, const char* _find, const char* _replace);
|
||||
int32_t writef(bx::WriterI* _writer, const char* _format, ...);
|
||||
void writeFile(const char* _filePath, const void* _data, int32_t _size);
|
||||
|
||||
|
|
|
@ -70,17 +70,17 @@ bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _gles, const std::str
|
|||
if (0 != _gles)
|
||||
{
|
||||
char* code = const_cast<char*>(optimizedShader);
|
||||
strreplace(code, "gl_FragDepthEXT", "gl_FragDepth");
|
||||
strReplace(code, "gl_FragDepthEXT", "gl_FragDepth");
|
||||
|
||||
strreplace(code, "texture2DLodEXT", "texture2DLod");
|
||||
strreplace(code, "texture2DProjLodEXT", "texture2DProjLod");
|
||||
strreplace(code, "textureCubeLodEXT", "textureCubeLod");
|
||||
strreplace(code, "texture2DGradEXT", "texture2DGrad");
|
||||
strreplace(code, "texture2DProjGradEXT", "texture2DProjGrad");
|
||||
strreplace(code, "textureCubeGradEXT", "textureCubeGrad");
|
||||
strReplace(code, "texture2DLodEXT", "texture2DLod");
|
||||
strReplace(code, "texture2DProjLodEXT", "texture2DProjLod");
|
||||
strReplace(code, "textureCubeLodEXT", "textureCubeLod");
|
||||
strReplace(code, "texture2DGradEXT", "texture2DGrad");
|
||||
strReplace(code, "texture2DProjGradEXT", "texture2DProjGrad");
|
||||
strReplace(code, "textureCubeGradEXT", "textureCubeGrad");
|
||||
|
||||
strreplace(code, "shadow2DEXT", "shadow2D");
|
||||
strreplace(code, "shadow2DProjEXT", "shadow2DProj");
|
||||
strReplace(code, "shadow2DEXT", "shadow2D");
|
||||
strReplace(code, "shadow2DProjEXT", "shadow2DProj");
|
||||
}
|
||||
|
||||
UniformArray uniforms;
|
||||
|
|
Loading…
Reference in New Issue