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