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/OgreGLSLPreprocessorWrapper.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/OgreGLSLPreprocessorWrapper.h =================================================================== --- source/graphics/OgreGLSLPreprocessorWrapper.h +++ source/graphics/OgreGLSLPreprocessorWrapper.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; @@ -37,8 +37,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/OgreGLSLPreprocessorWrapper.cpp =================================================================== --- source/graphics/OgreGLSLPreprocessorWrapper.cpp +++ source/graphics/OgreGLSLPreprocessorWrapper.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 @@ -17,11 +17,19 @@ #include "precompiled.h" -#include "PreprocessorWrapper.h" +#include "OgreGLSLPreprocessorWrapper.h" #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); +} + 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/OgreGLSLPreprocessorWrapper.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/OgreGLSLPreprocessorWrapper.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/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -34,6 +34,7 @@ #include "graphics/LightEnv.h" #include "graphics/MapReader.h" #include "graphics/MaterialManager.h" +#include "graphics/OgreGLSLPreprocessorWrapper.h" #include "graphics/TerrainTextureManager.h" #include "gui/CGUI.h" #include "gui/GUIManager.h" @@ -1016,6 +1017,7 @@ RunHardwareDetection(); + CPreprocessor::ErrorHandler = CPreprocessorWrapper::PyrogenesisShaderError; const int quality = SANE_TEX_QUALITY_DEFAULT; // TODO: set value from config file SetTextureQuality(quality); @@ -1214,7 +1216,7 @@ * -autostart-nonvisual disable any graphics and sounds * -autostart-victory=SCRIPTNAME sets the victory conditions with SCRIPTNAME * located in simulation/data/settings/victory_conditions/ - * (default conquest). When the first given SCRIPTNAME is + * (default conquest). When the first given SCRIPTNAME is * "endless", no victory conditions will apply. * -autostart-wonderduration=NUM sets the victory duration NUM for wonder victory condition * (default 10 minutes) 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/OgreGLSLPreprocessorWrapper.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;