Browse Source

Removed unbind() from buffers and textures.

It doesn't help with any safety, but just complicates everything and
makes unnecessary GL calls.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
70fa53b949
  1. 2
      src/AbstractTexture.cpp
  2. 13
      src/AbstractTexture.h
  3. 6
      src/Buffer.h
  4. 2
      src/CubeMapTexture.h
  5. 4
      src/IndexedMesh.cpp
  6. 3
      src/Mesh.cpp
  7. 1
      src/Texture.cpp
  8. 4
      src/Texture.h

2
src/AbstractTexture.cpp

@ -53,7 +53,6 @@ void AbstractTexture::setMinificationFilter(Filter filter, Mipmap mipmap) {
bind();
glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
static_cast<GLint>(filter)|static_cast<GLint>(mipmap));
unbind();
}
void AbstractTexture::generateMipmap() {
@ -61,7 +60,6 @@ void AbstractTexture::generateMipmap() {
bind();
glGenerateMipmap(target);
unbind();
}
}

13
src/AbstractTexture.h

@ -147,17 +147,6 @@ class MAGNUM_EXPORT AbstractTexture {
glBindTexture(target, texture);
}
/**
* @brief Unbind texture
*
* @note Unbinds any texture from given dimension, not only this
* particular one.
*/
inline void unbind() const {
glActiveTexture(GL_TEXTURE0 + _layer);
glBindTexture(target, 0);
}
/**
* @brief Set minification filter
* @param filter Filter
@ -187,7 +176,6 @@ class MAGNUM_EXPORT AbstractTexture {
inline void setMagnificationFilter(Filter filter) {
bind();
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, static_cast<GLint>(filter));
unbind();
}
/**
@ -199,7 +187,6 @@ class MAGNUM_EXPORT AbstractTexture {
inline void setBorderColor(const Vector4& color) {
bind();
glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color.data());
unbind();
}
/**

6
src/Buffer.h

@ -128,11 +128,6 @@ class Buffer {
glBindBuffer(_type, buffer);
}
/** @brief Unbind buffer */
inline void unbind() const {
glBindBuffer(_type, 0);
}
/**
* @brief Set buffer data
* @param size Data size
@ -142,7 +137,6 @@ class Buffer {
inline void setData(GLsizeiptr size, const GLvoid* data, Usage usage) {
bind();
glBufferData(_type, size, data, usage);
unbind();
}
private:

2
src/CubeMapTexture.h

@ -286,13 +286,11 @@ class CubeMapTexture: public Texture2D {
void setData(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<GLsizei, Dimensions>& _dimensions, ColorFormat colorFormat, GLenum type, const void* data) {
bind();
DataHelper<Dimensions>::set(target, mipLevel, internalFormat, _dimensions, colorFormat, type, data);
unbind();
}
void setSubData(GLenum target, GLint mipLevel, const Math::Vector<GLint, Dimensions>& offset, const Math::Vector<GLsizei, Dimensions>& dimensions, ColorFormat colorFormat, GLenum type, const void* data) {
bind();
DataHelper<Dimensions>::setSub(target, mipLevel, offset, dimensions, colorFormat, type, data);
unbind();
}
};

4
src/IndexedMesh.cpp

@ -46,15 +46,11 @@ void IndexedMesh::draw() {
default:
glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer);
}
/* Unbind buffer */
it->first->unbind();
}
/* Bind index array, draw the elements and unbind */
_indexBuffer.bind();
glDrawElements(primitive(), _indexCount, _indexType, nullptr);
_indexBuffer.unbind();
/* Disable vertex arrays for all attributes */
for(set<GLuint>::const_iterator it = attributes().begin(); it != attributes().end(); ++it)

3
src/Mesh.cpp

@ -64,9 +64,6 @@ void Mesh::draw() {
default:
glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer);
}
/* Unbind buffer */
it->first->unbind();
}
glDrawArrays(_primitive, 0, _vertexCount);

1
src/Texture.cpp

@ -36,7 +36,6 @@ template<size_t dimensions> void Texture<dimensions>::setWrapping(const Math::Ve
break;
}
}
unbind();
}
/* Instantiate all textures */

4
src/Texture.h

@ -88,7 +88,6 @@ template<size_t dimensions> class MAGNUM_EXPORT Texture: public AbstractTexture
template<class T> inline void setData(GLint mipLevel, InternalFormat internalFormat, const Math::Vector<GLsizei, Dimensions>& _dimensions, ColorFormat colorFormat, const T* data) {
bind();
DataHelper<Dimensions>::set(target, mipLevel, internalFormat, _dimensions, colorFormat, TypeTraits<typename TypeTraits<T>::TextureType>::glType(), data);
unbind();
}
/**
@ -103,7 +102,6 @@ template<size_t dimensions> class MAGNUM_EXPORT Texture: public AbstractTexture
inline void setData(GLint mipLevel, InternalFormat internalFormat, const Trade::Image<Dimensions>* image) {
bind();
DataHelper<dimensions>::set(target, mipLevel, internalFormat, image->dimensions(), image->colorFormat(), image->type(), image->data());
unbind();
}
/**
@ -121,7 +119,6 @@ template<size_t dimensions> class MAGNUM_EXPORT Texture: public AbstractTexture
template<class T> inline void setSubData(GLint mipLevel, const Math::Vector<GLint, Dimensions>& offset, const Math::Vector<GLsizei, Dimensions>& _dimensions, ColorFormat colorFormat, const T* data) {
bind();
DataHelper<Dimensions>::setSub(target, mipLevel, offset, _dimensions, colorFormat, TypeTraits<typename TypeTraits<T>::TextureType>::glType(), data);
unbind();
}
/**
@ -136,7 +133,6 @@ template<size_t dimensions> class MAGNUM_EXPORT Texture: public AbstractTexture
inline void setSubData(GLint mipLevel, const Math::Vector<GLint, Dimensions>& offset, const Trade::Image<Dimensions>* image) {
bind();
DataHelper<Dimensions>::setSub(target, mipLevel, offset, image->dimensions(), image->colorFormat(), image->type(), image->data());
unbind();
}
};

Loading…
Cancel
Save