28package com.jogamp.opengl.test.junit.graph;
31import java.io.IOException;
32import java.io.PrintStream;
33import java.time.Duration;
34import java.time.Instant;
35import java.util.Locale;
36import java.util.concurrent.TimeUnit;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GL2ES2;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLDrawable;
42import com.jogamp.opengl.GLException;
43import com.jogamp.opengl.GLProfile;
44import com.jogamp.opengl.JoglVersion;
46import com.jogamp.common.os.Clock;
47import com.jogamp.common.util.IOUtil;
48import com.jogamp.common.util.VersionUtil;
49import com.jogamp.graph.curve.Region;
50import com.jogamp.graph.curve.opengl.RenderState;
51import com.jogamp.graph.curve.opengl.GLRegion;
52import com.jogamp.graph.curve.opengl.RegionRenderer;
53import com.jogamp.graph.curve.opengl.TextRegionUtil;
54import com.jogamp.graph.font.Font;
55import com.jogamp.graph.font.FontFactory;
56import com.jogamp.math.Vec4f;
57import com.jogamp.math.geom.AABBox;
58import com.jogamp.math.geom.plane.AffineTransform;
59import com.jogamp.math.util.PMVMatrix4f;
60import com.jogamp.opengl.test.junit.util.MiscUtils;
61import com.jogamp.opengl.test.junit.util.NEWTGLContext;
62import com.jogamp.opengl.util.GLReadBufferUtil;
75 static final Instant t0i = Clock.getMonotonicTime();
76 static final long t0 = Clock.currentNanos();
77 static final boolean DEBUG =
false;
78 static final boolean TRACE =
false;
79 static long duration = 100;
80 static boolean forceES2 =
false;
81 static boolean forceGL3 =
false;
82 static int win_width = 1280;
83 static int win_height = 720;
84 static int loop_count = 1;
85 static boolean do_perf =
false;
86 static boolean do_snap =
false;
87 static boolean do_vsync =
false;
90 private final Vec4f fg_color =
new Vec4f( 0, 0, 0, 1 );
94 font =
FontFactory.
get(IOUtil.getResource(
"fonts/freefont/FreeSans.ttf",
97 }
catch (
final IOException e) {
102 public static void main(
final String args[])
throws IOException,
GLException, InterruptedException {
104 boolean wait =
false;
105 for(
int i=0; i<args.length; i++) {
106 if(args[i].equals(
"-time")) {
109 }
else if(args[i].equals(
"-width")) {
112 }
else if(args[i].equals(
"-height")) {
115 }
else if(args[i].equals(
"-es2")) {
117 }
else if(args[i].equals(
"-gl3")) {
119 }
else if(args[i].equals(
"-font")) {
122 }
else if(args[i].equals(
"-wait")) {
124 }
else if(args[i].equals(
"-loop")) {
127 if( 0 >= loop_count ) {
128 loop_count = Integer.MAX_VALUE;
130 }
else if(args[i].equals(
"-long_text")) {
132 }
else if(args[i].equals(
"-vsync")) {
134 }
else if(args[i].equals(
"-perf")) {
136 }
else if(args[i].equals(
"-snap")) {
140 System.err.println(
"Excessuive performance test enabled: "+do_perf);
141 System.err.println(
"VSync requested: "+do_vsync);
145 final int renderModes = Region.VBAA_RENDERING_BIT ;
146 final int sampleCount = 4;
149 obj.
test(renderModes, sampleCount, text);
152 static void sleep() {
154 System.err.println(
"** new frame ** (sleep: "+duration+
"ms)");
155 Thread.sleep(duration);
156 }
catch (
final InterruptedException ie) {}
161 public long td_graph = 0;
162 public long td_txt = 0;
163 public long td_draw = 0;
164 public long td_txt_draw = 0;
165 public long count = 0;
168 final Instant startupMTime = Clock.getMonotonicStartupTime();
169 final Instant currentMTime = Clock.getMonotonicTime();
170 final Instant wallTime = Clock.getWallClockTime();
171 final Duration elapsedSinceStartup = Duration.between(startupMTime, currentMTime);
172 System.err.printf(
"Perf: Elapsed since startup: %,d [ms], %,d [ns]%n", elapsedSinceStartup.toMillis(), elapsedSinceStartup.toNanos());
173 System.err.printf(
"- monotonic startup %s, %,d [ms]%n", startupMTime, startupMTime.toEpochMilli());
174 System.err.printf(
"- monotonic current %s, %,d [ms]%n", currentMTime, currentMTime.toEpochMilli());
175 System.err.printf(
"- wall current %s%n", wallTime);
176 final long td = Clock.currentNanos();
177 System.err.printf(
"- currentNanos: Elapsed %,d [ns]%n", (td-t0));
178 System.err.printf(
" - test-startup %,13d [ns]%n", t0);
179 System.err.printf(
" - test-current %,13d [ns]%n", td);
182 public void clear() {
190 public void print(
final PrintStream out,
final long frame,
final String msg) {
191 out.printf(
"%3d / %3d: Perf %s: Total: graph %,2d, txt %,2d, draw %,2d, txt+draw %,2d [ms]%n",
193 TimeUnit.NANOSECONDS.toMillis(td_graph),
194 TimeUnit.NANOSECONDS.toMillis(td_txt),
195 TimeUnit.NANOSECONDS.toMillis(td_draw), TimeUnit.NANOSECONDS.toMillis(td_txt_draw));
196 out.printf(
"%3d / %3d: Perf %s: PerLoop: graph %,4d, txt %,4d, draw %,4d, txt+draw %,4d [ns]%n",
198 td_graph/count, td_txt/count, td_draw/count, td_txt_draw/count );
202 public void test(
final int renderModes,
final int sampleCount,
final String text)
throws InterruptedException,
GLException, IOException {
206 }
else if(forceES2) {
212 final Instant t1i = Clock.getMonotonicTime();
213 final long t1 = Clock.currentNanos();
219 final GLDrawable drawable = winctx.context.getGLDrawable();
227 System.err.println(
"Initial GL Error: "+glerr);
230 System.err.println(VersionUtil.getPlatformInfo());
234 System.err.println(
"GLDrawable surface size: "+winctx.context.getGLDrawable().getSurfaceWidth()+
" x "+winctx.context.getGLDrawable().getSurfaceHeight());
236 System.err.println(
"Requested Caps: "+caps);
238 System.err.println(
"Chosen Caps: "+winctx.window.getChosenCapabilities());
249 System.err.println(
"Region post ctor w/ pre-calculated buffer size");
252 final Perf perf =
new Perf();
261 for(
int loop_i=0; loop_i < loop_count; ++loop_i) {
262 final long t2 = Clock.currentNanos();
279 final int z0 = -1000;
285 final long t3 = Clock.currentNanos();
288 final float fontScale;
296 t4 = Clock.currentNanos();
299 if( 0 == loop_i && !do_perf ) {
300 System.err.println(
"Text_1: tbox "+tbox_1);
301 System.err.println(
"Text_1: rbox "+rbox_1);
302 System.err.println(
"Font scale: "+fontScale);
311 pmv.
scaleMv(fontScale, fontScale, 1f);
312 region.
draw(gl, renderer);
313 final long t5 = Clock.currentNanos();
315 final long td_graph = t3 - t2;
316 final long td_txt = t4 - t3;
317 final long td_draw = t5 - t4;
318 final long td_txt_draw = t5 - t3;
319 perf.td_graph += td_graph;
320 perf.td_txt += td_txt;
321 perf.td_draw += td_draw;
322 perf.td_txt_draw += td_txt_draw;
324 final Duration td_launch0a = Duration.between(Clock.getMonotonicStartupTime(), t0i);
325 final Duration td_launch0b = Duration.between(Clock.getMonotonicStartupTime(), t1i);
326 final long td_launch1 = t1 - t0;
327 final long td_launch2 = t2 - t0;
328 final long td_launch3 = t3 - t0;
329 final long td_launch_txt = t4 - t0;
330 final long td_launch_draw = t5 - t0;
331 System.err.printf(
"%n%n%3d: Perf Launch:%n"+
332 "- loading GlueGen - loading test %,6d [ms]%n"+
333 "- loading GlueGen - start test %,6d [ms]%n"+
334 "- loading test - start test %,6d [ms]%n"+
335 "- loading test - gl %,6d [ms]%n"+
336 "- loading test - graph %,6d [ms]%n"+
337 "- loading test - txt %,6d [ms]%n"+
338 "- loading test - draw %,6d [ms]%n",
340 td_launch0a.toMillis(), td_launch0b.toMillis(),
341 TimeUnit.NANOSECONDS.toMillis(td_launch1), TimeUnit.NANOSECONDS.toMillis(td_launch2),
342 TimeUnit.NANOSECONDS.toMillis(td_launch3), TimeUnit.NANOSECONDS.toMillis(td_launch_txt),
343 TimeUnit.NANOSECONDS.toMillis(td_launch_draw));
344 perf.print(System.err, loop_i+1,
"Launch");
347 if( loop_count - 1 == loop_i && do_snap ) {
350 printScreen(screenshot, renderModes, drawable, gl,
false, sampleCount);
353 if(
null != perf && loop_count/2-1 == loop_i ) {
358 perf.print(System.err, loop_i+1,
"Frame"+(loop_i+1));
364 if( 0 == loop_i || loop_count - 1 == loop_i) {
367 System.err.println(
"GLRegion: "+region);
368 System.err.println(
"Text length: "+text.length());
373 perf.print(System.err, loop_i+1,
"Frame"+(loop_i+1));
389 "JOGL: Java™ Binding for OpenGL®, providing hardware-accelerated 3D graphics.\n\n"+
390 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus.\n"+
391 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies\n"+
392 "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit.\n"+
393 "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est.\n"+
394 "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi.\n"+
395 "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper\n"+
396 "Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem,\n" +
397 "I “Ask Jeff” or ‘Ask Jeff’. Take the chef d’œuvre! Two of [of] (of) ‘of’ “of” of? of! of*.\n"+
398 "Les Woëvres, the Fôret de Wœvres, the Voire and Vauvise. Yves is in heaven.\n"+
399 "Lyford’s in Texas & L’Anse-aux-Griffons in Québec; the Łyna in Poland. Yriarte is in Yale.\n"+
400 "Kyoto and Ryotsu are both in Japan, Kwikpak on the Yukon delta, Kvæven in Norway…\n"+
401 "Von-Vincke-Straße in Münster, Vdovino in Russia, Ytterbium in the periodic table.\n"+
402 "Miłosz and Wū Wŭ all in the library? 1510–1620, 11:00 pm, and the 1980s are over.\n"+
403 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
404 "-------Press H to change text---------";
407 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
408 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
409 "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
410 "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est. \n"+
411 "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi. \n"+
412 "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
413 "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem, \n" +
414 "I “Ask Jeff” or ‘Ask Jeff’. Take the chef d’œuvre! Two of"+
422 public static final String
text_1s =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus.";
424 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec sapien tellus. \n"+
425 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel urna. Mauris ultricies \n"+
426 "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices ultricies nec a elit. \n"+
427 "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia pharetra at venenatis est. \n"+
428 "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat nec, volutpat nec nisi. \n"+
429 "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum id tempus quis, semper \n"+
430 "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin. Quisque sit amet neque lorem, \n" +
431 "-------Press H to change text---------";
435 final int screenshot_num = 0;
436 final String dir =
"./";
437 final String objName =
"TestTextRendererNEWT00-snap"+screenshot_num;
440 final String bname = String.format((Locale)
null,
"%s-msaa%02d-%03dx%03d-%s%04d", objName,
441 drawable.getChosenGLCapabilities().getNumSamples(),
442 drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
443 final String filename = dir + bname +
".png";
444 if(screenshot.readPixels(gl,
false)) {
445 screenshot.write(
new File(filename));
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static final int DEFAULT_AA_QUALITY
Default pass2 AA-quality rendering {@value} for Graph Region AA render-modes: VBAA_RENDERING_BIT.
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
PerfCounterCtrl perfCounter()
final boolean usesI32Idx()
Returns true if implementation uses int32_t sized indices implying at least a GLProfile#isGL2ES3() al...
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
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 printBufferStats(final PrintStream out)
Print implementation buffer stats like detailed and total size and capacity in bytes etc.
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...
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 void reshapeOrtho(final int width, final int height, final float near, final float far)
Orthogonal projection, method also calls reshapeNotify(int, int, int, int).
final void setColorStatic(final Vec4f rgbaColor)
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final int setSampleCount(final int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
static final GLCallback defaultBlendDisable
Default GL#GL_BLEND disable GLCallback, simply turning-off the GL#GL_BLEND state and turning-on depth...
final int setAAQuality(final int v)
Sets pass2 AA-quality rendering value clipped to the range [Region#MIN_AA_QUALITY....
static final GLCallback defaultBlendEnable
Default GL#GL_BLEND enable GLCallback, turning-off depth writing via GL#glDepthMask(boolean) if Rende...
final void init(final GL2ES2 gl)
Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext if no...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
final void destroy(final GL2ES2 gl)
Deletes all ShaderPrograms and nullifies its references including RenderState#destroy(GL2ES2).
final void setHintBits(final int mask)
The RenderState is owned by RegionRenderer.
static final int BITHINT_GLOBAL_DEPTH_TEST_ENABLED
Bitfield hint, if set stating globally enabled GL#GL_DEPTH_TEST, otherwise disabled.
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, final CharSequence str, final Vec4f rgbaColor)
Add the string in 3D space w.r.t.
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
4D Vector based upon four float components.
Axis Aligned Bounding Box.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f translateMv(final float x, final float y, final float z)
Translate the modelview matrix.
final PMVMatrix4f scaleMv(final float x, final float y, final float z)
Scale the modelview matrix.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
Specifies a set of OpenGL capabilities.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
static StringBuilder getAllAvailableCapabilitiesInfo(AbstractGraphicsDevice device, StringBuilder sb)
TestTextRendererNEWT00 Variant.
static final String text_1
static final String text_long
static void main(final String args[])
static final String text_1b
void test(final int renderModes, final int sampleCount, final String text)
static final String text_1s
static void printScreen(final GLReadBufferUtil screenshot, final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount)
static void waitForKey(final String preMessage)
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
static WindowContext createWindow(final GLCapabilities caps, final int width, final int height, final boolean debugGL)
static void destroyWindow(final WindowContext winctx)
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
void dispose(final GL gl)
Interface wrapper for font implementation.
float getLineHeight()
Returns line height, baseline-to-baseline in em-size [0..1], composed from ‘hhea’ table entries.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...
int getGlyphID(final char codepoint)
Returns the Glyph ID mapped to given UTF16 (unicode) codepoint symbol.
float getAdvanceWidth(final int glyphID)
Returns advance-width of given glyphID in font em-size [0..1], sourced from hmtx table - same as Glyp...
GL getGL()
Casts this object to the GL interface.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
int getSwapInterval()
Return the current swap interval.
An abstraction for an OpenGL rendering target.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
void swapBuffers()
Swaps the front and back buffers of this drawable.
static final int GL_NO_ERROR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NO_ERROR" with expres...
int glGetError()
Entry point to C language function: GLenum {@native glGetError}() Part of GL_ES_VERSION_2_0,...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glFinish()
Entry point to C language function: void {@native glFinish}() Part of GL_ES_VERSION_2_0,...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...