Sampler 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* -*-c++-*-
  2. * Copyright (C) 2017 Julien Valentin <mp3butcher@hotmail.com>
  3. *
  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.
  8. *
  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.
  13. */
  14. #ifndef OSG_SAMPLER_H
  15. #define OSG_SAMPLER_H 1
  16. #include <osg/Texture>
  17. namespace osg{
  18. /** OpenGL Sampler
  19. * OpenGL 3.3 required
  20. * https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sampler_objects.txt
  21. * State Attribute controllig sampling instead of Texture
  22. * Sampler is prioritary over Texture sample parameter (don't play with both)
  23. */
  24. class OSG_EXPORT Sampler : public osg::StateAttribute
  25. {
  26. public:
  27. Sampler();
  28. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  29. Sampler(const Sampler& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  30. META_StateAttribute(osg,Sampler,SAMPLER)
  31. virtual bool isTextureAttribute() const { return true; }
  32. /** Sets the texture wrap mode. */
  33. void setWrap(Texture::WrapParameter which, Texture::WrapMode wrap);
  34. /** Gets the texture wrap mode. */
  35. Texture::WrapMode getWrap(Texture::WrapParameter which) const;
  36. /** Sets the texture filter mode. */
  37. void setFilter(Texture::FilterParameter which, Texture::FilterMode filter);
  38. /** Gets the texture filter mode. */
  39. Texture::FilterMode getFilter(Texture::FilterParameter which) const;
  40. /** Sets shadow texture comparison function. */
  41. void setShadowCompareFunc(Texture::ShadowCompareFunc func);
  42. Texture::ShadowCompareFunc getShadowCompareFunc() const { return _shadow_compare_func; }
  43. /** Sets shadow texture mode after comparison. */
  44. void setShadowTextureMode(Texture::ShadowTextureMode mode);
  45. Texture::ShadowTextureMode getShadowTextureMode() const { return _shadow_texture_mode; }
  46. /** Sets the border color. Only used when wrap mode is CLAMP_TO_BORDER.
  47. * The border color will be casted to the appropriate type to match the
  48. * internal pixel format of the texture. */
  49. void setBorderColor(const Vec4d& color);
  50. /** Gets the border color. */
  51. const Vec4d& getBorderColor() const { return _borderColor; }
  52. /** Sets the maximum anisotropy value, default value is 1.0 for no
  53. * anisotropic filtering. If hardware does not support anisotropic
  54. * filtering, use normal filtering (equivalent to a max anisotropy
  55. * value of 1.0. Valid range is 1.0f upwards. The maximum value
  56. * depends on the graphics system. */
  57. void setMaxAnisotropy(float anis);
  58. /** Gets the maximum anisotropy value. */
  59. inline float getMaxAnisotropy() const { return _maxAnisotropy; }
  60. void setMinLOD(float anis);
  61. /** Gets the maximum anisotropy value. */
  62. inline float getMinLOD() const { return _minlod; }
  63. void setMaxLOD(float anis);
  64. /** Gets the maximum anisotropy value. */
  65. inline float getMaxLOD() const { return _maxlod; }
  66. void setLODBias(float anis);
  67. /** Gets the maximum anisotropy value. */
  68. inline float getLODBias() const { return _lodbias; }
  69. /** helper method to generate Sampler from Texture's sampling parameters (except shadow_texture_mode left to NONE) */
  70. static void generateSamplerObjects(StateSet&);
  71. virtual void apply(State& state) const;
  72. virtual void compileGLObjects(State&) const;
  73. /** release state's SamplerObject **/
  74. virtual void releaseGLObjects(State* state=0) const;
  75. virtual int compare(const StateAttribute& sa) const;
  76. protected:
  77. Texture::WrapMode _wrap_s;
  78. Texture::WrapMode _wrap_t;
  79. Texture::WrapMode _wrap_r;
  80. Texture::ShadowCompareFunc _shadow_compare_func;
  81. Texture::ShadowTextureMode _shadow_texture_mode;
  82. Vec4d _borderColor;
  83. Texture::FilterMode _min_filter;
  84. Texture::FilterMode _mag_filter;
  85. float _maxAnisotropy, _minlod, _maxlod, _lodbias;
  86. mutable buffered_value<GLuint> _PCsampler;
  87. mutable buffered_value<uint8_t> _PCdirtyflags;
  88. };
  89. }
  90. #endif