diff --git a/src/java/org/lwjgl/generator/ContextCapabilitiesGenerator.java b/src/java/org/lwjgl/generator/ContextCapabilitiesGenerator.java index 7dea9423..5d70caa6 100644 --- a/src/java/org/lwjgl/generator/ContextCapabilitiesGenerator.java +++ b/src/java/org/lwjgl/generator/ContextCapabilitiesGenerator.java @@ -149,8 +149,30 @@ public class ContextCapabilitiesGenerator { writer.println("\t\treturn "); while (methods.hasNext()) { MethodDeclaration method = methods.next(); - writer.print("\t\t\t(" + Utils.getFunctionAddressName(d, method) + " = GLContext.getFunctionAddress(\""); - writer.print(method.getSimpleName() + "\")) != 0"); + writer.print("\t\t\t(" + Utils.getFunctionAddressName(d, method) + " = "); + PlatformDependent platform_dependent = method.getAnnotation(PlatformDependent.class); + if (platform_dependent != null) { + EnumSet platform_set = EnumSet.copyOf(Arrays.asList(platform_dependent.value())); + writer.print("GLContext.getPlatformSpecificFunctionAddress(\""); + writer.print(Platform.ALL.getPrefix() + "\", "); + writer.print("new String[]{"); + Iterator platforms = platform_set.iterator(); + while (platforms.hasNext()) { + writer.print("\"" + platforms.next().getOSPrefix() + "\""); + if(platforms.hasNext()) + writer.print(", "); + } + writer.print("}, new String[]{"); + platforms = platform_set.iterator(); + while (platforms.hasNext()) { + writer.print("\"" + platforms.next().getPrefix() + "\""); + if(platforms.hasNext()) + writer.print(", "); + } + writer.print("}, "); + } else + writer.print("GLContext.getFunctionAddress("); + writer.print("\"" + method.getSimpleName() + "\")) != 0"); if (methods.hasNext()) writer.println(" &&"); } diff --git a/src/java/org/lwjgl/generator/ContextGeneratorProcessorFactory.java b/src/java/org/lwjgl/generator/ContextGeneratorProcessorFactory.java index c69006e9..c2a88cde 100644 --- a/src/java/org/lwjgl/generator/ContextGeneratorProcessorFactory.java +++ b/src/java/org/lwjgl/generator/ContextGeneratorProcessorFactory.java @@ -127,10 +127,12 @@ public class ContextGeneratorProcessorFactory implements AnnotationProcessorFact InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl; ContextCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl); } - writer.println(); - for (TypeDeclaration typedecl : interface_decls) { - InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl; - ContextCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl); + if (context_specific) { + writer.println(); + for (TypeDeclaration typedecl : interface_decls) { + InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl; + ContextCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl); + } } ContextCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific); for (TypeDeclaration typedecl : interface_decls) { diff --git a/src/java/org/lwjgl/generator/Platform.java b/src/java/org/lwjgl/generator/Platform.java index acbcf761..3a6edc77 100644 --- a/src/java/org/lwjgl/generator/Platform.java +++ b/src/java/org/lwjgl/generator/Platform.java @@ -67,7 +67,18 @@ public enum Platform { writer.println("#endif"); } - public String getPostfix() { + public String getOSPrefix() { + switch (this) { + case WGL: + return "Windows"; + case GLX: + return "Linux"; + default: + throw new RuntimeException(this + " has no OS specific prefix"); + } + } + + public String getPrefix() { switch (this) { case WGL: return "wgl"; diff --git a/src/java/org/lwjgl/generator/RegisterStubsGenerator.java b/src/java/org/lwjgl/generator/RegisterStubsGenerator.java index 20815d37..978b5ae5 100644 --- a/src/java/org/lwjgl/generator/RegisterStubsGenerator.java +++ b/src/java/org/lwjgl/generator/RegisterStubsGenerator.java @@ -108,7 +108,7 @@ public class RegisterStubsGenerator { writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific)); if (mode == Mode.BUFFEROBJECT) writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); - String opengl_handle_name = method.getSimpleName().replaceFirst("gl", platform.getPostfix()); + String opengl_handle_name = method.getSimpleName().replaceFirst("gl", platform.getPrefix()); writer.print(", \"" + opengl_handle_name + "\", (void *)&" + method.getSimpleName() + "}"); if (has_more) writer.println(","); diff --git a/src/java/org/lwjgl/generator/TypeInfo.java b/src/java/org/lwjgl/generator/TypeInfo.java index 437b5885..103803a6 100644 --- a/src/java/org/lwjgl/generator/TypeInfo.java +++ b/src/java/org/lwjgl/generator/TypeInfo.java @@ -202,7 +202,7 @@ public class TypeInfo { } private static void getCrossProductRecursive(int index, ParameterDeclaration[] parameters, Map> typeinfos_map, HashMap current_instance, + Collection> typeinfos_map, Map current_instance, Collection> cross_product) { if (index == parameters.length) { cross_product.add(current_instance); @@ -212,7 +212,7 @@ public class TypeInfo { Collection typeinfos = typeinfos_map.get(param); if (typeinfos != null) { for (TypeInfo typeinfo : typeinfos) { - HashMap instance = (HashMap)current_instance.clone(); + Map instance = new HashMap(current_instance); instance.put(param, typeinfo); getCrossProductRecursive(index + 1, parameters, typeinfos_map, instance, cross_product); } diff --git a/src/java/org/lwjgl/opengl/ContextCapabilities.java b/src/java/org/lwjgl/opengl/ContextCapabilities.java index 4560301f..304baa72 100644 --- a/src/java/org/lwjgl/opengl/ContextCapabilities.java +++ b/src/java/org/lwjgl/opengl/ContextCapabilities.java @@ -1825,8 +1825,8 @@ public class ContextCapabilities { private boolean NV_vertex_array_range_initNativeFunctionAddresses() { return - (NV_vertex_array_range_glFreeMemoryNV_pointer = GLContext.getFunctionAddress("glFreeMemoryNV")) != 0 && - (NV_vertex_array_range_glAllocateMemoryNV_pointer = GLContext.getFunctionAddress("glAllocateMemoryNV")) != 0 && + (NV_vertex_array_range_glFreeMemoryNV_pointer = GLContext.getPlatformSpecificFunctionAddress("gl", new String[]{"Windows", "Linux"}, new String[]{"wgl", "glX"}, "glFreeMemoryNV")) != 0 && + (NV_vertex_array_range_glAllocateMemoryNV_pointer = GLContext.getPlatformSpecificFunctionAddress("gl", new String[]{"Windows", "Linux"}, new String[]{"wgl", "glX"}, "glAllocateMemoryNV")) != 0 && (NV_vertex_array_range_glFlushVertexArrayRangeNV_pointer = GLContext.getFunctionAddress("glFlushVertexArrayRangeNV")) != 0 && (NV_vertex_array_range_glVertexArrayRangeNV_pointer = GLContext.getFunctionAddress("glVertexArrayRangeNV")) != 0; } diff --git a/src/java/org/lwjgl/opengl/GLContext.java b/src/java/org/lwjgl/opengl/GLContext.java index 6ad18ddc..1c36325d 100644 --- a/src/java/org/lwjgl/opengl/GLContext.java +++ b/src/java/org/lwjgl/opengl/GLContext.java @@ -82,6 +82,21 @@ public final class GLContext { current_capabilities.set(capabilities); } + /** + * Helper method to get a pointer to a named function in the OpenGL library + * with a name dependent on the current platform + */ + static long getPlatformSpecificFunctionAddress(String function_prefix, String[] os_prefixes, String[] os_function_prefixes, String function) { + String os_name = System.getProperty("os.name"); + for (int i = 0; i < os_prefixes.length; i++) + if (os_name.startsWith(os_prefixes[i])) { + String platform_function_name = function.replaceFirst(function_prefix, os_function_prefixes[i]); + long address = getFunctionAddress(platform_function_name); + return address; + } + return 0; + } + /** * Helper method to get a pointer to a named function in the OpenGL library */