summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-15 03:37:44 +0100
committerSven Gothel <[email protected]>2023-03-15 03:37:44 +0100
commitf8584748e33aab56780eca5cf7009a5a0d11991d (patch)
tree607524acb482e80dad20a3a5b00e0a2e76179d34 /src/jogl/classes
parentb3fe96b2916eb0359412aa8e57a9b1a9577f247d (diff)
Graph: Make RenderState a composition of RegionRenderer, which also creates and destroys it. Dropping this also from user (complexity).
Diffstat (limited to 'src/jogl/classes')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java126
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java25
3 files changed, 120 insertions, 33 deletions
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 c8e9a0113..2ffa68be6 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -243,7 +243,7 @@ public abstract class GLRegion extends Region {
* The <i>alpha</i> component shall be set to zero.
* Note: If {@link GL#GL_BLEND blending} is enabled, the
* {@link RegionRenderer} might need to be
- * {@link RegionRenderer#create(RenderState, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) created}
+ * {@link RegionRenderer#create(Vertex.Factory<? extends Vertex>, RenderState, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) created}
* with the appropriate {@link RegionRenderer.GLCallback callbacks}.
* </p>
* @param matrix current {@link PMVMatrix}.
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
index 54deb9e4b..43a322a2d 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -47,6 +47,8 @@ import com.jogamp.opengl.util.PMVMatrix;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.geom.SVertex;
+import com.jogamp.graph.geom.Vertex;
/**
* OpenGL {@link Region} renderer
@@ -60,13 +62,13 @@ import com.jogamp.graph.curve.Region;
* At its {@link #destroy(GL2ES2) destruction}, all {@link ShaderProgram}s and its {@link RenderState}
* will be destroyed and released.
*/
-public class RegionRenderer {
+public final class RegionRenderer {
protected static final boolean DEBUG = Region.DEBUG;
protected static final boolean DEBUG_INSTANCE = Region.DEBUG_INSTANCE;
/**
* May be passed to
- * {@link RegionRenderer#create(RenderState, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) RegionRenderer ctor},
+ * {@link RegionRenderer#create(Vertex.Factory<? extends Vertex>, RenderState, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) RegionRenderer ctor},
* e.g.
* <ul>
* <li>{@link RegionRenderer#defaultBlendEnable}</li>
@@ -91,7 +93,7 @@ public class RegionRenderer {
* to set the proper {@link GL#glBlendFuncSeparate(int, int, int, int) blend-function}
* and the clear-color to <i>transparent-black</i> in case of {@link Region#isTwoPass(int) multipass} FBO rendering.
* </p>
- * @see #create(RenderState, GLCallback, GLCallback)
+ * @see #create(Vertex.Factory<? extends Vertex>, RenderState, GLCallback, GLCallback)
* @see #enable(GL2ES2, boolean)
*/
public static final GLCallback defaultBlendEnable = new GLCallback() {
@@ -115,7 +117,7 @@ public class RegionRenderer {
* <p>
* Implementation also clears {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}.
* </p>
- * @see #create(RenderState, GLCallback, GLCallback)
+ * @see #create(Vertex.Factory<? extends Vertex>, RenderState, GLCallback, GLCallback)
* @see #enable(GL2ES2, boolean)
*/
public static final GLCallback defaultBlendDisable = new GLCallback() {
@@ -131,15 +133,55 @@ public class RegionRenderer {
}
};
+ public static RegionRenderer create(final Vertex.Factory<? extends Vertex> pointFactory, final RenderState rs,
+ final GLCallback enableCallback, final GLCallback disableCallback) {
+ return null;
+ }
+
+ /**
+ * Create a hardware accelerated RegionRenderer including its {@link RenderState} composition.
+ * <p>
+ * The optional {@link GLCallback}s <code>enableCallback</code> and <code>disableCallback</code>
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.<br/>
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ * </p>
+ * @return an instance of Region Renderer
+ * @see #enable(GL2ES2, boolean)
+ */
+ public static RegionRenderer create() {
+ return new RegionRenderer(null, null, null);
+ }
+
+ /**
+ * Create a hardware accelerated RegionRenderer including its {@link RenderState} composition.
+ * <p>
+ * The optional {@link GLCallback}s <code>enableCallback</code> and <code>disableCallback</code>
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.<br/>
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ * </p>
+ * @param enableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * @param disableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #enable(GL2ES2, boolean) enable(gl, false)}.
+ * @return an instance of Region Renderer
+ * @see #enable(GL2ES2, boolean)
+ */
+ public static RegionRenderer create(final GLCallback enableCallback, final GLCallback disableCallback) {
+ return new RegionRenderer(null, enableCallback, disableCallback);
+ }
+
/**
- * Create a Hardware accelerated Region Renderer.
+ * Create a hardware accelerated RegionRenderer including its {@link RenderState} composition.
* <p>
* The optional {@link GLCallback}s <code>enableCallback</code> and <code>disableCallback</code>
* maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.<br/>
* For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
* can be utilized to enable and disable {@link GL#GL_BLEND}.
* </p>
- * @param rs the used {@link RenderState}
+ * @param pointFactory optional {@link Vertex.Factory} to be used for the {@link RenderState} composition,
+ * If null, SVertex.factory() will be used.
* @param enableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
* {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
* @param disableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
@@ -147,9 +189,32 @@ public class RegionRenderer {
* @return an instance of Region Renderer
* @see #enable(GL2ES2, boolean)
*/
- public static RegionRenderer create(final RenderState rs, final GLCallback enableCallback,
- final GLCallback disableCallback) {
- return new RegionRenderer(rs, enableCallback, disableCallback);
+ public static RegionRenderer create(final Vertex.Factory<? extends Vertex> pointFactory,
+ final GLCallback enableCallback, final GLCallback disableCallback) {
+ return new RegionRenderer(pointFactory, enableCallback, disableCallback);
+ }
+
+ /**
+ * Create a hardware accelerated RegionRenderer including its {@link RenderState} composition.
+ * <p>
+ * The optional {@link GLCallback}s <code>enableCallback</code> and <code>disableCallback</code>
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.<br/>
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ * </p>
+ * @param pointFactory optional {@link Vertex.Factory} to be used for the {@link RenderState} composition.
+ * If null, SVertex.factory() will be used.
+ * @param sharedPMVMatrix optional shared {@link PMVMatrix} to be used for the {@link RenderState} composition.
+ * @param enableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * @param disableCallback optional {@link GLCallback}, if not <code>null</code> will be issued at
+ * {@link #enable(GL2ES2, boolean) enable(gl, false)}.
+ * @return an instance of Region Renderer
+ * @see #enable(GL2ES2, boolean)
+ */
+ public static RegionRenderer create(final Vertex.Factory<? extends Vertex> pointFactory, final PMVMatrix sharedPMVMatrix,
+ final GLCallback enableCallback, final GLCallback disableCallback) {
+ return new RegionRenderer(pointFactory, sharedPMVMatrix, enableCallback, disableCallback);
}
private final RenderState rs;
@@ -177,15 +242,23 @@ public class RegionRenderer {
/** Return height of current viewport */
public final int getHeight() { return viewport[3]; }
+ /** Borrow the current {@link PMVMatrix}. */
public final PMVMatrix getMatrix() { return rs.getMatrix(); }
//////////////////////////////////////
- /**
- * @param rs the used {@link RenderState}
- */
- protected RegionRenderer(final RenderState rs, final GLCallback enableCallback, final GLCallback disableCallback) {
- this.rs = rs;
+ protected RegionRenderer(final Vertex.Factory<? extends Vertex> pointFactory,
+ final GLCallback enableCallback, final GLCallback disableCallback)
+ {
+ this.rs = new RenderState(pointFactory, null);
+ this.enableCallback = enableCallback;
+ this.disableCallback = disableCallback;
+ }
+
+ protected RegionRenderer(final Vertex.Factory<? extends Vertex> pointFactory, final PMVMatrix sharedPMVMatrix,
+ final GLCallback enableCallback, final GLCallback disableCallback)
+ {
+ this.rs = new RenderState(pointFactory, sharedPMVMatrix);
this.enableCallback = enableCallback;
this.disableCallback = disableCallback;
}
@@ -245,16 +318,25 @@ public class RegionRenderer {
initialized = false;
}
+ /** Return the {@link RenderState} composition. */
public final RenderState getRenderState() { return rs; }
/**
* Enabling or disabling the {@link #getRenderState() RenderState}'s
- * {@link RenderState#getShaderProgram() shader program}.
+ * current {@link RenderState#getShaderProgram() shader program}.
+ * <p>
+ * {@link #useShaderProgram(GL2ES2, int, boolean, int, int, TextureSequence)}
+ * generates, selects and caches the desired Curve-Graph {@link ShaderProgram}
+ * and {@link RenderState#setShaderProgram(GL2ES2, ShaderProgram) sets it current} in the {@link RenderState} composition.
+ * </p>
* <p>
- * In case enable and disable {@link GLCallback}s are setup via {@link #create(RenderState, GLCallback, GLCallback)},
+ * In case enable and disable {@link GLCallback}s are setup via {@link #create(Vertex.Factory<? extends Vertex>, RenderState, GLCallback, GLCallback)},
* they will be called before toggling the shader program.
* </p>
- * @see #create(RenderState, GLCallback, GLCallback)
+ * @see #create(Vertex.Factory<? extends Vertex>, RenderState, GLCallback, GLCallback)
+ * @see #useShaderProgram(GL2ES2, int, boolean, int, int, TextureSequence)
+ * @see RenderState#setShaderProgram(GL2ES2, ShaderProgram)
+ * @see RenderState#getShaderProgram()
*/
public final void enable(final GL2ES2 gl, final boolean enable) {
if( enable ) {
@@ -420,6 +502,11 @@ public class RegionRenderer {
private static final int TWO_PASS_BIT = 1 << 31;
/**
+ * Generate, selects and caches the desired Curve-Graph {@link ShaderProgram} according to the given parameters.
+ *
+ * The newly generated or cached {@link ShaderProgram} is {@link RenderState#setShaderProgram(GL2ES2, ShaderProgram) set current} in the {@link RenderState} composition
+ * and can be retrieved via {@link RenderState#getShaderProgram()}.
+ *
* @param gl
* @param renderModes
* @param pass1
@@ -428,6 +515,9 @@ public class RegionRenderer {
* @param colorTexSeq
* @return true if a new shader program is being used and hence external uniform-data and -location,
* as well as the attribute-location must be updated, otherwise false.
+ * @see #enable(GL2ES2, boolean)
+ * @see RenderState#setShaderProgram(GL2ES2, ShaderProgram)
+ * @see RenderState#getShaderProgram()
*/
public final boolean useShaderProgram(final GL2ES2 gl, final int renderModes,
final boolean pass1, final int quality, final int sampleCount, final TextureSequence colorTexSeq) {
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
index 3f7e3f81d..09486874d 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 JogAmp Community. All rights reserved.
+ * Copyright 2011-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -37,8 +37,8 @@ import com.jogamp.opengl.GLUniformData;
import jogamp.common.os.PlatformPropsImpl;
import jogamp.graph.curve.opengl.shader.UniformNames;
-import com.jogamp.common.os.Platform;
import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
@@ -82,14 +82,6 @@ public class RenderState {
*/
public static final int BITHINT_GLOBAL_DEPTH_TEST_ENABLED = 1 << 1 ;
- public static RenderState createRenderState(final Vertex.Factory<? extends Vertex> pointFactory) {
- return new RenderState(pointFactory, null);
- }
-
- public static RenderState createRenderState(final Vertex.Factory<? extends Vertex> pointFactory, final PMVMatrix pmvMatrix) {
- return new RenderState(pointFactory, pmvMatrix);
- }
-
public static final RenderState getRenderState(final GL2ES2 gl) {
return (RenderState) gl.getContext().getAttachedObject(thisKey);
}
@@ -186,11 +178,16 @@ public class RenderState {
}
}
- protected RenderState(final Vertex.Factory<? extends Vertex> vertexFactory, final PMVMatrix pmvMatrix) {
+ /**
+ * Create a RenderState, a composition of RegionRenderer
+ * @param vertexFactory used Vertex.Factory, if null SVertex.factory() will be used.
+ * @param sharedPMVMatrix optional shared PMVMatrix, if null using a local instance
+ */
+ /* pp */ RenderState(final Vertex.Factory<? extends Vertex> vertexFactory, final PMVMatrix sharedPMVMatrix) {
this.id = getNextID();
this.sp = null;
- this.vertexFactory = vertexFactory;
- this.pmvMatrix = null != pmvMatrix ? pmvMatrix : new PMVMatrix();
+ this.vertexFactory = null != vertexFactory ? vertexFactory : SVertex.factory();
+ this.pmvMatrix = null != sharedPMVMatrix ? sharedPMVMatrix : new PMVMatrix();
this.weight = new float[1];
this.weightBuffer = FloatBuffer.wrap(weight);
this.colorStatic = new float[4];
@@ -337,7 +334,7 @@ public class RenderState {
/**
* Only nullifies {@link ShaderProgram} reference owned by {@link RegionRenderer}.
*/
- public void destroy(final GL2ES2 gl) {
+ /* pp */ void destroy() {
sp = null; // owned by RegionRenderer
}