Fix projection matrix for raster image drawables (#2242)
This commit is contained in:
@@ -32,7 +32,7 @@ mat4 LayerTweaker::getTileMatrix(const UnwrappedTileID& tileID,
|
||||
style::TranslateAnchorType anchor,
|
||||
bool nearClipped,
|
||||
bool inViewportPixelUnits,
|
||||
[[maybe_unused]] const gfx::Drawable& drawable,
|
||||
const gfx::Drawable& drawable,
|
||||
bool aligned) {
|
||||
// from RenderTile::prepare
|
||||
mat4 tileMatrix;
|
||||
@@ -40,24 +40,7 @@ mat4 LayerTweaker::getTileMatrix(const UnwrappedTileID& tileID,
|
||||
if (const auto& origin{drawable.getOrigin()}; origin.has_value()) {
|
||||
matrix::translate(tileMatrix, tileMatrix, origin->x, origin->y, 0);
|
||||
}
|
||||
|
||||
// nearClippedMatrix has near plane moved further, to enhance depth buffer precision
|
||||
auto projMatrix = aligned ? parameters.transformParams.alignedProjMatrix
|
||||
: (nearClipped ? parameters.transformParams.nearClippedProjMatrix
|
||||
: parameters.transformParams.projMatrix);
|
||||
|
||||
#if !MLN_RENDER_BACKEND_OPENGL
|
||||
// If this drawable is participating in depth testing, offset the
|
||||
// projection matrix NDC depth range for the drawable's layer and sublayer.
|
||||
if (!drawable.getIs3D() && drawable.getEnableDepth()) {
|
||||
projMatrix[14] -= ((1 + drawable.getLayerIndex()) * PaintParameters::numSublayers -
|
||||
drawable.getSubLayerIndex()) *
|
||||
PaintParameters::depthEpsilon;
|
||||
}
|
||||
#endif
|
||||
|
||||
matrix::multiply(tileMatrix, projMatrix, tileMatrix);
|
||||
|
||||
multiplyWithProjectionMatrix(/*in-out*/ tileMatrix, parameters, drawable, nearClipped, aligned);
|
||||
return RenderTile::translateVtxMatrix(
|
||||
tileID, tileMatrix, translation, anchor, parameters.state, inViewportPixelUnits);
|
||||
}
|
||||
@@ -67,4 +50,31 @@ void LayerTweaker::updateProperties(Immutable<style::LayerProperties> newProps)
|
||||
propertiesUpdated = true;
|
||||
}
|
||||
|
||||
void LayerTweaker::multiplyWithProjectionMatrix(/*in-out*/ mat4& matrix,
|
||||
const PaintParameters& parameters,
|
||||
[[maybe_unused]] const gfx::Drawable& drawable,
|
||||
bool nearClipped,
|
||||
bool aligned) {
|
||||
// nearClippedMatrix has near plane moved further, to enhance depth buffer precision
|
||||
const auto& projMatrixRef = aligned ? parameters.transformParams.alignedProjMatrix
|
||||
: (nearClipped ? parameters.transformParams.nearClippedProjMatrix
|
||||
: parameters.transformParams.projMatrix);
|
||||
#if !MLN_RENDER_BACKEND_OPENGL
|
||||
// If this drawable is participating in depth testing, offset the
|
||||
// projection matrix NDC depth range for the drawable's layer and sublayer.
|
||||
if (!drawable.getIs3D() && drawable.getEnableDepth()) {
|
||||
// copy and adjust the projection matrix
|
||||
mat4 projMatrix = projMatrixRef;
|
||||
projMatrix[14] -= ((1 + drawable.getLayerIndex()) * PaintParameters::numSublayers -
|
||||
drawable.getSubLayerIndex()) *
|
||||
PaintParameters::depthEpsilon;
|
||||
// multiply with the copy
|
||||
matrix::multiply(matrix, projMatrix, matrix);
|
||||
// early return
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
matrix::multiply(matrix, projMatrixRef, matrix);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -55,8 +55,9 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup,
|
||||
// this is an image drawable
|
||||
if (const auto& data = drawable.getData()) {
|
||||
const gfx::ImageDrawableData& imageData = static_cast<const gfx::ImageDrawableData&>(*data);
|
||||
|
||||
matrix = imageData.matrix;
|
||||
multiplyWithProjectionMatrix(
|
||||
/*in-out*/ matrix, parameters, drawable, /*nearClipped*/ false, /*aligned*/ true);
|
||||
} else {
|
||||
Log::Error(Event::General, "Invalid raster layer drawable: neither tile id nor image data is set.");
|
||||
return;
|
||||
|
||||
@@ -101,7 +101,9 @@ void RenderImageSource::prepare(const SourcePrepareParameters& parameters) {
|
||||
mat4& matrix = matrices[i];
|
||||
matrix::identity(matrix);
|
||||
transformParams.state.matrixFor(matrix, tileIds[i]);
|
||||
#if MLN_LEGACY_RENDERER
|
||||
matrix::multiply(matrix, transformParams.alignedProjMatrix, matrix);
|
||||
#endif
|
||||
}
|
||||
renderData = std::make_unique<ImageSourceRenderData>(bucket, std::move(matrices), baseImpl->id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user