2018-10-08 19:19:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-09 15:42:17 +00:00
|
|
|
#include "Poseable2D.h"
|
|
|
|
#include "TextureRenderable.h"
|
|
|
|
#include "Poseable2DBatch.h"
|
2018-10-08 19:19:48 +00:00
|
|
|
|
|
|
|
namespace charcoal
|
|
|
|
{
|
|
|
|
namespace builtin
|
|
|
|
{
|
2018-10-09 15:42:17 +00:00
|
|
|
template <typename VertexType, typename IndexType>
|
|
|
|
class SpriteBatch : public Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >
|
2018-10-08 19:19:48 +00:00
|
|
|
{
|
2018-10-09 15:42:17 +00:00
|
|
|
// Note: This is VERY similar to builtin::textured::Batch
|
|
|
|
// TODO: Use Poseable2D for each sprite's position
|
|
|
|
// TODO: Have a texture
|
|
|
|
// Note: Uses GL_TEXTURE0. The uniform for this texture should be set in the scene before rendering.
|
2018-10-08 19:19:48 +00:00
|
|
|
SpriteBatch(
|
2018-10-09 15:42:17 +00:00
|
|
|
TextureRenderable<VertexType, IndexType>* renderable,
|
2018-10-08 19:19:48 +00:00
|
|
|
int element_count
|
2018-10-09 15:42:17 +00:00
|
|
|
) : Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >(renderable, element_count)
|
2018-10-08 19:19:48 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
SpriteBatch(
|
2018-10-09 15:42:17 +00:00
|
|
|
TextureRenderable<VertexType, IndexType>* renderable,
|
2018-10-08 19:19:48 +00:00
|
|
|
int element_count,
|
|
|
|
int element_render_count
|
2018-10-09 15:42:17 +00:00
|
|
|
) : Poseable2DBatch<VertexType, IndexType, TextureRenderable<VertexType, IndexType> >(renderable, element_count, element_render_count)
|
2018-10-08 19:19:48 +00:00
|
|
|
{}
|
2018-10-09 15:42:17 +00:00
|
|
|
|
|
|
|
void preprender() const override
|
|
|
|
{
|
|
|
|
// Note: Uses GL_TEXTURE0. The uniform for this texture should be set in the scene.
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_texture()->get_texture());
|
|
|
|
glBindSampler(0, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_p_renderable->get_sampler()->get_sampler());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void setup_vao() override
|
|
|
|
{
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_vertex_vbo);
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
// TODO: Figure out how to do this without offsetof :(
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, position));
|
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)offsetof(VertexType, uv));
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, TextureRenderable<VertexType, IndexType> >::m_element_buffers[0]);
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
glEnableVertexAttribArray(3);
|
|
|
|
glEnableVertexAttribArray(4);
|
|
|
|
glEnableVertexAttribArray(5);
|
|
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(0 * sizeof(vec4)));
|
|
|
|
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(1 * sizeof(vec4)));
|
|
|
|
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(2 * sizeof(vec4)));
|
|
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable2D), (void*)(3 * sizeof(vec4)));
|
|
|
|
|
|
|
|
glVertexAttribDivisor(0, 0); // Send the mesh data once
|
|
|
|
glVertexAttribDivisor(1, 0); // Send the mesh data once
|
|
|
|
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
|
|
|
|
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
|
|
|
|
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
|
|
|
|
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
|
|
|
|
}
|
2018-10-08 19:19:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|