-
Notifications
You must be signed in to change notification settings - Fork 2
/
SpriteBatch.h
82 lines (65 loc) · 1.83 KB
/
SpriteBatch.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include <GL\glew.h>
#include "Vertex.h"
#include <glm\glm.hpp>
#include <vector>
namespace NeroEngine{
enum class GlyphSortType
{
NONE,
FRONT_TO_BACK,
BACK_TO_FRONT,
TEXTURE
};
class Glyph
{
public :
Glyph();
Glyph(const glm::vec4& descRect, const glm::vec4& uvRect, GLuint Texture, float Depth, const Color& color);
Glyph(const glm::vec4& descRect, const glm::vec4& uvRect, GLuint Texture, float Depth, const Color& color,float angle);
GLuint texture;
float depth;
Vertex topLeft;
Vertex bottomLeft;
Vertex topRight;
Vertex bottomRight;
private:
glm::vec2 rotatePoint(glm::vec2 pos, float angle);
};
class RenderBatch{
public:
RenderBatch(GLuint Offset, GLuint NumVertices, GLuint Texture) :offset(Offset),
numVertices(NumVertices),
texture(Texture){
}
GLuint offset;
GLuint numVertices;
GLuint texture;
};
class SpriteBatch
{
public:
SpriteBatch();
~SpriteBatch();
void init();
void begin(GlyphSortType sortType = GlyphSortType::TEXTURE);
void end();
void draw(const glm::vec4& descRect, const glm::vec4& uvRect, GLuint texture, float depth, const Color& color);
void draw(const glm::vec4& descRect, const glm::vec4& uvRect, GLuint texture, float depth, const Color& color,float angle);
void draw(const glm::vec4& descRect, const glm::vec4& uvRect, GLuint texture, float depth, const Color& color,glm::vec2& dir);
void renderBatch();
private:
void createRenderBatches();
void createVertexArray();
void sortGlyphs();
static bool compareFrontToBack(Glyph* a,Glyph* b);
static bool compareBackToFront(Glyph* a, Glyph* b);
static bool comapreTexture(Glyph* a, Glyph* b);
GLuint _vbo;
GLuint _vao;
GlyphSortType _sortType;
std::vector<Glyph*> _glyphsPointers;
std::vector<Glyph> _glyphs;
std::vector<RenderBatch> _renderBatches;
};
}