heyzxz Posted January 17, 2018 Share Posted January 17, 2018 Hi there, First I know there is nothing private in javascript, but since it is marked as private in the typescript code , I'm just wondering if there is an official api/ or a nice trick to obtain it without breaking the rule... Quote Link to comment Share on other sites More sharing options...
Amarth2Estel Posted January 17, 2018 Share Posted January 17, 2018 Hi heyzxz ! The type of engine._gl is WebGLRenderingContext. You can use canvas.getContext('webgl') to access it.https://developer.mozilla.org/fr/docs/Web/API/WebGLRenderingContext Quote Link to comment Share on other sites More sharing options...
heyzxz Posted January 17, 2018 Author Share Posted January 17, 2018 2 hours ago, Amarth2Estel said: Hi heyzxz ! The type of engine._gl is WebGLRenderingContext. You can use canvas.getContext('webgl') to access it.https://developer.mozilla.org/fr/docs/Web/API/WebGLRenderingContext Thank you Amarth2Estel Ye it's a feasible way for some cases, but may not be my choice, because firstly I have to do some manually check like 'canvas.getContext("webgl2") || canvas.getContext("experimental-webgl2") || canvas.getContext("webgl") || getContext("experimental-webgl") ...', which is a little bit cumbersome . Secondly, I'm making custom materials, which means in my case, the 'canvas' should be unknowable. Later Edit: the canvas is knowable, there is a public 'engine.getRenderingCanvas()' , so ignore my 'secondly' above Quote Link to comment Share on other sites More sharing options...
Amarth2Estel Posted January 17, 2018 Share Posted January 17, 2018 Oh, sorry, you are completly right ! Perhaps you may use engine.webGLVersion to reduce the number of context keys ? Still not perfect... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2018 Share Posted January 17, 2018 Hello it is hidden and not accessible because the engine is doing a LOT of caching and optimizations in the background So I deeply encourage you to go through engine APIs instead of reaching the gl context directly Quote Link to comment Share on other sites More sharing options...
heyzxz Posted January 17, 2018 Author Share Posted January 17, 2018 1 hour ago, Deltakosh said: Hello it is hidden and not accessible because the engine is doing a LOT of caching and optimizations in the background So I deeply encourage you to go through engine APIs instead of reaching the gl context directly Hello @Deltakosh, Thanks for your reply . But please let me explain why I need engine._gl instead of using engine API. First, in my project, I want to do some preprocessing for some textrues. These textures are HDR and cubemap. To make it success, I need: 1. Create renderTargetCubeTexture( to draw the preprocessed results onto) with correct formats, currently the builtin 'engine.createRenderTargetCubeTexture' has hard coded the texture forms/type to 'RGBA , RGBA , UNSIGNED_BYTE' (see image below), but I may need 'RGBA32F + RGBA + FLOAT ' to match the HDR outputs; (Please let me know if there is another api can do this ) 2. Another problem is I need to bind framebuffer texture with different mipmap levels. Currently all the 'gl.framebufferTexture2D(...)' calls in the engine has hard coded the last 'level' parameter to 0, that's why I want the 'gl' object and call this function manually with different 'level' values. (I know for webgl1.0 the 'level' must be 0, but I tried for webgl2.0, nonzero levels do supported. And I can take care about the browser compatibilities myself). Well you may guessed what kind of preprocessing things I'm doing now, and yes, it's kind of things that IBLBaker can do: convert a single hdr texture, to irradiance map + radiance(specular) map, and some kind of 'integration' on the radiance map for better roughness look, all in realtime. Why I need to do this: 1. Because "I'm red-blooded and have too much time!"... kidding, because I'm on a MAC, no IBLBaker support; 2. Filesize is a big deal in my project, I need to keep things small. Any way, Currently I'll follow the way which Amarth2Estel mentioned and move forward. Once there is a better way found(or some changes bjs made), I'll get back and fix things up. Thank you guys! Quote Link to comment Share on other sites More sharing options...
heyzxz Posted January 17, 2018 Author Share Posted January 17, 2018 God I realized that there is a 'onContextRestored' handling... Things become more difficult now. Maybe I do have to preprocess textures offline... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2018 Share Posted January 17, 2018 1. Could be fixed easily but exposing a property where we can define the formats 2. This one is tougher but perhaps we could think of an API entry point as well I love people with free time and I'm jealous now! Quote Link to comment Share on other sites More sharing options...
heyzxz Posted January 18, 2018 Author Share Posted January 18, 2018 6 hours ago, Deltakosh said: 1. Could be fixed easily but exposing a property where we can define the formats 2. This one is tougher but perhaps we could think of an API entry point as well I love people with free time and I'm jealous now! Thank you Deltakosh, and yes it'll be great if you can make these changes in the future updates. But as I mentioned above, things gonna be more difficult when it comes to thinking about the onContextRestored operation for the (real-time) preprocessed textures. For now, just hacking 'engine._gl' isn't enough for me, something inside the InternalTexture._rebuild still needs to be hack(otherwise they can't be restored correctly if context lost/restored really happens )... which is too hacky and terrible I think... So, Finally I'll turn to think about making some kind of offline preprocess tools to fit my requirements instead of hacking bjs too much. And I'll mark this post as solved as I got enough informations I think. Thank you! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 18, 2018 Share Posted January 18, 2018 my pleasure! Please feel free to propose a PR where we can discuss how to implement these options for you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.