28package com.jogamp.opengl.test.junit.jogl.acore;
30import com.jogamp.common.nio.Buffers;
31import com.jogamp.opengl.util.GLPixelStorageModes;
32import com.jogamp.opengl.test.junit.util.NEWTGLContext;
33import com.jogamp.opengl.test.junit.util.UITestCase;
35import java.io.IOException;
36import java.nio.ByteBuffer;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GL2ES2;
40import com.jogamp.opengl.GL2GL3;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLDrawable;
43import com.jogamp.opengl.GLException;
44import com.jogamp.opengl.GLProfile;
46import org.junit.Assert;
48import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 static String hexString(
final int i) {
54 return "0x"+Integer.toHexString(i);
56 static String exceptionMsg(
final String pre,
final int format,
final int type,
final int components,
final int width,
final int height,
final int rl1,
final int rl4,
final int rl8) {
58 ": fmt "+hexString(format)+
", type "+hexString(type)+
", comps "+components+
59 ", "+width+
"x"+height+
60 ", rowlenA1 "+rl1+
", rowlenA4 "+rl4+
", rowlenA8 "+rl8;
63 static NEWTGLContext.WindowContext createCurrentGLOffscreenWindow(
final GLProfile glp,
final int width,
final int height)
throws GLException, InterruptedException {
67 caps, width, height,
true);
68 final GL gl = winctx.context.
getGL();
85 static int readPixelsCheck(
final GL gl,
final int format,
final int type,
final int components,
final int width,
final int height)
throws InterruptedException {
86 int expectedExceptions = 0;
88 final int rowlenA1 = width * components;
90 final int rowlenA4 = ( ( width * components + 3 ) / 4 ) * 4 ;
91 Assert.assertTrue(rowlenA4 % 4 == 0);
93 final int rowlenA8 = ( ( width * components + 7 ) / 8 ) * 8 ;
94 Assert.assertTrue(rowlenA8 % 8 == 0);
103 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1);
106 }
catch(
final IndexOutOfBoundsException e) {
110 exceptionMsg(
"Unexpected IndexOutOfBoundsException (size ok, alignment 1)",
111 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
117 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1-10);
120 }
catch(
final IndexOutOfBoundsException e) {
123 exceptionMsg(
"OK Expected IndexOutOfBoundsException (size-10 bytes)",
124 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+
125 ": "+ee.getMessage());
126 expectedExceptions++;
128 Assert.assertNotNull(
129 exceptionMsg(
"Expected IndexOutOfBoundsException (size-10 bytes)",
130 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
135 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1/4);
138 }
catch(
final IndexOutOfBoundsException e) {
141 exceptionMsg(
"OK Expected IndexOutOfBoundsException (size/4 bytes)",
142 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+
143 ": "+ee.getMessage());
144 expectedExceptions++;
146 Assert.assertNotNull(
147 exceptionMsg(
"Expected IndexOutOfBoundsException (size/4 bytes)",
148 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
158 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA4);
161 }
catch(
final IndexOutOfBoundsException e) {
165 exceptionMsg(
"Unexpected IndexOutOfBoundsException (size ok, alignment 4)",
166 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
171 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1);
174 }
catch(
final IndexOutOfBoundsException e) {
178 exceptionMsg(
"OK Expected IndexOutOfBoundsException (alignment 4)",
179 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+
180 ": "+ee.getMessage());
181 expectedExceptions++;
185 Assert.assertNotNull(
186 exceptionMsg(
"Expected IndexOutOfBoundsException (alignment 4)",
187 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
190 exceptionMsg(
"Unexpected IndexOutOfBoundsException (alignment 4)",
191 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
199 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA8);
202 }
catch(
final IndexOutOfBoundsException e) {
206 exceptionMsg(
"Unexpected IndexOutOfBoundsException (size ok, alignment 8)",
207 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
212 final ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1);
215 }
catch(
final IndexOutOfBoundsException e) {
219 exceptionMsg(
"OK Expected IndexOutOfBoundsException (alignment 8)",
220 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+
221 ": "+ee.getMessage());
222 expectedExceptions++;
226 Assert.assertNotNull(
227 exceptionMsg(
"Expected IndexOutOfBoundsException (alignment 8)",
228 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
231 exceptionMsg(
"Unexpected IndexOutOfBoundsException (alignment 8)",
232 format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee);
238 return expectedExceptions;
244 final int width = 640;
245 final int height= 480;
248 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height);
249 final GLDrawable drawable = winctx.context.getGLDrawable();
250 final GL gl = winctx.context.
getGL();
264 final int wwidth = 640;
265 final int wheight= 480;
266 final int rwidth = 99;
267 final int rheight= 100;
270 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight);
271 final GLDrawable drawable = winctx.context.getGLDrawable();
272 final GL gl = winctx.context.
getGL();
287 System.err.println(
"GL2ES3 n/a skip test");
290 final int width = 640;
291 final int height= 480;
294 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height);
295 final GLDrawable drawable = winctx.context.getGLDrawable();
296 final GL gl = winctx.context.
getGL();
311 System.err.println(
"GL2ES3 n/a skip test");
314 final int wwidth = 640;
315 final int wheight= 480;
316 final int rwidth = 99;
317 final int rheight= 100;
320 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight);
321 final GLDrawable drawable = winctx.context.getGLDrawable();
322 final GL gl = winctx.context.
getGL();
337 System.err.println(
"GL2ES3 n/a skip test");
340 final int width = 640;
341 final int height= 480;
344 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height);
345 final GLDrawable drawable = winctx.context.getGLDrawable();
361 System.err.println(
"GL2ES3 n/a skip test");
364 final int wwidth = 640;
365 final int wheight= 480;
366 final int rwidth = 102;
367 final int rheight= 100;
370 final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight);
371 final GLDrawable drawable = winctx.context.getGLDrawable();
383 public static void main(
final String args[])
throws IOException {
385 org.junit.runner.JUnitCore.
main(tstname);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
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 GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
final boolean isGL2ES3()
Indicates whether this profile is capable of GL2ES3.
void testReadPixelsGL2GL3_640x480xRGBxUB()
void testReadPixelsGL2GL3_99x100xRGBxUB()
void testReadPixelsGL_640x480xRGBAxUB()
static void main(final String args[])
void testReadPixelsGL2GL3_640x480xREDxUB()
void testReadPixelsGL2GL3_102x100xREDxUB()
void testReadPixelsGL_99x100xRGBxUB()
static WindowContext createWindow(final GLCapabilities caps, final int width, final int height, final boolean debugGL)
static void destroyWindow(final WindowContext winctx)
Utility to safely set and restore the PACK and UNPACK pixel storage mode, regardless of the GLProfile...
final void restore(final GL gl)
Restores PACK and UNPACK pixel storage mode previously saved w/ saveAll(GL) or savePack(GL) and saveU...
final void setPackAlignment(final GL gl, final int packAlignment)
Sets the GL#GL_PACK_ALIGNMENT.
static final int GL_RED
GL_ES_VERSION_3_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_NV_blend_equation_advanced, GL_EXT_texture_rg A...
GL getGL()
Casts this object to the GL interface.
GL2GL3 getGL2GL3()
Casts this object to the GL2GL3 interface.
An abstraction for an OpenGL rendering target.
void swapBuffers()
Swaps the front and back buffers of this drawable.
void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glReadPixels}(GLint x, GLint y,...
static final int GL_RGB
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGB" with expression ...
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 glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
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_RGBA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGBA" with expression...
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...
static final int GL_UNSIGNED_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_BYTE" with e...