TDME2  1.9.200
TransparentRenderFacesGroup.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <tuple>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
9 #include <tdme/engine/Color4.h>
14 #include <tdme/math/fwd-tdme.h>
15 #include <tdme/math/Matrix4x4.h>
16 #include <tdme/math/Vector2.h>
17 #include <tdme/math/Vector3.h>
19 #include <tdme/utilities/Console.h>
20 
21 using std::string;
22 using std::tuple;
23 using std::vector;
24 
36 
37 /**
38  * Transparent render faces group
39  * @author andreas.drewke
40  */
42 {
43  friend class ObjectNodeMesh;
44  friend class EntityRenderer;
46 
47 private:
49  vector<BatchRendererTriangles*> batchRenderers;
50  Model* model { nullptr };
51  ObjectNode* objectNode { nullptr };
52  int32_t facesEntityIdx;
53 
56 
57  const Material* material { nullptr };
59 
60  string shader;
61 
62  // forbid class copy
64 
65  /**
66  * Public constructor
67  */
69 
70  /**
71  * Set transparent render faces group
72  * @param objectRenderer object renderer
73  * @param model model
74  * @param objectNode object node
75  * @param facesEntityIdx faces entity idx
76  * @param effectColorAdd effect color add
77  * @param effectColorMul effect color mul
78  * @param material material
79  * @param textureCoordinates texture coordinates
80  * @param shader shader
81  */
83 
84  /**
85  * Creates a key for given transparent render faces group attributes
86  * @param model model
87  * @param objectNode object node
88  * @param facesEntityIdx faces entity idx
89  * @param effectColorAdd effect color add
90  * @param effectColorMul effect color mul
91  * @param material material
92  * @param textureCoordinates texture coordinates
93  * @param unique shader id
94  * @return key
95  */
96  inline static const tuple<Model*, ObjectNode*, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material*, bool, uint8_t> createKey(Model* model, ObjectNode* objectNode, int32_t facesEntityIdx, const Color4& effectColorAdd, const Color4& effectColorMul, const Material* material, bool textureCoordinates, uint8_t uniqueShaderId) {
97  return {
98  model,
99  objectNode,
101  static_cast<uint8_t>(effectColorAdd.getRed() * 255.0f),
102  static_cast<uint8_t>(effectColorAdd.getGreen() * 255.0f),
103  static_cast<uint8_t>(effectColorAdd.getBlue() * 255.0f),
104  static_cast<uint8_t>(effectColorAdd.getAlpha() * 255.0f),
105  static_cast<uint8_t>(effectColorMul.getRed() * 255.0f),
106  static_cast<uint8_t>(effectColorMul.getGreen() * 255.0f),
107  static_cast<uint8_t>(effectColorMul.getBlue() * 255.0f),
108  static_cast<uint8_t>(effectColorMul.getAlpha() * 255.0f),
109  material,
111  uniqueShaderId
112  };
113  }
114 
115  /**
116  * Adds a vertex to this transparent render faces group
117  * @param vertex vertex
118  * @param normal normal
119  * @param textureCoordinate texture coordinate
120  */
121  inline void addVertex(const Vector3& vertex, const Vector3& normal, const Vector2& textureCoordinate) {
122  // check if we have a batch renderer already?
123  if (batchRenderers.size() == 0) {
124  // nope, add first one
125  auto batchRendererTriangles = objectRenderer->acquireTrianglesBatchRenderer();
126  if (batchRendererTriangles == nullptr) {
127  Console::println(string("TransparentRenderFacesGroup::addVertex(): could not acquire triangles batch renderer"));
128  return;
129  }
130  batchRenderers.push_back(batchRendererTriangles);
131  }
132  // try to add vertex
133  auto batchRendererTriangles = batchRenderers[batchRenderers.size() - 1];
134  if (batchRendererTriangles->addVertex(vertex, normal, textureCoordinate) == true)
135  return;
136  // failed, acquire additionally one
137  batchRendererTriangles = objectRenderer->acquireTrianglesBatchRenderer();
138  if (batchRendererTriangles == nullptr) {
139  Console::println(string("TransparentRenderFacesGroup::addVertex(): could not acquire triangles batch renderer"));
140  return;
141  }
142  // add it
143  batchRenderers.push_back(batchRendererTriangles);
144  // add vertex
145  batchRendererTriangles->addVertex(vertex, normal, textureCoordinate);
146  }
147 
148  /**
149  * Render this transparent render faces node
150  * @param engine engine
151  * @param renderer renderer
152  * @param contextIdx context index
153  */
154  void render(Engine* engine, Renderer* renderer, int contextIdx);
155 
156 };
Color 4 definition class.
Definition: Color4.h:18
float getRed() const
Definition: Color4.h:92
float getGreen() const
Definition: Color4.h:107
float getAlpha() const
Definition: Color4.h:137
float getBlue() const
Definition: Color4.h:122
Engine main class.
Definition: Engine.h:131
Represents a material.
Definition: Material.h:23
Representation of a 3D model.
Definition: Model.h:35
Object node mesh specifically for rendering.
Object node specifically for rendering.
Definition: ObjectNode.h:41
void addVertex(const Vector3 &vertex, const Vector3 &normal, const Vector2 &textureCoordinate)
Adds a vertex to this transparent render faces group.
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.
static const tuple< Model *, ObjectNode *, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material *, bool, uint8_t > createKey(Model *model, ObjectNode *objectNode, int32_t facesEntityIdx, const Color4 &effectColorAdd, const Color4 &effectColorMul, const Material *material, bool textureCoordinates, uint8_t uniqueShaderId)
Creates a key for given transparent render faces group attributes.
void render(Engine *engine, Renderer *renderer, int contextIdx)
Render this transparent render faces node.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Console class.
Definition: Console.h:29
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6