BindImageTexture 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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. /// author: Julien Valentin 2017 (mp3butcher@hotmail.com)
  14. #ifndef _GLImageUnitBinding_H
  15. #define _GLImageUnitBinding_H
  16. #include <osg/Export>
  17. #include <osg/Texture>
  18. namespace osg
  19. {
  20. /** Bind texture to an image unit (available only if GL version is 4.2 or greater)
  21. * The format parameter for the image unit need not exactly match the texture internal format,
  22. * but if it is set to 0, the texture internal format will be used.
  23. * See http://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt
  24. * void bindToImageUnit(unsigned int unit, GLenum access, GLenum format=0, int level=0, bool layered=false, int layer=0);
  25. **/
  26. class OSG_EXPORT BindImageTexture : public osg::StateAttribute {
  27. public:
  28. /** Type of access that will be performed on the texture image. */
  29. enum Access
  30. {
  31. NOT_USED = 0,
  32. READ_ONLY = GL_READ_ONLY_ARB,
  33. WRITE_ONLY = GL_WRITE_ONLY_ARB,
  34. READ_WRITE = GL_READ_WRITE_ARB
  35. };
  36. BindImageTexture(
  37. GLuint imageunit = 0,
  38. osg::Texture* target = 0,
  39. Access access = READ_ONLY,
  40. GLenum format = GL_RGBA8,
  41. int level = 0,
  42. bool layered = GL_FALSE,
  43. int layer = 0) : osg::StateAttribute(),
  44. _target(target),
  45. _imageunit(imageunit),
  46. _level(level),
  47. _layered(layered),
  48. _layer(layer),
  49. _access(access),
  50. _format(format) {}
  51. BindImageTexture( const BindImageTexture&o,osg::CopyOp op=osg::CopyOp::SHALLOW_COPY):
  52. osg::StateAttribute(o,op),
  53. _target(o._target),
  54. _imageunit(o._imageunit),
  55. _level(o._level),
  56. _layered(o._layered),
  57. _layer(o._layer),
  58. _access(o._access),
  59. _format(o._format) {}
  60. virtual ~BindImageTexture() {}
  61. META_StateAttribute(osg,BindImageTexture, BINDIMAGETEXTURE)
  62. inline void setImageUnit(GLuint i) { _imageunit=i; }
  63. inline GLuint getImageUnit() const { return _imageunit; }
  64. inline void setLevel(GLint i) { _level=i; }
  65. inline GLint getLevel() const { return _level; }
  66. inline void setIsLayered(GLboolean i) { _layered=i; }
  67. inline GLboolean getIsLayered() const { return _layered; }
  68. inline void setLayer(GLint i) { _layer=i; }
  69. inline GLint getLayer() const { return _layer; }
  70. inline void setAccess(Access i) { _access=i; }
  71. inline Access getAccess() const { return _access; }
  72. inline void setFormat(GLenum i) { _format=i; }
  73. inline GLenum getFormat() const { return _format; }
  74. inline void setTexture(osg::Texture* target) { _target=target; }
  75. inline osg::Texture* getTexture() { return _target.get();}
  76. inline const osg::Texture* getTexture() const { return _target.get();}
  77. virtual void apply(osg::State&state) const;
  78. virtual int compare(const osg::StateAttribute &sa) const;
  79. virtual unsigned getMember() const { return static_cast<unsigned int>(_imageunit); }
  80. protected:
  81. osg::ref_ptr<osg::Texture> _target;
  82. GLuint _imageunit;
  83. GLint _level;
  84. GLboolean _layered;
  85. GLint _layer;
  86. Access _access;
  87. GLenum _format;
  88. };
  89. }
  90. #endif