1
0
forked from mirrors/0ad

Upgrade the Ogre GLSL Preprocessor

Add #elif support and some fixes.

Reviewed by: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D2456
This was SVN commit r23404.
This commit is contained in:
Stan
2020-01-15 18:20:36 +00:00
parent eafd44cfc5
commit 215447a761
5 changed files with 1528 additions and 1470 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -22,22 +22,22 @@
#include "graphics/ShaderDefines.h"
#include "ps/CLogger.h"
void CPreprocessorWrapper::PyrogenesisShaderError(void* UNUSED(iData), int iLine, const char* iError, const char* iToken, size_t iTokenLen)
void CPreprocessorWrapper::PyrogenesisShaderError(int iLine, const char* iError, const Ogre::CPreprocessor::Token* iToken)
{
if (iToken)
LOGERROR("Preprocessor error: line %d: %s: '%s'\n", iLine, iError, std::string(iToken, iTokenLen).c_str());
LOGERROR("Preprocessor error: line %d: %s: '%s'\n", iLine, iError, std::string(iToken->String, iToken->Length).c_str());
else
LOGERROR("Preprocessor error: line %d: %s\n", iLine, iError);
}
CPreprocessorWrapper::CPreprocessorWrapper()
{
CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError;
Ogre::CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError;
}
void CPreprocessorWrapper::AddDefine(const char* name, const char* value)
{
m_Preprocessor.Define(name, value);
m_Preprocessor.Define(name, strlen(name), value, strlen(value));
}
void CPreprocessorWrapper::AddDefines(const CShaderDefines& defines)
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -39,10 +39,10 @@ public:
CStr Preprocess(const CStr& input);
static void PyrogenesisShaderError(void* UNUSED(iData), int iLine, const char* iError, const char* iToken, size_t iTokenLen);
static void PyrogenesisShaderError(int iLine, const char* iError, const Ogre::CPreprocessor::Token* iToken);
private:
CPreprocessor m_Preprocessor;
Ogre::CPreprocessor m_Preprocessor;
};
#endif // INCLUDED_PREPROCESSORWRAPPER
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -25,12 +25,12 @@ class TestPreprocessor : public CxxTest::TestSuite
public:
void setUp()
{
CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError;
Ogre::CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError;
}
void test_basic()
{
CPreprocessor preproc;
Ogre::CPreprocessor preproc;
const char* in = "#define TEST 2\n1+1=TEST\n";
size_t len = 0;
char* out = preproc.Parse(in, strlen(in), len);
@@ -45,7 +45,7 @@ public:
{
TestLogger logger;
CPreprocessor preproc;
Ogre::CPreprocessor preproc;
const char* in = "foo\n#if ()\nbar\n";
size_t len = 0;
char* out = preproc.Parse(in, strlen(in), len);