microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

Windows8.1 SwapChainPanel Support, C# P/Invoke Support, Memory Leak Fix #12

Closed omochi closed 9 years ago

omochi commented 10 years ago

Hello, stammen san. Your ANGLE winrt supporting fork is very nice. I got a lot of help for porting my iOS/Android OpenGL application to Windows8.1. But a little troubles are there. I solved them and introduce details in below.

No SwapChainPanel support

In Windows8.1, Using SwapChainPanel is better than SwapChainBackgroundPanel. I added support of it.

It can't be called all functions from C# Managed Layer because of ComPtr class

I use this library for porting iOS/Android OpenGL Application. I write Application, EAGL(something seems to be EGL for Apple platform) by ObjectiveC and OpenGL by C. I write Application, EGL, OpenGL by java. So I want to write application by C# and call EGL, OpenGL by C# too. I made P/Invoke Static functions class in C# and call through corresponding C native function provided by this library. This approach is same to Java. Java OpenGL is simple JNI glue codes to native. But, only 2 function can't be call. They are eglGetDisplay and eglCreateWindowSurface. Because their arguments contains EGLNativeWindowType. this is ComPtr in this WinRT support fork. it is C++ class so it can not link to C# by P/Invoke interface. So I added simple C version of them, eglGetDisplay_c, eglCreateWindowSurface_c. but I think that this solution is bad. EGL function should not be modified/added if there are any other way. I think best approach is changing EGLNativeWindowType ComPtr to IUnknown*. but it has many modification points and potential to happen memory management problem. And I'm not familiar with COM programming, DirectX programming, My project time is finite. So I gave up to do best and do bad out of need.

And I change some function to extern "C".

Fix memory leak

I found that Xaml Page class never be destructed if it contains SwapChainPanel setup by ANGLE. I try to fix it and finally i found bug in below. IWinrtEglWindow::GetWindowInterface() returns ComObject that is called AddRef(). return value directly assign (using operator=) to ComPtr. So it occurs memory leak by Over Retain. I changed this to call ComPtr.Attach() method.

coopp commented 10 years ago

We have a development branch https://github.com/MSOpenTech/angle/tree/future-dev which contains Windows 8.1 and Windows Phone 8.1 support. This branch is actively being developed on and is currently taking changes from the latest google mainline ANGLE source. The design is a bit different from what you are currently working with. In this branch, EGLNatvieWindowType is typed as IInspectable (a Windows Store/WinRT interface) and the SwapChainPanel is passed directly to initialize EGL.

omochi commented 10 years ago

I'm sorry for my late response. I overlooked email from github. Thank you for response and tell me about future-dev branch very much. I'l try to change my project to that branch version !