Removed ability to share Display context in Pbuffer - it was too much trouble for little gain

This commit is contained in:
Elias Naur 2004-08-02 14:32:51 +00:00
parent adb35c3a2e
commit 6fb9a62cab
5 changed files with 20 additions and 98 deletions

View file

@ -156,46 +156,12 @@ public final class Pbuffer {
*/
private final int height;
/*
* The Display context that this buffer shares or null
*/
private final Object display_context;
static {
Sys.initialize();
}
/**
* Determine whether the Pbuffer is using the Display context.
*
* @return true of the Pbuffer is using the Display context, false if not.
*/
public boolean isUsingDisplayContext() {
return display_context != null;
}
/**
* Create an instance of a Pbuffer using the Display context. The buffer is single-buffered if possible.
* <p/>
* NOTE: The Pbuffer will use the same context as the Display and requires that the Display has been created. Therefore,
* no separate pixel format can be specified. All OpenGL state,
* including display lists, textures etc. is shared between the Pbuffer and the Display. If the Display is destroyed,
* the Pbuffer will not be usable, even if the Display is created again.
* <p/>
* This kind of Pbuffer is the fastest, because the context switch overhead is minimum.
*
* @param width Pbuffer width
* @param height Pbuffer height
*/
public static Pbuffer createPbufferUsingDisplayContext(int width, int height, RenderTexture renderTexture) throws LWJGLException {
if (!Display.isCreated())
throw new IllegalStateException("The Display must be created before a shared Pbuffer can be created that use the Display context");
ByteBuffer handle = createPbuffer(true, width, height, null, renderTexture);
return new Pbuffer(width, height, Display.getContext(), handle);
}
/**
* Create an instance of a Pbuffer with a unique OpenGL context. The buffer is single-buffered if possible.
* 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.
@ -212,26 +178,20 @@ public final class Pbuffer {
* @param pixel_format Minimum Pbuffer context properties
* @param renderTexture
*/
public static Pbuffer createPbufferUsingUniqueContext(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
ByteBuffer handle = createPbuffer(false, width, height, pixel_format, renderTexture);
return new Pbuffer(width, height, null, handle);
}
private Pbuffer(int width, int height, Object display_context, ByteBuffer handle) {
public Pbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
this.width = width;
this.height = height;
this.display_context = display_context;
this.handle = handle;
this.handle = createPbuffer(width, height, pixel_format, renderTexture);
}
private static ByteBuffer createPbuffer(boolean use_display_context, int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
private static ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format, RenderTexture renderTexture) throws LWJGLException {
GLContext.loadOpenGLLibrary();
try {
ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE);
if ( renderTexture == null )
nCreate(handle, use_display_context, width, height, pixel_format, null, null);
nCreate(handle, width, height, pixel_format, null, null);
else
nCreate(handle, use_display_context, width, height, pixel_format,
nCreate(handle, width, height, pixel_format,
renderTexture.pixelFormatCaps,
renderTexture.pBufferAttribs);
return handle;
@ -262,11 +222,8 @@ public final class Pbuffer {
* @throws LWJGLException if the context could not be made current
*/
public void makeCurrent() throws LWJGLException {
if (display_context != null && display_context != Display.getContext())
throw new IllegalStateException("Cannot make a Pbuffer current after the Display has been destroyed");
nMakeCurrent(handle);
if (display_context == null)
GLContext.useContext(this);
GLContext.useContext(this);
}
/**
@ -284,7 +241,7 @@ public final class Pbuffer {
/**
* Native method to create a Pbuffer
*/
private static native void nCreate(ByteBuffer handle, boolean shared, int width, int height, PixelFormat pixel_format,
private static native void nCreate(ByteBuffer handle, int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException;

View file

@ -96,7 +96,7 @@ public class PbufferTest {
private void initialize() {
try {
//find displaymode
pbuffer = Pbuffer.createPbufferUsingUniqueContext(512, 512, new PixelFormat(), null);
pbuffer = new Pbuffer(512, 512, new PixelFormat(), 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 = Pbuffer.createPbufferUsingUniqueContext(512, 512, new PixelFormat(), null);
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
initPbuffer();
} catch (LWJGLException e) {
e.printStackTrace();

View file

@ -70,10 +70,10 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_getPbufferCaps
/*
* Class: org_lwjgl_opengl_Pbuffer
* Method: nCreate
* Signature: (Ljava/nio/ByteBuffer;ZIILorg/lwjgl/opengl/PixelFormat;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V
* Signature: (Ljava/nio/ByteBuffer;IILorg/lwjgl/opengl/PixelFormat;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
(JNIEnv *, jclass, jobject, jboolean, jint, jint, jobject, jobject, jobject);
(JNIEnv *, jclass, jobject, jint, jint, jobject, jobject, jobject);
/*
* Class: org_lwjgl_opengl_Pbuffer

View file

@ -535,13 +535,10 @@ static void destroyContext(void) {
}
static bool initWindowGLX13(JNIEnv *env, jobject pixel_format) {
configs = chooseVisualGLX13(env, pixel_format, true, GLX_WINDOW_BIT | GLX_PBUFFER_BIT, true);
configs = chooseVisualGLX13(env, pixel_format, true, GLX_WINDOW_BIT, true);
if (configs == NULL) {
configs = chooseVisualGLX13(env, pixel_format, true, GLX_WINDOW_BIT, true);
if (configs == NULL) {
throwException(env, "Could not find a matching pixel format");
return false;
}
throwException(env, "Could not find a matching pixel format");
return false;
}
context = glXCreateNewContext(getDisplay(), configs[0], GLX_RGBA_TYPE, NULL, True);
if (context == NULL) {

View file

@ -48,7 +48,6 @@
typedef struct _PbufferInfo {
GLXPbuffer buffer;
GLXContext context;
bool use_display_context;
} PbufferInfo;
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
@ -69,8 +68,7 @@ static void destroyPbuffer(PbufferInfo *buffer_info) {
GLXPbuffer buffer = buffer_info->buffer;
GLXContext context = buffer_info->context;
glXDestroyPbuffer(getDisplay(), buffer);
if (!buffer_info->use_display_context)
glXDestroyContext(getDisplay(), context);
glXDestroyContext(getDisplay(), context);
decDisplay();
}
@ -100,11 +98,8 @@ static bool checkPbufferCaps(JNIEnv *env, GLXFBConfig config, int width, int hei
static bool createPbufferUsingUniqueContext(JNIEnv *env, PbufferInfo *pbuffer_info, jobject pixel_format, int width, int height, const int *buffer_attribs) {
GLXFBConfig *configs = chooseVisualGLX13(env, pixel_format, false, GLX_PBUFFER_BIT, false);
if (configs == NULL) {
GLXFBConfig *configs = chooseVisualGLX13(env, pixel_format, false, GLX_PBUFFER_BIT, true);
if (configs == NULL) {
throwException(env, "No matching pixel format");
return false;
}
throwException(env, "No matching pixel format");
return false;
}
if (!checkPbufferCaps(env, configs[0], width, height)) {
XFree(configs);
@ -174,29 +169,7 @@ static GLXFBConfig chooseSingleBufferedConfigFromConfig(const GLXFBConfig orig_c
return NULL;
}
static bool createPbufferUsingDisplayContext(JNIEnv *env, PbufferInfo *buffer_info, int width, int height, const int *buffer_attribs) {
if (!checkPbufferCaps(env, getCurrentGLXFBConfig(), width, height)) {
return false;
}
int drawable_type;
if (glXGetFBConfigAttrib(getDisplay(), getCurrentGLXFBConfig(), GLX_DRAWABLE_TYPE, &drawable_type) != Success) {
throwException(env, "Could not get GLX_DRAWABLE_TYPE attribute from Display context");
return false;
}
if (drawable_type & GLX_PBUFFER_BIT == 0) {
throwException(env, "Display context does not support Pbuffers");
return false;
}
GLXFBConfig config = chooseSingleBufferedConfigFromConfig(getCurrentGLXFBConfig());
if (config == NULL)
config = getCurrentGLXFBConfig();
GLXPbuffer buffer = glXCreatePbuffer(getDisplay(), config, buffer_attribs);
buffer_info->buffer = buffer;
buffer_info->context = getCurrentGLXContext();
return true;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jobject handle_buffer, jboolean use_display_context, jint width, jint height, jobject pixel_format, jobject pixelFormatCaps, jobject pBufferAttribs)
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jobject handle_buffer, jint width, jint height, jobject pixel_format, jobject pixelFormatCaps, jobject pBufferAttribs)
{
Display *disp = incDisplay(env);
if (disp == NULL) {
@ -221,13 +194,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass
return;
}
PbufferInfo *buffer_info = (PbufferInfo *)env->GetDirectBufferAddress(handle_buffer);
buffer_info->use_display_context = use_display_context;
bool result;
if (use_display_context) {
result = createPbufferUsingDisplayContext(env, buffer_info, width, height, buffer_attribs);
} else {
result = createPbufferUsingUniqueContext(env, buffer_info, pixel_format, width, height, buffer_attribs);
}
result = createPbufferUsingUniqueContext(env, buffer_info, pixel_format, width, height, buffer_attribs);
if (!result || !checkXError(env)) {
decDisplay();
destroyPbuffer(buffer_info);