Commit b67e001b authored by Robert Menzel's avatar Robert Menzel
Browse files

added 1D texture support and fixed memory access errors

parent e56585ad
......@@ -110,7 +110,7 @@ public:
public:
//! elements is the number of vertices (unless this AB should get interpreted in a strange way):
inline GLsizei getElements (void) const { return (GLsizei) (mSize/mStride); }
inline GLsizei getElements (void) const { return (GLsizei) (mStride==0?0:(mSize/mStride)); }
//! size in bytes of all attributes that make up one element (vertex):
inline GLsizei getStride (void) const { return mStride; }
......
......@@ -40,8 +40,8 @@ public:
: mObjectName(0),
mTarget(_target),
mWidth(0),
mHeight(0),
mDepth(0),
mHeight(1),
mDepth(1),
mInternalFormat(GL_RGBA),
mFormat(GL_RGBA),
mType(GL_UNSIGNED_BYTE),
......@@ -133,41 +133,30 @@ public:
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(const GLvoid* _pData = NULL)
{
if(mWidth > 0 && mHeight > 0 && mDepth > 0)
if (mWidth > 1 && mHeight > 1 && mDepth > 1)
{
//3D
//setImageData3D(_pData);
}
else if(mWidth > 0 && mHeight > 0)
else if (mWidth > 1 && mHeight > 1)
{
setImageData2D(_pData);
}
else if(mWidth > 0)
else
{
//1D
setImageData1D(mTarget, mFormat, mType, _pData);
}
}
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(
const GLvoid* _pData,
GLsizei _width,
GLsizei _height,
GLsizei _depth)
GLsizei _height = 1,
GLsizei _depth = 1 )
{
mWidth = _width;
mWidth = _width;
mHeight = _height;
mDepth = _depth;
if(mWidth > 0 && mHeight > 0 && mDepth > 0)
{
//3D
}
else if(mWidth > 0 && mHeight > 0)
{
setImageData2D(_pData);
}
else if(mWidth > 0)
{
//1D
}
mDepth = _depth;
setImageData( _pData );
}
//! Set texture data for 1D, 2D or 3D textures
......@@ -180,24 +169,13 @@ public:
GLenum _format,
GLenum _type)
{
mWidth = _width;
mWidth = _width;
mHeight = _height;
mDepth = _depth;
mDepth = _depth;
mInternalFormat = _internalFormat;
mFormat = _format;
mType = _type;
if(mWidth > 0 && mHeight > 0 && mDepth > 0)
{
//3D
}
else if(mWidth > 0 && mHeight > 0)
{
setImageData2D(_pData);
}
else if(mWidth > 0)
{
//1D
}
mType = _type;
setImageData( _pData );
}
//! Set texture data
......@@ -391,7 +369,28 @@ private:
_uploadType,
_pData);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
ACGL::Utils::error() << "could not generate 2D texture!" << std::endl;
}
}
//! Set texture data
inline void setImageData1D(GLenum _uploadTarget, GLenum _uploadFormat, GLenum _uploadType, const GLvoid* _pData = NULL)
{
openGLCriticalErrorOccured();
glBindTexture(mTarget, mObjectName);
openGLCriticalErrorOccured();
glTexImage1D(
_uploadTarget,
0,
mInternalFormat,
mWidth,
0,//no border
_uploadFormat,
_uploadType,
_pData);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate 1D texture!" << std::endl;
}
}
......
......@@ -235,7 +235,10 @@ public:
} DrawArraysIndirectCommand;
//! returns the number of vertices in one of the array buffers. NOTE: only useful if all array buffer have the same number of elements!
inline GLsizei getArrayVertexCount() const { return mAttributes[getFirstAttributeIndex()].arrayBuffer->getElements(); }
inline GLsizei getArrayVertexCount() const {
int firstAttribute = getFirstAttributeIndex(); // will be -1 if no attribte is set.
return ( (firstAttribute == -1)?0:mAttributes[firstAttribute].arrayBuffer->getElements());
}
//! draws the whole VAO
inline void drawArrays(void) const {
......
......@@ -104,21 +104,6 @@ void VertexArrayObject::detachAttribute( GLuint _location )
mAttributes[_location].arrayBuffer = SharedArrayBuffer();
glDisableVertexAttribArray( _location );
restoreOldVAO();
/*
for (AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
{
if (mAttributes[i].location == _location)
{
// the other pointer data is still set, but that isn't relevant if the attribute itself is deactivated
glDisableVertexArrayAttribEXT( mObjectName, mAttributes[i].location );
mAttributes.erase( mAttributes.begin()+i );
return;
}
}
// if we got here, no Attribute of the given name exists
ACGL::Utils::warning() << "can't detach attribute with location " << _location << " - no such Attribute" << std::endl;
*/
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment