openscenegraph
BindImageTexture
Go to the documentation of this file.
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
15#ifndef _GLImageUnitBinding_H
16#define _GLImageUnitBinding_H
17
18#include <osg/Export>
19#include <osg/Texture>
20
21namespace osg
22{
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);
28**/
29class OSG_EXPORT BindImageTexture : public osg::StateAttribute {
30 public:
31 /** Type of access that will be performed on the texture image. */
32 enum Access
33 {
34 NOT_USED = 0,
35 READ_ONLY = GL_READ_ONLY_ARB,
36 WRITE_ONLY = GL_WRITE_ONLY_ARB,
37 READ_WRITE = GL_READ_WRITE_ARB
38 };
39
40 BindImageTexture(
41 GLuint imageunit = 0,
42 osg::Texture* target = 0,
43 Access access = READ_ONLY,
44 GLenum format = GL_RGBA8,
45 int level = 0,
46 bool layered = GL_FALSE,
47 int layer = 0) : osg::StateAttribute(),
48 _target(target),
49 _imageunit(imageunit),
50 _level(level),
51 _layered(layered),
52 _layer(layer),
53 _access(access),
54 _format(format) {}
55
56 BindImageTexture( const BindImageTexture&o,osg::CopyOp op=osg::CopyOp::SHALLOW_COPY):
57 osg::StateAttribute(o,op),
58 _target(o._target),
59 _imageunit(o._imageunit),
60 _level(o._level),
61 _layered(o._layered),
62 _layer(o._layer),
63 _access(o._access),
64 _format(o._format) {}
65
66 virtual ~BindImageTexture() {}
67
68 META_StateAttribute(osg,BindImageTexture, BINDIMAGETEXTURE)
69
70 inline void setImageUnit(GLuint i) { _imageunit=i; }
71 inline GLuint getImageUnit() const { return _imageunit; }
72
73 inline void setLevel(GLint i) { _level=i; }
74 inline GLint getLevel() const { return _level; }
75
76 inline void setIsLayered(GLboolean i) { _layered=i; }
77 inline GLboolean getIsLayered() const { return _layered; }
78
79 inline void setLayer(GLint i) { _layer=i; }
80 inline GLint getLayer() const { return _layer; }
81
82 inline void setAccess(Access i) { _access=i; }
83 inline Access getAccess() const { return _access; }
84
85 inline void setFormat(GLenum i) { _format=i; }
86 inline GLenum getFormat() const { return _format; }
87
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();}
91
92 virtual void apply(osg::State&state) const;
93
94 virtual int compare(const osg::StateAttribute &sa) const;
95
96 virtual unsigned getMember() const { return static_cast<unsigned int>(_imageunit); }
97
98 protected:
99
100 osg::ref_ptr<osg::Texture> _target;
101 GLuint _imageunit;
102 GLint _level;
103 GLboolean _layered;
104 GLint _layer;
105 Access _access;
106 GLenum _format;
107
108};
109
110}
111#endif