Merge pull request #612 from Superbelko/migrate_bindbc

Migrate to bindbc
This commit is contained in:
Grim Maple 2022-06-02 20:41:37 +03:00 committed by GitHub
commit d92f668fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 297 additions and 143 deletions

View File

@ -582,7 +582,7 @@ in
{ {
assert (img.data.length); assert (img.data.length);
} }
body do
{ {
Compound!(bool, string) error(string errorMsg) Compound!(bool, string) error(string errorMsg)
{ {

View File

@ -5,48 +5,48 @@ public import fontconfig.fctypes;
extern( C ) @nogc nothrow { extern( C ) @nogc nothrow {
alias da_FC_FcObjectSetBuild = FcObjectSet * function(const char *first, ...); alias pFcObjectSetBuild = FcObjectSet * function(const char *first, ...);
alias da_FC_FcPatternCreate = FcPattern * function(); alias pFcPatternCreate = FcPattern * function();
alias da_FC_FcPatternAddBool = FcBool function(FcPattern *p, const char *object, FcBool b); alias pFcPatternAddBool = FcBool function(FcPattern *p, const char *object, FcBool b);
alias da_FC_FcFontList = FcFontSet * function(FcConfig *config, FcPattern *p, FcObjectSet *os); alias pFcFontList = FcFontSet * function(FcConfig *config, FcPattern *p, FcObjectSet *os);
alias da_FC_FcPatternDestroy = void function(FcPattern *p); alias pFcPatternDestroy = void function(FcPattern *p);
alias da_FC_FcObjectSetDestroy = void function(FcObjectSet *os); alias pFcObjectSetDestroy = void function(FcObjectSet *os);
alias da_FC_FcPatternGetString = FcResult function(const FcPattern *p, const char *object, int n, FcChar8 ** s); alias pFcPatternGetString = FcResult function(const FcPattern *p, const char *object, int n, FcChar8 ** s);
alias da_FC_FcPatternGetInteger = FcResult function(const FcPattern *p, const char *object, int n, int *i); alias pFcPatternGetInteger = FcResult function(const FcPattern *p, const char *object, int n, int *i);
alias da_FC_FcPatternGetBool = FcResult function(const FcPattern *p, const char *object, int n, FcBool *b); alias pFcPatternGetBool = FcResult function(const FcPattern *p, const char *object, int n, FcBool *b);
alias da_FC_FcFontSetDestroy = void function(FcFontSet *s); alias pFcFontSetDestroy = void function(FcFontSet *s);
} }
__gshared { __gshared {
da_FC_FcObjectSetBuild FcObjectSetBuild; pFcObjectSetBuild FcObjectSetBuild;
da_FC_FcPatternCreate FcPatternCreate; pFcPatternCreate FcPatternCreate;
da_FC_FcPatternAddBool FcPatternAddBool; pFcPatternAddBool FcPatternAddBool;
da_FC_FcFontList FcFontList; pFcFontList FcFontList;
da_FC_FcPatternDestroy FcPatternDestroy; pFcPatternDestroy FcPatternDestroy;
da_FC_FcObjectSetDestroy FcObjectSetDestroy; pFcObjectSetDestroy FcObjectSetDestroy;
da_FC_FcPatternGetString FcPatternGetString; pFcPatternGetString FcPatternGetString;
da_FC_FcPatternGetInteger FcPatternGetInteger; pFcPatternGetInteger FcPatternGetInteger;
da_FC_FcPatternGetBool FcPatternGetBool; pFcPatternGetBool FcPatternGetBool;
da_FC_FcFontSetDestroy FcFontSetDestroy; pFcFontSetDestroy FcFontSetDestroy;
} }
/+ /+

View File

@ -3,42 +3,88 @@ module fontconfig;
public import fontconfig.fctypes; public import fontconfig.fctypes;
public import fontconfig.functions; public import fontconfig.functions;
import bindbc.loader;
enum FCSupport {
noLibrary,
badLibrary,
// TODO: real versions and stuff
fc100 = 100,
}
private { private {
import derelict.util.loader; SharedLib lib;
import derelict.util.system; FCSupport loadedVersion;
static if( Derelict_OS_Windows )
enum libNames = "libfontconfig-1.dll";
else static if( Derelict_OS_Mac )
enum libNames = "/usr/local/lib/libfontconfig.dylib";
else static if( Derelict_OS_Posix )
enum libNames = "libfontconfig.so.1, libfontconfig.so";
else
static assert( 0, "Need to implement FontConfig libNames for this operating system." );
} }
class DerelictFCLoader : SharedLibLoader { @nogc nothrow:
public this() { void unloadFC()
super( libNames ); {
} if(lib != invalidHandle) {
lib.unload();
protected override void loadSymbols() {
bindFunc( cast( void** )&FcObjectSetBuild, "FcObjectSetBuild" );
bindFunc( cast( void** )&FcPatternCreate, "FcPatternCreate" );
bindFunc( cast( void** )&FcPatternAddBool, "FcPatternAddBool" );
bindFunc( cast( void** )&FcFontList, "FcFontList" );
bindFunc( cast( void** )&FcPatternDestroy, "FcPatternDestroy" );
bindFunc( cast( void** )&FcObjectSetDestroy, "FcObjectSetDestroy" );
bindFunc( cast( void** )&FcPatternGetString, "FcPatternGetString" );
bindFunc( cast( void** )&FcPatternGetInteger, "FcPatternGetInteger" );
bindFunc( cast( void** )&FcPatternGetBool, "FcPatternGetBool" );
bindFunc( cast( void** )&FcFontSetDestroy, "FcFontSetDestroy" );
} }
} }
__gshared DerelictFCLoader DerelictFC;
shared static this() { FCSupport loadedFCVersion() { return loadedVersion; }
DerelictFC = new DerelictFCLoader();
bool isFCLoaded()
{
return lib != invalidHandle;
}
FCSupport loadFC()
{
// #1778 prevents from using static arrays here :(
version(Windows) {
const(char)[][1] libNames = [ "libfontconfig-1.dll"];
}
else version(OSX) {
const(char)[][1] libNames = [
"/usr/local/lib/libfontconfig.dylib"
];
}
else version(Posix) {
const(char)[][2] libNames = [
"libfontconfig.so.1",
"libfontconfig.so"
];
}
else static assert(0, "bindbc-fc is not yet supported on this platform.");
FCSupport ret;
foreach(name; libNames) {
ret = loadFC(name.ptr);
if(ret != FCSupport.noLibrary) break;
}
return ret;
}
FCSupport loadFC(const(char)* libName)
{
lib = load(libName);
if(lib == invalidHandle) {
return FCSupport.noLibrary;
}
auto errCount = errorCount();
loadedVersion = FCSupport.badLibrary;
lib.bindSymbol( cast( void** )&FcObjectSetBuild, "FcObjectSetBuild" );
lib.bindSymbol( cast( void** )&FcPatternCreate, "FcPatternCreate" );
lib.bindSymbol( cast( void** )&FcPatternAddBool, "FcPatternAddBool" );
lib.bindSymbol( cast( void** )&FcFontList, "FcFontList" );
lib.bindSymbol( cast( void** )&FcPatternDestroy, "FcPatternDestroy" );
lib.bindSymbol( cast( void** )&FcObjectSetDestroy, "FcObjectSetDestroy" );
lib.bindSymbol( cast( void** )&FcPatternGetString, "FcPatternGetString" );
lib.bindSymbol( cast( void** )&FcPatternGetInteger, "FcPatternGetInteger" );
lib.bindSymbol( cast( void** )&FcPatternGetBool, "FcPatternGetBool" );
lib.bindSymbol( cast( void** )&FcFontSetDestroy, "FcFontSetDestroy" );
if(errorCount() != errCount) return FCSupport.badLibrary;
else loadedVersion = FCSupport.fc100;
return loadedVersion;
} }

View File

@ -30,12 +30,9 @@
"excludedSourceFiles-windows": ["3rdparty/fontconfig/*"], "excludedSourceFiles-windows": ["3rdparty/fontconfig/*"],
"dependencies": { "dependencies": {
"bindbc-opengl": "~>1.0.0",
"inilike": "~>1.2.1" "inilike": "~>1.2.1"
}, },
"versions": ["GL_AllowDeprecated", "GL_30"],
"subPackages": [ "subPackages": [
"./examples/helloworld/", "./examples/helloworld/",
"./examples/example1/", "./examples/example1/",
@ -52,16 +49,17 @@
"configurations": [ "configurations": [
{ {
"name": "default", "name": "default",
"versions": ["USE_OPENGL", "EmbedStandardResources"], "versions": ["USE_OPENGL", "EmbedStandardResources", "GL_32"],
"versions-posix": ["USE_SDL", "USE_FREETYPE"], "versions-posix": ["USE_SDL", "USE_FREETYPE", "SDL_204"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies": { "dependencies": {
"derelict-ft": "~>2.0.0-beta.5", "bindbc-opengl": "~>1.0.0",
"icontheme": "~>1.2.3" "bindbc-freetype": "~>1.0.0"
}, },
"dependencies-posix": { "dependencies-posix": {
"derelict-sdl2": "~>3.0.0-beta.8" "bindbc-sdl": "~>1.0.0",
"icontheme": "~>1.2.3"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll" "libs/windows/x86_64/libfreetype-6.dll"
@ -73,6 +71,7 @@
{ {
"name": "console", "name": "console",
"versions": ["USE_CONSOLE", "EmbedStandardResources"], "versions": ["USE_CONSOLE", "EmbedStandardResources"],
"libs-windows": ["user32"],
"excludedSourceFiles": ["3rdparty/*GL*", "3rdparty/android", "3rdparty/dimage", "3rdparty/fontconfig/*", "3rdparty/icontheme", "3rdparty/jni.d"] "excludedSourceFiles": ["3rdparty/*GL*", "3rdparty/android", "3rdparty/dimage", "3rdparty/fontconfig/*", "3rdparty/icontheme", "3rdparty/jni.d"]
}, },
{ {
@ -80,8 +79,8 @@
"versions": ["USE_EXTERNAL"], "versions": ["USE_EXTERNAL"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies": { "dependencies": {
"derelict-ft": "~>2.0.0-beta.5", "bindbc-opengl": "~>1.0.0",
"icontheme": "~>1.2.3" "bindbc-freetype": "~>1.0.0"
} }
}, },
{ {
@ -91,18 +90,21 @@
"versions-windows": ["Unicode" ,"NO_OPENGL"], "versions-windows": ["Unicode" ,"NO_OPENGL"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies-posix": { "dependencies-posix": {
"derelict-sdl2": "~>3.0.0-beta.8", "bindbc-opengl": "~>1.0.0",
"derelict-ft": "~>2.0.0-beta.5", "bindbc-freetype": "~>1.0.0",
"icontheme": "~>1.2.3" "bindbc-sdl": "~>1.0.0"
} }
}, },
{ {
"name": "sdl", "name": "sdl",
"versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources", "GL_32", "SDL_204"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-ft": "~>2.0.0-beta.5", "bindbc-opengl": "~>1.0.0",
"derelict-sdl2": "~>3.0.0-beta.8", "bindbc-freetype": "~>1.0.0",
"bindbc-sdl": "~>1.0.0"
},
"dependencies-posix": {
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
@ -116,20 +118,22 @@
}, },
{ {
"name": "x11", "name": "x11",
"versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources", "GL_32"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-ft": "~>2.0.0-beta.5", "bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"x11": "~>1.0.21", "x11": "~>1.0.21",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
} }
}, },
{ {
"name": "sfml", "name": "sfml",
"versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources", "GL_32"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-ft": "~>2.0.0-beta.4", "bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"dsfml": "~>2.1.0", "dsfml": "~>2.1.0",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
}, },

View File

@ -13,7 +13,7 @@ import dlangui.graphics.scene.objimport;
import dlangui.graphics.scene.fbximport; import dlangui.graphics.scene.fbximport;
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
import derelict.opengl.gl; import bindbc.opengl;
mixin APP_ENTRY_POINT; mixin APP_ENTRY_POINT;

View File

@ -11,6 +11,8 @@
"targetName": "dminer", "targetName": "dminer",
"targetType": "executable", "targetType": "executable",
"sourceFiles-windows-x86": ["$PACKAGE_DIR/src/win_app.def"],
"versions": ["EmbedStandardResources"], "versions": ["EmbedStandardResources"],
"dependencies": { "dependencies": {

View File

@ -1283,8 +1283,7 @@ void main()
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
import derelict.opengl; //3.gl3; import bindbc.opengl;
//import derelict.opengl3.gl;
class MyOpenglWidget : VerticalLayout { class MyOpenglWidget : VerticalLayout {
this() { this() {

View File

@ -11,7 +11,7 @@
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"], "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"],
"versions": ["EmbedStandardResources"], "versions": ["EmbedStandardResources", "GL_AllowDeprecated"],
"dependencies": { "dependencies": {
"dlangui": {"path": "../../"} "dlangui": {"path": "../../"}

View File

@ -33,6 +33,7 @@ extern (C) int UIAppMain(string[] args) {
static if (ENABLE_OPENGL): static if (ENABLE_OPENGL):
import bindbc.opengl;
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
@ -134,7 +135,7 @@ class MyOpenglWidget : VerticalLayout {
return; return;
} }
bool canUseOldApi = !!glLightfv; bool canUseOldApi = !!glLightfv;
bool canUseNewApi = !glSupport.legacyMode; bool canUseNewApi = true;
if (_exampleIndex == 0 || !canUseOldApi) if (_exampleIndex == 0 || !canUseOldApi)
drawUsingNewAPI(windowRect, rc); drawUsingNewAPI(windowRect, rc);
else if (_exampleIndex == 1 || !canUseNewApi) else if (_exampleIndex == 1 || !canUseNewApi)

View File

@ -24,7 +24,7 @@ import dlangui.core.linestream;
import dlangui.core.streams; import dlangui.core.streams;
import std.algorithm; import std.algorithm;
import std.conv : to; import std.conv : to;
import std.uni; static import std.uni;
// uncomment FileFormats debug symbol to dump file formats for loaded/saved files. // uncomment FileFormats debug symbol to dump file formats for loaded/saved files.
//debug = FileFormats; //debug = FileFormats;

View File

@ -14,8 +14,7 @@ static if (ENABLE_FREETYPE):
import dlangui.graphics.fonts; import dlangui.graphics.fonts;
import derelict.freetype.ft; import bindbc.freetype;
import derelict.util.exception;
import dlangui.core.logger; import dlangui.core.logger;
import dlangui.core.collections; import dlangui.core.collections;
import std.algorithm; import std.algorithm;
@ -23,6 +22,8 @@ import std.file;
import std.string; import std.string;
import std.utf; import std.utf;
import loader = bindbc.loader.sharedlib;
__gshared int[string] STD_FONT_FACES; __gshared int[string] STD_FONT_FACES;
int stdFontFacePriority(string face) { int stdFontFacePriority(string face) {
@ -471,17 +472,27 @@ class FreeTypeFont : Font {
@property override bool isNull() { return _files.length == 0; } @property override bool isNull() { return _files.length == 0; }
} }
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
private void ftCheckMissingSymFunc(const(loader.ErrorInfo)[] errors) {
import std.algorithm : equal; import std.algorithm : equal;
static import derelict.util.exception; immutable names = ["FT_New_Face", "FT_Attach_File", "FT_Set_Pixel_Sizes",
foreach(s; ["FT_New_Face", "FT_Attach_File", "FT_Set_Pixel_Sizes",
"FT_Get_Char_Index", "FT_Load_Glyph", "FT_Done_Face", "FT_Get_Char_Index", "FT_Load_Glyph", "FT_Done_Face",
"FT_Init_FreeType", "FT_Done_FreeType", "FT_Get_Kerning"]) { "FT_Init_FreeType", "FT_Done_FreeType", "FT_Get_Kerning"];
if (symName.equal(s)) // Symbol is used foreach(info; errors)
return derelict.util.exception.ShouldThrow.Yes; {
import std.array;
import std.algorithm;
import std.exception;
import core.stdc.string;
// NOTE: this has crappy complexity as it was just updated as is
// it also does not checks if the symbol was actually loaded
auto errMsg = cast(string) info.message[0 .. info.message.strlen];
bool found = names
.filter!(s => s.canFind(errMsg))
.array()
.length > 0;
enforce(!found, { return errMsg.idup; });
} }
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
} }
/// FreeType based font manager. /// FreeType based font manager.
@ -576,22 +587,15 @@ class FreeTypeFontManager : FontManager {
this() { this() {
// load dynaic library // load dynaic library
try { try {
Log.v("DerelictFT: Loading FreeType library"); import std.exception;
if (!DerelictFT) { import std.format;
Log.w("DerelictFT is null. Compiler bug? Applying workaround to fix it."); Log.v("bindbc-freetype: Loading FreeType library");
version(Android) { auto ftVer = loadFreeType();
//DerelictFT = new DerelictFTLoader("libft2.so"); enforce(ftVer != FTSupport.badLibrary && ftVer != FTSupport.noLibrary, format!"bindbc-freetype unable to find suitable library, %s minimum required"(ftSupport));
DerelictFT = new DerelictFTLoader; ftCheckMissingSymFunc(loader.errors);
} else { Log.v("bindbc-freetype: Loaded");
DerelictFT = new DerelictFTLoader;
}
}
DerelictFT.missingSymbolCallback = &missingSymFunc;
Log.v("DerelictFT: Missing symbols callback is registered");
DerelictFT.load();
Log.v("DerelictFT: Loaded");
} catch (Exception e) { } catch (Exception e) {
Log.e("Derelict: cannot load freetype shared library: ", e.msg); Log.e("bindbc-freetype: cannot load freetype shared library: ", e.msg);
throw new Exception("Cannot load freetype library"); throw new Exception("Cannot load freetype library");
} }
Log.v("Initializing FreeType library"); Log.v("Initializing FreeType library");
@ -725,9 +729,11 @@ version(Windows) {
bool registerFontConfigFonts(FreeTypeFontManager fontMan) { bool registerFontConfigFonts(FreeTypeFontManager fontMan) {
import fontconfig; import fontconfig;
import std.exception;
try { try {
DerelictFC.load(); auto fcVer = loadFC();
enforce(fcVer != FCSupport.badLibrary && fcVer != FCSupport.noLibrary);
} catch (Exception e) { } catch (Exception e) {
Log.w("Cannot load FontConfig shared library"); Log.w("Cannot load FontConfig shared library");
return false; return false;

View File

@ -49,6 +49,32 @@ version (Android) {
} else { } else {
enum SUPPORT_LEGACY_OPENGL = false; //true; enum SUPPORT_LEGACY_OPENGL = false; //true;
public import bindbc.opengl; public import bindbc.opengl;
public import bindbc.opengl.bind.arb.core_30;
import loader = bindbc.loader.sharedlib;
private void gl3CheckMissingSymFunc(const(loader.ErrorInfo)[] errors)
{
import std.algorithm : equal;
immutable names = ["glGetError", "glShaderSource", "glCompileShader",
"glGetShaderiv", "glGetShaderInfoLog", "glGetString",
"glCreateProgram", "glUseProgram", "glDeleteProgram",
"glDeleteShader", "glEnable", "glDisable", "glBlendFunc",
"glUniformMatrix4fv", "glGetAttribLocation", "glGetUniformLocation",
"glGenVertexArrays", "glBindVertexArray", "glBufferData",
"glBindBuffer", "glBufferSubData"];
foreach(info; errors)
{
import std.array;
import std.algorithm;
import std.exception;
import core.stdc.string;
// NOTE: this has crappy complexity as it was just updated as is
// it also does not checks if the symbol was actually loaded
auto errMsg = cast(string) info.message[0 .. info.message.strlen];
bool found = names.any!(s => s.indexOf(errMsg) != -1);
enforce(!found, { return errMsg.idup; });
}
} }
import dlangui.graphics.scene.mesh; import dlangui.graphics.scene.mesh;
@ -639,18 +665,43 @@ __gshared bool glNoContext;
/// initialize OpenGL support helper (call when current OpenGL context is initialized) /// initialize OpenGL support helper (call when current OpenGL context is initialized)
bool initGLSupport(bool legacy = false) { bool initGLSupport(bool legacy = false) {
import dlangui.platforms.common.platform : setOpenglEnabled; import dlangui.platforms.common.platform : setOpenglEnabled;
import loader = bindbc.loader.sharedlib;
if (_glSupport && _glSupport.valid) if (_glSupport && _glSupport.valid)
return true; return true;
version(Android) { version(Android) {
Log.d("initGLSupport"); Log.d("initGLSupport");
} else { } else {
static bool BINDBC_GL3_RELOADED;
auto support = loadOpenGL(); static bool gl3ReloadedOk;
if(support < bindbc.opengl.GLSupport.gl11) // No context! Error! static bool glReloadedOk;
{ if (!BINDBC_GL3_RELOADED) {
Log.e("OpenGL wasn't loaded successfully"); BINDBC_GL3_RELOADED = true;
try {
Log.v("Reloading bindbc-opengl");
import bindbc.opengl;
loadOpenGL();
gl3CheckMissingSymFunc(loader.errors);
gl3ReloadedOk = true;
} catch (Exception e) {
Log.e("bindbc-opengl exception while reloading opengl", e);
}
try {
Log.v("Reloading bindbc-opengl");
import bindbc.opengl;
loadOpenGL();
gl3CheckMissingSymFunc(loader.errors);
glReloadedOk = true;
} catch (Exception e) {
Log.e("bindbc-opengl exception while reloading opengl", e);
}
}
if (!gl3ReloadedOk && !glReloadedOk) {
Log.e("bindbc-opengl reloaded unsuccessfully");
return false; return false;
} }
if (!gl3ReloadedOk)
legacy = true;
else if (!glReloadedOk)
legacy = false; legacy = false;
} }
if (!_glSupport) { // TODO_GRIM: Legacy looks very broken to me. if (!_glSupport) { // TODO_GRIM: Legacy looks very broken to me.
@ -1618,3 +1669,4 @@ private final class OpenGLQueue {
_indices ~= cast(int[])indices; _indices ~= cast(int[])indices;
}; };
} }
}

View File

@ -39,18 +39,18 @@ import dlangui.widgets.styles;
import dlangui.widgets.widget; import dlangui.widgets.widget;
import dlangui.platforms.common.platform; import dlangui.platforms.common.platform;
import derelict.sdl2.sdl; import bindbc.sdl;
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
import bindbc.opengl; import bindbc.opengl;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
import loader = bindbc.loader.sharedlib;
} }
private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) { private void sdlCheckMissingSymFunc(const(loader.ErrorInfo)[] errors) {
import std.algorithm : equal; import std.algorithm : equal;
static import derelict.util.exception; immutable names = ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent",
foreach(s; ["SDL_DestroyRenderer", "SDL_GL_DeleteContext", "SDL_DestroyWindow", "SDL_PushEvent",
"SDL_GL_SetAttribute", "SDL_GL_CreateContext", "SDL_GetError", "SDL_GL_SetAttribute", "SDL_GL_CreateContext", "SDL_GetError",
"SDL_CreateWindow", "SDL_CreateRenderer", "SDL_GetWindowSize", "SDL_CreateWindow", "SDL_CreateRenderer", "SDL_GetWindowSize",
"SDL_GL_GetDrawableSize", "SDL_GetWindowID", "SDL_SetWindowSize", "SDL_GL_GetDrawableSize", "SDL_GetWindowID", "SDL_SetWindowSize",
@ -63,12 +63,19 @@ private derelict.util.exception.ShouldThrow missingSymFunc( string symName ) {
"SDL_RemoveTimer", "SDL_RemoveTimer", "SDL_PushEvent", "SDL_RemoveTimer", "SDL_RemoveTimer", "SDL_PushEvent",
"SDL_RegisterEvents", "SDL_WaitEvent", "SDL_StartTextInput", "SDL_RegisterEvents", "SDL_WaitEvent", "SDL_StartTextInput",
"SDL_Quit", "SDL_HasClipboardText", "SDL_GetClipboardText", "SDL_Quit", "SDL_HasClipboardText", "SDL_GetClipboardText",
"SDL_free", "SDL_SetClipboardText", "SDL_Init", "SDL_GetNumVideoDisplays"]) {//"SDL_GetDisplayDPI" "SDL_free", "SDL_SetClipboardText", "SDL_Init", "SDL_GetNumVideoDisplays"]; //"SDL_GetDisplayDPI"
if (symName.equal(s)) // Symbol is used foreach(info; errors)
return derelict.util.exception.ShouldThrow.Yes; {
import std.array;
import std.algorithm;
import std.exception;
import core.stdc.string;
// NOTE: this has crappy complexity as it was just updated as is
// it also does not checks if the symbol was actually loaded
auto errMsg = cast(string) info.message[0 .. info.message.strlen];
bool found = names.any!(s => s.indexOf(errMsg) != -1);
enforce(!found, { return errMsg.idup; });
} }
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
} }
private __gshared SDL_EventType USER_EVENT_ID; private __gshared SDL_EventType USER_EVENT_ID;
@ -1638,9 +1645,12 @@ int sdlmain(string[] args) {
} }
try { try {
DerelictSDL2.missingSymbolCallback = &missingSymFunc; import std.exception;
//DerelictSDL2.missingSymbolCallback = &missingSymFunc;
// Load the SDL 2 library. // Load the SDL 2 library.
DerelictSDL2.load(); auto sdlVer = loadSDL();
enforce(sdlVer != SDLSupport.noLibrary && sdlVer != SDLSupport.badLibrary, "bindbc-sdl unable to find SDL2 library");
sdlCheckMissingSymFunc(loader.errors);
} catch (Exception e) { } catch (Exception e) {
Log.e("Cannot load SDL2 library", e); Log.e("Cannot load SDL2 library", e);
return 1; return 1;

View File

@ -151,7 +151,7 @@ static if (ENABLE_OPENGL) {
return hPalette; return hPalette;
} }
private __gshared bool DERELICT_GL3_RELOADED = false; private __gshared bool BINDBC_GL3_RELOADED = false; // is this even used?
} }
const uint CUSTOM_MESSAGE_ID = WM_USER + 1; const uint CUSTOM_MESSAGE_ID = WM_USER + 1;
@ -323,6 +323,8 @@ class Win32Window : Window {
EndPaint(_hwnd, &ps); EndPaint(_hwnd, &ps);
import bindbc.opengl; //3.gl3;
import bindbc.opengl; //3.wgl;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
//Log.d("onPaint() start drawing opengl viewport: ", _dx, "x", _dy); //Log.d("onPaint() start drawing opengl viewport: ", _dx, "x", _dy);
//PAINTSTRUCT ps; //PAINTSTRUCT ps;
@ -1306,6 +1308,38 @@ string[] splitCmdLine(string line) {
private __gshared Win32Platform w32platform; private __gshared Win32Platform w32platform;
static if (ENABLE_OPENGL) {
import bindbc.opengl;
import bindbc.opengl.config : GLSupportVersion = GLSupport;
void initOpenGL() {
try {
Log.d("Loading bindbc-opengl");
auto glVer = loadOpenGL();
if(glVer < GLSupportVersion.gl32) {
import std.format : format;
throw new Exception(format!"OpenGL 3.2 or higher is required, got: %s"(glVer));
}
Log.d("bindbc-opengl - loaded");
//
//// just to check OpenGL context
//Log.i("Trying to setup OpenGL context");
//Win32Window tmpWindow = new Win32Window(w32platform, ""d, null, 0);
//destroy(tmpWindow);
//if (openglEnabled)
// Log.i("OpenGL support is enabled");
//else
// Log.w("OpenGL support is disabled");
//// process messages
//platform.enterMessageLoop();
} catch (Exception e) {
Log.e("Exception while trying to init OpenGL", e);
setOpenglEnabled(false);
}
}
}
int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdShow) int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdShow)
{ {
initLogs(); initLogs();