Commit a4ab590d authored by Christopher Tenter's avatar Christopher Tenter
Browse files

Corrected texture functions.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12372 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4ce816ae
......@@ -89,7 +89,7 @@ bool GLState::programLock_ = false;
std::deque <GLStateContext> GLState::stateStack_;
std::bitset<0xFFFF+1> GLState::glStateLock_;
int GLState::glBufferTargetLock_[4] = {0};
int GLState::glTextureTargetLock_[16][5];
int GLState::glTextureStageLock_[16] = {0};
bool GLState::framebufferLock_[2] = {false};
int GLState::maxTextureCoords_ = 0;
int GLState::maxCombinedTextureImageUnits_ = 0;
......@@ -114,10 +114,6 @@ GLState::GLState(bool _updateGL)
{
stateStack_.push_back(GLStateContext());
// every state is unlocked at start
for (int i = 0; i < 16; ++i)
memset(glTextureTargetLock_[i], 0, 5 * sizeof(int));
memset(glBufferTargetLock_, 0, sizeof(glBufferTargetLock_));
framebufferLock_[0] = framebufferLock_[1] = false;
......@@ -1346,9 +1342,7 @@ void GLState::syncFromGL()
GL_TEXTURE_BINDING_2D, GL_TEXTURE_2D,
GL_TEXTURE_BINDING_3D, GL_TEXTURE_3D,
GL_TEXTURE_BINDING_CUBE_MAP, GL_TEXTURE_CUBE_MAP
#ifndef __APPLE__
, GL_TEXTURE_BINDING_RECTANGLE, GL_TEXTURE_RECTANGLE
#endif
, GL_TEXTURE_BINDING_RECTANGLE_ARB, GL_TEXTURE_RECTANGLE_ARB
};
glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxTextureCoords_);
......@@ -1365,14 +1359,17 @@ void GLState::syncFromGL()
{
glActiveTexture(GL_TEXTURE0 + i);
getparam = 0;
// for each texture stage query 5 texture types: 1D, 2D, 3D, Cube, Rect
int entries = 5;
#ifdef __APPLE__
entries = 4;
#endif
for (int k = 0; k < entries; ++k)
glGetIntegerv(texBufGets[k*2],
(GLint*)stateStack_.back().glTextureTargetState_[i] + getTextureTargetIndex(texBufGets[k*2+1]));
for (int k = 0; k < 5 && !getparam; ++k)
{
glGetIntegerv(texBufGets[k*2], &getparam);
if (getparam)
{
stateStack_.back().glTextureStage_[i].buf_ = getparam;
stateStack_.back().glTextureStage_[i].target_ = texBufGets[k*2+1];
}
}
}
// restore active texture unit
......@@ -1707,21 +1704,6 @@ GLuint GLState::getBoundBuf(GLenum _target)
//-----------------------------------------------------------------------------
int GLState::getTextureTargetIndex(GLenum _target)
{
switch (_target)
{
case GL_TEXTURE_2D: return 1;
#ifndef __APPLE__
case GL_TEXTURE_RECTANGLE: return 4;
#endif
case GL_TEXTURE_CUBE_MAP: return 3;
case GL_TEXTURE_1D: return 0;
case GL_TEXTURE_3D: return 2;
}
return -1;
}
void GLState::activeTexture(GLenum _texunit)
{
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
......@@ -1737,42 +1719,48 @@ void GLState::bindTexture(GLenum _target, GLuint _buffer)
{
int activeTex = getActiveTextureIndex();
int texTargetIdx = getTextureTargetIndex(_target);
assert(activeTex >= 0);
assert(texTargetIdx >= 0);
GLStateContext::TextureStage* stage = stateStack_.back().glTextureStage_ + activeTex;
if (!glTextureTargetLock_[activeTex][texTargetIdx])
if (!glTextureStageLock_[activeTex])
{
#ifdef GLSTATE_AVOID_REDUNDANT_GLCALLS
if (_buffer != stateStack_.back().glTextureTargetState_[activeTex][texTargetIdx])
if (_buffer != stage->buf_ || _target != stage->target_)
#endif
{
glBindTexture(_target, _buffer);
stateStack_.back().glTextureTargetState_[activeTex][texTargetIdx] = _buffer;
stage->target_ = _target;
stage->buf_ = _buffer;
}
}
}
void GLState::lockTextureTarget(GLenum _target)
void GLState::lockTextureStage()
{
glTextureTargetLock_[getActiveTextureIndex()][getTextureTargetIndex(_target)] = 1;
glTextureStageLock_[getActiveTextureIndex()] = 1;
}
void GLState::unlockTextureTarget(GLenum _target)
void GLState::unlockTextureStage()
{
glTextureTargetLock_[getActiveTextureIndex()][getTextureTargetIndex(_target)] = 0;
glTextureStageLock_[getActiveTextureIndex()] = 0;
}
bool GLState::isTextureTargetLocked(GLenum _target)
bool GLState::isTextureTargetLocked()
{
return glTextureTargetLock_[getActiveTextureIndex()][getTextureTargetIndex(_target)] != 0;
return glTextureStageLock_[getActiveTextureIndex()] != 0;
}
GLuint GLState::getBoundTextureBuffer(GLenum _target)
GLuint GLState::getBoundTextureBuffer()
{
return stateStack_.back().glTextureTargetState_[getActiveTextureIndex()][getTextureTargetIndex(_target)];
return stateStack_.back().glTextureStage_[getActiveTextureIndex()].buf_;
}
GLenum GLState::getBoundTextureTarget()
{
return stateStack_.back().glTextureStage_[getActiveTextureIndex()].target_;
}
//----------------------------------------------------------
// vertex pointers
......@@ -2026,19 +2014,10 @@ void GLState::popAttrib()
bindBuffer(GL_PIXEL_PACK_BUFFER, p->glBufferTargetState_[2]);
bindBuffer(GL_PIXEL_UNPACK_BUFFER, p->glBufferTargetState_[3]);
for (int i = 0; i < num_texture_units_; ++i)
{
GLenum targets[4] = {GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP};
for (int i = 0; i < num_texture_units_; ++i)
{
activeTexture(GL_TEXTURE0 + i);
//TODO, changed 5 to 4 for end variable t as targets has only four elements
// check if this is correct
for (int t = 0; t < 4; ++t)
bindTexture(targets[t], stateStack_.back().glTextureTargetState_[i][t]);
}
activeTexture(GL_TEXTURE0 + i);
bindBuffer(p->glTextureStage_[i].target_, p->glTextureStage_[i].buf_);
}
activeTexture(p->activeTexture_);
......
......@@ -118,7 +118,7 @@ struct GLStateContext
// it contains a copy of the OpenGL state machine
public:
GLStateContext() { activeTexture_ = 0;}
GLStateContext() { activeTexture_ = GL_TEXTURE0;}
// glEnable / glDisable states
// iff a bit is set for a state, it is enabled in OpenGL
......@@ -146,10 +146,17 @@ public:
// active texture unit: GL_TEXTUREi
GLenum activeTexture_;
// 16 texture stages, 5 targets
// GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_RECTANGLE
// current state of a texture target
GLuint glTextureTargetState_[16][5];
struct TextureStage
{
TextureStage() : target_(0), buf_(0) {}
// current stage target
GLenum target_;
// current stage buffer
GLuint buf_;
};
// 16 texture stages
TextureStage glTextureStage_[16];
// current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
GLenum shadeModel_;
......@@ -368,17 +375,17 @@ public:
/// get vertex pointer, null-ptr safe
static void getVertexPointer(GLint* _size, GLenum* _type, GLsizei* _stride, const GLvoid** _pointer);
/// Wrapper: glVertexPointer for Vec2f
static void vertexPointer(const Vec2f* _p) {vertexPointer(2, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec2d
static void vertexPointer(const Vec2d* _p) {vertexPointer(2, GL_DOUBLE, 0, _p);}
/// Wrapper: glVertexPointer for Vec3f
static void vertexPointer(const Vec3f* _p) {vertexPointer(3, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec3d
static void vertexPointer(const Vec3d* _p) {vertexPointer(3, GL_DOUBLE, 0, _p);}
/// Wrapper: glVertexPointer for Vec4f
static void vertexPointer(const Vec4f* _p) {vertexPointer(4, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec4d
/// Wrapper: glVertexPointer for Vec2f
static void vertexPointer(const Vec2f* _p) {vertexPointer(2, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec2d
static void vertexPointer(const Vec2d* _p) {vertexPointer(2, GL_DOUBLE, 0, _p);}
/// Wrapper: glVertexPointer for Vec3f
static void vertexPointer(const Vec3f* _p) {vertexPointer(3, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec3d
static void vertexPointer(const Vec3d* _p) {vertexPointer(3, GL_DOUBLE, 0, _p);}
/// Wrapper: glVertexPointer for Vec4f
static void vertexPointer(const Vec4f* _p) {vertexPointer(4, GL_FLOAT, 0, _p);}
/// Wrapper: glVertexPointer for Vec4d
static void vertexPointer(const Vec4d* _p) {vertexPointer(4, GL_DOUBLE, 0, _p);}
/// lock vertex pointer
......@@ -393,9 +400,9 @@ public:
/// get normal pointer, null-ptr safe
static void getNormalPointer(GLenum* _type, GLsizei* _stride, const GLvoid** _pointer);
/// Wrapper: glNormalPointer for Vec3f
static void normalPointer(const Vec3f* _p) { glNormalPointer(GL_FLOAT, 0, _p); }
/// Wrapper: glNormalPointer for Vec3d
/// Wrapper: glNormalPointer for Vec3f
static void normalPointer(const Vec3f* _p) { glNormalPointer(GL_FLOAT, 0, _p); }
/// Wrapper: glNormalPointer for Vec3d
static void normalPointer(const Vec3d* _p) { glNormalPointer(GL_DOUBLE, 0, _p); }
/// lock normal pointer
......@@ -410,15 +417,15 @@ public:
static void colorPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid* _pointer);
/// get color pointer, null-ptr safe
static void getColorPointer(GLint* _size, GLenum* _type, GLsizei* _stride, const GLvoid** _pointer);
/// Wrapper: glColorPointer for Vec3uc
static void colorPointer(const Vec3uc* _p) {colorPointer(3, GL_UNSIGNED_BYTE, 0, _p);}
/// Wrapper: glColorPointer for Vec3f
static void colorPointer(const Vec3f* _p) {colorPointer(3, GL_FLOAT, 0, _p);}
/// Wrapper: glColorPointer for Vec4uc
static void colorPointer(const Vec4uc* _p) {colorPointer(4, GL_UNSIGNED_BYTE, 0, _p);}
/// Wrapper: glColorPointer for Vec4f
static void colorPointer(const Vec4f* _p) {colorPointer(4, GL_FLOAT, 0, _p);}
/// Wrapper: glColorPointer for Vec3uc
static void colorPointer(const Vec3uc* _p) {colorPointer(3, GL_UNSIGNED_BYTE, 0, _p);}
/// Wrapper: glColorPointer for Vec3f
static void colorPointer(const Vec3f* _p) {colorPointer(3, GL_FLOAT, 0, _p);}
/// Wrapper: glColorPointer for Vec4uc
static void colorPointer(const Vec4uc* _p) {colorPointer(4, GL_UNSIGNED_BYTE, 0, _p);}
/// Wrapper: glColorPointer for Vec4f
static void colorPointer(const Vec4f* _p) {colorPointer(4, GL_FLOAT, 0, _p);}
/// lock color pointer
static void lockColorPointer() {colorPointerLock_ = true;}
......@@ -553,35 +560,27 @@ public:
/// get active GL texture
inline static GLenum getActiveTexture() {return stateStack_.back().activeTexture_;}
/// get active texture as zero based index
inline static int getActiveTextureIndex() {
if (getActiveTexture() == 0)
return 0;
else
return getActiveTexture() - GL_TEXTURE0;
}
inline static int getActiveTextureIndex() {return getActiveTexture() - GL_TEXTURE0;}
/// replaces glBindTexture, supports locking
static void bindTexture(GLenum _target, GLuint _buffer);
/// locks the current texture stage (set by setActiveTexture)
static void lockTextureTarget(GLenum _target);
static void lockTextureStage();
/// unlocks the current texture target
static void unlockTextureTarget(GLenum _target);
static void unlockTextureStage();
/// get texture target locking state
static bool isTextureTargetLocked(GLenum _target);
static bool isTextureTargetLocked();
/// get bound texture
static GLuint getBoundTextureBuffer(GLenum _target);
static GLuint getBoundTextureBuffer();
/// get bound texture target
static GLenum getBoundTextureTarget();
/** @} */
private:
/// bijective map from GLenum texture_target to [0..4], -1 if unsupported
static int getTextureTargetIndex(GLenum _target);
public:
//===========================================================================
......@@ -1124,9 +1123,8 @@ private: //--------------------------------------------------------------------
// GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER
static int glBufferTargetLock_[4];
// 16 texture stages, 4 targets
// GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP
static int glTextureTargetLock_[16][5];
// 16 texture stages
static int glTextureStageLock_[16];
// current shade model: GL_FLAT, GL_SMOOTH, set by glShadeModel
static bool shadeModelLock_;
......
Markdown is supported
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