TDME2  1.9.200
TransparentRenderFacesGroup.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
6 #include <tdme/engine/Color4.h>
13 #include <tdme/math/Matrix4x4.h>
14 #include <tdme/utilities/Console.h>
15 
16 using std::string;
17 using std::to_string;
18 
29 
30 TransparentRenderFacesGroup::TransparentRenderFacesGroup()
31 {
32  this->objectRenderer = nullptr;
33  this->model = nullptr;
34  this->objectNode = nullptr;
35  this->facesEntityIdx = -1;
36  this->material = nullptr;
37  this->textureCoordinates = false;
38 }
39 
40 void TransparentRenderFacesGroup::set(EntityRenderer* objectRenderer, Model* model, ObjectNode* objectNode, int32_t facesEntityIdx, const Color4& effectColorAdd, const Color4& effectColorMul, const Material* material, bool textureCoordinates, const string& shader)
41 {
42  this->objectRenderer = objectRenderer;
43  this->batchRenderers.clear();
44  this->model = model;
45  this->objectNode = objectNode;
46  this->facesEntityIdx = facesEntityIdx;
47  this->effectColorAdd.set(effectColorAdd);
48  this->effectColorMul.set(effectColorMul);
49  this->material = material;
50  this->textureCoordinates = textureCoordinates;
51  this->shader = shader;
52 }
53 
54 void TransparentRenderFacesGroup::render(Engine* engine, Renderer* renderer, int contextIdx)
55 {
56  //
57  if (renderer->getShader(contextIdx) != shader) {
58  // update sahder
59  renderer->setShader(contextIdx, shader);
60  renderer->onUpdateShader(contextIdx);
61  // update lights
62  for (auto j = 0; j < engine->lights.size(); j++) {
63  engine->lights[j]->update(contextIdx);
64  }
65  // have identity texture matrix
66  renderer->getTextureMatrix(contextIdx).identity();
67  renderer->onUpdateTextureMatrix(contextIdx);
68  }
69  // store model view matrix
70  Matrix4x4 modelViewMatrix;
71  modelViewMatrix.set(renderer->getModelViewMatrix());
72  // effect
73  renderer->getEffectColorMul(contextIdx) = effectColorMul.getArray();
74  renderer->getEffectColorAdd(contextIdx) = effectColorAdd.getArray();
75  renderer->onUpdateEffect(contextIdx);
76  // material
77  string materialKey;
79  // model view matrix
80  renderer->getModelViewMatrix().identity();
81  renderer->onUpdateModelViewMatrix(contextIdx);
82  // render, reset
83  for (auto batchRendererTriangles: batchRenderers) {
84  batchRendererTriangles->render();
85  batchRendererTriangles->clear();
86  batchRendererTriangles->release();
87  }
88  batchRenderers.clear();
89  // restore GL state, model view matrix
90  renderer->unbindBufferObjects(contextIdx);
91  renderer->getModelViewMatrix().set(modelViewMatrix);
92  renderer->onUpdateModelViewMatrix(contextIdx);
93 }
Color 4 definition class.
Definition: Color4.h:18
const array< float, 4 > & getArray() const
Definition: Color4.h:262
void set(float r, float g, float b, float a)
Sets this color by its components.
Definition: Color4.h:66
Engine main class.
Definition: Engine.h:131
array< unique_ptr< Light >, LIGHTS_MAX > lights
Definition: Engine.h:291
Represents a material.
Definition: Material.h:23
Representation of a 3D model.
Definition: Model.h:35
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
virtual void onUpdateShader(int contextIdx)=0
On update shader.
array< float, 4 > & getEffectColorMul(int contextIdx)
Get effect color mul.
Definition: Renderer.h:1131
virtual void unbindBufferObjects(int contextIdx)=0
Unbind buffer objects.
const string & getShader(int contextIdx)
Get shader.
Definition: Renderer.h:1182
virtual void onUpdateTextureMatrix(int contextIdx)=0
Update texture matrix for active texture unit event.
void setShader(int contextIdx, const string &id)
Set shader.
Definition: Renderer.h:1193
virtual void onUpdateModelViewMatrix(int contextIdx)=0
Update model view matrix event.
virtual void onUpdateEffect(int contextIdx)=0
Update material.
void setupMaterial(int contextIdx, ObjectNode *objectNode, int32_t facesEntityIdx, int32_t renderTypes, bool updateOnly, string &materialKey, const string &currentMaterialKey=string())
Set ups a material for rendering.
Object node specifically for rendering.
Definition: ObjectNode.h:41
void set(EntityRenderer *objectRenderer, Model *model, ObjectNode *objectNode, int32_t facesEntityIdx, const Color4 &effectColorAdd, const Color4 &effectColorMul, const Material *material, bool textureCoordinates, const string &shader)
Set transparent render faces group.
void render(Engine *engine, Renderer *renderer, int contextIdx)
Render this transparent render faces node.
Matrix3x3 & identity()
Creates identity matrix.
Definition: Matrix3x3.h:128
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 & identity()
Creates identity matrix.
Definition: Matrix4x4.h:158
Matrix4x4 & set(float r0c0, float r0c1, float r0c2, float r0c3, float r1c0, float r1c1, float r1c2, float r1c3, float r2c0, float r2c1, float r2c2, float r2c3, float r3c0, float r3c1, float r3c2, float r3c3)
Sets this matrix by its components.
Definition: Matrix4x4.h:108
Console class.
Definition: Console.h:29