问题
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