54 lines
No EOL
1.1 KiB
C++
54 lines
No EOL
1.1 KiB
C++
#ifndef _H_INSTANCEDRAW_H
|
|
#define _H_INSTANCEDRAW_H
|
|
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
|
|
#define MAX_INSTANCES 1000
|
|
|
|
class Texture;
|
|
|
|
struct InstanceData {
|
|
glm::mat4 modelMatrix;
|
|
int tileIndex;
|
|
};
|
|
|
|
class BaseInstanceDraw
|
|
{
|
|
public:
|
|
virtual ~BaseInstanceDraw() {}
|
|
|
|
virtual void setup() = 0;
|
|
virtual void updateInstanceData(const std::vector<InstanceData>&) = 0;
|
|
virtual void draw() = 0;
|
|
protected:
|
|
unsigned VAO, VBO, EBO, instanceVBO;
|
|
Texture* texture = nullptr;
|
|
InstanceData instanceData[MAX_INSTANCES];
|
|
size_t numOfInstances = 0;
|
|
unsigned indices[6] = {
|
|
0, 1, 2,
|
|
3, 2, 0
|
|
};
|
|
};
|
|
|
|
class TileTextureInstance : public BaseInstanceDraw
|
|
{
|
|
public:
|
|
TileTextureInstance(const char* texturePath);
|
|
|
|
void updateInstanceData(const std::vector<InstanceData>&) override;
|
|
void draw() override;
|
|
|
|
private:
|
|
void setup() override;
|
|
float vertices[20] = {
|
|
// vertex
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, // bottom left
|
|
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
|
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // top right
|
|
0.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
|
|
};
|
|
};
|
|
|
|
#endif // _H_INSTANCEDRAW_H
|