FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
preprocessor.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FPLBASE_PREPROCESSOR_H
16 #define FPLBASE_PREPROCESSOR_H
17 
18 #include <set>
19 #include "fplbase/utilities.h"
20 
21 namespace fplbase {
22 /// @brief Load a file like `LoadFile()`, but scan for directives.
23 ///
24 /// The only supported directives is \#include.
25 /// @param[in] filename A UTF-8 C-string representing the file to load.
26 /// @param[out] dest A pointer to a `std::string` to capture the preprocessed
27 /// version of the file.
28 /// @param[out] error_message A pointer to a `std::string` that captures an
29 /// error message (if the function returned `false`, indicating failure).
30 /// @return If this function returns false, `error_message` indicates which
31 /// directive caused the problem and why.
32 bool LoadFileWithDirectives(const char *filename, std::string *dest,
33  std::string *error_message);
34 
35 /// @brief Overloaded LoadFileWithDirectives to allow pre-definining \#define
36 /// identifiers.
37 ///
38 /// @param[in] filename A UTF-8 C-string representing the file to load.
39 /// @param[out] dest A pointer to a `std::string` to capture the preprocessed
40 /// version of the file.
41 /// @param[in] defines A set of identifiers which will be
42 /// prefixed with \#define at the start of the file.
43 /// before loading the file.
44 /// @param[out] error_message A pointer to a `std::string` that captures an
45 /// error message (if the function returned `false`, indicating failure).
46 /// @return If this function returns false, `error_message` indicates which
47 /// directive caused the problem and why.
48 bool LoadFileWithDirectives(const char *filename, std::string *dest,
49  const std::set<std::string> &defines,
50  std::string *error_message);
51 
52 /// @brief Overloaded LoadFileWithDirectives to allow pre-definining \#define
53 /// identifiers in an array.
54 ///
55 /// @param[in] filename A UTF-8 C-string representing the file to load.
56 /// @param[out] dest A pointer to a `std::string` to capture the preprocessed
57 /// version of the file.
58 /// @param[in] defines A nullptr-terminated array of identifiers which will be
59 /// prefixed with \#define at the start of the file.
60 /// before loading the file.
61 /// @param[out] error_message A pointer to a `std::string` that captures an
62 /// error message (if the function returned `false`, indicating failure).
63 /// @return If this function returns false, `error_message` indicates which
64 /// directive caused the problem and why.
65 bool LoadFileWithDirectives(const char *filename, std::string *dest,
66  const char * const *defines,
67  std::string *error_message);
68 
69 /// @brief Prepares OpenGL shaders for compilation across desktop or mobile.
70 ///
71 /// This function adds platform-specific definitions that allow the same
72 /// shaders to be used on both desktop and mobile versions of GL. It does so
73 /// in a way that is aware of #version and #extension directives, which must
74 /// be placed before any shader code.
75 ///
76 /// @param[in] source Shader source to be sanitized.
77 /// @param[in] defines A nullptr-terminated array of identifiers which will be
78 /// safely prefixed with \#define at the start of the file. Can be null.
79 /// @param[out] result Sanitized source code.
80 void PlatformSanitizeShaderSource(const char *source,
81  const char * const *defines, std::string *result);
82 
83 } // namespace fplbase
84 
85 #endif // FPLBASE_PREPROCESSOR_H
void PlatformSanitizeShaderSource(const char *source, const char *const *defines, std::string *result)
Prepares OpenGL shaders for compilation across desktop or mobile.
General utility functions, used by FPLBase, and that might be of use to people using the library: ...
bool LoadFileWithDirectives(const char *filename, std::string *dest, std::string *error_message)
Load a file like LoadFile(), but scan for directives.