vujadin / BabylonHx

Port of Babylon.js 3D engine to Haxe.
http:/paradoxplay.com/babylonhx
Apache License 2.0
187 stars 43 forks source link

WebGL texture hijacking issue with OpenFL #78

Open Matan opened 8 years ago

Matan commented 8 years ago

Hi,

I've come across an issue where a Babylon texture will simply hijack the last loaded/rendered OpenFL texture.

I've modified the openfl sample project to illustrate the issue: https://github.com/Matan/BabylonHx/commit/44035b715cff28cb19e80fb9470284daeea9e4c6

Compile with: openfl build project_openfl.xml html5 -debug

Edit the project_openfl.xml between 'dom' and 'webgl' to see the difference: https://github.com/Matan/BabylonHx/blob/master/project_openfl.xml#L13-L14

When compiled with 'dom', everything works as expected. However, when compiled with 'webgl' the ground texture goes black end renders the FPS counter on it.

In my actual project I'm prototyping, it seems to just render the last known image buffer. I can't jump into the GL internals now, was hoping someone would have a quick fix.

Thanks, Matan

vujadin commented 8 years ago

As far as I know, if you compile with 'dom' flag it will create another canvas on top of the first one which it will use for 2D rendering (possibly will use context2d for this, not sure though...), while with 'webgl' it will create single canvas and render both 3D and 2D through webgl. The problem is that BHx leaves GL context in a state that OpenFL doesn't like and its not only about the texture(s), depending on the effects used in 3D scene you'll get all kinds of strange stuff in your final render. So the solution to this problem I guess is to return GL context to the state OpenFL expects it to be. This bug was reported so many times but I really have no time to mess with this. Any help would be great :)

Matan commented 8 years ago

Hi, thanks for the explanation. And thanks for building this great library. :) Unfortunately I'm also a bit too busy to jump in and see what I can do.

What I'd like to try is to have 2 canvas objects, one for OpenFL and one for Babylon. Then approach Babylon as a 'purejs' compile. Obviously this has some downsides, but no more so than the "Flash with Stage3D" approach. Thus, 2D layer at the top and 3D layer at the bottom. Could work. :)

Thanks again!

jobs-git commented 8 years ago

Hi! I would like help, how could we return a GL context that OpenFL expects it to be?