diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:50:49 +0000 |
commit | c853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch) | |
tree | 7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/ui/widget/canvas/texture.h | |
parent | Initial commit. (diff) | |
download | inkscape-upstream.tar.xz inkscape-upstream.zip |
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ui/widget/canvas/texture.h')
-rw-r--r-- | src/ui/widget/canvas/texture.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ui/widget/canvas/texture.h b/src/ui/widget/canvas/texture.h new file mode 100644 index 0000000..98aeba2 --- /dev/null +++ b/src/ui/widget/canvas/texture.h @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INKSCAPE_UI_WIDGET_CANVAS_TEXTURE_H +#define INKSCAPE_UI_WIDGET_CANVAS_TEXTURE_H + +#include <boost/noncopyable.hpp> +#include <2geom/point.h> +#include <epoxy/gl.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +class Texture +{ +public: + // Create null texture owning no resources. + Texture() = default; + + // Allocate a blank texture of a given size. The texture is bound to GL_TEXTURE_2D. + Texture(Geom::IntPoint const &size); + + // Wrap an existing texture. + Texture(GLuint id, Geom::IntPoint const &size) : _id(id), _size(size) {} + + // Boilerplate constructors/operators + Texture(Texture &&other) noexcept { _movefrom(other); } + Texture &operator=(Texture &&other) noexcept { _reset(); _movefrom(other); return *this; } + ~Texture() { _reset(); } + + // Observers + GLuint id() const { return _id; } + Geom::IntPoint const &size() const { return _size; } + explicit operator bool() const { return _id; } + + // Methods + void clear() { _reset(); _id = 0; } + void invalidate(); + +private: + GLuint _id = 0; + Geom::IntPoint _size; + + void _reset() noexcept { if (_id) glDeleteTextures(1, &_id); } + void _movefrom(Texture &other) noexcept { _id = other._id; _size = other._size; other._id = 0; } +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_CANVAS_TEXTURE_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : |