Draw WKWebView into OpenGL Texture

I'm trying to figure out how to display a Web Browser inside my iOS VR app (Obj-c, SceneKit and raw OpenGL), and the part i'm not fully understanding is how to get the WKWebView to draw it's content into a Pixel Buffer of some sort, so I can use the speed of CVOpenGLESTextureCacheCreateTextureFromImage to convert the pixel data into a OpenGl Texture quickly/efficently and display it on a floating surface.


I'm already doing something simular with the video portion of my app, but it has a AVPlayerItemVideoOutput, which produced the pixel buffer, but I can't figure out how to massage the CALayer into a Buffer so I can convert it into a texture to then draw in opengl.


I know it has something to do with drawLayer:(Layer) ,(Context), but searching online hasn't been very fruitful.


And i'm not using SceneKit like you would assume, the app was built before GVR for Scenekit was a thing, so every part of VR is handled manually (scenekit to textures, textures to opengl for Left/Right eye distortion mesh).

Answered by DTS Engineer in 899370022

Hello @SlashAndBurn

Displaying the browser as a scene view is an option for 3D environments, but for virtual reality: a native WKWebView overlay can't be rendered twice with different eye projections, there's no way to render the content individually per-eye to achieve the stereo effect.

You can potentially try takeSnapshot but will not have the same interactivity as a full browser.

If you'd like us to consider adding the necessary functionality, please file an enhancement request using Feedback Assistant. Once you file the request, please post the FB number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Thank you,

 Travis

On macOS there's https://developer.apple.com/documentation/quartzcore/carenderer?language=objc, but I'm not aware of an iOS equivalent...

I used CRenderer for off-screen rendering of WKWebView. On the iOS 16 system version, the web page content was blank, but it displayed normally on iOS 18 and above systems. How can this problem be solved?

Hello @SlashAndBurn

Displaying the browser as a scene view is an option for 3D environments, but for virtual reality: a native WKWebView overlay can't be rendered twice with different eye projections, there's no way to render the content individually per-eye to achieve the stereo effect.

You can potentially try takeSnapshot but will not have the same interactivity as a full browser.

If you'd like us to consider adding the necessary functionality, please file an enhancement request using Feedback Assistant. Once you file the request, please post the FB number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Thank you,

 Travis

Draw WKWebView into OpenGL Texture
 
 
Q