I've got a program that calls to EGL in C++. I want to make the same call in C#, but there doesn't seem to be an equivalent concept in C#.
I'm getting a read/write access denied error when the execution context enters the C++ EGL code.
This is the code in the C++ program that I'm trying to convert to C#:
PropertySet^ surfaceCreationProperties = ref new PropertySet();
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), somethingOtherThanAWindow);
mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties), surfaceAttributes));
I have a C# class which converts C# EGL calls into C++ calls. I believe the C++ is unmanaged, though I wouldn't know how to tell you for certain.
The C# class looks like this:
public static IntPtr CreateWindowSurface(IntPtr dpy, IntPtr config, IntPtr win, int[] attrib_list)
{
IntPtr retValue;
unsafe {
fixed (int* p_attrib_list = attrib_list)
{
retValue = Delegates.peglCreateWindowSurface(dpy, config, win, p_attrib_list);
}
}
return (retValue);
}
More of that code can be seen here: https://github.com/luca-piccioni/OpenGL.Net/blob/master/OpenGL.Net/Egl.VERSION_1_0.cs#L751
You may notice that this method has an IntPtr win
-- this is where I'm passing the PropertySet
. Typically I believe this would be a System.Windows.Forms.Control
, but some checking is done in the C++ EGL code to see if it is, or if it's a PropertySet
.
The C++ method that is being called is this:
EGLSurface EGLAPIENTRY CreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
More can be seen here: https://github.com/Microsoft/angle/blob/ms-holographic-experimental/src/libGLESv2/entry_points_egl.cpp#L241
As you can see, the C++ method is expecting an EGLNativeWindowType. I'm not exactly sure what the relationship to that is between an IInspectable, and a PropertSet - it seems strange that this can be casted.
EGLNativeWindowType has the following type definition:
typedef HWND EGLNativeWindowType;
Which implies it has to be some sort of window handle. I don't understand how a PropertySet could be a window handle.
I suspect the main problem is around choosing the correct type of object to pass to the C# EGL implementation. PropertySet seems like it might be the right choice, but the reinterpret_cast is really throwing me off.
Can anyone walk me through this?