Added line numbers for shaderc preprocessed code. Fixed premake script.
This commit is contained in:
parent
e53ff3c2b0
commit
732b2432f7
@ -3,6 +3,7 @@ project "shaderc"
|
||||
kind "ConsoleApp"
|
||||
|
||||
local GLSL_OPTIMIZER = (BGFX_DIR .. "3rdparty/glsl-optimizer/")
|
||||
local FCPP_DIR = (BGFX_DIR .. "3rdparty/fcpp/")
|
||||
|
||||
configuration { "vs*" }
|
||||
includedirs {
|
||||
@ -14,7 +15,7 @@ project "shaderc"
|
||||
includedirs {
|
||||
BGFX_DIR .. "../bx/include",
|
||||
|
||||
BGFX_DIR .. "3rdparty/fcpp",
|
||||
FCPP_DIR,
|
||||
|
||||
GLSL_OPTIMIZER .. "include",
|
||||
GLSL_OPTIMIZER .. "include/c99",
|
||||
@ -24,15 +25,15 @@ project "shaderc"
|
||||
}
|
||||
|
||||
files {
|
||||
BGFX_DIR .. "3rdparty/tools/shaderc.cpp",
|
||||
BGFX_DIR .. "3rdparty/fcpp/**.h",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp1.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp2.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp3.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp4.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp5.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp6.c",
|
||||
BGFX_DIR .. "3rdparty/fcpp/cpp6.c",
|
||||
BGFX_DIR .. "tools/shaderc.cpp",
|
||||
FCPP_DIR .. "**.h",
|
||||
FCPP_DIR .. "cpp1.c",
|
||||
FCPP_DIR .. "cpp2.c",
|
||||
FCPP_DIR .. "cpp3.c",
|
||||
FCPP_DIR .. "cpp4.c",
|
||||
FCPP_DIR .. "cpp5.c",
|
||||
FCPP_DIR .. "cpp6.c",
|
||||
FCPP_DIR .. "cpp6.c",
|
||||
|
||||
GLSL_OPTIMIZER .. "src/mesa/**.c",
|
||||
GLSL_OPTIMIZER .. "src/glsl/**.cpp",
|
||||
|
@ -200,6 +200,79 @@ private:
|
||||
bool m_bigEndian;
|
||||
};
|
||||
|
||||
class LineReader
|
||||
{
|
||||
public:
|
||||
LineReader(const char* _str)
|
||||
: m_str(_str)
|
||||
, m_pos(0)
|
||||
, m_size( (uint32_t)strlen(_str) )
|
||||
{
|
||||
}
|
||||
|
||||
std::string getLine()
|
||||
{
|
||||
const char* str = &m_str[m_pos];
|
||||
skipLine();
|
||||
|
||||
const char* eol = &m_str[m_pos];
|
||||
|
||||
std::string tmp;
|
||||
tmp.assign(str, eol-str);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool isEof() const
|
||||
{
|
||||
return m_str[m_pos] == '\0';
|
||||
}
|
||||
|
||||
private:
|
||||
void skipLine()
|
||||
{
|
||||
const char* str = &m_str[m_pos];
|
||||
const char* eol = strstr(str, "\r\n");
|
||||
if (NULL != eol)
|
||||
{
|
||||
m_pos += eol-str+2;
|
||||
return;
|
||||
}
|
||||
|
||||
eol = strstr(str, "\n\r");
|
||||
if (NULL != eol)
|
||||
{
|
||||
m_pos += eol-str+2;
|
||||
return;
|
||||
}
|
||||
|
||||
eol = strstr(str, "\n");
|
||||
if (NULL != eol)
|
||||
{
|
||||
m_pos += eol-str+1;
|
||||
return;
|
||||
}
|
||||
|
||||
m_pos += (uint32_t)strlen(str);
|
||||
}
|
||||
|
||||
const char* m_str;
|
||||
uint32_t m_pos;
|
||||
uint32_t m_size;
|
||||
};
|
||||
|
||||
void printCode(const char* _code)
|
||||
{
|
||||
fprintf(stderr, "Code:\n---\n");
|
||||
|
||||
LineReader lr(_code);
|
||||
for (uint32_t line = 1; !lr.isEof(); ++line)
|
||||
{
|
||||
fprintf(stderr, "%3d: %s", line, lr.getLine().c_str() );
|
||||
}
|
||||
|
||||
fprintf(stderr, "---\n");
|
||||
}
|
||||
|
||||
bool compileGLSLShader(CommandLine& _cmdLine, const std::string& _code, const char* _outFilePath)
|
||||
{
|
||||
const glslopt_shader_type type = (0 == _stricmp(_cmdLine.findOption('\0', "type"), "fragment") ) ? kGlslOptShaderFragment : kGlslOptShaderVertex;
|
||||
@ -210,7 +283,7 @@ bool compileGLSLShader(CommandLine& _cmdLine, const std::string& _code, const ch
|
||||
|
||||
if( !glslopt_get_status(shader) )
|
||||
{
|
||||
fprintf(stderr, "Code:\n---\n%s\n---\n", _code.c_str() );
|
||||
printCode(_code.c_str() );
|
||||
fprintf(stderr, "Error: %s\n", glslopt_get_log(shader) );
|
||||
glslopt_cleanup(ctx);
|
||||
return false;
|
||||
@ -269,6 +342,7 @@ bool compileHLSLShader(CommandLine& _cmdLine, const std::string& _code, const ch
|
||||
flags |= _cmdLine.hasArg('\0', "no-preshader") ? D3DXSHADER_NO_PRESHADER : 0;
|
||||
flags |= _cmdLine.hasArg('\0', "partial-precision") ? D3DXSHADER_PARTIALPRECISION : 0;
|
||||
flags |= _cmdLine.hasArg('\0', "prefer-flow-control") ? D3DXSHADER_PREFER_FLOW_CONTROL : 0;
|
||||
flags |= _cmdLine.hasArg('\0', "backwards-compatibility") ? D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY : 0;
|
||||
|
||||
uint32_t optimization = 3;
|
||||
if (_cmdLine.hasArg(optimization, 'O') )
|
||||
@ -302,7 +376,7 @@ bool compileHLSLShader(CommandLine& _cmdLine, const std::string& _code, const ch
|
||||
);
|
||||
if (FAILED(hr) )
|
||||
{
|
||||
fprintf(stderr, "Code:\n---\n%s\n---\n", _code.c_str() );
|
||||
printCode(_code.c_str() );
|
||||
fprintf(stderr, "Error: 0x%08x %s\n", hr, errorMsg->GetBufferPointer() );
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user