TDME2 1.9.121
TransparentRenderFacesGroup.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
13#include <tdme/math/Matrix4x4.h>
15
16using std::string;
17using std::to_string;
18
29
30TransparentRenderFacesGroup::TransparentRenderFacesGroup()
31{
32 this->object3DRenderer = nullptr;
33 this->model = nullptr;
34 this->object3DNode = nullptr;
35 this->facesEntityIdx = -1;
36 this->material = nullptr;
37 this->textureCoordinates = false;
38}
39
40void TransparentRenderFacesGroup::set(EntityRenderer* object3DRenderer, Model* model, Object3DNode* object3DNode, int32_t facesEntityIdx, const Color4& effectColorAdd, const Color4& effectColorMul, const Material* material, bool textureCoordinates, const string& shader)
41{
42 this->object3DRenderer = object3DRenderer;
43 this->batchRenderers.clear();
44 this->model = model;
45 this->object3DNode = object3DNode;
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
54const string TransparentRenderFacesGroup::createKey(Model* model, Object3DNode* object3DNode, int32_t facesEntityIdx, const Color4& effectColorAdd, const Color4& effectColorMul, const Material* material, bool textureCoordinates, const string& shader)
55{
56 auto& efcmData = effectColorMul.getArray();
57 auto& efcaData = effectColorAdd.getArray();
58 string key =
59 model->getId() +
60 "," +
62 "," +
63 (textureCoordinates == true ? "TCT" : "TCF");
64 "," +
65 shader +
66 ",";
67 (material == nullptr ? "tdme.material.none" : material->getId()) + // TODO: material id could contain this "," delimiter
68 ",";
70 key.append(",");
71 key.append((const char*)&facesEntityIdx, sizeof(facesEntityIdx));
72 key.append(",");
73 key.append((const char*)&efcmData[0], sizeof(efcmData[0]));
74 key.append(",");
75 key.append((const char*)&efcmData[1], sizeof(efcmData[1]));
76 key.append(",");
77 key.append((const char*)&efcmData[2], sizeof(efcmData[2]));
78 key.append(",");
79 key.append((const char*)&efcmData[3], sizeof(efcmData[3]));
80 key.append(",");
81 key.append((const char*)&efcaData[0], sizeof(efcaData[0]));
82 key.append(",");
83 key.append((const char*)&efcaData[1], sizeof(efcaData[1]));
84 key.append(",");
85 key.append((const char*)&efcaData[2], sizeof(efcaData[2]));
86 key.append(",");
87 key.append((const char*)&efcaData[3], sizeof(efcaData[3]));
88 return key;
89}
90
91void TransparentRenderFacesGroup::render(Engine* engine, Renderer* renderer, int contextIdx)
92{
93 //
94 if (renderer->getShader(contextIdx) != shader) {
95 // update sahder
96 renderer->setShader(contextIdx, shader);
97 renderer->onUpdateShader(contextIdx);
98 // update lights
99 for (auto j = 0; j < engine->lights.size(); j++) {
100 engine->lights[j].update(contextIdx);
101 }
102 // have identity texture matrix
103 renderer->getTextureMatrix(contextIdx).identity();
104 renderer->onUpdateTextureMatrix(contextIdx);
105 }
106 // store model view matrix
107 Matrix4x4 modelViewMatrix;
108 modelViewMatrix.set(renderer->getModelViewMatrix());
109 // effect
110 renderer->getEffectColorMul(contextIdx) = effectColorMul.getArray();
111 renderer->getEffectColorAdd(contextIdx) = effectColorAdd.getArray();
112 renderer->onUpdateEffect(contextIdx);
113 // material
114 string materialKey;
116 // model view matrix
117 renderer->getModelViewMatrix().identity();
118 renderer->onUpdateModelViewMatrix(contextIdx);
119 // render, reset
120 for (auto batchRendererTriangles: batchRenderers) {
121 batchRendererTriangles->render();
122 batchRendererTriangles->clear();
123 batchRendererTriangles->release();
124 }
125 batchRenderers.clear();
126 // restore GL state, model view matrix
127 renderer->unbindBufferObjects(contextIdx);
128 renderer->getModelViewMatrix().set(modelViewMatrix);
129 renderer->onUpdateModelViewMatrix(contextIdx);
130}
Engine main class.
Definition: Engine.h:122
array< Light, LIGHTS_MAX > lights
Definition: Engine.h:257
array< float, 4 > & getArray() const
Definition: Color4Base.h:219
void set(const array< float, 4 > &color)
Set up color.
Definition: Color4Base.h:68
Color 4 definition.
Definition: Color4.h:20
Represents a material.
Definition: Material.h:21
const string & getId() const
Definition: Material.h:57
Representation of a 3d model.
Definition: Model.h:32
const string & getId()
Definition: Model.h:119
array< float, 4 > & getEffectColorMul(int contextIdx)
Get effect color mul.
Definition: Renderer.h:1116
virtual void onUpdateShader(int contextIdx)=0
On update shader.
virtual void unbindBufferObjects(int contextIdx)=0
Unbind buffer objects.
virtual void onUpdateTextureMatrix(int contextIdx)=0
Update texture matrix for active texture unit event.
const string & getShader(int contextIdx)
Get shader.
Definition: Renderer.h:1167
void setShader(int contextIdx, const string &id)
Set shader.
Definition: Renderer.h:1178
virtual void onUpdateModelViewMatrix(int contextIdx)=0
Update model view matrix event.
Matrix2D3x3 & getTextureMatrix(int contextIdx)
Get texture matrix.
Definition: Renderer.h:578
virtual void onUpdateEffect(int contextIdx)=0
Update material.
array< float, 4 > & getEffectColorAdd(int contextIdx)
Get effect color add.
Definition: Renderer.h:1126
void setupMaterial(int contextIdx, Object3DNode *object3DNode, int32_t facesEntityIdx, int32_t renderTypes, bool updateOnly, string &materialKey, const string &currentMaterialKey=string())
Set ups a material for rendering.
Object 3d node specifically for rendering.
Definition: Object3DNode.h:39
vector< int32_t > specularMaterialDynamicDiffuseTextureIdsByEntities
Definition: Object3DNode.h:64
static const string createKey(Model *model, Object3DNode *object3DNode, int32_t facesEntityIdx, const Color4 &effectColorAdd, const Color4 &effectColorMul, const Material *material, bool textureCoordinates, const string &shader)
Creates a key for given transparent render faces group attributes.
void set(EntityRenderer *object3DRenderer, Model *model, Object3DNode *object3DNode, 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.
Matrix2D3x3 & identity()
Setup identity matrix.
Definition: Matrix2D3x3.h:116
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Matrix4x4 & identity()
Setup identity matrix.
Definition: Matrix4x4.h:326
Matrix4x4 & set(float r0c0, float r1c0, float r2c0, float r3c0, float r0c1, float r1c1, float r2c1, float r3c1, float r0c2, float r1c2, float r2c2, float r3c2, float r0c3, float r1c3, float r2c3, float r3c3)
Set up matrix by values.
Definition: Matrix4x4.h:95
Console class.
Definition: Console.h:26