Add and use ol.renderer.webgl.Layer#composeFrame
This commit is contained in:
@@ -7,6 +7,8 @@ goog.require('goog.webgl');
|
||||
goog.require('ol.FrameState');
|
||||
goog.require('ol.layer.Layer');
|
||||
goog.require('ol.renderer.Layer');
|
||||
goog.require('ol.renderer.webgl.map.shader.Color');
|
||||
goog.require('ol.renderer.webgl.map.shader.Default');
|
||||
goog.require('ol.vec.Mat4');
|
||||
|
||||
|
||||
@@ -105,6 +107,18 @@ ol.renderer.webgl.Layer = function(mapRenderer, layer) {
|
||||
*/
|
||||
this.saturationMatrix_ = goog.vec.Mat4.createFloat32();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.renderer.webgl.map.shader.Color.Locations}
|
||||
*/
|
||||
this.colorLocations_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.renderer.webgl.map.shader.Default.Locations}
|
||||
*/
|
||||
this.defaultLocations_ = null;
|
||||
|
||||
};
|
||||
goog.inherits(ol.renderer.webgl.Layer, ol.renderer.Layer);
|
||||
|
||||
@@ -163,6 +177,84 @@ ol.renderer.webgl.Layer.prototype.bindFramebuffer =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.FrameState} frameState Frame state.
|
||||
* @param {ol.layer.LayerState} layerState Layer state.
|
||||
* @param {ol.webgl.Context} context Context.
|
||||
*/
|
||||
ol.renderer.webgl.Layer.prototype.composeFrame =
|
||||
function(frameState, layerState, context) {
|
||||
|
||||
var gl = context.getGL();
|
||||
|
||||
var useColor =
|
||||
layerState.brightness ||
|
||||
layerState.contrast != 1 ||
|
||||
layerState.hue ||
|
||||
layerState.saturation != 1;
|
||||
|
||||
var fragmentShader, vertexShader;
|
||||
if (useColor) {
|
||||
fragmentShader = ol.renderer.webgl.map.shader.ColorFragment.getInstance();
|
||||
vertexShader = ol.renderer.webgl.map.shader.ColorVertex.getInstance();
|
||||
} else {
|
||||
fragmentShader =
|
||||
ol.renderer.webgl.map.shader.DefaultFragment.getInstance();
|
||||
vertexShader = ol.renderer.webgl.map.shader.DefaultVertex.getInstance();
|
||||
}
|
||||
|
||||
var program = context.getProgram(fragmentShader, vertexShader);
|
||||
|
||||
// FIXME colorLocations_ and defaultLocations_ should be shared somehow
|
||||
var locations;
|
||||
if (useColor) {
|
||||
if (goog.isNull(this.colorLocations_)) {
|
||||
locations =
|
||||
new ol.renderer.webgl.map.shader.Color.Locations(gl, program);
|
||||
this.colorLocations_ = locations;
|
||||
} else {
|
||||
locations = this.colorLocations_;
|
||||
}
|
||||
} else {
|
||||
if (goog.isNull(this.defaultLocations_)) {
|
||||
locations =
|
||||
new ol.renderer.webgl.map.shader.Default.Locations(gl, program);
|
||||
this.defaultLocations_ = locations;
|
||||
} else {
|
||||
locations = this.defaultLocations_;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.useProgram(program)) {
|
||||
gl.enableVertexAttribArray(locations.a_position);
|
||||
gl.vertexAttribPointer(
|
||||
locations.a_position, 2, goog.webgl.FLOAT, false, 16, 0);
|
||||
gl.enableVertexAttribArray(locations.a_texCoord);
|
||||
gl.vertexAttribPointer(
|
||||
locations.a_texCoord, 2, goog.webgl.FLOAT, false, 16, 8);
|
||||
gl.uniform1i(locations.u_texture, 0);
|
||||
}
|
||||
|
||||
gl.uniformMatrix4fv(
|
||||
locations.u_texCoordMatrix, false, this.getTexCoordMatrix());
|
||||
gl.uniformMatrix4fv(locations.u_projectionMatrix, false,
|
||||
this.getProjectionMatrix());
|
||||
if (useColor) {
|
||||
gl.uniformMatrix4fv(locations.u_colorMatrix, false,
|
||||
this.getColorMatrix(
|
||||
layerState.brightness,
|
||||
layerState.contrast,
|
||||
layerState.hue,
|
||||
layerState.saturation
|
||||
));
|
||||
}
|
||||
gl.uniform1f(locations.u_opacity, layerState.opacity);
|
||||
gl.bindTexture(goog.webgl.TEXTURE_2D, this.getTexture());
|
||||
gl.drawArrays(goog.webgl.TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} brightness Brightness.
|
||||
* @param {number} contrast Contrast.
|
||||
|
||||
Reference in New Issue
Block a user