charcoal/CharcoalBuiltin/PoseableBatch.h

53 lines
1.8 KiB
C
Raw Normal View History

2018-09-14 22:09:43 +00:00
#pragma once
#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
{
// Note: If anything is changed in this file, it must also be changed in Poseable2DBatch
2018-09-19 07:52:42 +00:00
template <typename VertexType, typename IndexType, typename RenderableT = RenderableT<VertexType, IndexType> >
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-09-19 07:52:42 +00:00
) : builtin::Batch<VertexType, IndexType, 1, RenderableT>(renderable, element_render_count), m_pose_elements(element_count)
2018-09-14 22:09:43 +00:00
{}
virtual ~PoseableBatch() {}
Poseable& get_pose(int index) { return m_pose_elements[index]; }
const Poseable& get_pose(int index) const { return m_pose_elements[index]; }
protected:
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-09-14 22:09:43 +00:00
glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW);
}
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-09-14 22:09:43 +00:00
glBufferData(GL_ARRAY_BUFFER, m_pose_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, m_pose_elements.size() * sizeof(Poseable), m_pose_elements.data());
}
std::vector<Poseable> m_pose_elements;
};
}
}