Display.java: Moved Context creation to after createWindow to relax the requirement that the Display PeerInfo must be valid before createWindow(). This will help Windows get rid of a dummy window.

This commit is contained in:
Elias Naur 2006-09-19 13:41:18 +00:00
parent 08c39c86d2
commit def08f06f8
1 changed files with 28 additions and 9 deletions

View File

@ -123,7 +123,7 @@ public final class Display {
/** /**
* Fetch the Drawable from the Display. * Fetch the Drawable from the Display.
* *
* @return the Drawable corresponding to the Display context, or null it display is * @return the Drawable corresponding to the Display context, or null if display is
* not created. * not created.
*/ */
public static Drawable getDrawable() { public static Drawable getDrawable() {
@ -230,8 +230,10 @@ public final class Display {
if (fullscreen) if (fullscreen)
switchDisplayMode(); switchDisplayMode();
createWindow(); createWindow();
makeCurrent();
} catch (LWJGLException e) { } catch (LWJGLException e) {
destroyContext(); destroyContext();
destroyPeerInfo();
display_impl.resetDisplayMode(); display_impl.resetDisplayMode();
throw e; throw e;
} }
@ -262,12 +264,10 @@ public final class Display {
window_y = 0; window_y = 0;
} }
display_impl.createWindow(current_mode, fullscreen, window_x, window_y); display_impl.createWindow(current_mode, fullscreen, window_x, window_y);
makeCurrent(); window_created = true;
setTitle(title); setTitle(title);
initControls(); initControls();
setSwapInterval(swap_interval);
window_created = true;
// set cached window icon if exists // set cached window icon if exists
if(cached_icons != null) { if(cached_icons != null) {
@ -468,8 +468,10 @@ public final class Display {
display_impl.resetDisplayMode(); display_impl.resetDisplayMode();
} }
createWindow(); createWindow();
makeCurrent();
} catch (LWJGLException e) { } catch (LWJGLException e) {
destroyContext(); destroyContext();
destroyPeerInfo();
display_impl.resetDisplayMode(); display_impl.resetDisplayMode();
throw e; throw e;
} }
@ -679,12 +681,23 @@ public final class Display {
switchDisplayMode(); switchDisplayMode();
try { try {
peer_info = display_impl.createPeerInfo(pixel_format); peer_info = display_impl.createPeerInfo(pixel_format);
context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null);
try { try {
createWindow(); createWindow();
initContext(); try {
context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null);
try {
makeCurrent();
initContext();
} catch (LWJGLException e) {
destroyContext();
throw e;
}
} catch (LWJGLException e) {
destroyWindow();
throw e;
}
} catch (LWJGLException e) { } catch (LWJGLException e) {
destroyContext(); destroyPeerInfo();
throw e; throw e;
} }
} catch (LWJGLException e) { } catch (LWJGLException e) {
@ -694,6 +707,7 @@ public final class Display {
} }
private static void initContext() { private static void initContext() {
setSwapInterval(swap_interval);
// Put the window into orthographic projection mode with 1:1 pixel ratio. // Put the window into orthographic projection mode with 1:1 pixel ratio.
// We haven't used GLU here to do this to avoid an unnecessary dependency. // We haven't used GLU here to do this to avoid an unnecessary dependency.
GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glMatrixMode(GL11.GL_PROJECTION);
@ -759,15 +773,20 @@ public final class Display {
destroyWindow(); destroyWindow();
destroyContext(); destroyContext();
destroyPeerInfo();
x = y = -1; x = y = -1;
cached_icons = null; cached_icons = null;
reset(); reset();
} }
private static void destroyPeerInfo() {
peer_info.destroy();
peer_info = null;
}
private static void destroyContext() { private static void destroyContext() {
try { try {
context.forceDestroy(); context.forceDestroy();
peer_info.destroy();
} catch (LWJGLException e) { } catch (LWJGLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally { } finally {
@ -795,7 +814,7 @@ public final class Display {
* @return true if the window's native peer has been created * @return true if the window's native peer has been created
*/ */
public static boolean isCreated() { public static boolean isCreated() {
return context != null; return window_created;
} }
/** /**