OSX Cocoa embed opengl view inside webview

2019-07-23 14:50发布

I am trying to build an MacOS app which create an OpenGL view and embed it to webview as it's element (using OpenGL instead of WebGL). The main goal is to use the web (html/javascript) as UI and draw the result with OpenGL view. (besides, the OpenGL view will also handle the user input)

The issue is the overlay between the webview and OpenGL view. If OpenGL view on top of webview, the webview UI (like: dropdown box) possible cut by the OpenGL view. The webview on top of OpenGL view, all of the webview view will block the OpenGL view.

Is there any solution to solve this? (OpenGL and Webview)

1条回答
甜甜的少女心
2楼-- · 2019-07-23 14:57

WebKit has an interesting functionality where you can associate webviews with certain MIME types to your own custom NSView classes.

In your HTML webview, you can put an iframe which has a custom mimetype (e.g. "application/my-custom-view").

After that, from your native app, you can call:

[WebView registerViewClass:[MyCustomView class] representationClass:[MyCustomRepresentation class] forMIMEType:@"application/my-custom-view"];

See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Webkit/Classes/WebView_Class/Reference/Reference.html#//apple_ref/occ/clm/WebView/registerViewClass:representationClass:forMIMEType:

MyCustomRepresentation can be pretty lightweight, my Representation class doesn't do anything, it just defines stub delegate functions.

查看更多
登录 后发表回答