2 * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version. The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * OpenSceneGraph Public License for more details.
15#define OSG_SAMPLER_H 1
22 * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sampler_objects.txt
23 * State Attribute controllig sampling instead of Texture
24 * Sampler is prioritary over Texture sample parameter (don't play with both)
28class OSG_EXPORT Sampler : public osg::StateAttribute
33 /** Copy constructor using CopyOp to manage deep vs shallow copy. */
34 Sampler(const Sampler& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
36 META_StateAttribute(osg,Sampler,SAMPLER)
38 virtual bool isTextureAttribute() const { return true; }
40 /** Sets the texture wrap mode. */
41 void setWrap(Texture::WrapParameter which, Texture::WrapMode wrap);
43 /** Gets the texture wrap mode. */
44 Texture::WrapMode getWrap(Texture::WrapParameter which) const;
46 /** Sets the texture filter mode. */
47 void setFilter(Texture::FilterParameter which, Texture::FilterMode filter);
49 /** Gets the texture filter mode. */
50 Texture::FilterMode getFilter(Texture::FilterParameter which) const;
52 /** Sets shadow texture comparison function. */
53 void setShadowCompareFunc(Texture::ShadowCompareFunc func);
54 Texture::ShadowCompareFunc getShadowCompareFunc() const { return _shadow_compare_func; }
56 /** Sets shadow texture mode after comparison. */
57 void setShadowTextureMode(Texture::ShadowTextureMode mode);
58 Texture::ShadowTextureMode getShadowTextureMode() const { return _shadow_texture_mode; }
60 /** Sets the border color. Only used when wrap mode is CLAMP_TO_BORDER.
61 * The border color will be casted to the appropriate type to match the
62 * internal pixel format of the texture. */
63 void setBorderColor(const Vec4d& color);
65 /** Gets the border color. */
66 const Vec4d& getBorderColor() const { return _borderColor; }
68 /** Sets the maximum anisotropy value, default value is 1.0 for no
69 * anisotropic filtering. If hardware does not support anisotropic
70 * filtering, use normal filtering (equivalent to a max anisotropy
71 * value of 1.0. Valid range is 1.0f upwards. The maximum value
72 * depends on the graphics system. */
73 void setMaxAnisotropy(float anis);
75 /** Gets the maximum anisotropy value. */
76 inline float getMaxAnisotropy() const { return _maxAnisotropy; }
78 void setMinLOD(float anis);
80 /** Gets the maximum anisotropy value. */
81 inline float getMinLOD() const { return _minlod; }
83 void setMaxLOD(float anis);
85 /** Gets the maximum anisotropy value. */
86 inline float getMaxLOD() const { return _maxlod; }
88 void setLODBias(float anis);
90 /** Gets the maximum anisotropy value. */
91 inline float getLODBias() const { return _lodbias; }
93 /** helper method to generate Sampler from Texture's sampling parameters (except shadow_texture_mode left to NONE) */
94 static void generateSamplerObjects(StateSet&);
96 virtual void apply(State& state) const;
98 virtual void compileGLObjects(State&) const;
100 /** release state's SamplerObject **/
101 virtual void releaseGLObjects(State* state=0) const;
103 virtual int compare(const StateAttribute& sa) const;
106 Texture::WrapMode _wrap_s;
107 Texture::WrapMode _wrap_t;
108 Texture::WrapMode _wrap_r;
109 Texture::ShadowCompareFunc _shadow_compare_func;
110 Texture::ShadowTextureMode _shadow_texture_mode;
113 Texture::FilterMode _min_filter;
114 Texture::FilterMode _mag_filter;
115 float _maxAnisotropy, _minlod, _maxlod, _lodbias;
117 mutable buffered_value<GLuint> _PCsampler;
118 mutable buffered_value<uint8_t> _PCdirtyflags;