TDME2  1.9.200
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUIRenderer.cpp
Go to the documentation of this file.
2 
3 #include <array>
4 #include <memory>
5 
6 #include <tdme/tdme.h>
10 #include <tdme/engine/Engine.h>
14 #include <tdme/gui/GUI.h>
15 #include <tdme/math/Math.h>
16 #include <tdme/math/Matrix3x3.h>
18 #include <tdme/utilities/Console.h>
22 #include <tdme/utilities/Time.h>
23 
24 using std::array;
25 using std::unique_ptr;
26 
35 using tdme::gui::GUI;
36 using tdme::math::Math;
44 
45 GUIRenderer::GUIRenderer(Renderer* renderer)
46 {
47  this->renderer = renderer;
48  sbIndicesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(QUAD_COUNT * 6 * (renderer->isUsingShortIndices() == true?sizeof(uint16_t):sizeof(uint32_t))));
49  fbVertices = (fbVerticesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(QUAD_COUNT * 6 * 3 * sizeof(float))))->asFloatBuffer();
50  fbColors = (fbColorsByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(QUAD_COUNT * 6 * 4 * sizeof(float))))->asFloatBuffer();
51  fbSolidColors = (fbSolidColorsByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(QUAD_COUNT * 6 * 1 * sizeof(float))))->asFloatBuffer();
52  fbTextureCoordinates = (fbTextureCoordinatesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(QUAD_COUNT * 6 * 2 * sizeof(float))))->asFloatBuffer();
53  renderAreaLeft = 0.0f;
54  renderAreaTop = 0.0f;
55  renderAreaRight = 0.0f;
56  renderAreaBottom = 0.0f;
57  renderOffsetX = 0.0f;
58  renderOffsetY = 0.0f;
59  guiEffectOffsetX = 0.0f;
60  guiEffectOffsetY = 0.0f;
61 }
62 
64 }
65 
67 {
68  if (vboIds == nullptr) {
69  auto created = false;
70  auto vboManaged = Engine::getInstance()->getVBOManager()->addVBO("tdme.guirenderer", 5, false, false, created);
71  vboIds = vboManaged->getVBOIds();
72  if (renderer->isUsingShortIndices() == true) {
73  auto sbIndices = sbIndicesByteBuffer->asShortBuffer();
74  for (auto i = 0; i < QUAD_COUNT; i++) {
75  sbIndices.put(static_cast<uint16_t>((i * 4 + 0)));
76  sbIndices.put(static_cast<uint16_t>((i * 4 + 1)));
77  sbIndices.put(static_cast<uint16_t>((i * 4 + 2)));
78  sbIndices.put(static_cast<uint16_t>((i * 4 + 2)));
79  sbIndices.put(static_cast<uint16_t>((i * 4 + 3)));
80  sbIndices.put(static_cast<uint16_t>((i * 4 + 0)));
81  }
82  renderer->uploadIndicesBufferObject(renderer->CONTEXTINDEX_DEFAULT, (*vboIds)[0], sbIndices.getPosition() * sizeof(uint16_t), &sbIndices);
83  } else {
84  auto ibIndices = sbIndicesByteBuffer->asIntBuffer();
85  for (auto i = 0; i < QUAD_COUNT; i++) {
86  ibIndices.put(i * 4 + 0);
87  ibIndices.put(i * 4 + 1);
88  ibIndices.put(i * 4 + 2);
89  ibIndices.put(i * 4 + 2);
90  ibIndices.put(i * 4 + 3);
91  ibIndices.put(i * 4 + 0);
92  }
93  renderer->uploadIndicesBufferObject(renderer->CONTEXTINDEX_DEFAULT, (*vboIds)[0], ibIndices.getPosition() * sizeof(uint32_t), &ibIndices);
94  }
95  }
96 }
97 
99 {
100  if (vboIds != nullptr) {
101  Engine::getInstance()->getVBOManager()->removeVBO("tdme.guirenderer");
102  vboIds = nullptr;
103  }
104 }
105 
107 {
112  Engine::getGUIShader()->useProgram();
114 }
115 
117 {
119  Engine::getGUIShader()->unUseProgram();
120 }
121 
123 {
124  this->screenNode = screenNode;
125  guiEffectOffsetX = 0.0f;
126  guiEffectOffsetY = 0.0f;
129 }
130 
132 {
133  this->screenNode = nullptr;
134  guiEffectColorMul = GUIColor::GUICOLOR_WHITE;
135  guiEffectColorAdd = GUIColor::GUICOLOR_BLACK;
136 }
137 
138 void GUIRenderer::setGUIEffectOffsetX(float guiEffectOffsetX)
139 {
140  this->guiEffectOffsetX = guiEffectOffsetX;
141  screenNode->setGUIEffectOffsetX(static_cast<int>((guiEffectOffsetX * screenNode->getScreenWidth() / 2.0f)));
142 }
143 
144 void GUIRenderer::setGUIEffectOffsetY(float guiEffectOffsetY)
145 {
146  this->guiEffectOffsetY = guiEffectOffsetY;
148 }
149 
150 void GUIRenderer::setTexureMatrix(const Matrix3x3& textureMatrix) {
152 }
153 
154 void GUIRenderer::bindTexture(int32_t textureId)
155 {
157 }
158 
159 void GUIRenderer::bindMask(int32_t textureId)
160 {
164 }
165 
166 void GUIRenderer::setMaskMaxValue(float maskMaxValue) {
168 }
169 
170 void GUIRenderer::setGradient(int count, array<GUIColor, 10>& colors, array<float, 10>& colorStarts, float rotationAngle) {
171  Engine::guiShader->setGradient(count, colors, colorStarts, rotationAngle);
172 }
173 
175  Engine::guiShader->unsetGradient();
176 }
177 
179 {
180  if (quadCount == 0) {
181  fontColor = GUIColor::GUICOLOR_WHITE.getArray();
182  effectColorMul = GUIColor::GUICOLOR_WHITE.getArray();
183  effectColorAdd = GUIColor::GUICOLOR_BLACK.getArray();
184  return;
185  }
186  // use default context
187  auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
188  renderer->uploadBufferObject(contextIdx, (*vboIds)[1], fbVertices.getPosition() * sizeof(float), &fbVertices);
189  renderer->uploadBufferObject(contextIdx, (*vboIds)[2], fbSolidColors.getPosition() * sizeof(float), &fbSolidColors);
191  renderer->uploadBufferObject(contextIdx, (*vboIds)[4], fbColors.getPosition() * sizeof(float), &fbColors);
192  renderer->bindIndicesBufferObject(contextIdx, (*vboIds)[0]);
193  renderer->bindVertices2BufferObject(contextIdx, (*vboIds)[1]);
194  renderer->bindSolidColorsBufferObject(contextIdx, (*vboIds)[2]);
196  renderer->bindColorsBufferObject(contextIdx, (*vboIds)[4]);
204  effectColorAddFinal[3] = 0.0f;
207  renderer->onUpdateEffect(contextIdx);
208  renderer->onUpdateTextureMatrix(contextIdx);
210  quadCount = 0;
211  fbVertices.clear();
214  fbColors.clear();
215  fontColor = GUIColor::GUICOLOR_WHITE.getArray();
216  effectColorMul = GUIColor::GUICOLOR_WHITE.getArray();
217  effectColorAdd = GUIColor::GUICOLOR_BLACK.getArray();
218  effectColorAdd[3] = 0.0f;
219  guiEffectColorAdd[3] = 0.0f;
220 }
221 
Engine main class.
Definition: Engine.h:131
virtual void setTextureUnit(int contextIdx, int32_t textureUnit)=0
Sets up texture unit.
virtual void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer *data)=0
Uploads buffer data to buffer object.
array< float, 4 > & getEffectColorAdd(int contextIdx)
Get effect color add.
Definition: Renderer.h:1141
Matrix3x3 & getTextureMatrix(int contextIdx)
Get texture matrix.
Definition: Renderer.h:579
array< float, 4 > & getEffectColorMul(int contextIdx)
Get effect color mul.
Definition: Renderer.h:1131
virtual void unbindBufferObjects(int contextIdx)=0
Unbind buffer objects.
virtual void onUpdateTextureMatrix(int contextIdx)=0
Update texture matrix for active texture unit event.
void setMaskMaxValue(int contextIdx, float maskMaxValue)
Set mask max value.
Definition: Renderer.h:1350
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
virtual void bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind indices buffer object.
virtual void drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)=0
Draw indexed triangles from buffer objects.
virtual void bindSolidColorsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind solid colors buffer object.
virtual void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data)=0
Uploads buffer data to buffer object.
virtual void bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind texture coordinates buffer object.
virtual void onUpdateEffect(int contextIdx)=0
Update material.
virtual void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind colors buffer object.
virtual void bindVertices2BufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind vertices 2 buffer object.
GUI module class.
Definition: GUI.h:64
void setGUIEffectOffsetY(int guiEffectOffsetY)
Set GUI effect offset Y.
Definition: GUINode.h:715
void setGUIEffectOffsetX(int guiEffectOffsetX)
Set GUI effect offset X.
Definition: GUINode.h:700
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
unique_ptr< ByteBuffer > sbIndicesByteBuffer
Definition: GUIRenderer.h:78
void setGradient(int count, array< GUIColor, 10 > &colors, array< float, 10 > &colorStarts, float rotationAngle)
Set gradient properties.
void setRenderAreaLeft(float renderAreaLeft)
Set up render area left.
Definition: GUIRenderer.h:263
void initRendering()
Init rendering.
void setMaskMaxValue(float maskMaxValue)
Set mask max value.
void setTexureMatrix(const Matrix3x3 &textureMatrix)
Set texture matrix.
void unsetGradient()
Disable gradient.
void setGUIEffectOffsetY(float guiEffectOffsetY)
Set GUI effect offset Y.
static constexpr float SCREEN_BOTTOM
Definition: GUIRenderer.h:51
static constexpr float SCREEN_TOP
Definition: GUIRenderer.h:49
array< float, 4 > effectColorMulFinal
Definition: GUIRenderer.h:99
void initScreen(GUIScreenNode *screenNode)
Init screen.
void bindTexture(int32_t textureId)
Bind texture.
void setGUIEffectOffsetX(float guiEffectOffsetX)
Set GUI effect offset X.
void doneRendering()
Done rendering.
array< float, 4 > effectColorAdd
Definition: GUIRenderer.h:98
void setRenderAreaRight(float renderAreaRight)
Set up render area right.
Definition: GUIRenderer.h:309
void setRenderAreaTop(float renderAreaTop)
Set up render area top.
Definition: GUIRenderer.h:286
static constexpr float SCREEN_RIGHT
Definition: GUIRenderer.h:50
static constexpr int QUAD_COUNT
Definition: GUIRenderer.h:54
vector< int32_t > * vboIds
Definition: GUIRenderer.h:76
unique_ptr< ByteBuffer > fbColorsByteBuffer
Definition: GUIRenderer.h:81
unique_ptr< ByteBuffer > fbVerticesByteBuffer
Definition: GUIRenderer.h:79
void bindMask(int32_t textureId)
Bind mask texture.
void setRenderAreaBottom(float renderAreaBottom)
Set up render area bottom.
Definition: GUIRenderer.h:332
unique_ptr< ByteBuffer > fbSolidColorsByteBuffer
Definition: GUIRenderer.h:83
array< float, 4 > effectColorAddFinal
Definition: GUIRenderer.h:100
static constexpr float SCREEN_LEFT
Definition: GUIRenderer.h:48
array< float, 4 > effectColorMul
Definition: GUIRenderer.h:97
unique_ptr< ByteBuffer > fbTextureCoordinatesByteBuffer
Definition: GUIRenderer.h:85
Standard math functions.
Definition: Math.h:19
Matrix3x3 class representing matrix3x3 mathematical structure and operations for 2d space.
Definition: Matrix3x3.h:20
Matrix3x3 & identity()
Creates identity matrix.
Definition: Matrix3x3.h:128
Matrix3x3 & set(float r0c0, float r0c1, float r0c2, float r1c0, float r1c1, float r1c2, float r2c0, float r2c1, float r2c2)
Sets this matrix by its components.
Definition: Matrix3x3.h:88
Buffer * clear()
Clear.
Definition: Buffer.h:74
Byte buffer class.
Definition: ByteBuffer.h:27
Console class.
Definition: Console.h:29
Float buffer class.
Definition: FloatBuffer.h:18
virtual int64_t getPosition()
Definition: FloatBuffer.h:45
Integer buffer class.
Definition: IntBuffer.h:14
Short buffer class.
Definition: ShortBuffer.h:14
Time utility class.
Definition: Time.h:20