started polygon patter shader

This commit is contained in:
Hannes Janetzek 2013-01-21 03:15:50 +01:00
parent 1dd7e3c7a8
commit 07dcbde928

View File

@ -82,7 +82,7 @@ public final class PolygonRenderer {
} }
hPolygonMatrix = glGetUniformLocation(polygonProgram, "u_mvp"); hPolygonMatrix = glGetUniformLocation(polygonProgram, "u_mvp");
hPolygonColor = glGetUniformLocation(polygonProgram, "u_color"); hPolygonColor = glGetUniformLocation(polygonProgram, "u_color");
hPolygonVertexPosition = glGetAttribLocation(polygonProgram, "a_position"); hPolygonVertexPosition = glGetAttribLocation(polygonProgram, "a_pos");
mFillPolys = new PolygonLayer[STENCIL_BITS]; mFillPolys = new PolygonLayer[STENCIL_BITS];
@ -170,6 +170,8 @@ public final class PolygonRenderer {
// stencil buffer index to start fill // stencil buffer index to start fill
private static int mStart; private static int mStart;
//private final static boolean drawBackground = false;
/** /**
* draw polygon layers (unil layer.next is not polygon layer) * draw polygon layers (unil layer.next is not polygon layer)
* using stencil buffer method * using stencil buffer method
@ -215,7 +217,8 @@ public final class PolygonRenderer {
mStart = mCount; mStart = mCount;
} }
GLState.test(drawClipped, true); //GLState.test(drawClipped, true);
GLState.test(true, true);
Layer l = layer; Layer l = layer;
@ -226,19 +229,27 @@ public final class PolygonRenderer {
continue; continue;
if (mCount == mStart) { if (mCount == mStart) {
// clear stencilbuffer (tile region) by drawing /* clear stencilbuffer (tile region) by drawing
// a quad with func 'always' and op 'zero' * a quad with func 'always' and op 'zero' */
// disable drawing to framebuffer // disable drawing to framebuffer
glColorMask(false, false, false, false); glColorMask(false, false, false, false);
// if (!first) {
// // first run draw map bg, otherwise
// // disable drawing to framebuffer
// glColorMask(false, false, false, false);
// } else {
// glUniform4fv(hPolygonColor, 1, GLRenderer.mClearColor, 0);
// }
// never pass the test: always apply fail op // never pass the test: always apply fail op
glStencilFunc(GL_ALWAYS, 0, 0xFF); glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilMask(0xFF); glStencilMask(0xFF);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
// draw clip-region into depth buffer: /* draw clip-region into depth buffer:
// this is used for lines and polygons * this is used for lines and polygons */
if (first && drawClipped) { if (first && drawClipped) {
// write to depth buffer // write to depth buffer
glDepthMask(true); glDepthMask(true);
@ -250,6 +261,10 @@ public final class PolygonRenderer {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// if (first) {
// glColorMask(false, false, false, false);
// }
if (first && drawClipped) { if (first && drawClipped) {
first = false; first = false;
// do not modify depth buffer anymore // do not modify depth buffer anymore
@ -259,11 +274,11 @@ public final class PolygonRenderer {
} }
// op for stencil method polygon drawing // op for stencil method polygon drawing
glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT); glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GL_INVERT);
} }
// no need for depth test while drawing stencil // no need for depth test while drawing stencil
GLState.test(false, true); //GLState.test(false, true);
mFillPolys[mCount] = pl; mFillPolys[mCount] = pl;
@ -295,6 +310,8 @@ public final class PolygonRenderer {
if (drawClipped && first) { if (drawClipped && first) {
GLState.test(true, false); GLState.test(true, false);
GLES20.glColorMask(false, false, false, false); GLES20.glColorMask(false, false, false, false);
//glUniform4fv(hPolygonColor, 1, GLRenderer.mClearColor, 0);
GLES20.glDepthMask(true); GLES20.glDepthMask(true);
GLES20.glDepthFunc(GLES20.GL_LESS); GLES20.glDepthFunc(GLES20.GL_LESS);
@ -341,26 +358,52 @@ public final class PolygonRenderer {
} }
private final static String polygonVertexShader = "" private final static String polygonVertexShader = ""
+ "precision highp float;" + "precision mediump float;"
+ "uniform mat4 u_mvp;" + "uniform mat4 u_mvp;"
+ "attribute vec4 a_position;" + "attribute vec4 a_pos;"
+ "void main() {" + "void main() {"
+ " gl_Position = u_mvp * a_position;" + " gl_Position = u_mvp * a_pos;"
+ "}"; + "}";
private final static String polygonFragmentShader = "" private final static String polygonFragmentShader = ""
+ "precision highp float;" + "precision mediump float;"
+ "uniform vec4 u_color;" + "uniform vec4 u_color;"
+ "void main() {" + "void main() {"
+ " gl_FragColor = u_color;" + " gl_FragColor = u_color;"
+ "}"; + "}";
private final static String polygonTexVertexShader = ""
+ "precision mediump float;"
+ "uniform mat4 u_mvp;"
+ "attribute vec4 a_pos;"
+ "varying vec2 v_st;"
+ "void main() {"
+ " if(gl_VertexID == 0)"
+ " v_st = vec2(0.0,0.0);"
+ " else if(gl_VertexID == 1)"
+ " v_st = vec2(1.0,0.0);"
+ " else if(gl_VertexID == 2)"
+ " v_st = vec2(1.0,1.0);"
+ " else if(gl_VertexID == 3)"
+ " v_st = vec2(0.0,1.0);"
+ " gl_Position = u_mvp * a_pos;"
+ "}";
private final static String polygonTexFragmentShader = ""
+ "precision mediump float;"
+ "uniform vec4 u_color;"
+ "uniform sampler2D tex;"
+ "varying vec2 v_st;"
+ "void main() {"
+ " gl_FragColor = u_color * texture2D(tex, v_st);"
+ "}";
private final static String polygonVertexShaderZ = "" private final static String polygonVertexShaderZ = ""
+ "precision highp float;" + "precision highp float;"
+ "uniform mat4 u_mvp;" + "uniform mat4 u_mvp;"
+ "attribute vec4 a_position;" + "attribute vec4 a_pos;"
+ "varying float z;" + "varying float z;"
+ "void main() {" + "void main() {"
+ " gl_Position = u_mvp * a_position;" + " gl_Position = u_mvp * a_pos;"
+ " z = gl_Position.z;" + " z = gl_Position.z;"
+ "}"; + "}";
private final static String polygonFragmentShaderZ = "" private final static String polygonFragmentShaderZ = ""