Moved loaded_stubs from GLContext to ContextCapabilities

This commit is contained in:
Elias Naur 2005-02-17 10:27:13 +00:00
parent 94a8c16bb9
commit 1310678934
4 changed files with 21 additions and 12 deletions

View File

@ -55,14 +55,18 @@ import java.lang.annotation.Annotation;
* @version $Revision$
*/
public class ContextCapabilitiesGenerator {
private final static String STUBS_LOADED_NAME = "loaded_stubs";
private final static String ALL_INIT_METHOD_NAME = "initAllStubs";
private final static String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
private final static String CACHED_EXTS_VAR_NAME = "supported_extensions";
private final static String EXTENSION_PREFIX = "GL_";
private final static String CORE_PREFIX = "Open";
public static void generateClassPrologue(PrintWriter writer) {
public static void generateClassPrologue(PrintWriter writer, boolean context_specific) {
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
if (!context_specific) {
writer.println("\tprivate static boolean " + STUBS_LOADED_NAME + " = false;");
}
}
public static void generateInitializerPrologue(PrintWriter writer) {
@ -101,6 +105,8 @@ public class ContextCapabilitiesGenerator {
public static void generateInitStubsPrologue(PrintWriter writer, boolean context_specific) {
writer.println("\tprivate Set " + ALL_INIT_METHOD_NAME + "() 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.initNativeStubs();");
} else {
writer.println("\t\tif (!" + getAddressesInitializerName("GL11") + "())");
@ -110,7 +116,10 @@ public class ContextCapabilitiesGenerator {
writer.println("\t\tSet " + CACHED_EXTS_VAR_NAME + " = GLContext.getSupportedExtensions();");
}
public static void generateInitStubsEpilogue(PrintWriter writer) {
public static void generateInitStubsEpilogue(PrintWriter writer, boolean context_specific) {
if (!context_specific) {
writer.println("\t\t" + STUBS_LOADED_NAME + " = true;");
}
writer.println("\t\treturn " + CACHED_EXTS_VAR_NAME + ";");
writer.println("\t}");
}

View File

@ -114,7 +114,7 @@ public class ContextGeneratorProcessorFactory implements AnnotationProcessorFact
writer.println("import org.lwjgl.LWJGLException;");
writer.println("import java.util.Set;");
writer.println();
ContextCapabilitiesGenerator.generateClassPrologue(writer);
ContextCapabilitiesGenerator.generateClassPrologue(writer, context_specific);
DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
Collection<TypeDeclaration> interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
for (TypeDeclaration typedecl : interface_decls) {
@ -127,12 +127,13 @@ public class ContextGeneratorProcessorFactory implements AnnotationProcessorFact
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
ContextCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl);
}
writer.println();
if (context_specific) {
writer.println();
for (TypeDeclaration typedecl : interface_decls) {
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
ContextCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl);
}
writer.println();
}
ContextCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
for (TypeDeclaration typedecl : interface_decls) {
@ -147,14 +148,17 @@ public class ContextGeneratorProcessorFactory implements AnnotationProcessorFact
continue;
ContextCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
}
ContextCapabilitiesGenerator.generateInitStubsEpilogue(writer);
ContextCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
writer.println();
writer.println("\tstatic void unloadAllStubs() {");
if (!context_specific) {
writer.println("\t\tif (!loaded_stubs)");
writer.println("\t\t\treturn;");
for (TypeDeclaration typedecl : interface_decls) {
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
ContextCapabilitiesGenerator.generateUnloadStubs(writer, interface_decl);
}
writer.println("\t\tloaded_stubs = false;");
}
writer.println("\t}");
writer.println();

View File

@ -1862,6 +1862,7 @@ public class ContextCapabilities {
(NV_vertex_program_glExecuteProgramNV_pointer = GLContext.getFunctionAddress("glExecuteProgramNV")) != 0;
}
private Set initAllStubs() throws LWJGLException {
if (!GL11_initNativeFunctionAddresses())
throw new LWJGLException("GL11 not supported");

View File

@ -56,7 +56,6 @@ public final class GLContext {
/** Map of classes that have native stubs loaded */
private static int gl_ref_count;
private static boolean did_auto_load;
private static boolean loaded_stubs;
static {
Sys.initialize();
@ -173,10 +172,7 @@ public final class GLContext {
}
private static void loadStubs() throws LWJGLException {
if (loaded_stubs)
return;
new ContextCapabilities();
loaded_stubs = true;
}
/**
@ -194,7 +190,7 @@ public final class GLContext {
* @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 void useContext(Object context) throws LWJGLException {
if ( context == null ) {
if (context == null) {
ContextCapabilities.unloadAllStubs();
setCapabilities(null);
if (did_auto_load)
@ -202,8 +198,7 @@ public final class GLContext {
BufferObjectTracker.setCurrent(null);
return;
}
// Ok, now it's the current context.
if ( gl_ref_count == 0 ) {
if (gl_ref_count == 0) {
loadOpenGLLibrary();
did_auto_load = true;
}