1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package ru.olamedia.asset;
import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLContext;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
public class Shader {
private ShaderState state;
public ShaderState getState() {
return state;
}
public void compile() {
GL2ES2 gl = GLContext.getCurrentGL().getGL2ES2();
state = new ShaderState();
state.setVerbose(true);
final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader", "shader/bin",
"block", true);
final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
"shader/bin", "block", true);
final ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
state.attachShaderProgram(gl, sp0, true);
}
public void enable() {
GL2ES2 gl = GLContext.getCurrentGL().getGL2ES2();
state.useProgram(gl, true);
gl.getContext().attachObject(Shader.class.getName(), state);
}
public void disable() {
GL2ES2 gl = GLContext.getCurrentGL().getGL2ES2();
state.useProgram(gl, false);
}
public static ShaderState getCurrentShaderState() {
final GLContext ctx = GLContext.getCurrent();
if(null != ctx) {
return (ShaderState) ctx.getAttachedObject(Shader.class.getName());
} else {
return null;
}
}
}
|