ContextAttribs: changed factory to constructor initialization

Fixed compatible spelling
Small pbuffer fix
This commit is contained in:
Ioannis Tsakpinis 2008-08-19 17:47:24 +00:00
parent d7ee23f9b2
commit 6ea785334e
10 changed files with 138 additions and 127 deletions

View File

@ -62,7 +62,7 @@ final class Context {
private final PeerInfo peer_info;
private final IntBuffer attribList;
private final boolean forwardCombatible;
private final boolean forwardCompatible;
/** Whether the context has been destroyed */
private boolean destroyed;
@ -111,10 +111,10 @@ final class Context {
this.peer_info = peer_info;
if ( attribs != null ) {
attribList = attribs.getAttribList();
forwardCombatible = attribs.isForwardCombatible();
forwardCompatible = attribs.isForwardCompatible();
} else {
attribList = null;
forwardCombatible = false;
forwardCompatible = false;
}
this.handle = implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null);
@ -180,7 +180,7 @@ final class Context {
thread = Thread.currentThread();
current_context_local.set(this);
implementation.makeCurrent(peer_info, handle);
GLContext.useContext(this, forwardCombatible);
GLContext.useContext(this, forwardCompatible);
}
ByteBuffer getHandle() {

View File

@ -45,16 +45,16 @@ import java.nio.IntBuffer;
* Use of this class is optional. If an OpenGL context is created without passing an instance of this class
* (or XGL_create_context is not supported), the old context creation code will be used. Use of ContextAttribs is required
* to create an OpenGL 3.0 or newer context. Support for debug and forward compatible mobes is not guaranteed by the OpenGL
* implementation. Developers may encounter debug contexts being the same as non-debug contexts or forward combatible
* implementation. Developers may encounter debug contexts being the same as non-debug contexts or forward compatible
* contexts having support for deprecated functionality.
* <p/>
* Warning: This functionality is currently available on the Windows platform only. However, if the forwardCombatible
* Warning: This functionality is currently available on the Windows platform only. However, if the forwardCompatible
* attribute is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0 specification). This
* means that developers can start working on cleaning up their applications without an OpenGL 3.0 complaint driver.
*
* @author spasi <spasi@users.sourceforge.net>
*/
public abstract class ContextAttribs {
public final class ContextAttribs {
private int majorVersion;
private int minorVersion;
@ -62,9 +62,13 @@ public abstract class ContextAttribs {
private int layerPlane;
private boolean debug;
private boolean forwardCombatible;
private boolean forwardCompatible;
protected ContextAttribs(final int majorVersion, final int minorVersion) {
public ContextAttribs() {
this(1, 0);
}
public ContextAttribs(final int majorVersion, final int minorVersion) {
if ( majorVersion < 0 ||
3 < majorVersion ||
minorVersion < 0 ||
@ -79,103 +83,76 @@ public abstract class ContextAttribs {
this.layerPlane = 0;
this.debug = false;
this.forwardCombatible = false;
this.forwardCompatible = false;
}
protected ContextAttribs(final ContextAttribs attribs) {
private ContextAttribs(final ContextAttribs attribs) {
this.majorVersion = attribs.majorVersion;
this.minorVersion = attribs.minorVersion;
this.layerPlane = attribs.layerPlane;
this.debug = attribs.debug;
this.forwardCombatible = attribs.forwardCombatible;
this.forwardCompatible = attribs.forwardCompatible;
}
public static ContextAttribs create() {
return create(1, 0);
}
public static ContextAttribs create(final int majorVersion, final int minorVersion) {
switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxContextAttribs(majorVersion, minorVersion);
case LWJGLUtil.PLATFORM_WINDOWS:
return new WindowsContextAttribs(majorVersion, minorVersion);
case LWJGLUtil.PLATFORM_MACOSX:
return new MacOSXContextAttribs(majorVersion, minorVersion);
default:
throw new IllegalStateException("Unsupported platform");
}
}
private static ContextAttribs create(final ContextAttribs attribs) {
switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxContextAttribs(attribs);
case LWJGLUtil.PLATFORM_WINDOWS:
return new WindowsContextAttribs(attribs);
case LWJGLUtil.PLATFORM_MACOSX:
return new MacOSXContextAttribs(attribs);
default:
throw new IllegalStateException("Unsupported platform");
}
}
public final int getMajorVersion() {
public int getMajorVersion() {
return majorVersion;
}
public final int getMinorVersion() {
public int getMinorVersion() {
return minorVersion;
}
public final int getLayerPlane() {
public int getLayerPlane() {
return layerPlane;
}
public final boolean isDebug() {
public boolean isDebug() {
return debug;
}
public final boolean isForwardCombatible() {
return forwardCombatible;
public boolean isForwardCompatible() {
return forwardCompatible;
}
public final ContextAttribs withLayer(final int layerPlane) {
public ContextAttribs withLayer(final int layerPlane) {
if ( layerPlane < 0 )
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
final ContextAttribs attribs = create(this);
final ContextAttribs attribs = new ContextAttribs(this);
attribs.layerPlane = layerPlane;
return attribs;
}
public final ContextAttribs withDebug(final boolean debug) {
final ContextAttribs attribs = create(this);
public ContextAttribs withDebug(final boolean debug) {
final ContextAttribs attribs = new ContextAttribs(this);
attribs.debug = debug;
return attribs;
}
public final ContextAttribs withForwardCombatible(final boolean forwardCombatible) {
final ContextAttribs attribs = create(this);
attribs.forwardCombatible = forwardCombatible;
public ContextAttribs withForwardCompatible(final boolean forwardCompatible) {
final ContextAttribs attribs = new ContextAttribs(this);
attribs.forwardCompatible = forwardCompatible;
return attribs;
}
protected abstract int getMajorVersionAttrib();
private static ContextAttribsImplementation getImplementation() {
switch ( LWJGLUtil.getPlatform() ) {
case LWJGLUtil.PLATFORM_LINUX:
return new LinuxContextAttribs();
case LWJGLUtil.PLATFORM_WINDOWS:
return new WindowsContextAttribs();
case LWJGLUtil.PLATFORM_MACOSX:
return new MacOSXContextAttribs();
default:
throw new IllegalStateException("Unsupported platform");
}
}
protected abstract int getMinorVersionAttrib();
IntBuffer getAttribList() {
ContextAttribsImplementation implementation = getImplementation();
protected abstract int getLayerPlaneAttrib();
protected abstract int getFlagsAttrib();
protected abstract int getDebugBit();
protected abstract int getForwardCombatibleBit();
final IntBuffer getAttribList() {
int attribCount = 0;
if ( !(majorVersion == 1 && minorVersion == 0) )
@ -185,9 +162,9 @@ public abstract class ContextAttribs {
int flags = 0;
if ( debug )
flags |= getDebugBit();
if ( forwardCombatible )
flags |= getForwardCombatibleBit();
flags |= implementation.getDebugBit();
if ( forwardCompatible )
flags |= implementation.getForwardCompatibleBit();
if ( 0 < flags )
attribCount++;
@ -197,13 +174,13 @@ public abstract class ContextAttribs {
final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);
if ( !(majorVersion == 1 && minorVersion == 0) ) {
attribs.put(getMajorVersionAttrib()).put(majorVersion);
attribs.put(getMinorVersionAttrib()).put(minorVersion);
attribs.put(implementation.getMajorVersionAttrib()).put(majorVersion);
attribs.put(implementation.getMinorVersionAttrib()).put(minorVersion);
}
if ( 0 < layerPlane )
attribs.put(getLayerPlaneAttrib()).put(layerPlane);
attribs.put(implementation.getLayerPlaneAttrib()).put(layerPlane);
if ( 0 < flags )
attribs.put(getFlagsAttrib()).put(flags);
attribs.put(implementation.getFlagsAttrib()).put(flags);
attribs.put(0);
attribs.rewind();

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2002-2008 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * 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 'LWJGL' 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.
*/
package org.lwjgl.opengl;
/** @author spasi <spasi@users.sourceforge.net> */
interface ContextAttribsImplementation {
int getMajorVersionAttrib();
int getMinorVersionAttrib();
int getLayerPlaneAttrib();
int getFlagsAttrib();
int getDebugBit();
int getForwardCompatibleBit();
}

View File

@ -291,16 +291,16 @@ public final class GLContext {
* of caps and function pointers will be used. <p>The reference to the context is held in a weak reference; therefore if no
* strong reference exists to the GL context it will automatically be forgotten by the VM at an indeterminate point in the
* future, freeing up a little RAM.
* <p>If forwardCombatible is true, function pointers of deprecated GL11-GL21 functionality will not be loaded. Calling a deprecated
* <p>If forwardCompatible is true, function pointers of deprecated GL11-GL21 functionality will not be loaded. Calling a deprecated
* function using the specified context will result in an <code>IllegalStateException</code>.
*
* @param context The context object, which uniquely identifies a GL context. If context is null, the native stubs are
* unloaded.
* @param forwardCombatible If the context is a forward combatible context (does not expose deprecated functionality, see XGL_ARB_create_context)
* @param forwardCompatible If the context is a forward compatible context (does not expose deprecated functionality, see XGL_ARB_create_context)
*
* @throws LWJGLException if context non-null, and the gl library can't be loaded or the basic GL11 functions can't be loaded
*/
public static synchronized void useContext(Object context, boolean forwardCombatible) throws LWJGLException {
public static synchronized void useContext(Object context, boolean forwardCompatible) throws LWJGLException {
if ( context == null ) {
ContextCapabilities.unloadAllStubs();
setCapabilities(null);
@ -321,7 +321,7 @@ public final class GLContext {
* as part of its capability discovery, but GL functions cannot be called before
* a capabilities object has been set.
*/
new ContextCapabilities(forwardCombatible);
new ContextCapabilities(forwardCompatible);
capability_cache.put(context, getCapabilities());
} else
setCapabilities(capabilities);

View File

@ -38,7 +38,7 @@ package org.lwjgl.opengl;
*
* @author spasi <spasi@users.sourceforge.net>
*/
final class LinuxContextAttribs extends ContextAttribs {
final class LinuxContextAttribs implements ContextAttribsImplementation {
private static final int GLX_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
private static final int GLX_CONTEXT_MINOR_VERSION_ARB = 0x2092;
@ -48,35 +48,30 @@ final class LinuxContextAttribs extends ContextAttribs {
private static final int GLX_CONTEXT_DEBUG_BIT_ARB = 0x0001;
private static final int GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
LinuxContextAttribs(final int majorVersion, final int minorVersion) {
super(majorVersion, minorVersion);
LinuxContextAttribs() {
}
LinuxContextAttribs(final ContextAttribs attribs) {
super(attribs);
}
protected int getMajorVersionAttrib() {
public int getMajorVersionAttrib() {
return GLX_CONTEXT_MAJOR_VERSION_ARB;
}
protected int getMinorVersionAttrib() {
public int getMinorVersionAttrib() {
return GLX_CONTEXT_MINOR_VERSION_ARB;
}
protected int getLayerPlaneAttrib() {
public int getLayerPlaneAttrib() {
return GLX_CONTEXT_LAYER_PLANE_ARB;
}
protected int getFlagsAttrib() {
public int getFlagsAttrib() {
return GLX_CONTEXT_FLAGS_ARB;
}
protected int getDebugBit() {
public int getDebugBit() {
return GLX_CONTEXT_DEBUG_BIT_ARB;
}
protected int getForwardCombatibleBit() {
public int getForwardCompatibleBit() {
return GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
}

View File

@ -38,7 +38,7 @@ package org.lwjgl.opengl;
*
* @author spasi <spasi@users.sourceforge.net>
*/
final class MacOSXContextAttribs extends ContextAttribs {
final class MacOSXContextAttribs implements ContextAttribsImplementation {
private static final int XGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
private static final int XGL_CONTEXT_MINOR_VERSION_ARB = 0x2092;
@ -48,35 +48,30 @@ final class MacOSXContextAttribs extends ContextAttribs {
private static final int XGL_CONTEXT_DEBUG_BIT_ARB = 0x0001;
private static final int XGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
MacOSXContextAttribs(final int majorVersion, final int minorVersion) {
super(majorVersion, minorVersion);
MacOSXContextAttribs() {
}
MacOSXContextAttribs(final ContextAttribs attribs) {
super(attribs);
}
protected int getMajorVersionAttrib() {
public int getMajorVersionAttrib() {
return XGL_CONTEXT_MAJOR_VERSION_ARB;
}
protected int getMinorVersionAttrib() {
public int getMinorVersionAttrib() {
return XGL_CONTEXT_MINOR_VERSION_ARB;
}
protected int getLayerPlaneAttrib() {
public int getLayerPlaneAttrib() {
return XGL_CONTEXT_LAYER_PLANE_ARB;
}
protected int getFlagsAttrib() {
public int getFlagsAttrib() {
return XGL_CONTEXT_FLAGS_ARB;
}
protected int getDebugBit() {
public int getDebugBit() {
return XGL_CONTEXT_DEBUG_BIT_ARB;
}
protected int getForwardCombatibleBit() {
public int getForwardCompatibleBit() {
return XGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
}

View File

@ -36,7 +36,7 @@ package org.lwjgl.opengl;
*
* @author spasi <spasi@users.sourceforge.net>
*/
final class WindowsContextAttribs extends ContextAttribs {
final class WindowsContextAttribs implements ContextAttribsImplementation {
private static final int WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
private static final int WGL_CONTEXT_MINOR_VERSION_ARB = 0x2092;
@ -46,35 +46,30 @@ final class WindowsContextAttribs extends ContextAttribs {
private static final int WGL_CONTEXT_DEBUG_BIT_ARB = 0x0001;
private static final int WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
WindowsContextAttribs(final int majorVersion, final int minorVersion) {
super(majorVersion, minorVersion);
WindowsContextAttribs() {
}
WindowsContextAttribs(final ContextAttribs attribs) {
super(attribs);
}
protected int getMajorVersionAttrib() {
public int getMajorVersionAttrib() {
return WGL_CONTEXT_MAJOR_VERSION_ARB;
}
protected int getMinorVersionAttrib() {
public int getMinorVersionAttrib() {
return WGL_CONTEXT_MINOR_VERSION_ARB;
}
protected int getLayerPlaneAttrib() {
public int getLayerPlaneAttrib() {
return WGL_CONTEXT_LAYER_PLANE_ARB;
}
protected int getFlagsAttrib() {
public int getFlagsAttrib() {
return WGL_CONTEXT_FLAGS_ARB;
}
protected int getDebugBit() {
public int getDebugBit() {
return WGL_CONTEXT_DEBUG_BIT_ARB;
}
protected int getForwardCombatibleBit() {
public int getForwardCompatibleBit() {
return WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
}

View File

@ -70,8 +70,8 @@ public class ContextCapabilitiesGenerator {
}
public static void generateInitializerPrologue(PrintWriter writer) {
writer.println("\t" + Utils.CONTEXT_CAPS_CLASS_NAME + "(boolean forwardCombatible) throws LWJGLException {");
writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCombatible);");
writer.println("\t" + Utils.CONTEXT_CAPS_CLASS_NAME + "(boolean forwardCompatible) throws LWJGLException {");
writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = " + ALL_INIT_METHOD_NAME + "(forwardCompatible);");
}
private static String translateFieldName(String interface_name) {
@ -116,13 +116,13 @@ public class ContextCapabilitiesGenerator {
}
public static void generateInitStubsPrologue(PrintWriter writer, boolean context_specific) {
writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "(boolean forwardCombatible) throws LWJGLException {");
writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "(boolean forwardCompatible) throws LWJGLException {");
if ( !context_specific ) {
writer.println("\t\tif (" + STUBS_LOADED_NAME + ")");
writer.println("\t\t\treturn GLContext.getSupportedExtensions();");
writer.println("\t\torg.lwjgl.opengl.GL11." + Utils.STUB_INITIALIZER_NAME + "();");
} else {
writer.println("\t\tif (!" + getAddressesInitializerName("GL11") + "(forwardCombatible))");
writer.println("\t\tif (!" + getAddressesInitializerName("GL11") + "(forwardCompatible))");
writer.println("\t\t\tthrow new LWJGLException(\"GL11 not supported\");");
}
// Try to initialize GL30.glGetStringi here, in case we have created an OpenGL 3.0 context
@ -154,7 +154,7 @@ public class ContextCapabilitiesGenerator {
writer.print(translateFieldName(d.getSimpleName()) + "\")");
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
if ( d.getAnnotation(DeprecatedGL.class) != null )
writer.print("forwardCombatible");
writer.print("forwardCompatible");
if ( d.getAnnotation(Dependent.class) != null ) {
if ( d.getAnnotation(DeprecatedGL.class) != null )
writer.print(",");
@ -186,7 +186,7 @@ public class ContextCapabilitiesGenerator {
DeprecatedGL deprecated = d.getAnnotation(DeprecatedGL.class);
Dependent dependent = d.getAnnotation(Dependent.class);
if ( deprecated != null )
writer.print("boolean forwardCombatible");
writer.print("boolean forwardCompatible");
if ( dependent != null ) {
if ( deprecated != null )
writer.print(",");
@ -202,7 +202,7 @@ public class ContextCapabilitiesGenerator {
writer.print("\t\t\t(");
if ( deprecated != null )
writer.print("forwardCombatible || ");
writer.print("forwardCompatible || ");
if ( dependent != null )
writer.print("!supported_extensions.contains(\"" + dependent.value() + "\") || ");
if ( deprecated != null || dependent != null )

View File

@ -33,7 +33,7 @@ package org.lwjgl.util.generator;
/**
* Use this annotation on extensions with deprecated functionality.
* Functions in such extensions marked with this annotation will not be loaded in a forward combatible context.
* Functions in such extensions marked with this annotation will not be loaded in a forward compatible context.
*
* @author spasi <spasi@users.sourceforge.net>
*/

View File

@ -68,7 +68,7 @@ static bool getExtensions(JNIEnv *env, WGLExtensions *extensions, jobject pixel_
return false;
}
dummy_hdc = GetDC(dummy_hwnd);
pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false, false);
pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false);
if (pixel_format_id == -1) {
closeWindow(&dummy_hwnd, &dummy_hdc);
return false;
@ -137,7 +137,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nCreate
WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
int pixel_format_id;
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
bool floating_point = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point", "Z"));
if ( pBufferAttribs != NULL ) {
pBufferAttribs_ptr = (const int *)(*env)->GetDirectBufferAddress(env, pBufferAttribs);
@ -152,7 +151,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nCreate
return;
}
dummy_hdc = GetDC(dummy_hwnd);
pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, false, true, false, floating_point);
pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, false, true, false);
if (pixel_format_id == -1) {
closeWindow(&dummy_hwnd, &dummy_hdc);
return;