Inkscape
Vector Graphics Editor
texture.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include "texture.h"
4
5namespace Inkscape::UI::Widget {
6
7static bool have_gltexstorage()
8{
9 static bool const result = epoxy_gl_version() >= 42 || epoxy_has_gl_extension("GL_ARB_texture_storage");
10 return result;
11}
12
14{
15 static bool const result = epoxy_gl_version() >= 43 || epoxy_has_gl_extension("ARB_invalidate_subdata");
16 return result;
17}
18
20 : _size(size)
21{
22 glGenTextures(1, &_id);
23 glBindTexture(GL_TEXTURE_2D, _id);
24
25 // Common flags for all textures used at the moment.
26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
27 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
28 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
29 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
30
31 if (have_gltexstorage()) {
32 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, size.x(), size.y());
33 } else {
34 // Note: This fallback path is always chosen on the Mac due to Apple's crippling of OpenGL.
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
37 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size.x(), size.y(), 0, GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
38 }
39}
40
42{
44 glInvalidateTexImage(_id, 0);
45 }
46}
47
48} // namespace Inkscape::UI::Widget
49
50/*
51 Local Variables:
52 mode:c++
53 c-file-style:"stroustrup"
54 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
55 indent-tabs-mode:nil
56 fill-column:99
57 End:
58*/
59// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Two-dimensional point with integer coordinates.
Definition: int-point.h:57
constexpr IntCoord x() const noexcept
Definition: int-point.h:77
constexpr IntCoord y() const noexcept
Definition: int-point.h:79
Geom::IntPoint const & size() const
Definition: texture.h:30
std::size_t _size
Definition: convex-hull.h:104
Css & result
Custom widgets.
Definition: desktop.h:127
static bool have_glinvalidateteximage()
Definition: texture.cpp:13
static bool have_gltexstorage()
Definition: texture.cpp:7
int size