Skip to content

Commit

Permalink
Make reload use the MissingSymbolCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
mdparker committed Mar 13, 2017
1 parent 42602eb commit f9bc5d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/derelict/opengl3/gl3.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 95,7 @@ class DerelictGL3Loader : SharedLibLoader
if(maxVer > maxVersion)
maxVer = maxVersion;

initExtensionCache(glVer, missingSymbolCallback);

if(maxVer >= GLVersion.GL12) {
bindGLFunc(cast(void**)&glDrawRangeElements, "glDrawRangeElements");
Expand Down Expand Up @@ -442,7 443,6 @@ class DerelictGL3Loader : SharedLibLoader
// the findMaxAvailable method
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

initExtensionCache(glVer);
loadARB(glVer);
loadEXT(glVer);
loadPlatformEXT( glVer );
Expand Down
21 changes: 14 additions & 7 deletions source/derelict/opengl3/internal.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 30,39 @@ module derelict.opengl3.internal;
private {
import std.array;

import derelict.util.system;
import derelict.opengl3.types;
import derelict.opengl3.constants;
import derelict.opengl3.functions;
import derelict.util.exception,
derelict.util.system;
import derelict.opengl3.constants,
derelict.opengl3.functions,
derelict.opengl3.types;
static if(Derelict_OS_Windows) import derelict.opengl3.wgl;
else static if(Derelict_OS_Mac) import derelict.opengl3.cgl;
else static if(Derelict_OS_Posix) import derelict.opengl3.glx;
}

private {
Appender!(const(char)*[]) _extCache;
MissingSymbolCallback symCallback;
}

package {
void bindGLFunc(void** ptr, string symName) {
import derelict.util.exception : SymbolLoadException;

auto sym = loadGLFunc(symName);
if(!sym)
throw new SymbolLoadException("Failed to load OpenGL symbol [" ~ symName ~ "]");
if(!sym) {
if(symCallback == null || symCallback(symName) == ShouldThrow.Yes)
throw new SymbolLoadException("Failed to load OpenGL symbol [" ~ symName ~ "]");
else return;
}
*ptr = sym;
}

/*
This is called from DerelictGL3.reload to reset the extension name cache,
since supported extensions can potentially vary from context to context.
*/
void initExtensionCache(GLVersion glversion) {
void initExtensionCache(GLVersion glversion, MissingSymbolCallback callback) {
// There's no need to cache extension names using the pre-3.0 glString
// technique, but the modern style of using glStringi results in a high
// number of calls when testing for every extension Derelict supports.
Expand All @@ -74,6 79,8 @@ package {
_extCache.put(glGetStringi(GL_EXTENSIONS, i));
}
}

symCallback = callback;
}

// Assumes that name is null-terminated, i.e. a string literal
Expand Down

0 comments on commit f9bc5d2

Please sign in to comment.