29package com.jogamp.opengl.util;
32import java.io.IOException;
34import com.jogamp.nativewindow.util.PixelFormat;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GL2ES3;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLDrawable;
39import com.jogamp.opengl.GLException;
41import com.jogamp.common.nio.Buffers;
42import com.jogamp.opengl.util.texture.Texture;
43import com.jogamp.opengl.util.texture.TextureData;
44import com.jogamp.opengl.util.GLPixelBuffer;
45import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
46import com.jogamp.opengl.util.GLPixelBuffer.GLPixelBufferProvider;
47import com.jogamp.opengl.util.texture.TextureIO;
83 this.alphaRequested = requestAlpha;
84 this.hasAlpha = requestAlpha;
126 public void write(
final File dest) {
130 }
catch (
final IOException ex) {
131 throw new RuntimeException(
"can not write to file: " + dest.getAbsolutePath(), ex);
147 public boolean readPixels(
final GL gl,
final boolean mustFlipVertically) {
148 return readPixels(gl, 0, 0, 0, 0, mustFlipVertically);
166 public boolean readPixels(
final GL gl,
final int inX,
final int inY,
final int inWidth,
final int inHeight,
final boolean mustFlipVertically) {
168 final int width, height;
179 return readPixelsImpl(drawable, gl, inX, inY, width, height, mustFlipVertically);
183 final int inX,
final int inY,
final int width,
final int height,
184 final boolean mustFlipVertically) {
187 System.err.println(
"Info: GLReadBufferUtil.readPixels: pre-exisiting GL error 0x"+Integer.toHexString(glerr0));
194 final int alignment, internalFormat;
195 if( 4 == componentCount ) {
202 final boolean flipVertically;
204 flipVertically = mustFlipVertically;
206 flipVertically = !mustFlipVertically;
209 final int tmp[] =
new int[1];
212 boolean newData =
false;
228 }
catch (
final Exception e) {
231 throw new RuntimeException(
"can not fetch offscreen texture", e);
254 }
catch(
final GLException gle) { res =
false; gle.printStackTrace(); }
259 System.err.println(
"GLReadBufferUtil.readPixels: readPixels error 0x"+Integer.toHexString(glerr1)+
260 " "+width+
"x"+height+
abstract GLDrawable getGLReadDrawable()
Returns the read-Drawable this context uses for read framebuffer operations.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Utility routines for dealing with direct buffers.
static final int sizeof(final GL gl, final int tmp[], final int bytesPerPixel, int width, int height, int depth, final boolean pack)
Returns the number of bytes required to read/write a memory buffer via OpenGL using the current GL pi...
final int type
The OpenGL pixel data type
final PixelFormat pfmt
PixelFormat describing the component layout
final int format
The OpenGL pixel data format.
OpenGL pixel data buffer, allowing user to provide buffers via their GLPixelBufferProvider implementa...
int position()
Returns the byte position of the buffer.
Buffer flip()
See Buffer#flip().
void dispose()
Dispose resources.
static final GLPixelBufferProvider defaultProviderNoRowStride
Default GLPixelBufferProvider with GLPixelBufferProvider#getAllowRowStride() == false,...
Buffer rewind()
See Buffer#rewind().
Buffer clear()
See Buffer#clear().
boolean requiresNewBuffer(final GL gl, final int newWidth, final int newHeight, int newByteSize)
Returns true, if invalid or implementation requires a new buffer based on the new size due to pixel a...
boolean isValid()
Is not disposed and has byteSize > 0.
final Buffer buffer
Buffer holding the pixel data.
Utility to safely set and restore the PACK and UNPACK pixel storage mode, regardless of the GLProfile...
final void setPackRowLength(final GL2ES3 gl, final int packRowLength)
Sets the GL2ES3#GL_PACK_ROW_LENGTH.
final void restore(final GL gl)
Restores PACK and UNPACK pixel storage mode previously saved w/ saveAll(GL) or savePack(GL) and saveU...
final void setPackAlignment(final GL gl, final int packAlignment)
Sets the GL#GL_PACK_ALIGNMENT.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
boolean hasAlpha()
Returns true if the OpenGL read data contains alpha.
TextureData getTextureData()
void rewindPixelBuffer()
rewind the raw pixel ByteBuffer
void write(final File dest)
Write the TextureData filled by readPixels(GLAutoDrawable, boolean) to file.
final boolean alphaRequested
boolean readPixels(final GL gl, final int inX, final int inY, final int inWidth, final int inHeight, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
GLPixelBufferProvider getPixelBufferProvider()
Returns the GLPixelBufferProvider used by this instance.
void setReadBuffer(final int name)
GLPixelStorageModes getGLPixelStorageModes()
TextureData readTextureData
final GLPixelStorageModes psm
void dispose(final GL gl)
boolean readPixelsImpl(final GLDrawable drawable, final GL gl, final int inX, final int inY, final int width, final int height, final boolean mustFlipVertically)
GLPixelBuffer readPixelBuffer
GLPixelBuffer getPixelBuffer()
Returns the GLPixelBuffer, created and filled by readPixels(GLAutoDrawable, boolean).
final Texture readTexture
GLReadBufferUtil(final boolean requestAlpha, final boolean write2Texture)
Using the default GLPixelBuffer: GLPixelBuffer#defaultProviderNoRowStride.
GLReadBufferUtil(final GLPixelBufferProvider pixelBufferProvider, final boolean requestAlpha, final boolean write2Texture)
boolean readPixels(final GL gl, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
final GLPixelBufferProvider pixelBufferProvider
Represents the data for an OpenGL texture.
void setHeight(final int height)
Sets the height in pixels of the texture data.
void setPixelAttributes(final GLPixelAttributes pixelAttributes)
Sets the intended OpenGL pixel format of the texture data.
void setInternalFormat(final int internalFormat)
Sets the intended OpenGL internal format of the texture data.
void setWidth(final int width)
Sets the width in pixels of the texture data.
static void write(final Texture texture, final File file)
Writes the given texture to a file.
Represents an OpenGL texture object.
void updateImage(final GL gl, final TextureData data)
Updates the entire content area incl.
void destroy(final GL gl)
Destroys and nulls the underlying native texture used by this Texture instance if owned,...
void updateSubImage(final GL gl, final TextureData data, final int mipmapLevel, final int x, final int y)
Updates a subregion of the content area of this texture using the given data.
void glReadBuffer(int mode)
Entry point to C language function: void {@native glReadBuffer}(GLenum mode) Part of GL_ES_VERSION...
boolean isGL2ES3()
Indicates whether this GL object conforms to a either a GL2GL3 or GL3ES3 compatible profile.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GLContext getContext()
Returns the GLContext associated which this GL object.
GL2ES3 getGL2ES3()
Casts this object to the GL2ES3 interface.
int getDefaultReadBuffer()
Returns the default color buffer within the current bound getDefaultReadFramebuffer(),...
An abstraction for an OpenGL rendering target.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
boolean isGLOriented()
Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glReadPixels}(GLint x, GLint y,...
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 ...
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expr...
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_RGBA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGBA" with expression...
Allows user to interface with another toolkit to define GLPixelAttributes and memory buffer to produc...
GLPixelBuffer allocate(GL gl, PixelFormat.Composition hostPixComp, GLPixelAttributes pixelAttributes, boolean pack, int width, int height, int depth, int minByteSize)
Allocates a new GLPixelBuffer object.
GLPixelAttributes getAttributes(GL gl, int componentCount, boolean pack)
Returns RGB[A] GLPixelAttributes matching GL, componentCount and pack.
PixelFormat.Composition getHostPixelComp(final GLProfile glp, final int componentCount)
Returns the host PixelFormat.Composition matching GL and componentCount if required by implementation...