1/* gskglattachmentstate.c
2 *
3 * Copyright 2020 Christian Hergert <chergert@redhat.com>
4 *
5 * This file is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 2.1 of the License, or (at your option)
8 * any later version.
9 *
10 * This file is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21#include "config.h"
22
23#include "gskglattachmentstateprivate.h"
24
25GskGLAttachmentState *
26gsk_gl_attachment_state_new (void)
27{
28 GskGLAttachmentState *self;
29
30 self = g_atomic_rc_box_new0 (GskGLAttachmentState);
31
32 self->fbo.changed = FALSE;
33 self->fbo.id = 0;
34 self->n_changed = 0;
35
36 /* Initialize textures, assume we are 2D by default since it
37 * doesn't really matter until we bind something other than
38 * GL_TEXTURE0 to it anyway.
39 */
40 for (guint i = 0; i < G_N_ELEMENTS (self->textures); i++)
41 {
42 self->textures[i].target = GL_TEXTURE_2D;
43 self->textures[i].texture = GL_TEXTURE0;
44 self->textures[i].id = 0;
45 self->textures[i].changed = FALSE;
46 self->textures[i].initial = TRUE;
47 }
48
49 return self;
50}
51
52GskGLAttachmentState *
53gsk_gl_attachment_state_ref (GskGLAttachmentState *self)
54{
55 return g_atomic_rc_box_acquire (self);
56}
57
58void
59gsk_gl_attachment_state_unref (GskGLAttachmentState *self)
60{
61 g_atomic_rc_box_release (mem_block: self);
62}
63
64void
65gsk_gl_attachment_state_bind_texture (GskGLAttachmentState *self,
66 GLenum target,
67 GLenum texture,
68 guint id)
69{
70 GskGLBindTexture *attach;
71
72 g_assert (self != NULL);
73 g_assert (target == GL_TEXTURE_1D ||
74 target == GL_TEXTURE_2D ||
75 target == GL_TEXTURE_3D);
76 g_assert (texture >= GL_TEXTURE0 && texture <= GL_TEXTURE16);
77
78 attach = &self->textures[texture - GL_TEXTURE0];
79
80 if (attach->target != target || attach->texture != texture || attach->id != id)
81 {
82 attach->target = target;
83 attach->texture = texture;
84 attach->id = id;
85 attach->initial = FALSE;
86
87 if (attach->changed == FALSE)
88 {
89 attach->changed = TRUE;
90 self->n_changed++;
91 }
92 }
93}
94
95void
96gsk_gl_attachment_state_bind_framebuffer (GskGLAttachmentState *self,
97 guint id)
98{
99 g_assert (self != NULL);
100
101 if (self->fbo.id != id)
102 {
103 self->fbo.id = id;
104 self->fbo.changed = TRUE;
105 }
106}
107

source code of gtk/gsk/gl/gskglattachmentstate.c