Browse Source

Saving vertex attribute parameters only if not using VAOs.

Same reasoning as in previous commit.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
dfb9491433
  1. 14
      src/Mesh.cpp
  2. 18
      src/Mesh.h

14
src/Mesh.cpp

@ -113,8 +113,6 @@ void Mesh::bindVAO(GLuint vao) {
} }
void Mesh::bind() { void Mesh::bind() {
CORRADE_ASSERT((_vertexCount != 0) || !attributes.empty(), "Mesh: attributes are bound but vertex count is zero", );
(this->*bindImplementation)(); (this->*bindImplementation)();
} }
@ -187,7 +185,9 @@ void Mesh::destroyImplementationVAO() {
#endif #endif
} }
void Mesh::attributePointerImplementationDefault(const Attribute&) {} void Mesh::attributePointerImplementationDefault(const Attribute& attribute) {
attributes.push_back(attribute);
}
void Mesh::attributePointerImplementationVAO(const Attribute& attribute) { void Mesh::attributePointerImplementationVAO(const Attribute& attribute) {
bindVAO(vao); bindVAO(vao);
@ -202,7 +202,9 @@ void Mesh::attributePointerImplementationDSA(const Attribute& attribute) {
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
void Mesh::attributePointerImplementationDefault(const IntegerAttribute&) {} void Mesh::attributePointerImplementationDefault(const IntegerAttribute& attribute) {
integerAttributes.push_back(attribute);
}
void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) { void Mesh::attributePointerImplementationVAO(const IntegerAttribute& attribute) {
bindVAO(vao); bindVAO(vao);
@ -217,7 +219,9 @@ void Mesh::attributePointerImplementationDSA(const IntegerAttribute& attribute)
#endif #endif
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
void Mesh::attributePointerImplementationDefault(const LongAttribute&) {} void Mesh::attributePointerImplementationDefault(const LongAttribute& attribute) {
longAttributes.push_back(attribute);
}
void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) { void Mesh::attributePointerImplementationVAO(const LongAttribute& attribute) {
bindVAO(vao); bindVAO(vao);

18
src/Mesh.h

@ -678,8 +678,8 @@ class MAGNUM_EXPORT Mesh {
inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {} inline void addInterleavedVertexBufferInternal(Buffer*, GLsizei, GLintptr) {}
template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::AttributeTraits<T>::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::AttributeTraits<T>::AttributeType, GLfloat>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
for(GLuint i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i) { for(GLuint i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i)
attributes.push_back({ (this->*attributePointerImplementation)(Attribute{
buffer, buffer,
location+i, location+i,
Implementation::Attribute<T>::components(attribute.dataOptions()), Implementation::Attribute<T>::components(attribute.dataOptions()),
@ -688,14 +688,11 @@ class MAGNUM_EXPORT Mesh {
offset, offset,
stride stride
}); });
(this->*attributePointerImplementation)(attributes.back());
}
} }
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_integral<typename Implementation::AttributeTraits<T>::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_integral<typename Implementation::AttributeTraits<T>::AttributeType>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
integerAttributes.push_back({ (this->*attributeIPointerImplementation)(IntegerAttribute{
buffer, buffer,
location, location,
Implementation::Attribute<T>::components(), Implementation::Attribute<T>::components(),
@ -703,14 +700,12 @@ class MAGNUM_EXPORT Mesh {
offset, offset,
stride stride
}); });
(this->*attributeIPointerImplementation)(integerAttributes.back());
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::AttributeTraits<T>::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<GLuint location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::AttributeTraits<T>::AttributeType, GLdouble>::value, Buffer*>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
for(GLuint i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i) { for(GLuint i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i)
longAttributes.push_back({ (this->*attributeLPointerImplementation)(LongAttribute{
buffer, buffer,
location+i, location+i,
Implementation::Attribute<T>::components(), Implementation::Attribute<T>::components(),
@ -718,9 +713,6 @@ class MAGNUM_EXPORT Mesh {
offset, offset,
stride stride
}); });
(this->*attributeLPointerImplementation)(longAttributes.back());
}
} }
#endif #endif
#endif #endif

Loading…
Cancel
Save