TDME2 1.9.121
GL3Renderer.h
Go to the documentation of this file.
1#pragma once
2
3#if defined (__APPLE__)
4 #include <OpenCL/opencl.h>
5#endif
6
7#include <array>
8#include <map>
9#include <string>
10#include <vector>
11
12#include <tdme/tdme.h>
17
18using std::array;
19using std::map;
20using std::string;
21using std::vector;
22
30
31/**
32 * OpenGL 3 renderer
33 * @author Andreas Drewke
34 * @version $Id$
35 */
37{
38private:
39 uint32_t engineVAO;
40 map<uint32_t, int32_t> vbosUsage;
42 #if defined (__APPLE__)
43 struct CLSkinningParameters {
44 array<int32_t, 8> boundGLBuffers { -1, -1, -1, -1, -1, -1, -1, -1 };
45 array<bool, 8> boundGLBuffersWrite { false, false, false, false, false, false, false, false };
46 int32_t matrixCount { 0 };
47 int32_t instanceCount { 0 };
48 int32_t vertexCount { 0 };
49 int32_t numGroupsX { 0 };
50 int32_t numGroupsY { 0 };
51 };
52 cl_context clContext;
53 cl_program clSkinningKernelProgram;
54 cl_kernel clSkinningKernel;
55 cl_command_queue clCommandQueue;
56 CLSkinningParameters clSkinningParameters;
57
58 /**
59 * OpenCL bind GL buffer
60 * @param idx argument index
61 * @param bufferObjectId OpenGL buffer object id
62 * @param write write
63 */
64 void clBindGLBuffer(int32_t idx, int32_t bufferObjectId, bool write);
65
66 /**
67 * OpenCL error callback
68 * @param errorInfo error info
69 * @param privateInfo private info
70 * @param cb cb?
71 * @param userData user data
72 */
73 static void clErrorCallback(const char* errorInfo, const void* privateInfo, size_t cb, void* userData);
74 #endif
75
77public:
78 /**
79 * Public constructor
80 */
82
83 // overridden methods
84 void initialize() override;
85 void initializeFrame() override;
86 void finishFrame() override;
87 const string getVendor() override;
88 const string getRenderer() override;
89 const string getShaderVersion() override;
91 bool isBufferObjectsAvailable() override;
92 bool isDepthTextureAvailable() override;
93 bool isUsingProgramAttributeLocation() override;
95 bool isSpecularMappingAvailable() override;
96 bool isNormalMappingAvailable() override;
97 bool isInstancedRenderingAvailable() override;
98 bool isPBRAvailable() override;
99 bool isComputeShaderAvailable() override;
100 bool isGLCLAvailable() override;
101 bool isUsingShortIndices() override;
102 bool isDeferredShadingAvailable() override;
103 int32_t getTextureUnits() override;
104 int32_t loadShader(int32_t type, const string& pathName, const string& fileName, const string& definitions = string(), const string& functions = string()) override;
105 void useProgram(int contextIdx, int32_t programId) override;
106 int32_t createProgram(int type) override;
107 void attachShaderToProgram(int32_t programId, int32_t shaderId) override;
108 bool linkProgram(int32_t programId) override;
109 int32_t getProgramUniformLocation(int32_t programId, const string& name) override;
110 void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value) override;
111 void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value) override;
112 void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array<float, 9>& data) override;
113 void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array<float, 16>& data) override;
114 void setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer* data) override;
115 void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array<float, 4>& data) override;
116 void setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array<float, 3>& data) override;
117 void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array<float, 2>& data) override;
118 void setProgramAttributeLocation(int32_t programId, int32_t location, const string& name) override;
119 void setViewPort(int32_t width, int32_t height) override;
120 void updateViewPort() override;
121 void setClearColor(float red, float green, float blue, float alpha) override;
122 void enableCulling(int contextIdx) override;
123 void disableCulling(int contextIdx) override;
124 void setFrontFace(int contextIdx, int32_t frontFace) override;
125 void setCullFace(int32_t cullFace) override;
126 void enableBlending() override;
127 void enableAdditionBlending() override;
128 void disableBlending() override;
129 void enableDepthBufferWriting() override;
130 void disableDepthBufferWriting() override;
131 void disableDepthBufferTest() override;
132 void enableDepthBufferTest() override;
133 void setDepthFunction(int32_t depthFunction) override;
134 void setColorMask(bool red, bool green, bool blue, bool alpha) override;
135 void clear(int32_t mask) override;
136 int32_t createTexture() override;
137 int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override;
138 int32_t createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override;
139 int32_t createGBufferGeometryTexture(int32_t width, int32_t height) override;
140 int32_t createGBufferColorTexture(int32_t width, int32_t height) override;
141 void uploadTexture(int contextIdx, Texture* texture) override;
142 void uploadCubeMapTexture(int contextIdx, Texture* textureLeft, Texture* textureRight, Texture* textureTop, Texture* textureBottom, Texture* textureFront, Texture* textureBack) override;
143 int32_t createCubeMapTexture(int contextIdx, int32_t width, int32_t height) override;
144 void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height) override;
145 void resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height) override;
146 void resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) override;
147 void resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) override;
148 void bindTexture(int contextIdx, int32_t textureId) override;
149 void bindCubeMapTexture(int contextIdx, int32_t textureId) override;
150 void disposeTexture(int32_t textureId) override;
151 int32_t createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId = 0, int32_t cubeMapTextureIndex = 0) override;
153 int32_t depthBufferTextureId,
154 int32_t geometryBufferTextureId1,
155 int32_t geometryBufferTextureId2,
156 int32_t geometryBufferTextureId3,
157 int32_t colorBufferTextureId1,
158 int32_t colorBufferTextureId2,
159 int32_t colorBufferTextureId3,
160 int32_t colorBufferTextureId4,
161 int32_t colorBufferTextureId5
162 ) override;
163 void bindFrameBuffer(int32_t frameBufferId) override;
164 void disposeFrameBufferObject(int32_t frameBufferId) override;
165 vector<int32_t> createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared) override;
166 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) override;
167 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data) override;
168 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
169 void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data) override;
170 void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
171 void bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override;
172 void bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId) override;
173 void bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override;
174 void bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override;
175 void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId) override;
176 void bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId) override;
177 void bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId) override;
178 void bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override;
179 void bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override;
180 void bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override;
181 void bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) override;
182 void bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override;
183 void bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) override;
184 void bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) override;
185 void drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override;
186 void drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override;
187 void drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override;
188 void drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override;
189 void drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override;
190 void setLineWidth(float lineWidth) override;
191 void drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override;
192 void unbindBufferObjects(int contextIdx) override;
193 void disposeBufferObjects(vector<int32_t>& bufferObjectIds) override;
194 int32_t getTextureUnit(int contextIdx) override;
195 void setTextureUnit(int contextIdx, int32_t textureUnit) override;
196 float readPixelDepth(int32_t x, int32_t y) override;
197 ByteBuffer* readPixels(int32_t x, int32_t y, int32_t width, int32_t height) override;
198 void initGuiMode() override;
199 void doneGuiMode() override;
200 void dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) override;
201 void memoryBarrier() override;
202 void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) override;
203 void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
204 void bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override;
205 void bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override;
206 void bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) override;
207 void bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) override;
208 void bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) override;
209 void bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) override;
210 void bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) override;
211 void bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override;
212 void setVSync(bool vSync) override;
213 const Renderer_Statistics getStatistics() override;
214
215private:
216
217 /**
218 * Checks if GL error did occour
219 */
220 void checkGLError(int line);
221};
Frame buffer class.
Definition: FrameBuffer.h:21
void setClearColor(float red, float green, float blue, float alpha) override
Set up clear color.
void enableDepthBufferWriting() override
Enable depth buffer writing.
void bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind sprite sheet dimension buffer object.
void bindTexture(int contextIdx, int32_t textureId) override
Binds a texture with given id or unbinds when using ID_NONE.
void clear(int32_t mask) override
Clear render buffer with given mask.
void bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind tangents buffer object.
void disposeBufferObjects(vector< int32_t > &bufferObjectIds) override
Disposes a frame buffer object.
int32_t getTextureUnit(int contextIdx) override
Get texture unit.
void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array< float, 9 > &data) override
Set up a float matrix 3x3 uniform value.
void doneGuiMode() override
Set up renderer for 3d rendering.
void setColorMask(bool red, bool green, bool blue, bool alpha) override
Set up GL rendering colormask.
void bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind texture coordinates buffer object.
void bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joint weights buffer object.
void dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) override
Dispatch compute.
void attachShaderToProgram(int32_t programId, int32_t shaderId) override
Attaches a shader to a program.
void setFrontFace(int contextIdx, int32_t frontFace) override
Set up clock wise or counter clock wise faces as front face.
void setTextureUnit(int contextIdx, int32_t textureUnit) override
Sets up texture unit.
void drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override
Draw lines from buffer objects.
void disableBlending() override
Disables blending.
void setProgramAttributeLocation(int32_t programId, int32_t location, const string &name) override
Bind attribute to a input location.
void setViewPort(int32_t width, int32_t height) override
Set up viewport parameter.
void bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertices result buffer object.
void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value) override
Set up a float uniform value.
const Renderer_Statistics getStatistics() override
void initialize() override
Initialize renderer.
void setVSync(bool vSync) override
Enable/Disable v-sync.
int32_t createGBufferColorTexture(int32_t width, int32_t height) override
Creates a geometry buffer color RGBA texture.
void setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array< float, 3 > &data) override
Set up a float vec3 uniform value.
void bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override
Bind effect color adds buffer object.
bool isBufferObjectsAvailable() override
Checks if buffer objects is available.
void disposeFrameBufferObject(int32_t frameBufferId) override
Disposes a frame buffer object.
void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data) override
Uploads buffer data to buffer object.
void memoryBarrier() override
Memory barrier.
void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value) override
Set up a integer uniform value.
int32_t getProgramUniformLocation(int32_t programId, const string &name) override
Returns location of given uniform variable.
void disableDepthBufferWriting() override
Disable depth buffer writing.
void bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joint indices buffer object.
void bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind normals buffer object.
void drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override
Draw points from buffer objects.
void drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override
Draw instanced triangles from buffer objects.
void disposeTexture(int32_t textureId) override
Dispose a texture.
int32_t createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override
Creates a color buffer texture.
void disableCulling(int contextIdx) override
Disable culling.
void bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override
Bind effect color muls buffer object.
int32_t createCubeMapTexture(int contextIdx, int32_t width, int32_t height) override
Create cube map texture from frame buffers.
int32_t createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId=0, int32_t cubeMapTextureIndex=0) override
Creates a frame buffer object with depth texture attached.
int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override
Creates a depth buffer texture.
void bindCubeMapTexture(int contextIdx, int32_t textureId) override
Binds a cube map texture with given id or unbinds when using ID_NONE.
void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array< float, 4 > &data) override
Set up a float vec4 uniform value.
void setDepthFunction(int32_t depthFunction) override
Set up depth function.
void uploadCubeMapTexture(int contextIdx, Texture *textureLeft, Texture *textureRight, Texture *textureTop, Texture *textureBottom, Texture *textureFront, Texture *textureBack) override
Uploads cube map texture data to current bound texture.
void bindFrameBuffer(int32_t frameBufferId) override
Enables a framebuffer to be rendered.
int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string()) override
Loads a shader.
bool isDepthTextureAvailable() override
Checks if depth texture is available.
void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a depth texture.
void resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a geometry buffer geometry texture.
bool isInstancedRenderingAvailable() override
Checks if instanced rendering is available.
void drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override
Draw triangles from buffer objects.
void initGuiMode() override
Set up renderer for GUI rendering.
void bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joints buffer object.
void setCullFace(int32_t cullFace) override
Sets up which face will be culled.
void enableBlending() override
Enables blending.
void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer *data) override
Uploads buffer data to buffer object.
bool linkProgram(int32_t programId) override
Links attached shaders to a program.
void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array< float, 16 > &data) override
Set up a float matrix 4x4 uniform value.
void enableCulling(int contextIdx) override
Enable culling.
void bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind origins buffer object.
int32_t createProgram(int type) override
Creates a shader program.
void bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind indices buffer object.
void initializeFrame() override
Pre Frame Initialization.
int32_t createGBufferGeometryTexture(int32_t width, int32_t height) override
Creates a geometry buffer geometry texture.
void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data) override
Upload skinning buffer object.
void enableAdditionBlending() override
Enable blending with c = a + b.
void bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind vertices buffer object.
void drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override
Draw instanced indexed triangles from buffer objects.
void useProgram(int contextIdx, int32_t programId) override
Use shader program.
void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind colors buffer object.
void bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind point sizes buffer object.
void bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertices buffer object.
void checkGLError(int line)
Checks if GL error did occour.
void bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind bitangents buffer object.
void bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning normals result buffer object.
void setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer *data) override
Set up a float matrices 4x4 uniform values.
void resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a geometry buffer color RGBA texture.
void bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning matrices result buffer object.
int32_t createGeometryBufferObject(int32_t depthBufferTextureId, int32_t geometryBufferTextureId1, int32_t geometryBufferTextureId2, int32_t geometryBufferTextureId3, int32_t colorBufferTextureId1, int32_t colorBufferTextureId2, int32_t colorBufferTextureId3, int32_t colorBufferTextureId4, int32_t colorBufferTextureId5) override
Creates a geometry frame buffer object.
vector< int32_t > createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared) override
Generate buffer objects for vertex data and such.
void updateViewPort() override
Update viewport.
void bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind model matrices buffer object.
void drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override
Draw indexed triangles from buffer objects.
void disableDepthBufferTest() override
Disable depth buffer test.
void bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning normal buffer object.
void unbindBufferObjects(int contextIdx) override
Unbind buffer objects.
int32_t createTexture() override
Creates a texture.
float readPixelDepth(int32_t x, int32_t y) override
Reads a pixel depth.
void uploadTexture(int contextIdx, Texture *texture) override
Uploads texture data to current bound texture.
void setLineWidth(float lineWidth) override
Set line width.
ByteBuffer * readPixels(int32_t x, int32_t y, int32_t width, int32_t height) override
Read pixels.
void enableDepthBufferTest() override
Enable depth buffer test.
void resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height) override
Resize color buffer texture.
void bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind texture and sprite indices buffer object.
void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array< float, 2 > &data) override
Set up a float vec2 uniform value.
Byte buffer class.
Definition: ByteBuffer.h:24
Float buffer class.
Definition: FloatBuffer.h:18
Integer buffer class.
Definition: IntBuffer.h:14
Short buffer class.
Definition: ShortBuffer.h:14