lwjgl2-arm64/src/java/org/lwjgl/opengl/Pbuffer.java

322 lines
10 KiB
Java
Raw Normal View History

2004-02-15 22:46:58 +01:00
/*
2003-08-17 18:38:57 +02:00
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
2004-02-15 22:46:58 +01:00
*
2003-08-17 18:38:57 +02:00
* Redistribution and use in source and binary forms, with or without
2004-02-15 22:46:58 +01:00
* modification, are permitted provided that the following conditions are
2003-08-17 18:38:57 +02:00
* met:
2004-02-15 22:46:58 +01:00
*
* * Redistributions of source code must retain the above copyright
2003-08-17 18:38:57 +02:00
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
2004-02-15 22:46:58 +01:00
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
2003-08-17 18:38:57 +02:00
* from this software without specific prior written permission.
2004-02-15 22:46:58 +01:00
*
2003-08-17 18:38:57 +02:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2004-02-15 22:46:58 +01:00
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2003-08-17 18:38:57 +02:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2004-02-15 22:46:58 +01:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2003-08-17 18:38:57 +02:00
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
2004-02-08 21:41:00 +01:00
import org.lwjgl.Sys;
2003-08-17 18:38:57 +02:00
2004-03-02 02:59:32 +01:00
import java.nio.IntBuffer;
2003-08-17 18:38:57 +02:00
/**
* $Id$
2004-03-02 02:59:32 +01:00
* <p/>
2003-08-17 18:38:57 +02:00
* Pbuffer encapsulates an OpenGL pbuffer.
2004-03-02 02:59:32 +01:00
* <p/>
* Each instance of GL is only valid in the thread that creates it. In addition, only one instance of an OpenGL window or
* Pbuffer may be the current GL context in any one thread. To make a GL instance the current context, use makeCurrent().
2004-02-15 22:46:58 +01:00
*
2003-08-17 18:38:57 +02:00
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
2004-02-23 17:30:48 +01:00
public final class Pbuffer {
2004-02-15 22:46:58 +01:00
2004-03-02 02:59:32 +01:00
/**
* Indicates that Pbuffers can be created.
*/
public static final int PBUFFER_SUPPORTED = 1 << 0;
/**
* Indicates that Pbuffers can be used as render-textures.
*/
public static final int RENDER_TEXTURE_SUPPORTED = 1 << 1;
/**
* Indicates that Pbuffers can be used as non-power-of-two render-textures.
*/
public static final int RENDER_TEXTURE_RECTANGLE_SUPPORTED = 1 << 2;
/**
* Indicates that Pbuffers can be used as depth render-textures.
*/
public static final int RENDER_DEPTH_TEXTURE_SUPPORTED = 1 << 3;
/**
* The render-to-texture mipmap level attribute.
*/
public static final int MIPMAP_LEVEL = RenderTexture.WGL_MIPMAP_LEVEL_ARB;
/**
* The render-to-texture cube map face attribute.
*/
public static final int CUBE_MAP_FACE = RenderTexture.WGL_CUBE_MAP_FACE_ARB;
/**
* The render-to-texture cube map positive X face value.
*/
public static final int TEXTURE_CUBE_MAP_POSITIVE_X = RenderTexture.WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB;
2004-02-15 22:46:58 +01:00
2004-03-02 02:59:32 +01:00
/**
* The render-to-texture cube map negative X face value.
*/
public static final int TEXTURE_CUBE_MAP_NEGATIVE_X = RenderTexture.WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB;
/**
* The render-to-texture cube map positive Y face value.
*/
public static final int TEXTURE_CUBE_MAP_POSITIVE_Y = RenderTexture.WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB;
/**
* The render-to-texture cube map negative Y face value.
*/
public static final int TEXTURE_CUBE_MAP_NEGATIVE_Y = RenderTexture.WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB;
/**
* The render-to-texture cube map positive Z face value.
*/
public static final int TEXTURE_CUBE_MAP_POSITIVE_Z = RenderTexture.WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB;
/**
* The render-to-texture cube map negative Z face value.
*/
public static final int TEXTURE_CUBE_MAP_NEGATIVE_Z = RenderTexture.WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB;
/**
* The Pbuffer front left buffer.
*/
public static final int FRONT_LEFT_BUFFER = RenderTexture.WGL_FRONT_LEFT_ARB;
/**
* The Pbuffer front right buffer.
*/
public static final int FRONT_RIGHT_BUFFER = RenderTexture.WGL_FRONT_RIGHT_ARB;
/**
* The Pbuffer back left buffer.
*/
public static final int BACK_LEFT_BUFFER = RenderTexture.WGL_BACK_LEFT_ARB;
/**
* The Pbuffer back right buffer.
*/
public static final int BACK_RIGHT_BUFFER = RenderTexture.WGL_BACK_RIGHT_ARB;
/**
* The Pbuffer depth buffer.
*/
public static final int DEPTH_BUFFER = RenderTexture.WGL_DEPTH_COMPONENT_NV;
/**
* Current Pbuffer
*/
private static Pbuffer currentBuffer;
/**
* Handle to the native GL rendering context
*/
2003-08-17 18:38:57 +02:00
private final int handle;
2004-03-02 02:59:32 +01:00
/**
* Width
*/
2004-02-18 18:48:26 +01:00
private final int width;
2004-03-02 02:59:32 +01:00
/**
* Height
*/
2004-02-18 18:48:26 +01:00
private final int height;
2003-08-17 18:38:57 +02:00
static {
System.loadLibrary(Sys.getLibraryName());
}
2004-02-15 22:46:58 +01:00
2003-08-17 18:38:57 +02:00
/**
2004-03-02 02:59:32 +01:00
* Construct an instance of a Pbuffer. If this fails then an Exception will be thrown. The buffer is single-buffered.
* <p/>
* NOTE: An OpenGL window must be created before a Pbuffer can be created. The Pbuffer will have its own context that shares
* display lists and textures with the OpenGL window context, but it will have its own OpenGL state. Therefore, state changes
* to a pbuffer will not be seen in the window context and vice versa.
* <p/>
* NOTE: Some OpenGL implementations requires the shared contexts to use the same pixel format. So if possible, use the same
* bpp, alpha, depth and stencil values used to create the main window.
* <p/>
* The renderTexture parameter defines the necessary state for enabling render-to-texture. When this parameter is null,
* render-to-texture is not available. Before using render-to-texture, the Pbuffer capabilities must be queried to ensure that
* it is supported.
2003-08-17 18:38:57 +02:00
*
2004-03-02 02:59:32 +01:00
* @param width Pbuffer width
* @param height Pbuffer height
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
* @param samples Minimum samples in multisample buffer (corresponds to GL_SAMPLES_ARB in GL_ARB_multisample spec). Pass
* 0 to disable multisampling. This parameter is ignored if GL_ARB_multisample is not supported.
* @param renderTexture
*/
public Pbuffer(int width, int height, int bpp, int alpha, int depth, int stencil, int samples, RenderTexture renderTexture) throws Exception {
2004-02-18 18:48:26 +01:00
this.width = width;
this.height = height;
2004-03-02 02:59:32 +01:00
if ( renderTexture == null )
handle = nCreate(width, height, bpp, alpha, depth, stencil, samples, null, 0, null, 0);
else
handle = nCreate(width, height,
bpp, alpha, depth, stencil,
samples,
renderTexture.pixelFormatCaps, renderTexture.pixelFormatCaps.limit(),
renderTexture.pBufferAttribs, renderTexture.pBufferAttribs.limit());
2003-08-17 18:38:57 +02:00
}
/**
2004-03-02 02:59:32 +01:00
* Method to test for validity of the buffer. If this function returns true, the buffer contents is lost. The buffer can still
* be used, but the results are undefined. The application is expected to release the buffer if needed, destroy it and recreate
* a new buffer.
2003-08-17 18:38:57 +02:00
*
* @return true if the buffer is lost and destroyed, false if the buffer is valid.
*/
2004-02-18 18:48:26 +01:00
public synchronized boolean isBufferLost() {
2003-08-17 18:38:57 +02:00
return nIsBufferLost(handle);
}
/**
* Native method to test for buffer integrity
*/
2004-03-02 02:59:32 +01:00
private static native boolean nIsBufferLost(int handle);
2003-08-17 18:38:57 +02:00
/**
2004-03-02 02:59:32 +01:00
* Method to make the Pbuffer context current. All subsequent OpenGL calls will go to this buffer.
2003-08-17 18:38:57 +02:00
*/
2004-02-18 18:48:26 +01:00
public synchronized void makeCurrent() {
2003-08-17 18:38:57 +02:00
currentBuffer = this;
nMakeCurrent(handle);
2004-02-18 18:48:26 +01:00
VBOTracker.setCurrent(this);
2003-08-17 18:38:57 +02:00
}
/**
* Native method to make a pbuffer current.
*/
2004-03-02 02:59:32 +01:00
private static native void nMakeCurrent(int handle);
2003-08-17 18:38:57 +02:00
/**
2004-03-02 02:59:32 +01:00
* Gets the Pbuffer capabilities.
2003-08-17 18:38:57 +02:00
*
* @return a bitmask of Pbuffer capabilities.
*/
public static native int getPbufferCaps();
2004-02-15 22:46:58 +01:00
2003-08-17 18:38:57 +02:00
/**
* Native method to create a Pbuffer
*/
2004-03-02 02:59:32 +01:00
private static native int nCreate(int width, int height,
int bpp, int alpha, int depth, int stencil,
int samples,
IntBuffer pixelFormatCaps, int pixelFormatCapsSize,
IntBuffer pBufferAttribs, int pBufferAttribsSize) throws Exception;
2004-02-15 22:46:58 +01:00
2003-08-17 18:38:57 +02:00
/**
2004-03-02 02:59:32 +01:00
* Destroys the Pbuffer. After this call, there will be no valid GL rendering context - regardless of whether this Pbuffer was
* the current rendering context or not.
2003-08-17 18:38:57 +02:00
*/
2004-02-18 18:48:26 +01:00
public synchronized void destroy() {
makeCurrent();
VBOTracker.remove(this);
2003-08-17 18:38:57 +02:00
nDestroy(handle);
}
/**
* Natively destroy any GL-related stuff
*/
2004-03-02 02:59:32 +01:00
private static native void nDestroy(int handle);
// -----------------------------------------------------------------------------------------
// ------------------------------- Render-to-Texture Methods -------------------------------
// -----------------------------------------------------------------------------------------
/**
* Sets a render-to-texture attribute.
* <p/>
* The attrib parameter can be one of MIPMAP_LEVEL and CUBE_MAP_FACE. When the attrib parameter is CUBE_MAP_FACE then the value
* parameter can be on of the following:
* <p/>
* TEXTURE_CUBE_MAP_POSITIVE_X TEXTURE_CUBE_MAP_NEGATIVE_X TEXTURE_CUBE_MAP_POSITIVE_Y TEXTURE_CUBE_MAP_NEGATIVE_Y
* TEXTURE_CUBE_MAP_POSITIVE_Z TEXTURE_CUBE_MAP_NEGATIVE_Z
*
* @param attrib
* @param value
*/
public synchronized void setAttrib(int attrib, int value) {
nSetAttrib(handle, attrib, value);
}
private static native void nSetAttrib(int handle, int attrib, int value);
/**
* Binds the currently bound texture to the buffer specified. The buffer can be one of the following:
* <p/>
* FRONT_LEFT_BUFFER FRONT_RIGHT_BUFFER BACK_LEFT_BUFFER BACK_RIGHT_BUFFER DEPTH_BUFFER
*
* @param buffer
*/
public synchronized void bindTexImage(int buffer) {
nBindTexImage(handle, buffer);
}
private static native void nBindTexImage(int handle, int buffer);
/**
* Releases the currently bound texture from the buffer specified.
*
* @param buffer
*/
public synchronized void releaseTexImage(int buffer) {
nReleaseTexImage(handle, buffer);
}
private static native void nReleaseTexImage(int handle, int buffer);
2004-02-18 18:48:26 +01:00
/**
* @return Returns the height.
*/
public int getHeight() {
return height;
}
2004-03-02 02:59:32 +01:00
2004-02-18 18:48:26 +01:00
/**
* @return Returns the width.
*/
public int getWidth() {
return width;
}
2004-03-02 02:59:32 +01:00
2003-08-17 18:38:57 +02:00
}