1/* gskglprogramprivate.h
2 *
3 * Copyright 2020 Christian Hergert <chergert@redhat.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21#ifndef __GSK_GL_PROGRAM_PRIVATE_H__
22#define __GSK_GL_PROGRAM_PRIVATE_H__
23
24#include "gskgltypesprivate.h"
25
26#include "gskglattachmentstateprivate.h"
27#include "gskglcommandqueueprivate.h"
28#include "gskgldriverprivate.h"
29
30G_BEGIN_DECLS
31
32#define GSK_TYPE_GL_PROGRAM (gsk_gl_program_get_type())
33#define GSK_GL_PROGRAM_MAX_CUSTOM_TEXTURES 4
34#define GSK_GL_PROGRAM_MAX_CUSTOM_ARGS 8
35
36G_DECLARE_FINAL_TYPE (GskGLProgram, gsk_gl_program, GSK, GL_PROGRAM, GObject)
37
38struct _GskGLProgram
39{
40 GObject parent_instance;
41
42 int id;
43 char *name;
44 GskGLDriver *driver;
45
46 /* Cached pointer to avoid lots of pointer chasing/lookups */
47 GskGLUniformState *uniforms;
48 GskGLUniformProgram *program_info;
49
50 /* Static array for key->location transforms */
51 GskGLUniformMapping mappings[32];
52 guint n_mappings;
53};
54
55GskGLProgram * gsk_gl_program_new (GskGLDriver *driver,
56 const char *name,
57 int program_id);
58gboolean gsk_gl_program_add_uniform (GskGLProgram *self,
59 const char *name,
60 guint key);
61void gsk_gl_program_uniforms_added (GskGLProgram *self,
62 gboolean has_attachments);
63void gsk_gl_program_delete (GskGLProgram *self);
64
65static inline void
66gsk_gl_program_set_uniform1fv (GskGLProgram *self,
67 guint key,
68 guint stamp,
69 guint count,
70 const float *values)
71{
72 gsk_gl_uniform_state_set1fv (state: self->uniforms, program: self->program_info,
73 key,
74 stamp,
75 count,
76 value: values);
77}
78
79static inline void
80gsk_gl_program_set_uniform2fv (GskGLProgram *self,
81 guint key,
82 guint stamp,
83 guint count,
84 const float *values)
85{
86 gsk_gl_uniform_state_set2fv (state: self->uniforms, program: self->program_info,
87 key,
88 stamp,
89 count,
90 value: values);
91}
92
93static inline void
94gsk_gl_program_set_uniform4fv (GskGLProgram *self,
95 guint key,
96 guint stamp,
97 guint count,
98 const float *values)
99{
100 gsk_gl_uniform_state_set4fv (state: self->uniforms, program: self->program_info,
101 key,
102 stamp,
103 count,
104 value: values);
105}
106
107static inline void
108gsk_gl_program_set_uniform_rounded_rect (GskGLProgram *self,
109 guint key,
110 guint stamp,
111 const GskRoundedRect *rounded_rect)
112{
113 gsk_gl_uniform_state_set_rounded_rect (state: self->uniforms, program: self->program_info,
114 key,
115 stamp,
116 rounded_rect);
117}
118
119static inline void
120gsk_gl_program_set_uniform1i (GskGLProgram *self,
121 guint key,
122 guint stamp,
123 int value0)
124{
125 gsk_gl_uniform_state_set1i (state: self->uniforms,
126 program: self->program_info,
127 key,
128 stamp,
129 value0);
130}
131
132static inline void
133gsk_gl_program_set_uniform2i (GskGLProgram *self,
134 guint key,
135 guint stamp,
136 int value0,
137 int value1)
138{
139 gsk_gl_uniform_state_set2i (state: self->uniforms,
140 program: self->program_info,
141 key,
142 stamp,
143 value0, value1);
144}
145
146static inline void
147gsk_gl_program_set_uniform3i (GskGLProgram *self,
148 guint key,
149 guint stamp,
150 int value0,
151 int value1,
152 int value2)
153{
154 gsk_gl_uniform_state_set3i (state: self->uniforms,
155 program: self->program_info,
156 key,
157 stamp,
158 value0, value1, value2);
159}
160
161static inline void
162gsk_gl_program_set_uniform4i (GskGLProgram *self,
163 guint key,
164 guint stamp,
165 int value0,
166 int value1,
167 int value2,
168 int value3)
169{
170 gsk_gl_uniform_state_set4i (state: self->uniforms,
171 program: self->program_info,
172 key,
173 stamp,
174 value0, value1, value2, value3);
175}
176
177static inline void
178gsk_gl_program_set_uniform1f (GskGLProgram *self,
179 guint key,
180 guint stamp,
181 float value0)
182{
183 gsk_gl_uniform_state_set1f (state: self->uniforms,
184 program: self->program_info,
185 key,
186 stamp,
187 value0);
188}
189
190static inline void
191gsk_gl_program_set_uniform2f (GskGLProgram *self,
192 guint key,
193 guint stamp,
194 float value0,
195 float value1)
196{
197 gsk_gl_uniform_state_set2f (state: self->uniforms,
198 program: self->program_info,
199 key,
200 stamp,
201 value0, value1);
202}
203
204static inline void
205gsk_gl_program_set_uniform3f (GskGLProgram *self,
206 guint key,
207 guint stamp,
208 float value0,
209 float value1,
210 float value2)
211{
212 gsk_gl_uniform_state_set3f (state: self->uniforms,
213 program: self->program_info,
214 key,
215 stamp,
216 value0, value1, value2);
217}
218
219static inline void
220gsk_gl_program_set_uniform4f (GskGLProgram *self,
221 guint key,
222 guint stamp,
223 float value0,
224 float value1,
225 float value2,
226 float value3)
227{
228 gsk_gl_uniform_state_set4f (state: self->uniforms,
229 program: self->program_info,
230 key,
231 stamp,
232 value0, value1, value2, value3);
233}
234
235static inline void
236gsk_gl_program_set_uniform_color (GskGLProgram *self,
237 guint key,
238 guint stamp,
239 const GdkRGBA *color)
240{
241 gsk_gl_uniform_state_set_color (state: self->uniforms,
242 program: self->program_info,
243 key,
244 stamp,
245 color);
246}
247
248static inline void
249gsk_gl_program_set_uniform_texture (GskGLProgram *self,
250 guint key,
251 guint stamp,
252 GLenum texture_target,
253 GLenum texture_slot,
254 guint texture_id)
255{
256 gsk_gl_attachment_state_bind_texture (self: self->driver->command_queue->attachments,
257 target: texture_target,
258 texture: texture_slot,
259 id: texture_id);
260 gsk_gl_uniform_state_set_texture (state: self->uniforms,
261 program: self->program_info,
262 key,
263 stamp,
264 texture_slot);
265}
266
267static inline void
268gsk_gl_program_set_uniform_matrix (GskGLProgram *self,
269 guint key,
270 guint stamp,
271 const graphene_matrix_t *matrix)
272{
273 gsk_gl_uniform_state_set_matrix (state: self->uniforms,
274 program: self->program_info,
275 key,
276 stamp,
277 matrix);
278}
279
280G_END_DECLS
281
282#endif /* __GSK_GL_PROGRAM_PRIVATE_H__ */
283

source code of gtk/gsk/gl/gskglprogramprivate.h