diff options
author | Sven Gothel <sgothel@jausoft.com> | 2014-04-09 09:09:51 +0200 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2014-04-09 09:09:51 +0200 |
commit | fe47c613e3e07681a5366d6ec3f071fdc4ade65d (patch) | |
tree | fd980c33b0fde468918227d31174320b8ae6b163 /src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java | |
parent | ff4e2b1996d2cfab1eb154020106004fb71471fd (diff) |
Bug 801: Region Dirty Update; TextureSequence GLMediaPlayer Fix; Blending Fix ;
- Region Dirty Update
- Split dirty -> ShapeDirty + StateDirty,
where StateDirty forces re-rendering content
w/o geometry update as req. for 2-pass mode.
- Fix TextureSequence (GLMediaPlayer) usage in RegionRenderer / GLRegion*
- handle GL_TEXTURE_EXTERNAL_OES incl. Android ES3 bug
- inject TextureSequence's shader stubs
- shader: Use abstract lookup 'texture2D' -> 'gcuTexture2D'
- flip scaled colorTexBBox if TextureSequence 'tex.getMustFlipVertically()'
- TODO: Handle multiple TextureSequence shader programs!
- Fix Blending: GLRegion* / RegionRenderer / RenderState
- Disable/Enable depth-writing w/ blending
- Region impl. sets proper glBlendFunc*(..),
i.e. 2-pass:
- render2FBO: glClearColor(0f, 0f, 0f, 0f)
glBlendFuncSeparate(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA)
- renderFBO: glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA)
- User code shall not set glClearColor(..) for 2-pass anymore
- Graph-UI Demo
- UIShape:
- Add MouseGestureListener, combining MouseListener + GestureListener
- EventDetails -> PointerEventInfo
- PointerEventInfo contains objPos (ray-intersection) and glWin-pos
- Toggle:
- Separate color (on/off) if enabled
- Toggle on click if enabled
- SceneUIController
- Use PinchToZoomGesture and propagete same gesture to UIShape
- Use AABBox.getRayIntersection(..) using 'real' shape coordinates
for 1st picking.
- Use shape PMV for secondary picking (drag, zoom 2-pointer, etc),
see windowToShapeCoords(..)
- Sort shapes according to z-value (render: ascending; picking: descending)
- Only 'drag' if pointerId matches 1st pressed pointer
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index c623eddb7..cea292210 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -49,6 +49,7 @@ import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public class VBORegion2PVBAAES2 extends GLRegion { @@ -131,7 +132,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { */ public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) { final RenderState rs = renderer.getRenderState(); - final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount, colorTexSeq); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); final boolean updateLocLocal; if( pass1 ) { @@ -295,11 +296,22 @@ public class VBORegion2PVBAAES2 extends GLRegion { gca_ColorsAttr.seal(gl, true); gca_ColorsAttr.enableBuffer(gl, false); } - if( null != gcu_ColorTexUnit ) { - colorTexBBox[0] = box.getMinX(); - colorTexBBox[1] = box.getMinY(); - colorTexBBox[2] = box.getMaxX(); - colorTexBBox[3] = box.getMaxY(); + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); + final Texture tex = frame.getTexture(); + final TextureCoords tc = tex.getImageTexCoords(); + final float tcSx = 1f / ( tc.right() - tc.left() ); + colorTexBBox[0] = box.getMinX() * tcSx; + colorTexBBox[2] = box.getMaxX() * tcSx; + if( tex.getMustFlipVertically() ) { + final float tcSy = 1f / ( tc.bottom() - tc.top() ); + colorTexBBox[1] = box.getMaxY() * tcSy; + colorTexBBox[3] = box.getMinY() * tcSy; + } else { + final float tcSy = 1f / ( tc.top() - tc.bottom() ); + colorTexBBox[1] = box.getMinY() * tcSy; + colorTexBBox[3] = box.getMaxY() * tcSy; + } } gca_FboVerticesAttr.seal(gl, false); { @@ -419,7 +431,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { System.err.printf("XXX.Scale %d * [%f x %f]: %d x %d%n", sampleCount[0], winWidth, winHeight, targetFboWidth, targetFboHeight); } - if( hasDelta || fboDirty || null == fbo ) { + if( hasDelta || fboDirty || isShapeDirty() || null == fbo ) { final int maxLength = Math.max(targetFboWidth, targetFboHeight); if( maxLength > maxTexSize[0] ) { if( targetFboWidth > targetFboHeight ) { @@ -503,6 +515,9 @@ public class VBORegion2PVBAAES2 extends GLRegion { FloatUtil.makeOrthof(pmvMatrix02, 0, true, minX, maxX, minY, maxY, -1, 1); useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, newFboWidth, newFboHeight, vpWidth, vpHeight, sampleCount[0]); + } else if( isStateDirty() ) { + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); + renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, fboWidth, fboHeight, vpWidth, vpHeight, sampleCount[0]); } useShaderProgram(gl, renderer, getRenderModes(), false, getQuality(), sampleCount[0]); renderFBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount[0]); @@ -513,6 +528,11 @@ public class VBORegion2PVBAAES2 extends GLRegion { final int vpWidth, final int vpHeight, final int sampleCount) { gl.glViewport(0, 0, vpWidth, vpHeight); + if( rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { + // RGB is already multiplied w/ alpha via renderRegion2FBO(..) + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + } + gl.glUniform(gcu_FboTexSize); gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); @@ -539,6 +559,8 @@ public class VBORegion2PVBAAES2 extends GLRegion { throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight); } + final boolean blendingEnabled = rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED); + if(null == fbo) { fboWidth = newFboWidth; fboHeight = newFboHeight; @@ -553,7 +575,10 @@ public class VBORegion2PVBAAES2 extends GLRegion { // FIXME: FXAA requires bilinear filtering! // texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); - fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + if( !blendingEnabled ) { + // no depth-buffer w/ blending + fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + } if( DEBUG_FBO_1 ) { System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString()); } @@ -576,7 +601,17 @@ public class VBORegion2PVBAAES2 extends GLRegion { //render texture gl.glViewport(0, 0, fboWidth, fboHeight); - gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); + if( blendingEnabled ) { + gl.glClearColor(0f, 0f, 0f, 0.0f); + gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT); // no depth-buffer w/ blending + // For already pre-multiplied alpha values, use: + // gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + + // Multiply RGB w/ Alpha, preserve alpha for renderFBO(..) + gl.glBlendFuncSeparate(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + } else { + gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); + } renderRegion(gl); @@ -593,7 +628,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { gca_ColorsAttr.enableBuffer(gl, true); } indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - if( null != gcu_ColorTexUnit ) { + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); final Texture tex = frame.getTexture(); @@ -604,7 +639,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { gcu_ColorTexUnit.setData(colorTexUnit); gl.glUniform(gcu_ColorTexUnit); } - gl.glUniform(gcu_ColorTexBBox); // FIXME: Only if changed! + gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); tex.disable(gl); // nop on core } else { |