aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
index 2af48cefd..aceb609a1 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java
@@ -54,7 +54,8 @@ import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
* </p>
*/
public class AWTGLPixelBuffer extends GLPixelBuffer {
- public static final GLPixelAttributes awtPixelAttributesIntRGB = new GLPixelAttributes(GL.GL_BGRA, GL.GL_UNSIGNED_BYTE);
+ public static final GLPixelAttributes awtPixelAttributesIntRGBA4 = new GLPixelAttributes(4, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE);
+ public static final GLPixelAttributes awtPixelAttributesIntRGB3 = new GLPixelAttributes(3, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE);
/** Allow {@link GL2GL3#GL_PACK_ROW_LENGTH}, or {@link GL2GL3#GL_UNPACK_ROW_LENGTH}. See {@link #requiresNewBuffer(GL, int, int, int)}. */
public final boolean allowRowStride;
@@ -92,6 +93,9 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
*/
@Override
public boolean requiresNewBuffer(GL gl, int newWidth, int newHeight, int minByteSize) {
+ if( !isValid() ) {
+ return true;
+ }
if( allowRowStride && gl.isGL2GL3() ) {
return width < newWidth || height < newHeight;
} else {
@@ -129,7 +133,7 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
}
@Override
public GLPixelAttributes getAttributes(GL gl, int componentCount) {
- return awtPixelAttributesIntRGB;
+ return 4 == componentCount ? awtPixelAttributesIntRGBA4 : awtPixelAttributesIntRGB3;
}
/**
@@ -157,8 +161,9 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
* The latter is true if size are compatible, hence <code>allowRowStride</code> should be enabled, if possible.
* </p>
*/
- public static class SingleAWTGLPixelBufferProvider extends AWTGLPixelBufferProvider {
- private AWTGLPixelBuffer single = null;
+ public static class SingleAWTGLPixelBufferProvider extends AWTGLPixelBufferProvider implements SingletonGLPixelBufferProvider {
+ private AWTGLPixelBuffer singleRGBA4 = null;
+ private AWTGLPixelBuffer singleRGB3 = null;
/**
* @param allowRowStride If <code>true</code>, allow row-stride, otherwise not. See {@link AWTGLPixelBuffer#requiresNewBuffer(GL, int, int, int)}.
@@ -175,10 +180,17 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
*/
@Override
public AWTGLPixelBuffer allocate(GL gl, GLPixelAttributes pixelAttributes, int width, int height, int depth, boolean pack, int minByteSize) {
- if( null == single || single.requiresNewBuffer(gl, width, height, minByteSize) ) {
- single = allocateImpl(pixelAttributes, width, height, depth, pack, minByteSize);
+ if( 4 == pixelAttributes.componentCount ) {
+ if( null == singleRGBA4 || singleRGBA4.requiresNewBuffer(gl, width, height, minByteSize) ) {
+ singleRGBA4 = allocateImpl(pixelAttributes, width, height, depth, pack, minByteSize);
+ }
+ return singleRGBA4;
+ } else {
+ if( null == singleRGB3 || singleRGB3.requiresNewBuffer(gl, width, height, minByteSize) ) {
+ singleRGB3 = allocateImpl(pixelAttributes, width, height, depth, pack, minByteSize);
+ }
+ return singleRGB3;
}
- return single;
}
private AWTGLPixelBuffer allocateImpl(GLPixelAttributes pixelAttributes, int width, int height, int depth, boolean pack, int minByteSize) {
@@ -188,16 +200,29 @@ public class AWTGLPixelBuffer extends GLPixelBuffer {
return new AWTGLPixelBuffer(pixelAttributes, width, height, depth, pack, image, ibuffer, allowRowStride);
}
+ /** Return the last {@link #allocate(GL, GLPixelAttributes, int, int, int, boolean, int) allocated} {@link AWTGLPixelBuffer} w/ {@link GLPixelAttributes#componentCount}. */
+ public AWTGLPixelBuffer getSingleBuffer(GLPixelAttributes pixelAttributes) {
+ return 4 == pixelAttributes.componentCount ? singleRGBA4 : singleRGB3;
+ }
+
/**
* Initializes the single {@link AWTGLPixelBuffer} w/ a given size, if not yet {@link #allocate(GL, GLPixelAttributes, int, int, int, boolean, int) allocated}.
* @return the newly initialized single {@link AWTGLPixelBuffer}, or null if already allocated.
*/
- public AWTGLPixelBuffer initSingleton(int width, int height, int depth, boolean pack) {
- if( null != single ) {
- return null;
+ public AWTGLPixelBuffer initSingleton(int componentCount, int width, int height, int depth, boolean pack) {
+ if( 4 == componentCount ) {
+ if( null != singleRGBA4 ) {
+ return null;
+ }
+ singleRGBA4 = allocateImpl(AWTGLPixelBuffer.awtPixelAttributesIntRGBA4, width, height, depth, pack, 0);
+ return singleRGBA4;
+ } else {
+ if( null != singleRGB3 ) {
+ return null;
+ }
+ singleRGB3 = allocateImpl(AWTGLPixelBuffer.awtPixelAttributesIntRGB3, width, height, depth, pack, 0);
+ return singleRGB3;
}
- single = allocateImpl(AWTGLPixelBuffer.awtPixelAttributesIntRGB, width, height, depth, pack, 0);
- return single;
}
}
} \ No newline at end of file