Make VertexAttributePointer store index instead of buffer pointer
This commit is contained in:
parent
3048d524b7
commit
ea632614b0
@ -25,7 +25,11 @@ struct VertexAttribute {
|
||||
VertexAttributeLayout layout;
|
||||
};
|
||||
|
||||
struct VertexAttributePointer;
|
||||
struct VertexAttributePointer {
|
||||
VertexAttribute attribute;
|
||||
GLuint buffer;
|
||||
GLuint index;
|
||||
};
|
||||
|
||||
static bool isIndexInVertexAttribute(int i, const VertexAttribute& va) {
|
||||
if ((i -= va.layout.offset) < 0) { return false; }
|
||||
@ -85,12 +89,6 @@ class VertexBuffer<true>
|
||||
|
||||
};
|
||||
|
||||
struct VertexAttributePointer {
|
||||
VertexAttribute attribute;
|
||||
VertexBuffer<false>* buffer;
|
||||
GLuint index;
|
||||
};
|
||||
|
||||
class VAO : public OpenGLObject {
|
||||
using Base = OpenGLObject;
|
||||
using Codes = VAOError::Codes;
|
||||
|
||||
@ -38,7 +38,7 @@ VertexAttributePointerList VAO::attributes(const VertexAttributePointerList& att
|
||||
_attrs = attrs_;
|
||||
bind();
|
||||
for (auto attr_ptr : attrs_) {
|
||||
attr_ptr.buffer->bind();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, attr_ptr.buffer);
|
||||
GLuint idx = attr_ptr.index;
|
||||
glVertexAttribPointer(
|
||||
idx,
|
||||
@ -124,7 +124,7 @@ size_t VertexGroup::buffer(VertexBuffer<false>&& buf_) {
|
||||
GLuint idx = attrs.size();
|
||||
for (auto attr : buf_ptr->attributes) {
|
||||
attrs.emplace_back(
|
||||
VertexAttributePointer{attr, buf_ptr,idx}
|
||||
VertexAttributePointer{attr, buf_ptr->id(),idx}
|
||||
);
|
||||
idx++;
|
||||
}
|
||||
@ -152,7 +152,7 @@ size_t VertexGroup::buffers(std::vector<VertexBuffer<false>>&& bufs_) {
|
||||
for (auto buf : _vertex_data) {
|
||||
for (auto attr : buf->attributes) {
|
||||
attr_ptrs.emplace_back(
|
||||
VertexAttributePointer{attr, buf.get(), idx}
|
||||
VertexAttributePointer{attr, buf->id(), idx}
|
||||
);
|
||||
idx++;
|
||||
}
|
||||
@ -197,10 +197,10 @@ void VertexGroup::disableAttr(GLuint idx) {
|
||||
}
|
||||
|
||||
void VertexGroup::disableBuffer(size_t idx) {
|
||||
auto buf_ptr = _vertex_data[idx].get();
|
||||
auto buf_idx = _vertex_data[idx]->id();
|
||||
bind();
|
||||
for (auto attr : _vao.attributes()) {
|
||||
if (attr.buffer == buf_ptr) {
|
||||
if (attr.buffer == buf_idx) {
|
||||
_vao.disable(attr.index);
|
||||
}
|
||||
}
|
||||
@ -208,10 +208,10 @@ void VertexGroup::disableBuffer(size_t idx) {
|
||||
}
|
||||
|
||||
void VertexGroup::enableBuffer(size_t idx) {
|
||||
auto buf_ptr = _vertex_data[idx].get();
|
||||
auto buf_idx = _vertex_data[idx]->id();
|
||||
bind();
|
||||
for (auto attr : _vao.attributes()) {
|
||||
if (attr.buffer == buf_ptr) {
|
||||
if (attr.buffer == buf_idx) {
|
||||
_vao.enable(attr.index);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user