TDME2 1.9.121
GL2Renderer.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <map>
5#include <string>
6#include <vector>
7
8#include <tdme/tdme.h>
12#include <tdme/math/fwd-tdme.h>
14
15using std::array;
16using std::map;
17using std::string;
18using std::vector;
19
27
28/**
29 * OpenGL 2 renderer
30 * @author Andreas Drewke
31 * @version $Id$
32 */
34{
35private:
37 map<uint32_t, int32_t> vbosUsage;
39
40private:
41
42 /**
43 * Checks if VBO is available
44 * @return vbo availability
45 */
47
48public:
49 /**
50 * Public constructor
51 */
53
54 // overridden methods
55 bool isDepthTextureAvailable() override;
56 void initialize() override;
57 void initializeFrame() override;
58 void finishFrame() override;
59 const string getVendor() override;
60 const string getRenderer() override;
61 const string getShaderVersion() override;
63 bool isBufferObjectsAvailable() override;
64 bool isUsingProgramAttributeLocation() override;
66 bool isSpecularMappingAvailable() override;
67 bool isNormalMappingAvailable() override;
68 bool isInstancedRenderingAvailable() override;
69 bool isPBRAvailable() override;
70 bool isComputeShaderAvailable() override;
71 bool isGLCLAvailable() override;
72 bool isUsingShortIndices() override;
73 bool isDeferredShadingAvailable() override;
74 int32_t getTextureUnits() override;
75 int32_t loadShader(int32_t type, const string& pathName, const string& fileName, const string& definitions = string(), const string& functions = string()) override;
76 void useProgram(int contextIdx, int32_t programId) override;
77 int32_t createProgram(int type) override;
78 void attachShaderToProgram(int32_t programId, int32_t shaderId) override;
79 bool linkProgram(int32_t programId) override;
80 int32_t getProgramUniformLocation(int32_t programId, const string& name) override;
81 void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value) override;
82 void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value) override;
83 void setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer* data) override;
84 void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array<float, 9>& data) override;
85 void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array<float, 16>& data) override;
86 void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array<float, 4>& data) override;
87 void setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array<float, 3>& data) override;
88 void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array<float, 2>& data) override;
89 void setProgramAttributeLocation(int32_t programId, int32_t location, const string& name) override;
90 void setViewPort(int32_t width, int32_t height) override;
91 void updateViewPort() override;
92 void setClearColor(float red, float green, float blue, float alpha) override;
93 void enableCulling(int contextIdx) override;
94 void disableCulling(int contextIdx) override;
95 void setFrontFace(int contextIdx, int32_t frontFace) override;
96 void setCullFace(int32_t cullFace) override;
97 void enableBlending() override;
98 void enableAdditionBlending() override;
99 void disableBlending() override;
100 void enableDepthBufferWriting() override;
101 void disableDepthBufferWriting() override;
102 void disableDepthBufferTest() override;
103 void enableDepthBufferTest() override;
104 void setDepthFunction(int32_t depthFunction) override;
105 void setColorMask(bool red, bool green, bool blue, bool alpha) override;
106 void clear(int32_t mask) override;
107 int32_t createTexture() override;
108 int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override;
109 int32_t createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override;
110 int32_t createGBufferGeometryTexture(int32_t width, int32_t height) override;
111 int32_t createGBufferColorTexture(int32_t width, int32_t height) override;
112 void uploadTexture(int contextIdx, Texture* texture) override;
113 void uploadCubeMapTexture(int contextIdx, Texture* textureLeft, Texture* textureRight, Texture* textureTop, Texture* textureBottom, Texture* textureFront, Texture* textureBack) override;
114 int32_t createCubeMapTexture(int contextIdx, int32_t width, int32_t height) override;
115 void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height) override;
116 void resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height) override;
117 void resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) override;
118 void resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) override;
119 void bindTexture(int contextIdx, int32_t textureId) override;
120 void bindCubeMapTexture(int contextIdx, int32_t textureId) override;
121 void disposeTexture(int32_t textureId) override;
122 int32_t createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId = 0, int32_t cubeMapTextureIndex = 0) override;
124 int32_t depthBufferTextureId,
125 int32_t geometryBufferTextureId1,
126 int32_t geometryBufferTextureId2,
127 int32_t geometryBufferTextureId3,
128 int32_t colorBufferTextureId1,
129 int32_t colorBufferTextureId2,
130 int32_t colorBufferTextureId3,
131 int32_t colorBufferTextureId4,
132 int32_t colorBufferTextureId5
133 ) override;
134 void bindFrameBuffer(int32_t frameBufferId) override;
135 void disposeFrameBufferObject(int32_t frameBufferId) override;
136 vector<int32_t> createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared) override;
137 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) override;
138 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
139 void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data) override;
140 void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data) override;
141 void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
142 void bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override;
143 void bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId) override;
144 void bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override;
145 void bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override;
146 void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId) override;
147 void bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId) override;
148 void bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId) override;
149 void bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override;
150 void bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override;
151 void bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override;
152 void bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) override;
153 void bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override;
154 void bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) override;
155 void bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) override;
156 void drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override;
157 void drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override;
158 void drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override;
159 void drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override;
160 void drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override;
161 void setLineWidth(float lineWidth) override;
162 void drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override;
163 void unbindBufferObjects(int contextIdx) override;
164 void disposeBufferObjects(vector<int32_t>& bufferObjectIds) override;
165 int32_t getTextureUnit(int contextIdx) override;
166 void setTextureUnit(int contextIdx, int32_t textureUnit) override;
167 float readPixelDepth(int32_t x, int32_t y) override;
168 ByteBuffer* readPixels(int32_t x, int32_t y, int32_t width, int32_t height) override;
169 void initGuiMode() override;
170 void doneGuiMode() override;
171
172 // overridden methods for skinning on GPU via compute shader
173 void dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) override;
174 void memoryBarrier() override;
175 void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) override;
176 void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) override;
177 void bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override;
178 void bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override;
179 void bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) override;
180 void bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) override;
181 void bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) override;
182 void bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) override;
183 void bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) override;
184 void bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override;
185
186 //
187 void setVSync(bool vSync) override;
188
189 //
190 const Renderer_Statistics getStatistics() override;
191};
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.
bool checkBufferObjectsAvailable()
Checks if VBO is available.
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 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.
4x4 3D Matrix class
Definition: Matrix4x4.h:24
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