gl2d
Version:
2D graphics package for WebGL
50 lines • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Helper class for rendering graphics with WebGL.
*/
var Renderer = (function () {
/**
* Creates a new rendering object.
* @param the WebGL rendering context to use.
* @param camera the camera that should be used.
*/
function Renderer(gl, camera) {
this.gl = gl;
this.camera = camera;
}
/**
* Called whenever the canvas size changes.
* @param width the new width of the canvas.
* @param height the new height of the canvas.
*/
Renderer.prototype.onSurfaceChanged = function (width, height) {
// Update the viewport to match the new dimensions of the drawing buffer
this.gl.viewport(0, 0, width, height);
// Adjust camera to viewport
this.camera.setViewport(width, height);
};
/**
* Binds the specified program to the WebGL rendering context, if not already bound.
* @param program the program to bind.
*/
Renderer.prototype.attachProgram = function (program) {
// If the program is not already being used
if (this.currentProgram !== program) {
// Start using it
this.gl.useProgram(program.location);
// Notify detached program
if (this.currentProgram) {
this.currentProgram.onDetach(this);
}
// Notify attached program
program.onAttach(this);
// Keep track of the current program
this.currentProgram = program;
}
};
return Renderer;
}());
exports.Renderer = Renderer;
;
//# sourceMappingURL=renderer.js.map