diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index e0d46b773..523039859 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -337,23 +337,32 @@ public class PGL { public static final int POLYGON_SMOOTH = GL2.GL_POLYGON_SMOOTH; /** Basic GL functionality, common to all profiles */ - public GL gl; + public static GL gl; /** GLU interface **/ - public GLU glu; + public static GLU glu; /** The rendering context (holds rendering state info) */ - public GLContext context; + public static GLContext context; - /** The AWT canvas where OpenGL rendering takes place */ - public Canvas canvas; + /** The canvas where OpenGL rendering takes place */ + public static Canvas canvas; + + /** Selected GL profile */ + public static GLProfile profile; + + /** The capabilities of the OpenGL rendering surface */ + protected static GLCapabilitiesImmutable capabilities; + + /** The rendering surface */ + protected static GLDrawable drawable; /** GLES2 functionality (shaders, etc) */ - protected GL2ES2 gl2; + protected static GL2ES2 gl2; /** GL2 desktop functionality (blit framebuffer, map buffer range, * multisampled renerbuffers) */ - protected GL2 gl2x; + protected static GL2 gl2x; /** The PGraphics object using this interface */ protected PGraphicsOpenGL pg; @@ -375,29 +384,20 @@ public class PGL { protected static int request_stencil_bits = 0; protected static int request_alpha_bits = 8; - /** Selected GL profile */ - protected GLProfile profile; - - /** The capabilities of the OpenGL rendering surface */ - protected GLCapabilitiesImmutable capabilities; - - /** The rendering surface */ - protected GLDrawable drawable; - /** The AWT-OpenGL canvas */ - protected GLCanvas canvasAWT; + protected static GLCanvas canvasAWT; /** The NEWT-OpenGL canvas */ - protected NewtCanvasAWT canvasNEWT; + protected static NewtCanvasAWT canvasNEWT; /** The NEWT window */ - protected GLWindow window; + protected static GLWindow window; /** The listener that fires the frame rendering in Processing */ - protected PGLListener listener; + protected static PGLListener listener; /** Animator to drive the rendering thread in NEWT */ - protected NEWTAnimator animator; + protected static NEWTAnimator animator; /** Desired target framerate */ protected float targetFramerate = 60; @@ -429,32 +429,32 @@ public class PGL { // Texture rendering - protected boolean loadedTex2DShader = false; - protected int tex2DShaderProgram; - protected int tex2DVertShader; - protected int tex2DFragShader; - protected GLContext tex2DShaderContext; - protected int tex2DVertLoc; - protected int tex2DTCoordLoc; + protected static boolean loadedTex2DShader = false; + protected static int tex2DShaderProgram; + protected static int tex2DVertShader; + protected static int tex2DFragShader; + protected static GLContext tex2DShaderContext; + protected static int tex2DVertLoc; + protected static int tex2DTCoordLoc; - protected boolean loadedTexRectShader = false; - protected int texRectShaderProgram; - protected int texRectVertShader; - protected int texRectFragShader; - protected GLContext texRectShaderContext; - protected int texRectVertLoc; - protected int texRectTCoordLoc; + protected static boolean loadedTexRectShader = false; + protected static int texRectShaderProgram; + protected static int texRectVertShader; + protected static int texRectFragShader; + protected static GLContext texRectShaderContext; + protected static int texRectVertLoc; + protected static int texRectTCoordLoc; - protected float[] texCoords = { + protected static float[] texCoords = { // X, Y, U, V -1.0f, -1.0f, 0.0f, 0.0f, +1.0f, -1.0f, 1.0f, 0.0f, -1.0f, +1.0f, 0.0f, 1.0f, +1.0f, +1.0f, 1.0f, 1.0f }; - protected FloatBuffer texData; + protected static FloatBuffer texData; - protected String texVertShaderSource = + protected static String texVertShaderSource = "attribute vec2 inVertex;" + "attribute vec2 inTexcoord;" + "varying vec2 vertTexcoord;" + @@ -463,7 +463,7 @@ public class PGL { " vertTexcoord = inTexcoord;" + "}"; - protected String tex2DFragShaderSource = + protected static String tex2DFragShaderSource = SHADER_PREPROCESSOR_DIRECTIVE + "uniform sampler2D textureSampler;" + "varying vec2 vertTexcoord;" + @@ -471,7 +471,7 @@ public class PGL { " gl_FragColor = texture2D(textureSampler, vertTexcoord.st);" + "}"; - protected String texRectFragShaderSource = + protected static String texRectFragShaderSource = SHADER_PREPROCESSOR_DIRECTIVE + "uniform sampler2DRect textureSampler;" + "varying vec2 vertTexcoord;" + @@ -495,7 +495,9 @@ public class PGL { public PGL(PGraphicsOpenGL pg) { this.pg = pg; - glu = new GLU(); + if (glu == null) { + glu = new GLU(); + } initialized = false; } @@ -523,7 +525,7 @@ public class PGL { } - protected void initPrimarySurface(int antialias) { + protected void initSurface(int antialias) { if (profile == null) { profile = GLProfile.getDefault(); } else { @@ -609,34 +611,14 @@ public class PGL { } - protected void initOffscreenSurface(PGL primary) { - context = primary.context; - capabilities = primary.capabilities; - drawable = null; - initialized = true; - } - - - protected void updatePrimary() { + protected void update() { if (!setFramerate) { setFrameRate(targetFramerate); } } - protected void updateOffscreen(PGL primary) { - gl = primary.gl; - gl2 = primary.gl2; - gl2x = primary.gl2x; - } - - - - - - // CLEANUP! - - protected int primaryReadFramebuffer() { + protected int getReadFramebuffer() { if (capabilities.isFBO()) { return context.getDefaultReadFramebuffer(); } else { @@ -645,7 +627,7 @@ public class PGL { } - protected int primaryDrawFramebuffer() { + protected int getDrawFramebuffer() { if (capabilities.isFBO()) { return context.getDefaultDrawFramebuffer(); } else { @@ -653,15 +635,8 @@ public class PGL { } } - protected int primaryDrawBuffer() { - if (capabilities.isFBO()) { - return GL.GL_COLOR_ATTACHMENT0; - } else { - return GL.GL_BACK; - } - } - protected int primaryReadBuffer() { + protected int getBackBuffer() { if (capabilities.isFBO()) { return GL.GL_COLOR_ATTACHMENT0; } else { @@ -670,165 +645,66 @@ public class PGL { } + protected int getFrontBuffer() { + if (capabilities.isFBO()) { + return GL.GL_COLOR_ATTACHMENT0; + } else { + return GL.GL_BACK; + } + } protected boolean isFBOBacked() { return capabilities.isFBO(); } - protected int getBackTexName() { + + protected Texture wrapBackTexture() { + Texture tex = new Texture(pg.parent); + tex.init(backTex.getName(), + GL.GL_TEXTURE_2D, backTex.format, + backTex.getWidth(), backTex.getHeight(), + backTex.minFilter, backTex.magFilter, + backTex.wrapS, backTex.wrapT); + tex.invertedY(true); + tex.colorBufferOf(pg); + pg.setCache(pg, tex); + return tex; + } + + + protected Texture wrapFrontTexture() { + Texture tex = new Texture(pg.parent); + tex.init(backTex.getName(), + GL.GL_TEXTURE_2D, frontTex.format, + frontTex.getWidth(), frontTex.getHeight(), + frontTex.minFilter, frontTex.magFilter, + frontTex.wrapS, frontTex.wrapT); + tex.invertedY(true); + tex.colorBufferOf(pg); + return tex; + } + + + int getBackTextureName() { return backTex.getName(); } - protected int getBackTexTarget() { - return GL.GL_TEXTURE_2D; - } - protected int getBackTexFormat() { - return backTex.format; - } - - protected int getBackTexWidth() { - return backTex.getWidth(); - } - - protected int getBackTexHeight() { - return backTex.getHeight(); - } - - protected int getBackTexMinFilter() { - return backTex.minFilter; - } - - protected int getBackTexMagFilter() { - return backTex.magFilter; - } - - protected int getBackTexWrapS() { - return backTex.wrapS; - } - - protected int getBackTexWrapT() { - return backTex.wrapT; - } - - protected int getFrontTexName() { + int getFrontTextureName() { return frontTex.getName(); } - protected int getFrontTexTarget() { - return GL.GL_TEXTURE_2D; - } - - protected int getFrontTexFormat() { - return frontTex.format; - } - - protected int getFrontTexWidth() { - return frontTex.getWidth(); - } - - protected int getFrontTexHeight() { - return frontTex.getHeight(); - } - - protected int getFrontTexMinFilter() { - return frontTex.minFilter; - } - - protected int getFrontTexMagFilter() { - return frontTex.magFilter; - } - - protected int getFrontTexWrapS() { - return frontTex.wrapS; - } - - protected int getFrontTexWrapT() { - return frontTex.wrapT; - } - - - - - /* - protected void bindPrimaryColorFBO() { - if (multisample) { - // Blit the contents of the multisampled FBO into the color FBO, - // so the later is up to date. - gl.glBindFramebuffer(GL2.GL_READ_FRAMEBUFFER, glMultiFbo[0]); - gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, glColorFbo[0]); - gl2x.glBlitFramebuffer(0, 0, fboWidth, fboHeight, - 0, 0, fboWidth, fboHeight, - GL.GL_COLOR_BUFFER_BIT, GL.GL_NEAREST); - } - - gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glColorFbo[0]); - PGraphicsOpenGL.screenFramebuffer.glFbo = glColorFbo[0]; - - // Make the color buffer opaque so it doesn't show - // the background when drawn on top of another surface. - gl.glColorMask(false, false, false, true); - gl.glClearColor(0, 0, 0, 1); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); - gl.glColorMask(true, true, true, true); - } - - - protected void bindPrimaryMultiFBO() { - if (multisample) { - gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, glMultiFbo[0]); - PGraphicsOpenGL.screenFramebuffer.glFbo = glMultiFbo[0]; - } - } - - - protected void releaseScreenFBO() { - gl.glDeleteTextures(1, glColorTex, 0); - gl.glDeleteFramebuffers(1, glColorFbo, 0); - if (packedDepthStencil) { - gl.glDeleteRenderbuffers(1, glPackedDepthStencil, 0); - } else { - gl.glDeleteRenderbuffers(1, glDepthBuffer, 0); - gl.glDeleteRenderbuffers(1, glStencilBuffer, 0); - } - if (multisample) { - gl.glDeleteFramebuffers(1, glMultiFbo, 0); - gl.glDeleteRenderbuffers(1, glColorRenderBuffer, 0); - } - } -*/ - - protected int qualityToSamples(int quality) { - if (quality <= 1) { - return 1; - } else { - // Number of samples is always an even number: - int n = 2 * (quality / 2); - return n; - } - } - - protected void forceUpdate() { - if (0 < capabilities.getNumSamples()) { - backFBO.syncSamplingSink(gl); - backFBO.bind(gl); - } - } - - - protected void bindBackBufferTex() { + protected void bindFrontTexture() { if (!texturingIsEnabled(GL.GL_TEXTURE_2D)) { enableTexturing(GL.GL_TEXTURE_2D); } gl.glBindTexture(GL.GL_TEXTURE_2D, frontTex.getName()); - } - protected void unbindBackBufferTex() { - + protected void unbindFrontTexture() { if (textureIsBound(GL.GL_TEXTURE_2D, frontTex.getName())) { // We don't want to unbind another texture // that might be bound instead of this one. @@ -840,13 +716,26 @@ public class PGL { gl.glBindTexture(GL.GL_TEXTURE_2D, 0); } } - } + protected void syncBackTexture() { + if (0 < capabilities.getNumSamples()) { + backFBO.syncSamplingSink(gl); + backFBO.bind(gl); + } + } - + protected int qualityToSamples(int quality) { + if (quality <= 1) { + return 1; + } else { + // Number of samples is always an even number: + int n = 2 * (quality / 2); + return n; + } + } /////////////////////////////////////////////////////////// @@ -854,11 +743,11 @@ public class PGL { // Frame rendering - protected void beginOnscreenDraw(boolean clear) { + protected void beginDraw(boolean clear) { } - protected void endOnscreenDraw(boolean clear0) { + protected void endDraw(boolean clear0) { if (!clear0 && isFBOBacked() && capabilities.getNumSamples() == 0) { // Draw the back texture into the front texture, which will be used as // front texture in the next frame. Otherwise flickering will occur if @@ -2513,7 +2402,7 @@ public class PGL { backTex = (FBObject.TextureAttachment) sinkFBO.getColorbuffer(0); frontTex = (FBObject.TextureAttachment)frontFBO.getColorbuffer(0); } else { - // W/out multisampling, rendering is done on the back buffer. + // w/out multisampling, rendering is done on the back buffer. frontFBO = fboDrawable.getFBObject(GL.GL_FRONT); backTex = fboDrawable.getTextureBuffer(GL.GL_BACK); diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a9f33cb06..44b54a953 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -398,11 +398,6 @@ public class PGraphicsOpenGL extends PGraphics { /** Texture containing the previous frame */ protected Texture ptexture; - /** Used to create a temporary copy of the color buffer of this - * rendering surface when applying a filter */ -// protected Texture textureCopy; -// protected PImage imageCopy; - /** IntBuffer wrapping the pixels array. */ protected IntBuffer pixelBuffer; @@ -432,8 +427,8 @@ public class PGraphicsOpenGL extends PGraphics { protected int lastSmoothCall = -10; /** Type of pixels operation. */ - static protected final int OP_NONE = 0; - static protected final int OP_READ = 1; + static protected final int OP_NONE = 0; + static protected final int OP_READ = 1; static protected final int OP_WRITE = 2; protected int pixelsOp = OP_NONE; @@ -484,7 +479,6 @@ public class PGraphicsOpenGL extends PGraphics { public PGraphicsOpenGL() { pgl = new PGL(this); - if (tessellator == null) { tessellator = new Tessellator(); } @@ -1575,15 +1569,18 @@ public class PGraphicsOpenGL extends PGraphics { if (readFramebuffer == null) { readFramebuffer = new FrameBuffer(parent, width, height, true); } -// if (pgl.isFBOBacked()) { -// loadTextureImpl(); -// } + if (pgl.isFBOBacked() && texture == null) { + texture = pgl.wrapBackTexture(); + ptexture = pgl.wrapFrontTexture(); + } - drawFramebuffer.setFBO(pgl.primaryDrawFramebuffer()); - readFramebuffer.setFBO(pgl.primaryReadFramebuffer()); + drawFramebuffer.setFBO(pgl.getDrawFramebuffer()); + readFramebuffer.setFBO(pgl.getReadFramebuffer()); + texture.glName = pgl.getBackTextureName(); + ptexture.glName = pgl.getFrontTextureName(); - pgl.updatePrimary(); - pgl.drawBuffer(pgl.primaryDrawBuffer()); + pgl.update(); + pgl.drawBuffer(pgl.getBackBuffer()); } else { if (!pgl.initialized) { initOffscreen(); @@ -1604,7 +1601,7 @@ public class PGraphicsOpenGL extends PGraphics { } else { setFramebuffer(offscreenFramebuffer); } - pgl.updateOffscreen(pgPrimary.pgl); +// pgl.updateOffscreen(pgPrimary.pgl); pgl.drawBuffer(PGL.COLOR_ATTACHMENT0); } @@ -1725,7 +1722,7 @@ public class PGraphicsOpenGL extends PGraphics { // Should go right after report("top beginDraw()") ------------------------- if (primarySurface) { - pgl.beginOnscreenDraw(clearColorBuffer); + pgl.beginDraw(clearColorBuffer); } else { beginOffscreenDraw(); } @@ -1735,10 +1732,12 @@ public class PGraphicsOpenGL extends PGraphics { defaultSettings(); } + /* if (restoreSurface) { restoreSurfaceFromPixels(); restoreSurface = false; } + */ if (hints[DISABLE_DEPTH_MASK]) { pgl.depthMask(false); @@ -1776,8 +1775,9 @@ public class PGraphicsOpenGL extends PGraphics { } if (primarySurface) { - pgl.endOnscreenDraw(clearColorBuffer0); + pgl.endDraw(clearColorBuffer0); + /* if (!pgl.initialized || parent.frameCount == 0) { // TODO: check this code and see if should go before endOnscreenDraw // Smooth was called at some point during drawing. We save @@ -1789,6 +1789,7 @@ public class PGraphicsOpenGL extends PGraphics { saveSurfaceToPixels(); restoreSurface = true; } + */ pgl.flush(); } else { @@ -1865,26 +1866,27 @@ public class PGraphicsOpenGL extends PGraphics { pgl.depthMask(true); } - pgl.drawBuffer(pgl.primaryDrawBuffer()); + pgl.drawBuffer(pgl.getBackBuffer()); } protected void beginPixelsOp(int op) { + // TODO: need to revise... if (primarySurface) { // We read or write from the back buffer, where all the // drawing in the current frame is taking place. pushFramebuffer(); if (op == OP_READ) { setFramebuffer(readFramebuffer); - pgl.readBuffer(pgl.primaryReadBuffer()); + pgl.readBuffer(pgl.getFrontBuffer()); if (pgl.isFBOBacked()) { - pgl.forceUpdate(); + pgl.syncBackTexture(); } } else { setFramebuffer(drawFramebuffer); - pgl.drawBuffer(pgl.primaryDrawBuffer()); + pgl.drawBuffer(pgl.getBackBuffer()); } offscreenNotCurrent = true; } else { @@ -1899,7 +1901,7 @@ public class PGraphicsOpenGL extends PGraphics { if (offscreenNotCurrent) { pushFramebuffer(); setFramebuffer(offscreenFramebuffer); - pgl.updateOffscreen(pgPrimary.pgl); + //pgl.updateOffscreen(pgPrimary.pgl); } pgl.readBuffer(PGL.COLOR_ATTACHMENT0); } else { @@ -1918,7 +1920,7 @@ public class PGraphicsOpenGL extends PGraphics { } else { setFramebuffer(offscreenFramebuffer); } - pgl.updateOffscreen(pgPrimary.pgl); + //pgl.updateOffscreen(pgPrimary.pgl); } pgl.drawBuffer(PGL.COLOR_ATTACHMENT0); } @@ -1928,6 +1930,8 @@ public class PGraphicsOpenGL extends PGraphics { protected void endPixelsOp() { + // TODO: need to revise... + if (offscreenNotCurrent) { if (!primarySurface && pixelsOp == OP_WRITE && offscreenMultisample) { // We were writing to the multisample FBO, so we need @@ -5226,8 +5230,10 @@ public class PGraphicsOpenGL extends PGraphics { PGL.javaToNativeARGB(nativePixels, w, h); // Copying pixel buffer to screen texture... - if (primarySurface) { - loadTextureImpl(POINT, false); // (first making sure that the screen texture is valid). + if (primarySurface && !pgl.isFBOBacked()) { + // First making sure that the screen texture is valid. Only in the case + // of non-FBO-backed primary surface we might need to create the texture. + loadTextureImpl(POINT, false); } pgl.copyToTexture(texture.glTarget, texture.glFormat, texture.glName, x, y, w, h, IntBuffer.wrap(nativePixels)); @@ -5301,13 +5307,13 @@ public class PGraphicsOpenGL extends PGraphics { flush(); // To make sure the color buffer is updated. if (primarySurface) { - loadTextureImpl(Texture.POINT, false); - if (pgl.isFBOBacked()) { - pgl.forceUpdate(); - texture.set(pgl.getBackTexTarget(), pgl.getBackTexName(), - pgl.getBackTexWidth(), pgl.getBackTexHeight(), width, height); + // In the case of MSAA, this is needed so the back buffer is in sync + // with the rendering. + pgl.syncBackTexture(); } else { + loadTextureImpl(Texture.POINT, false); + // Here we go the slow route: we first copy the contents of the color // buffer into a pixels array (but we keep it in native format) and // then copy this array into the texture. @@ -5358,40 +5364,6 @@ public class PGraphicsOpenGL extends PGraphics { endPixelsOp(); } -/* - // Uses the texture in img as the color buffer for this surface. - public void setTexture(PImage img) { - if (width != img.width || height != img.height) { - PGraphics.showWarning("Resolution of image is different from PGraphics " + - "object"); - return; - } - - if (texture == null || texture != pgPrimary.getCache(img)) { - Texture tex = (Texture)pgPrimary.getCache(img); - Texture.Parameters params = tex != null ? tex.getParameters() : null; - if (tex == null || tex.contextIsOutdated() || !validSurfaceTex(tex)) { - if (primarySurface) { - params = new Texture.Parameters(ARGB, Texture.POINT, false); - } else { - params = new Texture.Parameters(ARGB, Texture.BILINEAR, false); - } - tex = addTexture(img, params); - } - if (tex != null) { - texture = tex; - texture.invertedY(true); - pgPrimary.setCache(this, texture); - - if (!primarySurface && offscreenFramebuffer != null) { - // Attach as the color buffer for this offscreen surface - offscreenFramebuffer.setColorBuffer(texture); - offscreenFramebuffer.clear(); - } - } - } - } -*/ public void drawTexture(int target, int id, int width, int height, int X0, int Y0, int X1, int Y1) { @@ -5422,69 +5394,20 @@ public class PGraphicsOpenGL extends PGraphics { texture.invertedY(true); texture.colorBufferOf(this); pgPrimary.setCache(this, texture); - } - - -/* - if (width == 0 || height == 0) return; - if (texture == null || texture.contextIsOutdated()) { - if (primarySurface) { - if (pgl.isFBOBacked()) { - texture = new Texture(parent); - texture.init(pgl.getBackTexName(), - pgl.getBackTexTarget(), pgl.getBackTexFormat(), - pgl.getBackTexWidth(), pgl.getBackTexHeight(), - pgl.getBackTexMinFilter(), pgl.getBackTexMagFilter(), - pgl.getBackTexWrapS(), pgl.getBackTexWrapT()); - texture.invertedY(true); - texture.colorBufferOf(this); - pgPrimary.setCache(this, texture); - - ptexture = new Texture(parent); - ptexture.init(pgl.getFrontTexName(), - pgl.getFrontTexTarget(), pgl.getFrontTexFormat(), - pgl.getFrontTexWidth(), pgl.getFrontTexHeight(), - pgl.getFrontTexMinFilter(), pgl.getFrontTexMagFilter(), - pgl.getFrontTexWrapS(), pgl.getFrontTexWrapT()); - ptexture.invertedY(true); - ptexture.colorBufferOf(this); - } else { - Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT, false); - texture = new Texture(parent, width, height, params); - texture.invertedY(true); - texture.colorBufferOf(this); - pgPrimary.setCache(this, texture); - - ptexture = null; - } - } else { - Texture.Parameters params = new Texture.Parameters(ARGB, Texture.BILINEAR, false); - texture = new Texture(parent, width, height, params); - texture.invertedY(true); - texture.colorBufferOf(this); - pgPrimary.setCache(this, texture); + if (!primarySurface) { ptexture = new Texture(parent, width, height, params); ptexture.invertedY(true); ptexture.colorBufferOf(this); } } - */ } - protected void swapTexture() { - if (primarySurface) { - if (pgl.isFBOBacked()) { - texture.glName = pgl.getBackTexName(); - ptexture.glName = pgl.getFrontTexName(); - } - } else { - // Swap texture id's - int temp = texture.glName; - texture.glName = ptexture.glName; - ptexture.glName = temp; - } + protected void swapTextures() { + int temp = texture.glName; + texture.glName = ptexture.glName; + ptexture.glName = temp; } @@ -5502,54 +5425,6 @@ public class PGraphicsOpenGL extends PGraphics { } -/* - protected boolean validSurfaceTex(Texture tex) { - Texture.Parameters params = tex.getParameters(); - if (primarySurface) { - return params.sampling == Texture.POINT && !params.mipmaps; - } else { - return params.sampling == Texture.BILINEAR && !params.mipmaps; - } - } -*/ - - - ////////////////////////////////////////////////////////////// - - // IMAGE CONVERSION - - - /* - static public void nativeToJavaRGB(PImage image) { - if (image.pixels != null) { - PGL.nativeToJavaRGB(image.pixels, image.width, image.height); - } - } - - - static public void nativeToJavaARGB(PImage image) { - if (image.pixels != null) { - PGL.nativeToJavaARGB(image.pixels, image.width, image.height); - } - } - - - static public void javaToNativeRGB(PImage image) { - if (image.pixels != null) { - PGL.javaToNativeRGB(image.pixels, image.width, image.height); - } - } - - - static public void javaToNativeARGB(PImage image) { - if (image.pixels != null) { - PGL.javaToNativeARGB(image.pixels, image.width, image.height); - } - } - */ - - - ////////////////////////////////////////////////////////////// // MASK @@ -5620,19 +5495,6 @@ public class PGraphicsOpenGL extends PGraphics { loadTexture(); -/* - if (textureCopy == null || textureCopy.width != width || - textureCopy.height != height) { - Texture.Parameters params = new Texture.Parameters(ARGB, Texture.POINT, - false); - textureCopy = new Texture(parent, width, height, params); - textureCopy.invertedY(true); - imageCopy = wrapTexture(textureCopy); - } - textureCopy.set(texture.glTarget, texture.glName, - texture.glWidth, texture.glHeight, width, height); -*/ - // Disable writing to the depth buffer, so that after applying the filter we // can still use the depth information to keep adding geometry to the scene. pgl.depthMask(false); @@ -5908,7 +5770,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void bindBackTexture() { if (primarySurface) { - pgl.bindBackBufferTex(); + pgl.bindFrontTexture(); } else { ptexture.bind(); } @@ -5917,7 +5779,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void unbindBackTexture() { if (primarySurface) { - pgl.unbindBackBufferTex(); + pgl.unbindFrontTexture(); } else { ptexture.unbind(); } @@ -6014,7 +5876,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void initPrimary() { - pgl.initPrimarySurface(quality); + pgl.initSurface(quality); if (pgPrimary == null) { pgPrimary = this; } @@ -6024,14 +5886,12 @@ public class PGraphicsOpenGL extends PGraphics { protected void initOffscreen() { // Getting the context and capabilities from the main renderer. pgPrimary = (PGraphicsOpenGL)parent.g; - pgl.initOffscreenSurface(pgPrimary.pgl); - pgl.updateOffscreen(pgPrimary.pgl); + pgl.initialized = true; +// pgl.initOffscreenSurface(pgPrimary.pgl); +// pgl.updateOffscreen(pgPrimary.pgl); + loadTextureImpl(Texture.BILINEAR, false); - Texture.Parameters params = new Texture.Parameters(ARGB, Texture.BILINEAR, false); - ptexture = new Texture(parent, width, height, params); - ptexture.invertedY(true); - ptexture.colorBufferOf(this); // In case of reinitialization (for example, when the smooth level // is changed), we make sure that all the OpenGL resources associated @@ -6092,6 +5952,7 @@ public class PGraphicsOpenGL extends PGraphics { offscreenFramebufferMultisample.copy(offscreenFramebuffer); } + /* if (!pgl.initialized || !pgPrimary.pgl.initialized || parent.frameCount == 0) { // If the primary surface is re-initialized, this offscreen @@ -6106,6 +5967,7 @@ public class PGraphicsOpenGL extends PGraphics { saveSurfaceToPixels(); restoreSurface = true; } +*/ if (!clearColorBuffer0) { // Draw the back texture into the front texture, which will be used as @@ -6126,9 +5988,7 @@ public class PGraphicsOpenGL extends PGraphics { popFramebuffer(); texture.updateTexels(); // Mark all texels in screen texture as modified. - int temp = texture.glName; - texture.glName = ptexture.glName; - ptexture.glName = temp; + swapTextures(); pgPrimary.restoreGL(); }