Added new buffered_value template class which encapsulates a std::vector but
initializes the array to the number of graphics contexts, and automatically expands the array when indices outside the current size are required. Added new osg::Texture::Extensions nested class to handle extensions on a per context basis.
This commit is contained in:
@@ -11,10 +11,8 @@
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/buffered_value>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
// if not defined by gl.h use the definition found in:
|
||||
// http://oss.sgi.com/projects/ogl-sample/registry/EXT/texture_filter_anisotropic.txt
|
||||
@@ -179,34 +177,55 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
bool isCompressedInternalFormat() const;
|
||||
|
||||
|
||||
// /** Get the handle to the texture object for the current context.*/
|
||||
// /** return the OpenGL texture object for specified context.*/
|
||||
// inline GLuint& getTextureObject(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_handleList.size()<=contextID)
|
||||
// _handleList.resize(contextID+1,0);
|
||||
//
|
||||
// // get the globj for the current contextID.
|
||||
// return _handleList[contextID];
|
||||
// }
|
||||
//
|
||||
// inline uint& getModifiedTag(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_modifiedTag.size()<=contextID)
|
||||
// _modifiedTag.resize(contextID+1,0);
|
||||
//
|
||||
// // get the modified tag for the current contextID.
|
||||
// return _modifiedTag[contextID];
|
||||
// }
|
||||
//
|
||||
// inline uint& getTextureParameterDity(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_texParametersDirtyList.size()<=contextID)
|
||||
// _texParametersDirtyList.resize(contextID+1,0);
|
||||
//
|
||||
// // get the dirty flag for the current contextID.
|
||||
// return _texParametersDirtyList[contextID];
|
||||
// }
|
||||
|
||||
|
||||
/** Get the handle to the texture object for the current context.*/
|
||||
/** return the OpenGL texture object for specified context.*/
|
||||
inline GLuint& getTextureObject(uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_handleList.size()<=contextID)
|
||||
_handleList.resize(contextID+1,0);
|
||||
|
||||
// get the globj for the current contextID.
|
||||
return _handleList[contextID];
|
||||
}
|
||||
|
||||
inline uint& getModifiedTag(uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_modifiedTag.size()<=contextID)
|
||||
_modifiedTag.resize(contextID+1,0);
|
||||
|
||||
// get the modified tag for the current contextID.
|
||||
return _modifiedTag[contextID];
|
||||
}
|
||||
|
||||
inline uint& getTextureParameterDity(uint contextID) const
|
||||
{
|
||||
// pad out handle list if required.
|
||||
if (_texParametersDirtyList.size()<=contextID)
|
||||
_texParametersDirtyList.resize(contextID+1,0);
|
||||
|
||||
// get the dirty flag for the current contextID.
|
||||
return _texParametersDirtyList[contextID];
|
||||
}
|
||||
@@ -259,13 +278,16 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
int compareTexture(const Texture& rhs) const;
|
||||
|
||||
typedef std::vector<GLuint> TextureNameList;
|
||||
// typedef std::vector<GLuint> TextureNameList;
|
||||
typedef buffered_value<GLuint> TextureNameList;
|
||||
mutable TextureNameList _handleList;
|
||||
|
||||
typedef std::vector<uint> ImageModifiedTag;
|
||||
// typedef std::vector<uint> ImageModifiedTag;
|
||||
typedef buffered_value<uint> ImageModifiedTag;
|
||||
mutable ImageModifiedTag _modifiedTag;
|
||||
|
||||
typedef std::vector<uint> TexParameterDirtyList;
|
||||
// typedef std::vector<uint> TexParameterDirtyList;
|
||||
typedef buffered_value<uint> TexParameterDirtyList;
|
||||
mutable TexParameterDirtyList _texParametersDirtyList;
|
||||
|
||||
WrapMode _wrap_s;
|
||||
@@ -281,11 +303,6 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
InternalFormatMode _internalFormatMode;
|
||||
mutable GLint _internalFormat;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedTextureObjectCache;
|
||||
static DeletedTextureObjectCache s_deletedTextureObjectCache;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -92,6 +92,26 @@ class SG_EXPORT Texture3D : public Texture
|
||||
/** On first apply (unless already compiled), create the minmapped
|
||||
* texture and bind it, subsequent apply will simple bind to texture.*/
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
|
||||
struct Extensions : public osg::Referenced
|
||||
{
|
||||
Extensions();
|
||||
|
||||
|
||||
bool isTexture3DSupported;
|
||||
bool isTexture3DFast;
|
||||
GLint maxTexture3DSize;
|
||||
|
||||
|
||||
void glTexImage3D( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
void glTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
|
||||
void glCopyTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
|
||||
void gluBuild3DMipmaps( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data);
|
||||
|
||||
};
|
||||
|
||||
static Extensions* getExtensions(uint contextID=0);
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
59
include/osg/buffered_value
Normal file
59
include/osg/buffered_value
Normal file
@@ -0,0 +1,59 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_BUFFERED_VALUE
|
||||
#define OSG_BUFFERED_VALUE 1
|
||||
|
||||
#include <osg/DisplaySettings>
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Simple buffered value array which is used for values that need to multibuffered on
|
||||
* one per graphics context basis.*/
|
||||
|
||||
template<class T>
|
||||
class buffered_value
|
||||
{
|
||||
public:
|
||||
|
||||
inline buffered_value():
|
||||
_array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0)
|
||||
{}
|
||||
|
||||
buffered_value& operator = (const buffered_value& rhs)
|
||||
{
|
||||
_array = rhs._array;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void clear() { _array.clear(); }
|
||||
|
||||
inline bool empty() const { return _array.empty(); }
|
||||
|
||||
inline unsigned int size() const { return _array.size(); }
|
||||
|
||||
inline T& operator[] (unsigned int pos)
|
||||
{
|
||||
// automatically resize array.
|
||||
if (_array.size()<=pos)
|
||||
_array.resize(pos+1,0);
|
||||
|
||||
return _array[pos];
|
||||
}
|
||||
/* // do we implement the const version???
|
||||
inline T operator[] (unsigned int pos) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
protected:
|
||||
|
||||
std::vector<T> _array;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user