[core] force explicit initialization of uniform values
force users to use the actual names to avoid implicit conversion accidentally targeting the wrong shader
This commit is contained in:
@@ -18,7 +18,6 @@ class Uniform {
|
||||
public:
|
||||
class Value {
|
||||
public:
|
||||
Value(T t_) : t(std::move(t_)) {}
|
||||
T t;
|
||||
};
|
||||
|
||||
|
||||
@@ -54,11 +54,11 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye
|
||||
colorModeForRenderPass(),
|
||||
parameters.shaders.fill,
|
||||
FillColorUniforms::Values {
|
||||
matrixForTile(tileID),
|
||||
properties.backgroundOpacity.value,
|
||||
properties.backgroundColor.value,
|
||||
properties.backgroundColor.value,
|
||||
context.viewport.getCurrentValue().size
|
||||
uniforms::u_matrix::Value{ matrixForTile(tileID) },
|
||||
uniforms::u_opacity::Value{ properties.backgroundOpacity.value },
|
||||
uniforms::u_color::Value{ properties.backgroundColor.value },
|
||||
uniforms::u_outline_color::Value{ properties.backgroundColor.value },
|
||||
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
|
||||
},
|
||||
gl::Unindexed<gl::TriangleStrip>(tileTriangleVertexBuffer)
|
||||
});
|
||||
|
||||
@@ -21,6 +21,7 @@ void Painter::renderCircle(PaintParameters& parameters,
|
||||
}
|
||||
|
||||
const CirclePaintProperties& properties = layer.impl->paint;
|
||||
const bool scaleWithMap = properties.circlePitchScale.value == CirclePitchScaleType::Map;
|
||||
|
||||
context.draw({
|
||||
depthModeForSublayer(0, gl::DepthMode::ReadOnly),
|
||||
@@ -30,21 +31,21 @@ void Painter::renderCircle(PaintParameters& parameters,
|
||||
colorModeForRenderPass(),
|
||||
parameters.shaders.circle,
|
||||
CircleUniforms::Values {
|
||||
tile.translatedMatrix(properties.circleTranslate.value,
|
||||
properties.circleTranslateAnchor.value,
|
||||
state),
|
||||
properties.circleOpacity.value,
|
||||
properties.circleColor.value,
|
||||
properties.circleRadius.value,
|
||||
properties.circleBlur.value,
|
||||
properties.circlePitchScale.value == CirclePitchScaleType::Map,
|
||||
properties.circlePitchScale.value == CirclePitchScaleType::Map
|
||||
uniforms::u_matrix::Value{ tile.translatedMatrix(properties.circleTranslate.value,
|
||||
properties.circleTranslateAnchor.value,
|
||||
state) },
|
||||
uniforms::u_opacity::Value{ properties.circleOpacity.value },
|
||||
uniforms::u_color::Value{ properties.circleColor.value },
|
||||
uniforms::u_radius::Value{ properties.circleRadius.value },
|
||||
uniforms::u_blur::Value{ properties.circleBlur.value },
|
||||
uniforms::u_scale_with_map::Value{ scaleWithMap },
|
||||
uniforms::u_extrude_scale::Value{ scaleWithMap
|
||||
? std::array<float, 2> {{
|
||||
pixelsToGLUnits[0] * state.getAltitude(),
|
||||
pixelsToGLUnits[1] * state.getAltitude()
|
||||
}}
|
||||
: pixelsToGLUnits,
|
||||
frame.pixelRatio
|
||||
: pixelsToGLUnits },
|
||||
uniforms::u_devicepixelratio::Value{ frame.pixelRatio },
|
||||
},
|
||||
gl::Segmented<gl::Triangles>(
|
||||
*bucket.vertexBuffer,
|
||||
|
||||
@@ -19,11 +19,11 @@ void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& cl
|
||||
gl::ColorMode::disabled(),
|
||||
shaders->fill,
|
||||
FillColorUniforms::Values {
|
||||
matrixForTile(tileID),
|
||||
0.0f,
|
||||
Color {},
|
||||
Color {},
|
||||
context.viewport.getCurrentValue().size
|
||||
uniforms::u_matrix::Value{ matrixForTile(tileID) },
|
||||
uniforms::u_opacity::Value{ 0.0f },
|
||||
uniforms::u_color::Value{ Color {} },
|
||||
uniforms::u_outline_color::Value{ Color {} },
|
||||
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
|
||||
},
|
||||
gl::Unindexed<gl::Triangles>(tileTriangleVertexBuffer)
|
||||
});
|
||||
|
||||
@@ -25,11 +25,11 @@ void Painter::renderTileDebug(const RenderTile& renderTile) {
|
||||
gl::ColorMode::unblended(),
|
||||
shaders->fill,
|
||||
FillColorUniforms::Values {
|
||||
renderTile.matrix,
|
||||
1.0f,
|
||||
color,
|
||||
color,
|
||||
context.viewport.getCurrentValue().size
|
||||
uniforms::u_matrix::Value{ renderTile.matrix },
|
||||
uniforms::u_opacity::Value{ 1.0f },
|
||||
uniforms::u_color::Value{ color },
|
||||
uniforms::u_outline_color::Value{ color },
|
||||
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
|
||||
},
|
||||
subject
|
||||
});
|
||||
|
||||
@@ -83,13 +83,13 @@ void Painter::renderFill(PaintParameters& parameters,
|
||||
colorModeForRenderPass(),
|
||||
shader,
|
||||
FillColorUniforms::Values {
|
||||
tile.translatedMatrix(properties.fillTranslate.value,
|
||||
properties.fillTranslateAnchor.value,
|
||||
state),
|
||||
properties.fillOpacity.value,
|
||||
properties.fillColor.value,
|
||||
outlineColor,
|
||||
context.viewport.getCurrentValue().size
|
||||
uniforms::u_matrix::Value{ tile.translatedMatrix(properties.fillTranslate.value,
|
||||
properties.fillTranslateAnchor.value,
|
||||
state) },
|
||||
uniforms::u_opacity::Value{ properties.fillOpacity.value },
|
||||
uniforms::u_color::Value{ properties.fillColor.value },
|
||||
uniforms::u_outline_color::Value{ outlineColor },
|
||||
uniforms::u_world::Value{ context.viewport.getCurrentValue().size },
|
||||
},
|
||||
subject
|
||||
});
|
||||
|
||||
@@ -60,19 +60,19 @@ void Painter::renderRaster(PaintParameters& parameters,
|
||||
colorModeForRenderPass(),
|
||||
parameters.shaders.raster,
|
||||
RasterUniforms::Values {
|
||||
tile.matrix,
|
||||
0,
|
||||
1,
|
||||
properties.rasterOpacity.value,
|
||||
0,
|
||||
properties.rasterBrightnessMin.value,
|
||||
properties.rasterBrightnessMax.value,
|
||||
saturationFactor(properties.rasterSaturation.value),
|
||||
contrastFactor(properties.rasterContrast.value),
|
||||
spinWeights(properties.rasterHueRotate.value),
|
||||
1.0f,
|
||||
1.0f,
|
||||
std::array<float, 2> {{ 0.0f, 0.0f }}
|
||||
uniforms::u_matrix::Value{ tile.matrix },
|
||||
uniforms::u_image0::Value{ 0 },
|
||||
uniforms::u_image1::Value{ 1 },
|
||||
uniforms::u_opacity0::Value{ properties.rasterOpacity.value },
|
||||
uniforms::u_opacity1::Value{ 0 },
|
||||
uniforms::u_brightness_low::Value{ properties.rasterBrightnessMin.value },
|
||||
uniforms::u_brightness_high::Value{ properties.rasterBrightnessMax.value },
|
||||
uniforms::u_saturation_factor::Value{ saturationFactor(properties.rasterSaturation.value) },
|
||||
uniforms::u_contrast_factor::Value{ contrastFactor(properties.rasterContrast.value) },
|
||||
uniforms::u_spin_weights::Value{ spinWeights(properties.rasterHueRotate.value) },
|
||||
uniforms::u_buffer_scale::Value{ 1.0f },
|
||||
uniforms::u_scale_parent::Value{ 1.0f },
|
||||
uniforms::u_tl_parent::Value{ std::array<float, 2> {{ 0.0f, 0.0f }} },
|
||||
},
|
||||
gl::Unindexed<gl::TriangleStrip>(rasterVertexBuffer)
|
||||
});
|
||||
|
||||
@@ -125,10 +125,10 @@ void Painter::renderSymbol(PaintParameters& parameters,
|
||||
colorModeForRenderPass(),
|
||||
shaders->collisionBox,
|
||||
CollisionBoxUniforms::Values {
|
||||
tile.matrix,
|
||||
std::pow(2.0f, state.getZoom() - tile.tile.id.overscaledZ),
|
||||
state.getZoom() * 10,
|
||||
(tile.id.canonical.z + 1) * 10
|
||||
uniforms::u_matrix::Value{ tile.matrix },
|
||||
uniforms::u_scale::Value{ std::pow(2.0f, float(state.getZoom() - tile.tile.id.overscaledZ)) },
|
||||
uniforms::u_zoom::Value{ float(state.getZoom() * 10) },
|
||||
uniforms::u_maxzoom::Value{ float((tile.id.canonical.z + 1) * 10) },
|
||||
},
|
||||
gl::Unindexed<gl::Lines>(
|
||||
*bucket.collisionBox.vertexBuffer,
|
||||
|
||||
@@ -23,22 +23,22 @@ FillPatternUniforms::values(mat4 matrix,
|
||||
int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y;
|
||||
|
||||
return FillPatternUniforms::Values {
|
||||
matrix,
|
||||
opacity,
|
||||
framebufferSize,
|
||||
a.tl,
|
||||
a.br,
|
||||
b.tl,
|
||||
b.br,
|
||||
a.size,
|
||||
b.size,
|
||||
fading.fromScale,
|
||||
fading.toScale,
|
||||
fading.t,
|
||||
0,
|
||||
std::array<float, 2> {{ float(pixelX >> 16), float(pixelY >> 16) }},
|
||||
std::array<float, 2> {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }},
|
||||
1.0f / tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom())
|
||||
uniforms::u_matrix::Value{ matrix },
|
||||
uniforms::u_opacity::Value{ opacity },
|
||||
uniforms::u_world::Value{ framebufferSize },
|
||||
uniforms::u_pattern_tl_a::Value{ a.tl },
|
||||
uniforms::u_pattern_br_a::Value{ a.br },
|
||||
uniforms::u_pattern_tl_b::Value{ b.tl },
|
||||
uniforms::u_pattern_br_b::Value{ b.br },
|
||||
uniforms::u_pattern_size_a::Value{ a.size },
|
||||
uniforms::u_pattern_size_b::Value{ b.size },
|
||||
uniforms::u_scale_a::Value{ fading.fromScale },
|
||||
uniforms::u_scale_b::Value{ fading.toScale },
|
||||
uniforms::u_mix::Value{ fading.t },
|
||||
uniforms::u_image::Value{ 0 },
|
||||
uniforms::u_pixel_coord_upper::Value{ std::array<float, 2> {{ float(pixelX >> 16), float(pixelY >> 16) }} },
|
||||
uniforms::u_pixel_coord_lower::Value{ std::array<float, 2> {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }} },
|
||||
uniforms::u_tile_units_to_pixels::Value{ 1.0f / tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom()) },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -29,18 +29,18 @@ Values makeValues(const style::LinePaintProperties& properties,
|
||||
float x = state.getSize().height / 2.0f * std::tan(state.getPitch());
|
||||
|
||||
return Values {
|
||||
tile.translatedMatrix(properties.lineTranslate.value,
|
||||
properties.lineTranslateAnchor.value,
|
||||
state),
|
||||
properties.lineOpacity.value,
|
||||
properties.lineWidth.value / 2,
|
||||
properties.lineGapWidth.value / 2,
|
||||
properties.lineBlur.value + antialiasing,
|
||||
-properties.lineOffset.value,
|
||||
antialiasing / 2,
|
||||
antialiasingMatrix,
|
||||
1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()),
|
||||
(topedgelength + x) / topedgelength - 1.0f,
|
||||
uniforms::u_matrix::Value{ tile.translatedMatrix(properties.lineTranslate.value,
|
||||
properties.lineTranslateAnchor.value,
|
||||
state) },
|
||||
uniforms::u_opacity::Value{ properties.lineOpacity.value },
|
||||
uniforms::u_linewidth::Value{ properties.lineWidth.value / 2 },
|
||||
uniforms::u_gapwidth::Value{ properties.lineGapWidth.value / 2 },
|
||||
uniforms::u_blur::Value{ properties.lineBlur.value + antialiasing },
|
||||
uniforms::u_offset::Value{ -properties.lineOffset.value },
|
||||
uniforms::u_antialiasing::Value{ antialiasing / 2 },
|
||||
uniforms::u_antialiasingmatrix::Value{ antialiasingMatrix },
|
||||
uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) },
|
||||
uniforms::u_extra::Value{ (topedgelength + x) / topedgelength - 1.0f },
|
||||
std::forward<Args>(args)...
|
||||
};
|
||||
}
|
||||
@@ -55,7 +55,7 @@ LineColorUniforms::values(const style::LinePaintProperties& properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
properties.lineColor.value
|
||||
uniforms::u_color::Value{ properties.lineColor.value }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,14 +86,14 @@ LineSDFUniforms::values(const style::LinePaintProperties& properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
properties.lineColor.value,
|
||||
scaleA,
|
||||
scaleB,
|
||||
posA.y,
|
||||
posB.y,
|
||||
properties.lineDasharray.value.t,
|
||||
atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f,
|
||||
0
|
||||
uniforms::u_color::Value{ properties.lineColor.value },
|
||||
uniforms::u_patternscale_a::Value{ scaleA },
|
||||
uniforms::u_patternscale_b::Value{ scaleB },
|
||||
uniforms::u_tex_y_a::Value{ posA.y },
|
||||
uniforms::u_tex_y_b::Value{ posB.y },
|
||||
uniforms::u_mix::Value{ properties.lineDasharray.value.t },
|
||||
uniforms::u_sdfgamma::Value{ atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f },
|
||||
uniforms::u_image::Value{ 0 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,14 +119,14 @@ LinePatternUniforms::values(const style::LinePaintProperties& properties,
|
||||
pixelRatio,
|
||||
tile,
|
||||
state,
|
||||
posA.tl,
|
||||
posA.br,
|
||||
posB.tl,
|
||||
posB.br,
|
||||
sizeA,
|
||||
sizeB,
|
||||
properties.linePattern.value.t,
|
||||
0
|
||||
uniforms::u_pattern_tl_a::Value{ posA.tl },
|
||||
uniforms::u_pattern_br_a::Value{ posA.br },
|
||||
uniforms::u_pattern_tl_b::Value{ posB.tl },
|
||||
uniforms::u_pattern_br_b::Value{ posB.br },
|
||||
uniforms::u_pattern_size_a::Value{ sizeA },
|
||||
uniforms::u_pattern_size_b::Value{ sizeB },
|
||||
uniforms::u_fade::Value{ properties.linePattern.value.t },
|
||||
uniforms::u_image::Value{ 0 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,16 +30,16 @@ Values makeValues(const style::SymbolPropertyValues& values,
|
||||
float zoomAdjust = std::log(values.paintSize / values.layoutSize) / std::log(2);
|
||||
|
||||
return Values {
|
||||
tile.translatedMatrix(values.translate,
|
||||
values.translateAnchor,
|
||||
state),
|
||||
values.opacity,
|
||||
extrudeScale,
|
||||
std::array<float, 2> {{ float(texsize.width) / 4, float(texsize.height) / 4 }},
|
||||
(state.getZoom() - zoomAdjust) * 10.0f,
|
||||
values.rotationAlignment == AlignmentType::Map,
|
||||
0,
|
||||
1,
|
||||
uniforms::u_matrix::Value{ tile.translatedMatrix(values.translate,
|
||||
values.translateAnchor,
|
||||
state) },
|
||||
uniforms::u_opacity::Value{ values.opacity },
|
||||
uniforms::u_extrude_scale::Value{ extrudeScale },
|
||||
uniforms::u_texsize::Value{ std::array<float, 2> {{ float(texsize.width) / 4, float(texsize.height) / 4 }} },
|
||||
uniforms::u_zoom::Value{ float((state.getZoom() - zoomAdjust) * 10) },
|
||||
uniforms::u_rotate_with_map::Value{ values.rotationAlignment == AlignmentType::Map },
|
||||
uniforms::u_texture::Value{ 0 },
|
||||
uniforms::u_fadetexture::Value{ 1 },
|
||||
std::forward<Args>(args)...
|
||||
};
|
||||
}
|
||||
@@ -83,13 +83,13 @@ static SymbolSDFUniforms::Values makeSDFValues(const style::SymbolPropertyValues
|
||||
pixelsToGLUnits,
|
||||
tile,
|
||||
state,
|
||||
color,
|
||||
buffer,
|
||||
(gammaBase + gammaAdjust) * gammaScale,
|
||||
state.getPitch(),
|
||||
-1.0f * state.getAngle(),
|
||||
(state.getSize().width * 1.0f) / (state.getSize().height * 1.0f),
|
||||
values.pitchAlignment == AlignmentType::Map
|
||||
uniforms::u_color::Value{ color },
|
||||
uniforms::u_buffer::Value{ buffer },
|
||||
uniforms::u_gamma::Value{ (gammaBase + gammaAdjust) * gammaScale },
|
||||
uniforms::u_pitch::Value{ state.getPitch() },
|
||||
uniforms::u_bearing::Value{ -1.0f * state.getAngle() },
|
||||
uniforms::u_aspect_ratio::Value{ (state.getSize().width * 1.0f) / (state.getSize().height * 1.0f) },
|
||||
uniforms::u_pitch_with_map::Value{ values.pitchAlignment == AlignmentType::Map }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user