Fixed vsync bug

This commit is contained in:
Ioannis Tsakpinis 2004-03-28 20:29:52 +00:00
parent 9d55bbb302
commit 5fb7f5e0e2
1 changed files with 32 additions and 37 deletions

View File

@ -1,31 +1,31 @@
/* /*
* Copyright (c) 2002-2004 Light Weight Java Game Library Project * Copyright (c) 2002-2004 Light Weight Java Game Library Project
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
* met: * met:
* *
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* *
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* * Neither the name of 'Light Weight Java Game Library' nor the names of * * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived * its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
@ -35,7 +35,7 @@ package org.lwjgl.opengl;
/** /**
* This is the abstract class for a Window in LWJGL. LWJGL windows have some * This is the abstract class for a Window in LWJGL. LWJGL windows have some
* peculiar characteristics: * peculiar characteristics:
* *
* - width and height are always fixed and cannot be changed * - width and height are always fixed and cannot be changed
* - the position of the window may or may not be programmable but once specified * - the position of the window may or may not be programmable but once specified
* cannot be changed programmatically * cannot be changed programmatically
@ -43,7 +43,7 @@ package org.lwjgl.opengl;
* by the user or operating system * by the user or operating system
* - only one window may ever be open at once * - only one window may ever be open at once
* - the operating system may or may not be able to do fullscreen or windowed windows. * - the operating system may or may not be able to do fullscreen or windowed windows.
* *
* @author foo * @author foo
*/ */
@ -81,15 +81,12 @@ public final class Window {
/** Fullscreen */ /** Fullscreen */
private static boolean fullscreen; private static boolean fullscreen;
/** Vsync */
private static boolean vsync;
/** Tracks VBO state for the window context */ /** Tracks VBO state for the window context */
private static VBOTracker vbo_tracker; private static VBOTracker vbo_tracker;
/** A unique context object, so we can track different contexts between creates() and destroys() */ /** A unique context object, so we can track different contexts between creates() and destroys() */
private static Window context; private static Window context;
/** Whether we created the Mouse */ /** Whether we created the Mouse */
private static boolean createdMouse; private static boolean createdMouse;
@ -195,7 +192,7 @@ public final class Window {
* Minimize the game and allow the operating system's default display to become * Minimize the game and allow the operating system's default display to become
* visible. It is the responsibility of LWJGL's native code to restore the display * visible. It is the responsibility of LWJGL's native code to restore the display
* to its normal display settings. * to its normal display settings.
* *
* If the display is already minimized then this is a no-op. * If the display is already minimized then this is a no-op.
*/ */
public static native void minimize(); public static native void minimize();
@ -203,7 +200,7 @@ public final class Window {
/** /**
* Restore the game and hide the operating system away. It is the responsibility of * Restore the game and hide the operating system away. It is the responsibility of
* LWJGL's native code to restore the display to its game display settings. * LWJGL's native code to restore the display to its game display settings.
* *
* If the display is not minimized then this is a no-op/ * If the display is not minimized then this is a no-op/
*/ */
public static native void restore(); public static native void restore();
@ -214,7 +211,7 @@ public final class Window {
* every frame regardless, you can ignore this flag altogether. If you are * every frame regardless, you can ignore this flag altogether. If you are
* trying to be kind to other processes you can check this flag and only * trying to be kind to other processes you can check this flag and only
* redraw when it returns true. The flag is cleared when you call paint(). * redraw when it returns true. The flag is cleared when you call paint().
* *
* @return true if the window has been damaged by external changes * @return true if the window has been damaged by external changes
* and needs to repaint itself * and needs to repaint itself
*/ */
@ -233,7 +230,7 @@ public final class Window {
*/ */
public static void update() { public static void update() {
if (!isCreated()) if (!isCreated())
throw new IllegalStateException("Cannot determine update uncreated window"); throw new IllegalStateException("Cannot update uncreated window");
nUpdate(); nUpdate();
if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) { if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) {
Util.checkGLError(); Util.checkGLError();
@ -265,7 +262,7 @@ public final class Window {
* Swap double buffers. * Swap double buffers.
*/ */
private static native void swapBuffers(); private static native void swapBuffers();
/** /**
* Make the Window the current rendering context for GL calls. * Make the Window the current rendering context for GL calls.
*/ */
@ -275,12 +272,12 @@ public final class Window {
nMakeCurrent(); nMakeCurrent();
GLContext.useContext(context); GLContext.useContext(context);
} }
/** /**
* Make the window the current rendering context for GL calls. * Make the window the current rendering context for GL calls.
*/ */
private static native void nMakeCurrent(); private static native void nMakeCurrent();
/** /**
* Create a fullscreen window that matches the current display depth. Default common values are chosen * Create a fullscreen window that matches the current display depth. Default common values are chosen
* for common OpenGL rendering operations: you will get at least a 16-bit depth buffer, an 8 bit stencil * for common OpenGL rendering operations: you will get at least a 16-bit depth buffer, an 8 bit stencil
@ -309,7 +306,7 @@ public final class Window {
public static void create(String title, int bpp, int alpha, int depth, int stencil) throws LWJGLException { public static void create(String title, int bpp, int alpha, int depth, int stencil) throws LWJGLException {
create(title, bpp, alpha, depth, stencil, 0); create(title, bpp, alpha, depth, stencil, 0);
} }
/** /**
* Create a fullscreen window. If the underlying OS does not * Create a fullscreen window. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this * support fullscreen mode, then a window will be created instead. If this
@ -351,8 +348,6 @@ public final class Window {
* @param bpp Minimum bits per pixel * @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer * @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer * @param depth Minimum bits per pixel in depth 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.
* @throws LWJGLException if the window could not be created for any reason; typically because * @throws LWJGLException if the window could not be created for any reason; typically because
* the minimum requirements could not be met satisfactorily * the minimum requirements could not be met satisfactorily
*/ */
@ -475,7 +470,7 @@ public final class Window {
if (context == null) { if (context == null) {
return; return;
} }
// Automatically destroy keyboard, mouse, and controller // Automatically destroy keyboard, mouse, and controller
if (createdMouse && Mouse.isCreated()) { if (createdMouse && Mouse.isCreated()) {
Mouse.destroy(); Mouse.destroy();
@ -489,12 +484,12 @@ public final class Window {
Controller.destroy(); Controller.destroy();
createdController = false; createdController = false;
} }
makeCurrent(); makeCurrent();
nDestroy(); nDestroy();
context = null; context = null;
} }
/** /**
* @return the unique Window context (or null, if the Window has not been created) * @return the unique Window context (or null, if the Window has not been created)
*/ */
@ -505,7 +500,7 @@ public final class Window {
/** /**
* Destroy the native window peer. * Destroy the native window peer.
*/ */
private native static void nDestroy(); private static native void nDestroy();
/** /**
* @return true if the window's native peer has been created * @return true if the window's native peer has been created
@ -530,13 +525,13 @@ public final class Window {
* @return boolean * @return boolean
*/ */
public static boolean isVSyncEnabled() { public static boolean isVSyncEnabled() {
if (isCreated()) if (!isCreated())
throw new IllegalStateException("Cannot determine vsync state of uncreated window"); throw new IllegalStateException("Cannot determine vsync state of uncreated window");
return nIsVSyncEnabled(); return nIsVSyncEnabled();
} }
private static native boolean nIsVSyncEnabled(); private static native boolean nIsVSyncEnabled();
/** /**
* Enable or disable vertical monitor synchronization. This call is a best-attempt at changing * Enable or disable vertical monitor synchronization. This call is a best-attempt at changing
* the vertical refresh synchronization of the monitor, and is not guaranteed to be successful. * the vertical refresh synchronization of the monitor, and is not guaranteed to be successful.
@ -544,7 +539,7 @@ public final class Window {
* @param sync true to synchronize; false to ignore synchronization * @param sync true to synchronize; false to ignore synchronization
*/ */
public static void setVSyncEnabled(boolean sync) { public static void setVSyncEnabled(boolean sync) {
if (isCreated()) if (!isCreated())
throw new IllegalStateException("Cannot set vsync state of uncreated window"); throw new IllegalStateException("Cannot set vsync state of uncreated window");
nSetVSyncEnabled(sync); nSetVSyncEnabled(sync);
} }