28package com.jogamp.opengl.test.junit.jogl.acore;
30import com.jogamp.opengl.FBObject;
31import com.jogamp.opengl.FBObject.TextureAttachment;
32import com.jogamp.opengl.util.GLArrayDataServer;
33import com.jogamp.opengl.util.GLReadBufferUtil;
34import com.jogamp.opengl.util.PMVMatrix;
35import com.jogamp.opengl.util.glsl.ShaderCode;
36import com.jogamp.opengl.util.glsl.ShaderProgram;
37import com.jogamp.opengl.util.glsl.ShaderState;
38import com.jogamp.opengl.util.texture.TextureIO;
39import com.jogamp.opengl.FBObject.Attachment.Type;
40import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
41import com.jogamp.opengl.test.junit.util.MiscUtils;
42import com.jogamp.opengl.test.junit.util.NEWTGLContext;
43import com.jogamp.opengl.test.junit.util.UITestCase;
45import java.io.IOException;
47import com.jogamp.common.os.Platform;
48import com.jogamp.junit.util.JunitTracer;
49import com.jogamp.nativewindow.NativeSurface;
50import com.jogamp.opengl.GL;
51import com.jogamp.opengl.GL2ES2;
52import com.jogamp.opengl.GL2GL3;
53import com.jogamp.opengl.GLCapabilities;
54import com.jogamp.opengl.GLDrawable;
55import com.jogamp.opengl.GLProfile;
56import com.jogamp.opengl.GLUniformData;
57import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
59import org.junit.Assert;
60import org.junit.BeforeClass;
62import org.junit.FixMethodOrder;
63import org.junit.runners.MethodSorters;
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static long durationPerTest = 10*40*2;
70 public void test01() throws InterruptedException {
72 final int width = 800;
73 final int height = 600;
76 System.err.println(
"Test requires GL2/GL3 profile.");
81 final GLDrawable drawable = winctx.context.getGLDrawable();
84 System.err.println(winctx.context);
92 "shader/bin",
"fbo-mrt-1",
true);
94 "shader/bin",
"fbo-mrt-1",
true);
98 sp0.
add(gl, vp0, System.err);
99 sp0.
add(gl, fp0, System.err);
100 Assert.assertTrue(0 != sp0.
program());
101 Assert.assertTrue(!sp0.
inUse());
102 Assert.assertTrue(!sp0.
linked());
107 "shader/bin",
"fbo-mrt-2",
true);
109 "shader/bin",
"fbo-mrt-2",
true);
113 sp1.
add(gl, vp1, System.err);
114 sp1.
add(gl, fp1, System.err);
115 Assert.assertTrue(0 != sp1.
program());
116 Assert.assertTrue(!sp1.
inUse());
117 Assert.assertTrue(!sp1.
linked());
125 st.
uniform(gl, pmvMatrixUniform);
130 vertices0.
putf(0); vertices0.
putf(1); vertices0.
putf(0);
131 vertices0.
putf(1); vertices0.
putf(1); vertices0.
putf(0);
132 vertices0.
putf(0); vertices0.
putf(0); vertices0.
putf(0);
133 vertices0.
putf(1); vertices0.
putf(0); vertices0.
putf(0);
134 vertices0.
seal(gl,
true);
145 colors0.
seal(gl,
true);
159 texCoords0.
putf(0f); texCoords0.
putf(1f);
160 texCoords0.
putf(1f); texCoords0.
putf(1f);
161 texCoords0.
putf(0f); texCoords0.
putf(0f);
162 texCoords0.
putf(1f); texCoords0.
putf(0f);
163 texCoords0.
seal(gl,
true);
168 final int texA0Point = 0;
169 final int texA1Point = 1;
180 System.err.println(
"FBO supports only one attachment, no MRT available!");
194 pmvMatrix.
glOrthof(0f, 1f, 0f, 1f, -10f, 10f);
197 st.
uniform(gl, pmvMatrixUniform);
201 final int[] bck_buffers =
new int[] { GL2GL3.GL_BACK_LEFT };
205 final int[] last_snap_size =
new int[] { 0, 0 };
207 for(
int i=0; i<durationPerTest; i+=50) {
234 fbo_mrt.
use(gl, texA0);
237 fbo_mrt.
use(gl, texA1);
250 snapshot(step_i,
null, gl, screenshot,
TextureIO.
PNG,
null);
258 final int j = (int) ( i / (durationPerTest/step) ) + 1;
260 final int w = width/step * j;
261 final int h = height/step * j;
262 System.err.println(
"resize: "+step_i+
" -> "+j+
" - "+w+
"x"+h);
263 fbo_mrt.
reset(gl, w, h, 0);
264 winctx.window.setSize(w, h);
275 if( Platform.OSType.MACOS == Platform.getOSType() ) {
276 JunitTracer.setTestSupported(
false);
280 static boolean manual_test =
false;
282 public static void main(
final String args[])
throws IOException {
284 System.err.println(
"main - start");
285 for(
int i=0; i<args.length; i++) {
286 if(args[i].equals(
"-time")) {
287 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
291 org.junit.runner.JUnitCore.
main(tstname);
292 System.err.println(
"main - end");
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
Core utility class simplifying usage of framebuffer objects (FBO) with all GLProfiles.
final void attachRenderbuffer(final GL gl, final Attachment.Type atype, final int reqBits)
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,...
final void bind(final GL gl)
Bind this FBO, i.e.
final TextureAttachment attachTexture2D(final GL gl, final int attachmentPoint, final boolean alpha)
Attaches a Colorbuffer, i.e.
final int getWidth()
Returns the width.
final boolean isStatusValid()
The status may even be valid if incomplete during transition of attachments.
final int getMaxColorAttachments()
Returns the maximum number of colorbuffer attachments.
final int getHeight()
Returns the height.
final void unuse(final GL gl)
Unbind texture, ie bind 'non' texture 0.
final void use(final GL gl, final TextureAttachment ta)
Synchronize the sampling sink and bind the given TextureAttachment, if not null.
final void unbind(final GL gl)
Unbind this FBO, i.e.
final boolean reset(final GL gl, int newWidth, int newHeight, int newSamples)
Resets this FBO's instance.
static final int CHOSEN_BITS
Request current context drawable's chosen depth- or stencil-bits; value {@value}.
void init(final GL gl, final int newWidth, final int newHeight, final int newSamples)
Initializes this FBO's instance.
Specifies a set of OpenGL capabilities.
abstract GLDrawable getGLReadDrawable()
Returns the read-Drawable this context uses for read framebuffer operations.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static GLProfile getGL2GL3(final AbstractGraphicsDevice device)
Returns the GL2GL3 profile implementation, hence compatible w/ GL2GL3.
static final String GL2GL3
The intersection of the desktop GL3 and GL2 profile.
static void beforeClass()
static void main(final String args[])
static int atoi(final String str, final int def)
static WindowContext createWindow(final GLCapabilities caps, final int width, final int height, final boolean debugGL)
static void destroyWindow(final WindowContext winctx)
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createGLSL(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name and starting with a new created Buffer object ...
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the orthogonal matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Convenient shader code class to use and instantiate vertex or fragment programs.
final int defaultShaderCustomization(final GL2ES2 gl, final boolean preludeVersion, final boolean addDefaultPrecision)
Default customization of this shader source code.
static ShaderCode create(final GL2ES2 gl, final int type, final int count, final Class<?> context, final String[] sourceFiles, final boolean mutableStringBuilder)
Creates a complete ShaderCode object while reading all shader source of sourceFiles,...
int program()
Returns the shader program name, which is non zero if valid.
synchronized void add(final ShaderCode shaderCode)
Adds a new shader to this program.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
void ownAttribute(final GLArrayData attribute, final boolean own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
boolean uniform(final GL2ES2 gl, final GLUniformData data)
Set the uniform data, if it's location is valid, i.e.
void ownUniform(final GLUniformData uniform)
Bind the GLUniform lifecycle to this ShaderState.
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
void glDrawBuffers(int n, IntBuffer bufs)
Entry point to C language function: void {@native glDrawBuffers}(GLsizei n, const GLenum * bufs) P...
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...
GL getGL()
Casts this object to the GL interface.
GLContext getContext()
Returns the GLContext associated which this GL object.
GL2GL3 getGL2GL3()
Casts this object to the GL2GL3 interface.
An abstraction for an OpenGL rendering target.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.
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.
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
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_COLOR_ATTACHMENT0
GL_ES_VERSION_2_0, GL_ARB_framebuffer_object, GL_VERSION_3_0, GL_NV_draw_buffers, GL_OES_framebuffer_...
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 glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with ...
static final int GL_NEAREST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NEAREST" with express...
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_TEXTURE0
GL_ES_VERSION_2_0, GL_VERSION_1_3, GL_VERSION_ES_1_0, GL_ARB_multitexture Alias for: GL_TEXTURE0_ARB ...
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_CLAMP_TO_EDGE
GL_ES_VERSION_2_0, GL_VERSION_1_2, GL_VERSION_ES_1_0, GL_SGIS_texture_edge_clamp Alias for: GL_CLAMP_...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.