JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug365TextureGenerateMipMaps.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.glu;
2
3import java.nio.ByteBuffer;
4
5import com.jogamp.opengl.GL;
6import com.jogamp.opengl.GL2;
7import com.jogamp.opengl.GL2ES2;
8import com.jogamp.opengl.GLCapabilities;
9import com.jogamp.opengl.GLContext;
10import com.jogamp.opengl.GLDrawableFactory;
11import com.jogamp.opengl.GLOffscreenAutoDrawable;
12import com.jogamp.opengl.GLProfile;
13
14import org.junit.AfterClass;
15import org.junit.Assert;
16import org.junit.BeforeClass;
17import org.junit.FixMethodOrder;
18import org.junit.Test;
19import org.junit.runners.MethodSorters;
20
21import jogamp.opengl.glu.mipmap.Mipmap;
22import jogamp.opengl.glu.mipmap.ScaleInternal;
23
24import com.jogamp.common.nio.Buffers;
25import com.jogamp.opengl.test.junit.util.UITestCase;
26import com.jogamp.opengl.util.texture.Texture;
27import com.jogamp.opengl.util.texture.TextureData;
28import com.jogamp.opengl.util.texture.TextureIO;
29
30/**
31 * This test creates a {@link Texture} from {@link TextureData} of various pixel formats
32 * and pixel types with auto generate mipmaps set to {@code true}.
33 * <br></br>
34 * Bug Reference: https://jogamp.org/bugzilla/show_bug.cgi?id=365
35 * <br></br>
36 * The bug pertains to mipmap generation from a Texture and exists in {@link ScaleInternal}
37 * where a {@link java.nio.BufferUnderflowException} is thrown.
38 * <br></br>
39 * <ul>This suite of test cases test:
40 * <li>{@link ScaleInternal#scale_internal_ubyte(int, int, int, ByteBuffer, int, int, ByteBuffer, int, int, int)}</li>
41 * <li>{@link ScaleInternal#scale_internal_byte(int, int, int, ByteBuffer, int, int, ByteBuffer, int, int, int)}</li>
42 * <li>{@link ScaleInternal#scale_internal_ushort(int, int, int, ByteBuffer, int, int, java.nio.ShortBuffer, int, int, int, boolean)}</li>
43 * <li>{@link ScaleInternal#scale_internal_short(int, int, int, ByteBuffer, int, int, java.nio.ShortBuffer, int, int, int, boolean)}</li>
44 * <li>{@link ScaleInternal#scale_internal_uint(int, int, int, ByteBuffer, int, int, java.nio.IntBuffer, int, int, int, boolean)}</li>
45 * <li>{@link ScaleInternal#scale_internal_int(int, int, int, ByteBuffer, int, int, java.nio.IntBuffer, int, int, int, boolean)}</li>
46 * <li>{@link ScaleInternal#scale_internal_float(int, int, int, ByteBuffer, int, int, java.nio.FloatBuffer, int, int, int, boolean)}</li>
47 * </ul>
48 *
49 * @author Michael Esemplare, et.al.
50 *
51 */
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 static GLOffscreenAutoDrawable drawable;
55
56 @BeforeClass
57 public static void setup() throws Throwable {
58 // disableNPOT
59 System.setProperty("jogl.texture.nonpot", "true");
60 try {
61 setUpOffscreenAutoDrawable();
62 } catch (final Throwable t) {
63 throw t;
64 }
65 }
66
67 @AfterClass
68 public static void teardown() {
69 tearDownOffscreenAutoDrawable();
70 }
71
72 private static void setUpOffscreenAutoDrawable() throws Throwable {
73 final GLProfile glp = GLProfile.getDefault();
74 final GLCapabilities caps = new GLCapabilities(glp);
75
77
78 // Make a drawable to get an offscreen context
79 drawable = factory.createOffscreenAutoDrawable(null, caps, null, 2, 2);
80 drawable.display(); // trigger context creation
81 final GLContext glContext = drawable.getContext();
82 try {
83 Assert.assertTrue("Could not make context current", GLContext.CONTEXT_NOT_CURRENT < glContext.makeCurrent());
84 } catch (final Throwable t) {
85 tearDownOffscreenAutoDrawable();
86 throw t;
87 }
88 }
89
90 private static void tearDownOffscreenAutoDrawable() {
91 if(drawable != null) {
92 drawable.getContext().release();
93 drawable.destroy();
94 drawable = null;
95 }
96 }
97
98 private static void testTextureMipMapGeneration(final int width, final int height, final int pixelFormat, final int pixelType) {
99 final int internalFormat = pixelFormat;
100 final int border = 0;
101 final boolean mipmap = true;
102 final boolean dataIsCompressed = false;
103 final boolean mustFlipVertically = false;
104
105 final int memReq = Mipmap.image_size( width, height, pixelFormat, pixelType );
106 ByteBuffer buffer = Buffers.newDirectByteBuffer( memReq );
107
108 final TextureData data = new TextureData(drawable.getGLProfile(),
109 internalFormat,
110 width,
111 height,
112 border,
113 pixelFormat,
114 pixelType,
115 mipmap,
116 dataIsCompressed,
117 mustFlipVertically,
118 buffer,
119 null);
120
121 final Texture texture = TextureIO.newTexture(drawable.getGL(), data);
122 // Cleanup
123 texture.destroy(drawable.getGL());
124 data.destroy();
125 buffer.clear();
126 buffer = null;
127 }
128
129 @Test
131 final int width = 1;
132 final int height = 7;
133 final int pixelFormat = GL.GL_RGB;
134 final int pixelType = GL.GL_UNSIGNED_BYTE;
135
136 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
137 }
138
139 @Test
141 final int width = 1;
142 final int height = 7;
143 final int pixelFormat = GL.GL_RGBA;
144 final int pixelType = GL.GL_UNSIGNED_BYTE;
145
146 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
147 }
148
149 @Test
151 final int width = 1;
152 final int height = 7;
153 final int pixelFormat = GL.GL_RGB;
154 final int pixelType = GL.GL_BYTE;
155
156 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
157 }
158
159 @Test
161 final int width = 1;
162 final int height = 7;
163 final int pixelFormat = GL.GL_RGBA;
164 final int pixelType = GL.GL_BYTE;
165
166 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
167 }
168
169 @Test
171 final int width = 1;
172 final int height = 7;
173 final int pixelFormat = GL.GL_RGB;
174 final int pixelType = GL.GL_UNSIGNED_SHORT;
175
176 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
177 }
178
179 @Test
181 final int width = 1;
182 final int height = 7;
183 final int pixelFormat = GL.GL_RGBA;
184 final int pixelType = GL.GL_UNSIGNED_SHORT;
185
186 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
187 }
188
189 @Test
191 final int width = 1;
192 final int height = 7;
193 final int pixelFormat = GL.GL_RGB;
194 final int pixelType = GL.GL_SHORT;
195
196 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
197 }
198
199 @Test
201 final int width = 1;
202 final int height = 7;
203 final int pixelFormat = GL.GL_RGBA;
204 final int pixelType = GL.GL_SHORT;
205
206 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
207 }
208
209 @Test
211 final int width = 1;
212 final int height = 7;
213 final int pixelFormat = GL.GL_RGB;
214 final int pixelType = GL.GL_UNSIGNED_INT;
215
216 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
217 }
218
219 @Test
221 final int width = 1;
222 final int height = 7;
223 final int pixelFormat = GL.GL_RGBA;
224 final int pixelType = GL.GL_UNSIGNED_INT;
225
226 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
227 }
228
229 @Test
231 final int width = 1;
232 final int height = 7;
233 final int pixelFormat = GL.GL_RGB;
234 final int pixelType = GL2ES2.GL_INT;
235
236 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
237 }
238
239 @Test
241 final int width = 1;
242 final int height = 7;
243 final int pixelFormat = GL.GL_RGBA;
244 final int pixelType = GL2ES2.GL_INT;
245
246 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
247 }
248
249 @Test
251 final int width = 1;
252 final int height = 7;
253 final int pixelFormat = GL.GL_RGB;
254 final int pixelType = GL.GL_FLOAT;
255
256 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
257 }
258
259 @Test
261 final int width = 1;
262 final int height = 7;
263 final int pixelFormat = GL.GL_RGBA;
264 final int pixelType = GL.GL_FLOAT;
265
266 testTextureMipMapGeneration(width, height, pixelFormat, pixelType);
267 }
268
269 public static void main(final String[] args) {
270 org.junit.runner.JUnitCore.main(TestBug365TextureGenerateMipMaps.class.getName());
271 }
272}
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
static final int CONTEXT_NOT_CURRENT
Indicates that the context was not made current during the last call to makeCurrent,...
Definition: GLContext.java:112
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract void release()
Releases control of this GLContext from the current thread.
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.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
This test creates a Texture from TextureData of various pixel formats and pixel types with auto gener...
static final int GL_INT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0 Define "GL_INT" with expression '0x1404',...
Definition: GL2ES2.java:200
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLContext getContext()
Returns the context associated with this drawable.
GLProfile getGLProfile()
Fetches the GLProfile for this drawable.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.
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 ...
Definition: GL.java:374
static final int GL_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_SHORT" with expressio...
Definition: GL.java:125
static final int GL_UNSIGNED_INT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_OES_element_index_uint Define "GL_UNSIGNED_INT"...
Definition: GL.java:294
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...
Definition: GL.java:786
static final int GL_UNSIGNED_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_SHORT" with ...
Definition: GL.java:346
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
static final int GL_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BYTE" with expression...
Definition: GL.java:159