X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fsampler.h;h=c79068775b144499943196b316dc0f8f0406f75b;hp=e1e9bec5d60332e5331cd6e1e52e421c5256e8e9;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/core/sampler.h b/source/core/sampler.h index e1e9bec5..c7906877 100644 --- a/source/core/sampler.h +++ b/source/core/sampler.h @@ -2,8 +2,9 @@ #define MSP_GL_SAMPLER_H_ #include -#include "gl.h" +#include "color.h" #include "predicate.h" +#include "sampler_backend.h" namespace Msp { namespace GL { @@ -11,39 +12,40 @@ namespace GL { enum TextureFilter { /// No filtering - NEAREST = GL_NEAREST, + NEAREST, /// Bilinear filtering - LINEAR = GL_LINEAR, + LINEAR, /// Mipmapping without filtering - NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST, + NEAREST_MIPMAP_NEAREST, /// Linear filtering between two mipmap levels - NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR, + NEAREST_MIPMAP_LINEAR, /// Bilinear filtering on the closest mipmap level - LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST, + LINEAR_MIPMAP_NEAREST, /// Trilinear filtering between two mipmap levels - LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR + LINEAR_MIPMAP_LINEAR }; enum TextureWrap { /// Tile the texture infinitely - REPEAT = GL_REPEAT, + REPEAT, /// Extend the texels at the edge of the texture to infinity - CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE, + CLAMP_TO_EDGE, + + /// Sampling outside the texture will return border color + CLAMP_TO_BORDER, /// Tile the texture, with every other repetition mirrored - MIRRORED_REPEAT = GL_MIRRORED_REPEAT + MIRRORED_REPEAT }; -class Texture; - /** Samplers are used to access texture data in shaders. To use a sampler with a @@ -59,8 +61,10 @@ for magnification and NEAREST_MIPMAP_LINEAR for minification. If texture coordinates fall outside of the principal range of the texture, wrapping is applied. The default for all directions is REPEAT. */ -class Sampler +class Sampler: public SamplerBackend { + friend SamplerBackend; + public: class Loader: public DataFile::ObjectLoader { @@ -69,6 +73,8 @@ public: private: void init(); + void border_color(float, float, float, float); + void compare(Predicate); void filter(TextureFilter); void mag_filter(TextureFilter); void max_anisotropy(float); @@ -88,30 +94,22 @@ private: WRAP_S = 8, WRAP_T = 16, WRAP_R = 32, - COMPARE = 64 + BORDER_COLOR = 64, + COMPARE = 128 }; - unsigned id; - const Texture *owner; - TextureFilter min_filter; - TextureFilter mag_filter; - float max_anisotropy; - TextureWrap wrap_s; - TextureWrap wrap_t; - TextureWrap wrap_r; - bool compare; - Predicate cmp_func; - mutable int dirty_params; - -public: - Sampler(); - Sampler(const Texture &); -private: - void init(); + TextureFilter min_filter = NEAREST_MIPMAP_LINEAR; + TextureFilter mag_filter = LINEAR; + float max_anisotropy = 1.0f; + TextureWrap wrap_s = REPEAT; + TextureWrap wrap_t = REPEAT; + TextureWrap wrap_r = REPEAT; + Color border_color = { 0.0f, 0.0f, 0.0f, 0.0f }; + bool compare = false; + Predicate cmp_func = LEQUAL; + mutable int dirty_params = 0; - void update_parameter(int) const; - void set_parameter_i(unsigned, int) const; - void set_parameter_f(unsigned, float) const; + void update() const; public: void set_min_filter(TextureFilter); @@ -134,6 +132,9 @@ public: void set_wrap_t(TextureWrap); void set_wrap_r(TextureWrap); + void set_border_color(const Color &); + const Color &get_border_color() const { return border_color; } + /** Disables depth comparison. */ void disable_compare(); @@ -146,14 +147,9 @@ public: bool is_compare_enabled() const { return compare; } Predicate get_compare_function() const { return cmp_func; } - void bind() const { bind_to(0); } - void bind_to(unsigned) const; - - static const Sampler *current(unsigned = 0); - static void unbind() { unbind_from(0); } - static void unbind_from(unsigned); + void refresh() const { if(dirty_params) update(); } - void unload(); + using SamplerBackend::set_debug_name; };