Track current program in context, rather than renderers

This commit is contained in:
Tom Payne
2013-10-31 16:48:37 +01:00
parent 10c41cd064
commit 26fa8d9d53
3 changed files with 40 additions and 22 deletions

View File

@@ -56,6 +56,12 @@ ol.webgl.Context = function(canvas, gl) {
*/
this.programCache_ = {};
/**
* @private
* @type {WebGLProgram}
*/
this.currentProgram_ = null;
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST,
this.handleWebGLContextLost, false, this);
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED,
@@ -226,6 +232,7 @@ ol.webgl.Context.prototype.handleWebGLContextLost = function() {
goog.object.clear(this.bufferCache_);
goog.object.clear(this.shaderCache_);
goog.object.clear(this.programCache_);
this.currentProgram_ = null;
};
@@ -236,6 +243,22 @@ ol.webgl.Context.prototype.handleWebGLContextRestored = function() {
};
/**
* @param {WebGLProgram} program Program.
* @return {boolean} Changed.
*/
ol.webgl.Context.prototype.useProgram = function(program) {
if (program == this.currentProgram_) {
return false;
} else {
var gl = this.getGL();
gl.useProgram(program);
this.currentProgram_ = program;
return true;
}
};
/**
* @private
* @type {goog.log.Logger}