| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 87e0aca commit 066722c
23 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | 26 | import java.nio.Buffer; | |
| 27 | 27 | import java.nio.ByteBuffer; | |
| 28 | + import java.nio.IntBuffer; | ||
| 28 | 29 | ||
| 29 | 30 | import javax.microedition.khronos.egl.EGL10; | |
| 30 | 31 | import javax.microedition.khronos.egl.EGLConfig; | |
@@ -380,8 +381,8 @@ public boolean contextIsCurrent(Context other) { | |||
| 380 | 381 | } | |
| 381 | 382 | ||
| 382 | 383 | static public short makeIndex(int intIdx) { | |
| 383 | - // When the index value is greater than 32767 subtracting 65536 | ||
| 384 | - // will make it as a short to wrap around to the negative range, which | ||
| 384 | + // When the index value is greater than 32767, subtracting 65536 | ||
| 385 | + // will make it (as a short) to wrap around to the negative range, which | ||
| 385 | 386 | // is all we need to later pass these numbers to opengl (which will | |
| 386 | 387 | // interpret them as unsigned shorts). See discussion here: | |
| 387 | 388 | // http://stackoverflow.com/questions/4331021/java-opengl-gldrawelements-with-32767-vertices | |
@@ -396,6 +397,30 @@ public void disableTexturing(int target) { | |||
| 396 | 397 | //gl.glDisable(target); | |
| 397 | 398 | } | |
| 398 | 399 | ||
| 400 | + public void initTexture(int target, int width, int height, int format, int type) { | ||
| 401 | + // Doing in patches of 16x16 pixels to avoid creating a (potentially) | ||
| 402 | + // very large transient array which in certain situations (memory- | ||
| 403 | + // constrained android devices) might lead to an out-of-memory error. | ||
| 404 | + int[] texels = new int[16 * 16]; | ||
| 405 | + for (int y = 0; y < height + 16; y += 16) { | ||
| 406 | + int h = PApplet.min(16, height - y); | ||
| 407 | + for (int x = 0; x < width + 16; x += 16) { | ||
| 408 | + int w = PApplet.min(16, width - x); | ||
| 409 | + gl.glTexSubImage2D(target, 0, x, y, w, h, format, type, IntBuffer.wrap(texels)); | ||
| 410 | + } | ||
| 411 | + } | ||
| 412 | + } | ||
| 413 | + | ||
| 414 | + public String getShaderLog(int id) { | ||
| 415 | + int[] compiled = new int[1]; | ||
| 416 | + GLES20.glGetShaderiv(id, GLES20.GL_COMPILE_STATUS, compiled, 0); | ||
| 417 | + if (compiled[0] == 0) { | ||
| 418 | + return GLES20.glGetShaderInfoLog(id); | ||
| 419 | + } else { | ||
| 420 | + return ""; | ||
| 421 | + } | ||
| 422 | + } | ||
| 423 | + | ||
| 399 | 424 | /////////////////////////////////////////////////////////////////////////////////// | |
| 400 | 425 | ||
| 401 | 426 | // Frame rendering | |
@@ -660,12 +685,12 @@ public void glVertexAttribPointer(int loc, int size, int type, boolean normalize | |||
| 660 | 685 | } | |
| 661 | 686 | ||
| 662 | 687 | ||
| 663 | - public ByteBuffer glMapBuffer(int target, int acccess) { | ||
| 688 | + public ByteBuffer glMapBuffer(int target, int access) { | ||
| 664 | 689 | //return gl2f.glMapBuffer(GL.GL_ARRAY_BUFFER, GL2.GL_READ_WRITE); | |
| 665 | 690 | return null; | |
| 666 | 691 | } | |
| 667 | 692 | ||
| 668 | - public ByteBuffer glMapBufferRange(int target, int offset, int length, int acccess) { | ||
| 693 | + public ByteBuffer glMapBufferRange(int target, int offset, int length, int access) { | ||
| 669 | 694 | //return gl2x.glMapBufferRange(GL.GL_ARRAY_BUFFER, offset, length, GL2.GL_READ_WRITE); | |
| 670 | 695 | return null; | |
| 671 | 696 | } | |
@@ -707,7 +732,7 @@ public void glFramebufferTexture2D(int target, int attachment, int texTarget, in | |||
| 707 | 732 | } | |
| 708 | 733 | ||
| 709 | 734 | public void glBindRenderbuffer(int target, int id) { | |
| 710 | - GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, id); | ||
| 735 | + GLES20.glBindRenderbuffer(target, id); | ||
| 711 | 736 | } | |
| 712 | 737 | ||
| 713 | 738 | public void glRenderbufferStorageMultisample(int target, int samples, int format, int width, int height) { | |
@@ -842,16 +867,6 @@ public void glAttachShader(int prog, int shader) { | |||
| 842 | 867 | GLES20.glAttachShader(prog, shader); | |
| 843 | 868 | } | |
| 844 | 869 | ||
| 845 | - public String getShaderLog(int id) { | ||
| 846 | - int[] compiled = new int[1]; | ||
| 847 | - GLES20.glGetShaderiv(id, GLES20.GL_COMPILE_STATUS, compiled, 0); | ||
| 848 | - if (compiled[0] == 0) { | ||
| 849 | - return GLES20.glGetShaderInfoLog(id); | ||
| 850 | - } else { | ||
| 851 | - return ""; | ||
| 852 | - } | ||
| 853 | - } | ||
| 854 | - | ||
| 855 | 870 | ///////////////////////////////////////////////////////////////////////////////// | |
| 856 | 871 | ||
| 857 | 872 | // Viewport | |
@@ -895,7 +910,7 @@ public void setReadBuffer(int buf) { | |||
| 895 | 910 | } | |
| 896 | 911 | ||
| 897 | 912 | public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) { | |
| 898 | - GLES20.glReadPixels(x, y, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer); | ||
| 913 | + GLES20.glReadPixels(x, y, width, height, format, type, buffer); | ||
| 899 | 914 | } | |
| 900 | 915 | ||
| 901 | 916 | public void setDrawBuffer(int buf) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -907,7 +907,6 @@ public void normal(float nx, float ny, float nz) { | |||
| 907 | 907 | normalY = ny; | |
| 908 | 908 | normalZ = nz; | |
| 909 | 909 | ||
| 910 | - /* | ||
| 911 | 910 | // if drawing a shape and the normal hasn't been set yet, | |
| 912 | 911 | // then we need to set the normals for each vertex so far | |
| 913 | 912 | if (shape != 0) { | |
@@ -918,11 +917,9 @@ public void normal(float nx, float ny, float nz) { | |||
| 918 | 917 | // a separate normal for each vertex | |
| 919 | 918 | normalMode = NORMAL_MODE_VERTEX; | |
| 920 | 919 | } | |
| 921 | - } | ||
| 922 | - */ | ||
| 920 | + } | ||
| 923 | 921 | } | |
| 924 | 922 | ||
| 925 | - | ||
| 926 | 923 | /** | |
| 927 | 924 | * Set texture mode to either to use coordinates based on the IMAGE | |
| 928 | 925 | * (more intuitive for new users) or NORMALIZED (better for advanced chaps) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -780,8 +780,6 @@ protected void deleteFinalizedRenderBufferObjects() { | |||
| 780 | 780 | // GLSL Program Objects ----------------------------------------------- | |
| 781 | 781 | ||
| 782 | 782 | protected int createGLSLProgramObject() { | |
| 783 | - | ||
| 784 | - pg.report("before delete"); | ||
| 785 | 783 | deleteFinalizedGLSLProgramObjects(); | |
| 786 | 784 | ||
| 787 | 785 | int id = pgl.glCreateProgram(); | |
@@ -2203,7 +2201,7 @@ public void flush() { | |||
| 2203 | 2201 | } | |
| 2204 | 2202 | ||
| 2205 | 2203 | if (flushMode == FLUSH_WHEN_FULL && !hints[DISABLE_TRANSFORM_CACHE]) { | |
| 2206 | - //popMatrix(); | ||
| 2204 | + popMatrix(); | ||
| 2207 | 2205 | } | |
| 2208 | 2206 | } | |
| 2209 | 2207 | ||
@@ -6327,7 +6325,7 @@ public void allocate() { | |||
| 6327 | 6325 | } | |
| 6328 | 6326 | ||
| 6329 | 6327 | public void trim() { | |
| 6330 | - if (vertexCount < vertices.length / 3) { | ||
| 6328 | + if (0 < vertexCount && vertexCount < vertices.length / 3) { | ||
| 6331 | 6329 | trimVertices(); | |
| 6332 | 6330 | trimColors(); | |
| 6333 | 6331 | trimNormals(); | |
@@ -6337,9 +6335,12 @@ public void trim() { | |||
| 6337 | 6335 | trimAmbient(); | |
| 6338 | 6336 | trimSpecular(); | |
| 6339 | 6337 | trimEmissive(); | |
| 6340 | - trimShininess(); | ||
| 6338 | + trimShininess(); | ||
| 6339 | + } | ||
| 6340 | + | ||
| 6341 | + if (0 < edgeCount && edgeCount < edges.length) { | ||
| 6341 | 6342 | trimEdges(); | |
| 6342 | - } | ||
| 6343 | + } | ||
| 6343 | 6344 | } | |
| 6344 | 6345 | ||
| 6345 | 6346 | public void dispose() { | |
@@ -6437,7 +6438,7 @@ public int addVertex(float x, float y, float z, | |||
| 6437 | 6438 | index = 3 * vertexCount; | |
| 6438 | 6439 | normals[index++] = nx; | |
| 6439 | 6440 | normals[index++] = ny; | |
| 6440 | - normals[index ] = ny; | ||
| 6441 | + normals[index ] = nz; | ||
| 6441 | 6442 | ||
| 6442 | 6443 | index = 2 * vertexCount; | |
| 6443 | 6444 | texcoords[index++] = u; | |
@@ -7065,7 +7066,7 @@ public void allocate() { | |||
| 7065 | 7066 | } | |
| 7066 | 7067 | ||
| 7067 | 7068 | public void trim() { | |
| 7068 | - if (fillVertexCount < fillVertices.length / 3) { | ||
| 7069 | + if (0 < fillVertexCount && fillVertexCount < fillVertices.length / 3) { | ||
| 7069 | 7070 | trimFillVertices(); | |
| 7070 | 7071 | trimFillColors(); | |
| 7071 | 7072 | trimFillNormals(); | |
@@ -7076,31 +7077,31 @@ public void trim() { | |||
| 7076 | 7077 | trimFillShininess(); | |
| 7077 | 7078 | } | |
| 7078 | 7079 | ||
| 7079 | - if (fillIndexCount < fillIndices.length) { | ||
| 7080 | + if (0 < fillIndexCount && fillIndexCount < fillIndices.length) { | ||
| 7080 | 7081 | trimFillIndices(); | |
| 7081 | 7082 | } | |
| 7082 | 7083 | ||
| 7083 | - if (lineVertexCount < lineVertices.length / 3) { | ||
| 7084 | + if (0 < lineVertexCount && lineVertexCount < lineVertices.length / 3) { | ||
| 7084 | 7085 | trimLineVertices(); | |
| 7085 | 7086 | trimLineColors(); | |
| 7086 | 7087 | trimLineAttributes(); | |
| 7087 | 7088 | } | |
| 7088 | 7089 | ||
| 7089 | - if (lineIndexCount < lineIndices.length) { | ||
| 7090 | + if (0 < lineIndexCount && lineIndexCount < lineIndices.length) { | ||
| 7090 | 7091 | trimLineIndices(); | |
| 7091 | 7092 | } | |
| 7092 | 7093 | ||
| 7093 | - if (pointVertexCount < pointVertices.length / 3) { | ||
| 7094 | + if (0 < pointVertexCount && pointVertexCount < pointVertices.length / 3) { | ||
| 7094 | 7095 | trimPointVertices(); | |
| 7095 | 7096 | trimPointColors(); | |
| 7096 | 7097 | trimPointAttributes(); | |
| 7097 | 7098 | } | |
| 7098 | 7099 | ||
| 7099 | - if (pointIndexCount < pointIndices.length) { | ||
| 7100 | + if (0 < pointIndexCount && pointIndexCount < pointIndices.length) { | ||
| 7100 | 7101 | trimPointIndices(); | |
| 7101 | 7102 | } | |
| 7102 | 7103 | } | |
| 7103 | - | ||
| 7104 | + | ||
| 7104 | 7105 | protected void trimFillVertices() { | |
| 7105 | 7106 | float temp[] = new float[3 * fillVertexCount]; | |
| 7106 | 7107 | PApplet.arrayCopy(fillVertices, 0, temp, 0, 3 * fillVertexCount); | |
@@ -7174,7 +7175,7 @@ protected void trimLineAttributes() { | |||
| 7174 | 7175 | } | |
| 7175 | 7176 | ||
| 7176 | 7177 | protected void trimLineIndices() { | |
| 7177 | - short temp[] = new short[lineVertexCount]; | ||
| 7178 | + short temp[] = new short[lineIndexCount]; | ||
| 7178 | 7179 | PApplet.arrayCopy(lineIndices, 0, temp, 0, lineIndexCount); | |
| 7179 | 7180 | lineIndices = temp; | |
| 7180 | 7181 | } | |
@@ -8571,10 +8572,11 @@ public void tessellatePolygon(boolean solid, boolean closed, boolean calcNormals | |||
| 8571 | 8572 | ||
| 8572 | 8573 | // Vertex data includes coordinates, colors, normals, texture coordinates, and material properties. | |
| 8573 | 8574 | double[] vertex = new double[] { in.vertices [3 * i + 0], in.vertices [3 * i + 1], in.vertices[3 * i + 2], | |
| 8574 | - in.colors [4 * i + 0], in.colors [4 * i + 1], in.colors [4 * i + 2], in.colors[4 * i + 3], | ||
| 8575 | + in.colors [i], | ||
| 8575 | 8576 | in.normals [3 * i + 0], in.normals [3 * i + 1], in.normals [3 * i + 2], | |
| 8576 | 8577 | in.texcoords[2 * i + 0], in.texcoords[2 * i + 1], | |
| 8577 | 8578 | in.ambient[i], in.specular[i], in.emissive[i], in.shininess[i] }; | |
| 8579 | + | ||
| 8578 | 8580 | gluTess.addVertex(vertex); | |
| 8579 | 8581 | } | |
| 8580 | 8582 | gluTess.endContour(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ | |||
| 28 | 28 | import java.util.LinkedList; | |
| 29 | 29 | import java.util.NoSuchElementException; | |
| 30 | 30 | ||
| 31 | + | ||
| 31 | 32 | /** | |
| 32 | 33 | * This class wraps an OpenGL texture. | |
| 33 | 34 | * By Andres Colubri | |
@@ -782,20 +783,8 @@ protected void allocate() { | |||
| 782 | 783 | // from w/h in the case that the GPU doesn't support NPOT textures) | |
| 783 | 784 | pgl.glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE, null); | |
| 784 | 785 | ||
| 785 | - // Once OpenGL knows the size of the new texture, we make sure it doesn't | ||
| 786 | - // contain any garbage in the region of interest (0, 0, width, height): | ||
| 787 | - // Doing in patches of 16x16 pixels to avoid creating a (potentially) | ||
| 788 | - // very large transient array which in certain situations (memory- | ||
| 789 | - // constrained android devices) might lead to an out-of-memory error. | ||
| 790 | - int[] texels = new int[16 * 16]; | ||
| 791 | - for (int y = 0; y < height + 16; y += 16) { | ||
| 792 | - int h = PApplet.min(16, height - y); | ||
| 793 | - for (int x = 0; x < width + 16; x += 16) { | ||
| 794 | - int w = PApplet.min(16, width - x); | ||
| 795 | - setTexels(texels, x, y, w, h); | ||
| 796 | - } | ||
| 797 | - } | ||
| 798 | - texels = null; | ||
| 786 | + // Makes sure that the texture buffer in video memory doesn't contain any garbage. | ||
| 787 | + pgl.initTexture(glTarget, width, height, PGL.GL_RGBA, PGL.GL_UNSIGNED_BYTE); | ||
| 799 | 788 | ||
| 800 | 789 | pgl.glBindTexture(glTarget, 0); | |
| 801 | 790 | pgl.disableTexturing(glTarget); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,15 @@ public interface PConstants { | |||
| 46 | 46 | static public final int FLUSH_CONTINUOUSLY = 0; | |
| 47 | 47 | static public final int FLUSH_WHEN_FULL = 1; | |
| 48 | 48 | ||
| 49 | + // shaders | ||
| 50 | + | ||
| 51 | + static public final int FILL_SHADER_SIMPLE = 0; | ||
| 52 | + static public final int FILL_SHADER_LIT = 1; | ||
| 53 | + static public final int FILL_SHADER_TEX = 2; | ||
| 54 | + static public final int FILL_SHADER_FULL = 3; | ||
| 55 | + static public final int LINE_SHADER = 4; | ||
| 56 | + static public final int POINT_SHADER = 5; | ||
| 57 | + | ||
| 49 | 58 | // vertex fields | |
| 50 | 59 | ||
| 51 | 60 | static public final int X = 0; // model coords xyz (formerly MX/MY/MZ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments