Better handle uniform locations in shaders
This commit is contained in:
@@ -8,46 +8,46 @@ import WebGLContext, {DefaultUniform} from '../../webgl/Context';
|
||||
import WebGLVertex from "../../webgl/Vertex";
|
||||
import WebGLFragment from "../../webgl/Fragment";
|
||||
|
||||
const VERTEX_SHADER =
|
||||
'attribute vec2 a_position;' +
|
||||
'attribute vec2 a_texCoord;' +
|
||||
'attribute float a_opacity;' +
|
||||
'attribute float a_rotateWithView;' +
|
||||
'' +
|
||||
'uniform mat4 u_projectionMatrix;' +
|
||||
'uniform mat4 u_offsetScaleMatrix;' +
|
||||
'uniform mat4 u_offsetRotateMatrix;' +
|
||||
'' +
|
||||
'varying vec2 v_texCoord;' +
|
||||
'varying float v_opacity;' +
|
||||
'' +
|
||||
'void main(void) {' +
|
||||
' mat4 offsetMatrix = u_offsetScaleMatrix;' +
|
||||
' if (a_rotateWithView == 1.0) {' +
|
||||
' offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;' +
|
||||
' }' +
|
||||
' vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);' +
|
||||
' gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;' +
|
||||
' v_texCoord = a_texCoord;' +
|
||||
' v_opacity = a_opacity;' +
|
||||
'}';
|
||||
const VERTEX_SHADER = `
|
||||
attribute vec2 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
attribute float a_opacity;
|
||||
attribute float a_rotateWithView;
|
||||
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_offsetScaleMatrix;
|
||||
uniform mat4 u_offsetRotateMatrix;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
varying float v_opacity;
|
||||
|
||||
void main(void) {
|
||||
mat4 offsetMatrix = u_offsetScaleMatrix;
|
||||
if (a_rotateWithView == 1.0) {
|
||||
offsetMatrix = u_offsetScaleMatrix * u_offsetRotateMatrix;
|
||||
}
|
||||
vec4 offsets = offsetMatrix * vec4(a_offsets, 0.0, 0.0);
|
||||
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;
|
||||
v_texCoord = a_texCoord;
|
||||
v_opacity = a_opacity;
|
||||
}`;
|
||||
|
||||
const FRAGMENT_SHADER =
|
||||
'uniform float u_opacity;' +
|
||||
'uniform sampler2D u_image;' +
|
||||
'' +
|
||||
'varying vec2 v_texCoord;' +
|
||||
'varying float v_opacity;' +
|
||||
'' +
|
||||
'void main(void) {' +
|
||||
' vec4 texColor = texture2D(u_image, v_texCoord);' +
|
||||
' gl_FragColor.rgb = texColor.rgb;' +
|
||||
' float alpha = texColor.a * v_opacity * u_opacity;' +
|
||||
' if (alpha == 0.0) {' +
|
||||
' discard;' +
|
||||
' }' +
|
||||
' gl_FragColor.a = alpha;' +
|
||||
'}';
|
||||
const FRAGMENT_SHADER = `
|
||||
uniform float u_opacity;
|
||||
uniform sampler2D u_image;
|
||||
|
||||
varying vec2 v_texCoord;
|
||||
varying float v_opacity;
|
||||
|
||||
void main(void) {
|
||||
vec4 texColor = texture2D(u_image, v_texCoord);
|
||||
gl_FragColor.rgb = texColor.rgb;
|
||||
float alpha = texColor.a * v_opacity * u_opacity;
|
||||
if (alpha == 0.0) {
|
||||
discard;
|
||||
}
|
||||
gl_FragColor.a = alpha;
|
||||
}`;
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -100,8 +100,8 @@ class WebGLPointsLayerRenderer extends LayerRenderer {
|
||||
* @inheritDoc
|
||||
*/
|
||||
prepareFrame(frameState) {
|
||||
const vectorLayer = this.getLayer();
|
||||
const vectorSource = vectorLayer.getSource();
|
||||
const vectorLayer = /** @type {import("../../layer/Vector.js").default} */ (this.getLayer());
|
||||
const vectorSource = /** @type {import("../../source/Vector.js").default} */ (vectorLayer.getSource());
|
||||
|
||||
if (this.sourceRevision_ >= vectorSource.getRevision()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user