From bb6ee81bc5514663bb7b22224fcdd5ba34a51ac6 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Wed, 2 Aug 2023 15:42:38 +0200
Subject: Graph TextRegionUtil.drawString3D(..): Redefine 'rgbaColor'
 semantics: Either fill color-channel with value if used and set static-color
 to white - or just set static color channel with value.

Have the given rgbaColor to definitely setting the text color regardless whether a color channel is used or not.
Note: Using a color-channel is more expensive (color value per vertex) and should only be required if mixing
colors within one region!

Also removes potential side-effects if color-channel is used but user forgets to set the static value properly.
---
 .../jogamp/graph/curve/opengl/TextRegionUtil.java  | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

(limited to 'src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java')

diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
index d751f80f6..975e16e4c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -199,7 +199,9 @@ public class TextRegionUtil {
      * @param renderer TODO
      * @param font {@link Font} to be used
      * @param str text to be rendered
-     * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored.
+     * @param rgbaColor used to fill the {@link Region#hasColorChannel() region's color-channel} if used
+     *                  and set {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} to white.
+     *                  Otherwise used to set the {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} only.
      * @param sampleCount desired multisampling sample count for msaa-rendering.
      *        The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
      * @return the bounding box of the given string from the produced and rendered GLRegion
@@ -221,6 +223,11 @@ public class TextRegionUtil {
             res = new AABBox();
             res.copy(region.getBounds());
         }
+        if( !region.hasColorChannel() ) {
+            renderer.setColorStatic(rgbaColor);
+        } else {
+            renderer.setColorStatic(1, 1, 1, 1);
+        }
         region.draw(gl, renderer, sampleCount);
         return res;
     }
@@ -258,7 +265,9 @@ public class TextRegionUtil {
      * @param renderModes TODO
      * @param font {@link Font} to be used
      * @param str text to be rendered
-     * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored.
+     * @param rgbaColor used to fill the {@link Region#hasColorChannel() region's color-channel} if used
+     *                  and set {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} to white.
+     *                  Otherwise used to set the {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} only.
      * @param sampleCount desired multisampling sample count for msaa-rendering.
      *        The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
      * @param tmp1 temp {@link AffineTransform} to be reused
@@ -274,6 +283,11 @@ public class TextRegionUtil {
         }
         final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, font, str);
         final AABBox res = addStringToRegion(false /* preGrowRegion */, region, font, null, str, rgbaColor, tmp1, tmp2);
+        if( !region.hasColorChannel() ) {
+            renderer.setColorStatic(rgbaColor);
+        } else {
+            renderer.setColorStatic(1, 1, 1, 1);
+        }
         region.draw(gl, renderer, sampleCount);
         region.destroy(gl);
         return res;
@@ -309,7 +323,9 @@ public class TextRegionUtil {
      * @param renderer
      * @param font {@link Font} to be used
      * @param str text to be rendered
-     * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored.
+     * @param rgbaColor used to fill the {@link Region#hasColorChannel() region's color-channel} if used
+     *                  and set {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} to white.
+     *                  Otherwise used to set the {@link RegionRenderer#setColorStatic(Vec4f) renderer's static-color} only.
      * @param sampleCount desired multisampling sample count for msaa-rendering.
      *        The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched.
      * @param tmp1 temp {@link AffineTransform} to be reused
@@ -324,6 +340,11 @@ public class TextRegionUtil {
             throw new GLException("TextRendererImpl01: not initialized!");
         }
         final AABBox res = addStringToRegion(true /* preGrowRegion */, region, font, null, str, rgbaColor, tmp1, tmp2);
+        if( !region.hasColorChannel() ) {
+            renderer.setColorStatic(rgbaColor);
+        } else {
+            renderer.setColorStatic(1, 1, 1, 1);
+        }
         region.draw(gl, renderer, sampleCount);
         return res;
     }
-- 
cgit v1.2.3