openscenegraph
Texture2DMultisample
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
2 *
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.
7 *
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.
12 *
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.
15*/
16
17#ifndef OSG_TEXTURE2DMS
18#define OSG_TEXTURE2DMS 1
19
20#include <osg/Texture>
21
22namespace osg {
23
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.
27 */
28
29class OSG_EXPORT Texture2DMultisample : public Texture
30{
31 public :
32
33 Texture2DMultisample();
34
35 Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations);
36
37 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
38 Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
39
40 META_StateAttribute(osg, Texture2DMultisample,TEXTURE);
41
42 /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
43 virtual int compare(const StateAttribute& rhs) const;
44
45 virtual GLenum getTextureTarget() const
46 {
47 return GL_TEXTURE_2D_MULTISAMPLE;
48 }
49
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; }
52
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
56 {
57 _textureWidth = width;
58 _textureHeight = height;
59 }
60
61 inline void setNumSamples( int samples ) { _numSamples = samples; }
62 GLsizei getNumSamples() const { return _numSamples; }
63
64 inline void setFixedSampleLocations( GLboolean fixedSampleLocations ) { _fixedsamplelocations = fixedSampleLocations; }
65 inline GLboolean getFixedSampleLocations() const { return _fixedsamplelocations; }
66
67 // unnecessary for Texture2DMultisample
68 virtual void setImage(unsigned int /*face*/, Image* /*image*/) {}
69
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 {}
74
75 void setTextureWidth(int width) { _textureWidth=width; }
76 void setTextureHeight(int height) { _textureHeight=height; }
77
78 virtual int getTextureWidth() const { return _textureWidth; }
79 virtual int getTextureHeight() const { return _textureHeight; }
80 virtual int getTextureDepth() const { return 1; }
81
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;
85
86 protected :
87
88 virtual ~Texture2DMultisample();
89
90 virtual void computeInternalFormat() const;
91
92 /** Subloaded images can have different texture and image sizes. */
93 mutable GLsizei _textureWidth, _textureHeight;
94
95 mutable GLsizei _numSamples;
96
97 mutable GLboolean _fixedsamplelocations;
98
99};
100
101}
102
103#endif