Skip to content

Conversation

yousifd
Copy link
Contributor

@yousifd yousifd commented Jul 29, 2025

This PR adds the following:

  • Exposes a frustumOffset property in iOS and Android that allows a user to specify how much of the edges of the screen is out of view and shouldn't be rendered in logical pixel units.
  • Modifies the projection matrix computation to compute the fov with a top offset from the provided frustumOffset property.
  • Modifies the Metal, OpenGL, and Vulkan renderers to apply a scissor test given the frustumOffset to reject fragments at the edges of the screen which might be behind UI elements.

Copy link

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +17.1Ki  +0.2% +32.0Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-3676-compared-to-main.txt

Copy link

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +13.6Ki  +0.0% +5.16Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3676-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +33% +38.2Mi  +448% +26.8Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3676-compared-to-legacy.txt

Copy link

Benchmark Results ⚡

Benchmark                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                            -0.0130         -0.0127             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-3676-compared-to-main.txt

* @param offset_ A set of edge insets in logical pixels.
* @return reference to MapOptions for chaining options together.
*/
MapOptions& withFrustumOffset(const EdgeInsets& offset_);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using MapOptions::withFrustumOffset for static setup sounds like a worse option than resizing the draw surface to match the content. I think Map::setFrustumOffset handles all use cases and encourages dynamic updates (when needed).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what if you need to draw to a larger area layer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I'd think that most people would solve it via composition instead of searching for this specific option. If withFrustumOffset is used the color and depth attachments are still allocated to the full size. My point is it's not the most intuitive option for static layouts and if you still need it you can use Map::setFrustumOffset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
Frustum offset used to disable rendering of elements at the edge of the screen

Offset applied to camera frustum and scissor rectangle. The camrea frustum is modofied
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Offset applied to camera frustum and scissor rectangle. The camrea frustum is modofied
Offset applied to camera frustum and scissor rectangle. The camrea frustum is modified

@@ -117,6 +117,13 @@ public void enableRenderingStatsView(boolean value) {
nativeMapView.enableRenderingStatsView(value);
}

/**
* Set frustum offset to disable rendering for edges of the screen
Copy link
Member

@louwers louwers Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could make the documentation comments similar for iOS and Android.


class ScissorRect {
public:
int32_t x, y;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put these on their own lines.

int32_t x, y;
uint32_t width, height;

bool operator==(const ScissorRect& other) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using C++20 I think we can use = default now for both operator== and operator!=. https://en.cppreference.com/w/cpp/language/default_comparisons.html

class ScissorRect {
public:
int32_t x, y;
uint32_t width, height;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put on individual lines.

Copy link
Member

@louwers louwers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider adding some kind of test coverage, if only for the setters/getters of the platforms.

Android Build needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants