TDME2  1.9.200
BatchRendererTriangles.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <memory>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
9 #include <tdme/engine/Color4.h>
13 #include <tdme/math/fwd-tdme.h>
14 #include <tdme/math/Matrix4x4.h>
15 #include <tdme/math/Vector2.h>
16 #include <tdme/math/Vector3.h>
19 
20 using std::array;
21 using std::unique_ptr;
22 using std::vector;
23 
31 
32 /**
33  * Batch renderer for transparent triangles
34  * @author andreas.drewke
35  */
37 {
39 
40 private:
41  static constexpr int32_t TRIANGLE_COUNT { 1024 };
42  static constexpr int32_t VERTEX_COUNT { TRIANGLE_COUNT * 3 };
43  Renderer* renderer { nullptr };
44  vector<int32_t>* vboIds { nullptr };
45  int32_t id;
46  bool acquired;
47  int32_t vertices;
48  unique_ptr<ByteBuffer> fbModelMatricesByteBuffer;
50  unique_ptr<ByteBuffer> fbEffectColorMulsByteBuffer;
52  unique_ptr<ByteBuffer> fbEffectColorAddsByteBuffer;
54  unique_ptr<ByteBuffer> fbVerticesByteBuffer;
56  unique_ptr<ByteBuffer> fbNormalsByteBuffer;
58  unique_ptr<ByteBuffer> fbTextureCoordinatesByteBuffer;
60 
61  /**
62  * Clears this batch vbo renderer
63  */
64  void clear();
65 
66  /**
67  * Render
68  */
69  void render();
70 
71  /**
72  * Adds a vertex to this transparent render faces group
73  * @param vertex vertex
74  * @param normal normal
75  * @param textureCoordinate texture coordinate
76  * @return success
77  */
78  inline bool addVertex(const Vector3& vertex, const Vector3& normal, const Vector2& textureCoordinate) {
79  // check if full
80  if (vertices == VERTEX_COUNT) return false;
81 
82  // otherwise
83  fbVertices.put(vertex.getArray());
84  fbNormals.put(normal.getArray());
85  fbTextureCoordinates.put(textureCoordinate.getArray());
86 
87  //
88  vertices++;
89  return true;
90  }
91 
92 public:
93  // forbid class copy
95 
96  /**
97  * Public constructor
98  * @param renderer renderer
99  * @param id id
100  */
102 
103  /**
104  * Destructor
105  */
107 
108  /**
109  * @return acquired
110  */
111  bool isAcquired();
112 
113  /**
114  * Acquire
115  */
116  bool acquire();
117 
118  /**
119  * Release
120  */
121  void release();
122 
123  /**
124  * Init
125  */
126  void initialize();
127 
128  /**
129  * Dispose
130  */
131  void dispose();
132 
133 };
Color 4 definition class.
Definition: Color4.h:18
bool addVertex(const Vector3 &vertex, const Vector3 &normal, const Vector2 &textureCoordinate)
Adds a vertex to this transparent render faces group.
BatchRendererTriangles(Renderer *renderer, int32_t id)
Public constructor.
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
const array< float, 2 > & getArray() const
Definition: Vector2.h:257
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
const array< float, 3 > & getArray() const
Definition: Vector3.h:366
Byte buffer class.
Definition: ByteBuffer.h:27
Float buffer class.
Definition: FloatBuffer.h:18
FloatBuffer * put(float value)
Put a float value into float buffer.
Definition: FloatBuffer.h:67
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6