Overte C++ Documentation
GLShared.h
1 //
2 // Created by Bradley Austin Davis on 2016/05/15
3 // Copyright 2013-2016 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #ifndef hifi_gpu_GLShared_h
9 #define hifi_gpu_GLShared_h
10 
11 #include <gl/Config.h>
12 #include <gl/GLHelpers.h>
13 #include <gpu/Forward.h>
14 #include <gpu/Format.h>
15 #include <gpu/Context.h>
16 #include <QLoggingCategory>
17 
18 Q_DECLARE_LOGGING_CATEGORY(gpugllogging)
19 Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl)
20 Q_DECLARE_LOGGING_CATEGORY(trace_render_gpu_gl_detail)
21 
22 #if defined(__clang__)
23 #define BUFFER_OFFSET(bytes) (reinterpret_cast<GLvoid*>(bytes))
24 #else
25 #define BUFFER_OFFSET(bytes) ((GLubyte*) nullptr + (bytes))
26 #endif
27 
28 namespace gpu { namespace gl {
29 
30 // Create a fence and inject a GPU wait on the fence
31 void serverWait();
32 
33 // Create a fence and synchronously wait on the fence
34 void clientWait();
35 
36 gpu::Size getFreeDedicatedMemory();
37 ComparisonFunction comparisonFuncFromGL(GLenum func);
38 State::StencilOp stencilOpFromGL(GLenum stencilOp);
39 State::BlendOp blendOpFromGL(GLenum blendOp);
40 State::BlendArg blendArgFromGL(GLenum blendArg);
41 void getCurrentGLState(State::Data& state);
42 
43 enum GLSyncState {
44  // The object is currently undergoing no processing, although it's content
45  // may be out of date, or it's storage may be invalid relative to the
46  // owning GPU object
47  Idle,
48  // The object has been queued for transfer to the GPU
49  Pending,
50  // The object has been transferred to the GPU, but is awaiting
51  // any post transfer operations that may need to occur on the
52  // primary rendering thread
53  Transferred,
54 };
55 
56 static const GLenum BLEND_OPS_TO_GL[State::NUM_BLEND_OPS] = {
57  GL_FUNC_ADD,
58  GL_FUNC_SUBTRACT,
59  GL_FUNC_REVERSE_SUBTRACT,
60  GL_MIN,
61  GL_MAX
62 };
63 
64 static const GLenum BLEND_ARGS_TO_GL[State::NUM_BLEND_ARGS] = {
65  GL_ZERO,
66  GL_ONE,
67  GL_SRC_COLOR,
68  GL_ONE_MINUS_SRC_COLOR,
69  GL_SRC_ALPHA,
70  GL_ONE_MINUS_SRC_ALPHA,
71  GL_DST_ALPHA,
72  GL_ONE_MINUS_DST_ALPHA,
73  GL_DST_COLOR,
74  GL_ONE_MINUS_DST_COLOR,
75  GL_SRC_ALPHA_SATURATE,
76  GL_CONSTANT_COLOR,
77  GL_ONE_MINUS_CONSTANT_COLOR,
78  GL_CONSTANT_ALPHA,
79  GL_ONE_MINUS_CONSTANT_ALPHA,
80 };
81 
82 static const GLenum COMPARISON_TO_GL[gpu::NUM_COMPARISON_FUNCS] = {
83  GL_NEVER,
84  GL_LESS,
85  GL_EQUAL,
86  GL_LEQUAL,
87  GL_GREATER,
88  GL_NOTEQUAL,
89  GL_GEQUAL,
90  GL_ALWAYS
91 };
92 
93 static const GLenum PRIMITIVE_TO_GL[gpu::NUM_PRIMITIVES] = {
94  GL_POINTS,
95  GL_LINES,
96  GL_LINE_STRIP,
97  GL_TRIANGLES,
98  GL_TRIANGLE_STRIP,
99  GL_TRIANGLE_FAN,
100 };
101 
102 static const GLenum ELEMENT_TYPE_TO_GL[gpu::NUM_TYPES] = {
103  GL_FLOAT,
104  GL_INT,
105  GL_UNSIGNED_INT,
106  GL_HALF_FLOAT,
107  GL_SHORT,
108  GL_UNSIGNED_SHORT,
109  GL_BYTE,
110  GL_UNSIGNED_BYTE,
111  // Normalized values
112  GL_INT,
113  GL_UNSIGNED_INT,
114  GL_SHORT,
115  GL_UNSIGNED_SHORT,
116  GL_BYTE,
117  GL_UNSIGNED_BYTE,
118  GL_UNSIGNED_BYTE,
119  GL_INT_2_10_10_10_REV,
120 };
121 
122 class GLBackend;
123 
124 template <typename GPUType>
125 struct GLObject : public GPUObject {
126 public:
127  GLObject(const std::weak_ptr<GLBackend>& backend, const GPUType& gpuObject, GLuint id) : _gpuObject(gpuObject), _id(id), _backend(backend) {}
128 
129  virtual ~GLObject() { }
130 
131  const GPUType& _gpuObject;
132  const GLuint _id;
133 protected:
134  const std::weak_ptr<GLBackend> _backend;
135 };
136 
137 class GlBuffer;
138 class GLFramebuffer;
139 class GLPipeline;
140 class GLQuery;
141 class GLState;
142 class GLShader;
143 class GLTexture;
144 class GLTextureTransferEngine;
145 using GLTextureTransferEnginePointer = std::shared_ptr<GLTextureTransferEngine>;
146 struct ShaderObject;
147 
148 } } // namespace gpu::gl
149 
150 #endif
151 
152 
153