Skip to content

Commit cf8bfc7

Browse files
committed
expose frustum offset on ios and enable scissor test for metal
1 parent 5abaaee commit cf8bfc7

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

include/mbgl/mtl/render_pass.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class RenderPass final : public gfx::RenderPass {
6262

6363
void setCullMode(const MTL::CullMode);
6464
void setFrontFacingWinding(const MTL::Winding);
65+
void setScissorRect(const MTL::ScissorRect);
6566

6667
private:
6768
void pushDebugGroup(const char* name) override;
@@ -92,6 +93,7 @@ class RenderPass final : public gfx::RenderPass {
9293

9394
MTL::CullMode currentCullMode = MTL::CullModeNone;
9495
MTL::Winding currentWinding = MTL::WindingClockwise;
96+
MTL::ScissorRect currentScissorRect;
9597
};
9698

9799
} // namespace mtl

platform/ios/src/MLNMapView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,16 @@ MLN_EXPORT
508508
*/
509509
@property (nonatomic, assign) double tileLodZoomShift;
510510

511+
/**
512+
Frustum offset used to disable rendering of elements at the edge of the screen
513+
514+
Offset applied to camera frustum and scissor rectangle. The camrea frustum is modofied
515+
to avoid loading geometry that's behind UI elements at the top of the screen. The scissor
516+
rectangle is used to avoid shading fragments that are behind UI elements at the edges of
517+
the screen. All values are in logical pixels.
518+
*/
519+
@property (nonatomic, assign) UIEdgeInsets frustumOffset;
520+
511521
// MARK: Displaying the User’s Location
512522

513523
/**

platform/ios/src/MLNMapView.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,6 +3301,16 @@ -(double)tileLodZoomShift
33013301
return _mbglMap->getTileLodZoomShift();
33023302
}
33033303

3304+
-(void)setFrustumOffset:(UIEdgeInsets)frustomOffset
3305+
{
3306+
_mbglMap->setFrustumOffset(MLNEdgeInsetsFromNSEdgeInsets(frustomOffset));
3307+
}
3308+
3309+
-(UIEdgeInsets)frustumOffset
3310+
{
3311+
return NSEdgeInsetsFromMLNEdgeInsets(_mbglMap->getFrustumOffset());
3312+
}
3313+
33043314
// MARK: - Accessibility -
33053315

33063316
- (NSString *)accessibilityValue

src/mbgl/mtl/drawable.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ MTL::Winding mapWindingMode(const gfx::CullFaceWindingType mode) noexcept {
121121
}
122122
}
123123

124+
MTL::ScissorRect getMetalScissorRect(gfx::ScissorRect rect) noexcept {
125+
return {static_cast<uint32_t>(rect.x), static_cast<uint32_t>(rect.y), rect.width, rect.height};
126+
}
127+
124128
} // namespace
125129

126130
void Drawable::setColorMode(const gfx::ColorMode& value) {
@@ -215,6 +219,8 @@ void Drawable::draw(PaintParameters& parameters) const {
215219
renderPass.setCullMode(cullMode.enabled ? mapCullMode(cullMode.side) : MTL::CullModeNone);
216220
renderPass.setFrontFacingWinding(mapWindingMode(cullMode.winding));
217221

222+
renderPass.setScissorRect(getMetalScissorRect(parameters.scissorRect));
223+
218224
if (!impl->pipelineState) {
219225
impl->pipelineState = shaderMTL.getRenderPipelineState(
220226
renderable,

src/mbgl/mtl/render_pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void RenderPass::resetState() {
7878

7979
currentCullMode = MTL::CullModeNone;
8080
currentWinding = MTL::WindingClockwise;
81+
currentScissorRect = {0, 0, 0, 0};
8182
}
8283

8384
namespace {
@@ -216,5 +217,13 @@ void RenderPass::setFrontFacingWinding(const MTL::Winding winding) {
216217
}
217218
}
218219

220+
void RenderPass::setScissorRect(const MTL::ScissorRect rect) {
221+
if (rect.x != currentScissorRect.x || rect.y != currentScissorRect.y || rect.width != currentScissorRect.width ||
222+
rect.height != currentScissorRect.height) {
223+
encoder->setScissorRect(rect);
224+
currentScissorRect = rect;
225+
}
226+
}
227+
219228
} // namespace mtl
220229
} // namespace mbgl

0 commit comments

Comments
 (0)