summaryrefslogtreecommitdiffstats
path: root/old/graphics/RenderSection.hpp
blob: 7f976240f5b60d7fc917e26e0c70e2e26a0c951b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once

#include <GL/glew.h>
#include <glm/detail/type_mat.hpp>
#include <glm/vec2.hpp>
#include <glm/detail/type_mat4x4.hpp>
#include <glm/gtx/transform.hpp>
#include <easylogging++.h>

#include "../core/AssetManager.hpp"
#include "../world/Section.hpp"
#include "../world/World.hpp"

class RenderState {
	GLuint ActiveVao;
	GLuint ActiveShader;
public:
	void SetActiveVao(GLuint Vao);
	void SetActiveShader(GLuint Shader);
};

class RenderSection {
	Vector sectionPosition;
	World *world;
	GLuint Vao, VboTextures, VboModels, VboColors;
	std::vector<glm::mat4> models;
	std::vector<glm::vec4> textures;
	std::vector<glm::vec3> colors;

	static GLuint VboVertices, VboUvs;
	static std::map<GLuint, int> refCounterVbo;
	static std::map<GLuint, int> refCounterVao;

	size_t numOfFaces = 0;

    bool isEnabled = true;

    size_t hash = 0;
public:
	RenderSection(World *world, Vector position);
	RenderSection(const RenderSection &other);
	~RenderSection();

	void UpdateState(const std::map<BlockTextureId, glm::vec4> &textureAtlas);
	void Render(RenderState &state);

    void SetEnabled(bool isEnabled);

	Section *GetSection();

    bool IsNeedUpdate();
};