lwjgl2-arm64/src/java/org/lwjgl/opengl/BaseGL.java

184 lines
5.2 KiB
Java
Raw Normal View History

2002-08-15 18:19:01 +02:00
/*
2002-12-21 13:37:20 +01:00
* Copyright (c) 2002 Lightweight Java Game Library Project
2002-08-15 18:19:01 +02:00
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
2002-08-09 12:56:30 +02:00
*
2002-08-15 18:19:01 +02:00
* * 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* 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.
2002-08-09 12:56:30 +02:00
*/
2002-08-15 18:19:01 +02:00
2002-08-09 12:56:30 +02:00
package org.lwjgl.opengl;
import org.lwjgl.*;
import org.lwjgl.Window;
2002-08-09 12:56:30 +02:00
/**
2002-08-15 18:19:01 +02:00
* $Id$
*
2002-08-09 12:56:30 +02:00
* The base GL functionality (no actual GL methods).
*
* Each instance of GL is only valid in the thread that creates it.
* In addition, only one instance may be the current GL context in any one
* thread. To make a GL instance the current context, use makeCurrent().
*
* This has been provided as a base class that we can use for either the
* full GL1.4 specification or as a cut-down OpenGL embedded spec. (aka
* a mini-driver).
*
2002-08-15 18:19:01 +02:00
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
2002-08-09 12:56:30 +02:00
*/
2003-03-28 20:02:24 +01:00
public class BaseGL extends Window {
2003-03-28 20:02:24 +01:00
static {
System.loadLibrary(Sys.getLibraryName());
}
2002-08-09 12:56:30 +02:00
/** The current rendering context */
2003-03-28 20:02:24 +01:00
//private static BaseGL currentContext;
2002-08-09 12:56:30 +02:00
/** Has the GL been created yet? */
private boolean created;
/** Handle to the native GL rendering context */
2002-08-09 12:56:30 +02:00
protected int handle;
2003-03-28 20:02:24 +01:00
/** Color bits */
protected final int color;
/** Alpha bits */
protected final int alpha;
/** Depth bits */
protected final int depth;
/** Stencil bits */
protected final int stencil;
private int x, y;
/** Fullscreen */
protected final boolean fullscreen;
2002-08-09 12:56:30 +02:00
/**
* Construct a windowed instance of GL. If the underlying OS does not
* support windowed mode, then the width and height must match the current
* display resolution, or an Exception will be thrown. Otherwise a fullscreen
* window will be created.
* @param title The title of the window
* @param x, y The position of the window. May be ignored.
* @param width, height The size of the window's client area
* @param bpp Require colour bits
* @param alpha Required alpha bits
* @param depth Required depth bits
* @param stencil Required stencil bits
*/
2003-03-28 20:07:50 +01:00
public BaseGL(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) {
super(title, x, y, width, height);
2003-03-28 20:02:24 +01:00
this.x = x;
this.y = y;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = false;
2002-08-09 12:56:30 +02:00
}
2002-08-09 12:56:30 +02:00
/**
* Construct a fullscreen instance of GL. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this
* fails too then an Exception will be thrown.
* @param title The title of the window
* @param x, y The position of the window. May be ignored.
* @param width, height The size of the window's client area
2002-08-09 12:56:30 +02:00
*/
2003-03-28 20:07:50 +01:00
public BaseGL(String title, int bpp, int alpha, int depth, int stencil) {
super(title, 0, 0, Display.getWidth(), Display.getHeight());
2003-03-28 20:02:24 +01:00
this.x = 0;
this.y = 0;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = true;
}
protected void doCreate() throws Exception {
2003-03-28 22:04:43 +01:00
nCreate(getTitle(), x, y, getWidth(), getHeight(), color, alpha, depth, stencil, fullscreen);
2002-08-09 12:56:30 +02:00
}
2003-03-30 21:26:39 +02:00
protected void doPaint() {
swapBuffers();
}
/**
* Swap the buffers.
*/
private native void swapBuffers();
2002-08-09 12:56:30 +02:00
/**
* Native method to create a windowed GL
2002-08-09 12:56:30 +02:00
*/
2003-03-28 20:02:24 +01:00
private native void nCreate(
2003-03-28 22:04:43 +01:00
String title,
2003-03-28 20:02:24 +01:00
int x,
int y,
int width,
int height,
int bpp,
int alpha,
int depth,
int stencil,
boolean fullscreen) throws Exception;
/* (non-Javadoc)
2003-03-28 20:02:24 +01:00
* @see org.lwjgl.Window#doDestroy()
*/
2003-03-28 20:02:24 +01:00
protected void doDestroy() {
nDestroyGL();
}
2003-03-28 20:02:24 +01:00
/**
* Natively destroy any GL-related stuff
*/
2003-03-28 20:02:24 +01:00
private native void nDestroyGL();
/**
* Make the GL context current to the current thread
*/
public native void makeContextCurrent();
/**
* Release the GL context
*/
public native void releaseContext();
2002-08-09 12:56:30 +02:00
}