aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-12-23 13:53:36 +0100
committerSven Gothel <[email protected]>2012-12-23 13:53:36 +0100
commit7cf2ca62bed2a8a9541f09a72d8a26e4f1203de2 (patch)
tree72b37e9a58bee51ba9be3cb8d4b85b722f476161
parent4bd8df723573250f11afb7b67c7235f8dc8b631e (diff)
Shader: Add 'current' ShaderState setting via GLContext attachement (removed from latest JOGL); Associate created GLArrayDataServer w/ current ShaderState; Add notes re: GL2.GL_QUADS
-rw-r--r--src/ru/olamedia/asset/Shader.java10
-rw-r--r--src/ru/olamedia/game/GameManager.java5
-rw-r--r--src/ru/olamedia/geom/ImmModeMesh.java5
-rw-r--r--src/ru/olamedia/geom/Mesh.java26
4 files changed, 35 insertions, 11 deletions
diff --git a/src/ru/olamedia/asset/Shader.java b/src/ru/olamedia/asset/Shader.java
index 8fd9ada..bd19556 100644
--- a/src/ru/olamedia/asset/Shader.java
+++ b/src/ru/olamedia/asset/Shader.java
@@ -31,10 +31,20 @@ public class Shader {
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;
+ }
+ }
}
diff --git a/src/ru/olamedia/game/GameManager.java b/src/ru/olamedia/game/GameManager.java
index 7e1ed71..257f3d4 100644
--- a/src/ru/olamedia/game/GameManager.java
+++ b/src/ru/olamedia/game/GameManager.java
@@ -5,7 +5,6 @@ import java.util.Set;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
@@ -297,7 +296,7 @@ public class GameManager implements GLEventListener {
@Override
public void display(GLAutoDrawable drawable) {
- final GL3 gl = drawable.getGL().getGL3();
+ // final GL gl = drawable.getGL();
// gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
renderer.render(drawable);
@@ -316,7 +315,7 @@ public class GameManager implements GLEventListener {
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- final GL gl = drawable.getGL().getGL2ES2();
+ final GL gl = drawable.getGL();
gl.glViewport(0, 0, width, height);
renderer.reshape(drawable);
}
diff --git a/src/ru/olamedia/geom/ImmModeMesh.java b/src/ru/olamedia/geom/ImmModeMesh.java
index 4ce419b..0c79d1b 100644
--- a/src/ru/olamedia/geom/ImmModeMesh.java
+++ b/src/ru/olamedia/geom/ImmModeMesh.java
@@ -10,6 +10,8 @@ import javax.media.opengl.GL2ES2;
import javax.media.opengl.GLContext;
import javax.media.opengl.fixedfunc.GLPointerFunc;
+import ru.olamedia.asset.Shader;
+
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.util.GLArrayDataServer;
@@ -19,7 +21,7 @@ public class ImmModeMesh {
protected GLArrayDataServer interleaved;
protected FloatBuffer buf;
private int vertexCount = 0;
- protected int mode = GL2.GL_QUADS;
+ protected int mode = GL2.GL_QUADS; // FIXME: Use GL.GL_TRIANGLE_FAN or GL.GL_TRIANGLE_STRIP !!
protected boolean isGLSL = false;
protected byte vertexComponent = 0;
protected byte normalComponent = 0;
@@ -163,6 +165,7 @@ public class ImmModeMesh {
}
buf.rewind();
interleaved = buf;
+ interleaved.associate(Shader.getCurrentShaderState(), true); // FIXME: Maybe prefer pass-through, than TLS ctx bound
}
protected final boolean growBufferIfNecessary(int spare) {
diff --git a/src/ru/olamedia/geom/Mesh.java b/src/ru/olamedia/geom/Mesh.java
index 7e25666..1ae7734 100644
--- a/src/ru/olamedia/geom/Mesh.java
+++ b/src/ru/olamedia/geom/Mesh.java
@@ -148,6 +148,7 @@ public class Mesh {
interleaved.addGLSLSubArray("mesh_vertices", 3, GL.GL_ARRAY_BUFFER);
interleaved.addGLSLSubArray("mesh_colors", 4, GL.GL_ARRAY_BUFFER);
interleaved.addGLSLSubArray("mesh_texCoord", 2, GL.GL_ARRAY_BUFFER);
+ interleaved.associate(getShader().getState(), true);
arrays.put(m, interleaved);
}
for (int n = 0; n < vertexCount; n++) {
@@ -272,10 +273,12 @@ public class Mesh {
if (useVbo) {
GL2ES2 gl = glx.getGL2ES2();
// GL2 gl = glx.getGL2();
- getShader().enable();
+ final Shader shader = getShader();
+ final ShaderState shaderState = shader.getState();
+ shader.enable();
Game.client.getScene().dayTime.getClearColor();
- getShader().getState().uniform(gl, pmvMatrixUniform);
- getShader().getState().uniform(gl, sunColor);
+ shaderState.uniform(gl, pmvMatrixUniform);
+ shaderState.uniform(gl, sunColor);
for (Integer m : materials.keySet()) {
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glBindTexture(GL.GL_TEXTURE_2D, (int) m);
@@ -287,15 +290,24 @@ public class Mesh {
// GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
// gl.glTexParameteri(GL.GL_TEXTURE_2D,
// GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
- arrays.get(m).enableBuffer(gl, true);
+ final GLArrayDataServer ad = arrays.get(m);
+ ad.enableBuffer(gl, true);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_DEPTH_TEST);
// gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_FILL);
- gl.glDrawArrays(GL2.GL_QUADS, 0, arrays.get(m).getElementCount());
- arrays.get(m).enableBuffer(gl, false);
+ // FIXME: Use GL.GL_TRIANGLE_FAN or GL.GL_TRIANGLE_STRIP !!
+ final int vElems = ad.getElementCount();
+ if ( !gl.isGL2() ) {
+ for (int j = 0; j < vElems - 3; j += 4) {
+ gl.glDrawArrays(GL.GL_TRIANGLE_FAN, j, 4);
+ }
+ } else {
+ gl.glDrawArrays(GL2.GL_QUADS, 0, vElems);
+ }
+ ad.enableBuffer(gl, false);
// System.exit(0);
}
- getShader().disable();
+ shader.disable();
} else {
GL2 gl = glx.getGL2();
if (useDisplayList) {