diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 12:19:41 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-04 12:19:41 +0100 |
commit | 55a1e0ad7c9d2661c266b2e767bfcb2f944e859f (patch) | |
tree | fe3ac90ab853e2f87bd33294976a3fc56e144988 /src/spritebatch.cpp | |
parent | aa67c8bb56cb750ac83ecbd361439f5ecb5e12d9 (diff) | |
download | YAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.tar.gz YAGE-55a1e0ad7c9d2661c266b2e767bfcb2f944e859f.zip |
Adding spritebatch class
Diffstat (limited to 'src/spritebatch.cpp')
-rw-r--r-- | src/spritebatch.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/spritebatch.cpp b/src/spritebatch.cpp new file mode 100644 index 00000000..1abcc567 --- /dev/null +++ b/src/spritebatch.cpp @@ -0,0 +1,67 @@ +#include "spritebatch.hpp" + +#include <algorithm> + +namespace yage +{ + +SpriteBatch::SpriteBatch() +{ + createVertexArray(); +} + +SpriteBatch::~SpriteBatch() +{ + if(vao_!=0) + glDeleteVertexArrays(1, &vao_); + + if(vbo_!=0) + glDeleteVertexArrays(1, &vbo_); +} + +void SpriteBatch::begin() +{} + +void SpriteBatch::end() +{} + +void SpriteBatch::draw(const glm::vec4 &destination_rect, const glm::vec4 &uv_rect, GLuint texture, const Color &color, float depth) +{ + Glyph new_glyph; + new_glyph.texture=texture; + new_glyph.depth=depth; + + new_glyph.top_left.color=color; + new_glyph.top_left.setPosition(destination_rect.x, destination_rect.y+destination_rect.w); + new_glyph.top_left.setUv(uv_rect.x, uv_rect.y+uv_rect.w); + + new_glyph.top_right.color=color; + new_glyph.top_right.setPosition(destination_rect.x+destination_rect.z, destination_rect.y+destination_rect.w); + new_glyph.top_right.setUv(uv_rect.x+uv_rect.z, uv_rect.y+uv_rect.w); + + new_glyph.bottom_right.color=color; + new_glyph.bottom_right.setPosition(destination_rect.x+destination_rect.z, destination_rect.y); + new_glyph.bottom_right.setUv(uv_rect.x+uv_rect.z, uv_rect.y); + + new_glyph.bottom_right.color=color; + new_glyph.bottom_right.setPosition(destination_rect.x, destination_rect.y); + new_glyph.bottom_right.setUv(uv_rect.x, uv_rect.y); + + // deal with fragmenting + glyphs_.push_back(new_glyph); + glyph_ptrs_.push_back(&glyphs_.back()); +} + +void SpriteBatch::renderBatch() +{} + +void SpriteBatch::sortGlyphs() +{ + std::sort(glyph_ptrs_.begin(), glyph_ptrs_.end(), [] (Glyph *a, Glyph *b)->bool { + if(a->depth==b->depth) + return a->texture<b->texture; + return a->depth<b->depth; + }); +} + +} // yage |