JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GLRegion.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.graph.curve.opengl;
29
30import com.jogamp.opengl.GL;
31import com.jogamp.opengl.GL2ES2;
32import com.jogamp.opengl.GLArrayData;
33import com.jogamp.opengl.util.GLArrayDataClient;
34import com.jogamp.opengl.util.GLArrayDataEditable;
35import com.jogamp.opengl.util.GLArrayDataServer;
36import com.jogamp.opengl.util.GLArrayDataWrapper;
37import com.jogamp.opengl.GLProfile;
38
39import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
40import jogamp.graph.curve.opengl.VBORegion2PVBAAES2;
41import jogamp.graph.curve.opengl.VBORegionSPES2;
42import jogamp.graph.curve.opengl.shader.AttributeNames;
43import jogamp.opengl.Debug;
44
45import com.jogamp.opengl.util.glsl.ShaderProgram;
46import com.jogamp.opengl.util.texture.TextureSequence;
47import com.jogamp.graph.curve.Region;
48import com.jogamp.graph.font.Font;
49import com.jogamp.math.Vec3f;
50import com.jogamp.math.Vec4f;
51
52import java.io.PrintStream;
53import java.nio.FloatBuffer;
54import java.nio.IntBuffer;
55import java.nio.ShortBuffer;
56
57import com.jogamp.graph.curve.OutlineShape;
58
59/** A GLRegion is the OGL binding of one or more OutlineShapes
60 * Defined by its vertices and generated triangles. The Region
61 * defines the final shape of the OutlineShape(s), which shall produced a shaded
62 * region on the screen.
63 *
64 * Implementations of the GLRegion shall take care of the OGL
65 * binding of the depending on its context, profile.
66 *
67 * @see Region
68 * @see OutlineShape
69 */
70public abstract class GLRegion extends Region {
71
72 /**
73 * Heuristics with TestTextRendererNEWT00 text_1 + text_2 = 1334 chars
74 * - FreeSans ~ vertices 64/char, indices 33/char
75 * - Ubuntu Light ~ vertices 100/char, indices 50/char
76 * - FreeSerif ~ vertices 115/char, indices 61/char
77 *
78 * However, proper initial size is pre-calculated via ..
79 * - {@link GLRegion#create(GLProfile, int, TextureSequence, Font, CharSequence)}
80 * - {@Link Region#countOutlineShape(OutlineShape, int[])}
81 * - {@link TextRegionUtil#countStringRegion(Font, CharSequence, int[])}
82 */
83
84 /**
85 * Default initial vertices count {@value}, assuming small sized shapes.
86 */
87 public static final int defaultVerticesCount = 64;
88
89 /**
90 * Default initial indices count {@value}, assuming small sized shapes.
91 */
92 public static final int defaultIndicesCount = 64;
93
94 // private static final float growthFactor = 1.2f; // avg +5% size but 15% more overhead (34% total)
95 protected static final float growthFactor = GLArrayDataClient.DEFAULT_GROWTH_FACTOR; // avg +20% size, but 15% less CPU overhead compared to 1.2 (19% total)
96
97 private static final boolean DEBUG_BUFFER = Debug.debug("graph.curve.Buffer");
98
99 /**
100 * Create a GLRegion using the passed render mode
101 *
102 * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
103 * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
104 * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
105 * @param pass2TexUnit texture unit for 2nd pass rendering ({@link Region#VBAA_RENDERING_BIT}), default is {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT}.
106 * @param initialVerticesCount initial number of vertices in the render-buffer
107 * @param initialIndicesCount initial number of indices in the render-buffer
108 */
109 public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit,
110 final int initialVerticesCount, final int initialIndicesCount)
111 {
112 if( null != colorTexSeq ) {
113 renderModes |= Region.COLORTEXTURE_RENDERING_BIT;
114 } else if( Region.hasColorTexture(renderModes) ) {
115 throw new IllegalArgumentException("COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
116 }
117 if( isVBAA(renderModes) ) {
118 return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, pass2TexUnit, initialVerticesCount, initialIndicesCount);
119 } else if( isMSAA(renderModes) ) {
120 return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, pass2TexUnit, initialVerticesCount, initialIndicesCount);
121 } else {
122 return new VBORegionSPES2(glp, renderModes, colorTexSeq, initialVerticesCount, initialIndicesCount);
123 }
124 }
125
126 /**
127 * Create a GLRegion using the passed render mode
128 *
129 * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
130 * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
131 * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
132 * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
133 * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
134 * @param initialVerticesCount initial number of vertices in the render-buffer
135 * @param initialIndicesCount initial number of indices in the render-buffer
136 */
137 public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq,
138 final int initialVerticesCount, final int initialIndicesCount)
139 {
140 return create(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, initialVerticesCount, initialIndicesCount);
141 }
142
143 /**
144 * Create a GLRegion using the passed render mode and default initial buffer sizes {@link #defaultVerticesCount} and {@link #defaultIndicesCount}.
145 *
146 * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
147 * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
148 * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
149 * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
150 * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
151 */
152 public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
154 }
155
156 /**
157 * Create a GLRegion using the passed render mode and pre-calculating its buffer sizes
158 * using {@link Region#countOutlineShape(OutlineShape, int[])}.
159 *
160 * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
161 * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
162 * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
163 * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
164 * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
165 * @param shape the {@link OutlineShape} used to determine {@link GLRegion}'s buffer sizes via {@link Region#countOutlineShape(OutlineShape, int[])}
166 */
167 public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final OutlineShape shape) {
168 final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
169 return GLRegion.create(glp, renderModes, colorTexSeq, vertIndexCount[0], vertIndexCount[1]);
170 }
171
172 /**
173 * Create a GLRegion using the passed render mode and pre-calculating its buffer sizes
174 * using given font's {@link Font#processString(com.jogamp.graph.font.Font.GlyphVisitor2, CharSequence)}
175 * to {@link #countOutlineShape(OutlineShape, int[])}.
176 *
177 * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
178 * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
179 * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
180 * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
181 * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
182 * @param font Font used to {@link Font#processString(com.jogamp.graph.curve.OutlineShape.Visitor2, CharSequence)} to {@link #countOutlineShape(OutlineShape, int[]) to count initial number of vertices and indices}
183 * @param str the string used to to {@link #countOutlineShape(OutlineShape, int[]) to count initial number of vertices and indices}
184 */
185 public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final Font font, final CharSequence str) {
186 final int[] vertIndexCount = { 0, 0 };
187 final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() {
188 @Override
189 public final void visit(final Font.Glyph glyph) {
190 if( !glyph.isNonContour() ) {
191 Region.countOutlineShape(glyph.getShape(), vertIndexCount);
192 }
193 } };
194 font.processString(visitor, str);
195 return GLRegion.create(glp, renderModes, colorTexSeq, vertIndexCount[0], vertIndexCount[1]);
196 }
197
198 private final int gl_idx_type;
200
201 // pass-1 common data
202 protected int curVerticesCap = 0;
203 protected int curIndicesCap = 0;
204 protected int growCount = 0;
205
206 /** Interleaved buffer for GLSL attributes: vectices, curveParams and optionally colors */
212
213 protected GLRegion(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
214 super(renderModes, glp.isGL2ES3() /* use_int32_idx */);
215 this.gl_idx_type = usesI32Idx() ? GL.GL_UNSIGNED_INT : GL.GL_UNSIGNED_SHORT;
216 this.colorTexSeq = colorTexSeq;
217 }
218
219 protected final int glIdxType() { return this.gl_idx_type; }
220
221 public GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage) {
222 if( useMappedBuffers ) {
223 return GLArrayDataServer.createGLSLInterleavedMapped(comps, dataType, normalized, initialSize, vboUsage);
224 } else {
225 return GLArrayDataServer.createGLSLInterleaved(comps, dataType, normalized, initialSize, vboUsage);
226 }
227 }
228
229 public void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components) {
230 array.addGLSLSubArray("vertices", components, GL.GL_ARRAY_BUFFER);
231 array.addGLSLSubArray("normals", components, GL.GL_ARRAY_BUFFER);
232 }
233
234 protected final void initBuffer(final int verticeCount, final int indexCount) {
238
239 final boolean cc = hasColorChannel();
240 final int totalCompsPerElem = 3 + 3 + (cc ? 4 : 0);
241 vpc_ileave = GLArrayDataServer.createGLSLInterleaved(totalCompsPerElem, GL.GL_FLOAT, false /* normalized */, verticeCount, GL.GL_STATIC_DRAW);
243
244 gca_VerticesAttr = vpc_ileave.addGLSLSubArray(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_ARRAY_BUFFER);
245 gca_CurveParamsAttr = vpc_ileave.addGLSLSubArray(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_ARRAY_BUFFER);
246 if( cc ) {
247 gca_ColorsAttr = vpc_ileave.addGLSLSubArray(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_ARRAY_BUFFER);
248 }
250 growCount = 0;
251 }
252
253 @Override
254 public final boolean growBuffer(final int verticesCount, final int indicesCount) {
255 boolean grown = false;
256 if( !DEBUG_BUFFER ) {
257 if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
260 grown = true;
261 }
262 if( curVerticesCap < vpc_ileave.elemPosition() + verticesCount ) {
265 grown = true;
266 }
267 } else {
268 if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
269 System.err.printf("GLRegion: Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
271
273
274 System.err.println("GLRegion: Grew Indices 0x"+Integer.toHexString(hashCode())+": "+curIndicesCap+" -> "+indicesBuffer.getElemCapacity()+", "+indicesBuffer.elemStatsToString());
275 Thread.dumpStack();
276
278 grown = true;
279 }
280 if( curVerticesCap < vpc_ileave.elemPosition() + verticesCount ) {
281 System.err.printf("GLRegion: Buffer grow - Vertices: %d < ( %d = %d + %d ); Status: %s%n",
283
285
286 System.err.println("GLRegion: Grew Vertices 0x"+Integer.toHexString(hashCode())+": "+curVerticesCap+" -> "+gca_VerticesAttr.getElemCapacity()+", "+gca_VerticesAttr.elemStatsToString());
287
289 grown = true;
290 }
291 }
292 if( grown ) {
293 ++growCount;
294 return true;
295 } else {
296 return false;
297 }
298 }
299
300 @Override
301 public final boolean setBufferCapacity(final int verticesCount, final int indicesCount) {
302 boolean grown = false;
303 if( curIndicesCap < indicesCount ) {
304 indicesBuffer.reserve(indicesCount);
306 grown = true;
307 }
308 if( curVerticesCap < verticesCount ) {
309 vpc_ileave.reserve(verticesCount);
311 grown = true;
312 }
313 return grown;
314 }
315
316 @Override
317 public final void printBufferStats(final PrintStream out) {
318 final int[] size= { 0 }, capacity= { 0 };
319 out.println("GLRegion: idx32 "+usesI32Idx()+", obj 0x"+Integer.toHexString(hashCode()));
320 printAndCount(out, " indices ", indicesBuffer, size, capacity);
321 out.println();
322 printAndCount(out, " ileave ", vpc_ileave, size, capacity);
323 out.println();
324 {
325 print(out, " - vertices ", gca_VerticesAttr);
326 out.println();
327 print(out, " - params ", gca_CurveParamsAttr);
328 out.println();
329 print(out, " - color ", gca_ColorsAttr);
330 out.println();
331 }
332 final float filled = (float)size[0]/(float)capacity[0];
333 out.printf(" total [bytes %,d / %,d], filled[%.1f%%, left %.1f%%], grow-cnt %d, obj 0x%x%n",
334 size[0], capacity[0], filled*100f, (1f-filled)*100f, growCount, hashCode());
335 // out.printf(" vpc_ileave: %s%n", vpc_ileave.toString());
336 // out.printf(" - vertices: %s%n", gca_VerticesAttr.toString());
337 }
338
339 private static void printAndCount(final PrintStream out, final String name, final GLArrayData data, final int[] size, final int[] capacity) {
340 out.print(name+"[");
341 if( null != data ) {
342 out.print(data.fillStatsToString());
343 size[0] += data.getByteCount();
344 capacity[0] += data.getByteCapacity();
345 out.print("]");
346 } else {
347 out.print("null]");
348 }
349 }
350 private static void print(final PrintStream out, final String name, final GLArrayData data) {
351 out.print(name+"[");
352 if( null != data ) {
353 out.print(data.fillStatsToString());
354 out.print("]");
355 } else {
356 out.print("null]");
357 }
358 }
359
360 /** Set the 2nd pass texture unit. */
361 public abstract void setTextureUnit(final int pass2TexUnit);
362
363 @Override
364 protected final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba) {
365 // NIO array[3] is much slows than group/single
366 // gca_VerticesAttr.putf(coords, 0, 3);
367 // gca_CurveParamsAttr.putf(texParams, 0, 3);
368 // gca_VerticesAttr.put3f(coords.x(), coords.y(), coords.z());
369 // System.err.println("GLRegion V: "+coords);
370 put3f((FloatBuffer)vpc_ileave.getBuffer(), coords);
371 put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams);
372 if( hasColorChannel() ) {
373 if( null != rgba ) {
374 put4f((FloatBuffer)vpc_ileave.getBuffer(), rgba);
375 } else {
376 throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
377 }
378 }
379 }
380
381 @Override
382 protected final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3,
383 final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba) {
384 final boolean cc = hasColorChannel();
385 if( cc && null == rgba ) {
386 throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
387 }
388 // System.err.println("GLRegion V: "+coords1+", "+coords2+", "+coords3);
389 put3f((FloatBuffer)vpc_ileave.getBuffer(), coords1);
390 put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams1);
391 if( cc ) {
392 put4f((FloatBuffer)vpc_ileave.getBuffer(), rgba);
393 }
394 put3f((FloatBuffer)vpc_ileave.getBuffer(), coords2);
395 put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams2);
396 if( cc ) {
397 put4f((FloatBuffer)vpc_ileave.getBuffer(), rgba);
398 }
399 put3f((FloatBuffer)vpc_ileave.getBuffer(), coords3);
400 put3f((FloatBuffer)vpc_ileave.getBuffer(), texParams3);
401 if( cc ) {
402 put4f((FloatBuffer)vpc_ileave.getBuffer(), rgba);
403 }
404 }
405
406 @Override
407 protected final void pushIndex(final int idx) {
408 if( usesI32Idx() ) {
409 indicesBuffer.puti(idx);
410 } else {
411 indicesBuffer.puts((short)idx);
412 }
413 }
414
415 @Override
416 protected final void pushIndices(final int idx1, final int idx2, final int idx3) {
417 if( usesI32Idx() ) {
418 // indicesBuffer.put3i(idx1, idx2, idx3);
419 put3i((IntBuffer)indicesBuffer.getBuffer(), idx1, idx2, idx3);
420 } else {
421 // indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3);
422 put3s((ShortBuffer)indicesBuffer.getBuffer(), (short)idx1, (short)idx2, (short)idx3);
423 }
424 }
425
426 /**
427 * Clears all buffers, i.e. triangles, vertices etc and and resets states accordingly, see {@link GLArrayDataEditable#clear(GL)}.
428 * <p>
429 * This method does not actually erase the data in the buffer and will most often be used when erasing the underlying memory is suitable.
430 * </p>
431 *
432 * @param gl the current {@link GL2ES2} object
433 * @return this {@link GLRegion} for chaining.
434 * @see GLArrayDataEditable#clear(GL)
435 */
436 public final GLRegion clear(final GL2ES2 gl) {
437 lastRenderModes = 0;
438 if(DEBUG_INSTANCE) {
439 System.err.println("GLRegion Clear: " + this);
440 }
441 if( null != indicesBuffer ) {
443 }
444 if( null != vpc_ileave ) {
445 vpc_ileave.clear(gl);
446 }
447 clearImpl(gl);
448 clearImpl();
449 return this;
450 }
451 protected abstract void clearImpl(final GL2ES2 gl);
452
453 /**
454 * Delete and clear the associated OGL objects.
455 * <p>
456 * The {@link ShaderProgram}s references are nullified but not {@link ShaderProgram#destroy(GL2ES2) destroyed}
457 * as they are owned by {@link RegionRenderer}.
458 * </p>
459 */
460 public final void destroy(final GL2ES2 gl) {
461 clear(gl);
462 if( null != vpc_ileave ) {
464 vpc_ileave = null;
465 }
466 if( null != gca_VerticesAttr ) {
468 gca_VerticesAttr = null;
469 }
470 if( null != gca_CurveParamsAttr ) {
472 gca_CurveParamsAttr = null;
473 }
474 if( null != gca_ColorsAttr ) {
476 gca_ColorsAttr = null;
477 }
478 if(null != indicesBuffer) {
480 indicesBuffer = null;
481 }
482 curVerticesCap = 0;
483 curIndicesCap = 0;
484 growCount = 0;
485 destroyImpl(gl);
486 }
487 protected abstract void destroyImpl(final GL2ES2 gl);
488
489 /**
490 * Renders the associated OGL objects specifying
491 * current width/hight of window for optional multi pass rendering of the region.
492 * <p>
493 * User shall consider {@link RegionRenderer#enable(GL2ES2, boolean) enabling}
494 * the renderer beforehand and {@link RegionRenderer#enable(GL2ES2, boolean) disabling}
495 * it afterwards when used in conjunction with other renderer.
496 * </p>
497 * <p>
498 * Users shall also consider setting the {@link GL#glClearColor(float, float, float, float) clear-color}
499 * appropriately:
500 * <ul>
501 * <li>If {@link GL#GL_BLEND blending} is enabled, <i>RGB</i> shall be set to text color, otherwise
502 * blending will reduce the alpha seam's contrast and the font will appear thinner.</li>
503 * <li>If {@link GL#GL_BLEND blending} is disabled, <i>RGB</i> shall be set to the actual desired background.</li>
504 * </ul>
505 * The <i>alpha</i> component shall be set to zero.
506 * Note: If {@link GL#GL_BLEND blending} is enabled, the
507 * {@link RegionRenderer} might need to be
508 * {@link RegionRenderer#create(Vertex.Factory<? extends Vertex>, RenderState, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback, com.jogamp.graph.curve.opengl.RegionRenderer.GLCallback) created}
509 * with the appropriate {@link RegionRenderer.GLCallback callbacks}.
510 * </p>
511 * @param gl current {@link GL2ES2}.
512 * @param renderer the {@link RegionRenderer} to be used
513 * @see RegionRenderer#enable(GL2ES2, boolean)
514 * @see RegionRenderer#setAAQuality(int)
515 * @see RegionRenderer#setSampleCount(int)
516 * @see RegionRenderer#setClipBBox(com.jogamp.math.geom.AABBox)
517 */
518 public final void draw(final GL2ES2 gl, final RegionRenderer renderer) {
519 final int pass2Quality = renderer.getAAQuality();
520 final int pass2SampleCount = renderer.getSampleCount();
521 final int curRenderModes;
522 if( 0 == pass2SampleCount ) {
523 // no sampling, reduce to pass1
524 curRenderModes = getRenderModes() & ~( VBAA_RENDERING_BIT | MSAA_RENDERING_BIT );
525 } else if( 0 > pass2SampleCount ) {
526 // negative sampling, hint we perform glSelect: pass1 w/o any color texture nor channel, use static select color only
528 } else {
529 // normal 2-pass sampling
530 curRenderModes = getRenderModes();
531 }
532 // System.err.println("XXX.0 "+Region.getRenderModeString(getRenderModes(), sampleCount[0], 0)+": "+
533 // Region.getRenderModeString(lastRenderModes, sampleCount[0], 0)+" -> "+Region.getRenderModeString(curRenderModes, sampleCount[0], 0));
534
535 if( lastRenderModes != curRenderModes ) {
538 } else if( Region.isGraphAA(curRenderModes) &&
539 ( lastPass2Quality != pass2Quality || lastPass2SampleCount != pass2SampleCount ) ) {
541 }
542 if( isShapeDirty() ) {
543 updateImpl(gl, renderer, curRenderModes);
544 }
545 drawImpl(gl, renderer, curRenderModes);
547 lastRenderModes = curRenderModes;
548 lastPass2Quality = pass2Quality;
549 lastPass2SampleCount = pass2SampleCount;
550 }
551
552 /** Perform glSelect false color rendering: pass1 w/o any color texture nor channel, use static select color only */
553 public final void drawToSelect(final GL2ES2 gl, final RegionRenderer renderer) {
555 if( lastRenderModes != curRenderModes ) {
558 }
559 if( isShapeDirty() ) {
560 updateImpl(gl, renderer, curRenderModes);
561 }
562 drawImpl(gl, renderer, curRenderModes);
564 lastRenderModes = curRenderModes;
565 }
566
567 private int lastRenderModes = 0;
568 private int lastPass2Quality = -1;
569 private int lastPass2SampleCount = -1;
570
571 /**
572 * Updates a graph region by updating the ogl related
573 * objects for use in rendering if {@link #isShapeDirty()}.
574 * <p>Allocates the ogl related data and initializes it the 1st time.<p>
575 * <p>Called by {@link #draw(GL2ES2, RenderState, int, int, int)}.</p>
576 */
577 protected abstract void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes);
578
579 protected abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes);
580}
A Generic shape objects which is defined by a list of Outlines.
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int MSAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:95
final boolean isVBAA()
Returns true if capable of two pass rendering - VBAA, otherwise false.
Definition: Region.java:358
final boolean hasColorChannel()
Returns true if getRenderModes() has a color channel, i.e.
Definition: Region.java:386
static void put3f(final FloatBuffer b, final Vec3f v)
Definition: Region.java:467
static final int COLORCHANNEL_RENDERING_BIT
Rendering-Mode bit for Region to optionally enable a color-channel per vertex.
Definition: Region.java:148
static final int COLORTEXTURE_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:161
static final int DEFAULT_TWO_PASS_TEXTURE_UNIT
Definition: Region.java:181
final void markStateDirty()
Mark this region's render-state dirty, i.e.
Definition: Region.java:811
final void clearDirtyBits(final int v)
See markShapeDirty() and markStateDirty().
Definition: Region.java:822
static final int[] countOutlineShape(final OutlineShape shape, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
Definition: Region.java:572
final boolean isShapeDirty()
Returns true if this region's shape are dirty, see markShapeDirty().
Definition: Region.java:801
final boolean isMSAA()
Returns true if capable of two pass rendering - MSAA, otherwise false.
Definition: Region.java:366
static boolean isGraphAA(final int renderModes)
Returns true if given renderModes has any of Region#AA_RENDERING_MASK set.
Definition: Region.java:208
static final int DIRTY_STATE
Definition: Region.java:184
static final int DIRTY_SHAPE
Definition: Region.java:183
static final boolean DEBUG_INSTANCE
Definition: Region.java:65
static void put4f(final FloatBuffer b, final float v1, final float v2, final float v3, final float v4)
Definition: Region.java:470
final int getRenderModes()
Returns bit-field of render modes, see create(..).
Definition: Region.java:344
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
static void put3i(final IntBuffer b, final int v1, final int v2, final int v3)
Definition: Region.java:461
final boolean usesI32Idx()
Returns true if implementation uses int32_t sized indices implying at least a GLProfile#isGL2ES3() al...
Definition: Region.java:305
static void put3s(final ShortBuffer b, final short v1, final short v2, final short v3)
Definition: Region.java:464
final void markShapeDirty()
Mark this region's shape dirty, i.e.
Definition: Region.java:797
static boolean hasColorTexture(final int renderModes)
Returns true if render mode has a color texture, i.e.
Definition: Region.java:240
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
Definition: GLRegion.java:70
static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
Definition: GLRegion.java:137
final void drawToSelect(final GL2ES2 gl, final RegionRenderer renderer)
Perform glSelect false color rendering: pass1 w/o any color texture nor channel, use static select co...
Definition: GLRegion.java:553
GLRegion(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq)
Definition: GLRegion.java:213
GLArrayDataServer vpc_ileave
Interleaved buffer for GLSL attributes: vectices, curveParams and optionally colors.
Definition: GLRegion.java:207
abstract void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes)
static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final OutlineShape shape)
Create a GLRegion using the passed render mode and pre-calculating its buffer sizes using Region#coun...
Definition: GLRegion.java:167
static final int defaultIndicesCount
Default initial indices count {@value}, assuming small sized shapes.
Definition: GLRegion.java:92
static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final Font font, final CharSequence str)
Create a GLRegion using the passed render mode and pre-calculating its buffer sizes using given font'...
Definition: GLRegion.java:185
final GLRegion clear(final GL2ES2 gl)
Clears all buffers, i.e.
Definition: GLRegion.java:436
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
Definition: GLRegion.java:460
final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba)
Definition: GLRegion.java:364
final void printBufferStats(final PrintStream out)
Print implementation buffer stats like detailed and total size and capacity in bytes etc.
Definition: GLRegion.java:317
GLArrayDataWrapper gca_CurveParamsAttr
Definition: GLRegion.java:209
GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage)
Definition: GLRegion.java:221
static final int defaultVerticesCount
Heuristics with TestTextRendererNEWT00 text_1 + text_2 = 1334 chars.
Definition: GLRegion.java:87
final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3, final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba)
Definition: GLRegion.java:382
final void initBuffer(final int verticeCount, final int indexCount)
Definition: GLRegion.java:234
void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components)
Definition: GLRegion.java:229
final void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the associated OGL objects specifying current width/hight of window for optional multi pass r...
Definition: GLRegion.java:518
final void pushIndices(final int idx1, final int idx2, final int idx3)
Definition: GLRegion.java:416
abstract void clearImpl(final GL2ES2 gl)
abstract void destroyImpl(final GL2ES2 gl)
abstract void setTextureUnit(final int pass2TexUnit)
Set the 2nd pass texture unit.
final boolean setBufferCapacity(final int verticesCount, final int indicesCount)
Set the renderer buffers pre-emptively for given vertices- and index counts.
Definition: GLRegion.java:301
final TextureSequence colorTexSeq
Definition: GLRegion.java:199
final void pushIndex(final int idx)
Definition: GLRegion.java:407
static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq)
Create a GLRegion using the passed render mode and default initial buffer sizes defaultVerticesCount ...
Definition: GLRegion.java:152
final boolean growBuffer(final int verticesCount, final int indicesCount)
Increase the renderer buffers if necessary to add given counts of vertices- and index elements.
Definition: GLRegion.java:254
abstract void updateImpl(final GL2ES2 gl, final RegionRenderer renderer, final int curRenderModes)
Updates a graph region by updating the ogl related objects for use in rendering if isShapeDirty().
static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
Definition: GLRegion.java:109
final int getAAQuality()
Returns pass2 AA-quality rendering value for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT.
final int getSampleCount()
Returns pass2 AA sample count for Graph Region AA render-modes: VBAA_RENDERING_BIT or Region#MSAA_REN...
3D Vector based upon three float components.
Definition: Vec3f.java:37
4D Vector based upon four float components.
Definition: Vec4f.java:37
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
final boolean isGL2ES3()
Indicates whether this profile is capable of GL2ES3.
final boolean growIfNeeded(final int spareComponents)
Increase the capacity of the buffer if necessary to add given spareComponents components.
void setGrowthFactor(final float v)
Sets a new growth factor for this buffer.
static final float DEFAULT_GROWTH_FACTOR
Default growth factor using the golden ratio 1.618.
final boolean reserve(int elementCount)
Increase the capacity of the buffer to given elementCount element size, i.e.
void clear(final GL gl)
Clears this buffer and resets states accordingly.
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
static GLArrayDataServer createData(final int compsPerElement, final int dataType, final int stride, final Buffer buffer, final int vboUsage, final int vboTarget)
Create a VBO data object for any target w/o render pipeline association, ie GL#GL_ELEMENT_ARRAY_BUFFE...
GLArrayDataWrapper addGLSLSubArray(final String name, final int comps, final int vboTarget)
Configure a segment of this GLSL interleaved array (see createGLSLInterleaved(int,...
static GLArrayDataServer createGLSLInterleavedMapped(final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data intended for GPU buffer storage mapping,...
final int getCompsPerElem()
The number of components per element.
final int elemPosition()
Returns the element position.
String elemStatsToString()
Returns a string with detailed buffer element stats, i.e.
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
int getElemCapacity()
Return the element capacity.
General purpose Font.Glyph visitor w/o AffineTransform.
Definition: Font.java:310
Interface wrapper for font implementation.
Definition: Font.java:60
AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string)
Try using processString(GlyphVisitor, AffineTransform, CharSequence, AffineTransform,...
The total number of bytes hold by the referenced buffer is: getComponentSize()* getComponentNumber() ...
String fillStatsToString()
Returns a string with detailed buffer fill stats.
int getByteCapacity()
Return the capacity in bytes.
int getByteCount()
Returns the byte position (written elements) if not sealed() or the byte limit (available to read) af...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
Definition: GL.java:673
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
Definition: GL.java:786
static final int GL_UNSIGNED_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_SHORT" with ...
Definition: GL.java:346
static final int GL_ELEMENT_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ELEME...
Definition: GL.java:318
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
Definition: GL.java:633
Protocol for texture sequences, like animations, movies, etc.