Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -745,6 +745,7 @@ source_dirs = { + "third_party/ogre3d_preprocessor", "tools/atlas/GameInterface", "tools/atlas/GameInterface/Handlers" } Index: source/graphics/MaterialManager.cpp =================================================================== --- source/graphics/MaterialManager.cpp +++ source/graphics/MaterialManager.cpp @@ -19,13 +19,13 @@ #include "MaterialManager.h" +#include "graphics/PreprocessorWrapper.h" #include "lib/ogl.h" #include "maths/MathUtil.h" #include "maths/Vector4D.h" #include "ps/CLogger.h" #include "ps/ConfigDB.h" #include "ps/Filesystem.h" -#include "ps/PreprocessorWrapper.h" #include "ps/XML/Xeromyces.h" #include "renderer/RenderingOptions.h" Index: source/graphics/PreprocessorWrapper.h =================================================================== --- source/graphics/PreprocessorWrapper.h +++ source/graphics/PreprocessorWrapper.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -15,10 +15,10 @@ * along with 0 A.D. If not, see . */ -#ifndef INCLUDED_PREPROCESSORWRAPPER -#define INCLUDED_PREPROCESSORWRAPPER +#ifndef INCLUDED_OGREGLSLPREPROCESSORWRAPPER +#define INCLUDED_OGREGLSLPREPROCESSORWRAPPER -#include "ps/Preprocessor.h" +#include "third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.h" #include "ps/CStr.h" class CShaderDefines; @@ -29,6 +29,8 @@ class CPreprocessorWrapper { public: + CPreprocessorWrapper(); + void AddDefine(const char* name, const char* value); void AddDefines(const CShaderDefines& defines); @@ -37,8 +39,10 @@ CStr Preprocess(const CStr& input); + static void PyrogenesisShaderError(void* UNUSED(iData), int iLine, const char* iError, const char* iToken, size_t iTokenLen); + private: CPreprocessor m_Preprocessor; }; -#endif // INCLUDED_PREPROCESSORWRAPPER +#endif // INCLUDED_OGREGLSLPREPROCESSORWRAPPER Index: source/graphics/PreprocessorWrapper.cpp =================================================================== --- source/graphics/PreprocessorWrapper.cpp +++ source/graphics/PreprocessorWrapper.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,6 +22,19 @@ #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) +{ + if (iToken) + LOGERROR("Preprocessor error: line %d: %s: '%s'\n", iLine, iError, std::string(iToken, iTokenLen).c_str()); + else + LOGERROR("Preprocessor error: line %d: %s\n", iLine, iError); +} + +CPreprocessorWrapper::CPreprocessorWrapper() +{ + CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError; +} + void CPreprocessorWrapper::AddDefine(const char* name, const char* value) { m_Preprocessor.Define(name, value); Index: source/graphics/ShaderManager.cpp =================================================================== --- source/graphics/ShaderManager.cpp +++ source/graphics/ShaderManager.cpp @@ -19,6 +19,7 @@ #include "ShaderManager.h" +#include "graphics/PreprocessorWrapper.h" #include "graphics/ShaderTechnique.h" #include "lib/config2.h" #include "lib/timer.h" @@ -26,7 +27,6 @@ #include "ps/CLogger.h" #include "ps/CStrIntern.h" #include "ps/Filesystem.h" -#include "ps/PreprocessorWrapper.h" #include "ps/Profile.h" #if USE_SHADER_XML_VALIDATION # include "ps/XML/RelaxNG.h" Index: source/graphics/ShaderProgram.cpp =================================================================== --- source/graphics/ShaderProgram.cpp +++ source/graphics/ShaderProgram.cpp @@ -20,6 +20,7 @@ #include "ShaderProgram.h" #include "graphics/Color.h" +#include "graphics/PreprocessorWrapper.h" #include "graphics/ShaderManager.h" #include "graphics/TextureManager.h" #include "lib/res/graphics/ogl_tex.h" @@ -27,7 +28,6 @@ #include "maths/Vector3D.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" -#include "ps/PreprocessorWrapper.h" #if !CONFIG2_GLES Index: source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp =================================================================== --- source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp +++ source/third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.cpp @@ -34,9 +34,7 @@ #include "precompiled.h" -#include "Preprocessor.h" - -#include "ps/CLogger.h" +#include "OgreGLSLPreprocessor.h" // Limit max number of macro arguments to this #define MAX_MACRO_ARGS 16 @@ -230,11 +228,12 @@ const char *iToken, size_t iTokenLen) { (void)iData; + char line [1000]; if (iToken) - LOGERROR("Preprocessor error: line %d: %s: '%s'\n", - iLine, iError, std::string (iToken, iTokenLen)); + snprintf (line, sizeof (line), "line %d: %s: `%.*s'\n", + iLine, iError, int (iTokenLen), iToken); else - LOGERROR("Preprocessor error: line %d: %s\n", iLine, iError); + snprintf (line, sizeof (line), "line %d: %s\n", iLine, iError); } //---------------------------------------------------------------------------// Index: source/third_party/ogre3d_preprocessor/tests/test_Preprocessor.h =================================================================== --- source/third_party/ogre3d_preprocessor/tests/test_Preprocessor.h +++ source/third_party/ogre3d_preprocessor/tests/test_Preprocessor.h @@ -17,11 +17,17 @@ #include "lib/self_test.h" -#include "ps/Preprocessor.h" +#include "graphics/PreprocessorWrapper.h" +#include "third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.h" class TestPreprocessor : public CxxTest::TestSuite { public: + void setUp() + { + CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError; + } + void test_basic() { CPreprocessor preproc;