Skip to content

Commit

Permalink
Merge pull request #612 from Superbelko/migrate_bindbc
Browse files Browse the repository at this point in the history
Migrate to bindbc
  • Loading branch information
GrimMaple committed Jun 2, 2022
2 parents 76c9e10 + a65085d commit d92f668
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 143 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/dimage/png.d
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ in
{
assert (img.data.length);
}
body
do
{
Compound!(bool, string) error(string errorMsg)
{
Expand Down
40 changes: 20 additions & 20 deletions 3rdparty/fontconfig/functions.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@ public import fontconfig.fctypes;

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 {

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;
}

/+
Expand Down
108 changes: 77 additions & 31 deletions 3rdparty/fontconfig/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,88 @@ module fontconfig;
public import fontconfig.fctypes;
public import fontconfig.functions;

import bindbc.loader;

enum FCSupport {
noLibrary,
badLibrary,
// TODO: real versions and stuff
fc100 = 100,
}

private {
import derelict.util.loader;
import derelict.util.system;

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." );
SharedLib lib;
FCSupport loadedVersion;
}


@nogc nothrow:
void unloadFC()
{
if(lib != invalidHandle) {
lib.unload();
}
}


FCSupport loadedFCVersion() { return loadedVersion; }

bool isFCLoaded()
{
return lib != invalidHandle;
}


class DerelictFCLoader : SharedLibLoader {
public this() {
super( libNames );
}

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" );
}
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;
}

__gshared DerelictFCLoader DerelictFC;
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;

shared static this() {
DerelictFC = new DerelictFCLoader();
return loadedVersion;
}
44 changes: 24 additions & 20 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@
"excludedSourceFiles-windows": ["3rdparty/fontconfig/*"],

"dependencies": {
"bindbc-opengl": "~>1.0.0",
"inilike": "~>1.2.1"
},

"versions": ["GL_AllowDeprecated", "GL_30"],

"subPackages": [
"./examples/helloworld/",
"./examples/example1/",
Expand All @@ -52,16 +49,17 @@
"configurations": [
{
"name": "default",
"versions": ["USE_OPENGL", "EmbedStandardResources"],
"versions-posix": ["USE_SDL", "USE_FREETYPE"],
"versions": ["USE_OPENGL", "EmbedStandardResources", "GL_32"],
"versions-posix": ["USE_SDL", "USE_FREETYPE", "SDL_204"],
"versions-windows": ["Unicode"],
"libs-windows": ["opengl32"],
"dependencies": {
"derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3"
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0"
},
"dependencies-posix": {
"derelict-sdl2": "~>3.0.0-beta.8"
"bindbc-sdl": "~>1.0.0",
"icontheme": "~>1.2.3"
},
"copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll"
Expand All @@ -73,15 +71,16 @@
{
"name": "console",
"versions": ["USE_CONSOLE", "EmbedStandardResources"],
"libs-windows": ["user32"],
"excludedSourceFiles": ["3rdparty/*GL*", "3rdparty/android", "3rdparty/dimage", "3rdparty/fontconfig/*", "3rdparty/icontheme", "3rdparty/jni.d"]
},
{
"name": "external",
"versions": ["USE_EXTERNAL"],
"libs-windows": ["opengl32"],
"dependencies": {
"derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3"
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0"
}
},
{
Expand All @@ -91,18 +90,21 @@
"versions-windows": ["Unicode" ,"NO_OPENGL"],
"libs-windows": ["opengl32"],
"dependencies-posix": {
"derelict-sdl2": "~>3.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3"
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"bindbc-sdl": "~>1.0.0"
}
},
{
"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"],
"dependencies": {
"derelict-ft": "~>2.0.0-beta.5",
"derelict-sdl2": "~>3.0.0-beta.8",
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"bindbc-sdl": "~>1.0.0"
},
"dependencies-posix": {
"icontheme": "~>1.2.3"
},
"copyFiles-windows-x86_64": [
Expand All @@ -116,20 +118,22 @@
},
{
"name": "x11",
"versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources"],
"versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources", "GL_32"],
"versions-windows": ["Unicode"],
"dependencies": {
"derelict-ft": "~>2.0.0-beta.5",
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"x11": "~>1.0.21",
"icontheme": "~>1.2.3"
}
},
{
"name": "sfml",
"versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
"versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources", "GL_32"],
"versions-windows": ["Unicode"],
"dependencies": {
"derelict-ft": "~>2.0.0-beta.4",
"bindbc-opengl": "~>1.0.0",
"bindbc-freetype": "~>1.0.0",
"dsfml": "~>2.1.0",
"icontheme": "~>1.2.3"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/d3d/src/d3d.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dlangui.graphics.scene.objimport;
import dlangui.graphics.scene.fbximport;
import dlangui.graphics.glsupport;
import dlangui.graphics.gldrawbuf;
import derelict.opengl.gl;
import bindbc.opengl;

mixin APP_ENTRY_POINT;

Expand Down
2 changes: 2 additions & 0 deletions examples/dminer/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"targetName": "dminer",
"targetType": "executable",

"sourceFiles-windows-x86": ["$PACKAGE_DIR/src/win_app.def"],

"versions": ["EmbedStandardResources"],

"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions examples/example1/src/example1.d
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,7 @@ void main()

static if (ENABLE_OPENGL) {

import derelict.opengl; //3.gl3;
//import derelict.opengl3.gl;
import bindbc.opengl;

class MyOpenglWidget : VerticalLayout {
this() {
Expand Down
2 changes: 1 addition & 1 deletion examples/opengl/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"],

"versions": ["EmbedStandardResources"],
"versions": ["EmbedStandardResources", "GL_AllowDeprecated"],

"dependencies": {
"dlangui": {"path": "../../"}
Expand Down
3 changes: 2 additions & 1 deletion examples/opengl/src/openglexample.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern (C) int UIAppMain(string[] args) {

static if (ENABLE_OPENGL):

import bindbc.opengl;
import dlangui.graphics.glsupport;
import dlangui.graphics.gldrawbuf;

Expand Down Expand Up @@ -134,7 +135,7 @@ class MyOpenglWidget : VerticalLayout {
return;
}
bool canUseOldApi = !!glLightfv;
bool canUseNewApi = !glSupport.legacyMode;
bool canUseNewApi = true;
if (_exampleIndex == 0 || !canUseOldApi)
drawUsingNewAPI(windowRect, rc);
else if (_exampleIndex == 1 || !canUseNewApi)
Expand Down
2 changes: 1 addition & 1 deletion src/dlangui/core/editable.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import dlangui.core.linestream;
import dlangui.core.streams;
import std.algorithm;
import std.conv : to;
import std.uni;
static import std.uni;

// uncomment FileFormats debug symbol to dump file formats for loaded/saved files.
//debug = FileFormats;
Expand Down

0 comments on commit d92f668

Please sign in to comment.