HTML and CSS Reference
In-Depth Information
GraphicsResource.prototype.getBinding = function() {
return this.binding_;
GraphicsResource.prototype.setBinding = function(binding) {
this.binding_ = binding;
Texture2D.prototype = new GraphicsResource();
Texture2D.constructor = Texture2D;
function Texture2D(device) {, device);
Texture2D.prototype.getType = function() {
// Corresponds to WebGLRenderingContext.TEXTURE_2D
return 0x0DE1;
The layer is built to reflect those concerns. A GraphicsDevice class handles the creation and deletion of
resources. Those resources are descended from the GraphicsResource class, which serves as a mechanism for
binding the underlying objects WebGL provides. Resources such as textures and buffers would descend from
the resource class and communicate an interface that allows the object's internal state to be modified. The
GraphicsContext class handles the state of the pipeline, containing a snapshot of its current condition, which is used
to prevent redundant calls from being made.
The OpenGL is a C API, so it doesn't have the clear separation of concerns that DirectX offers (see Listing 9-5).
This means that the GraphicsContext class and GraphicsDevice class are more intertwined than is desirable, as
initializing a texture requires calling to the context.
Listing 9-5. Texture Binding
function GraphicsContext(gl) {
this.gl_ = gl;
this.activeTexture_ = 0;
this.boundTextures_ = new Array(8);
GraphicsContext.prototype.setTextureAt = function(index, texture) {
// See if the texture is already bound
if (this.boundTextures_[index] !== texture) {
var gl = this.gl_;
// See if the active texture unit is at the given index
if (this.activeTexture_ !== index) {
gl.activeTexture(gl.TEXTURE0 + index);
this.activeTexture_ = index;
Search WWH ::

Custom Search