From Marcin Hajder, "This submission contains Texture2DMultisample osg implementation.
Texture2DMultismaple as name suggests provides means to directly access subsamples of rendered FBO target. (GLSL 1.5 texelFetch call). Recently I was working on deferred renderer with OSG, during that I noticed there is no support for multisampled textures (GL_ARB_texture_multisample extension). After consultations with Paul Martz and Wojtek Lewandowski I added Texture2DMultisample class and made few necessary changes around osg::FrameBufferObject, osg::Texture and osgUtil::RenderStage classes." and from follow email: "Fixed. According to ARB_texture_multisample extension specification multisample textures don't need TexParameters since they can only be fetched with texelFetch."
This commit is contained in:
@@ -345,6 +345,7 @@ namespace osg
|
||||
**************************************************************************/
|
||||
class Texture1D;
|
||||
class Texture2D;
|
||||
class Texture2DMultisample;
|
||||
class Texture3D;
|
||||
class Texture2DArray;
|
||||
class TextureCubeMap;
|
||||
@@ -359,6 +360,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);
|
||||
|
||||
@@ -222,6 +222,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
|
||||
@@ -619,7 +623,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
|
||||
|
||||
void setTextureFilterAnisotropicSupported(bool flag) { _isTextureFilterAnisotropicSupported=flag; }
|
||||
bool isTextureFilterAnisotropicSupported() const { return _isTextureFilterAnisotropicSupported; }
|
||||
|
||||
|
||||
void setTextureCompressionARBSupported(bool flag) { _isTextureCompressionARBSupported=flag; }
|
||||
bool isTextureCompressionARBSupported() const { return _isTextureCompressionARBSupported; }
|
||||
|
||||
@@ -638,6 +642,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; }
|
||||
|
||||
@@ -683,6 +690,11 @@ class OSG_EXPORT Texture : public osg::StateAttribute
|
||||
_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);
|
||||
@@ -696,16 +708,18 @@ class OSG_EXPORT Texture : public osg::StateAttribute
|
||||
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;
|
||||
|
||||
@@ -718,6 +732,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
|
||||
bool _isTextureEdgeClampSupported;
|
||||
bool _isTextureBorderClampSupported;
|
||||
bool _isGenerateMipMapSupported;
|
||||
bool _isTextureMultisampledSupported;
|
||||
bool _isShadowSupported;
|
||||
bool _isShadowAmbientSupported;
|
||||
bool _isClientStorageSupported;
|
||||
@@ -761,6 +776,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
|
||||
|
||||
95
include/osg/Texture2DMultisample
Normal file
95
include/osg/Texture2DMultisample
Normal file
@@ -0,0 +1,95 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*
|
||||
* Texture2DMultisample codes Copyright (C) 2010 Marcin Hajder
|
||||
* Thanks to to my company http://www.ai.com.pl for allowing me free this work.
|
||||
*/
|
||||
|
||||
#ifndef OSG_TEXTURE2DMS
|
||||
#define OSG_TEXTURE2DMS 1
|
||||
|
||||
#include <osg/Texture>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Texture2DMultisample state class which encapsulates OpenGL 2D multisampled texture functionality.
|
||||
* Multisampled texture were introduced with OpenGL 3.1 and extension GL_ARB_texture_multisample.
|
||||
* See http://www.opengl.org/registry/specs/ARB/texture_multisample.txt for more info.
|
||||
*/
|
||||
|
||||
class OSG_EXPORT Texture2DMultisample : public Texture
|
||||
{
|
||||
public :
|
||||
|
||||
Texture2DMultisample();
|
||||
|
||||
Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations);
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Texture2DMultisample,TEXTURE);
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual GLenum getTextureTarget() const
|
||||
{
|
||||
return GL_TEXTURE_2D_MULTISAMPLE;
|
||||
}
|
||||
|
||||
/** Sets the texture width and height. If width or height are zero,
|
||||
* calculate the respective value from the source image size. */
|
||||
inline void setTextureSize(int width, int height) const
|
||||
{
|
||||
_textureWidth = width;
|
||||
_textureHeight = height;
|
||||
}
|
||||
|
||||
inline void setNumSamples( int samples ) { _numSamples = samples; }
|
||||
|
||||
// unnecessary for Texture2DMultisample
|
||||
virtual void setImage(unsigned int face, Image* image){}
|
||||
virtual Image* getImage(unsigned int face){return NULL;}
|
||||
virtual const Image* getImage(unsigned int face) const{return NULL;}
|
||||
virtual unsigned int getNumImages() const{return 0;}
|
||||
virtual void allocateMipmap(State& state) const {}
|
||||
|
||||
void setTextureWidth(int width) { _textureWidth=width; }
|
||||
void setTextureHeight(int height) { _textureHeight=height; }
|
||||
|
||||
virtual int getTextureWidth() const { return _textureWidth; }
|
||||
virtual int getTextureHeight() const { return _textureHeight; }
|
||||
virtual int getTextureDepth() const { return 1; }
|
||||
|
||||
/** Bind the texture object. If the texture object hasn't already been
|
||||
* compiled, create the texture mipmap levels. */
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~Texture2DMultisample();
|
||||
|
||||
virtual void computeInternalFormat() const;
|
||||
|
||||
/** Subloaded images can have different texture and image sizes. */
|
||||
mutable GLsizei _textureWidth, _textureHeight;
|
||||
|
||||
mutable GLsizei _numSamples;
|
||||
|
||||
mutable GLboolean _fixedsamplelocations;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user