From 5fb7f5e0e26189ed9dcaf34a88522385a85139ce Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Sun, 28 Mar 2004 20:29:52 +0000 Subject: [PATCH] Fixed vsync bug --- src/java/org/lwjgl/opengl/Window.java | 69 +++++++++++++-------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/src/java/org/lwjgl/opengl/Window.java b/src/java/org/lwjgl/opengl/Window.java index 2767842f..a8968254 100644 --- a/src/java/org/lwjgl/opengl/Window.java +++ b/src/java/org/lwjgl/opengl/Window.java @@ -1,31 +1,31 @@ -/* +/* * Copyright (c) 2002-2004 Light Weight Java Game Library Project * All rights reserved. - * + * * 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: - * - * * 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. * * * 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. * - * * Neither the name of 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * 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 - * 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 + * 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 * 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 * 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 * peculiar characteristics: - * + * * - width and height are always fixed and cannot be changed * - the position of the window may or may not be programmable but once specified * cannot be changed programmatically @@ -43,7 +43,7 @@ package org.lwjgl.opengl; * by the user or operating system * - only one window may ever be open at once * - the operating system may or may not be able to do fullscreen or windowed windows. - * + * * @author foo */ @@ -81,15 +81,12 @@ public final class Window { /** Fullscreen */ private static boolean fullscreen; - /** Vsync */ - private static boolean vsync; - /** Tracks VBO state for the window context */ private static VBOTracker vbo_tracker; - + /** A unique context object, so we can track different contexts between creates() and destroys() */ private static Window context; - + /** Whether we created the Mouse */ 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 * visible. It is the responsibility of LWJGL's native code to restore the display * to its normal display settings. - * + * * If the display is already minimized then this is a no-op. */ 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 * 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/ */ 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 * 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(). - * + * * @return true if the window has been damaged by external changes * and needs to repaint itself */ @@ -233,7 +230,7 @@ public final class Window { */ public static void update() { if (!isCreated()) - throw new IllegalStateException("Cannot determine update uncreated window"); + throw new IllegalStateException("Cannot update uncreated window"); nUpdate(); if ((isDirty() && !isMinimized()) || (isFocused() && !isMinimized())) { Util.checkGLError(); @@ -265,7 +262,7 @@ public final class Window { * Swap double buffers. */ private static native void swapBuffers(); - + /** * Make the Window the current rendering context for GL calls. */ @@ -275,12 +272,12 @@ public final class Window { nMakeCurrent(); GLContext.useContext(context); } - + /** * Make the window the current rendering context for GL calls. */ private static native void nMakeCurrent(); - + /** * 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 @@ -309,7 +306,7 @@ public final class Window { public static void create(String title, int bpp, int alpha, int depth, int stencil) throws LWJGLException { create(title, bpp, alpha, depth, stencil, 0); } - + /** * Create a fullscreen window. If the underlying OS does not * 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 alpha Minimum bits per pixel in alpha 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 * the minimum requirements could not be met satisfactorily */ @@ -475,7 +470,7 @@ public final class Window { if (context == null) { return; } - + // Automatically destroy keyboard, mouse, and controller if (createdMouse && Mouse.isCreated()) { Mouse.destroy(); @@ -489,12 +484,12 @@ public final class Window { Controller.destroy(); createdController = false; } - + makeCurrent(); nDestroy(); context = null; } - + /** * @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. */ - private native static void nDestroy(); + private static native void nDestroy(); /** * @return true if the window's native peer has been created @@ -530,13 +525,13 @@ public final class Window { * @return boolean */ public static boolean isVSyncEnabled() { - if (isCreated()) + if (!isCreated()) throw new IllegalStateException("Cannot determine vsync state of uncreated window"); return nIsVSyncEnabled(); } private static native boolean nIsVSyncEnabled(); - + /** * 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. @@ -544,7 +539,7 @@ public final class Window { * @param sync true to synchronize; false to ignore synchronization */ public static void setVSyncEnabled(boolean sync) { - if (isCreated()) + if (!isCreated()) throw new IllegalStateException("Cannot set vsync state of uncreated window"); nSetVSyncEnabled(sync); }