scg3  0.6
scg_internals.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2014-2019 Volker Ahlers
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 
25 #ifndef SCG_INTERNALS_H_
26 #define SCG_INTERNALS_H_
27 
28 #include <memory>
29 #include <string>
30 #include <utility>
31 #include "scg_glew.h"
32 
33 namespace scg {
34 
35 
36 /*
37  * Ensure that required C++11 extensions are supported by compiler.
38  * Currently used C++11 features:
39  * auto-typed variables
40  * rvalue references
41  * strongly-typed enumerations
42  * nullptr keyword
43  * range-based for
44  * initializer lists (optional, only in application)
45  * lambda functions (optional, only in application)
46  * library functional: function objects, bind
47  * library memory: smart pointers
48  * library random
49  */
50 
51 
52 #if defined __clang__
53 // --- Clang ---
54 
55 // ensure Clang version supports required C++11 features
56 #if !__has_feature(cxx_auto_type)
57 #error Clang version supporting C++11 feature auto-typed variables is required.
58 #endif
59 
60 #if !__has_feature(cxx_rvalue_references)
61 #error Clang version supporting C++11 feature rvalue references is required.
62 #endif
63 
64 #if !__has_feature(cxx_strong_enums)
65 #error Clang version supporting C++11 feature strongly-typed enumerations is required.
66 #endif
67 
68 #if !__has_feature(cxx_nullptr)
69 #error Clang version supporting C++11 feature nullptr keyword is required.
70 #endif
71 
72 #if !__has_feature(cxx_range_for)
73 #error Clang version supporting C++11 feature range-based for is required.
74 #endif
75 
76 // check which optional C++11 features are available
77 #if __has_feature(cxx_lambdas)
78 #define SCG_CPP11_LAMBDA_FUNCTIONS
79 #endif
80 
81 #if __has_feature(cxx_generalized_initializers)
82 #define SCG_CPP11_INITIALIZER_LISTS
83 #endif
84 
85 #else
86 #if defined __GNUC__
87 // --- GCC ---
88 
89 // ensure GCC version 4.6 or higher is used
90 #define SCG_GCC_VERSION (100 * __GNUC__ + __GNUC_MINOR__)
91 #if SCG_GCC_VERSION < 406 // GCC version < 4.6
92 #error GCC 4.6 or higher is required.
93 #endif
94 
95 // check which optional C++11 features are available
96 #if SCG_GCC_VERSION >= 405 // GCC version >= 4.5
97 #define SCG_CPP11_LAMBDA_FUNCTIONS
98 #endif
99 
100 #if SCG_GCC_VERSION >= 406 // GCC version >= 4.6
101 #define SCG_CPP11_INITIALIZER_LISTS
102 #endif
103 
104 #else
105 #if defined _MSC_VER
106 // --- Visual C++ ---
107 
108 // ensure Visual C++ compiler version 11.00 (Visual Studio 2012) or higher is used
109 #if _MSC_VER < 1700 // Visual C++ internal version < 17.00
110 #error Visual C++ compiler version 11.00 (Visual Studio 2012) or higher is required.
111 #endif
112 
113 // check which optional C++11 features are available
114 #if _MSC_VER >= 1600 // Visual C++ internal version >= 16.00 (Visual Studio 2010)
115 #define SCG_CPP11_LAMBDA_FUNCTIONS
116 #endif
117 
118 #if _MSC_VER >= 1800 // Visual C++ internal version >= 18.00 (Visual Studio 2013)
119 #define SCG_CPP11_INITIALIZER_LISTS
120 #endif
121 
122 #else
123 // --- neither GCC nor Visual C++ ---
124 
125 #error Unknown compiler: only Clang, GCC, and Visual C++ are supported.
126 
127 #endif // _MSC_VER
128 
129 #endif // __GNUC__
130 
131 #endif // __clang__
132 
133 
140 #define SCG_DECLARE_CLASS(TypeName) \
141  class TypeName; \
142  typedef std::shared_ptr<TypeName> TypeName##SP; \
143  typedef std::unique_ptr<TypeName> TypeName##UP;
144 
145 SCG_DECLARE_CLASS(Animation);
146 SCG_DECLARE_CLASS(BumpMapCore);
147 SCG_DECLARE_CLASS(Camera);
148 SCG_DECLARE_CLASS(CameraController);
149 SCG_DECLARE_CLASS(Composite);
150 SCG_DECLARE_CLASS(Controller);
151 SCG_DECLARE_CLASS(ColorCore);
152 SCG_DECLARE_CLASS(Core);
153 SCG_DECLARE_CLASS(CubeMapCore);
154 SCG_DECLARE_CLASS(GeometryCore);
155 SCG_DECLARE_CLASS(GeometryCoreFactory);
156 SCG_DECLARE_CLASS(Group);
157 SCG_DECLARE_CLASS(InfoTraverser);
158 SCG_DECLARE_CLASS(KeyboardController);
159 SCG_DECLARE_CLASS(Leaf);
160 SCG_DECLARE_CLASS(Light);
161 SCG_DECLARE_CLASS(LightPosition);
162 SCG_DECLARE_CLASS(MaterialCore);
163 SCG_DECLARE_CLASS(MouseController);
164 SCG_DECLARE_CLASS(Node);
165 SCG_DECLARE_CLASS(OrthographicCamera);
166 SCG_DECLARE_CLASS(PerspectiveCamera);
167 SCG_DECLARE_CLASS(PreTraverser);
168 SCG_DECLARE_CLASS(Renderer);
169 SCG_DECLARE_CLASS(RenderState);
170 SCG_DECLARE_CLASS(RenderTraverser);
171 SCG_DECLARE_CLASS(ShaderCore);
172 SCG_DECLARE_CLASS(ShaderCoreFactory);
173 SCG_DECLARE_CLASS(Shape);
174 SCG_DECLARE_CLASS(StandardRenderer);
175 SCG_DECLARE_CLASS(TextureCore);
176 SCG_DECLARE_CLASS(Texture2DCore);
177 SCG_DECLARE_CLASS(TransformAnimation);
178 SCG_DECLARE_CLASS(Transformation);
179 SCG_DECLARE_CLASS(Traverser);
180 SCG_DECLARE_CLASS(Viewer);
181 SCG_DECLARE_CLASS(ViewState);
182 
183 
187 #define CameraTransformation Error_scg3_CameraTransformation_is_obsolete_Use_Camera_instead
188 
189 
195 #define SCG_DISALLOW_COPY_AND_ASSIGN(TypeName) \
196  TypeName(const TypeName&); \
197  void operator=(const TypeName&);
198 
199 
205 #define SCG_SAVE_AND_SWITCH_PROGRAM(_program, _programOld) \
206  GLuint _programOld; \
207  glGetIntegerv(GL_CURRENT_PROGRAM, reinterpret_cast<GLint*>(&_programOld)); \
208  if (_program != _programOld) { \
209  glUseProgram(_program); \
210  }
211 
212 
217 #define SCG_RESTORE_PROGRAM(_program, _programOld) \
218  if (_program != _programOld) { \
219  glUseProgram(_programOld); \
220  }
221 
222 
226 struct OGLAttrib {
227  const GLchar* name;
228  GLuint location;
229 };
230 
231 
235 struct OGLFragData {
236  const GLchar* name;
237  GLuint location;
238 };
239 
240 
245  const GLchar* name;
246  GLuint bindingPoint;
247 };
248 
249 
253 struct OGLSampler {
254  const GLchar* name;
255  GLuint texUnit;
256 };
257 
258 
264 
265 public:
266 
271  static void bindAttribFragDataLocations(GLuint program);
272 
277  static void bindUniformBlocks(GLuint program);
278 
283  static void bindSamplers(GLuint program);
284 
285 public:
286 
287  // attribute names and locations, defined in internals.cpp
288  static const OGLAttrib VERTEX;
289  static const OGLAttrib COLOR;
290  static const OGLAttrib NORMAL;
291  static const OGLAttrib TEX_COORD_0;
292  static const OGLAttrib TEX_COORD_1;
293  static const OGLAttrib TANGENT;
294  static const OGLAttrib BINORMAL;
295 
296  // fragment data names and locations, defined in internals.cpp
297  static const OGLFragData FRAG_COLOR;
298 
299  // uniform block names and indices, defined in internals.cpp
300  static const OGLUniformBlock LIGHT;
301  static const OGLUniformBlock MATERIAL;
302 
303  // uniform names
304  static const char* MODEL_VIEW_MATRIX;
305  static const char* PROJECTION_MATRIX;
306  static const char* MVP_MATRIX;
307  static const char* NORMAL_MATRIX;
308  static const char* TEXTURE_MATRIX;
309  static const char* COLOR_MATRIX;
310  static const char* N_LIGHTS;
311  static const char* GLOBAL_AMBIENT_LIGHT;
312  static const char* TIME;
313 
314  // sampler names and texture units
315  static const OGLSampler TEXTURE0;
316  static const OGLSampler TEXTURE1;
317 
318  // parameters
319  static const int MAX_NUMBER_OF_LIGHTS = 10;
320 
321 };
322 
323 } /* namespace scg */
324 
325 
326 #endif /* SCG_INTERNALS_H_ */
static const char * PROJECTION_MATRIX
static const OGLFragData FRAG_COLOR
static const OGLAttrib VERTEX
static const OGLAttrib TANGENT
static const OGLAttrib COLOR
OpenGL attribute names and locations, uniform names, etc., to be used by ShaderCore,...
Fragment data name and location.
static const char * COLOR_MATRIX
static const char * GLOBAL_AMBIENT_LIGHT
static const OGLUniformBlock MATERIAL
static void bindSamplers(GLuint program)
const GLchar * name
static const OGLSampler TEXTURE1
const GLchar * name
const GLchar * name
static const char * N_LIGHTS
static const char * TEXTURE_MATRIX
Local header file for GLEW library.
Attribute name and location.
static const char * MODEL_VIEW_MATRIX
static const OGLAttrib BINORMAL
static void bindAttribFragDataLocations(GLuint program)
static const OGLAttrib TEX_COORD_0
static void bindUniformBlocks(GLuint program)
static const OGLAttrib NORMAL
static const OGLUniformBlock LIGHT
Sampler name and texture unit.
Definition: Animation.h:28
const GLchar * name
static const OGLSampler TEXTURE0
static const char * TIME
SCG_DECLARE_CLASS(Animation)
Uniform block name and index.
static const char * NORMAL_MATRIX
static const int MAX_NUMBER_OF_LIGHTS
static const char * MVP_MATRIX
static const OGLAttrib TEX_COORD_1