1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13 * Texture2DMultisample codes Copyright (C) 2010 Marcin Hajder
14 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
17#ifndef OSG_TEXTURE2DMS
18#define OSG_TEXTURE2DMS 1
24 /** Texture2DMultisample state class which encapsulates OpenGL 2D multisampled texture functionality.
25 * Multisampled texture were introduced with OpenGL 3.1 and extension GL_ARB_texture_multisample.
26 * See http://www.opengl.org/registry/specs/ARB/texture_multisample.txt for more info.
29class OSG_EXPORT Texture2DMultisample : public Texture
33 Texture2DMultisample();
35 Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations);
37 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
38 Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
40 META_StateAttribute(osg, Texture2DMultisample,TEXTURE);
42 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
43 virtual int compare(const StateAttribute& rhs) const;
45 virtual GLenum getTextureTarget() const
47 return GL_TEXTURE_2D_MULTISAMPLE;
50 /** Texture2DMultisample is related to non fixed pipeline usage only so isn't appropriate to enable/disable.*/
51 virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; }
53 /** Sets the texture width and height. If width or height are zero,
54 * calculate the respective value from the source image size. */
55 inline void setTextureSize(int width, int height) const
57 _textureWidth = width;
58 _textureHeight = height;
61 inline void setNumSamples( int samples ) { _numSamples = samples; }
62 GLsizei getNumSamples() const { return _numSamples; }
64 inline void setFixedSampleLocations( GLboolean fixedSampleLocations ) { _fixedsamplelocations = fixedSampleLocations; }
65 inline GLboolean getFixedSampleLocations() const { return _fixedsamplelocations; }
67 // unnecessary for Texture2DMultisample
68 virtual void setImage(unsigned int /*face*/, Image* /*image*/) {}
70 virtual Image* getImage(unsigned int /*face*/) { return NULL; }
71 virtual const Image* getImage(unsigned int /*face*/) const { return NULL; }
72 virtual unsigned int getNumImages() const {return 0; }
73 virtual void allocateMipmap(State& /*state*/) const {}
75 void setTextureWidth(int width) { _textureWidth=width; }
76 void setTextureHeight(int height) { _textureHeight=height; }
78 virtual int getTextureWidth() const { return _textureWidth; }
79 virtual int getTextureHeight() const { return _textureHeight; }
80 virtual int getTextureDepth() const { return 1; }
82 /** Bind the texture object. If the texture object hasn't already been
83 * compiled, create the texture mipmap levels. */
84 virtual void apply(State& state) const;
88 virtual ~Texture2DMultisample();
90 virtual void computeInternalFormat() const;
92 /** Subloaded images can have different texture and image sizes. */
93 mutable GLsizei _textureWidth, _textureHeight;
95 mutable GLsizei _numSamples;
97 mutable GLboolean _fixedsamplelocations;