Created
October 10, 2009 22:11
-
-
Save xeolabs/207184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** An example of a installation of a backend for a canvas. | |
*/ | |
SceneJs.Backend.installCanvasBackend(new (function() { | |
this.canvasType = 'awesome-new-canvas-0.1'; | |
/** SceneJs.Backend's acquireCanvas method calls this method on each installed | |
* canvas backend to poll them for a context on the given canvas. As soon as one | |
* is able to provide a context, the canvas and the successful backend become active. | |
* | |
* Then, when a node requests a node backend from SceneJs.Backend getNodeBackend, that | |
* method will attempt to provide a node backend for the canvas. | |
* | |
* The context is returned wrapped in an object that may bundle resources | |
* alongside the context. | |
*/ | |
this.getConfig = function(canvas) { | |
var cfg = null; | |
var context = null; | |
if (!canvas) { | |
throw 'canvas is undefined'; | |
} | |
try { | |
context = canvas.getContext(this.canvasType); | |
} catch(e) { | |
} | |
return context ? { canvas: canvas, context: context } : null; | |
}; | |
/** SceneJs.aquireCanvas calls this method to signal this canvas plugin that it | |
* has just acquired a context on a canvas of the type this plugin supports. | |
* | |
* The cfg parameter is the same object returned by this plugin's getConfig method. | |
* In this method, the plugin has a chance to intercept the acquisition and | |
* maybe do some pre-acquire operations on the cfg object or the canvas context | |
* it wraps. | |
*/ | |
this.aquire = function(cfg) { | |
var context = cfg.context; | |
//... | |
}; | |
/** SceneJs.releaseCanvas calls this method to signal this canvas plugin that it | |
* is about to release a context that was previously acquired on a canvas of | |
* the type this plugin supports. | |
* The cfg parameter is the same object returned by this plugin's getConfig method. | |
* In this method, the plugin has a chance to intercept the release and | |
* maybe do some pre-release operations on the cfg object or the canvas context | |
* it wraps. | |
*/ | |
this.release = function(cfg) { | |
cfg.context.swapBuffers(); | |
}; | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment