WebGL in QuickLook

江枫思渺然 提交于 2019-12-14 04:20:14

问题


Is it possible to use WebGL in a quicklook plugin?

I followed this tutorial replacing the relevant code in GeneratePreviewForURL.m with

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) {
    NSString *_content = [NSString stringWithContentsOfURL:(__bridge NSURL *)url encoding:NSUTF8StringEncoding error:nil];
    NSString* path = @"/Users/myusername/Downloads/TodoQL/demo.html";

    NSError *error = nil;
    NSString* _html = [NSString stringWithContentsOfFile:path
      encoding:NSUTF8StringEncoding
       error:&error];
   if(error) { // If error object was instantiated, handle it.
      NSLog(@"ERROR while loading from file: %@", error);
      }
    NSLog(@"\n%@\n",_html);
    QLPreviewRequestSetDataRepresentation(preview,(__bridge CFDataRef)[_html dataUsingEncoding:NSUTF8StringEncoding],kUTTypeHTML,NULL);

    return noErr;
}

void CancelPreviewGeneration(void *thisInterface, QLPreviewRequestRef preview) {
    // Implement only if supported 
}

For debugging, this is set up to discard the contents of of the file quicklook is given and rather just render a local html file located at /Users/myusername/Downloads/TodoQL/demo.html.

I use this barebones WebGL example, altering only slight to show that the gl context is not being loaded:

gl = canvas.getContext("experimental-webgl");
if(!gl)
{
  document.body.innerHTML = ":-(";
  return;
}

Indeed, running /usr/bin/qlmanage -p example.example shows the disappointed face rather than the webgl demo.

In Safari, this demo works so long as I "Enable WebGL". Do I need to enable WebGL somehow for quicklook plugins? How?

来源:https://stackoverflow.com/questions/18443710/webgl-in-quicklook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!