File: Sampler

package info (click to toggle)
openscenegraph 3.6.5%2Bdfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,028 kB
  • sloc: cpp: 392,065; ansic: 21,495; java: 1,020; yacc: 548; makefile: 430; objc: 406; xml: 155; lex: 151; javascript: 34
file content (121 lines) | stat: -rw-r--r-- 4,601 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*  -*-c++-*-
 *  Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/
#ifndef OSG_SAMPLER_H
#define OSG_SAMPLER_H 1

#include <osg/Texture>

namespace osg{
/**  OpenGL Sampler
 *   OpenGL 3.3 required
 *   https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sampler_objects.txt
 *   State Attribute controllig sampling instead of Texture
 *   Sampler is prioritary over Texture sample parameter (don't play with both)
*/


class OSG_EXPORT Sampler : public osg::StateAttribute
{
    public:
        Sampler();

        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
        Sampler(const Sampler& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);

        META_StateAttribute(osg,Sampler,SAMPLER)

        virtual bool isTextureAttribute() const { return true; }

        /** Sets the texture wrap mode. */
        void setWrap(Texture::WrapParameter which, Texture::WrapMode wrap);

        /** Gets the texture wrap mode. */
        Texture::WrapMode getWrap(Texture::WrapParameter which) const;

        /** Sets the texture filter mode. */
        void setFilter(Texture::FilterParameter which, Texture::FilterMode filter);

        /** Gets the texture filter mode. */
        Texture::FilterMode getFilter(Texture::FilterParameter which) const;

        /** Sets shadow texture comparison function. */
        void setShadowCompareFunc(Texture::ShadowCompareFunc func);
        Texture::ShadowCompareFunc getShadowCompareFunc() const { return _shadow_compare_func; }

        /** Sets shadow texture mode after comparison. */
        void setShadowTextureMode(Texture::ShadowTextureMode mode);
        Texture::ShadowTextureMode getShadowTextureMode() const { return _shadow_texture_mode; }

        /** Sets the border color. Only used when wrap mode is CLAMP_TO_BORDER.
         * The border color will be casted to the appropriate type to match the
         * internal pixel format of the texture. */
        void setBorderColor(const Vec4d& color);

        /** Gets the border color. */
        const Vec4d& getBorderColor() const { return _borderColor; }

        /** Sets the maximum anisotropy value, default value is 1.0 for no
          * anisotropic filtering. If hardware does not support anisotropic
          * filtering, use normal filtering (equivalent to a max anisotropy
          * value of 1.0. Valid range is 1.0f upwards.  The maximum value
          * depends on the graphics system. */
        void setMaxAnisotropy(float anis);

        /** Gets the maximum anisotropy value. */
        inline float getMaxAnisotropy() const { return _maxAnisotropy; }

        void setMinLOD(float anis);

        /** Gets the maximum anisotropy value. */
        inline float getMinLOD() const { return _minlod; }

        void setMaxLOD(float anis);

        /** Gets the maximum anisotropy value. */
        inline float getMaxLOD() const { return _maxlod; }

        void setLODBias(float anis);

        /** Gets the maximum anisotropy value. */
        inline float getLODBias() const { return _lodbias; }

        /** helper method to generate Sampler from Texture's sampling parameters (except shadow_texture_mode left to NONE) */
        static void generateSamplerObjects(StateSet&);

        virtual void apply(State& state) const;

        virtual void compileGLObjects(State&) const;

        /** release state's SamplerObject **/
        virtual void releaseGLObjects(State* state=0) const;

        virtual int compare(const StateAttribute& sa) const;

    protected:
        Texture::WrapMode _wrap_s;
        Texture::WrapMode _wrap_t;
        Texture::WrapMode _wrap_r;
        Texture::ShadowCompareFunc _shadow_compare_func;
        Texture::ShadowTextureMode _shadow_texture_mode;
        Vec4d _borderColor;

        Texture::FilterMode _min_filter;
        Texture::FilterMode _mag_filter;
        float _maxAnisotropy, _minlod, _maxlod, _lodbias;

        mutable buffered_value<GLuint> _PCsampler;
        mutable buffered_value<uint8_t> _PCdirtyflags;
};
}
#endif