2018-09-14 22:09:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-11 05:26:24 +00:00
|
|
|
#include <charcoal/Batch.h>
|
|
|
|
#include <charcoal/Renderable.h>
|
|
|
|
#include <charcoal/Poseable.h>
|
2018-09-14 22:09:43 +00:00
|
|
|
#include "BuiltinBatch.h"
|
|
|
|
|
|
|
|
namespace charcoal
|
|
|
|
{
|
|
|
|
namespace builtin
|
|
|
|
{
|
2018-10-09 15:42:17 +00:00
|
|
|
// Note: If anything is changed in this file, it must also be changed in Poseable2DBatch
|
2018-10-14 04:52:32 +00:00
|
|
|
template <typename VertexType, typename IndexType, int orientation_attrib_offset, typename RenderableT = RenderableT<VertexType, IndexType> >
|
2018-09-19 07:52:42 +00:00
|
|
|
class PoseableBatch : public builtin::Batch<VertexType, IndexType, 1, RenderableT>
|
2018-09-14 22:09:43 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PoseableBatch(
|
2018-09-19 07:52:42 +00:00
|
|
|
RenderableT* renderable,
|
2018-09-14 22:09:43 +00:00
|
|
|
int element_count
|
|
|
|
) : PoseableBatch(renderable, element_count, element_count)
|
|
|
|
{}
|
|
|
|
|
|
|
|
PoseableBatch(
|
2018-09-19 07:52:42 +00:00
|
|
|
RenderableT* renderable,
|
2018-09-14 22:09:43 +00:00
|
|
|
int element_count,
|
|
|
|
int element_render_count
|
2018-10-14 04:52:32 +00:00
|
|
|
) : builtin::Batch<VertexType, IndexType, 1, RenderableT>(renderable, element_render_count), m_orientation_elements(element_count)
|
2018-09-14 22:09:43 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~PoseableBatch() {}
|
|
|
|
|
2018-10-14 04:52:32 +00:00
|
|
|
void reset_rendered() { charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_render_count = 0; }
|
|
|
|
|
|
|
|
void add_rendered(const Poseable& poseable) { m_orientation_elements[charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_render_count++] = poseable.get_orientation_matrix(); }
|
2018-09-14 22:09:43 +00:00
|
|
|
|
|
|
|
protected:
|
2018-09-15 01:29:05 +00:00
|
|
|
void setup_element_buffers()
|
2018-09-14 22:09:43 +00:00
|
|
|
{
|
2018-09-19 07:52:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
|
2018-10-14 04:52:32 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW);
|
2018-09-14 22:09:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 01:29:05 +00:00
|
|
|
void update_element_buffers()
|
2018-09-14 22:09:43 +00:00
|
|
|
{
|
|
|
|
// TODO: There are probably better ways to do this. Should check with the old engine to see what I did there.
|
2018-09-19 07:52:42 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
|
2018-10-14 04:52:32 +00:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_orientation_elements.size() * sizeof(mat4), NULL, GL_STREAM_DRAW);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, m_orientation_elements.size() * sizeof(mat4), m_orientation_elements.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void setup_vao_vertex() = 0;
|
|
|
|
|
|
|
|
void setup_vao() override
|
|
|
|
{
|
|
|
|
setup_vao_vertex();
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch<VertexType, IndexType, 1, RenderableT>::m_element_buffers[0]);
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(orientation_attrib_offset + 0);
|
|
|
|
glEnableVertexAttribArray(orientation_attrib_offset + 1);
|
|
|
|
glEnableVertexAttribArray(orientation_attrib_offset + 2);
|
|
|
|
glEnableVertexAttribArray(orientation_attrib_offset + 3);
|
|
|
|
|
|
|
|
glVertexAttribPointer(orientation_attrib_offset + 0, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(0 * sizeof(mat4::col_type)));
|
|
|
|
glVertexAttribPointer(orientation_attrib_offset + 1, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(1 * sizeof(mat4::col_type)));
|
|
|
|
glVertexAttribPointer(orientation_attrib_offset + 2, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(2 * sizeof(mat4::col_type)));
|
|
|
|
glVertexAttribPointer(orientation_attrib_offset + 3, 4, GL_FLOAT, GL_FALSE, sizeof(mat4), (void*)(3 * sizeof(mat4::col_type)));
|
|
|
|
|
|
|
|
glVertexAttribDivisor(orientation_attrib_offset + 0, 1); // Send the orientation data for each instance drawn
|
|
|
|
glVertexAttribDivisor(orientation_attrib_offset + 1, 1); // Send the orientation data for each instance drawn
|
|
|
|
glVertexAttribDivisor(orientation_attrib_offset + 2, 1); // Send the orientation data for each instance drawn
|
|
|
|
glVertexAttribDivisor(orientation_attrib_offset + 3, 1); // Send the orientation data for each instance drawn
|
2018-09-14 22:09:43 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 04:52:32 +00:00
|
|
|
std::vector<mat4> m_orientation_elements;
|
2018-09-14 22:09:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|