TextureBuffer 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 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. // -*-c++-*-
  14. #ifndef OSG_TEXTUREBUFFEROBJECT
  15. #define OSG_TEXTUREBUFFEROBJECT 1
  16. #include <osg/Texture>
  17. #include <osg/BufferObject>
  18. namespace osg {
  19. /** Encapsulates OpenGL texture buffer functionality in a Texture delegating its content to attached BufferObject
  20. */
  21. class OSG_EXPORT TextureBuffer : public Texture
  22. {
  23. public :
  24. TextureBuffer();
  25. TextureBuffer(BufferData* image);
  26. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  27. TextureBuffer(const TextureBuffer& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  28. META_StateAttribute(osg, TextureBuffer, TEXTURE);
  29. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  30. virtual int compare(const StateAttribute& rhs) const;
  31. virtual GLenum getTextureTarget() const { return GL_TEXTURE_BUFFER; }
  32. /** Sets the texture image. */
  33. void setImage(Image* image);
  34. /** Gets the texture image. */
  35. Image* getImage() { return dynamic_cast<Image*>(_bufferData.get() ); }
  36. /** Gets the const texture image. */
  37. inline const Image* getImage() const { return dynamic_cast<Image*>(_bufferData.get() ); }
  38. /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/
  39. virtual bool isDirty(unsigned int contextID) const { return (_bufferData.valid() && _bufferData->getModifiedCount()!=_modifiedCount[contextID]); }
  40. inline unsigned int & getModifiedCount(unsigned int contextID) const
  41. {
  42. // get the modified count for the current contextID.
  43. return _modifiedCount[contextID];
  44. }
  45. /** Sets the texture image, ignoring face. */
  46. virtual void setImage(unsigned int, Image* image) { setImage(image); }
  47. /** Gets the texture image, ignoring face. */
  48. virtual Image* getImage(unsigned int) { return getImage(); }
  49. /** Gets the const texture image, ignoring face. */
  50. virtual const Image* getImage(unsigned int) const { return getImage(); }
  51. /** Gets the number of images that can be assigned to the Texture. */
  52. virtual unsigned int getNumImages() const { return 1; }
  53. /** Sets the texture width. If width is zero, calculate the value
  54. * from the source image width. */
  55. inline void setTextureWidth(int width) { _textureWidth = width; }
  56. /** Gets the texture width. */
  57. virtual int getTextureWidth() const { return _textureWidth; }
  58. virtual int getTextureHeight() const { return 1; }
  59. virtual int getTextureDepth() const { return 1; }
  60. virtual void allocateMipmap(State& /*state*/) const {};
  61. /** Bind the texture buffer.*/
  62. virtual void apply(State& state) const;
  63. /** Set setBufferData attached */
  64. void setBufferData(BufferData *bo);
  65. /** Set setBufferData attached */
  66. const BufferData * getBufferData()const {return _bufferData.get();}
  67. protected :
  68. virtual ~TextureBuffer();
  69. virtual void computeInternalFormat() const;
  70. ref_ptr< BufferData > _bufferData;
  71. GLsizei _textureWidth;
  72. typedef buffered_value< unsigned int > BufferDataModifiedCount;
  73. mutable BufferDataModifiedCount _modifiedCount;
  74. };
  75. }
  76. #endif