FPLBase
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
type_conversions_gl.h
1 // Copyright 2017 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_TYPE_CONVERSIONS_GL_H
16 #define FPLBASE_TYPE_CONVERSIONS_GL_H
17 
18 #include "fplbase/handles.h"
19 #include "fplbase/internal/detailed_render_state.h"
20 #include "fplbase/render_target.h"
21 
22 namespace fplbase {
23 
24 /// @brief Converts FPL render function value to equivalent GL enum value.
25 ///
26 /// @param func The render function value to convert.
27 unsigned int RenderFunctionToGlFunction(RenderFunction func);
28 
29 /// @brief Converts FPL blend state factor to equivalent GL enum value.
30 ///
31 /// @param factor The blend state factor to convert.
32 unsigned int BlendStateFactorToGl(BlendState::BlendFactor factor);
33 
34 /// @brief Converts FPL stencil operation value to equivalent GL enum value.
35 ///
36 /// @param op The stencil operation to convert.
37 unsigned int StencilOpToGlOp(StencilOperation::StencilOperations op);
38 
39 /// @brief Converts FPL cull face value to equivalent GL enum value.
40 ///
41 /// @param face The cull face value to convert.
42 unsigned int CullFaceToGl(CullState::CullFace face);
43 
44 /// @brief Converts FPL RenderTargetFormat to equivalent GL enum value.
45 ///
46 /// @param face The format to convert.
47 unsigned int RenderTargetFormatToGl(RenderTargetFormat format);
48 
50  HandleUnionGl() { handle.handle = 0; }
51  explicit HandleUnionGl(internal::OpaqueHandle handle) : handle(handle) {}
52  explicit HandleUnionGl(unsigned int gl_param) {
53  handle.handle = 0; // Clear all the memory first.
54  gl = gl_param;
55  }
56 
57  // Opaque handle used in external API.
59 
60  // OpenGL handles, unsigned and signed.
61  unsigned int gl;
62  int gl_int;
63 };
64 
65 // Call from OpenGL code to convert between GL and external API handles.
66 inline TextureHandle TextureHandleFromGl(unsigned int gl) {
67  return HandleUnionGl(gl).handle;
68 }
69 
70 inline TextureTarget TextureTargetFromGl(unsigned int gl) {
71  return HandleUnionGl(gl).handle;
72 }
73 
74 inline ShaderHandle ShaderHandleFromGl(unsigned int gl) {
75  return HandleUnionGl(gl).handle;
76 }
77 
78 inline UniformHandle UniformHandleFromGl(int gl_int) {
79  HandleUnionGl u;
80  u.gl_int = gl_int;
81  return u.handle;
82 }
83 
84 inline BufferHandle BufferHandleFromGl(unsigned int gl) {
85  return HandleUnionGl(gl).handle;
86 }
87 
88 inline unsigned int GlTextureHandle(TextureHandle handle) {
89  return HandleUnionGl(handle).gl;
90 }
91 
92 inline unsigned int GlTextureTarget(TextureTarget handle) {
93  return HandleUnionGl(handle).gl;
94 }
95 
96 inline unsigned int GlShaderHandle(ShaderHandle handle) {
97  return HandleUnionGl(handle).gl;
98 }
99 
100 inline int GlUniformHandle(UniformHandle handle) {
101  HandleUnionGl u;
102  u.handle = handle;
103  return u.gl_int;
104 }
105 
106 inline unsigned int GlBufferHandle(BufferHandle handle) {
107  return HandleUnionGl(handle).gl;
108 }
109 
110 } // namespace fplbase
111 
112 #endif // FPLBASE_TYPE_CONVERSIONS_GL_H
unsigned int RenderTargetFormatToGl(RenderTargetFormat format)
Converts FPL RenderTargetFormat to equivalent GL enum value.
unsigned int BlendStateFactorToGl(BlendState::BlendFactor factor)
Converts FPL blend state factor to equivalent GL enum value.
internal::OpaqueHandle TextureHandle
Backend agnostic handles to various resources.
Definition: handles.h:40
unsigned int CullFaceToGl(CullState::CullFace face)
Converts FPL cull face value to equivalent GL enum value.
Definition: type_conversions_gl.h:49
unsigned int RenderFunctionToGlFunction(RenderFunction func)
Converts FPL render function value to equivalent GL enum value.
Definition: handles.h:24
unsigned int StencilOpToGlOp(StencilOperation::StencilOperations op)
Converts FPL stencil operation value to equivalent GL enum value.