way of accessing and binding shared references. normal vbo now returns a shared_ptr which can be used in place of a vbo_t

main
Brett 2024-01-08 21:29:39 -05:00
parent 5bff8b675c
commit 2f9bccc348
2 changed files with 22 additions and 6 deletions

View File

@ -85,9 +85,10 @@ namespace blt::gfx
*/ */
class static_dynamic_array class static_dynamic_array
{ {
public:
using vbo_type = std::shared_ptr<vbo_t_owner>;
private: private:
static constexpr size_t DATA_SIZE = 8; static constexpr size_t DATA_SIZE = 8;
using vbo_type = std::shared_ptr<vbo_t_owner>;
using array_t = std::array<vbo_type, DATA_SIZE>; using array_t = std::array<vbo_type, DATA_SIZE>;
std::variant<array_t, vbo_type*> data_; std::variant<array_t, vbo_type*> data_;
size_t size_ = DATA_SIZE; size_t size_ = DATA_SIZE;
@ -130,6 +131,8 @@ namespace blt::gfx
static_dynamic_array VBOs; static_dynamic_array VBOs;
HASHSET<GLuint> used_attributes; HASHSET<GLuint> used_attributes;
vbo_t element; vbo_t element;
void handle_vbo(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset);
public: public:
vertex_array(); vertex_array();
@ -150,8 +153,10 @@ namespace blt::gfx
* @param stride how many bytes this data takes (for the entire per-vertex data structure) 0 will assume packed data * @param stride how many bytes this data takes (for the entire per-vertex data structure) 0 will assume packed data
* This is in effect how many bytes until the next block of data * This is in effect how many bytes until the next block of data
* @param offset offset into the data structure to where the data is stored * @param offset offset into the data structure to where the data is stored
* @return a shared pointer to the stored vbo. used for chaining VAOs with multiple shared VBOs
*/ */
void bindVBO(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset); static_dynamic_array::vbo_type bindVBO(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset);
void bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset);
inline void bindElement(const vbo_t& vbo) inline void bindElement(const vbo_t& vbo)
{ {

View File

@ -130,7 +130,21 @@ namespace blt::gfx
glDeleteVertexArrays(1, &vaoID); glDeleteVertexArrays(1, &vaoID);
} }
void vertex_array::bindVBO(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset) static_dynamic_array::vbo_type vertex_array::bindVBO(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride,
long offset)
{
handle_vbo(vbo, attribute_number, coordinate_size, type, stride, offset);
VBOs[attribute_number] = std::make_shared<vbo_t_owner>(vbo);
return VBOs[attribute_number];
}
void vertex_array::bindVBO(const static_dynamic_array::vbo_type& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset)
{
handle_vbo(vbo->vbo, attribute_number, coordinate_size, type, stride, offset);
VBOs[attribute_number] = vbo;
}
void vertex_array::handle_vbo(const vbo_t& vbo, int attribute_number, int coordinate_size, GLenum type, int stride, long offset)
{ {
used_attributes.insert(attribute_number); used_attributes.insert(attribute_number);
bind(); bind();
@ -138,9 +152,6 @@ namespace blt::gfx
glVertexAttribPointer(attribute_number, coordinate_size, type, GL_FALSE, stride < 0 ? 0 : stride, (void*) offset); glVertexAttribPointer(attribute_number, coordinate_size, type, GL_FALSE, stride < 0 ? 0 : stride, (void*) offset);
glEnableVertexAttribArray(attribute_number); glEnableVertexAttribArray(attribute_number);
VBOs[attribute_number] = std::make_shared<vbo_t_owner>(vbo);
unbind(); unbind();
} }
} }