29package com.jogamp.opengl.test.junit.math;
31import java.nio.FloatBuffer;
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;
44import jogamp.common.os.PlatformPropsImpl;
46import org.junit.AfterClass;
47import org.junit.Assert;
48import org.junit.BeforeClass;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
53import com.jogamp.opengl.test.junit.util.MiscUtils;
54import com.jogamp.opengl.test.junit.util.UITestCase;
55import com.jogamp.opengl.util.PMVMatrix;
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static final float epsilon = 0.00001f;
63 static FloatBuffer matrix2x3R = FloatBuffer.wrap(
new float[] { 1.0f, 2.0f, 3.0f,
67 static FloatBuffer matrix2x3C = FloatBuffer.wrap(
new float[] { 1.0f, 4.0f,
72 static FloatBuffer matrix3x2R = FloatBuffer.wrap(
new float[] { 1.0f, 2.0f,
77 static FloatBuffer matrix3x2C = FloatBuffer.wrap(
new float[] { 1.0f, 3.0f, 5.0f,
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 } );
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 } );
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 } );
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 } );
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();
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);
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);
146 System.err.println(
"test01a.P0: "+pmv.
toString());
175 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
177 System.err.println(
"test01a.P1: "+pmv.
toString());
182 Assert.assertEquals(
"Update has been perfomed, but non requested",
false, pmv.
update());
193 IllegalArgumentException e =
null;
196 }
catch(
final IllegalArgumentException iae) {
199 Assert.assertNotNull(e);
203 Assert.assertNotNull(pmv.
getPMv());
204 Assert.assertNotNull(pmv.
getPMvi());
214 System.err.println(
"test01a.PX: "+pmv.
toString());
227 System.err.println(
"test01b.P0: "+pmv.
toString());
249 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
257 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
260 System.err.println(
"test01b.P1: "+pmv.
toString());
264 Assert.assertEquals(
true, pmv.
update());
268 Assert.assertNotNull(pmv.
getPMv());
269 Assert.assertNotNull(pmv.
getPMvi());
287 Assert.assertNotNull(pmv.
getPMv());
288 Assert.assertNotNull(pmv.
getPMvi());
303 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
307 System.err.println(
"test01b.P2: "+pmv.
toString());
315 Assert.assertEquals(
true, pmv.
update());
324 Assert.assertNotNull(pmv.
getPMv());
325 Assert.assertNotNull(pmv.
getPMvi());
328 System.err.println(
"test01b.PX: "+pmv.
toString());
361 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
365 Assert.assertEquals(
true, pmv.
update());
369 Assert.assertNotNull(pmv.
getPMv());
370 Assert.assertNotNull(pmv.
getPMvi());
399 Assert.assertTrue(
"Modified bits zero", 0 != pmv.
getModifiedBits(
true));
411 Assert.assertEquals(
true, pmv.
update());
415 Assert.assertNotNull(pmv.
getPMv());
416 Assert.assertNotNull(pmv.
getPMvi());
441 final FloatBuffer glMv = FloatBuffer.allocate(16);
457 ", actual"+PlatformPropsImpl.NEWLINE+pmvMv,
458 glMvMat, pmvMv, epsilon);
482 final FloatBuffer glMv = FloatBuffer.allocate(16);
498 ", actual"+PlatformPropsImpl.NEWLINE+pmvMv,
499 glMvMat, pmvMv, epsilon);
505 static DrawableContext dc;
508 public static void setup() throws Throwable {
510 dc = createOffscreenDrawableAndCurrentFFPContext();
511 }
catch (
final Throwable t) {
512 setTestSupported(
false);
519 destroyDrawableContext(dc);
522 static class DrawableContext {
531 private static DrawableContext createOffscreenDrawableAndCurrentFFPContext() throws Throwable {
543 return new DrawableContext(d, glc);
544 }
catch (
final Throwable t) {
553 private static void destroyDrawableContext(
final DrawableContext dc) {
559 dc.d.setRealized(
false);
564 public static void main(
final String args[]) {
Basic Float math utility functions.
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).
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
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.
static final int CONTEXT_NOT_CURRENT
Indicates that the context was not made current during the last call to makeCurrent,...
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.
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
void test01bTraditionalAccess()
Test using traditional access workflow, i.e.
void test02MviUpdateShaderAccess()
Test using shader access workflow, i.e.
void test00MatrixToString()
static void main(final String args[])
void test11MvTranslateRotate()
void test01aTraditionalAccess()
Test using traditional access workflow, i.e.
static void assertMatrix4fEquals(final Matrix4f expected, final Matrix4f actual, final float delta)
static void assertMatrix4fNotEqual(final String errmsg, final Matrix4f expected, final Matrix4f actual, final float delta)
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void glRotatef(final float ang_deg, final float x, final float y, final float z)
Rotate the current matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
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.
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.