Jump to content

Is there an elegant way to obtain 'engine._gl' ?


heyzxz
 Share

Recommended Posts

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 :)

 

Link to comment
Share on other sites

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 )5a5f872769ae1_ScreenShot2018-01-18at1_24_33AM.thumb.png.23a022a776daff1b2ec3ce6e299f98a6.png

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!

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...