Added a Pbuffer argument to the Pbuffer constructor to enable sharing between pbuffers when the display is not created. Moved Pbuffer native methods into DisplayImplementation.

This commit is contained in:
Elias Naur 2005-01-11 13:53:12 +00:00
parent 28aff73635
commit 925139bc7d
11 changed files with 189 additions and 119 deletions

View file

@ -233,8 +233,36 @@ public interface DisplayImplementation {
void destroyCursor(Object cursor_handle);
/* Pbuffer caps */
/* Pbuffer */
int getPbufferCaps();
/**
* Method to test for buffer integrity
*/
public boolean isBufferLost(ByteBuffer handle);
/**
* Method to make a pbuffer current.
*/
public void makePbufferCurrent(ByteBuffer handle) throws LWJGLException;
/**
* Method to create a Pbuffer
*/
public ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
/**
* Destroy pbuffer
*/
public void destroyPbuffer(ByteBuffer handle);
public void setPbufferAttrib(ByteBuffer handle, int attrib, int value);
public void bindTexImageToPbuffer(ByteBuffer handle, int buffer);
public void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer);
boolean openURL(String url);
}

View file

@ -48,6 +48,7 @@ import org.lwjgl.LWJGLException;
final class LinuxDisplay implements DisplayImplementation {
private static final int CURSOR_HANDLE_SIZE = 8;
private static final int PBUFFER_HANDLE_SIZE = 24;
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
public native void destroyWindow();
@ -113,6 +114,37 @@ final class LinuxDisplay implements DisplayImplementation {
public native void destroyCursor(Object cursorHandle);
public native int getPbufferCaps();
public boolean isBufferLost(ByteBuffer handle) {
return false;
}
public native void makePbufferCurrent(ByteBuffer handle) throws LWJGLException;
public ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException {
ByteBuffer handle = BufferUtils.createByteBuffer(PBUFFER_HANDLE_SIZE);
nCreatePbuffer(handle, width, height, pixel_format, pixelFormatCaps, pBufferAttribs, shared_pbuffer_handle);
return handle;
}
private native void nCreatePbuffer(ByteBuffer handle, int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
public native void destroyPbuffer(ByteBuffer handle);
public void setPbufferAttrib(ByteBuffer handle, int attrib, int value) {
throw new UnsupportedOperationException();
}
public void bindTexImageToPbuffer(ByteBuffer handle, int buffer) {
throw new UnsupportedOperationException();
}
public void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer) {
throw new UnsupportedOperationException();
}
public boolean openURL(String url) {
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it

View file

@ -55,9 +55,11 @@ import java.util.ArrayList;
import java.util.List;
import org.lwjgl.LWJGLException;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;
final class MacOSXDisplay implements DisplayImplementation {
private static final int PBUFFER_HANDLE_SIZE = 24;
private static final int GAMMA_LENGTH = 256;
private MacOSXFrame frame;
@ -426,4 +428,36 @@ final class MacOSXDisplay implements DisplayImplementation {
return null;
}
}
public boolean isBufferLost(ByteBuffer handle) {
return false;
}
public native void makePbufferCurrent(ByteBuffer handle) throws LWJGLException;
public ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException {
ByteBuffer handle = BufferUtils.createByteBuffer(PBUFFER_HANDLE_SIZE);
nCreatePbuffer(handle, width, height, pixel_format, pixelFormatCaps, pBufferAttribs, shared_pbuffer_handle);
return handle;
}
private native void nCreatePbuffer(ByteBuffer handle, int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
public native void destroyPbuffer(ByteBuffer handle);
public void setPbufferAttrib(ByteBuffer handle, int attrib, int value) {
throw new UnsupportedOperationException();
}
public void bindTexImageToPbuffer(ByteBuffer handle, int buffer) {
throw new UnsupportedOperationException();
}
public void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer) {
throw new UnsupportedOperationException();
}
}

View file

@ -136,11 +136,6 @@ public final class Pbuffer {
*/
public static final int DEPTH_BUFFER = RenderTexture.WGL_DEPTH_COMPONENT_NV;
/**
* The maximum number of bytes in the native handle
*/
private static final int HANDLE_SIZE = 24;
/**
* Handle to the native GL rendering context
*/
@ -163,38 +158,38 @@ public final class Pbuffer {
/**
* Create an instance of a Pbuffer with a unique OpenGL context. The buffer is single-buffered.
* <p/>
* NOTE: The Pbuffer will have its own context that shares display lists and textures with the Display context (if it is created),
* 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/>
* This kind of Pbuffer is primarily intended for non interactive use, since the makeCurrent context switch will be more expensive
* than a Pbuffer using the Display context.
* NOTE: The Pbuffer will have its own context that shares display lists and textures with <code>shared_context</code>,
* or, if <code>shared_context</code> is <code>null</code>, the Display context if it is created. The Pbuffer
* will have its own OpenGL state. Therefore, state changes to a pbuffer will not be seen in the window context and vice versa.
* <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.
* <p/>
*
* @param width Pbuffer width
* @param height Pbuffer height
* @param pixel_format Minimum Pbuffer context properties
* @param renderTexture
* @param shared_context If non-null the Pbuffer will share display lists and textures with it. Otherwise, the Pbuffer will share
* with the Display context (if created).
*/
public Pbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
public Pbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture, Pbuffer shared_context) throws LWJGLException {
this.width = width;
this.height = height;
this.handle = createPbuffer(width, height, pixel_format, renderTexture);
this.handle = createPbuffer(width, height, pixel_format, renderTexture, shared_context != null ? shared_context.handle : null);
}
private static ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
private static ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture, ByteBuffer shared_context_handle) throws LWJGLException {
GLContext.loadOpenGLLibrary();
try {
ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE);
if ( renderTexture == null )
nCreate(handle, width, height, pixel_format, null, null);
return Display.getImplementation().createPbuffer(width, height, pixel_format, null, null, shared_context_handle);
else
nCreate(handle, width, height, pixel_format,
return Display.getImplementation().createPbuffer(width, height, pixel_format,
renderTexture.pixelFormatCaps,
renderTexture.pBufferAttribs);
return handle;
renderTexture.pBufferAttribs,
shared_context_handle);
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
@ -209,28 +204,18 @@ public final class Pbuffer {
* @return true if the buffer is lost and destroyed, false if the buffer is valid.
*/
public boolean isBufferLost() {
return nIsBufferLost(handle);
return Display.getImplementation().isBufferLost(handle);
}
/**
* Native method to test for buffer integrity
*/
private static native boolean nIsBufferLost(ByteBuffer handle);
/**
* Method to make the Pbuffer context current. All subsequent OpenGL calls will go to this buffer.
* @throws LWJGLException if the context could not be made current
*/
public void makeCurrent() throws LWJGLException {
nMakeCurrent(handle);
Display.getImplementation().makePbufferCurrent(handle);
GLContext.useContext(this);
}
/**
* Native method to make a pbuffer current.
*/
private static native void nMakeCurrent(ByteBuffer handle) throws LWJGLException;
/**
* Gets the Pbuffer capabilities.
*
@ -240,13 +225,6 @@ public final class Pbuffer {
return Display.getImplementation().getPbufferCaps();
}
/**
* Native method to create a Pbuffer
*/
private static native void nCreate(ByteBuffer handle, int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException;
/**
* 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.
@ -255,7 +233,7 @@ public final class Pbuffer {
try {
makeCurrent();
int error = GL11.glGetError();
nDestroy(handle);
Display.getImplementation().destroyPbuffer(handle);
GLContext.useContext(null);
GLContext.unloadOpenGLLibrary();
if (error != GL11.GL_NO_ERROR)
@ -265,11 +243,6 @@ public final class Pbuffer {
}
}
/**
* Natively destroy any GL-related stuff
*/
private static native void nDestroy(ByteBuffer handle);
// -----------------------------------------------------------------------------------------
// ------------------------------- Render-to-Texture Methods -------------------------------
// -----------------------------------------------------------------------------------------
@ -287,11 +260,9 @@ public final class Pbuffer {
* @param value
*/
public void setAttrib(int attrib, int value) {
nSetAttrib(handle, attrib, value);
Display.getImplementation().setPbufferAttrib(handle, attrib, value);
}
private static native void nSetAttrib(ByteBuffer handle, int attrib, int value);
/**
* Binds the currently bound texture to the buffer specified. The buffer can be one of the following:
* <p/>
@ -300,22 +271,18 @@ public final class Pbuffer {
* @param buffer
*/
public void bindTexImage(int buffer) {
nBindTexImage(handle, buffer);
Display.getImplementation().bindTexImageToPbuffer(handle, buffer);
}
private static native void nBindTexImage(ByteBuffer handle, int buffer);
/**
* Releases the currently bound texture from the buffer specified.
*
* @param buffer
*/
public void releaseTexImage(int buffer) {
nReleaseTexImage(handle, buffer);
Display.getImplementation().releaseTexImageFromPbuffer(handle, buffer);
}
private static native void nReleaseTexImage(ByteBuffer handle, int buffer);
/**
* @return Returns the height.
*/

View file

@ -47,6 +47,7 @@ import org.lwjgl.LWJGLException;
final class Win32Display implements DisplayImplementation {
private static final int CURSOR_HANDLE_SIZE = 8;
private static final int PBUFFER_HANDLE_SIZE = 24;
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
public native void destroyWindow();
@ -104,6 +105,27 @@ final class Win32Display implements DisplayImplementation {
public native void destroyCursor(Object cursorHandle);
public native int getPbufferCaps();
public native boolean isBufferLost(ByteBuffer handle);
public native void makePbufferCurrent(ByteBuffer handle) throws LWJGLException;
public ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException {
ByteBuffer handle = BufferUtils.createByteBuffer(PBUFFER_HANDLE_SIZE);
nCreatePbuffer(handle, width, height, pixel_format, pixelFormatCaps, pBufferAttribs, shared_pbuffer_handle);
return handle;
}
private native void nCreatePbuffer(ByteBuffer handle, int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
public native void destroyPbuffer(ByteBuffer handle);
public native void setPbufferAttrib(ByteBuffer handle, int attrib, int value);
public native void bindTexImageToPbuffer(ByteBuffer handle, int buffer);
public native void releaseTexImageFromPbuffer(ByteBuffer handle, int buffer);
public boolean openURL(String url) {
nOpenURL(url);
return true;

View file

@ -96,7 +96,7 @@ public class PbufferTest {
private void initialize() {
try {
//find displaymode
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null, null);
mode = findDisplayMode(800, 600, 16);
Display.setDisplayMode(mode);
// start of in windowed mode
@ -176,7 +176,7 @@ public class PbufferTest {
System.out.println("Buffer contents lost - will recreate the buffer");
pbuffer.destroy();
try {
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null, null);
initPbuffer();
} catch (LWJGLException e) {
e.printStackTrace();

View file

@ -47,7 +47,7 @@ final class UniqueRenderer extends TextureRenderer {
Pbuffer pbuffer = null;
try {
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), null);
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), null, null);
// Initialise state of the pbuffer context.
pbuffer.makeCurrent();

View file

@ -46,7 +46,7 @@ final class UniqueRendererRTT extends TextureRenderer {
try {
final RenderTexture rt = new RenderTexture(true, false, false, false, RenderTexture.RENDER_TEXTURE_2D, 0);
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), rt);
pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), rt, null);
// Initialise state of the pbuffer context.
pbuffer.makeCurrent();