Track current program in context, rather than renderers
This commit is contained in:
@@ -425,7 +425,6 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
|
|||||||
|
|
||||||
context.bindBuffer(goog.webgl.ARRAY_BUFFER, this.arrayBuffer_);
|
context.bindBuffer(goog.webgl.ARRAY_BUFFER, this.arrayBuffer_);
|
||||||
|
|
||||||
var currentProgram = null;
|
|
||||||
var locations;
|
var locations;
|
||||||
for (i = 0, ii = layersArray.length; i < ii; ++i) {
|
for (i = 0, ii = layersArray.length; i < ii; ++i) {
|
||||||
layer = layersArray[i];
|
layer = layersArray[i];
|
||||||
@@ -453,10 +452,6 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var program = context.getProgram(fragmentShader, vertexShader);
|
var program = context.getProgram(fragmentShader, vertexShader);
|
||||||
if (program != currentProgram) {
|
|
||||||
|
|
||||||
gl.useProgram(program);
|
|
||||||
currentProgram = program;
|
|
||||||
|
|
||||||
if (useColor) {
|
if (useColor) {
|
||||||
if (goog.isNull(this.colorLocations_)) {
|
if (goog.isNull(this.colorLocations_)) {
|
||||||
@@ -476,6 +471,7 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.useProgram(program)) {
|
||||||
gl.enableVertexAttribArray(locations.a_position);
|
gl.enableVertexAttribArray(locations.a_position);
|
||||||
gl.vertexAttribPointer(
|
gl.vertexAttribPointer(
|
||||||
locations.a_position, 2, goog.webgl.FLOAT, false, 16, 0);
|
locations.a_position, 2, goog.webgl.FLOAT, false, 16, 0);
|
||||||
@@ -483,7 +479,6 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
|
|||||||
gl.vertexAttribPointer(
|
gl.vertexAttribPointer(
|
||||||
locations.a_texCoord, 2, goog.webgl.FLOAT, false, 16, 8);
|
locations.a_texCoord, 2, goog.webgl.FLOAT, false, 16, 8);
|
||||||
gl.uniform1i(locations.u_texture, 0);
|
gl.uniform1i(locations.u_texture, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
layerRenderer = this.getLayerRenderer(layer);
|
layerRenderer = this.getLayerRenderer(layer);
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
|||||||
gl.disable(goog.webgl.BLEND);
|
gl.disable(goog.webgl.BLEND);
|
||||||
|
|
||||||
var program = context.getProgram(this.fragmentShader_, this.vertexShader_);
|
var program = context.getProgram(this.fragmentShader_, this.vertexShader_);
|
||||||
gl.useProgram(program);
|
context.useProgram(program);
|
||||||
if (goog.isNull(this.locations_)) {
|
if (goog.isNull(this.locations_)) {
|
||||||
this.locations_ =
|
this.locations_ =
|
||||||
new ol.renderer.webgl.tilelayer.shader.Locations(gl, program);
|
new ol.renderer.webgl.tilelayer.shader.Locations(gl, program);
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ ol.webgl.Context = function(canvas, gl) {
|
|||||||
*/
|
*/
|
||||||
this.programCache_ = {};
|
this.programCache_ = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {WebGLProgram}
|
||||||
|
*/
|
||||||
|
this.currentProgram_ = null;
|
||||||
|
|
||||||
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST,
|
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST,
|
||||||
this.handleWebGLContextLost, false, this);
|
this.handleWebGLContextLost, false, this);
|
||||||
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED,
|
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.bufferCache_);
|
||||||
goog.object.clear(this.shaderCache_);
|
goog.object.clear(this.shaderCache_);
|
||||||
goog.object.clear(this.programCache_);
|
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
|
* @private
|
||||||
* @type {goog.log.Logger}
|
* @type {goog.log.Logger}
|
||||||
|
|||||||
Reference in New Issue
Block a user