1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package hat.buffer;
26
27 import hat.types.ivec2;
28 import hat.types.vec2;
29 import hat.types.vec3;
30 import hat.types.vec4;
31 import optkl.ifacemapper.BoundSchema;
32 import optkl.ifacemapper.Buffer;
33 import optkl.ifacemapper.Schema;
34 import optkl.util.carriers.ArenaAndLookupCarrier;
35
36 public interface Uniforms extends Buffer {
37 interface ivec2Field extends ivec2.Field, Struct {
38 void x(int x);
39
40 void y(int y);
41 }
42
43 interface vec2Field extends vec2.Field, Struct {
44 void x(float x);
45
46 void y(float y);
47 }
48
49 interface vec3Field extends vec3.Field, Struct {
50 void x(float x);
51
52 void y(float y);
53
54 void z(float z);
55 }
56
57 interface vec4Field extends vec4.Field, Struct {
58 void x(float x);
59
60 void y(float y);
61
62 void z(float z);
63
64 void w(float w);
65 }
66
67 vec2Field fragCoord();
68
69 vec4Field fragColor();
70
71 vec3Field iResolution();
72
73 float iTime();
74
75 void iTime(float iTime);
76
77 ivec2Field iMouse();
78
79 long iFrame();
80
81 void iFrame(long iFrame);
82
83 Schema<Uniforms> schema = Schema.of(Uniforms.class, uniforms -> uniforms
84 .field("fragCoord", fragCoord -> fragCoord.fields("x", "y"))
85 .field("fragColor", fragColor -> fragColor.fields("x", "y", "z", "w"))
86 .field("iResolution", iResolution -> iResolution.fields("x", "y", "z"))
87 .pad(4)
88 .field("iMouse", iMouse -> iMouse.fields("x", "y"))
89 .field("iTime")
90 .pad(4)
91 .field("iFrame")
92 );
93
94 static Uniforms create(ArenaAndLookupCarrier arenaAndLookupCarrier) {
95 return BoundSchema.of(arenaAndLookupCarrier, schema).allocate();
96 }
97 }