From de4767e90f752cb9804403fa4ac775394bb45324 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 Aug 2023 18:57:41 +0200 Subject: Graph Add {GLRegion, GraphShape}.setTextureUnit(int): Allowing to set texture unit after ctor --- .../opengl/demos/graph/ui/UISceneDemoU01a.java | 26 +++++++++++++++------- .../classes/com/jogamp/graph/ui/GraphShape.java | 14 ++++++++++-- .../com/jogamp/graph/curve/opengl/GLRegion.java | 3 +++ .../graph/curve/opengl/VBORegion2PMSAAES2.java | 5 +++++ .../graph/curve/opengl/VBORegion2PVBAAES2.java | 5 +++++ .../jogamp/graph/curve/opengl/VBORegionSPES2.java | 5 +++++ 6 files changed, 48 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java index a2002ad4a..4eb5f90e3 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java @@ -37,7 +37,7 @@ import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.font.FontSet; import com.jogamp.graph.geom.plane.AffineTransform; -import com.jogamp.graph.ui.Shape; +import com.jogamp.graph.ui.GraphShape; import com.jogamp.graph.ui.shapes.CrossHair; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; @@ -48,6 +48,7 @@ import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.demos.graph.ui.util.GraphUIDemoArgs; import com.jogamp.opengl.demos.util.MiscUtils; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; @@ -95,6 +96,7 @@ public class UISceneDemoU01a { static Font font; static boolean projOrtho = true; static boolean projOrthoWin = false; + static int pass2TexUnit = GLRegion.DEFAULT_TWO_PASS_TEXTURE_UNIT; static final Vec2i winOrigin = new Vec2i(options.surface_width/2, options.surface_height/2); static final float normWidgetSize = 1/4f; @@ -110,6 +112,9 @@ public class UISceneDemoU01a { } else if(args[idx[0]].equals("-projWin")) { projOrtho = true; projOrthoWin = true; + } else if(args[idx[0]].equals("-texUnit")) { + idx[0]++; + pass2TexUnit = MiscUtils.atoi(args[idx[0]], pass2TexUnit); } else if(args[idx[0]].equals("-x")) { idx[0]++; winOrigin.setX( MiscUtils.atoi(args[idx[0]], winOrigin.x()) ); @@ -119,8 +124,11 @@ public class UISceneDemoU01a { } } } + System.err.println(JoglVersion.getInstance().toString()); + System.err.println(options); System.err.println("Ortho Projection "+projOrtho+", Ortho-Win "+projOrthoWin); + System.err.println("pass2TexUnit "+pass2TexUnit); final GLProfile reqGLP = GLProfile.get(options.glProfileName); System.err.println("GLProfile: "+reqGLP); @@ -178,7 +186,7 @@ public class UISceneDemoU01a { /** The Graph region for text */ private GLRegion textRegion; /** The GraphUI shape */ - private Shape shape; + private GraphShape shape; public MyRenderer() { if( projOrtho ) { @@ -200,6 +208,7 @@ public class UISceneDemoU01a { final GL2ES2 gl = drawable.getGL().getGL2ES2(); shape = new CrossHair(options.renderModes, normWidgetSize, normWidgetSize, normWidgetSize/100f); // normalized: 1 is 100% surface size (width and/or height) + shape.setTextureUnit(pass2TexUnit); shape.setColor(0, 0, 1, 1); System.err.println("Init: Shape bounds "+shape.getBounds(drawable.getGLProfile())); System.err.println("Init: Shape "+shape); @@ -207,7 +216,7 @@ public class UISceneDemoU01a { renderer.init(gl); if( null == textRegion ) { - textRegion = GLRegion.create(gl.getGLProfile(), options.renderModes, null, 0, 0); + textRegion = GLRegion.create(gl.getGLProfile(), options.renderModes, null, pass2TexUnit, 0, 0); } } @@ -230,6 +239,7 @@ public class UISceneDemoU01a { worldDim.setX( viewport.width() ); worldDim.setY( worldDim.x() / ratio ); // adjust aspect ratio pmv.glOrthof(0, worldDim.x(), 0, worldDim.y(), zNear, zFar); + // similar: renderer.reshapeOrtho(viewport.width(), viewport.height(), zNear, zFar); } else if( projOrtho ) { worldDim.setY( worldDim.x() / ratio ); // adjust aspect ratio pmv.glOrthof(-worldDim.x()/2f, worldDim.x()/2f, -worldDim.y()/2f, worldDim.y()/2f, zNear, zFar); @@ -291,6 +301,11 @@ public class UISceneDemoU01a { } renderer.enable(gl, true); + { + pmv.glPushMatrix(); + drawText(gl, pmv, "Hello JogAmp Users!"); + pmv.glPopMatrix(); + } { pmv.glPushMatrix(); shape.setTransform(pmv); @@ -308,11 +323,6 @@ public class UISceneDemoU01a { } pmv.glPopMatrix(); } - { - pmv.glPushMatrix(); - drawText(gl, pmv, "Hello JogAmp Users!"); - pmv.glPopMatrix(); - } renderer.enable(gl, false); onceAtDisplay = false; } diff --git a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java index 7dccd41a0..f0329ad3c 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java @@ -53,6 +53,7 @@ import com.jogamp.opengl.util.texture.TextureSequence; */ public abstract class GraphShape extends Shape { protected final int renderModes; + protected int pass2TexUnit = GLRegion.DEFAULT_TWO_PASS_TEXTURE_UNIT; protected GLRegion region = null; protected float oshapeSharpness = OutlineShape.DEFAULT_SHARPNESS; private int regionQuality = Region.MAX_QUALITY; @@ -83,6 +84,15 @@ public abstract class GraphShape extends Shape { } return this; } + + /** Set the 2nd pass texture unit. */ + public void setTextureUnit(final int pass2TexUnit) { + this.pass2TexUnit = pass2TexUnit; + if( null != region ) { + region.setTextureUnit(pass2TexUnit); + } + } + /** * Return the shape's Graph {@link Region}'s quality parameter. * @see #setQuality(int) @@ -178,10 +188,10 @@ public abstract class GraphShape extends Shape { indexCount += 24; } if( null == region ) { - region = GLRegion.create(glp, renderModes, colorTexSeq, vertexCount, indexCount); + region = GLRegion.create(glp, renderModes, colorTexSeq, pass2TexUnit, vertexCount, indexCount); } else if( null == gl ) { dirtyRegions.add(region); - region = GLRegion.create(glp, renderModes, colorTexSeq, vertexCount, indexCount); + region = GLRegion.create(glp, renderModes, colorTexSeq, pass2TexUnit, vertexCount, indexCount); } else { region.clear(gl); region.setBufferCapacity(vertexCount, indexCount); diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index 2864f48bb..c282a4b92 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -356,6 +356,9 @@ public abstract class GLRegion extends Region { } } + /** Set the 2nd pass texture unit. */ + public abstract void setTextureUnit(final int pass2TexUnit); + @Override protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) { // NIO array[3] is much slows than group/single diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index 62451ec50..e5221eefb 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -126,6 +126,11 @@ public final class VBORegion2PMSAAES2 extends GLRegion { false, 4, GL.GL_STATIC_DRAW); } + @Override + public void setTextureUnit(final int pass2TexUnit) { + gcu_FboTexUnit.setData(pass2TexUnit); + } + @Override protected final void clearImpl(final GL2ES2 gl) { fboDirty = true; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index 3acbd6c73..f7ab0a2d6 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -219,6 +219,11 @@ public final class VBORegion2PVBAAES2 extends GLRegion { false, 4, GL.GL_STATIC_DRAW); } + @Override + public void setTextureUnit(final int pass2TexUnit) { + gcu_FboTexUnit.setData(pass2TexUnit); + } + @Override protected final void clearImpl(final GL2ES2 gl) { fboDirty = true; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index a55bd626a..9d9e2bbea 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -74,6 +74,11 @@ public final class VBORegionSPES2 extends GLRegion { } } + @Override + public void setTextureUnit(final int pass2TexUnit) { + // nop + } + @Override protected final void clearImpl(final GL2ES2 gl) { } -- cgit v1.2.3