Created
October 10, 2009 22:17
-
-
Save xeolabs/207191 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 installation of a backend through which nodes of a given type | |
* can drive a canvas of a particular type. | |
*/ | |
SceneJs.Backend.installNodeBackend( | |
new (function() { | |
this.canvasType = 'awesome-new-canvas0.1'; | |
this.nodeType = 'my-node-type'; | |
var ctx; | |
var cfg; | |
/** SceneJs.Backend.installNodeBackend calls this method as this node back-end is installed. | |
* | |
* The _ctx parameter is a context that is shared within each set of backends for a | |
* supported canvas type. | |
* | |
* Typically, node backends create resources on the context, such as matrix stacks, shader | |
* script registries etc. | |
* | |
* Node backends that share resources on the context will of course need to be installed in | |
* the order of those dependencies. | |
*/ | |
this.install = function(_ctx) { | |
ctx = _ctx; | |
}; | |
/** SceneJs.Backend.getNodeBackend calls this method just before it returns the node back-end | |
* to the client node that requested it. | |
* | |
* The _cfg parameter is the same object provided by the canvas back-end's getConfig method, | |
* which wraps a context on the canvas supported by this node back-end. | |
* | |
* This method gives the node backend a chance to do setup operations on the _cfg or on the | |
* canvas context it wraps before the client node starts driving the canvas. | |
*/ | |
this.configure = function(_cfg) { | |
cfg = _cfg; | |
}; | |
/** This is an example of a facade method through which the client node can drive the canvas. | |
*/ | |
this.doSomethingToCanvas = function(someData) { | |
cfg.context.doSomething(someData); | |
}; | |
this.doSomethingElseToCanvas = function(someMoreData) { | |
cfg.context.doSomethingElse(someMoreData); | |
}; | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment