Skip to content

Commit 5991080

Browse files
committed
start clean-up of surface handling (onscreen and offscreen)
1 parent 0a81703 commit 5991080

3 files changed

Lines changed: 176 additions & 12 deletions

File tree

core/src/processing/opengl/PGL.java

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ protected void updateOffscreen(PGL primary) {
630630
}
631631

632632

633+
634+
635+
636+
637+
// CLEANUP!
638+
633639
protected int primaryReadFramebuffer() {
634640
if (capabilities.isFBO()) {
635641
return context.getDefaultReadFramebuffer();
@@ -638,6 +644,7 @@ protected int primaryReadFramebuffer() {
638644
}
639645
}
640646

647+
641648
protected int primaryDrawFramebuffer() {
642649
if (capabilities.isFBO()) {
643650
return context.getDefaultDrawFramebuffer();
@@ -662,26 +669,88 @@ protected int primaryReadBuffer() {
662669
}
663670
}
664671

665-
protected boolean primaryIsFboBacked() {
672+
673+
674+
675+
protected boolean isFBOBacked() {
666676
return capabilities.isFBO();
667677
}
668678

669-
protected int getFboTexTarget() {
679+
protected int getBackTexName() {
680+
return backTex.getName();
681+
}
682+
683+
protected int getBackTexTarget() {
670684
return GL.GL_TEXTURE_2D;
671685
}
672686

673-
protected int getFboTexName() {
674-
return backTex.getName();
687+
protected int getBackTexFormat() {
688+
return backTex.format;
675689
}
676690

677-
protected int getFboWidth() {
691+
protected int getBackTexWidth() {
678692
return backTex.getWidth();
679693
}
680694

681-
protected int getFboHeight() {
695+
protected int getBackTexHeight() {
682696
return backTex.getHeight();
683697
}
684698

699+
protected int getBackTexMinFilter() {
700+
return backTex.minFilter;
701+
}
702+
703+
protected int getBackTexMagFilter() {
704+
return backTex.magFilter;
705+
}
706+
707+
protected int getBackTexWrapS() {
708+
return backTex.wrapS;
709+
}
710+
711+
protected int getBackTexWrapT() {
712+
return backTex.wrapT;
713+
}
714+
715+
protected int getFrontTexName() {
716+
return frontTex.getName();
717+
}
718+
719+
protected int getFrontTexTarget() {
720+
return GL.GL_TEXTURE_2D;
721+
}
722+
723+
protected int getFrontTexFormat() {
724+
return frontTex.format;
725+
}
726+
727+
protected int getFrontTexWidth() {
728+
return frontTex.getWidth();
729+
}
730+
731+
protected int getFrontTexHeight() {
732+
return frontTex.getHeight();
733+
}
734+
735+
protected int getFrontTexMinFilter() {
736+
return frontTex.minFilter;
737+
}
738+
739+
protected int getFrontTexMagFilter() {
740+
return frontTex.magFilter;
741+
}
742+
743+
protected int getFrontTexWrapS() {
744+
return frontTex.wrapS;
745+
}
746+
747+
protected int getFrontTexWrapT() {
748+
return frontTex.wrapT;
749+
}
750+
751+
752+
753+
685754
/*
686755
protected void bindPrimaryColorFBO() {
687756
if (multisample) {
@@ -775,6 +844,11 @@ protected void unbindBackBufferTex() {
775844
}
776845

777846

847+
848+
849+
850+
851+
778852
///////////////////////////////////////////////////////////
779853

780854
// Frame rendering

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,12 @@ public class PGraphicsOpenGL extends PGraphics {
390390

391391
// Screen surface:
392392

393-
/** A handy reference to the PTexture bound to the drawing surface
394-
* (off or on-screen) */
393+
/** Texture containing the current frame */
395394
protected Texture texture;
396395

396+
/** Texture containing the previous frame */
397+
protected Texture ptexture;
398+
397399
/** Used to create a temporary copy of the color buffer of this
398400
* rendering surface when applying a filter */
399401
// protected Texture textureCopy;
@@ -1893,7 +1895,7 @@ protected void beginPixelsOp(int op) {
18931895
if (op == OP_READ) {
18941896
setFramebuffer(readFramebuffer);
18951897
pgl.readBuffer(pgl.primaryReadBuffer());
1896-
if (pgl.primaryIsFboBacked()) {
1898+
if (pgl.isFBOBacked()) {
18971899
pgl.forceUpdate();
18981900
}
18991901
} else {
@@ -5392,10 +5394,10 @@ public void loadTexture() {
53925394
if (primarySurface) {
53935395
loadTextureImpl(Texture.POINT, false);
53945396

5395-
if (pgl.primaryIsFboBacked()) {
5397+
if (pgl.isFBOBacked()) {
53965398
pgl.forceUpdate();
5397-
texture.set(pgl.getFboTexTarget(), pgl.getFboTexName(),
5398-
pgl.getFboWidth(), pgl.getFboHeight(), width, height);
5399+
texture.set(pgl.getBackTexTarget(), pgl.getBackTexName(),
5400+
pgl.getBackTexWidth(), pgl.getBackTexHeight(), width, height);
53995401
} else {
54005402
// Here we go the slow route: we first copy the contents of the color
54015403
// buffer into a pixels array (but we keep it in native format) and
@@ -5511,6 +5513,57 @@ protected void loadTextureImpl(int sampling, boolean mipmap) {
55115513
texture.colorBufferOf(this);
55125514
pgPrimary.setCache(this, texture);
55135515
}
5516+
5517+
5518+
5519+
/*
5520+
texture.glName = pgl.getBackTexName();
5521+
ptexture.glName = pgl.getFrontTexName();
5522+
5523+
if (width == 0 || height == 0) return;
5524+
if (texture == null || texture.contextIsOutdated()) {
5525+
if (primarySurface) {
5526+
if (pgl.isFBOBacked()) {
5527+
texture = new Texture(parent);
5528+
texture.init(pgl.getBackTexName(),
5529+
pgl.getBackTexTarget(), pgl.getBackTexFormat(),
5530+
pgl.getBackTexWidth(), pgl.getBackTexHeight(),
5531+
pgl.getBackTexMinFilter(), pgl.getBackTexMagFilter(),
5532+
pgl.getBackTexWrapS(), pgl.getBackTexWrapT());
5533+
texture.invertedY(true);
5534+
texture.colorBufferOf(this);
5535+
pgPrimary.setCache(this, texture);
5536+
5537+
ptexture = new Texture(parent);
5538+
ptexture.init(pgl.getFrontTexName(),
5539+
pgl.getFrontTexTarget(), pgl.getFrontTexFormat(),
5540+
pgl.getFrontTexWidth(), pgl.getFrontTexHeight(),
5541+
pgl.getFrontTexMinFilter(), pgl.getFrontTexMagFilter(),
5542+
pgl.getFrontTexWrapS(), pgl.getFrontTexWrapT());
5543+
ptexture.invertedY(true);
5544+
ptexture.colorBufferOf(this);
5545+
} else {
5546+
Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT, false);
5547+
texture = new Texture(parent, width, height, params);
5548+
texture.invertedY(true);
5549+
texture.colorBufferOf(this);
5550+
pgPrimary.setCache(this, texture);
5551+
5552+
ptexture = null;
5553+
}
5554+
} else {
5555+
Texture.Parameters params = new Texture.Parameters(ARGB, Texture.BILINEAR, false);
5556+
texture = new Texture(parent, width, height, params);
5557+
texture.invertedY(true);
5558+
texture.colorBufferOf(this);
5559+
pgPrimary.setCache(this, texture);
5560+
5561+
ptexture = new Texture(parent, width, height, params);
5562+
ptexture.invertedY(true);
5563+
ptexture.colorBufferOf(this);
5564+
}
5565+
}
5566+
*/
55145567
}
55155568

55165569

core/src/processing/opengl/Texture.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public class Texture implements PConstants {
108108

109109
// Constructors.
110110

111+
public Texture(PApplet parent) {
112+
this.parent = parent;
113+
114+
pg = (PGraphicsOpenGL)parent.g;
115+
pgl = pg.pgl;
116+
context = pgl.createEmptyContext();
117+
118+
pgDraw = null;
119+
120+
glName = 0;
121+
}
122+
111123

112124
/**
113125
* Creates an instance of PTexture with size width x height. The texture is
@@ -226,6 +238,31 @@ public boolean available() {
226238
return 0 < glName;
227239
}
228240

241+
/**
242+
* Initializes the texture using GL parameters
243+
*/
244+
public void init(int glName, int glTarget, int glFormat, int glWidth, int glHeight,
245+
int glMinFilter, int glMagFilter, int glWrapS, int glWrapT) {
246+
this.glName = glName;
247+
this.glTarget = glTarget;
248+
this.glFormat = glFormat;
249+
this.glWidth = glWidth;
250+
this.glHeight = glHeight;
251+
this.glMinFilter = glMinFilter;
252+
this.glMagFilter = glMagFilter;
253+
this.glWrapS = glWrapS;
254+
this.glWrapT = glWrapT;
255+
256+
width = glWidth;
257+
height = glHeight;
258+
maxTexcoordU = 1;
259+
maxTexcoordV = 1;
260+
261+
usingMipmaps = glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
262+
glMinFilter == PGL.LINEAR_MIPMAP_LINEAR;
263+
264+
usingRepeat = glWrapS == PGL.REPEAT || glWrapT == PGL.REPEAT;
265+
}
229266

230267
////////////////////////////////////////////////////////////
231268

0 commit comments

Comments
 (0)