JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug463ScaleImageMemoryAWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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.jogl.glu;
30
31import java.awt.Frame;
32import java.nio.ByteBuffer;
33
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GLAutoDrawable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.awt.GLCanvas;
40import com.jogamp.opengl.glu.gl2es1.GLUgl2es1;
41
42import org.junit.Assume;
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.opengl.test.junit.util.UITestCase;
48
49/**
50 * Tests for bug 463, where gluScaleImage uses up all system memory. This was due to creating millions of
51 * 4-byte direct buffer objects inside the tight loops of Image.fill_image() and Image.empty_image(). Since
52 * the JVM apparently can only allocate direct buffer in 4MB chunks, each 4-byte buffer cost us a million times
53 * the memory it should have. Changing the constructor of Type_Widget.java back to non-direct buffer (like it
54 * was in JOGL 1) solves the problem.
55 * @author Wade Walker
56 */
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59
60 /* @Override */
61 public void init(final GLAutoDrawable drawable) {
62 }
63
64 /* @Override */
65 public void display(final GLAutoDrawable drawable) {
66 final int widthin = 559;
67 final int heightin = 425;
68
69 final int widthout = 1024;
70 final int heightout = 512;
71
72 final int textureInLength = widthin * heightin * 4;
73 final int textureOutLength = widthout * heightout * 4;
74
75 final byte[] datain = new byte[textureInLength];
76 final byte[] dataout = new byte[textureOutLength];
77
78 final ByteBuffer bufferIn = ByteBuffer.wrap(datain);
79 final ByteBuffer bufferOut = ByteBuffer.wrap(dataout);
80 final GLUgl2es1 glu = new GLUgl2es1();
81 // in the failing case, the system would run out of memory in here
83 widthin, heightin, GL.GL_UNSIGNED_BYTE, bufferIn,
84 widthout, heightout, GL.GL_UNSIGNED_BYTE, bufferOut );
85 }
86
87 /* @Override */
88 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
89 }
90
91
92 /* @Override */
93 public void dispose(final GLAutoDrawable drawable) {
94 }
95
96 @Test
97 public void test01() throws InterruptedException {
98 final GLProfile glprofile = GLProfile.getGL2ES1();
99 final GLCapabilities glCapabilities = new GLCapabilities(glprofile);
100 final GLCanvas canvas = new GLCanvas(glCapabilities);
101 canvas.addGLEventListener( this );
102
103 final Frame frame = new Frame("Test");
104 frame.add(canvas);
105 frame.setSize(256, 256);
106 frame.validate();
107
108 try {
109 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
110 public void run() {
111 frame.setVisible(true);
112 }});
113 } catch (final Throwable t) {
114 t.printStackTrace();
115 Assume.assumeNoException(t);
116 }
117
118 canvas.display();
119
120 Thread.sleep(200);
121
122 try {
123 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
124 public void run() {
125 frame.setVisible(false);
126 frame.remove(canvas);
127 frame.dispose();
128 }});
129 } catch (final Throwable t) {
130 t.printStackTrace();
131 Assume.assumeNoException(t);
132 }
133 }
134
135 public static void main(final String args[]) {
136 org.junit.runner.JUnitCore.main(TestBug463ScaleImageMemoryAWT.class.getName());
137 }
138}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES1(final AbstractGraphicsDevice device)
Returns the GL2ES1 profile implementation, hence compatible w/ GL2ES1.
Definition: GLProfile.java:883
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
final int gluScaleImage(int format, int widthin, int heightin, int typein, java.nio.Buffer datain, int widthout, int heightout, int typeout, java.nio.Buffer dataout)
Optional, throws GLException if not available in profile.
Definition: GLUgl2es1.java:146
Tests for bug 463, where gluScaleImage uses up all system memory.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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...
Definition: GL.java:150
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...
Definition: GL.java:284