28package com.jogamp.graph.curve.opengl;
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;
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;
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;
52import java.io.PrintStream;
53import java.nio.FloatBuffer;
54import java.nio.IntBuffer;
55import java.nio.ShortBuffer;
57import com.jogamp.graph.curve.OutlineShape;
97 private static final boolean DEBUG_BUFFER = Debug.debug(
"graph.curve.Buffer");
110 final int initialVerticesCount,
final int initialIndicesCount)
115 throw new IllegalArgumentException(
"COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
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);
122 return new VBORegionSPES2(glp, renderModes,
colorTexSeq, initialVerticesCount, initialIndicesCount);
138 final int initialVerticesCount,
final int initialIndicesCount)
186 final int[] vertIndexCount = { 0, 0 };
189 public final void visit(
final Font.
Glyph glyph) {
190 if( !glyph.isNonContour() ) {
198 private final int gl_idx_type;
214 super(renderModes, glp.
isGL2ES3() );
219 protected final int glIdxType() {
return this.gl_idx_type; }
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 ) {
234 protected final void initBuffer(
final int verticeCount,
final int indexCount) {
240 final int totalCompsPerElem = 3 + 3 + (cc ? 4 : 0);
254 public final boolean growBuffer(
final int verticesCount,
final int indicesCount) {
255 boolean grown =
false;
256 if( !DEBUG_BUFFER ) {
269 System.err.printf(
"GLRegion: Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
281 System.err.printf(
"GLRegion: Buffer grow - Vertices: %d < ( %d = %d + %d ); Status: %s%n",
302 boolean grown =
false;
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);
322 printAndCount(out,
" ileave ",
vpc_ileave, size, capacity);
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());
339 private static void printAndCount(
final PrintStream out,
final String name,
final GLArrayData data,
final int[] size,
final int[] capacity) {
350 private static void print(
final PrintStream out,
final String name,
final GLArrayData data) {
353 out.print(data.fillStatsToString());
376 throw new IllegalArgumentException(
"Null color given for COLOR_CHANNEL rendering mode");
385 if( cc &&
null == rgba ) {
386 throw new IllegalArgumentException(
"Null color given for COLOR_CHANNEL rendering mode");
416 protected final void pushIndices(
final int idx1,
final int idx2,
final int idx3) {
439 System.err.println(
"GLRegion Clear: " +
this);
521 final int curRenderModes;
522 if( 0 == pass2SampleCount ) {
525 }
else if( 0 > pass2SampleCount ) {
535 if( lastRenderModes != curRenderModes ) {
539 ( lastPass2Quality != pass2Quality || lastPass2SampleCount != pass2SampleCount ) ) {
545 drawImpl(gl, renderer, curRenderModes);
547 lastRenderModes = curRenderModes;
548 lastPass2Quality = pass2Quality;
549 lastPass2SampleCount = pass2SampleCount;
555 if( lastRenderModes != curRenderModes ) {
562 drawImpl(gl, renderer, curRenderModes);
564 lastRenderModes = curRenderModes;
567 private int lastRenderModes = 0;
568 private int lastPass2Quality = -1;
569 private int lastPass2SampleCount = -1;
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.
static final int MSAA_RENDERING_BIT
Rendering-Mode bit for Region.
final boolean isVBAA()
Returns true if capable of two pass rendering - VBAA, otherwise false.
final boolean hasColorChannel()
Returns true if getRenderModes() has a color channel, i.e.
static void put3f(final FloatBuffer b, final Vec3f v)
static final int COLORCHANNEL_RENDERING_BIT
Rendering-Mode bit for Region to optionally enable a color-channel per vertex.
static final int COLORTEXTURE_RENDERING_BIT
Rendering-Mode bit for Region.
static final int DEFAULT_TWO_PASS_TEXTURE_UNIT
final void markStateDirty()
Mark this region's render-state dirty, i.e.
final void clearDirtyBits(final int v)
See markShapeDirty() and markStateDirty().
static final int[] countOutlineShape(final OutlineShape shape, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
final boolean isShapeDirty()
Returns true if this region's shape are dirty, see markShapeDirty().
final boolean isMSAA()
Returns true if capable of two pass rendering - MSAA, otherwise false.
static boolean isGraphAA(final int renderModes)
Returns true if given renderModes has any of Region#AA_RENDERING_MASK set.
static final int DIRTY_STATE
static final int DIRTY_SHAPE
static final boolean DEBUG_INSTANCE
static void put4f(final FloatBuffer b, final float v1, final float v2, final float v3, final float v4)
final int getRenderModes()
Returns bit-field of render modes, see create(..).
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
static void put3i(final IntBuffer b, final int v1, final int v2, final int v3)
final boolean usesI32Idx()
Returns true if implementation uses int32_t sized indices implying at least a GLProfile#isGL2ES3() al...
static void put3s(final ShortBuffer b, final short v1, final short v2, final short v3)
final void markShapeDirty()
Mark this region's shape dirty, i.e.
static boolean hasColorTexture(final int renderModes)
Returns true if render mode has a color texture, i.e.
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
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.
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...
GLRegion(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq)
GLArrayDataServer vpc_ileave
Interleaved buffer for GLSL attributes: vectices, curveParams and optionally colors.
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...
static final int defaultIndicesCount
Default initial indices count {@value}, assuming small sized shapes.
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'...
final GLRegion clear(final GL2ES2 gl)
Clears all buffers, i.e.
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
final void pushVertex(final Vec3f coords, final Vec3f texParams, final Vec4f rgba)
GLArrayDataWrapper gca_VerticesAttr
final void printBufferStats(final PrintStream out)
Print implementation buffer stats like detailed and total size and capacity in bytes etc.
GLArrayDataWrapper gca_CurveParamsAttr
GLArrayDataWrapper gca_ColorsAttr
GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage)
static final int defaultVerticesCount
Heuristics with TestTextRendererNEWT00 text_1 + text_2 = 1334 chars.
final void pushVertices(final Vec3f coords1, final Vec3f coords2, final Vec3f coords3, final Vec3f texParams1, final Vec3f texParams2, final Vec3f texParams3, final Vec4f rgba)
final void initBuffer(final int verticeCount, final int indexCount)
void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components)
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...
final void pushIndices(final int idx1, final int idx2, final int idx3)
abstract void clearImpl(final GL2ES2 gl)
abstract void destroyImpl(final GL2ES2 gl)
abstract void setTextureUnit(final int pass2TexUnit)
Set the 2nd pass texture unit.
GLArrayDataServer indicesBuffer
static final float growthFactor
final boolean setBufferCapacity(final int verticesCount, final int indicesCount)
Set the renderer buffers pre-emptively for given vertices- and index counts.
final TextureSequence colorTexSeq
final void pushIndex(final int idx)
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 ...
final boolean growBuffer(final int verticesCount, final int indicesCount)
Increase the renderer buffers if necessary to add given counts of vertices- and index elements.
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.
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.
4D Vector based upon four float components.
Specifies the the OpenGL profile.
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...
void destroy(final GL gl)
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.
void destroy(final GL gl)
int getElemCapacity()
Return the element capacity.
General purpose Font.Glyph visitor w/o AffineTransform.
Interface wrapper for font implementation.
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...
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...
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 ...
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...
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...
Protocol for texture sequences, like animations, movies, etc.