Texture2DMultisample 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef OSG_TEXTURE2DMS
  17. #define OSG_TEXTURE2DMS 1
  18. #include <osg/Texture>
  19. namespace osg {
  20. /** Texture2DMultisample state class which encapsulates OpenGL 2D multisampled texture functionality.
  21. * Multisampled texture were introduced with OpenGL 3.1 and extension GL_ARB_texture_multisample.
  22. * See http://www.opengl.org/registry/specs/ARB/texture_multisample.txt for more info.
  23. */
  24. class OSG_EXPORT Texture2DMultisample : public Texture
  25. {
  26. public :
  27. Texture2DMultisample();
  28. Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations);
  29. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  30. Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  31. META_StateAttribute(osg, Texture2DMultisample,TEXTURE);
  32. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  33. virtual int compare(const StateAttribute& rhs) const;
  34. virtual GLenum getTextureTarget() const
  35. {
  36. return GL_TEXTURE_2D_MULTISAMPLE;
  37. }
  38. /** Texture2DMultisample is related to non fixed pipeline usage only so isn't appropriate to enable/disable.*/
  39. virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; }
  40. /** Sets the texture width and height. If width or height are zero,
  41. * calculate the respective value from the source image size. */
  42. inline void setTextureSize(int width, int height) const
  43. {
  44. _textureWidth = width;
  45. _textureHeight = height;
  46. }
  47. inline void setNumSamples( int samples ) { _numSamples = samples; }
  48. GLsizei getNumSamples() const { return _numSamples; }
  49. inline void setFixedSampleLocations( GLboolean fixedSampleLocations ) { _fixedsamplelocations = fixedSampleLocations; }
  50. inline GLboolean getFixedSampleLocations() const { return _fixedsamplelocations; }
  51. // unnecessary for Texture2DMultisample
  52. virtual void setImage(unsigned int /*face*/, Image* /*image*/) {}
  53. virtual Image* getImage(unsigned int /*face*/) { return NULL; }
  54. virtual const Image* getImage(unsigned int /*face*/) const { return NULL; }
  55. virtual unsigned int getNumImages() const {return 0; }
  56. virtual void allocateMipmap(State& /*state*/) const {}
  57. void setTextureWidth(int width) { _textureWidth=width; }
  58. void setTextureHeight(int height) { _textureHeight=height; }
  59. virtual int getTextureWidth() const { return _textureWidth; }
  60. virtual int getTextureHeight() const { return _textureHeight; }
  61. virtual int getTextureDepth() const { return 1; }
  62. /** Bind the texture object. If the texture object hasn't already been
  63. * compiled, create the texture mipmap levels. */
  64. virtual void apply(State& state) const;
  65. protected :
  66. virtual ~Texture2DMultisample();
  67. virtual void computeInternalFormat() const;
  68. /** Subloaded images can have different texture and image sizes. */
  69. mutable GLsizei _textureWidth, _textureHeight;
  70. mutable GLsizei _numSamples;
  71. mutable GLboolean _fixedsamplelocations;
  72. };
  73. }
  74. #endif