3 #include "nta/SpriteBatch.h"
4 #include "nta/Vertex.h"
9 SpriteBatch::~SpriteBatch() {
11 glDeleteBuffers(1, &m_vbo);
14 glDeleteVertexArrays(1, &
m_vao);
25 glGenBuffers(1, &m_vbo);
28 glGenVertexArrays(1, &
m_vao);
30 glBindVertexArray(
m_vao);
31 glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
32 for (
int i = 0; i < NUM_VERTEX_ATTRIBS; i++) {
33 glEnableVertexAttribArray(i);
34 Vertex2D::attribs[i].setup();
44 for (
int i = 0; i <
m_glyphs.size(); i++) {
60 bool SpriteBatch::compareDepth(
Glyph* lhs,
Glyph* rhs) {
95 glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
96 glBufferData(GL_ARRAY_BUFFER, vertexData.size()*
sizeof(
Vertex2D),
nullptr, GL_DYNAMIC_DRAW);
97 glBufferSubData(GL_ARRAY_BUFFER, 0, vertexData.size()*
sizeof(
Vertex2D), vertexData.data());
98 glBindBuffer(GL_ARRAY_BUFFER, 0);
101 crvec4 color,
float depth) {
102 m_glyphs.emplace_back(posRect, uvRect, texture, depth, color);
106 addGlyph(posRect, uvRect, texture, color, 0, depth);
109 float depth, crvec4 color) {
110 addGlyph(corner1, corner2, uvRect, texture, color, 0, depth);
113 float angle,
float depth) {
114 m_glyphs.emplace_back(posRect, uvRect, texture, depth, color, angle);
117 crvec4 color,
float angle,
float depth) {
118 glm::vec4 posRect(glm::min(corner1.x, corner2.x), glm::max(corner1.y, corner2.y),
119 glm::abs(corner1-corner2));
120 addGlyph(posRect, uvRect, texture, color, angle, depth);
123 glBindVertexArray(
m_vao);
129 glBindVertexArray(0);