| 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 | |
|---|
| 22 | namespace 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 | |
|---|
| 29 | class 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 | /** Sets the texture width and height. If width or height are zero, |
|---|
| 51 | * calculate the respective value from the source image size. */ |
|---|
| 52 | inline void setTextureSize(int width, int height) const |
|---|
| 53 | { |
|---|
| 54 | _textureWidth = width; |
|---|
| 55 | _textureHeight = height; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | inline void setNumSamples( int samples ) { _numSamples = samples; } |
|---|
| 59 | |
|---|
| 60 | // unnecessary for Texture2DMultisample |
|---|
| 61 | virtual void setImage(unsigned int /*face*/, Image* /*image*/) {} |
|---|
| 62 | virtual Image* getImage(unsigned int /*face*/) { return NULL; } |
|---|
| 63 | virtual const Image* getImage(unsigned int /*face*/) const { return NULL; } |
|---|
| 64 | virtual unsigned int getNumImages() const {return 0; } |
|---|
| 65 | virtual void allocateMipmap(State& /*state*/) const {} |
|---|
| 66 | |
|---|
| 67 | void setTextureWidth(int width) { _textureWidth=width; } |
|---|
| 68 | void setTextureHeight(int height) { _textureHeight=height; } |
|---|
| 69 | |
|---|
| 70 | virtual int getTextureWidth() const { return _textureWidth; } |
|---|
| 71 | virtual int getTextureHeight() const { return _textureHeight; } |
|---|
| 72 | virtual int getTextureDepth() const { return 1; } |
|---|
| 73 | |
|---|
| 74 | /** Bind the texture object. If the texture object hasn't already been |
|---|
| 75 | * compiled, create the texture mipmap levels. */ |
|---|
| 76 | virtual void apply(State& state) const; |
|---|
| 77 | |
|---|
| 78 | protected : |
|---|
| 79 | |
|---|
| 80 | virtual ~Texture2DMultisample(); |
|---|
| 81 | |
|---|
| 82 | virtual void computeInternalFormat() const; |
|---|
| 83 | |
|---|
| 84 | /** Subloaded images can have different texture and image sizes. */ |
|---|
| 85 | mutable GLsizei _textureWidth, _textureHeight; |
|---|
| 86 | |
|---|
| 87 | mutable GLsizei _numSamples; |
|---|
| 88 | |
|---|
| 89 | mutable GLboolean _fixedsamplelocations; |
|---|
| 90 | |
|---|
| 91 | }; |
|---|
| 92 | |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | #endif |
|---|