TDME2  1.9.200
BatchRendererPoints.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
6 #include <tdme/engine/Color4.h>
11 #include <tdme/engine/Engine.h>
12 #include <tdme/math/Vector3.h>
16 
17 using std::string;
18 using std::to_string;
19 
21 
31 
32 constexpr int32_t BatchRendererPoints::POINT_COUNT;
33 
34 BatchRendererPoints::BatchRendererPoints(Renderer* renderer, int32_t id)
35 {
36  this->id = id;
37  this->renderer = renderer;
38  this->acquired = false;
39  fbVertices = (fbVerticesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 3 * sizeof(float))))->asFloatBuffer();
40  fbColors = (fbColorsByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 4 * sizeof(float))))->asFloatBuffer();
41  fbPointSizes = (fbPointSizesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * sizeof(float))))->asFloatBuffer();
42  fbEffectColorMul = (fbEffectColorMulByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 4 * sizeof(float))))->asFloatBuffer();
43  fbEffectColorAdd = (fbEffectColorAddByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 4 * sizeof(float))))->asFloatBuffer();
45  sbTextureSpriteIndices = (sbTextureSpriteIndicesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 2 * sizeof(uint16_t))))->asShortBuffer();
46  sbSpriteSheetDimension = (sbSpriteSheetDimensionByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 2 * sizeof(uint16_t))))->asShortBuffer();
47  } else {
48  fbTextureSpriteIndices = (fbTextureSpriteIndicesByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 2 * sizeof(float))))->asFloatBuffer();
49  fbSpriteSheetDimension = (fbSpriteSheetDimensionByteBuffer = unique_ptr<ByteBuffer>(ByteBuffer::allocate(POINT_COUNT * 2 * sizeof(float))))->asFloatBuffer();
50  }
51 }
52 
54 {
55 }
56 
58 {
59  // initialize if not yet done
60  if (vboIds == nullptr) {
61  auto created = false;
62  auto vboManaged = Engine::getInstance()->getVBOManager()->addVBO("tdme.batchvborendererpoints." + to_string(id), 7, false, false, created);
63  vboIds = vboManaged->getVBOIds();
64  }
65 }
66 
67 void BatchRendererPoints::render(int contextIdx)
68 {
69  // skip if no vertex data exists
70  if (fbVertices.getPosition() == 0)
71  return;
72 
73  // determine point count
74  auto points = fbVertices.getPosition() / 3;
75  // upload
76  renderer->uploadBufferObject(contextIdx, (*vboIds)[0], fbVertices.getPosition() * sizeof(float), &fbVertices);
77  renderer->uploadBufferObject(contextIdx, (*vboIds)[2], fbColors.getPosition() * sizeof(float), &fbColors);
78  renderer->uploadBufferObject(contextIdx, (*vboIds)[4], fbPointSizes.getPosition() * sizeof(float), &fbPointSizes);
79  renderer->uploadBufferObject(contextIdx, (*vboIds)[5], fbEffectColorMul.getPosition() * sizeof(float), &fbEffectColorMul);
80  renderer->uploadBufferObject(contextIdx, (*vboIds)[6], fbEffectColorAdd.getPosition() * sizeof(float), &fbEffectColorAdd);
84  } else {
87  }
88  // bind vertices
89  renderer->bindVerticesBufferObject(contextIdx, (*vboIds)[0]);
90  // bind texture and sprite indices
92  // bind colors
93  renderer->bindColorsBufferObject(contextIdx, (*vboIds)[2]);
94  // bind sprite sheet dimension
96  // bind point sizes
97  renderer->bindPointSizesBufferObject(contextIdx, (*vboIds)[4]);
98  // bind effect color mul
99  renderer->bindEffectColorMulsBufferObject(contextIdx, (*vboIds)[5], 0);
100  // bind effect color add
101  renderer->bindEffectColorAddsBufferObject(contextIdx, (*vboIds)[6], 0);
102  // draw
103  renderer->drawPointsFromBufferObjects(contextIdx, points, 0);
104 }
105 
107 {
108  if (vboIds != nullptr) {
109  Engine::getInstance()->getVBOManager()->removeVBO("tdme.batchvborendererpoints." + to_string(id));
110  vboIds = nullptr;
111  }
112 }
113 
115 {
116  fbVertices.clear();
117  fbColors.clear();
124  } else {
127  }
128 }
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
static Engine * getInstance()
Returns engine instance.
Definition: Engine.h:612
static VBOManager * getVBOManager()
Definition: Engine.h:635
VBOManager_VBOManaged * addVBO(const string &vboId, int32_t ids, bool useGPUMemory, bool shared, bool &created)
Adds a VBO to manager or retrieve VBO if existing.
Definition: VBOManager.cpp:31
void removeVBO(const string &vboId)
Removes a VBO from manager.
Definition: VBOManager.cpp:73
virtual void bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor)=0
Bind effect color muls buffer object.
virtual void bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind sprite sheet dimension buffer object.
virtual void drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)=0
Draw points from buffer objects.
virtual void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data)=0
Uploads buffer data to buffer object.
virtual void bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind point sizes buffer object.
virtual void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind colors buffer object.
virtual void bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind vertices buffer object.
virtual void bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind texture and sprite indices buffer object.
virtual void bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor)=0
Bind effect color adds buffer object.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Buffer * clear()
Clear.
Definition: Buffer.h:74
Byte buffer class.
Definition: ByteBuffer.h:27
Float buffer class.
Definition: FloatBuffer.h:18
virtual int64_t getPosition()
Definition: FloatBuffer.h:45
virtual int64_t getPosition()
Definition: ShortBuffer.h:41