-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support wayland and x11 EGL by use of versions #12
base: master
Are you sure you want to change the base?
Conversation
In addition, it is proposed to expose void* type and request client to cast. This avoids to pull-in dependencies. Having an opaque struct declaration will not help as casting would be needed anyway.
This binding needs a lot of love, but it's a low priority for me right now. I do not use GLES and know very little about EGL and its usage on different platforms. I intend to tackle it if I can ever make the time to finish up all the other work that needs doing. I'll keep this open until I'm able to spend the time I need with this.
I strongly disagree with this. Even in C, I don't like this approach. Opaque structs are more typesafe and avoid the need for casts. I can't think of any advantage of using void* instead. |
And so? You'd prefer to pull-in dependencies? We'd need one version per bindings project. Not so many after all, to my knowledge, there is one binding project for wayland and 2 for X11. |
No. Opaque structs shouldn't pull in external dependencies if they're declared properly as extern(C) everywhere (which they currently aren't in DerelictGLES). Then they simply become forward references. That extern(C) bit is key, though. If a given binding doesn't use it, then D mangling makes them different types. This is one of the things I'll have to evaluate when I get around to getting this package up to speed. My preference is to eliminate the void* where practical. |
I can't find any reference specifying that In fact it doesn't work.
|
You don't need the extra extern. That's only used for instances of a type, not type declarations.
Finally, I just did a test to show you that it does indeed work only to discover that it doesn't. That, IMO, is a bug. I'll take it to the forums later to see if others agree with me. |
OK, the first example I put together was flawed. This one works.
Compiling with |
Your example works because module ec3 doesn't know anything about ec1. module ec1;
extern(C):
struct Foo { int x; }
Foo* newFoo(int x) { return new Foo(x); }
void printFoo(Foo* f) {
import std.stdio;
writeln(f.x);
} module ec3;
extern(C) {
struct Foo;
void printFoo(Foo*);
}
void callPrintFoo(Foo* foo)
{
printFoo(foo);
} module app;
import ec1;
import ec3;
void main()
{
auto foo = newFoo(5);
printFoo(foo);
callPrintFoo(foo);
}
read: |
Alright. I was in a rush the other day and didn't put much time into this, but now I've been playing around with it. My first "flawed" test used three modules before I rewrote it (which is why there's no ec2 in the test I posted). Turns out the flaw wasn't what I thought it was. Had I spent more time with it, I would have recognized it. TL;DR
Obviously, types have no linkage, but even so I know I'm not the only one who understood that extern(C) would turn off mangling of Foo. My original "flawed" test:
This produces the following errors:
Notice the braces on Foo in ec1. It's a full type, not a forward declaration. When I finally noticed it, I believed that to be the cause. I would expect a conflict error in that case, even when mangling is turned off. And we see that in the first line. After I rewrote it, I noticed the braces and thought that had been the cause of the error. What I failed to make note of was that the error message explicitly shows the mangled names (ec1.Foo and ec2.Foo). And if I had taken the time to revert back to this test and try again without the braces, I would have found the same exact error messages. I really believe |
Alright. So in that thread Walter helped shed light on my misunderstanding of the compiler internals. |
In addition, it is proposed to expose
void*
type and request client to cast.Rationale:
This avoids to pull-in dependencies, which would be wrong IMO as there are multiple bindings to x11 and derelict should not prefer one above another. Besides, dependencies version clash is easy to generate.
Having opaque struct declarations is hurting more than helping because:
Tested example of derelict-gles client with EGL, GLES2 and wayland can be found here:
https://github.com/rtbo/wayland-d/blob/master/examples/egl_window/source/egl_window.d
With
dub
, selecting wayland or x11 is done by clients like this:It defaults to
x11
on linux, and should be transparent on other platforms (though I did not test that).