Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_sampler_object.hpp
1#pragma once
2
3#include "structure/design_pattern/spk_activable_object.hpp"
4#include "structure/opengl/spk_opengl_includes.hpp"
5#include "structure/opengl/spk_texture_object.hpp"
6#include "utils/spk_opengl_utils.hpp"
7#include <stdexcept>
8
9namespace spk
10{
11 namespace OpenGL
12 {
18 {
19 private:
20 const TextureObject *_texture = nullptr;
21 GLuint _textureUnitIndex;
22 GLint _uniformLocation = -1;
23 bool _uniformBound = false;
24
25 void _ensureUniformIsBoundToUnit();
26 void _ensureTextureIsBound();
27 void _releaseTexture();
28 void _registerCallbacks();
29
30 public:
36 explicit SamplerObject(GLint p_uniformLocation, GLuint p_textureUnitIndex = 0);
41 SamplerObject(const SamplerObject &p_other);
47 SamplerObject &operator=(const SamplerObject &p_other);
48
53 void bind(const TextureObject *p_texture);
57 void unbind();
58
63 const TextureObject *texture() const;
64 };
65 }
66}
Stateful helper toggling between activated/deactivated states.
Definition spk_activable_object.hpp:20
void unbind()
Unbinds any texture from this sampler.
Definition spk_sampler_object.cpp:118
SamplerObject(GLint p_uniformLocation, GLuint p_textureUnitIndex=0)
Builds a sampler targeting a uniform location and texture unit.
Definition spk_sampler_object.cpp:49
SamplerObject & operator=(const SamplerObject &p_other)
Copies sampler binding state from another sampler.
Definition spk_sampler_object.cpp:83
void bind(const TextureObject *p_texture)
Binds a texture to this sampler.
Definition spk_sampler_object.cpp:108
const TextureObject * texture() const
Returns the currently bound texture.
Definition spk_sampler_object.cpp:133
CPU-staged 2D texture with activation and parameter controls.
Definition spk_texture_object.hpp:25