1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
13/// author: Julien Valentin 2017 (mp3butcher@hotmail.com)
15#ifndef _GLImageUnitBinding_H
16#define _GLImageUnitBinding_H
23/** Bind texture to an image unit (available only if GL version is 4.2 or greater)
24* The format parameter for the image unit need not exactly match the texture internal format,
25* but if it is set to 0, the texture internal format will be used.
26* See http://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt
27* void bindToImageUnit(unsigned int unit, GLenum access, GLenum format=0, int level=0, bool layered=false, int layer=0);
29class OSG_EXPORT BindImageTexture : public osg::StateAttribute {
31 /** Type of access that will be performed on the texture image. */
35 READ_ONLY = GL_READ_ONLY_ARB,
36 WRITE_ONLY = GL_WRITE_ONLY_ARB,
37 READ_WRITE = GL_READ_WRITE_ARB
42 osg::Texture* target = 0,
43 Access access = READ_ONLY,
44 GLenum format = GL_RGBA8,
46 bool layered = GL_FALSE,
47 int layer = 0) : osg::StateAttribute(),
49 _imageunit(imageunit),
56 BindImageTexture( const BindImageTexture&o,osg::CopyOp op=osg::CopyOp::SHALLOW_COPY):
57 osg::StateAttribute(o,op),
59 _imageunit(o._imageunit),
66 virtual ~BindImageTexture() {}
68 META_StateAttribute(osg,BindImageTexture, BINDIMAGETEXTURE)
70 inline void setImageUnit(GLuint i) { _imageunit=i; }
71 inline GLuint getImageUnit() const { return _imageunit; }
73 inline void setLevel(GLint i) { _level=i; }
74 inline GLint getLevel() const { return _level; }
76 inline void setIsLayered(GLboolean i) { _layered=i; }
77 inline GLboolean getIsLayered() const { return _layered; }
79 inline void setLayer(GLint i) { _layer=i; }
80 inline GLint getLayer() const { return _layer; }
82 inline void setAccess(Access i) { _access=i; }
83 inline Access getAccess() const { return _access; }
85 inline void setFormat(GLenum i) { _format=i; }
86 inline GLenum getFormat() const { return _format; }
88 inline void setTexture(osg::Texture* target) { _target=target; }
89 inline osg::Texture* getTexture() { return _target.get();}
90 inline const osg::Texture* getTexture() const { return _target.get();}
92 virtual void apply(osg::State&state) const;
94 virtual int compare(const osg::StateAttribute &sa) const;
96 virtual unsigned getMember() const { return static_cast<unsigned int>(_imageunit); }
100 osg::ref_ptr<osg::Texture> _target;