Skip to content

Commit 97e73e5

Browse files
committed
android sync
1 parent b278d73 commit 97e73e5

File tree

8 files changed

+319
-72
lines changed

8 files changed

+319
-72
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ public PGL(PGraphicsOpenGL pg) {
334334
}
335335

336336

337+
/**
338+
* Return the native canvas the OpenGL context associated to this PGL object
339+
* is rendering to (if any).
340+
*/
341+
public abstract Object getCanvas();
342+
343+
337344
protected abstract void setFps(float fps);
338345

339346

@@ -836,7 +843,7 @@ protected void initTexture(int target, int format, int width, int height,
836843
int initColor) {
837844
int[] glcolor = new int[16 * 16];
838845
Arrays.fill(glcolor, javaToNativeARGB(initColor));
839-
IntBuffer texels = PGL.allocateDirectIntBuffer(16 * 16);
846+
IntBuffer texels = allocateDirectIntBuffer(16 * 16);
840847
texels.put(glcolor);
841848
texels.rewind();
842849
for (int y = 0; y < height; y += 16) {
@@ -987,8 +994,8 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
987994
uniform1i(tex2DSamplerLoc, 0);
988995

989996
texData.position(0);
990-
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
991-
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
997+
bindBuffer(ARRAY_BUFFER, texGeoVBO);
998+
bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, STATIC_DRAW);
992999

9931000
vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
9941001
vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
@@ -1113,8 +1120,8 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
11131120
uniform1i(texRectSamplerLoc, 0);
11141121

11151122
texData.position(0);
1116-
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
1117-
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
1123+
bindBuffer(ARRAY_BUFFER, texGeoVBO);
1124+
bufferData(ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, STATIC_DRAW);
11181125

11191126
vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
11201127
vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
@@ -1193,7 +1200,7 @@ protected static int nextPowerOfTwo(int val) {
11931200
* endian) to Java ARGB.
11941201
*/
11951202
protected static int nativeToJavaARGB(int color) {
1196-
if (PGL.BIG_ENDIAN) { // RGBA to ARGB
1203+
if (BIG_ENDIAN) { // RGBA to ARGB
11971204
return (color >>> 8) | ((color << 24) & 0xFF000000);
11981205
// equivalent to
11991206
// ((color >> 8) & 0x00FFFFFF) | ((color << 24) & 0xFF000000)
@@ -1706,7 +1713,7 @@ protected static ByteBuffer allocateByteBuffer(int size) {
17061713

17071714
protected static ByteBuffer allocateByteBuffer(byte[] arr) {
17081715
if (USE_DIRECT_BUFFERS) {
1709-
return PGL.allocateDirectByteBuffer(arr.length);
1716+
return allocateDirectByteBuffer(arr.length);
17101717
} else {
17111718
return ByteBuffer.wrap(arr);
17121719
}
@@ -1717,7 +1724,7 @@ protected static ByteBuffer updateByteBuffer(ByteBuffer buf, byte[] arr,
17171724
boolean wrap) {
17181725
if (USE_DIRECT_BUFFERS) {
17191726
if (buf == null || buf.capacity() < arr.length) {
1720-
buf = PGL.allocateDirectByteBuffer(arr.length);
1727+
buf = allocateDirectByteBuffer(arr.length);
17211728
}
17221729
buf.position(0);
17231730
buf.put(arr);
@@ -1795,7 +1802,7 @@ protected static ShortBuffer allocateShortBuffer(int size) {
17951802

17961803
protected static ShortBuffer allocateShortBuffer(short[] arr) {
17971804
if (USE_DIRECT_BUFFERS) {
1798-
return PGL.allocateDirectShortBuffer(arr.length);
1805+
return allocateDirectShortBuffer(arr.length);
17991806
} else {
18001807
return ShortBuffer.wrap(arr);
18011808
}
@@ -1806,7 +1813,7 @@ protected static ShortBuffer updateShortBuffer(ShortBuffer buf, short[] arr,
18061813
boolean wrap) {
18071814
if (USE_DIRECT_BUFFERS) {
18081815
if (buf == null || buf.capacity() < arr.length) {
1809-
buf = PGL.allocateDirectShortBuffer(arr.length);
1816+
buf = allocateDirectShortBuffer(arr.length);
18101817
}
18111818
buf.position(0);
18121819
buf.put(arr);
@@ -1884,7 +1891,7 @@ protected static IntBuffer allocateIntBuffer(int size) {
18841891

18851892
protected static IntBuffer allocateIntBuffer(int[] arr) {
18861893
if (USE_DIRECT_BUFFERS) {
1887-
return PGL.allocateDirectIntBuffer(arr.length);
1894+
return allocateDirectIntBuffer(arr.length);
18881895
} else {
18891896
return IntBuffer.wrap(arr);
18901897
}
@@ -1895,7 +1902,7 @@ protected static IntBuffer updateIntBuffer(IntBuffer buf, int[] arr,
18951902
boolean wrap) {
18961903
if (USE_DIRECT_BUFFERS) {
18971904
if (buf == null || buf.capacity() < arr.length) {
1898-
buf = PGL.allocateDirectIntBuffer(arr.length);
1905+
buf = allocateDirectIntBuffer(arr.length);
18991906
}
19001907
buf.position(0);
19011908
buf.put(arr);
@@ -1972,7 +1979,7 @@ protected static FloatBuffer allocateFloatBuffer(int size) {
19721979

19731980
protected static FloatBuffer allocateFloatBuffer(float[] arr) {
19741981
if (USE_DIRECT_BUFFERS) {
1975-
return PGL.allocateDirectFloatBuffer(arr.length);
1982+
return allocateDirectFloatBuffer(arr.length);
19761983
} else {
19771984
return FloatBuffer.wrap(arr);
19781985
}
@@ -1983,7 +1990,7 @@ protected static FloatBuffer updateFloatBuffer(FloatBuffer buf, float[] arr,
19831990
boolean wrap) {
19841991
if (USE_DIRECT_BUFFERS) {
19851992
if (buf == null || buf.capacity() < arr.length) {
1986-
buf = PGL.allocateDirectFloatBuffer(arr.length);
1993+
buf = allocateDirectFloatBuffer(arr.length);
19871994
}
19881995
buf.position(0);
19891996
buf.put(arr);

core/src/processing/opengl/PGLES.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import android.opengl.GLSurfaceView.EGLConfigChooser;
1717
import android.opengl.GLSurfaceView.Renderer;
1818
import android.opengl.GLU;
19-
2019
import processing.core.PApplet;
2120
import processing.opengl.tess.PGLU;
2221
import processing.opengl.tess.PGLUtessellator;
@@ -87,6 +86,12 @@ public PGLES(PGraphicsOpenGL pg) {
8786
}
8887

8988

89+
@Override
90+
public GLSurfaceView getCanvas() {
91+
return glview;
92+
}
93+
94+
9095
@Override
9196
protected void setFps(float fps) { }
9297

core/src/processing/opengl/PGraphics2D.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public void frustum(float left, float right, float bottom, float top,
119119

120120
@Override
121121
protected void defaultPerspective() {
122+
// The camera part of the modelview is simply the identity matrix, so in
123+
// order to the ortho projection to be consistent with this, it needs to be
124+
// set as follows, because ortho() will shift the viewing rectangle at
125+
// (width/2, height/2) and will also apply the axis inversion along Y:
122126
super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1);
123127
}
124128

@@ -180,12 +184,6 @@ protected void end2D() {
180184
popProjection();
181185
}
182186

183-
// @Override
184-
// public void resetMatrix() {
185-
// super.resetMatrix();
186-
// defaultCamera();
187-
// }
188-
189187

190188
//////////////////////////////////////////////////////////////
191189

core/src/processing/opengl/PGraphics3D.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,20 @@ protected void begin2D() {
8787
pushProjection();
8888
ortho(0, width, 0, height, -1, +1);
8989
pushMatrix();
90-
camera(width/2, height/2);
90+
91+
// Set camera for 2D rendering, it simply centers at (width/2, height/2)
92+
float centerX = width/2;
93+
float centerY = height/2;
94+
modelview.reset();
95+
modelview.translate(-centerX, -centerY);
96+
97+
modelviewInv.set(modelview);
98+
modelviewInv.invert();
99+
100+
camera.set(modelview);
101+
cameraInv.set(modelviewInv);
102+
103+
updateProjmodelview();
91104
}
92105

93106

0 commit comments

Comments
 (0)