bindbc / bindbc-glfw Goto Github PK
View Code? Open in Web Editor NEWStatic & dynamic D bindings to GLFW, compatible with BetterC, @nogc, and nothrow.
License: Boost Software License 1.0
Static & dynamic D bindings to GLFW, compatible with BetterC, @nogc, and nothrow.
License: Boost Software License 1.0
bindbc-glfw/source/bindbc/glfw/binddynamic.d
Line 271 in a9396bc
Can you add @nogc @safe nothrow
attributes to some of the bindbc-glfw functions so that caller's code can make use of these attributes freely?
loadedGLFWVersion
and isGLFWLoaded
cannot currently be called from a @nogc @safe nothrow
function, but it seems like they should be compatible with these attributes.
loadGLFW
and unloadGLFW
cannot currently be called from a @nogc nothrow
function, but it seems like they should be compatible with these attributes.
Same thing for bindbc-sdl
, but I'm too lazy to create two issues.
module main;
import std.stdio;
import bindbc.glfw;
@nogc @safe nothrow
void foo()
{
writeln(loadedGLFWVersion());
writeln(isGLFWLoaded());
}
@nogc nothrow
void bar()
{
loadGLFW();
foo();
unloadGLFW();
}
void main()
{
bar();
}
$ dub run
Performing "debug" build using /usr/bin/dmd for x86_64.
bindbc-loader 0.2.1: building configuration "noBC"...
bindbc-glfw 0.6.0: building configuration "dynamic"...
test ~master: building configuration "application"...
src/app.d(8,28): Error: `@safe` function `main.foo` cannot call `@system` function `bindbc.glfw.binddynamic.loadedGLFWVersion`
.dub/packages/bindbc-glfw-0.6.0/bindbc-glfw/source/bindbc/glfw/binddynamic.d(271,14): `bindbc.glfw.binddynamic.loadedGLFWVersion` is declared here
src/app.d(8,28): Error: `@nogc` function `main.foo` cannot call non-@nogc function `bindbc.glfw.binddynamic.loadedGLFWVersion`
src/app.d(8,10): Error: `@nogc` function `main.foo` cannot call non-@nogc function `std.stdio.writeln!(GLFWSupport).writeln`
src/app.d(9,23): Error: `@safe` function `main.foo` cannot call `@system` function `bindbc.glfw.binddynamic.isGLFWLoaded`
.dub/packages/bindbc-glfw-0.6.0/bindbc-glfw/source/bindbc/glfw/binddynamic.d(272,7): `bindbc.glfw.binddynamic.isGLFWLoaded` is declared here
src/app.d(9,23): Error: `@nogc` function `main.foo` cannot call non-@nogc function `bindbc.glfw.binddynamic.isGLFWLoaded`
src/app.d(9,10): Error: `@nogc` function `main.foo` cannot call non-@nogc function `std.stdio.writeln!bool.writeln`
src/app.d(8,28): Error: function `bindbc.glfw.binddynamic.loadedGLFWVersion` is not `nothrow`
src/app.d(9,23): Error: function `bindbc.glfw.binddynamic.isGLFWLoaded` is not `nothrow`
src/app.d(6,6): Error: `nothrow` function `main.foo` may throw
src/app.d(15,11): Error: `@nogc` function `main.bar` cannot call non-@nogc function `bindbc.glfw.binddynamic.loadGLFW`
src/app.d(17,13): Error: `@nogc` function `main.bar` cannot call non-@nogc function `bindbc.glfw.binddynamic.unloadGLFW`
src/app.d(15,11): Error: function `bindbc.glfw.binddynamic.loadGLFW` is not `nothrow`
src/app.d(17,13): Error: function `bindbc.glfw.binddynamic.unloadGLFW` is not `nothrow`
src/app.d(13,6): Error: `nothrow` function `main.bar` may throw
/usr/bin/dmd failed with exit code 1.
When I use the 'BindGLFW_Static' version directive, I get the build error; Error: undefined identifier loadGLFW
, when trying to use loadGLFW
. This does not happen when not using the directive, with everything functioning seemingly normal.
The library files I have present are 'glfw3.dll', 'glfw3.lib' & 'glfw3dll.lib', with my dub.json looking like this:
{
"authors": [
"HuskyNator"
],
"copyright": "Copyright © 2021, HuskyNator",
"dependencies": {
"bindbc-glfw": "~>0.10.1",
"bindbc-opengl": "~>0.13.0"
},
"description": "Learning OpenGL (in Dutch)",
"libs": ["glfw3"],
"license": "proprietary",
"name": "hoekjed",
"versions": [ "BindGLFW_Static", "GLFW_33", "GL_46"]
}
I have tried using both 'glfw3 and 'glfw3dll' within the libs property, and also tried this without the GLFW_33 directive.
I get this one error about isGLFWLoaded. The other functions are fine.
.\common\derelict_libraries.d(101,14): Error: undefined identifier isGLFWLoaded
AIL .dub\build\application-debug-windows-x86_64-ldc_2083-B17D37CE3FF9DAC34CB3E8A692CBE9CF\ 06_03_04_levels executable
dc2 failed with exit code 1.
..\duball exited with code 2
Believe I can get by without it.
GLFWSupport ret = loadGLFW();
if (ret == GLFWSupport.noLibrary)
writeln("No FreeImage shared library was detected");
if (ret == GLFWSupport.badLibrary)
writeln("One or more symbols failed to load.");
if (isGLFWLoaded())
{
GLFWSupport glfwVer = loadedGLFWVersion();
if (glfwVer == GLFWSupport.glfw30)
writeln("GLFW - Graphics Library FrameWork - Version 3.0 successfully loaded");
else if (glfwVer == GLFWSupport.glfw31)
writeln("GLFW - Graphics Library FrameWork - Version 3.1 successfully loaded");
else if (glfwVer == GLFWSupport.glfw32)
writeln("GLFW - Graphics Library FrameWork - Version 3.2 successfully loaded");
else
writeln("An unexpected version of GLFW - Graphics Library FrameWork - was loaded");
}
else
writeln("No version of the GLFW library was loaded");
The function pointer types defined in module bindbc.glfw.types, line 410, are not non-@nogc, which makes them hard to call manually in @nogc code:
// from upcomming d_imgui glfw vulkan backend code
module foo;
GLFWmousebuttonfun g_PrevUserCallbackMousebutton;
// Assign some function pointer to g_PrevUserCallbackMousebutton
extern( C ) void bar( GLFWwindow* window, int button, int action, int mods ) nothrow @nogc
{
if( g_PrevUserCallbackMousebutton != null )
g_PrevUserCallbackMousebutton( window, button, action, mods );
// ...
}
Compiler:
Error: `@nogc` function `foo.bar` cannot call non-@nogc function pointer `g_PrevUserCallbackMousebutton`
My suggestion is, either add @nogc to the types, or add another version specifier, e.g.: BindGLFW_NoGC_func_ptr_types:
version(BindGLFW_NoGC_func_ptr_types) {
extern(C) nothrow @nogc {
alias GLFWerrorfun = void function(int,const(char)*);
// ...
}
} else {
extern(C) nothrow {
alias GLFWerrorfun = void function(int,const(char)*);
// ...
}
}
This was the wrong library whoops!
bindbc-glfw/source/bindbc/glfw/binddynamic.d
Line 385 in fdc07a2
Would it be practical for loadGLFW
to also track what was the last version for which all compatible symbols loaded without issue?
As is, it looks like after loadGLFW
returns GLFWSupport.badLibrary
due to a missing symbol, then loadedGLFWVersion
returns the highest version requested, not the highest version successfully loaded. Is that right?
Of course, I can certainly use glfwGetVersion
to get the currently loaded version, but loadedGLFWVersion
sounds like it should be able to do the same.
Hello,
I'm making an application using Vulkan and GLFW in D. I use erupted to load Vulkan symbols (it works fine with Bindbc.SDL).
It looks like bindGLFW_Vulkan (defined at binddynamic.d:476) does not compile as it is supposed to when used with mixin, as described in the comment just above line 456 (which looks inaccurate, symbol glfwVulkanBind does not exist, I suppose it was meant to be bindGLFW_Vulkan).
Here's my code:
module myapp;
import erupted; // Necessary to have VK symbols object, used in bindGLFW_Vulkan
import bindbc.glfw;
mixin(bindGLFW_Vulkan); //Compilation fails: lib, errorCount and invalidHandle are undefined
The reason it fails is because the 3 undefined symbols are private within binddynamic.d.
To solve the problem, I defined some public functions hub to lib and errorCount in binddynamic.d:
public auto getGLFWlib()
{
return lib;
}
public auto getGLFWerrorCount()
{
return errorCount();
}
And I changed the definition of loadGLFW_Vulkan to:
bool loadGLFW_Vulkan()
{
import bindbc.loader;
assert(isGLFWLoaded(), "loadGLFW must be successfully called before loadGLFW_Vulkan");
auto errCount = getGLFWerrorCount();
getGLFWlib.bindSymbol(cast(void**)&glfwGetRequiredInstanceExtensions, "glfwGetRequiredInstanceExtensions");
getGLFWlib.bindSymbol(cast(void**)&glfwGetInstanceProcAddress, "glfwGetInstanceProcAddress");
getGLFWlib.bindSymbol(cast(void**)&glfwGetPhysicalDevicePresentationSupport, "glfwGetPhysicalDevicePresentationSupport");
getGLFWlib.bindSymbol(cast(void**)&glfwCreateWindowSurface, "glfwCreateWindowSurface");
return getGLFWerrorCount() == errCount;
}
With those changes, it builds fine, and it works.
I suspect the same problems occurs with bindGLFW_EGL, bindGLFW_WGL, bindGLFW_Windows, bindGLFW_NSGL, bindGLFW_Cocoa (enum name mismatches at line 595), bindGLFW_GLX, bindGLFW_X11, etc...
I have not made a pull-request for that as it requires some API change, and the names getGLFWlib and getGLFWerrorCount I used are pretty bad. Maybe there is a more elegant solution (or maybe I have missed something)?
If you need me to do the mundane task of writing the correction, I can make a pull-request for you to review as the code is fresh in my mind.
Regards,
Claude
Error: cannot return non-void from void
function
void loadGLFW_NSGL() {
import bindbc.loader.sharedlib : errorCount;
if(!isGLFWLoaded) return false;
bindGLFWSymbol(cast(void**)&glfwGetWGLContext,"glfwGetWGLContext");
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.