Skip to content

Commit 8337f5d

Browse files
committed
Fixed calculation of texture matrix, some tweaks in beginDraw()
1 parent d616cb3 commit 8337f5d

5 files changed

Lines changed: 96 additions & 125 deletions

File tree

android/core/src/processing/core/PApplet.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,11 +1585,6 @@ public PGraphics createGraphics(int iwidth, int iheight, String irenderer) {
15851585
pg.setPrimary(false);
15861586
pg.setSize(iwidth, iheight);
15871587

1588-
// In the case of A3D, the first beginDraw/endDraw
1589-
// call is needed to initialize the offscreen buffers.
1590-
pg.beginDraw();
1591-
pg.endDraw();
1592-
15931588
return pg;
15941589
}
15951590

android/core/src/processing/core/PGL.java

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ public class PGL {
305305

306306
// Intialization, finalization
307307

308-
// TODO: implement double buffering support in offscreen rendering.
309-
310308

311309
public PGL(PGraphicsAndroid3D pg) {
312310
this.pg = pg;
@@ -320,6 +318,19 @@ public void setFramerate(float framerate) {
320318
}
321319

322320

321+
public void initPrimarySurface(int antialias) {
322+
// We do the initialization in updatePrimary() because
323+
// at the moment initPrimarySurface() gets called we
324+
// cannot rely on the GL surface actually being
325+
// available.
326+
}
327+
328+
329+
public void initOffscreenSurface(PGL primary) {
330+
initialized = true;
331+
}
332+
333+
323334
public void updatePrimary() {
324335
if (!initialized) {
325336
String ext = GLES20.glGetString(GLES20.GL_EXTENSIONS);
@@ -374,61 +385,6 @@ public void updateOffscreen(PGL primary) {
374385
gl = primary.gl;
375386
}
376387

377-
378-
379-
public void initPrimarySurface(int antialias) {
380-
}
381-
382-
383-
public void initOffscreenSurface(PGL primary) {
384-
385-
/*
386-
offscreenTexCrop = new int[4];
387-
offscreenTexCrop[0] = 0;
388-
offscreenTexCrop[1] = 0;
389-
offscreenTexCrop[2] = width;
390-
offscreenTexCrop[3] = height;
391-
392-
offscreenImages = new PImage[2];
393-
offscreenParams = new PTexture.Parameters[2];
394-
// Linear filtering is needed to keep decent image quality when rendering
395-
// texture at a size different from its original resolution. This is expected
396-
// to happen for offscreen rendering.
397-
offscreenParams[0] = new PTexture.Parameters(ARGB, BILINEAR);
398-
offscreenParams[1] = new PTexture.Parameters(ARGB, BILINEAR);
399-
offscreenImages[0] = parent.createImage(width, height, ARGB, offscreenParams[0]);
400-
offscreenImages[1] = parent.createImage(width, height, ARGB, offscreenParams[1]);
401-
402-
403-
offscreenTextures = new PTexture[2];
404-
offscreenTextures[0] = addTexture(offscreenImages[0]);
405-
offscreenTextures[1] = addTexture(offscreenImages[1]);
406-
407-
// Drawing textures are marked as flipped along Y to ensure they are properly
408-
// rendered by Processing, which has inverted Y axis with respect to
409-
// OpenGL.
410-
offscreenTextures[0].setFlippedY(true);
411-
offscreenTextures[1].setFlippedY(true);
412-
413-
offscreenIndex = 0;
414-
415-
416-
417-
418-
419-
offscreenFramebuffer = new PFramebuffer(parent, offscreenTextures[0].glWidth, offscreenTextures[0].glHeight,
420-
1, 1, offscreenDepthBits, offscreenStencilBits, false);
421-
422-
// The image texture points to the current offscreen texture.
423-
texture = offscreenTextures[offscreenIndex];
424-
this.setCache(a3d, offscreenTextures[offscreenIndex]);
425-
this.setParams(a3d, offscreenParams[offscreenIndex]);
426-
*/
427-
428-
429-
initialized = true;
430-
}
431-
432388

433389
///////////////////////////////////////////////////////////////////////////////////
434390

@@ -488,23 +444,10 @@ public void endOnscreenDraw(boolean clear0) {
488444

489445

490446
public void beginOffscreenDraw(boolean clear) {
491-
/*
492-
// Drawing contents of back color buffer as background.
493-
gl.glClearColor(0, 0, 0, 0);
494-
if (clear || frame == 0) {
495-
// No need to draw back color buffer.
496-
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
497-
} else {
498-
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
499-
// Render previous draw texture as background.
500-
drawOffscreenTexture((offscreenIndex + 1) % 2);
501-
}
502-
*/
503447
}
504448

505449

506450
public void endOffscreenDraw(boolean clear0) {
507-
//swapOffscreenIndex();
508451
}
509452

510453

@@ -795,7 +738,7 @@ public void glRenderbufferStorageMultisample(int target, int samples, int format
795738

796739

797740
public void glRenderbufferStorage(int target, int format, int width, int height) {
798-
// GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, format, w, h);
741+
GLES20.glRenderbufferStorage(target, format, width, height);
799742
}
800743

801744

android/core/src/processing/core/PGraphicsAndroid3D.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ public class PGraphicsAndroid3D extends PGraphics {
299299
/** Used to detect the occurrence of a frame resize event. */
300300
protected boolean resized = false;
301301

302-
/** Stores previous viewport dimensions. */
303-
protected int[] savedViewport = {0, 0, 0, 0};
302+
/** Viewport dimensions. */
304303
protected int[] viewport = {0, 0, 0, 0};
305304

306305
/** Used to register calls to glClear. */
@@ -1443,8 +1442,8 @@ public void beginDraw() {
14431442
pgl.glDisable(PGL.GL_POLYGON_SMOOTH);
14441443
}
14451444

1446-
// setup opengl viewport.
1447-
pgl.glGetIntegerv(PGL.GL_VIEWPORT, savedViewport, 0);
1445+
1446+
// setup opengl viewport.
14481447
viewport[0] = 0; viewport[1] = 0; viewport[2] = width; viewport[3] = height;
14491448
pgl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
14501449
if (resized) {
@@ -1504,7 +1503,10 @@ public void beginDraw() {
15041503
if (primarySurface) {
15051504
pgl.beginOnscreenDraw(clearColorBuffer);
15061505
} else {
1507-
pgl.beginOffscreenDraw(clearColorBuffer);
1506+
pgl.beginOffscreenDraw(clearColorBuffer);
1507+
1508+
// Just in case the texture was recreated (in a resize event for example)
1509+
offscreenFramebuffer.setColorBuffer(texture);
15081510
}
15091511

15101512
if (hints[DISABLE_DEPTH_MASK]) {
@@ -1539,9 +1541,6 @@ public void endDraw() {
15391541
return;
15401542
}
15411543

1542-
// Restoring previous viewport.
1543-
pgl.glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]);
1544-
15451544
if (primarySurface) {
15461545
pgl.endOnscreenDraw(clearColorBuffer0);
15471546
pgl.glFlush();
@@ -1555,7 +1554,7 @@ public void endDraw() {
15551554

15561555
pg.restoreGL();
15571556
}
1558-
1557+
15591558
drawing = false;
15601559

15611560
report("bot endDraw()");
@@ -5587,7 +5586,7 @@ protected void initOffscreen() {
55875586

55885587
pgl.updateOffscreen(pg.pgl);
55895588
loadTextureImpl(BILINEAR);
5590-
5589+
55915590
// In case of reinitialization (for example, when the smooth level
55925591
// is changed), we make sure that all the OpenGL resources associated
55935592
// to the surface are released by calling delete().
@@ -5598,8 +5597,6 @@ protected void initOffscreen() {
55985597
offscreenFramebufferMultisample.release();
55995598
}
56005599

5601-
// We need the GL2GL3 profile to access the glRenderbufferStorageMultisample
5602-
// function used in multisampled (antialiased) offscreen rendering.
56035600
if (PGraphicsAndroid3D.fboMultisampleSupported && 1 < antialias) {
56045601
offscreenFramebufferMultisample = new PFramebuffer(parent, texture.glWidth, texture.glHeight, antialias, 0,
56055602
PGL.DEFAULT_DEPTH_BITS, PGL.DEFAULT_STENCIL_BITS,
@@ -5623,7 +5620,7 @@ protected void initOffscreen() {
56235620
}
56245621

56255622
offscreenFramebuffer.setColorBuffer(texture);
5626-
offscreenFramebuffer.clear();
5623+
offscreenFramebuffer.clear();
56275624
}
56285625

56295626

@@ -6109,16 +6106,26 @@ public void setTexCoordAttribute(int vboId, int size, int type, int stride, int
61096106
}
61106107

61116108
public void setTexture(PTexture tex) {
6112-
float scaleu = tex.maxTexCoordU;
6113-
float scalev = tex.maxTexCoordV;
6109+
float scaleu = 1;
6110+
float scalev = 1;
61146111
float dispu = 0;
61156112
float dispv = 0;
6113+
6114+
if (tex.isFlippedX()) {
6115+
scaleu = -1;
6116+
dispu = 1;
6117+
}
61166118

61176119
if (tex.isFlippedY()) {
6118-
scalev *= -1;
6120+
scalev = -1;
61196121
dispv = 1;
61206122
}
61216123

6124+
scaleu *= tex.maxTexCoordU;
6125+
dispu *= tex.maxTexCoordU;
6126+
scalev *= tex.maxTexCoordV;
6127+
dispv *= tex.maxTexCoordV;
6128+
61226129
if (tcmat == null) {
61236130
tcmat = new float[16];
61246131
}
@@ -6184,16 +6191,26 @@ public void setTexCoordAttribute(int vboId, int size, int type, int stride, int
61846191
}
61856192

61866193
public void setTexture(PTexture tex) {
6187-
float scaleu = tex.maxTexCoordU;
6188-
float scalev = tex.maxTexCoordV;
6194+
float scaleu = 1;
6195+
float scalev = 1;
61896196
float dispu = 0;
61906197
float dispv = 0;
6198+
6199+
if (tex.isFlippedX()) {
6200+
scaleu = -1;
6201+
dispu = 1;
6202+
}
61916203

61926204
if (tex.isFlippedY()) {
6193-
scalev *= -1;
6205+
scalev = -1;
61946206
dispv = 1;
61956207
}
61966208

6209+
scaleu *= tex.maxTexCoordU;
6210+
dispu *= tex.maxTexCoordU;
6211+
scalev *= tex.maxTexCoordV;
6212+
dispv *= tex.maxTexCoordV;
6213+
61976214
if (tcmat == null) {
61986215
tcmat = new float[16];
61996216
}

java/libraries/opengl/src/processing/opengl/PGL.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,7 @@ public void setFramerate(float framerate) {
359359
setFramerate = true;
360360
}
361361

362-
363-
public void updatePrimary() {
364-
if (!setFramerate) {
365-
setFramerate(targetFramerate);
366-
}
367-
}
368362

369-
370-
public void updateOffscreen(PGL primary) {
371-
gl = primary.gl;
372-
gl2 = primary.gl2;
373-
}
374-
375-
376363
public void initPrimarySurface(int antialias) {
377364
if (profile == null) {
378365
profile = GLProfile.getDefault();
@@ -439,7 +426,20 @@ public void initOffscreenSurface(PGL primary) {
439426
capabilities = primary.capabilities;
440427
drawable = null;
441428
initialized = true;
442-
}
429+
}
430+
431+
432+
public void updatePrimary() {
433+
if (!setFramerate) {
434+
setFramerate(targetFramerate);
435+
}
436+
}
437+
438+
439+
public void updateOffscreen(PGL primary) {
440+
gl = primary.gl;
441+
gl2 = primary.gl2;
442+
}
443443

444444

445445
///////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)