Skip to content

Commit

Permalink
Make CGL/GLX/WGL usable without a current context
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Mar 28, 2016
1 parent 90247e1 commit 364b881
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
19 changes: 10 additions & 9 deletions modules/core/src/main/java/org/lwjgl/opengl/GL.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,19 @@ long getExtensionAddress(long name) {
break;
case LINUX:
functionProvider = new FunctionProviderGL() {
private final long glXGetProcAddress = OPENGL.getFunctionAddress("glXGetProcAddress");
private final long glXGetProcAddressARB = OPENGL.getFunctionAddress("glXGetProcAddressARB");
private final long glXGetProcAddress;

@Override
long getExtensionAddress(long name) {
if ( glXGetProcAddress != NULL )
return callPP(glXGetProcAddress, name);
{
long GetProcAddress = OPENGL.getFunctionAddress("glXGetProcAddress");
if ( GetProcAddress == NULL )
GetProcAddress = OPENGL.getFunctionAddress("glXGetProcAddressARB");

if ( glXGetProcAddressARB != NULL )
return callPP(glXGetProcAddressARB, name);
glXGetProcAddress = GetProcAddress;
}

return NULL;
@Override
long getExtensionAddress(long name) {
return glXGetProcAddress == NULL ? NULL : callPP(glXGetProcAddress, name);
}
};
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.WGL.*;
import static org.lwjgl.system.JNI.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.jawt.JAWTFunctions.*;
import static org.lwjgl.system.windows.GDI32.*;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void paint(Graphics g) {
createContext(dsi_win);
gears.initGLState();
} else {
if ( callPPI(caps.wglMakeCurrent, hdc, hglrc) == 0 )
if ( wglMakeCurrent(hdc, hglrc) == 0 )
throw new IllegalStateException("wglMakeCurrent() failed");

GL.setCapabilities(caps);
Expand Down Expand Up @@ -134,12 +133,12 @@ private void createContext(JAWTWin32DrawingSurfaceInfo dsi_win) {
throw new IllegalStateException("SetPixelFormat() failed: " + WinBase.getLastError());
}

hglrc = callPP(caps.wglCreateContext, hdc);
hglrc = wglCreateContext(hdc);

if ( hglrc == NULL )
throw new IllegalStateException("wglCreateContext() failed");

if ( callPPI(caps.wglMakeCurrent, hdc, hglrc) == 0 )
if ( wglMakeCurrent(hdc, hglrc) == 0 )
throw new IllegalStateException("wglMakeCurrent() failed");

caps = GL.createCapabilities();
Expand All @@ -152,7 +151,7 @@ public void destroy() {
awt.free();

if ( hglrc != NULL )
callPI(caps.wglDeleteContext, hglrc);
wglDeleteContext(hglrc);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,13 @@ val GLBinding = Generator.register(object : APIBinding(OPENGL_PACKAGE, CAPABILIT

fun String.nativeClassGL(
templateName: String,
nativeSubPath: String = "",
prefix: String = "GL",
prefixMethod: String = prefix.toLowerCase(),
postfix: String = "",
init: (NativeClass.() -> Unit)? = null
) = nativeClass(
OPENGL_PACKAGE,
templateName,
nativeSubPath = nativeSubPath,
prefix = prefix,
prefixMethod = prefixMethod,
postfix = postfix,
Expand All @@ -227,10 +225,10 @@ fun String.nativeClassGL(
)

fun String.nativeClassWGL(templateName: String, postfix: String = "", init: (NativeClass.() -> Unit)? = null) =
nativeClassGL(templateName, "wgl", "WGL", postfix = postfix, init = init)
nativeClassGL(templateName, "WGL", postfix = postfix, init = init)

fun String.nativeClassGLX(templateName: String, postfix: String = "", init: (NativeClass.() -> Unit)? = null) =
nativeClassGL(templateName, "glx", "GLX", "glX", postfix, init)
nativeClassGL(templateName, "GLX", "glX", postfix, init)

private val REGISTRY_PATTERN = Pattern.compile("([A-Z]+)_(\\w+)")
val NativeClass.registryLink: String get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import org.lwjgl.generator.*
import org.lwjgl.opengl.*
import org.lwjgl.system.macosx.*

val CGL = "CGL".nativeClass(OPENGL_PACKAGE, prefix = "CGL", prefixMethod = "CGL", prefixConstant = "kCGL", binding = GLBinding) {
val CGL = "CGL".nativeClass(
OPENGL_PACKAGE,
prefix = "CGL",
prefixConstant = "kCGL",
prefixMethod = "CGL",
binding = GLBinding.delegate("GL.getFunctionProvider()")
) {
documentation = "Native bindings to CGL."

// -----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.lwjgl.generator.*
import org.lwjgl.opengl.*
import org.lwjgl.system.linux.*

val GLX = "GLX".nativeClassGLX("GLX") {
val GLX = "GLX".nativeClass(OPENGL_PACKAGE, prefix = "GLX", prefixMethod = "glX", binding = GLBinding.delegate("GL.getFunctionProvider()")) {
javaImport(
"org.lwjgl.system.linux.*"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.lwjgl.generator.*
import org.lwjgl.opengl.*
import org.lwjgl.system.windows.*

val WGL = "WGL".nativeClassWGL("WGL") {
val WGL = "WGL".nativeClass(OPENGL_PACKAGE, prefix = "WGL", binding = GLBinding.delegate("GL.getFunctionProvider()")) {
javaImport(
"org.lwjgl.system.windows.*"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package org.lwjgl.opengl.templates

import org.lwjgl.generator.*
import org.lwjgl.opengl.*
import org.lwjgl.opengl.BufferType.*
import org.lwjgl.system.windows.*

val WGL_AMD_gpu_association = "WGLAMDGPUAssociation".nativeClassWGL("WGL_AMD_gpu_association", AMD) {
Expand Down

0 comments on commit 364b881

Please sign in to comment.