JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestPMVMatrix01NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 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 */
28
29package com.jogamp.opengl.test.junit.math;
30
31import java.nio.FloatBuffer;
32
33import com.jogamp.math.FloatUtil;
34import com.jogamp.math.Matrix4f;
35import com.jogamp.math.util.PMVMatrix4f;
36import com.jogamp.opengl.GL2ES1;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLContext;
39import com.jogamp.opengl.GLDrawable;
40import com.jogamp.opengl.GLDrawableFactory;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
43
44import jogamp.common.os.PlatformPropsImpl;
45
46import org.junit.AfterClass;
47import org.junit.Assert;
48import org.junit.BeforeClass;
49import org.junit.Test;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
52
53import com.jogamp.opengl.test.junit.util.MiscUtils;
54import com.jogamp.opengl.test.junit.util.UITestCase;
55import com.jogamp.opengl.util.PMVMatrix;
56
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58public class TestPMVMatrix01NEWT extends UITestCase {
59
60 static final float epsilon = 0.00001f;
61
62 // matrix 2 rows x 3 columns - In row major order
63 static FloatBuffer matrix2x3R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f, 3.0f,
64 4.0f, 5.0f, 6.0f } );
65
66 // matrix 2 rows x 3 columns - In column major order
67 static FloatBuffer matrix2x3C = FloatBuffer.wrap( new float[] { 1.0f, 4.0f,
68 2.0f, 5.0f,
69 3.0f, 6.0f } );
70
71 // matrix 3 rows x 2 columns - In row major order
72 static FloatBuffer matrix3x2R = FloatBuffer.wrap( new float[] { 1.0f, 2.0f,
73 3.0f, 4.0f,
74 5.0f, 6.0f } );
75
76 // matrix 3 rows x 2 columns - In column major order
77 static FloatBuffer matrix3x2C = FloatBuffer.wrap( new float[] { 1.0f, 3.0f, 5.0f,
78 2.0f, 4.0f, 6.0f } );
79
80 // Translated xyz 123 - Row - In row major order !
81 static Matrix4f translated123R = new Matrix4f( new float[] { 1.0f, 0.0f, 0.0f, 1.0f,
82 0.0f, 1.0f, 0.0f, 2.0f,
83 0.0f, 0.0f, 1.0f, 3.0f,
84 0.0f, 0.0f, 0.0f, 1.0f } );
85
86 // Translated xyz 123 - Column - In column major order !
87 static Matrix4f translated123C = new Matrix4f( new float[] { 1.0f, 0.0f, 0.0f, 0.0f,
88 0.0f, 1.0f, 0.0f, 0.0f,
89 0.0f, 0.0f, 1.0f, 0.0f,
90 1.0f, 2.0f, 3.0f, 1.0f } );
91
92 // Translated xyz 123 - Inverse - In column major order !
93 static Matrix4f translated123I = new Matrix4f( new float[] { 1.0f, 0.0f, 0.0f, 0.0f,
94 0.0f, 1.0f, 0.0f, 0.0f,
95 0.0f, 0.0f, 1.0f, 0.0f,
96 -1.0f, -2.0f, -3.0f, 1.0f } );
97
98 // Translated xyz 123 - Inverse and Transposed - In column major order !
99 static Matrix4f translated123IT = new Matrix4f( new float[] { 1.0f, 0.0f, 0.0f, -1.0f,
100 0.0f, 1.0f, 0.0f, -2.0f,
101 0.0f, 0.0f, 1.0f, -3.0f,
102 0.0f, 0.0f, 0.0f, 1.0f } );
103
104 @Test
105 public void test00MatrixToString() {
106 final String s4x4Cflu = translated123C.toString(null, null, "%10.5f").toString();
107 final String s4x4Rflu = translated123R.toString(null, null, "%10.5f").toString();
108 System.err.println("FLU-C-O 4x4: ");
109 System.err.println(s4x4Cflu);
110 System.err.println();
111 System.err.println("FLU-R-O 4x4: ");
112 System.err.println(s4x4Rflu);
113 System.err.println();
114
115 final String s2x3Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3R, 0, 2, 3, true).toString();
116 final String s2x3Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix2x3C, 0, 2, 3, false).toString();
117 System.err.println("FLU-R-O 2x3: ");
118 System.err.println(s2x3Rflu);
119 System.err.println();
120 System.err.println("FLU-C-O 2x3: ");
121 System.err.println(s2x3Cflu);
122 System.err.println();
123 Assert.assertEquals(s2x3Cflu, s2x3Rflu);
124
125 final String s3x2Rflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2R, 0, 3, 2, true).toString();
126 final String s3x2Cflu = FloatUtil.matrixToString(null, null, "%10.5f", matrix3x2C, 0, 3, 2, false).toString();
127 System.err.println("FLU-R-O 3x2: ");
128 System.err.println(s3x2Rflu);
129 System.err.println();
130 System.err.println("FLU-C-O 3x2: ");
131 System.err.println(s3x2Cflu);
132 System.err.println();
133 Assert.assertEquals(s3x2Cflu, s3x2Rflu);
134 }
135
136 /**
137 * Test using traditional access workflow, i.e. 1) operation 2) get-matrix references
138 * <p>
139 * No Mvi nor Mvit being used.
140 * </p>
141 */
142 @Test
144 Matrix4f p, mv;
145 final PMVMatrix pmv = new PMVMatrix();
146 System.err.println("test01a.P0: "+pmv.toString());
147
148 Assert.assertEquals(0, pmv.getReqBits());
149 Assert.assertEquals(false, pmv.isReqDirty());
150 Assert.assertTrue(0 != pmv.getDirtyBits());
151 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
152
153 //
154 // Action #0
155 //
156 final Matrix4f ident;
157 {
159 pmv.glLoadIdentity();
160 ident = pmv.getP();
161
163 pmv.glLoadIdentity();
164 }
165 Assert.assertTrue(0 != pmv.getModifiedBits(true)); // clear & test
166 Assert.assertTrue(0 == pmv.getModifiedBits(false)); // clear & test
167 Assert.assertTrue(0 != pmv.getDirtyBits());
168 Assert.assertEquals(false, pmv.isReqDirty());
169 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
170
171 //
172 // Action #1
173 //
174 pmv.glTranslatef(1f, 2f, 3f); // all dirty !
175 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
176 Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits());
177 System.err.println("test01a.P1: "+pmv.toString());
178
179 Assert.assertEquals(false, pmv.isReqDirty());
180 Assert.assertTrue(0 != pmv.getDirtyBits());
181 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
182 Assert.assertEquals("Update has been perfomed, but non requested", false, pmv.update()); // nothing has been requested
183 // System.err.println("P2: "+pmv.toString());
184
185 //
186 // Get
187 //
188 p = pmv.getP();
189 MiscUtils.assertMatrix4fEquals("P not identity, "+pmv.toString(), ident, p, epsilon);
190 mv = pmv.getMv();
191 MiscUtils.assertMatrix4fEquals("Mv not translated123, "+pmv.toString(), translated123C, mv, epsilon);
192 {
193 IllegalArgumentException e = null;
194 try {
195 pmv.getMvi();
196 } catch(final IllegalArgumentException iae) {
197 e = iae;
198 }
199 Assert.assertNotNull(e);
200 }
201 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
202 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
203 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
204 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
205 Assert.assertEquals(0, pmv.getDirtyBits());
206 // System.err.println("P3: "+pmv.toString());
207
208 //
209 // Action #2
210 //
211 pmv.glLoadIdentity(); // all dirty
212 Assert.assertTrue(0 != pmv.getModifiedBits(true)); // clear & test
213 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
214 System.err.println("test01a.PX: "+pmv.toString());
215 }
216
217 /**
218 * Test using traditional access workflow, i.e. 1) operation 2) get-matrix references
219 * <p>
220 * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated.
221 * </p>
222 */
223 @Test
225 Matrix4f p, mv, mvi, mvit;
227 System.err.println("test01b.P0: "+pmv.toString());
228
230 Assert.assertTrue(0 != pmv.getDirtyBits());
231 Assert.assertEquals(true, pmv.isReqDirty());
233
234 Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits());
235 Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix4f.INVERSE_MODELVIEW | PMVMatrix4f.INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
236
237 //
238 // Action #0
239 //
240 final Matrix4f ident;
241 {
243 pmv.glLoadIdentity();
244 ident = pmv.getP();
245
247 pmv.glLoadIdentity();
248 }
249 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
250 Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits());
251 Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix4f.INVERSE_MODELVIEW|PMVMatrix4f.INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
252
253 //
254 // Action #1
255 //
256 pmv.glTranslatef(1f, 2f, 3f); // all dirty !
257 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
258 Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits());
259 Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix4f.INVERSE_MODELVIEW|PMVMatrix4f.INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
260 System.err.println("test01b.P1: "+pmv.toString());
261
263 Assert.assertEquals(true, pmv.isReqDirty());
264 Assert.assertEquals(true, pmv.update());
265 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
266 Assert.assertEquals(false, pmv.isReqDirty());
267 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
268 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
269 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
270 Assert.assertEquals(0, pmv.getDirtyBits());
271 Assert.assertEquals(false, pmv.isReqDirty());
272 // System.err.println("P2: "+pmv.toString());
273
274 //
275 // Get
276 //
277 p = pmv.getP();
278 MiscUtils.assertMatrix4fEquals("P not identity, "+pmv.toString(), ident, p, epsilon);
279 mv = pmv.getMv();
280 MiscUtils.assertMatrix4fEquals("Mv not translated123, "+pmv.toString(), translated123C, mv, epsilon);
281 mvi = pmv.getMvi();
282 MiscUtils.assertMatrix4fEquals("Mvi not translated123, "+pmv.toString(), translated123I, mvi, epsilon);
283 Assert.assertEquals(0, pmv.getDirtyBits());
284 Assert.assertEquals(false, pmv.isReqDirty());
285
286 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
287 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
288 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
289 Assert.assertEquals(0, pmv.getDirtyBits());
290 Assert.assertEquals(false, pmv.isReqDirty());
291 // System.err.println("P3: "+pmv.toString());
292
293 mvit = pmv.getMvit();
294 MiscUtils.assertMatrix4fEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon);
295 Assert.assertEquals(0, pmv.getDirtyBits());
296 Assert.assertEquals(false, pmv.isReqDirty());
297 // System.err.println("P4: "+pmv.toString());
298
299 //
300 // Action #2
301 //
302 pmv.glLoadIdentity(); // all dirty
303 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
304 Assert.assertTrue(0 != pmv.getDirtyBits());
305 Assert.assertEquals(true, pmv.isReqDirty());
307 System.err.println("test01b.P2: "+pmv.toString());
308 MiscUtils.assertMatrix4fEquals("P not identity, "+pmv.toString(), ident, p, epsilon);
309 MiscUtils.assertMatrix4fEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon);
310 MiscUtils.assertMatrix4fNotEqual("Mvi already identity w/o update, "+pmv.toString(), ident, mvi, epsilon);
311 MiscUtils.assertMatrix4fNotEqual("Mvit already identity w/o update, "+pmv.toString(), ident, mvit, epsilon);
312 MiscUtils.assertMatrix4fEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon);
313 MiscUtils.assertMatrix4fEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon);
314
315 Assert.assertEquals(true, pmv.update());
316 Assert.assertTrue(0 != pmv.getDirtyBits());
317 Assert.assertEquals(false, pmv.isReqDirty());
318 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
319
320 MiscUtils.assertMatrix4fEquals("Mvi not identity after update, "+pmv.toString(), ident, mvi, epsilon);
321 MiscUtils.assertMatrix4fEquals("Mvit not identity after update, "+pmv.toString(), ident, mvit, epsilon);
322
323 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
324 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
325 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
326 Assert.assertEquals(0, pmv.getDirtyBits());
327 Assert.assertEquals(false, pmv.isReqDirty());
328 System.err.println("test01b.PX: "+pmv.toString());
329 }
330
331 /**
332 * Test using shader access workflow, i.e. 1) get-matrix references 2) operations
333 * <p>
334 * The Mvi, Mvit and Frustum dirty-bits and request-mask will be validated.
335 * </p>
336 */
337 @Test
339 final Matrix4f p, mv, mvi, mvit;
341 // System.err.println("P0: "+pmv.toString());
342
344 Assert.assertTrue(0 != pmv.getDirtyBits());
345 Assert.assertEquals(true, pmv.isReqDirty());
347
348 //
349 // Action #0
350 //
351 final Matrix4f ident;
352 {
354 pmv.glLoadIdentity();
355 ident = pmv.getP();
356
358 pmv.glLoadIdentity();
359 }
360 // System.err.println("P0: "+pmv.toString());
361 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
362
364 Assert.assertEquals(true, pmv.isReqDirty());
365 Assert.assertEquals(true, pmv.update());
366 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
367 Assert.assertEquals(false, pmv.isReqDirty());
368 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
369 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
370 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
371 Assert.assertEquals(0, pmv.getDirtyBits());
372 Assert.assertEquals(false, pmv.isReqDirty());
373 // System.err.println("P1: "+pmv.toString());
374
375 //
376 // Get
377 //
378 p = pmv.getP();
379 MiscUtils.assertMatrix4fEquals("P not identity, "+pmv.toString(), ident, p, epsilon);
380 mv = pmv.getMv();
381 MiscUtils.assertMatrix4fEquals("Mv not identity, "+pmv.toString(), ident, mv, epsilon);
382 Assert.assertEquals(0, pmv.getDirtyBits());
383 Assert.assertEquals(false, pmv.isReqDirty());
384
385 mvi = pmv.getMvi();
386 MiscUtils.assertMatrix4fEquals("Mvi not identity, "+pmv.toString(), ident, mvi, epsilon);
387 Assert.assertEquals(0, pmv.getDirtyBits());
388 Assert.assertEquals(false, pmv.isReqDirty());
389
390 mvit = pmv.getMvit();
391 MiscUtils.assertMatrix4fEquals("Mvi not identity, "+pmv.toString(), ident, mvit, epsilon);
392 Assert.assertEquals(0, pmv.getDirtyBits());
393 Assert.assertEquals(false, pmv.isReqDirty());
394
395 //
396 // Action #1
397 //
398 pmv.glTranslatef(1f, 2f, 3f); // all dirty !
399 Assert.assertTrue("Modified bits zero", 0 != pmv.getModifiedBits(true)); // clear & test
400 Assert.assertTrue("Dirty bits clean, "+pmv.toString(), 0 != pmv.getDirtyBits());
401 Assert.assertEquals("Remaining dirty bits not Mvi|Mvit|Frustum, "+pmv.toString(), PMVMatrix4f.INVERSE_MODELVIEW|PMVMatrix4f.INVERSE_TRANSPOSED_MODELVIEW | PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
402 MiscUtils.assertMatrix4fEquals("P not identity, "+pmv.toString()+pmv.toString(), ident, p, epsilon);
403 MiscUtils.assertMatrix4fEquals("Mv not translated123, "+pmv.toString()+pmv.toString(), translated123C, mv, epsilon);
404 MiscUtils.assertMatrix4fNotEqual("Mvi already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon);
405 MiscUtils.assertMatrix4fNotEqual("Mvit already translated123 w/o update, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon);
406 MiscUtils.assertMatrix4fEquals("Mvi not identity, "+pmv.toString()+pmv.toString(), ident, mvi, epsilon);
407 MiscUtils.assertMatrix4fEquals("Mvit not identity, "+pmv.toString()+pmv.toString(), ident, mvit, epsilon);
408
410 Assert.assertEquals(true, pmv.isReqDirty());
411 Assert.assertEquals(true, pmv.update()); // will clean dirty bits, since all requests has been made -> true
412 Assert.assertEquals(PMVMatrix4f.MANUAL_BITS, pmv.getDirtyBits());
413 Assert.assertEquals(false, pmv.isReqDirty());
414 Assert.assertNotNull(pmv.getFrustum()); // FIXME: Test Frustum value!
415 Assert.assertNotNull(pmv.getPMv()); // FIXME: Test value!
416 Assert.assertNotNull(pmv.getPMvi()); // FIXME: Test value!
417 Assert.assertEquals(0, pmv.getDirtyBits());
418 Assert.assertEquals(false, pmv.isReqDirty());
419 MiscUtils.assertMatrix4fEquals("Mvi not translated123, "+pmv.toString()+pmv.toString(), translated123I, mvi, epsilon);
420 MiscUtils.assertMatrix4fEquals("Mvit not translated123, "+pmv.toString()+pmv.toString(), translated123IT, mvit, epsilon);
421 // System.err.println("P2: "+pmv.toString());
422 }
423
424 @Test
425 public void test10MvTranslate() {
426 final Matrix4f pmvMv = new Matrix4f();
427 // final Matrix4f pmvMvi, pmvMvit;
428 {
429 final PMVMatrix pmv = new PMVMatrix();
431 pmv.glLoadIdentity();
433 pmv.glLoadIdentity();
434 pmv.glTranslatef(5f, 6f, 7f);
435
436 pmvMv.load(pmv.getMv());
437 // pmvMvi = pmv.glGetMviMatrixf();
438 // pmvMvit = pmv.glGetMvitMatrixf();
439 }
440
441 final FloatBuffer glMv = FloatBuffer.allocate(16);
442 {
443 final GL2ES1 gl = dc.glc.getGL().getGL2ES1();
445 gl.glLoadIdentity();
447 gl.glLoadIdentity();
448 gl.glTranslatef(5f, 6f, 7f);
449
451 }
452 final Matrix4f glMvMat = new Matrix4f(glMv);
453
454 // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString());
455
456 MiscUtils.assertMatrix4fEquals("Arrays not equal, expected"+PlatformPropsImpl.NEWLINE+glMvMat+
457 ", actual"+PlatformPropsImpl.NEWLINE+pmvMv,
458 glMvMat, pmvMv, epsilon);
459
460 // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi));
461 // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit));
462 }
463
464 @Test
466 final Matrix4f pmvMv = new Matrix4f();
467 // final Matrix4f pmvMvi, pmvMvit;
468 {
469 final PMVMatrix pmv = new PMVMatrix();
471 pmv.glLoadIdentity();
473 pmv.glLoadIdentity();
474 pmv.glTranslatef(5f, 6f, 7f);
475 pmv.glRotatef(90f, 1f, 0f, 0f);
476
477 pmvMv.load(pmv.getMv());
478 // pmvMvi = pmv.glGetMviMatrixf();
479 // pmvMvit = pmv.glGetMvitMatrixf();
480 }
481
482 final FloatBuffer glMv = FloatBuffer.allocate(16);
483 {
484 final GL2ES1 gl = dc.glc.getGL().getGL2ES1();
486 gl.glLoadIdentity();
488 gl.glLoadIdentity();
489 gl.glTranslatef(5f, 6f, 7f);
490 gl.glRotatef(90f, 1f, 0f, 0f);
491
493 }
494 final Matrix4f glMvMat = new Matrix4f(glMv);
495 // System.err.println(PMVMatrix.matrixToString(null, "%10.5f", glMv, pmvMv).toString());
496
497 MiscUtils.assertMatrix4fEquals("Arrays not equal, expected"+PlatformPropsImpl.NEWLINE+glMvMat+
498 ", actual"+PlatformPropsImpl.NEWLINE+pmvMv,
499 glMvMat, pmvMv, epsilon);
500
501 // System.err.println("pmvMvi: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvi));
502 // System.err.println("pmvMvit: "+Platform.NEWLINE+PMVMatrix.matrixToString(null, "%10.5f", pmvMvit));
503 }
504
505 static DrawableContext dc;
506
507 @BeforeClass
508 public static void setup() throws Throwable {
509 try {
510 dc = createOffscreenDrawableAndCurrentFFPContext();
511 } catch (final Throwable t) {
512 setTestSupported(false);
513 throw t;
514 }
515 }
516
517 @AfterClass
518 public static void cleanup() {
519 destroyDrawableContext(dc);
520 }
521
522 static class DrawableContext {
523 DrawableContext(final GLDrawable d, final GLContext glc) {
524 this.d = d;
525 this.glc = glc;
526 }
527 GLDrawable d;
528 GLContext glc;
529 }
530
531 private static DrawableContext createOffscreenDrawableAndCurrentFFPContext() throws Throwable {
532 final GLProfile glp = GLProfile.getMaxFixedFunc(true);
533 final GLCapabilities glCaps = new GLCapabilities(glp);
534 glCaps.setOnscreen(false);
535 glCaps.setPBuffer(true);
537 final GLDrawable d = factory.createOffscreenDrawable(null, glCaps, null, 64, 64);
538 d.setRealized(true);
539 GLContext glc = null;
540 try {
541 glc = d.createContext(null);
542 Assert.assertTrue("Context could not be made current", GLContext.CONTEXT_NOT_CURRENT < glc.makeCurrent());
543 return new DrawableContext(d, glc);
544 } catch (final Throwable t) {
545 if(null != glc) {
546 glc.destroy();
547 }
548 d.setRealized(false);
549 throw t;
550 }
551 }
552
553 private static void destroyDrawableContext(final DrawableContext dc) {
554 if(null != dc.glc) {
555 dc.glc.destroy();
556 dc.glc = null;
557 }
558 if(null != dc.d) {
559 dc.d.setRealized(false);
560 dc.d = null;
561 }
562 }
563
564 public static void main(final String args[]) {
565 org.junit.runner.JUnitCore.main(TestPMVMatrix01NEWT.class.getName());
566 }
567}
Basic Float math utility functions.
Definition: FloatUtil.java:83
static StringBuilder matrixToString(StringBuilder sb, final String rowPrefix, final String f, final FloatBuffer a, final int aOffset, final int rows, final int columns, final boolean rowMajorOrder)
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
Definition: Matrix4f.java:89
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
Definition: Matrix4f.java:186
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
Definition: Matrix4f.java:2085
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final int getReqBits()
Returns the request bit mask, which uses bit values equal to the dirty mask and may contain.
static final int MANUAL_BITS
Manual bits not covered by update() but getFrustum(), FRUSTUM, getPMv(), PREMUL_PMV,...
final Matrix4f getMvi()
Returns the inverse modelview matrix (Mvi) if requested.
final int getDirtyBits()
Returns the dirty bits due to mutable operations, i.e.
final int getModifiedBits(final boolean clear)
Returns the modified bits due to mutable operations.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
StringBuilder toString(StringBuilder sb, final String f)
static final int INVERSE_TRANSPOSED_MODELVIEW
Bit value for inverse transposed modelview matrix (Mvit), updated via update().
final Matrix4f getPMv()
Returns the pre-multiplied projection x modelview, P x Mv.
static final int INVERSE_MODELVIEW
Bit value for inverse modelview matrix (Mvi), updated via update().
final boolean update()
Update the derived inverse modelview (Mvi), inverse transposed modelview (Mvit) matrices if they are ...
final Frustum getFrustum()
Returns the frustum, derived from projection x modelview.
final Matrix4f getP()
Returns the projection matrix (P).
final Matrix4f getPMvi()
Returns the pre-multiplied inverse projection x modelview, if Matrix4f#invert(Matrix4f) succeeded,...
final boolean isReqDirty()
Returns true if the one of the requested bits are are set dirty due to mutable operations,...
final Matrix4f getMvit()
Returns the inverse transposed modelview matrix (Mvit) if requested.
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
static final int CONTEXT_NOT_CURRENT
Indicates that the context was not made current during the last call to makeCurrent,...
Definition: GLContext.java:112
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract void destroy()
Destroys this OpenGL context and frees its associated resources.
abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates an unrealized offscreen GLDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
void test01bTraditionalAccess()
Test using traditional access workflow, i.e.
void test02MviUpdateShaderAccess()
Test using shader access workflow, i.e.
void test01aTraditionalAccess()
Test using traditional access workflow, i.e.
static void assertMatrix4fEquals(final Matrix4f expected, final Matrix4f actual, final float delta)
Definition: MiscUtils.java:154
static void assertMatrix4fNotEqual(final String errmsg, final Matrix4f expected, final Matrix4f actual, final float delta)
Definition: MiscUtils.java:177
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
Definition: PMVMatrix.java:62
final void glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
Definition: PMVMatrix.java:379
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
Definition: PMVMatrix.java:218
final void glRotatef(final float ang_deg, final float x, final float y, final float z)
Rotate the current matrix.
Definition: PMVMatrix.java:413
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Definition: PMVMatrix.java:325
GL getGL()
Casts this object to the GL interface.
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...
void glGetFloatv(int pname, FloatBuffer data)
Entry point to C language function: void {@native glGetFloatv}(GLenum pname, GLfloat * data) Part ...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
static final int GL_MODELVIEW_MATRIX
Matrix access name for modelview.
void glRotatef(float angle, float x, float y, float z)
Rotate the current matrix.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.