LCOV - code coverage report
Current view: top level - source/graphics - PreprocessorWrapper.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 1 100.0 %
Date: 2023-01-19 00:18:29 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_PREPROCESSORWRAPPER
      19             : #define INCLUDED_PREPROCESSORWRAPPER
      20             : 
      21             : #include "ps/CStr.h"
      22             : #include "third_party/ogre3d_preprocessor/OgreGLSLPreprocessor.h"
      23             : 
      24             : #include <functional>
      25             : #include <unordered_map>
      26             : 
      27             : class CShaderDefines;
      28             : 
      29             : /**
      30             :  * Convenience wrapper around CPreprocessor.
      31             :  */
      32           6 : class CPreprocessorWrapper
      33             : {
      34             : public:
      35             :     using IncludeRetrieverCallback = std::function<bool(const CStr&, CStr& out)>;
      36             : 
      37             :     CPreprocessorWrapper();
      38             :     CPreprocessorWrapper(const IncludeRetrieverCallback& includeCallback);
      39             : 
      40             :     void AddDefine(const char* name, const char* value);
      41             : 
      42             :     void AddDefines(const CShaderDefines& defines);
      43             : 
      44             :     bool TestConditional(const CStr& expr);
      45             : 
      46             :     // Find all #include directives in the input and replace them by
      47             :     // by a file content from the directive's argument. Parsing is strict
      48             :     // and simple. The directive will be expanded in comments and multiline
      49             :     // strings.
      50             :     CStr ResolveIncludes(const CStr& source);
      51             : 
      52             :     CStr Preprocess(const CStr& input);
      53             : 
      54             :     static void PyrogenesisShaderError(int iLine, const char* iError, const Ogre::CPreprocessor::Token* iToken);
      55             : 
      56             : private:
      57             :     Ogre::CPreprocessor m_Preprocessor;
      58             :     IncludeRetrieverCallback m_IncludeCallback;
      59             :     std::unordered_map<CStr, CStr> m_IncludeCache;
      60             : };
      61             : 
      62             : #endif // INCLUDED_PREPROCESSORWRAPPER

Generated by: LCOV version 1.13