NWengine 0.9
Loading...
Searching...
No Matches
Batch.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "Shader.h"
9#include "Texture.h"
10#include "GameObject.h"
11
12#include <unordered_map>
13#include <vector>
14
15#define UNIFORM_VIEWxPROJ_STR "uVP"
16#define UNIFORM_TEXTURE_ARRAY_STR "uTex"
17
22class Batch {
23private:
24 uint32 VAO;
25 uint32 VBO;
26 uint32 EBO;
27 bool _shouldDraw = 1; //Used for static batch only
28 int currentTexSlot = 0;
29 int offset = 0;
30
31public:
32 std::string shader = "";
33 int layer = 0;
34 bool isDynamic = 1;
35
36 std::unordered_map<GameObject*, int> objs; //The value is the offset in stride unit
37 std::vector<float> vertices;
38 std::unordered_map<Texture*, int> textures; //value is a texure slot
39
43 Batch();
44
51 bool Render(GameObject* go, float* stride);
52
56 void BindTextures();
57
61 void Draw();
62
66 void Delete();
67
68 static const uint32 strideSize;
69 static const uint32 strideSizeByte;
70 static uint32* indices;
71 static int indicesSize;
72 static uint32 batchMaxQuads;
73 static uint16 maxBatchTextures;
74
75 static std::unordered_map<int, std::vector<Batch*>> batchMap; //Batches are allocated dynamically and it's pointer is owned by this map which should be deleted with scene
76
80 static void ComputeIndices();
81
87 static int DefaultBatchDrawCallback(void* data);
88};
Defines the GameObject class and its related components.
The Batch class represents a batch of game objects to be rendered together.
Definition Batch.h:22
void Draw()
Draws the batch.
Definition Batch.cpp:143
void BindTextures()
Binds the textures associated with the batch.
Definition Batch.cpp:54
static int DefaultBatchDrawCallback(void *data)
Default batch draw callback function.
Definition Batch.cpp:187
static void ComputeIndices()
Computes the indices for the batch.
Definition Batch.cpp:71
bool Render(GameObject *go, float *stride)
Renders a game object using the batch.
Definition Batch.cpp:87
Batch()
Default constructor for the Batch class.
Definition Batch.cpp:27
void Delete()
Deletes the batch.
Definition Batch.cpp:178
Class representing a game object.
Definition GameObject.h:68