Commit 19cf2b44 authored by Lars Krecklau's avatar Lars Krecklau
Browse files

- Sorry for the last commit! My mistake. Here come the updated files.

- Furthermore, I have added support for normalized attribute values.
parent fe386c95
......@@ -8,14 +8,14 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class ArrayBufferControl : public Resource::BasicController<ArrayBuffer>
class ArrayBufferControl : public Resource::BasicCreateController<ArrayBuffer>
{
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
......@@ -24,8 +24,9 @@ public:
struct AttributeDefine
{
std::string name;
GLenum type;
GLint dimension;
GLenum type;
GLint dimension;
GLboolean normalized;
};
// ===================================================================================================== \/
......@@ -61,9 +62,9 @@ public:
return *this;
}
inline ArrayBufferControl& attribute (const std::string& _name, GLenum _type, GLint _dimension)
inline ArrayBufferControl& attribute (const std::string& _name, GLenum _type, GLint _dimension, GLboolean _normalized = GL_FALSE)
{
AttributeDefine a = {_name, _type, _dimension};
AttributeDefine a = {_name, _type, _dimension, _normalized};
mAttributeDefines.push_back(a);
return *this;
}
......
......@@ -8,14 +8,14 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/ElementArrayBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class ElementArrayBufferControl : public Resource::BasicController<ElementArrayBuffer>
class ElementArrayBufferControl : public Resource::BasicCreateController<ElementArrayBuffer>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
......
......@@ -8,7 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/FrameBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
......@@ -18,14 +18,14 @@
namespace ACGL{
namespace OpenGL{
class FrameBufferControl : public Resource::BasicController<FrameBuffer>
class FrameBufferControl : public Resource::BasicCreateController<FrameBuffer>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
FrameBufferControl(void) :
mWidth(0),
FrameBufferControl(void)
: mWidth(0),
mHeight(0),
mColorAttachments(),
mDepthAttachment()
......
......@@ -8,21 +8,21 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/RenderBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class RenderBufferControl : public Resource::BasicController<RenderBuffer>
class RenderBufferControl : public Resource::BasicCreateController<RenderBuffer>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
RenderBufferControl(void) :
mWidth(0),
RenderBufferControl(void)
: mWidth(0),
mHeight(0),
mInternalFormat()
{}
......
......@@ -8,22 +8,22 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/Resource/BasicUpdateController.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class TextureControl : public Resource::BasicController<Texture>
class TextureControl : public Resource::BasicCreateController<Texture>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureControl(void)
: Resource::BasicController<Texture>(),
mWidth(0),
: mWidth(0),
mHeight(0),
mDepth(0),
mInternalFormat(GL_RGBA),
......@@ -60,15 +60,18 @@ public:
public:
virtual SharedTexture create(void)
{
SharedTexture texture(new Texture(
SharedTexture texture(new Texture(mTarget));
texture->bind();
if(mMinFilter > 0) texture->setMinFilter(mMinFilter);
if(mMagFilter > 0) texture->setMagFilter(mMagFilter);
texture->setImageData(
NULL,
mWidth,
mHeight,
mDepth,
mInternalFormat,
mTarget,
mFormat,
mType));
texture->bind();
texture->setParameter(GL_TEXTURE_MIN_FILTER, mMinFilter == 0 ? GL_NEAREST : mMinFilter);
texture->setParameter(GL_TEXTURE_MAG_FILTER, mMagFilter == 0 ? GL_NEAREST : mMagFilter);
texture->setSize(mWidth, mHeight, mDepth);
mType);
return texture;
}
......
......@@ -8,14 +8,14 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/VertexBuffer.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class VertexBufferControl : public Resource::BasicController<VertexBuffer>
class VertexBufferControl : public Resource::BasicCreateController<VertexBuffer>
{
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
......@@ -39,7 +39,7 @@ public:
// ========================================================================================================= \/
public:
VertexBufferControl(void)
: Resource::BasicController<VertexBuffer>(),
: Resource::BasicCreateController<VertexBuffer>(),
mpElementArrayBuffer(),
mArrayBuffers(),
mAttributeDefines()
......
......@@ -31,9 +31,10 @@ public:
struct Attribute
{
std::string name;
GLenum type;
GLint dimension;
GLint offset;
GLenum type;
GLint dimension;
GLint offset;
GLboolean normalized;
};
// ===================================================================================================== \/
......@@ -78,13 +79,6 @@ public:
inline GLsizei getElements (void) const { return mElements; }
inline GLsizei getStride (void) const { return mStride; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
// ==================================================================================================== \/
// ============================================================================================ SETTERS \/
// ==================================================================================================== \/
public:
inline void setUsage (GLenum _usage) { mUsage = _usage; }
inline void setMode (GLenum _mode) { mMode = _mode; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
......@@ -95,13 +89,15 @@ public:
inline void attachAttribute(
const std::string& _name,
GLenum _type,
GLint _dimension)
GLint _dimension,
GLboolean _normalized = GL_FALSE)
{
Attribute attribute = {
_name,
_type,
_dimension,
mStride};
mStride,
_normalized};
mStride += getGLTypeSize(_type) * _dimension;
mAttributes.push_back(attribute);
}
......@@ -123,6 +119,11 @@ public:
glDrawArrays(mMode, 0, mElements);
}
void draw(GLint _first, GLsizei _count) const
{
glDrawArrays(mMode, _first, _count);
}
//! Bind this buffer
inline void bind(void) const
{
......@@ -135,7 +136,7 @@ public:
_indexInShader,
mAttributes[_indexInArray].dimension,
mAttributes[_indexInArray].type,
GL_FALSE,
mAttributes[_indexInArray].normalized,
mStride,
reinterpret_cast<GLvoid*>(mAttributes[_indexInArray].offset));
}
......@@ -163,9 +164,29 @@ public:
}
//! Set data for this buffer and change its size
inline void setData(const GLvoid* _pData, GLsizei _elements)
inline void setData(
const GLvoid* _pData,
GLsizei _elements)
{
mElements = _elements;
glBindBuffer(GL_ARRAY_BUFFER, mContext);
glBufferData(
GL_ARRAY_BUFFER,
mStride * mElements,
_pData,
mUsage);
}
//! Set data for this buffer and change its size
inline void setData(
const GLvoid* _pData,
GLsizei _elements,
GLenum _usage,
GLenum _mode)
{
mElements = _elements;
mUsage = _usage;
mMode = _mode;
glBindBuffer(GL_ARRAY_BUFFER, mContext);
glBufferData(
GL_ARRAY_BUFFER,
......
......@@ -27,19 +27,21 @@ class Texture
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
Texture(
GLenum _internalFormat = GL_RGBA,
GLenum _target = GL_TEXTURE_2D,
GLenum _format = GL_RGBA,
GLenum _type = GL_UNSIGNED_BYTE)
//!
/*!
Default texture parameters taken from: http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml
*/
Texture(GLenum _target)
: mContext(0),
mTarget(_target),
mWidth(0),
mHeight(0),
mDepth(0),
mInternalFormat(_internalFormat),
mTarget(_target),
mFormat(_format),
mType(_type)
mInternalFormat(GL_RGBA),
mFormat(GL_RGBA),
mType(GL_UNSIGNED_BYTE),
mMinFilter(GL_NEAREST_MIPMAP_LINEAR),
mMagFilter(GL_LINEAR)
{
glGenTextures(1, &mContext);
if (openGLCriticalErrorOccured() ) {
......@@ -58,22 +60,15 @@ public:
// ==================================================================================================== \/
public:
inline GLuint getContext (void) const { return mContext; }
inline GLenum getTarget (void) const { return mTarget; }
inline GLsizei getWidth (void) const { return mWidth; }
inline GLsizei getHeight (void) const { return mHeight; }
inline GLsizei getDepth (void) const { return mDepth; }
inline GLenum getInternalFormat (void) const { return mInternalFormat; }
inline GLenum getTarget (void) const { return mTarget; }
inline GLenum getFormat (void) const { return mFormat; }
inline GLenum getType (void) const { return mType; }
// ==================================================================================================== \/
// ============================================================================================ SETTERS \/
// ==================================================================================================== \/
public:
inline void setInternalFormat (GLenum _internalFormat) { mInternalFormat = _internalFormat; }
inline void setTarget (GLenum _target) { mTarget = _target; }
inline void setFormat (GLenum _format) { mFormat = _format; }
inline void setType (GLenum _type) { mType = _type; }
inline GLint getMinFilter (void) const { return mMinFilter; }
inline GLint getMagFilter (void) const { return mMagFilter; }
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
......@@ -95,26 +90,45 @@ public:
}
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setParameter(GLenum _parameter, GLint _value)
inline void setMinFilter(GLint _value)
{
mMinFilter = _value;
glBindTexture(mTarget, mContext);
glTexParameteri(mTarget, _parameter, _value);
glTexParameteri(mTarget, GL_TEXTURE_MIN_FILTER, mMinFilter);
openGLRareError();
}
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setParameter(GLenum _parameter, GLfloat _value)
inline void setMagFilter(GLint _value)
{
mMagFilter = _value;
glBindTexture(mTarget, mContext);
glTexParameterf(mTarget, _parameter, _value);
glTexParameteri(mTarget, GL_TEXTURE_MAG_FILTER, mMagFilter);
openGLRareError();
}
//! Set texture size for 1D, 2D or 3D textures and NULL data
inline void setSize(
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(const GLvoid* _pData = NULL)
{
if(mWidth > 0 && mHeight > 0 && mDepth > 0)
{
//3D
}
else if(mWidth > 0 && mHeight > 0)
{
setImageData2D(_pData);
}
else if(mWidth > 0)
{
//1D
}
}
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(
const GLvoid* _pData,
GLsizei _width,
GLsizei _height = 0,
GLsizei _depth = 0)
GLsizei _height,
GLsizei _depth)
{
mWidth = _width;
mHeight = _height;
......@@ -125,7 +139,7 @@ public:
}
else if(mWidth > 0 && mHeight > 0)
{
setSize2D(mWidth, mHeight);
setImageData2D(_pData);
}
else if(mWidth > 0)
{
......@@ -133,13 +147,39 @@ public:
}
}
//! Set texture size and NULL data
inline void setSize2D(
//! Set texture data for 1D, 2D or 3D textures
inline void setImageData(
const GLvoid* _pData,
GLsizei _width,
GLsizei _height)
GLsizei _height,
GLsizei _depth,
GLenum _internalFormat,
GLenum _format,
GLenum _type)
{
mWidth = _width;
mHeight = _height;
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
}
}
//! Set texture data
inline void setImageData2D(const GLvoid* _pData = NULL)
{
glBindTexture(mTarget, mContext);
glTexImage2D(
mTarget,
......@@ -150,14 +190,17 @@ public:
0,//no border
mFormat,
mType,
NULL);
_pData);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!d" << std::endl;
}
}
//! Set texture data
inline void setImage2D(
GLsizei _width,
GLsizei _height,
const GLvoid* _pData)
inline void setImageData2D(
const GLvoid* _pData,
GLsizei _width,
GLsizei _height)
{
mWidth = _width;
mHeight = _height;
......@@ -175,10 +218,19 @@ public:
}
//! Set texture data
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setImage2D(
const GLvoid* _pData)
inline void setImageData2D(
const GLvoid* _pData,
GLsizei _width,
GLsizei _height,
GLenum _internalFormat,
GLenum _format,
GLenum _type)
{
mWidth = _width;
mHeight = _height;
mInternalFormat = _internalFormat;
mFormat = _format;
mType = _type;
glBindTexture(mTarget, mContext);
glTexImage2D(
mTarget,
......@@ -198,17 +250,19 @@ public:
its size calculating (w,h)/2^level where w and h are the width and height of the base texture.
Note: The function is not const, because it changes the corresponding GPU data
*/
inline void setImage2D(
inline void setImageDataMipMap2D(
const GLvoid* _pData,
GLint _mipmapLevel)
GLint _mipmapLevel,
GLsizei _width = 0,
GLsizei _height = 0)
{
glBindTexture(mTarget, mContext);
glTexImage2D(
mTarget,
_mipmapLevel,
mInternalFormat,
mWidth / GLsizei(Math::Functions::pow(2.0f, float(_mipmapLevel))),
mHeight / GLsizei(Math::Functions::pow(2.0f, float(_mipmapLevel))),
_width > 0 ? _width : mWidth / GLsizei(Math::Functions::pow(2.0f, float(_mipmapLevel))),
_height > 0 ? _height : mHeight / GLsizei(Math::Functions::pow(2.0f, float(_mipmapLevel))),
0,//no border
mFormat,
mType,
......@@ -217,7 +271,7 @@ public:
//! Set data for specific area within the 2D texture
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setSubImage2D(
inline void setSubImageData2D(
const GLvoid* _pData,
int _x,
int _y,
......@@ -239,7 +293,7 @@ public:
//! Set data for specific area within the 3D texture
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setSubImage3D(
inline void setSubImageData3D(
const GLvoid* _pData,
int _x,
int _y,
......@@ -278,13 +332,15 @@ public:
// =================================================================================================== \/
private:
GLuint mContext;
GLenum mTarget;
GLsizei mWidth;
GLsizei mHeight;
GLsizei mDepth;
GLenum mInternalFormat;
GLenum mTarget;
GLenum mFormat;
GLenum mType;
GLint mMinFilter;
GLint mMagFilter;
};
ACGL_SHARED_TYPEDEF(Texture)
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_RESOURCE_BASICCONTROLLER_HH
#define ACGL_RESOURCE_BASICCONTROLLER_HH
/*
* Base class for all controllers.
*
* Controllers can provide more flexible ways of creating objects, they are also
* making managers more flexibe.
*/
#include <tr1/memory>
#include <ACGL/ACGL.hh>
namespace ACGL{
namespace Resource{
template<typename RESOURCE>
class BasicController
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
BasicController(){}
virtual ~BasicController(){}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
virtual std::tr1::shared_ptr<RESOURCE> create(void) = 0;
};
} // Resource
} // ACGL
#endif // ACGL_RESOURCE_BASICCONTROLLER_HH
......@@ -8,7 +8,8 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicController.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/Resource/BasicUpdateController.hh>
#include <ACGL/Base/FileHelpers.hh>
#include <string>
......@@ -17,15 +18,14 @@ namespace ACGL{
namespace Resource{