TDME2  1.9.200
BatchRendererPoints.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/engine/Color4.h>
13 
14 using std::unique_ptr;
15 using std::to_string;
16 using std::vector;
17 
24 
25 /**
26  * Batch renderer for points
27  * @author andreas.drewke
28  */
30 {
31  friend class EntityRenderer;
32 
33 private:
34  static constexpr int32_t POINT_COUNT { 65535 };
35  Renderer* renderer { nullptr };
36  vector<int32_t>* vboIds { nullptr };
37  int32_t id;
38  bool acquired;
39  unique_ptr<ByteBuffer> fbVerticesByteBuffer;
41  unique_ptr<ByteBuffer> sbTextureSpriteIndicesByteBuffer;
43  unique_ptr<ByteBuffer> fbColorsByteBuffer;
45  unique_ptr<ByteBuffer> fbPointSizesByteBuffer;
47  unique_ptr<ByteBuffer> sbSpriteSheetDimensionByteBuffer;
49  unique_ptr<ByteBuffer> fbEffectColorMulByteBuffer;
51  unique_ptr<ByteBuffer> fbEffectColorAddByteBuffer;
53 
54  unique_ptr<ByteBuffer> fbTextureSpriteIndicesByteBuffer;
56  unique_ptr<ByteBuffer> fbSpriteSheetDimensionByteBuffer;
58 
59 public:
60  // forbid class copy
62 
63  /**
64  * Public constructor
65  */
67 
68  /**
69  * Destructor
70  */
72 
73  /**
74  * Render
75  * @param contextIdx context index
76  */
77  void render(int contextIdx);
78 
79  /**
80  * Clears this batch vbo renderer
81  */
82  void clear();
83 
84  /**
85  * Adds a transparent render point to this transparent render points
86  * @param point transparent render point
87  * @param atlasTextureIndex atlas texture index
88  * @param pointSize point size
89  * @param effectColorMul effect color mul
90  * @param effectColorAdd effect color add
91  * @param textureHorizontalSprites texture horizontal sprites
92  * @param textureVerticalSprites texture vertical sprites
93  */
94  inline void addPoint(const TransparentRenderPoint* point, int atlasTextureIndex, float pointSize, const Color4& effectColorMul, const Color4& effectColorAdd, int textureHorizontalSprites, int textureVerticalSprites) {
95  fbVertices.put(point->point.getArray());
96  sbTextureSpriteIndices.put(atlasTextureIndex);
98  fbColors.put(point->color.getArray());
99  fbPointSizes.put(pointSize);
100  sbSpriteSheetDimension.put(textureHorizontalSprites);
101  sbSpriteSheetDimension.put(textureVerticalSprites);
102  fbEffectColorMul.put(effectColorMul.getArray());
103  fbEffectColorAdd.put(effectColorAdd.getArray());
104  }
105 
106  /**
107  * Adds a transparent render point to this transparent render points
108  * @param point transparent render point
109  * @param atlasTextureIndex atlas texture index
110  * @param pointSize point size
111  * @param effectColorMul effect color mul
112  * @param effectColorAdd effect color add
113  * @param textureHorizontalSprites texture horizontal sprites
114  * @param textureVerticalSprites texture vertical sprites
115  */
116  inline void addPointNoInteger(const TransparentRenderPoint* point, int atlasTextureIndex, float pointSize, const Color4& effectColorMul, const Color4& effectColorAdd, int textureHorizontalSprites, int textureVerticalSprites) {
117  fbVertices.put(point->point.getArray());
118  fbTextureSpriteIndices.put(static_cast<float>(atlasTextureIndex + 0.1f));
119  fbTextureSpriteIndices.put(static_cast<float>(point->spriteIndex + 0.1f));
120  fbColors.put(point->color.getArray());
121  fbPointSizes.put(pointSize);
122  fbSpriteSheetDimension.put(static_cast<float>(textureHorizontalSprites + 0.1f));
123  fbSpriteSheetDimension.put(static_cast<float>(textureVerticalSprites + 0.1f));
124  fbEffectColorMul.put(effectColorMul.getArray());
125  fbEffectColorAdd.put(effectColorAdd.getArray());
126  }
127 
128  /**
129  * @return has points
130  */
131  inline bool hasPoints() {
132  return fbVertices.getPosition() > 0;
133  }
134 
135  inline int getPointCount() {
136  return fbVertices.getPosition() / 3;
137  }
138 
139  /**
140  * @return acquired
141  */
142  inline bool isAcquired() {
143  return acquired;
144  }
145 
146  /**
147  * Acquire
148  */
149  inline bool acquire() {
150  if (acquired == true) return false;
151  acquired = true;
152  return true;
153  }
154 
155  /**
156  * Release
157  */
158  inline void release() {
159  acquired = false;
160  }
161 
162  /**
163  * Init
164  */
165  void initialize();
166 
167  /**
168  * Dispose
169  */
170  void dispose();
171 };
Color 4 definition class.
Definition: Color4.h:18
const array< float, 4 > & getArray() const
Definition: Color4.h:262
BatchRendererPoints(Renderer *renderer, int32_t id)
Public constructor.
void addPointNoInteger(const TransparentRenderPoint *point, int atlasTextureIndex, float pointSize, const Color4 &effectColorMul, const Color4 &effectColorAdd, int textureHorizontalSprites, int textureVerticalSprites)
Adds a transparent render point to this transparent render points.
void addPoint(const TransparentRenderPoint *point, int atlasTextureIndex, float pointSize, const Color4 &effectColorMul, const Color4 &effectColorAdd, int textureHorizontalSprites, int textureVerticalSprites)
Adds a transparent render point to this transparent render points.
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
virtual int64_t getPosition()
Definition: FloatBuffer.h:45
Short buffer class.
Definition: ShortBuffer.h:14
ShortBuffer * put(uint16_t value)
Put a value into current position.
Definition: ShortBuffer.h:60
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6