Commit 21585e94 authored by Lars Krecklau's avatar Lars Krecklau

Removed static contexts from the opengl object. In future, this has to be...

Removed static contexts from the opengl object. In future, this has to be handled by our opengl wrapper, which will hold a copy of the gl state on cpu side.
Made all opengl contexts not copyable.
Created a macro for the shared typedefs which directly creates a const version of the pointer.
Started to change some opengl object functions to be non-const although they might not change any class members, because the function still might change something on gpu side. Therfore, returning the context of any opengl object is also non-const now!
Changed the renderbuffer constructor to just create the context and moved the rest to its corresponding controller.
Removed own type enums in opengl objects => ONLY use the orginial GLenums here!
parent 9c1591ea
......@@ -7,9 +7,13 @@
#define ACGL_BASE_MACROS_HH
//Macro to make a class not copyable
#define NOT_COPYABLE(Class) private:\
Class(const Class& other){ }\
void operator=(Class& other){ }
#define ACGL_NOT_COPYABLE(Class) \
private:\
Class(const Class& other){ }\
void operator=(Class& other){ }
#define ACGL_SHARED_TYPEDEF(Class) \
typedef std::tr1::shared_ptr<Class> Shared ## Class;
#endif // MACROS_HH
......@@ -40,7 +40,7 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline FrameBufferControl& size (GLsizei _width, GLsizei _height) { mWidth = _width; mHeight = _height; return *this; }
inline FrameBufferControl& size (GLsizei _width, GLsizei _height) { mWidth = _width; mHeight = _height; return *this; }
inline FrameBufferControl& depthTexture (const SharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferControl& depthRenderBuffer (const SharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; }
......
......@@ -41,10 +41,9 @@ public:
public:
virtual SharedRenderBuffer create(void)
{
return SharedRenderBuffer(new RenderBuffer(
mWidth,
mHeight,
mInternalFormat));
SharedRenderBuffer renderBuffer(new RenderBuffer(mInternalFormat));
renderBuffer->setSize(mWidth, mHeight);
return renderBuffer;
}
// =================================================================================================== \/
......
......@@ -24,7 +24,7 @@ class ShaderControlFile : public Resource::FileController<Shader>
public:
ShaderControlFile(const std::string& _filename)
: Resource::FileController<Shader>(_filename, Base::Settings::the()->getFullShaderPath()),
mType(Shader::ShaderTypeInvalid)
mType(GL_INVALID_ENUM)
{}
virtual ~ShaderControlFile(void) {}
......
......@@ -68,7 +68,7 @@ public:
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->setRenderTarget(mWidth, mHeight, mDepth);
texture->setSize(mWidth, mHeight, mDepth);
return texture;
}
......
......@@ -8,6 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
......@@ -20,11 +21,7 @@ namespace OpenGL{
class ArrayBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sArrayBufferContext;
ACGL_NOT_COPYABLE(ArrayBuffer)
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
......@@ -75,7 +72,7 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline GLuint getContext (void) const { return mContext; }
inline GLuint getContext (void) { return mContext; }
inline GLenum getUsage (void) const { return mUsage; }
inline GLenum getMode (void) const { return mMode; }
inline GLsizei getElements (void) const { return mElements; }
......@@ -129,11 +126,7 @@ public:
//! Bind this buffer
inline void bind(void) const
{
if(sArrayBufferContext == mContext)
return;
glBindBuffer(GL_ARRAY_BUFFER, mContext);
sArrayBufferContext = mContext;
}
inline void setPointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
......@@ -158,8 +151,10 @@ public:
}
//! Set data for this buffer
inline void setData(const GLvoid* _pData) const
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData(const GLvoid* _pData)
{
glBindBuffer(GL_ARRAY_BUFFER, mContext);
glBufferData(
GL_ARRAY_BUFFER,
mStride * mElements,
......@@ -171,6 +166,7 @@ public:
inline void setData(const GLvoid* _pData, GLsizei _elements)
{
mElements = _elements;
glBindBuffer(GL_ARRAY_BUFFER, mContext);
glBufferData(
GL_ARRAY_BUFFER,
mStride * mElements,
......@@ -190,7 +186,7 @@ protected:
AttributeVec mAttributes;
};
typedef std::tr1::shared_ptr<ArrayBuffer> SharedArrayBuffer;
ACGL_SHARED_TYPEDEF(ArrayBuffer)
} // OpenGL
} // ACGL
......
......@@ -8,6 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
......@@ -18,11 +19,8 @@ namespace OpenGL{
class ElementArrayBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sElementArrayBufferContext;
ACGL_NOT_COPYABLE(ElementArrayBuffer)
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
......@@ -55,7 +53,7 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline GLuint getContext (void) const { return mContext; }
inline GLuint getContext (void) { return mContext; }
inline GLenum getUsage (void) const { return mUsage; }
inline GLenum getMode (void) const { return mMode; }
inline GLsizei getElements (void) const { return mElements; }
......@@ -82,11 +80,7 @@ public:
//! Bind this buffer
inline void bind(void) const
{
if(sElementArrayBufferContext == mContext)
return;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext);
sElementArrayBufferContext = mContext;
}
void draw(void) const
......@@ -95,9 +89,11 @@ public:
}
//! Set data for this buffer
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData(
const GLvoid* _pData)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
mElements * mSizeOfType,
......@@ -111,6 +107,7 @@ public:
GLsizei _elements)
{
mElements = _elements;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mContext);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
mElements * mSizeOfType,
......@@ -130,7 +127,7 @@ protected:
GLint mSizeOfType;
};
typedef std::tr1::shared_ptr<ElementArrayBuffer> SharedElementArrayBuffer;
ACGL_SHARED_TYPEDEF(ElementArrayBuffer)
} // OpenGL
} // ACGL
......
......@@ -24,12 +24,12 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/Base/StringOperations.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Objects/RenderBuffer.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/Base/StringOperations.hh>
#include <tr1/memory>
......@@ -38,11 +38,7 @@ namespace OpenGL{
class FrameBuffer
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sFrameBufferContext;
ACGL_NOT_COPYABLE(FrameBuffer)
// =================================================================================================== \/
// ============================================================================================ STATIC \/
......@@ -62,14 +58,6 @@ public:
SharedRenderBuffer renderBuffer;
};
// Per default an FBO is used for reading (glReadPixels etc) and drawing (glDraw*) but a
// read-only/draw-only setup is also possible.
enum TargetType {
READ_FRAMEBUFFER = GL_READ_FRAMEBUFFER,
DRAW_FRAMEBUFFER = GL_DRAW_FRAMEBUFFER,
READ_DRAW_FRAMEBUFFER = GL_FRAMEBUFFER
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
......@@ -111,7 +99,6 @@ public:
inline GLuint getContext (void) const { return mContext; }
inline GLsizei getWidth (void) const { return mWidth; }
inline GLsizei getHeight (void) const { return mHeight; }
inline GLsizei getDrawBuffers (void) const { return mDrawBuffers; }
inline const AttachmentVec& getColorAttachments (void) const { return mColorAttachments; }
inline const Attachment& getDepthAttachment (void) const { return mDepthAttachment; }
......@@ -119,37 +106,40 @@ public:
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
inline void bindAsRenderTarget(void) const
{
bind();
setDrawBuffers();
}
/**
* Per default a FrameBuffer gets used for read/write operations, but we can
* bind two different FrameBuffers for these operations!
*/
inline void bind( TargetType _type = READ_DRAW_FRAMEBUFFER ) const
inline void bind(GLenum _type = GL_FRAMEBUFFER) const
{
if(sFrameBufferContext == mContext)
return;
glBindFramebuffer(_type, mContext);
openGLRareError(); // glBindFramebuffer can only fail if the contect is no valid FBO which shouldn't happen using this framework
sFrameBufferContext = mContext;
}
inline void setDrawBuffers(void) const
inline void bindAsRenderTarget(GLenum _type = GL_FRAMEBUFFER) const
{
glDrawBuffers(mDrawBuffers, msBuffers);
openGLRareError();
bind(_type);
setDrawBuffers();
glViewport(0, 0, mWidth, mHeight);
}
inline void setViewport(void) const
inline void bindAsRenderTarget(GLint _x, GLint _y, GLsizei _w, GLsizei _h, GLenum _type = GL_FRAMEBUFFER) const
{
bind(_type);
setDrawBuffers();
glViewport(0, 0, mWidth, mHeight);
}
inline bool isFrameBufferComplete(void) const
{
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
Utils::error() << "Failed to make complete FrameBuffer object: " << (glCheckFramebufferStatus(GL_FRAMEBUFFER)) << std::endl;
return false;
}
return true;
}
inline bool attachColorRenderBuffer(const SharedRenderBuffer& _renderBuffer)
{
if(_renderBuffer->getWidth() != mWidth && _renderBuffer->getHeight() != mHeight)
......@@ -228,22 +218,13 @@ public:
return true;
}
inline bool isFrameBufferComplete(void)
private:
inline void setDrawBuffers(void) const
{
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
Utils::error() << "Failed to make complete FrameBuffer object: " << (glCheckFramebufferStatus(GL_FRAMEBUFFER)) << std::endl;
return false;
}
return true;
glDrawBuffers(mDrawBuffers, msBuffers);
openGLRareError();
}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
protected:
void clean(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
......@@ -256,7 +237,7 @@ protected:
Attachment mDepthAttachment; // depth and stencil are combined
};
typedef std::tr1::shared_ptr<FrameBuffer> SharedFrameBuffer;
ACGL_SHARED_TYPEDEF(FrameBuffer)
} // OpenGL
} // ACGL
......
......@@ -8,6 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
......@@ -18,28 +19,24 @@ namespace OpenGL{
class RenderBuffer
{
ACGL_NOT_COPYABLE(RenderBuffer)
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
RenderBuffer(
GLsizei _width,
GLsizei _height,
GLenum _internalFormat)
: mContext(0),
mInternalFormat(_internalFormat),
mWidth(_width),
mHeight(_height)
mWidth(0),
mHeight(0)
{
glGenRenderbuffers(1, &mContext);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate renderbuffer!" << std::endl;
return;
}
glBindRenderbuffer(GL_RENDERBUFFER, mContext);
glRenderbufferStorage(GL_RENDERBUFFER, mInternalFormat, mWidth, mHeight);
}
virtual ~RenderBuffer(void)
......@@ -57,6 +54,27 @@ public:
inline GLsizei getWidth (void) const { return mWidth; }
inline GLsizei getHeight (void) const { return mHeight; }
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
//! Bind the renderbuffer
inline void bind(void) const
{
glBindRenderbuffer(GL_RENDERBUFFER, mContext);
}
//! Set texture size and NULL data
inline void setSize(
GLsizei _width,
GLsizei _height)
{
mWidth = _width;
mHeight = _height;
glBindRenderbuffer(GL_RENDERBUFFER, mContext);
glRenderbufferStorage(GL_RENDERBUFFER, mInternalFormat, mWidth, mHeight);
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
......@@ -67,7 +85,7 @@ protected:
GLsizei mHeight;
};
typedef std::tr1::shared_ptr<RenderBuffer> SharedRenderBuffer;
ACGL_SHARED_TYPEDEF(RenderBuffer)
} // OpenGL
} // ACGL
......
......@@ -12,6 +12,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
......@@ -19,28 +20,13 @@ namespace OpenGL{
class Shader
{
ACGL_NOT_COPYABLE(Shader)
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector<std::string> AttributeVec;
// ================================================================================================== \/
// ============================================================================================ ENUMS \/
// ================================================================================================== \/
public:
//! Different types of a shader (i.e. vertex or fragment shaders)
enum ShaderType
{
ShaderTypeInvalid = 0,
ShaderTypeVertex = GL_VERTEX_SHADER,
ShaderTypeFragment = GL_FRAGMENT_SHADER
#ifndef OPENGL_ES
,
ShaderTypeGeometry = GL_GEOMETRY_SHADER,
ShaderTypeControl = GL_TESS_CONTROL_SHADER,
ShaderTypeEvaluation = GL_TESS_EVALUATION_SHADER
#endif
};
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
......@@ -87,7 +73,7 @@ protected:
AttributeVec mAttributes;
};
typedef std::tr1::shared_ptr<Shader> SharedShader;
ACGL_SHARED_TYPEDEF(Shader)
} // OpenGL
} // ACGL
......
......@@ -8,11 +8,11 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/Math/Math.hh>
#include <ACGL/OpenGL/Objects/Shader.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/Math/Math.hh>
#include <vector>
#include <tr1/memory>
......@@ -22,11 +22,7 @@ namespace OpenGL{
class ShaderProgram
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sShaderProgramContext;
ACGL_NOT_COPYABLE(ShaderProgram)
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
......@@ -82,24 +78,22 @@ public:
bool link (void) const;
inline void setUniform (GLint _location, GLint _v) const { glUniform1i (_location, _v); }
inline void setUniform (GLint _location, GLfloat _v) const { glUniform1f (_location, _v); }
inline void setUniform (GLint _location, GLint _v) const { glUniform1i (_location, _v); }
inline void setUniform (GLint _location, GLfloat _v) const { glUniform1f (_location, _v); }
inline void setUniform (GLint _location, const glm::vec2& _v) const { glUniform2fv(_location, 1, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::vec3& _v) const { glUniform3fv(_location, 1, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::vec4& _v) const { glUniform4fv(_location, 1, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat2& _v) const { glUniformMatrix2fv(_location, 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat3& _v) const { glUniformMatrix3fv(_location, 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat4& _v) const { glUniformMatrix4fv(_location, 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix2fv(_location, 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix3fv(_location, 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (GLint _location, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix4fv(_location, 1, _transpose, glm::value_ptr(_v)); }
inline void setTexture (GLint _location, const SharedTexture& _texture, GLenum _unit = 0) const { glUniform1i(_location, _unit); _texture->bind(_unit); }
inline void use (void) const
inline void use(void) const
{
if(sShaderProgramContext == mContext)
return;
glUseProgram(mContext);
sShaderProgramContext = mContext;
}
inline GLint getUniformLocation( const char *_name ) const { return glGetUniformLocation( mContext, _name ); }
......@@ -108,14 +102,16 @@ public:
// ============================================================================== HIGH LEVEL FUNCTIONS \/
// =================================================================================================== \/
inline void setUniform (const std::string& _nameInShader, GLint _v) const { glUniform1i (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLfloat _v) const { glUniform1f (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLint _v) const { glUniform1i (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, GLfloat _v) const { glUniform1f (getUniformLocation(_nameInShader), _v); }
inline void setUniform (const std::string& _nameInShader, const glm::vec2& _v) const { glUniform2fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::vec3& _v) const { glUniform3fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::vec4& _v) const { glUniform4fv(getUniformLocation(_nameInShader), 1, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat2& _v) const { glUniformMatrix2fv(getUniformLocation(_nameInShader), 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat3& _v) const { glUniformMatrix3fv(getUniformLocation(_nameInShader), 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat4& _v) const { glUniformMatrix4fv(getUniformLocation(_nameInShader), 1, GL_FALSE, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat2& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix2fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat3& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix3fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setUniform (const std::string& _nameInShader, const glm::mat4& _v, GLboolean _transpose = GL_FALSE) const { glUniformMatrix4fv(getUniformLocation(_nameInShader), 1, _transpose, glm::value_ptr(_v)); }
inline void setTexture (const std::string& _nameInShader, const SharedTexture& _texture, GLenum _unit = 0) const { glUniform1i(getUniformLocation(_nameInShader), _unit); _texture->bind(_unit); }
......@@ -129,7 +125,7 @@ protected:
SharedShaderVec mShaders;
};
typedef std::tr1::shared_ptr<ShaderProgram> SharedShaderProgram;
ACGL_SHARED_TYPEDEF(ShaderProgram)
} // OpenGL
} // ACGL
......
......@@ -8,6 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Math/Math.hh>
......@@ -20,11 +21,7 @@ namespace OpenGL{
class Texture
{
// ======================================================================================================== \/
// ============================================================================================ GPU CONTEXT \/
// ======================================================================================================== \/
private:
static GLuint sTextureContext;
ACGL_NOT_COPYABLE(Texture)
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
......@@ -48,7 +45,6 @@ public:
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
}
}
virtual ~Texture(void)
......@@ -79,16 +75,6 @@ public:
inline void setFormat (GLenum _format) { mFormat = _format; }
inline void setType (GLenum _type) { mType = _type; }
inline void setSize(
GLsizei _width = 0,
GLsizei _height = 0,
GLsizei _depth = 0)
{
mWidth = _width;
mHeight = _height;
mDepth = _depth;
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
......@@ -96,45 +82,40 @@ public:
//! Activate texture unit and bind this texture.
inline void bind(GLenum _textureUnit) const
{
if(sTextureContext == mContext)
return;
glActiveTexture(GL_TEXTURE0 + _textureUnit);
glBindTexture(mTarget, mContext);
openGLRareError();
sTextureContext = mContext;
}
//! Bind this texture.
inline void bind(void) const
{
if(sTextureContext == mContext)
return;
glBindTexture(mTarget, mContext);
openGLRareError();
sTextureContext = mContext;
}
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setParameter(GLenum _parameter, GLint _value)
{
bind();
glBindTexture(mTarget, mContext);
glTexParameteri(mTarget, _parameter, _value);
openGLRareError();
}
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setParameter(GLenum _parameter, GLfloat _value)
{
bind();
glBindTexture(mTarget, mContext);
glTexParameterf(mTarget, _parameter, _value);
openGLRareError();
}
//! Set texture size for 1D, 2D or 3D textures and NULL data
inline void setRenderTarget(
inline void setSize(
GLsizei _width,
GLsizei _height = 0,
GLsizei _depth = 0)
{
bind();
mWidth = _width;
mHeight = _height;
mDepth = _depth;
......@@ -144,16 +125,7 @@ public:
}
else if(mWidth > 0 && mHeight > 0)
{
glTexImage2D(
mTarget,
0,
mInternalFormat,
mWidth,
mHeight,
0,//no border
mFormat,
mType,
NULL);
setSize2D(mWidth, mHeight);
}
else if(mWidth > 0)
{
......@@ -162,13 +134,13 @@ public:
}
//! Set texture size and NULL data
inline void setRenderTarget2D(
inline void setSize2D(
GLsizei _width,
GLsizei _height)
{
bind();
mWidth = _width;
mHeight = _height;
glBindTexture(mTarget, mContext);
glTexImage2D(
mTarget,
0,
......@@ -181,15 +153,33 @@ public:
NULL);
}
//! Set texture data for some mipmap level.
/*!
If you upload a texture for a higher mipmap level, the function will automatically determine
its size calculating (w,h)/2^level where w and h are the width and height of the base texture.
*/
inline void setTexImage2D(
//! Set texture data
inline void setImage2D(
GLsizei _width,
GLsizei _height,
const GLvoid* _pData)
{
bind();
mWidth = _width;
mHeight = _height;
glBindTexture(mTarget, mContext);