2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
#ifndef OSG_TEXTURE3D
|
|
|
|
#define OSG_TEXTURE3D 1
|
|
|
|
|
2002-08-28 23:28:11 +08:00
|
|
|
#include <osg/Texture>
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2008-09-01 17:57:35 +08:00
|
|
|
#ifndef GL_MAX_3D_TEXTURE_SIZE
|
2010-10-07 02:29:23 +08:00
|
|
|
#define GL_MAX_3D_TEXTURE_SIZE 0x8073
|
2008-09-01 17:57:35 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
namespace osg {
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Encapsulates OpenGL 3D texture functionality. Doesn't support cube maps,
|
2004-09-14 00:10:59 +08:00
|
|
|
* so ignore \a face parameters.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Texture3D : public Texture
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
Texture3D();
|
|
|
|
|
2008-10-08 19:30:18 +08:00
|
|
|
Texture3D(Image* image);
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-08-25 03:39:39 +08:00
|
|
|
Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
META_StateAttribute(osg, Texture3D,TEXTURE);
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2002-08-25 03:39:39 +08:00
|
|
|
virtual int compare(const StateAttribute& rhs) const;
|
|
|
|
|
2005-07-27 19:27:44 +08:00
|
|
|
virtual GLenum getTextureTarget() const { return GL_TEXTURE_3D; }
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture image. */
|
2002-08-25 03:39:39 +08:00
|
|
|
void setImage(Image* image);
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture image. */
|
2002-08-25 03:39:39 +08:00
|
|
|
Image* getImage() { return _image.get(); }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the const texture image. */
|
2002-08-25 03:39:39 +08:00
|
|
|
inline const Image* getImage() const { return _image.get(); }
|
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
inline unsigned int& getModifiedCount(unsigned int contextID) const
|
2003-04-07 17:46:06 +08:00
|
|
|
{
|
2005-02-09 18:39:45 +08:00
|
|
|
// get the modified count for the current contextID.
|
|
|
|
return _modifiedCount[contextID];
|
2003-04-07 17:46:06 +08:00
|
|
|
}
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture image, ignoring face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual void setImage(unsigned int, Image* image) { setImage(image); }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture image, ignoring face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual Image* getImage(unsigned int) { return _image.get(); }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the const texture image, ignoring face. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual const Image* getImage(unsigned int) const { return _image.get(); }
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the number of images that can be assigned to the Texture. */
|
2004-07-27 18:11:45 +08:00
|
|
|
virtual unsigned int getNumImages() const { return 1; }
|
|
|
|
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Sets the texture width, height, and depth. If width, height, or
|
|
|
|
* depth are zero, calculate the respective value from the source
|
|
|
|
* image size. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setTextureSize(int width, int height, int depth) const
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
|
|
|
_textureWidth = width;
|
|
|
|
_textureHeight = height;
|
|
|
|
_textureDepth = depth;
|
|
|
|
}
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the texture subload width. */
|
2002-08-25 03:39:39 +08:00
|
|
|
inline void getTextureSize(int& width, int& height, int& depth) const
|
|
|
|
{
|
|
|
|
width = _textureWidth;
|
|
|
|
height = _textureHeight;
|
|
|
|
depth = _textureDepth;
|
|
|
|
}
|
|
|
|
|
2005-11-04 20:08:16 +08:00
|
|
|
void setTextureWidth(int width) { _textureWidth=width; }
|
|
|
|
void setTextureHeight(int height) { _textureHeight=height; }
|
|
|
|
void setTextureDepth(int depth) { _textureDepth=depth; }
|
2006-08-03 23:57:39 +08:00
|
|
|
|
|
|
|
virtual int getTextureWidth() const { return _textureWidth; }
|
|
|
|
virtual int getTextureHeight() const { return _textureHeight; }
|
|
|
|
virtual int getTextureDepth() const { return _textureDepth; }
|
2005-11-04 20:08:16 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT SubloadCallback : public Referenced
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void load(const Texture3D& texture,State& state) const = 0;
|
|
|
|
virtual void subload(const Texture3D& texture,State& state) const = 0;
|
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
|
|
|
|
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Helper function. Sets the number of mipmap levels created for this
|
2007-12-11 01:30:18 +08:00
|
|
|
* texture. Should only be called within an osg::Texture::apply(), or
|
2004-09-14 00:10:59 +08:00
|
|
|
* during a custom OpenGL texture load. */
|
2003-07-14 22:42:10 +08:00
|
|
|
void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Gets the number of mipmap levels created. */
|
2003-07-14 22:42:10 +08:00
|
|
|
unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Copies a two-dimensional texture subimage, as per
|
|
|
|
* glCopyTexSubImage3D. Updates a portion of an existing OpenGL
|
|
|
|
* texture object from the current OpenGL background framebuffer
|
|
|
|
* contents at position \a x, \a y with width \a width and height
|
|
|
|
* \a height. Loads framebuffer data into the texture using offsets
|
|
|
|
* \a xoffset, \a yoffset, and \a zoffset. \a width and \a height
|
|
|
|
* must be powers of two. */
|
2002-08-25 03:39:39 +08:00
|
|
|
void copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
|
|
|
|
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Bind the texture object. If the texture object hasn't already been
|
|
|
|
* compiled, create the texture mipmap levels. */
|
2002-08-25 03:39:39 +08:00
|
|
|
virtual void apply(State& state) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-09-05 23:45:10 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Encapsulates queries of extension availability, obtains extension
|
2007-12-11 01:30:18 +08:00
|
|
|
* function pointers, and provides convenience wrappers for
|
2012-03-22 01:36:20 +08:00
|
|
|
* calling extension functions. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Extensions : public osg::Referenced
|
2002-09-05 19:42:55 +08:00
|
|
|
{
|
2002-09-05 23:45:10 +08:00
|
|
|
public:
|
2005-04-26 21:15:27 +08:00
|
|
|
Extensions(unsigned int contextID);
|
2002-09-05 23:45:10 +08:00
|
|
|
|
2002-09-14 18:38:28 +08:00
|
|
|
Extensions(const Extensions& rhs);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-09-14 18:38:28 +08:00
|
|
|
void lowestCommonDenominator(const Extensions& rhs);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2006-03-09 00:11:54 +08:00
|
|
|
void setupGLExtensions(unsigned int contextID);
|
2002-09-14 18:38:28 +08:00
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setTexture3DSupported(bool flag) { _isTexture3DSupported=flag; }
|
2002-09-05 23:45:10 +08:00
|
|
|
bool isTexture3DSupported() const { return _isTexture3DSupported; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setTexture3DFast(bool flag) { _isTexture3DFast=flag; }
|
2002-09-05 23:45:10 +08:00
|
|
|
bool isTexture3DFast() const { return _isTexture3DFast; }
|
2002-09-17 04:58:05 +08:00
|
|
|
|
2003-04-10 21:41:45 +08:00
|
|
|
void setMaxTexture3DSize(GLint maxsize) { _maxTexture3DSize=maxsize; }
|
2002-09-05 23:45:10 +08:00
|
|
|
GLint maxTexture3DSize() const { return _maxTexture3DSize; }
|
|
|
|
|
2010-10-08 19:20:56 +08:00
|
|
|
bool isCompressedTexImage3DSupported() const { return glCompressedTexImage3D!=0; }
|
2004-09-29 18:01:46 +08:00
|
|
|
|
2010-10-08 19:20:56 +08:00
|
|
|
bool isCompressedTexSubImage3DSupported() const { return glCompressedTexSubImage3D!=0; }
|
2002-09-05 23:45:10 +08:00
|
|
|
|
2010-04-29 05:22:44 +08:00
|
|
|
typedef void (GL_APIENTRY * GLTexImage3DProc) ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
|
|
|
|
typedef void (GL_APIENTRY * GLTexSubImage3DProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
|
|
|
|
typedef void (GL_APIENTRY * CompressedTexImage3DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * CompressedTexSubImage3DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * GLCopyTexSubImageProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
|
2008-12-18 00:13:23 +08:00
|
|
|
|
2010-10-08 19:20:56 +08:00
|
|
|
GLTexImage3DProc glTexImage3D;
|
|
|
|
GLTexSubImage3DProc glTexSubImage3D;
|
|
|
|
CompressedTexImage3DArbProc glCompressedTexImage3D;
|
|
|
|
CompressedTexSubImage3DArbProc glCompressedTexSubImage3D;
|
|
|
|
GLCopyTexSubImageProc glCopyTexSubImage3D;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
~Extensions() {}
|
2002-09-05 19:42:55 +08:00
|
|
|
|
2010-10-08 19:20:56 +08:00
|
|
|
bool _isTexture3DSupported;
|
|
|
|
bool _isTexture3DFast;
|
|
|
|
GLint _maxTexture3DSize;
|
2002-09-05 19:42:55 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Encapsulates queries of extension availability, obtains extension
|
2007-12-11 01:30:18 +08:00
|
|
|
* function pointers, and provides convenience wrappers for
|
2012-03-22 01:36:20 +08:00
|
|
|
* calling extension functions. */
|
2003-04-10 21:41:45 +08:00
|
|
|
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Overrides Extensions objects across graphics contexts. Typically
|
|
|
|
* used to ensure the same lowest common denominator of extensions
|
2007-12-11 01:30:18 +08:00
|
|
|
* on systems with different graphics pipes. */
|
2003-02-14 19:41:52 +08:00
|
|
|
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
2002-09-14 18:38:28 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Texture3D();
|
|
|
|
|
2004-09-30 17:10:29 +08:00
|
|
|
void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& depth, GLsizei& numMipmapLevels) const;
|
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
virtual void computeInternalFormat() const;
|
2007-09-11 20:04:58 +08:00
|
|
|
void allocateMipmap(State& state) const;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2003-07-14 22:42:10 +08:00
|
|
|
void applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMipmapLevels) const;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** It's not ideal that _image is mutable, but it's required since
|
|
|
|
* Image::ensureDimensionsArePowerOfTwo() can only be called in a
|
|
|
|
* valid OpenGL context, and therefore within Texture::apply, which
|
|
|
|
* is const. */
|
2002-08-25 03:39:39 +08:00
|
|
|
mutable ref_ptr<Image> _image;
|
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Subloaded images can have different texture and image sizes. */
|
2002-08-25 03:39:39 +08:00
|
|
|
mutable GLsizei _textureWidth, _textureHeight, _textureDepth;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-14 00:10:59 +08:00
|
|
|
/** Number of mip map levels the the texture has been created with, */
|
2003-07-14 22:42:10 +08:00
|
|
|
mutable GLsizei _numMipmapLevels;
|
2002-08-25 03:39:39 +08:00
|
|
|
|
|
|
|
ref_ptr<SubloadCallback> _subloadCallback;
|
2003-04-07 17:46:06 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
typedef buffered_value<unsigned int> ImageModifiedCount;
|
|
|
|
mutable ImageModifiedCount _modifiedCount;
|
2003-04-07 17:46:06 +08:00
|
|
|
|
2002-08-25 03:39:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|