@@ -9,57 +9,24 @@ import baaahs.gl.render.ModelRenderer
9
9
import baaahs.glsl.Uniform
10
10
import baaahs.show.DataSource
11
11
import baaahs.show.OutputPortRef
12
- import com.danielgergely.kgl.GL_LINK_STATUS
13
- import com.danielgergely.kgl.GL_TRUE
14
12
15
13
class GlslProgram (
16
14
internal val gl : GlContext ,
17
15
private val linkedPatch : LinkedPatch ,
18
16
resolver : Resolver
19
17
) {
20
- internal val id = gl.runInContext { gl.check { createProgram() ? : throw IllegalStateException () } }
21
18
22
19
private val vertexShader =
23
20
gl.createVertexShader(
24
- """
25
- #version ${gl.glslVersion}
26
-
27
- precision lowp float;
28
-
29
- // xy = vertex position in normalized device coordinates ([-1,+1] range).
30
- in vec2 Vertex;
31
-
32
- const vec2 scale = vec2(0.5, 0.5);
33
-
34
- void main()
35
- {
36
- vec2 vTexCoords = Vertex * scale + scale; // scale vertex attribute to [0,1] range
37
- gl_Position = vec4(Vertex, 0.0, 1.0);
38
- }
39
- """ .trimIndent()
21
+ " #version ${gl.glslVersion} \n ${GlslProgram .vertexShader} "
40
22
)
41
23
42
24
internal val fragShader =
43
25
gl.createFragmentShader(linkedPatch.toFullGlsl(gl.glslVersion))
44
26
45
- private val bindings : List < Binding >
27
+ val id = gl.compile(vertexShader, fragShader)
46
28
47
- init {
48
- gl.runInContext {
49
- gl.check { attachShader(id, vertexShader.shaderId) }
50
- gl.check { attachShader(id, fragShader.shaderId) }
51
- gl.check { linkProgram(id) }
52
- if (gl.check { getProgramParameter(id, GL_LINK_STATUS ) } != GL_TRUE ) {
53
- vertexShader.validate()
54
- fragShader.validate()
55
-
56
- val infoLog = gl.check { getProgramInfoLog(id) }
57
- throw CompilationException (infoLog ? : " Huh? Program error?" )
58
- }
59
- }
60
-
61
- bindings = gl.runInContext { bind(resolver) }
62
- }
29
+ private val bindings = gl.runInContext { bind(resolver) }
63
30
64
31
val vertexAttribLocation: Int = gl.runInContext {
65
32
gl.check { getAttribLocation(id, " Vertex" ) }
@@ -169,6 +136,21 @@ class GlslProgram(
169
136
private val logger = Logger (" GlslProgram" )
170
137
171
138
val PixelColor = OutputPortRef (" sm_result" )
139
+
140
+ val vertexShader = """
141
+ precision lowp float;
142
+
143
+ // xy = vertex position in normalized device coordinates ([-1,+1] range).
144
+ in vec2 Vertex;
145
+
146
+ const vec2 scale = vec2(0.5, 0.5);
147
+
148
+ void main()
149
+ {
150
+ vec2 vTexCoords = Vertex * scale + scale; // scale vertex attribute to [0,1] range
151
+ gl_Position = vec4(Vertex, 0.0, 1.0);
152
+ }
153
+ """ .trimIndent()
172
154
}
173
155
}
174
156
0 commit comments