From f8584748e33aab56780eca5cf7009a5a0d11991d Mon Sep 17 00:00:00 2001
From: Sven Gothel
* Implementation also clears {@link RegionRenderer#getRenderState() RenderState}'s {@link RenderState#BITHINT_BLENDING_ENABLED blending bit-hint}. *
- * @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. + *
+ * The optional {@link GLCallback}s enableCallback
and disableCallback
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ *
+ * The optional {@link GLCallback}s enableCallback
and disableCallback
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ *
null
will be issued at
+ * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * @param disableCallback optional {@link GLCallback}, if not null
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.
*
* The optional {@link GLCallback}s enableCallback
and disableCallback
* maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.
* For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
* can be utilized to enable and disable {@link GL#GL_BLEND}.
*
null
will be issued at
* {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
* @param disableCallback optional {@link GLCallback}, if not null
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.
+ *
+ * The optional {@link GLCallback}s enableCallback
and disableCallback
+ * maybe used to issue certain tasks at {@link #enable(GL2ES2, boolean)}.
+ * For example, instances {@link #defaultBlendEnable} and {@link #defaultBlendDisable}
+ * can be utilized to enable and disable {@link GL#GL_BLEND}.
+ *
null
will be issued at
+ * {@link #init(GL2ES2) init(gl)} and {@link #enable(GL2ES2, boolean) enable(gl, true)}.
+ * @param disableCallback optional {@link GLCallback}, if not null
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}.
+ * + * {@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. + *
*- * 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. *
- * @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 } -- cgit v1.2.3