2.8 branch: Texture2DMultisample support. This is a backport of r11218, r11229, and r11365 from trunk.

This commit is contained in:
Paul MARTZ
2011-05-22 20:52:41 +00:00
parent 8d20926032
commit 6c6c1183c0
6 changed files with 91 additions and 154 deletions

View File

@@ -331,6 +331,7 @@ namespace osg
**************************************************************************/
class Texture1D;
class Texture2D;
class Texture2DMultisample;
class Texture3D;
class Texture2DArray;
class TextureCubeMap;
@@ -345,6 +346,7 @@ namespace osg
explicit FrameBufferAttachment(RenderBuffer* target);
explicit FrameBufferAttachment(Texture1D* target, int level = 0);
explicit FrameBufferAttachment(Texture2D* target, int level = 0);
explicit FrameBufferAttachment(Texture2DMultisample* target, int level = 0);
explicit FrameBufferAttachment(Texture3D* target, int zoffset, int level = 0);
explicit FrameBufferAttachment(Texture2DArray* target, int layer, int level = 0);
explicit FrameBufferAttachment(TextureCubeMap* target, int face, int level = 0);

View File

@@ -199,6 +199,10 @@
#define GL_TEXTURE_DEPTH 0x8071
#endif
#ifndef GL_TEXTURE_2D_MULTISAMPLE
#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
#endif
// Integer teture extension as in http://www.opengl.org/registry/specs/EXT/texture_integer.txt
#ifndef GL_EXT_texture_integer
#define GL_RGBA32UI_EXT 0x8D70
@@ -579,12 +583,6 @@ class OSG_EXPORT Texture : public osg::StateAttribute
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
void setMultiTexturingSupported(bool flag) { _isMultiTexturingSupported=flag; }
bool isMultiTexturingSupported() const { return _isMultiTexturingSupported; }
@@ -609,6 +607,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute
void setGenerateMipMapSupported(bool flag) { _isGenerateMipMapSupported=flag; }
bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; }
void setTextureMultisampledSupported(bool flag) { _isTextureMultisampledSupported=flag; }
bool isTextureMultisampledSupported() const { return _isTextureMultisampledSupported; }
void setShadowSupported(bool flag) { _isShadowSupported = flag; }
bool isShadowSupported() const { return _isShadowSupported; }
@@ -624,10 +625,6 @@ class OSG_EXPORT Texture : public osg::StateAttribute
bool isCompressedTexImage2DSupported() const { return _glCompressedTexImage2D!=0; }
bool isCompressedTexSubImage2DSupported() const { return _glCompressedTexSubImage2D!=0; }
void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const;
void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei type, const GLvoid *data) const;
void glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const;
bool isClientStorageSupported() const { return _isClientStorageSupported; }
bool isNonPowerOfTwoTextureSupported(GLenum filter) const
@@ -640,13 +637,55 @@ class OSG_EXPORT Texture : public osg::StateAttribute
void setTextureIntegerSupported(bool flag) { _isTextureIntegerEXTSupported=flag; }
bool isTextureIntegerSupported() const { return _isTextureIntegerEXTSupported; }
void glTexParameterIiv(GLenum target, GLenum pname, const GLint* data) const;
void glTexParameterIuiv(GLenum target, GLenum pname, const GLuint* data) const;
void glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const
{
_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
void glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) const
{
_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
void glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const
{
_glGetCompressedTexImage(target, level, data);
}
void glTexImage2DMultisample(GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations) const
{
_glTexImage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
}
void glTexParameterIiv(GLenum target, GLenum pname, const GLint* data) const
{
_glTexParameterIiv(target, pname, data);
}
void glTexParameterIuiv(GLenum target, GLenum pname, const GLuint* data) const
{
_glTexParameterIuiv(target, pname, data);
}
protected:
~Extensions() {}
typedef void (APIENTRY * CompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
typedef void (APIENTRY * CompressedTexSubImage2DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
typedef void (APIENTRY * GetCompressedTexImageArbProc) (GLenum target, GLint level, GLvoid *data);
typedef void (APIENTRY * TexImage2DMultisample)(GLenum target, GLsizei samples, GLint internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
typedef void (APIENTRY * TexParameterIivProc)(GLenum target, GLenum pname, const GLint* data);
typedef void (APIENTRY * TexParameterIuivProc)(GLenum target, GLenum pname, const GLuint* data);
CompressedTexImage2DArbProc _glCompressedTexImage2D;
CompressedTexSubImage2DArbProc _glCompressedTexSubImage2D;
GetCompressedTexImageArbProc _glGetCompressedTexImage;
TexImage2DMultisample _glTexImage2DMultisample;
TexParameterIivProc _glTexParameterIiv;
TexParameterIuivProc _glTexParameterIuiv;
bool _isMultiTexturingSupported;
bool _isTextureFilterAnisotropicSupported;
bool _isTextureCompressionARBSupported;
@@ -655,6 +694,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
bool _isTextureEdgeClampSupported;
bool _isTextureBorderClampSupported;
bool _isGenerateMipMapSupported;
bool _isTextureMultisampledSupported;
bool _isShadowSupported;
bool _isShadowAmbientSupported;
bool _isClientStorageSupported;
@@ -664,19 +704,6 @@ class OSG_EXPORT Texture : public osg::StateAttribute
GLint _maxTextureSize;
GLint _numTextureUnits;
typedef void (APIENTRY * CompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
typedef void (APIENTRY * CompressedTexSubImage2DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
typedef void (APIENTRY * GetCompressedTexImageArbProc) (GLenum target, GLint level, GLvoid *data);
typedef void (APIENTRY * TexParameterIivProc)(GLenum target, GLenum pname, const GLint* data);
typedef void (APIENTRY * TexParameterIuivProc)(GLenum target, GLenum pname, const GLuint* data);
CompressedTexImage2DArbProc _glCompressedTexImage2D;
CompressedTexSubImage2DArbProc _glCompressedTexSubImage2D;
GetCompressedTexImageArbProc _glGetCompressedTexImage;
TexParameterIivProc _glTexParameterIiv;
TexParameterIuivProc _glTexParameterIuiv;
};
/** Gets the extension for the specified context. Creates the
@@ -710,6 +737,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
* unless you're implementing a subload callback. */
void applyTexImage2D_subload(State& state, GLenum target, const Image* image, GLsizei width, GLsizei height, GLint inInternalFormat, GLsizei numMipmapLevels) const;
/** Returned by mipmapBeforeTexImage() to indicate what
* mipmapAfterTexImage() should do */
enum GenerateMipmapMode

View File

@@ -154,6 +154,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Texture
${HEADER_PATH}/Texture1D
${HEADER_PATH}/Texture2D
${HEADER_PATH}/Texture2DMultisample
${HEADER_PATH}/Texture2DArray
${HEADER_PATH}/Texture3D
${HEADER_PATH}/TextureCubeMap
@@ -309,6 +310,7 @@ ADD_LIBRARY(${LIB_NAME}
Texture1D.cpp
Texture2DArray.cpp
Texture2D.cpp
Texture2DMultisample.cpp
Texture3D.cpp
Texture.cpp
TextureCubeMap.cpp

View File

@@ -18,6 +18,7 @@
#include <osg/GLExtensions>
#include <osg/Texture1D>
#include <osg/Texture2D>
#include <osg/Texture2DMultisample>
#include <osg/Texture3D>
#include <osg/Texture2DArray>
#include <osg/TextureCubeMap>
@@ -301,7 +302,8 @@ struct FrameBufferAttachment::Pimpl
TEXTURE3D,
TEXTURECUBE,
TEXTURERECT,
TEXTURE2DARRAY
TEXTURE2DARRAY,
TEXTURE2DMULTISAMPLE
};
TargetType targetType;
@@ -358,6 +360,12 @@ FrameBufferAttachment::FrameBufferAttachment(Texture2D* target, int level)
_ximpl->textureTarget = target;
}
FrameBufferAttachment::FrameBufferAttachment(Texture2DMultisample* target, int level)
{
_ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLE, level);
_ximpl->textureTarget = target;
}
FrameBufferAttachment::FrameBufferAttachment(Texture3D* target, int zoffset, int level)
{
_ximpl = new Pimpl(Pimpl::TEXTURE3D, level);
@@ -407,6 +415,14 @@ FrameBufferAttachment::FrameBufferAttachment(Camera::Attachment& attachment)
return;
}
osg::Texture2DMultisample* texture2DMS = dynamic_cast<osg::Texture2DMultisample*>(texture);
if (texture2DMS)
{
_ximpl = new Pimpl(Pimpl::TEXTURE2DMULTISAMPLE, attachment._level);
_ximpl->textureTarget = texture2DMS;
return;
}
osg::Texture3D* texture3D = dynamic_cast<osg::Texture3D*>(texture);
if (texture3D)
{
@@ -548,6 +564,9 @@ void FrameBufferAttachment::attach(State &state, GLenum target, GLenum attachmen
case Pimpl::TEXTURE2D:
ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_2D, tobj->_id, _ximpl->level);
break;
case Pimpl::TEXTURE2DMULTISAMPLE:
ext->glFramebufferTexture2DEXT(target, attachment_point, GL_TEXTURE_2D_MULTISAMPLE, tobj->_id, _ximpl->level);
break;
case Pimpl::TEXTURE3D:
ext->glFramebufferTexture3DEXT(target, attachment_point, GL_TEXTURE_3D, tobj->_id, _ximpl->level, _ximpl->zoffset);
break;

View File

@@ -1562,70 +1562,6 @@ void Texture::setExtensions(unsigned int contextID,Extensions* extensions)
}
Texture::Extensions::Extensions(unsigned int contextID)
{
setupGLExtensions(contextID);
}
Texture::Extensions::Extensions(const Extensions& rhs):
Referenced()
{
_isMultiTexturingSupported = rhs._isMultiTexturingSupported;
_isTextureFilterAnisotropicSupported = rhs._isTextureFilterAnisotropicSupported;
_isTextureCompressionARBSupported = rhs._isTextureCompressionARBSupported;
_isTextureCompressionS3TCSupported = rhs._isTextureCompressionS3TCSupported;
_isTextureMirroredRepeatSupported = rhs._isTextureMirroredRepeatSupported;
_isTextureEdgeClampSupported = rhs._isTextureEdgeClampSupported;
_isTextureBorderClampSupported = rhs._isTextureBorderClampSupported;
_isGenerateMipMapSupported = rhs._isGenerateMipMapSupported;
_maxTextureSize = rhs._maxTextureSize;
_glCompressedTexImage2D = rhs._glCompressedTexImage2D;
_isShadowSupported = rhs._isShadowSupported;
_isShadowAmbientSupported = rhs._isShadowAmbientSupported;
_isClientStorageSupported = rhs._isClientStorageSupported;
_isNonPowerOfTwoTextureMipMappedSupported = rhs._isNonPowerOfTwoTextureMipMappedSupported;
_isNonPowerOfTwoTextureNonMipMappedSupported = rhs._isNonPowerOfTwoTextureNonMipMappedSupported;
_isTextureIntegerEXTSupported = rhs._isTextureIntegerEXTSupported;
}
void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs)
{
if (!rhs._isMultiTexturingSupported) _isMultiTexturingSupported = false;
if (!rhs._isTextureFilterAnisotropicSupported) _isTextureFilterAnisotropicSupported = false;
if (!rhs._isTextureMirroredRepeatSupported) _isTextureMirroredRepeatSupported = false;
if (!rhs._isTextureEdgeClampSupported) _isTextureEdgeClampSupported = false;
if (!rhs._isTextureBorderClampSupported) _isTextureBorderClampSupported = false;
if (!rhs._isTextureCompressionARBSupported) _isTextureCompressionARBSupported = false;
if (!rhs._isTextureCompressionS3TCSupported) _isTextureCompressionS3TCSupported = false;
if (!rhs._isGenerateMipMapSupported) _isGenerateMipMapSupported = false;
if (rhs._maxTextureSize<_maxTextureSize) _maxTextureSize = rhs._maxTextureSize;
if (rhs._numTextureUnits<_numTextureUnits) _numTextureUnits = rhs._numTextureUnits;
if (!rhs._glCompressedTexImage2D) _glCompressedTexImage2D = 0;
if (!rhs._glCompressedTexSubImage2D) _glCompressedTexSubImage2D = 0;
if (!rhs._glGetCompressedTexImage) _glGetCompressedTexImage = 0;
if (!rhs._isShadowSupported) _isShadowSupported = false;
if (!rhs._isShadowAmbientSupported) _isShadowAmbientSupported = false;
if (!rhs._isClientStorageSupported) _isClientStorageSupported = false;
if (!rhs._isNonPowerOfTwoTextureMipMappedSupported) _isNonPowerOfTwoTextureMipMappedSupported = false;
if (!rhs._isNonPowerOfTwoTextureNonMipMappedSupported) _isNonPowerOfTwoTextureNonMipMappedSupported = false;
if (!rhs._isTextureIntegerEXTSupported) _isTextureIntegerEXTSupported = false;
}
void Texture::Extensions::setupGLExtensions(unsigned int contextID)
{
const char* version = (const char*) glGetString( GL_VERSION );
if (!version)
@@ -1655,6 +1591,8 @@ void Texture::Extensions::setupGLExtensions(unsigned int contextID)
_isTextureBorderClampSupported = isGLExtensionOrVersionSupported(contextID,"GL_ARB_texture_border_clamp", 1.3f);
_isGenerateMipMapSupported = isGLExtensionOrVersionSupported(contextID,"GL_SGIS_generate_mipmap", 1.4f);
_isTextureMultisampledSupported = isGLExtensionSupported(contextID,"GL_ARB_texture_multisample");
_isShadowSupported = isGLExtensionSupported(contextID,"GL_ARB_shadow");
@@ -1706,73 +1644,12 @@ void Texture::Extensions::setupGLExtensions(unsigned int contextID)
setGLExtensionFuncPtr(_glCompressedTexImage2D,"glCompressedTexImage2D","glCompressedTexImage2DARB");
setGLExtensionFuncPtr(_glCompressedTexSubImage2D,"glCompressedTexSubImage2D","glCompressedTexSubImage2DARB");
setGLExtensionFuncPtr(_glGetCompressedTexImage,"glGetCompressedTexImage","glGetCompressedTexImageARB");;
setGLExtensionFuncPtr(_glTexImage2DMultisample, "glTexImage2DMultisample", "glTexImage2DMultisampleARB");
setGLExtensionFuncPtr(_glTexParameterIiv, "glTexParameterIiv", "glTexParameterIivARB");
setGLExtensionFuncPtr(_glTexParameterIuiv, "glTexParameterIuiv", "glTexParameterIuivARB");
if (_glTexParameterIiv == NULL) setGLExtensionFuncPtr(_glTexParameterIiv, "glTexParameterIivEXT");
if (_glTexParameterIuiv == NULL) setGLExtensionFuncPtr(_glTexParameterIuiv, "glTexParameterIuivEXT");
}
void Texture::Extensions::glTexParameterIiv(GLenum target, GLenum pname, const GLint* data) const
{
if (_glTexParameterIiv)
{
_glTexParameterIiv(target, pname, data);
}
else
{
notify(WARN)<<"Error: glTexParameterIiv not supported by OpenGL driver"<<std::endl;
}
}
void Texture::Extensions::glTexParameterIuiv(GLenum target, GLenum pname, const GLuint* data) const
{
if (_glTexParameterIuiv)
{
_glTexParameterIuiv(target, pname, data);
}
else
{
notify(WARN)<<"Error: glTexParameterIuiv not supported by OpenGL driver"<<std::endl;
}
}
void Texture::Extensions::glCompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) const
{
if (_glCompressedTexImage2D)
{
_glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
else
{
notify(WARN)<<"Error: glCompressedTexImage2D not supported by OpenGL driver"<<std::endl;
}
}
void Texture::Extensions::glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) const
{
if (_glCompressedTexSubImage2D)
{
_glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
else
{
notify(WARN)<<"Error: glCompressedTexImage2D not supported by OpenGL driver"<<std::endl;
}
}
void Texture::Extensions::glGetCompressedTexImage(GLenum target, GLint level, GLvoid *data) const
{
if (_glGetCompressedTexImage)
{
_glGetCompressedTexImage(target, level, data);
}
else
{
notify(WARN)<<"Error: glGetCompressedTexImage not supported by OpenGL driver"<<std::endl;
}
}

View File

@@ -15,6 +15,7 @@
#include <osg/Notify>
#include <osg/Texture1D>
#include <osg/Texture2D>
#include <osg/Texture2DMultisample>
#include <osg/Texture3D>
#include <osg/TextureRectangle>
#include <osg/TextureCubeMap>
@@ -275,6 +276,7 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
osg::Texture* texture = itr->second._texture.get();
osg::Texture1D* texture1D = 0;
osg::Texture2D* texture2D = 0;
osg::Texture2DMultisample* texture2DMS = 0;
osg::Texture3D* texture3D = 0;
osg::TextureCubeMap* textureCubeMap = 0;
osg::TextureRectangle* textureRectangle = 0;
@@ -292,6 +294,13 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo)
texture2D->setTextureSize(width,height);
}
}
else if (0 != (texture2DMS = dynamic_cast<osg::Texture2DMultisample*>(texture)))
{
if (texture2DMS->getTextureWidth()==0 || texture2DMS->getTextureHeight()==0)
{
texture2DMS->setTextureSize(width,height);
}
}
else if (0 != (texture3D = dynamic_cast<osg::Texture3D*>(texture)))
{
if (texture3D->getTextureWidth()==0 || texture3D->getTextureHeight()==0 || texture3D->getTextureDepth()==0 )