29package com.jogamp.opengl.test.junit.jogl.acore;
31import com.jogamp.opengl.GL;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLCapabilitiesImmutable;
34import com.jogamp.opengl.GLContext;
35import com.jogamp.opengl.GLDrawableFactory;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLFBODrawable;
38import com.jogamp.opengl.GLOffscreenAutoDrawable;
39import com.jogamp.opengl.GLProfile;
41import org.junit.Assert;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
46import com.jogamp.opengl.FBObject;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.FBOMix2DemosES2;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.MultisampleDemoES2;
50import com.jogamp.opengl.test.junit.util.GLTestUtil;
51import com.jogamp.opengl.test.junit.util.UITestCase;
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66 static final int widthStep = 800/4;
67 static final int heightStep = 600/4;
68 volatile int szStep = 2;
71 void setMakeSnapshot();
86 testGLFBODrawableImpl(caps, 0,
new GearsES2(0));
94 testGLFBODrawableImpl(caps, 0,
new GearsES2(0));
149 System.err.println(
"EGL ES2 n/a");
162 System.err.println(
"EGL ES2 n/a");
173 System.err.println(
"GL3 n/a");
182 Assert.assertNotNull(glad);
184 System.out.println(
"Requested: "+caps);
185 System.out.println(
"Realized GLAD: "+glad);
186 System.out.println(
"Realized GLAD: "+glad.getChosenGLCapabilities());
187 Assert.assertTrue(
"FBO drawable is initialized before ctx creation", !glad.isInitialized());
188 glad.setFBOMode(fboMode);
192 final GLContext context = glad.getContext();
193 Assert.assertNotNull(context);
196 Assert.assertTrue(
"FBO drawable is not initialized after ctx creation", glad.isInitialized());
198 final boolean expDepth = caps.getDepthBits() > 0;
199 final boolean reqDepth = glad.getRequestedGLCapabilities().getDepthBits() > 0;
200 final boolean hasDepth = glad.getChosenGLCapabilities().getDepthBits() > 0;
201 System.out.println(
"Depth: exp "+expDepth+
", req "+reqDepth+
", has "+hasDepth);
202 Assert.assertEquals(
"Depth: expected not passed to requested", expDepth, reqDepth);
203 Assert.assertEquals(
"Depth: requested not passed to chosen", reqDepth, hasDepth);
210 System.out.println(
"Init GLAD: "+glad);
211 System.out.println(
"Init GLAD: "+chosenCaps);
216 System.out.println(
"Init front FBO: "+fboFront);
217 System.out.println(
"Init back FBO: "+fboBack);
219 Assert.assertTrue(
"FBO drawable is not initialized before ctx creation", glad.isInitialized());
220 Assert.assertTrue(
"FBO Front is not initialized before ctx creation", fboFront.
isInitialized());
221 Assert.assertTrue(
"FBO Back is not initialized before ctx creation", fboBack.
isInitialized());
224 Assert.assertNotEquals(
"FBO are equal: "+fboFront+
" == "+fboBack, fboFront, fboBack);
225 Assert.assertNotSame(fboFront, fboBack);
227 Assert.assertEquals(
"FBO are not equal: "+fboFront+
" != "+fboBack, fboFront, fboBack);
228 Assert.assertSame(fboFront, fboBack);
231 final FBObject.Colorbuffer color0, color1;
234 if(0==glad.getNumSamples()) {
235 color1 = glad.getColorbuffer(
GL.
GL_BACK);
240 final boolean expTexture = 0 != ( GLFBODrawable.FBOMODE_USE_TEXTURE & glad.getFBOMode() );
241 System.out.println(
"Texture: exp "+expTexture+
", hasFront "+color0.isTextureAttachment());
242 Assert.assertEquals(
"Texture: Front", expTexture, color0.isTextureAttachment());
243 if(0==glad.getNumSamples()) {
244 Assert.assertEquals(
"Texture: Back", expTexture, color1.isTextureAttachment());
247 final FBObject.Colorbuffer colorA, colorB;
248 final FBObject.RenderAttachment depthA, depthB;
251 Assert.assertNotNull(colorA);
253 Assert.assertNotNull(colorB);
255 Assert.assertEquals(
"Texture: Front", expTexture, colorA.isTextureAttachment());
256 if(0==glad.getNumSamples()) {
257 Assert.assertEquals(
"Texture: Back", expTexture, colorB.isTextureAttachment());
259 Assert.assertEquals(
"Texture: MSAA Back is Texture",
false, colorB.isTextureAttachment());
264 Assert.assertNotNull(depthA);
266 Assert.assertNotNull(depthB);
276 Assert.assertNotEquals(
"Color attachments are equal: "+colorB+
" == "+colorA, colorA, colorB);
277 Assert.assertNotSame(colorB, colorA);
279 Assert.assertNotEquals(
"Depth attachments are equal: "+depthB+
" == "+depthA, depthA, depthB);
280 Assert.assertNotSame(depthB, depthA);
284 Assert.assertEquals(colorA, colorB);
285 Assert.assertSame(colorA, colorB);
286 Assert.assertEquals(depthA, depthB);
287 Assert.assertSame(depthA, depthB);
290 Assert.assertEquals(color0, colorA);
291 Assert.assertSame(color0, colorA);
292 if(0==glad.getNumSamples()) {
293 Assert.assertEquals(color1, colorB);
294 Assert.assertSame(color1, colorB);
299 final FBObject _fboFront = glad.getFBObject(GL.GL_FRONT);
300 final FBObject _fboBack = glad.getFBObject(GL.GL_BACK);
301 Assert.assertEquals(
"FBO are not equal: "+fboFront+
" != "+_fboFront, fboFront, _fboFront);
302 Assert.assertSame(fboFront, _fboFront);
303 Assert.assertEquals(
"FBO are not equal: "+fboBack+
" != "+_fboBack, fboBack, _fboBack);
304 Assert.assertSame(fboBack, _fboBack);
307 final FBObject _fboFront = glad.getFBObject(GL.GL_FRONT);
308 final FBObject _fboBack = glad.getFBObject(GL.GL_BACK);
309 Assert.assertEquals(
"FBO are not equal: "+fboBack+
" != "+_fboFront, fboBack, _fboFront);
310 Assert.assertSame(fboBack, _fboFront);
311 Assert.assertEquals(
"FBO are not equal: "+fboFront+
" != "+_fboBack, fboFront, _fboBack);
312 Assert.assertSame(fboFront, _fboBack);
315 final FBObject _fboFront = glad.getFBObject(GL.GL_FRONT);
316 final FBObject _fboBack = glad.getFBObject(GL.GL_BACK);
317 Assert.assertEquals(
"FBO are not equal: "+fboFront+
" != "+_fboFront, fboFront, _fboFront);
318 Assert.assertSame(fboFront, _fboFront);
319 Assert.assertEquals(
"FBO are not equal: "+fboBack+
" != "+_fboFront, fboBack, _fboFront);
320 Assert.assertSame(fboBack, _fboFront);
321 Assert.assertEquals(
"FBO are not equal: "+fboBack+
" != "+_fboBack, fboBack, _fboBack);
322 Assert.assertSame(fboBack, _fboBack);
323 Assert.assertEquals(
"FBO are not equal: "+fboFront+
" != "+_fboBack, fboFront, _fboBack);
324 Assert.assertSame(fboFront, _fboBack);
327 glad.addGLEventListener(demo);
329 final SnapshotGLEventListener snapshotGLEventListener =
new SnapshotGLEventListener();
330 glad.addGLEventListener(snapshotGLEventListener);
335 snapshotGLEventListener.setMakeSnapshot();
340 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
341 Assert.assertTrue(
"Size not reached: Expected "+(widthStep*szStep)+
"x"+(heightStep*szStep)+
", Is "+glad.getSurfaceWidth()+
"x"+glad.getSurfaceHeight(),
342 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep,
null));
343 snapshotGLEventListener.setMakeSnapshot();
348 final FBObject _fboFront = glad.getFBObject(GL.GL_FRONT);
349 final FBObject _fboBack = glad.getFBObject(GL.GL_BACK);
350 System.out.println(
"Resize1.oldFront: "+fboFront);
351 System.out.println(
"Resize1.nowFront: "+_fboFront);
352 System.out.println(
"Resize1.oldBack : "+fboBack);
353 System.out.println(
"Resize1.nowBack : "+_fboBack);
354 Assert.assertEquals(fboFront, _fboFront);
355 Assert.assertSame(fboFront, _fboFront);
356 Assert.assertEquals(fboBack, _fboBack);
357 Assert.assertSame(fboBack, _fboBack);
359 FBObject.Colorbuffer _color = _fboFront.getColorbuffer(0);
360 Assert.assertNotNull(_color);
361 Assert.assertEquals(colorA, _color);
362 Assert.assertSame(colorA, _color);
364 FBObject.RenderAttachment _depth = _fboFront.getDepthAttachment();
365 System.err.println(
"Resize1.oldDepth "+depthA);
366 System.err.println(
"Resize1.newDepth "+_depth);
368 Assert.assertNotNull(_depth);
371 Assert.assertEquals(depthA, _depth);
372 Assert.assertSame(depthA, _depth);
373 _depth = _fboBack.getDepthAttachment();
375 Assert.assertNotNull(_depth);
377 Assert.assertEquals(depthB, _depth);
378 Assert.assertSame(depthB, _depth);
380 _color = _fboFront.getColorbuffer(colorA);
381 Assert.assertNotNull(_color);
382 Assert.assertEquals(colorA, _color);
383 Assert.assertSame(colorA, _color);
388 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
389 Assert.assertTrue(
"Size not reached: Expected "+(widthStep*szStep)+
"x"+(heightStep*szStep)+
", Is "+glad.getSurfaceWidth()+
"x"+glad.getSurfaceHeight(),
390 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep,
null));
391 snapshotGLEventListener.setMakeSnapshot();
396 final FBObject _fboFront = glad.getFBObject(GL.GL_FRONT);
397 final FBObject _fboBack = glad.getFBObject(GL.GL_BACK);
398 System.out.println(
"Resize2.oldFront: "+fboFront);
399 System.out.println(
"Resize2.nowFront: "+_fboFront);
400 System.out.println(
"Resize2.oldBack : "+fboBack);
401 System.out.println(
"Resize2.nowBack : "+_fboBack);
404 Assert.assertEquals(fboBack, _fboFront);
405 Assert.assertEquals(fboFront, _fboBack);
408 Assert.assertEquals(fboFront, _fboFront);
409 Assert.assertEquals(fboBack, _fboBack);
413 Assert.assertNotNull(_color);
414 Assert.assertEquals(colorB, _color);
415 Assert.assertSame(colorB, _color);
419 Assert.assertNotNull(_depth);
421 Assert.assertEquals(depthB, _depth);
422 Assert.assertSame(depthB, _depth);
426 Assert.assertNotNull(_depth);
428 Assert.assertEquals(depthA, _depth);
429 Assert.assertSame(depthA, _depth);
432 Assert.assertNotNull(_color);
433 Assert.assertEquals(colorB, _color);
434 Assert.assertSame(colorB, _color);
439 final int newSampleCount = oldSampleCount > 0 ? 0 : 4;
440 System.out.println(
"Resize3.sampleCount: "+oldSampleCount+
" -> "+newSampleCount);
441 glad.setNumSamples(glad.getGL(), newSampleCount);
442 snapshotGLEventListener.setMakeSnapshot();
447 glad.setSurfaceSize(widthStep*szStep, heightStep*szStep);
448 Assert.assertTrue(
"Size not reached: Expected "+(widthStep*szStep)+
"x"+(heightStep*szStep)+
", Is "+glad.getSurfaceWidth()+
"x"+glad.getSurfaceHeight(),
449 GLTestUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep,
null));
450 snapshotGLEventListener.setMakeSnapshot();
454 System.out.println(
"Fin: "+glad);
457 public static void main(
final String args[])
throws Exception {
Core utility class simplifying usage of framebuffer objects (FBO) with all GLProfiles.
final boolean isInitialized()
Returns true if this instance has been initialized with reset(GL, int, int) or reset(GL,...
final RenderAttachment getDepthAttachment()
Return the depth RenderAttachment attachment.
final Colorbuffer getColorbuffer(final int attachmentPoint)
Return the Colorbuffer attachment at attachmentPoint if it is attached to this FBO,...
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
void setDepthBits(final int depthBits)
Sets the number of bits requested for the depth buffer.
Abstraction for an OpenGL rendering context.
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable 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 boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
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.
Toolkit agnostic GLOffscreenAutoDrawable.FBO tests using the factory model.
void test02a_GL2ES2_Demo1_DoubleBuffer_Normal()
void test04_GL2ES2_FBODemoMSAA4_Normal()
void test03a_GL2ES2_Demo2MSAA4_Normal()
void test01c_GL2ES2_Demo1_SingleBuffer_NoTexNoDepth()
void test01a_GL2ES2_Demo1_SingleBuffer_Normal()
static void main(final String args[])
void test01b_GL2ES2_Demo1_SingleBuffer_NoTex()
void test21_GL3_Demo0Normal()
void test03b_GL2ES2_Demo2MSAA4_NoTex()
void test03c_GL2ES2_Demo2MSAA4_NoTexNoDepth()
void test11_EGLES2_Demo0Normal()
void test13_EGLES2_Demo0MSAA4()
void setDoRotation(final boolean rotate)
Specifies an immutable set of OpenGL capabilities.
int getNumSamples()
Returns the number of sample buffers to be allocated if sample buffers are enabled,...
boolean getDoubleBuffered()
Returns whether double-buffering is requested, available or chosen.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
Platform-independent GLDrawable specialization, exposing FBObject functionality.
static final int FBOMODE_USE_TEXTURE
FBO Mode Bit: Use a TextureAttachment for the render colorbuffer, see setFBOMode(int).
FBObject based GLOffscreenAutoDrawable specialization
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.
static final int GL_BACK
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BACK" with expression...
static final int GL_FRONT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT" with expressio...