Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self Masking for Vector Layers #584

Merged
merged 3 commits into from
Feb 1, 2024
Merged

Conversation

maurhofer-ubique
Copy link
Contributor

@maurhofer-ubique maurhofer-ubique commented Jan 26, 2024

Summary by CodeRabbit

  • New Features
    • Introduced enhanced stencil operations for more sophisticated masking and rendering techniques across various graphical objects.
    • Added support for masked rendering passes, enabling conditional rendering effects.
  • Bug Fixes
    • Adjusted rendering logic for polygons, lines, and text to correctly handle masking conditions, ensuring accurate visual output.
  • Refactor
    • Streamlined conditional logic in rendering methods for improved clarity and performance.
    • Updated several classes to accommodate new masking and rendering functionalities, ensuring a consistent approach across the platform.
  • Chores
    • Extended data models and configurations to support new masking attributes, facilitating future development and customization.

Copy link
Contributor

coderabbitai bot commented Jan 26, 2024

Walkthrough

The updates focus on enhancing stencil operations and masking logic across various OpenGL objects and layer descriptions in a graphics rendering context. A significant addition is the isPassMasked boolean parameter, streamlining the handling of render passes with masking conditions. The modifications span across Android and iOS bridging, graphics objects, and map layer configurations, indicating a comprehensive effort to refine rendering efficiency and flexibility in response to masking requirements.

Changes

Files Change Summary
.../cpp/graphics/objects/* Introduced stencilMask, validTarget, and zpass for dynamic stencil operations based on masking conditions.
.../jni/graphics/NativeRenderPassConfig.*, .../java/io/openmobilemaps/mapscore/shared/graphics/RenderPassConfig.kt Added isPassMasked to handle new render pass masking logic.
.../ios/MCRenderPassConfig*, djinni/graphics/core.djinni Included isPassMasked parameter in render pass config classes and definitions.
.../graphics/Model/*, .../RenderingContext.swift Adjusted for new stencil operations and isPassMasked logic in rendering methods.
shared/public/*VectorLayerDescription.h, .../Tiled2dMapVectorLayer.h Modified to include selfMasked parameter, affecting layer description initialization.
shared/src/map/layers/* Updated constructor calls for RenderPass and related logic to accommodate isPassMasked and selfMasked parameters.
.../tiled/vector/* Adjustments in vector tile handling and parsing to support new masking and stencil logic.

🐰✨
In the realm of code, where pixels align,
Changes weave through, line by line.
With masks and stencils, we refine,
Crafting worlds, by design.
🌟🎨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Base automatically changed from feature/to-boolean to develop January 26, 2024 08:10
@zimmermannubique zimmermannubique self-requested a review February 1, 2024 08:22
@maurhofer-ubique maurhofer-ubique marked this pull request as ready for review February 1, 2024 08:27
@maurhofer-ubique maurhofer-ubique merged commit df94302 into develop Feb 1, 2024
2 checks passed
@maurhofer-ubique maurhofer-ubique deleted the feature/self-masking branch February 1, 2024 08:27
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 10

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f8596f3 and 0d43778.
Files selected for processing (46)
  • android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Polygon2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/PolygonGroup2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Text2dOpenGl.cpp (1 hunks)
  • bridging/android/java/io/openmobilemaps/mapscore/shared/graphics/RenderPassConfig.kt (1 hunks)
  • bridging/android/jni/graphics/NativeRenderPassConfig.cpp (1 hunks)
  • bridging/android/jni/graphics/NativeRenderPassConfig.h (1 hunks)
  • bridging/ios/MCRenderPassConfig+Private.mm (1 hunks)
  • bridging/ios/MCRenderPassConfig.h (1 hunks)
  • bridging/ios/MCRenderPassConfig.mm (1 hunks)
  • djinni/graphics/core.djinni (1 hunks)
  • ios/graphics/Model/BaseGraphicsObject.swift (1 hunks)
  • ios/graphics/Model/Polygon/PolygonGroup2d.swift (3 hunks)
  • ios/graphics/RenderingContext.swift (1 hunks)
  • shared/public/BackgroundVectorLayerDescription.h (1 hunks)
  • shared/public/LineVectorLayerDescription.h (1 hunks)
  • shared/public/PolygonVectorLayerDescription.h (1 hunks)
  • shared/public/RasterVectorLayerDescription.h (1 hunks)
  • shared/public/RenderPassConfig.h (1 hunks)
  • shared/public/SymbolVectorLayerDescription.h (1 hunks)
  • shared/public/Tiled2dMapVectorLayer.h (1 hunks)
  • shared/public/VectorLayerDescription.h (3 hunks)
  • shared/src/map/layers/icon/IconLayer.cpp (1 hunks)
  • shared/src/map/layers/line/LineLayer.cpp (1 hunks)
  • shared/src/map/layers/polygon/PolygonLayer.cpp (1 hunks)
  • shared/src/map/layers/text/TextLayer.cpp (1 hunks)
  • shared/src/map/layers/tiled/raster/Tiled2dMapRasterLayer.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp (5 hunks)
  • shared/src/map/layers/tiled/vector/geojson/geojsonvt/geojsonvt.hpp (2 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceDataManager.h (1 hunks)
  • shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/sublayers/background/Tiled2dMapVectorBackgroundSubLayer.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (2 hunks)
  • shared/src/map/layers/tiled/vector/tiles/line/Tiled2dMapVectorLineTile.cpp (5 hunks)
  • shared/src/map/layers/tiled/vector/tiles/line/Tiled2dMapVectorLineTile.h (1 hunks)
  • shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonPatternTile.cpp (8 hunks)
  • shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonPatternTile.h (2 hunks)
  • shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonTile.cpp (5 hunks)
  • shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonTile.h (1 hunks)
Additional comments: 54
bridging/ios/MCRenderPassConfig.h (1)
  • 9-12: The addition of isPassMasked to the initializer and factory method is correctly implemented. However, ensure that all calls to these methods throughout the iOS codebase are updated to include the new parameter.
bridging/ios/MCRenderPassConfig+Private.mm (1)
  • 13-20: Correctly integrates isPassMasked into the Objective-C to C++ conversion. No issues found.
bridging/ios/MCRenderPassConfig.mm (2)
  • 10-14: Initialization of isPassMasked in the constructor is correctly implemented.
  • 29-29: The inclusion of isPassMasked in the description method provides better debugging visibility. Good practice.
bridging/android/jni/graphics/NativeRenderPassConfig.h (1)
  • 28-30: Correctly added field_isPassMasked to support the new isPassMasked field in JNI conversions.
bridging/android/jni/graphics/NativeRenderPassConfig.cpp (2)
  • 16-17: Correctly handles the isPassMasked field in the fromCpp JNI conversion method.
  • 26-27: Correctly handles the isPassMasked field in the toCpp JNI conversion method.
shared/public/VectorLayerDescription.h (2)
  • 30-30: The addition of selfMasked as a member variable is correctly implemented. Ensure that all instances of VectorLayerDescription and its derived classes are updated accordingly.
  • 61-68: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [64-75]

The constructor correctly includes the selfMasked parameter. Ensure that all constructor calls are updated to pass this new parameter.

djinni/graphics/core.djinni (1)
  • 61-61: The addition of is_pass_masked to the render_pass_config record is correctly implemented. Ensure that all related Djinni-generated code is regenerated.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceDataManager.cpp (1)
  • 37-39: Correctly adds layer indexes to selfMaskedLayers based on the selfMasked property. This logic ensures that self-masked layers are tracked separately.
shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonTile.h (1)
  • 52-52: The change in the addPolygons method parameter type from unordered_map to vector of vector indicates a significant change in how polygons are managed and grouped. Ensure that the implementation logic in the corresponding .cpp file is updated to handle this new data structure efficiently.
shared/src/map/layers/tiled/vector/tiles/line/Tiled2dMapVectorLineTile.h (1)
  • 46-46: The modification in the addLines method signature reflects a change in how line data is structured and processed. Ensure that the implementation is updated to efficiently handle the new vector of vector structure for line data.
shared/public/BackgroundVectorLayerDescription.h (1)
  • 68-68: The constructor call to VectorLayerDescription within BackgroundVectorLayerDescription correctly passes the new selfMasked parameter. This ensures that the background layer can also support self-masking features.
ios/graphics/Model/BaseGraphicsObject.swift (2)
  • 84-98: The maskStencilState method correctly sets up a stencil state for masking operations. The configuration aligns with typical stencil masking techniques.
  • 100-114: The renderPassMaskStencilState method is correctly implemented to support stencil operations specific to render passes. This addition enhances the flexibility in rendering operations.
shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonPatternTile.h (1)
  • 56-56: The change in the addPolygons method parameter type and the addition of polygonRenderOrder indicate enhancements in polygon pattern rendering and order management. Ensure that the implementation logic efficiently supports these changes.
ios/graphics/Model/Polygon/PolygonGroup2d.swift (1)
  • 20-27: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [84-114]

The modifications to handle renderPass parameter and the introduction of renderPassStencilState based on the isPassMasked property are correctly implemented. This change allows for more nuanced control over stencil operations during rendering.

shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceDataManager.h (1)
  • 87-87: The declaration of std::unordered_set<int32_t> selfMaskedLayers is correctly added to track self-masked layers. This addition is crucial for managing rendering behavior based on self-masking properties.
shared/public/PolygonVectorLayerDescription.h (1)
  • 102-110: The constructor and clone method correctly incorporate the selfMasked parameter, ensuring that polygon layers can specify self-masking behavior. This change is consistent with the overall goal of enhancing rendering capabilities.
ios/graphics/RenderingContext.swift (1)
  • 88-88: The modification to include an isPassMasked boolean parameter in the RenderPassConfig initialization within the clearStencilBuffer method is a significant change. This adjustment implies a semantic change in how rendering passes are handled, particularly in relation to stencil operations. Ensure that:
  • The default value of false for isPassMasked in this context is appropriate and aligns with the intended behavior of stencil buffer clearing operations.
  • All calls to RenderPassConfig throughout the iOS codebase have been audited to ensure that the new isPassMasked parameter is correctly set according to the desired rendering logic.

Consider adding unit tests or integration tests that specifically verify the behavior of rendering operations with and without the isPassMasked flag set, to ensure that this change does not introduce unintended side effects in rendering logic.

android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.cpp (1)
  • 112-112: The change to use a ternary operator for setting the stencil function based on isMaskInversed in the render method simplifies the conditional logic, making it more concise. However, ensure that:
  • The logic accurately reflects the intended behavior for both masked and unmasked rendering scenarios.
  • This change is consistently applied across all similar instances in the codebase where stencil operations are determined by masking conditions.

This refinement improves code readability and maintainability. Just verify that it aligns with the overall rendering strategy and does not introduce any unintended side effects.

shared/src/map/layers/text/TextLayer.cpp (1)
  • 193-193: The adjustment to the RenderPassConfig constructor within the generateRenderPasses method, adding false as an argument, is crucial for controlling rendering behavior. This change implies a specific handling of masking for text layers. To ensure this change is effectively integrated:
  • Confirm that the addition of the false argument to RenderPassConfig aligns with the intended behavior for text layer rendering, particularly in relation to masking and stencil operations.
  • Review all instances where RenderPassConfig is instantiated within the text layer rendering logic to ensure consistency and correctness.

It would be beneficial to conduct thorough testing of text rendering under various conditions (with and without masking) to verify that the rendering behavior remains consistent with expectations and that no unintended side effects have been introduced.

android/src/main/cpp/graphics/objects/PolygonPatternGroup2dOpenGl.cpp (1)
  • 144-158: The logic for calculating stencilMask, validTarget, and zpass based on isMasked and renderPass.isPassMasked conditions is correct and follows the intended functionality for handling masking and rendering passes. However, ensure that the values used for stencilMask and validTarget are consistent with the rest of the rendering pipeline and that they do not conflict with other stencil operations in the application.
shared/src/map/layers/tiled/vector/sublayers/background/Tiled2dMapVectorBackgroundSubLayer.cpp (1)
  • 79-79: The modification to the RenderPass constructor call to include a new boolean parameter (false) is correctly implemented. This change is necessary to support the new self-masking feature by explicitly setting the masking behavior of the render pass. Ensure that all other instances where RenderPass is constructed throughout the codebase are reviewed and updated accordingly if needed to maintain consistency.
android/src/main/cpp/graphics/objects/Text2dOpenGl.cpp (1)
  • 212-226: The implementation for calculating stencilMask, validTarget, and zpass in the render method based on isMasked and renderPass.isPassMasked conditions is correct. This addition aligns with the objective of enhancing the rendering process to support self-masking for text elements. Ensure that the stencil operations defined here are compatible with the overall rendering strategy and do not interfere with other graphical elements.
shared/public/Tiled2dMapVectorLayer.h (1)
  • 108-108: The addition of the selfMasked boolean attribute to the Tiled2dMapVectorLayer class is correctly implemented. This attribute is essential for indicating whether the layer is self-masked or not, aligning with the PR's objective to introduce self-masking capabilities. Ensure that this new attribute is utilized appropriately in the layer's rendering logic and that any necessary logic to handle self-masking is implemented.
shared/src/map/layers/line/LineLayer.cpp (1)
  • 188-188: The addition of false as a parameter to RenderPassConfig constructor in the generateRenderPasses method is a significant change. This boolean likely controls the new self-masking feature for the line layer. Ensure that all instances where RenderPassConfig is instantiated have been updated to include this new parameter where necessary. This change aligns with the PR's objective to introduce self-masking capabilities across various vector layer types.
android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (1)
  • 209-223: The logic for setting stencilMask, validTarget, and zpass based on isMasked and renderPass.isPassMasked conditions, and the subsequent configuration of glStencilFunc and glStencilOp, introduces a more nuanced control over the rendering process, specifically tailored to support self-masking features. This is a critical update for enhancing rendering capabilities with respect to self-masking. Ensure that the logic correctly handles all possible combinations of isMasked and renderPass.isPassMasked to avoid rendering artifacts or unexpected behavior.
android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (1)
  • 203-217: Similar to Quad2dInstancedOpenGl, the adjustments made to stencil operations in Text2dInstancedOpenGl are crucial for implementing self-masking features. The careful calculation of stencilMask, validTarget, and zpass ensures that text rendering can also benefit from self-masking, enhancing the visual quality and performance of text elements in vector layers. It's important to validate that these changes integrate well with the overall rendering pipeline and do not introduce side effects when rendering text with or without self-masking.
shared/src/map/layers/polygon/PolygonLayer.cpp (1)
  • 253-253: The modification to include false as an additional argument in the RenderPassConfig constructor within the generateRenderPasses method for PolygonLayer aligns with the overarching goal of introducing self-masking capabilities. This change is consistent with similar updates in other layer types, ensuring a unified approach to handling self-masking across the rendering engine. It's essential to ensure that this new parameter is correctly utilized in all relevant contexts to fully leverage the self-masking feature.
android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (1)
  • 208-222: The logic for setting glStencilFunc and glStencilOp based on isMasked and renderPass.isPassMasked is correct and aligns with the PR's objective to enhance self-masking capabilities for vector layers. However, ensure that the values used for stencilMask, validTarget, and zpass are consistent with the intended masking behavior and OpenGL standards.
shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonTile.cpp (5)
  • 151-151: The replacement of std::unordered_map with std::vector for styleGroupNewPolygonsVector introduces a more sequential and ordered approach to handling style groups and polygons. This change could potentially improve cache locality and performance during rendering. Ensure that the logic for indexing and accessing these vectors correctly matches the intended grouping and rendering order of polygons.
  • 188-188: The initialization of styleGroupNewPolygonsVector with an empty vector for each new style group is correct. This setup facilitates the addition of polygons to their respective style groups in a structured manner. Verify that the logic for appending polygons to these vectors is implemented correctly in subsequent parts of the code.
  • 211-223: The logic for appending polygon indices and vertices to the last element of styleGroupNewPolygonsVector[styleGroupIndex] is sound. This approach allows for efficient grouping of polygon data by style group. However, ensure that the handling of indexOffset and the calculation of new sizes for vertices and indices are accurate to prevent buffer overflows or rendering artifacts.
  • 241-241: The call to addPolygons with styleGroupNewPolygonsVector as the argument is appropriate and aligns with the changes made to the polygon handling logic. This encapsulation of polygon addition logic enhances modularity and maintainability of the code. Confirm that addPolygons is implemented to correctly process the vector-based input.
  • 264-272: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [248-313]

The addPolygons method's adaptation to accept a vector of vectors (styleGroupNewPolygonsVector) instead of an unordered map is a significant change that aligns with the PR's objectives. This change simplifies the handling of style groups and polygons, potentially improving performance. Ensure that the iteration over styleGroupNewPolygonsVector and the subsequent setup of polygon group objects are correctly implemented to reflect the new data structure.

shared/src/map/layers/tiled/vector/tiles/line/Tiled2dMapVectorLineTile.cpp (3)
  • 288-300: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [232-313]

The transition from using std::unordered_map to std::vector for handling line style groups (styleGroupNewLinesVector) and line subgroups (styleGroupLineSubGroupVector) is consistent with the PR's goal of enhancing the handling of vector layer elements. This change likely improves data access patterns and simplifies the logic for managing line styles and groups. Ensure that the logic for populating these vectors, especially the handling of line subgroups and the transition between them when the maxNumLinePoints limit is reached, is correctly implemented to maintain the integrity of line rendering.

  • 320-320: The call to addLines with styleGroupNewLinesVector as the argument correctly reflects the changes made to line handling logic. This approach, which now uses a vector of vectors, is expected to streamline the processing of line data according to their style groups. Confirm that addLines is implemented to accurately process the vector-based input, ensuring that line data is correctly grouped and rendered according to their styles.
  • 328-328: The adaptation of the addLines method to accept a vector of vectors (styleIdLinesVector) instead of an unordered map represents a significant change that aligns with the PR's objectives. This modification simplifies the handling of line styles and groups, potentially improving performance. Ensure that the iteration over styleIdLinesVector and the subsequent setup of line group objects are correctly implemented to reflect the new data structure.
shared/src/map/layers/tiled/vector/sourcemanagers/Tiled2dMapVectorSourceTileDataManager.cpp (1)
  • 70-73: The addition of the selfMasked boolean variable to the Tiled2dMapVectorLayer::TileRenderDescription constructor call is a critical update for implementing self-masking capabilities for vector layers. This change correctly uses the presence of layerIndex in selfMaskedLayers to determine the selfMasked status, which is a logical approach for enabling self-masking based on layer configurations. Ensure that all relevant documentation and tests are updated to reflect this new parameter's role in rendering logic.
shared/src/map/layers/icon/IconLayer.cpp (1)
  • 342-342: The modification to include an additional boolean argument (false) in the RenderPassConfig constructor call within the buildRenderPasses method aligns with the broader implementation strategy for self-masking capabilities. By explicitly setting this argument to false, it indicates that icon layers do not utilize self-masking by default, which should be consistent with the design intentions. Ensure that this behavior is documented clearly, and consider if any scenarios might require this to be configurable for icon layers in the future.
shared/src/map/layers/tiled/vector/tiles/polygon/Tiled2dMapVectorPolygonPatternTile.cpp (2)
  • 169-169: The transition from std::unordered_map to std::vector for handling style groups and polygons in Tiled2dMapVectorPolygonPatternTile.cpp is a significant change that could enhance performance due to the contiguous memory layout of vectors. This modification should make the management of polygons and their associated styles more efficient, especially if the number of style groups is known and relatively stable. Verify that this change does not introduce any regressions in the ordering or accessibility of polygon data, particularly in scenarios where dynamic modifications to style groups occur.
  • 271-273: In the addPolygons method, the use of a vector to pass polygon descriptions maintains consistency with the earlier change to vector-based management. This approach simplifies the handling of polygon data. However, ensure that the logic for adding, updating, or removing polygons accounts for the vector's indexing, which is inherently different from key-based access in unordered maps. This might require additional checks or updates to ensure that polygon data is correctly associated with their respective style groups without any mismatches.
shared/public/SymbolVectorLayerDescription.h (2)
  • 512-514: The constructor of SymbolVectorLayerDescription now includes a new parameter selfMasked. Ensure that all instantiations of this class throughout the codebase are updated to include this new parameter.
  • 520-520: The clone method of SymbolVectorLayerDescription now correctly clones the selfMasked property. This is a good practice for ensuring that cloned objects maintain the same state as their originals.
shared/src/map/layers/tiled/raster/Tiled2dMapRasterLayer.cpp (3)
  • 419-419: The addition of a boolean argument to the RenderPassConfig constructor within std::make_shared<RenderPass> calls is consistent with the PR's objective to support self-masking for vector layers. However, ensure that the hardcoded false value is intentional and correctly reflects the desired behavior for all instances where a RenderPass is created.
Verification successful

The provided script output does not offer new information or insights into the use of the hardcoded false value for selfMasking in the RenderPassConfig constructor. The output simply echoes the initial concern about needing manual verification to confirm if the hardcoded value aligns with the intended use cases for selfMasking. This indicates that the script executed was not designed to analyze the codebase or check for the usage of RenderPassConfig across different instances. Therefore, to move forward with the verification process, we need to conduct a more detailed analysis of the codebase to understand how RenderPassConfig is used and whether the hardcoded false value is appropriate in all instances.

Given the limitations of the provided script output, I will proceed with generating a new verification strategy to analyze the usage of RenderPassConfig within the codebase. This will involve searching for instances where RenderPassConfig is instantiated to review the context in which the boolean argument is set.


The search results provide several instances where RenderPassConfig is instantiated with a boolean argument for self-masking across different layers and contexts within the codebase. Notably, the hardcoded false value is consistently used in various layers, including tiled vector and raster layers, text, polygon, icon, and line layers. However, there is an exception in the Tiled2dMapVectorLayer.cpp file, where the boolean argument is dynamically set based on description->selfMasked, indicating that self-masking can be enabled or disabled based on specific conditions.

Given this information, it appears that the hardcoded false value for self-masking in the RenderPassConfig constructor is intentional for most use cases, with flexibility provided in certain contexts to enable self-masking based on specific layer or rendering conditions. This approach suggests that the implementation is designed to default to no self-masking for most rendering passes, with the option to enable it where necessary, aligning with the PR's objective to support self-masking for vector layers selectively.

Based on the analysis of the codebase and the usage patterns of RenderPassConfig, the review comment is verified as the hardcoded false value seems to be intentionally used to reflect the desired behavior across the majority of instances where a RenderPass is created, with provisions for enabling self-masking where applicable.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if the hardcoded false value for selfMasking is intentional in all cases.
# Manual verification might be needed to confirm the logic aligns with the intended use cases.
echo "Manual verification needed to confirm the logic aligns with the intended use cases for selfMasking."

Length of output: 208



Script:

#!/bin/bash
# Search for all instances of RenderPassConfig being instantiated to review the context of the boolean argument usage.
rg "RenderPassConfig\(" --context 2

Length of output: 18211

* 426-426: Similar to the previous comment, verify that the hardcoded `false` value for the `selfMasked` parameter in the `RenderPassConfig` constructor is intentional and aligns with the desired behavior for raster layers. * 431-431: Again, ensure that the hardcoded `false` value for the `selfMasked` parameter in the `RenderPassConfig` constructor is intentional and correctly reflects the desired behavior for all instances where a `RenderPass` is created without a specific mask.
shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayerParserHelper.cpp (3)
  • 227-227: The addition of the layerSelfMasked boolean property to represent whether a layer is self-masked aligns with the PR's objectives. However, ensure that this property is correctly parsed from the metadata and utilized in all relevant layer descriptions.
  • 240-242: The parsing of the selfMasked property from the layer's metadata is a crucial step for enabling self-masking capabilities. Ensure that the metadata for each layer correctly specifies this property where applicable.
  • 370-377: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [313-395]

The inclusion of the layerSelfMasked parameter in the construction of layer descriptions is consistent with the PR's objective to support self-masking for vector layers. Ensure that all layer descriptions correctly utilize this parameter based on the layer's metadata.

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1)
  • 721-727: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [724-736]

The introduction of the selfMasked boolean variable and its usage in the Tiled2dMapVectorLayer::TileRenderDescription constructor call is correctly implemented. The logic to determine selfMasked based on the presence of the index in selfMaskedLayers is sound. However, ensure that the selfMaskedLayers set is properly maintained elsewhere in the code to accurately reflect layers that should be self-masked.

shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (1)
  • 632-632: Creating a RenderPass with RenderPassConfig(description->renderPassIndex, description->selfMasked) correctly respects the selfMasked property. However, this is done within a condition that might not always be reached due to the logic in lines 626-628. Ensure that all scenarios where a layer's self-masking property should affect rendering are correctly handled.

@@ -618,26 +618,26 @@ void Tiled2dMapVectorLayer::pregenerateRenderPasses() {
continue;
}
if (description->maskingObject != lastMask && !renderObjects.empty()) {
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex), renderObjects, lastMask));
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, false), renderObjects, lastMask));
Copy link
Contributor

Choose a reason for hiding this comment

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

The creation of a RenderPass object with RenderPassConfig(description->renderPassIndex, false) seems to ignore the selfMasked property of the description object. This could potentially lead to incorrect rendering behavior where self-masking properties of layers are not respected.

- newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, false), renderObjects, lastMask));
+ newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, description->selfMasked), renderObjects, lastMask));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, false), renderObjects, lastMask));
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, description->selfMasked), renderObjects, lastMask));

Comment on lines +626 to +628
if (description->isModifyingMask || description->selfMasked) {
if (!renderObjects.empty()) {
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex), renderObjects, lastMask));
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(description->renderPassIndex, false), renderObjects, lastMask));
Copy link
Contributor

Choose a reason for hiding this comment

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

The creation of a RenderPass object with RenderPassConfig(description->renderPassIndex, false) immediately before potentially creating another RenderPass with description->selfMasked seems redundant and could lead to unnecessary render passes being created. Consider optimizing this logic to avoid creating an unnecessary render pass when description->isModifyingMask or description->selfMasked is true.

Consider restructuring this logic to only create a new RenderPass when necessary, potentially by checking the conditions first and then deciding on the RenderPassConfig parameters.

} else {
renderObjects.insert(renderObjects.end(), description->renderObjects.begin(), description->renderObjects.end());
lastMask = description->maskingObject;
lastRenderPassIndex = description->renderPassIndex;
}
}
if (!renderObjects.empty()) {
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(lastRenderPassIndex), renderObjects, lastMask));
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(lastRenderPassIndex, false), renderObjects, lastMask));
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the comment on line 621, this creation of a RenderPass object ignores the selfMasked property for the last batch of render objects. This could lead to incorrect handling of self-masking properties in certain scenarios.

- newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(lastRenderPassIndex, false), renderObjects, lastMask));
+ // Ensure to correctly handle the selfMasked property for the last batch of render objects.
+ // This might require tracking the selfMasked property of the last description or adjusting the logic to ensure it's correctly applied.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
newPasses.emplace_back(std::make_shared<RenderPass>(RenderPassConfig(lastRenderPassIndex, false), renderObjects, lastMask));
// Ensure to correctly handle the selfMasked property for the last batch of render objects.
// This might require tracking the selfMasked property of the last description or adjusting the logic to ensure it's correctly applied.

@@ -5,4 +5,5 @@ package io.openmobilemaps.mapscore.shared.graphics

data class RenderPassConfig(
val renderPassIndex: Int,
val isPassMasked: Boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing default value for isPassMasked.

-    val isPassMasked: Boolean,
+    val isPassMasked: Boolean = false,

@@ -8,9 +8,11 @@

struct RenderPassConfig final {
int32_t renderPassIndex;
bool isPassMasked;
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of std::move for primitive types like int32_t and bool is unnecessary and does not have any effect.

-    : renderPassIndex(std::move(renderPassIndex_))
-    , isPassMasked(std::move(isPassMasked_))
+    : renderPassIndex(renderPassIndex_)
+    , isPassMasked(isPassMasked_)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
bool isPassMasked;
bool isPassMasked;

Comment on lines +101 to +115
GLuint stencilMask = 0;
GLuint validTarget = 0;
GLenum zpass = GL_KEEP;
if (isMasked) {
glStencilFunc(GL_EQUAL, isMaskInversed ? 0 : 128, 128);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
stencilMask += 128;
validTarget = isMaskInversed ? 0 : 128;
}
if (renderPass.isPassMasked) {
stencilMask += 127;
zpass = GL_INCR;
}

if (stencilMask != 0) {
glStencilFunc(GL_EQUAL, validTarget, stencilMask);
glStencilOp(GL_KEEP, GL_KEEP, zpass);
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of stencil operations in the render method introduces a more flexible handling of masking conditions. However, consider the following points for improvement:

  • Ensure that the initial values of stencilMask and validTarget are appropriately chosen for all possible states of isMasked and renderPass.isPassMasked.
  • The increment of stencilMask by 127 when renderPass.isPassMasked is true might lead to unexpected behavior if both isMasked and renderPass.isPassMasked are true, as the total value could exceed the maximum value representable in the stencil buffer. Verify that this logic aligns with the intended stencil operations.
  • The use of GL_INCR for zpass when renderPass.isPassMasked is true assumes that the stencil buffer is being used in a way that supports incremental updates. Ensure this matches the overall rendering strategy and that there's no risk of overflow in the stencil values which could lead to visual artifacts.

Consider adding comments to explain the rationale behind the chosen stencil operation values, especially the significance of 128 and 127, to improve maintainability and readability for future developers.

Comment on lines +107 to +121
GLuint stencilMask = 0;
GLuint validTarget = 0;
GLenum zpass = GL_KEEP;
if (isMasked) {
if (isMaskInversed) {
glStencilFunc(GL_EQUAL, 0, 255);
} else {
glStencilFunc(GL_EQUAL, 128, 255);
}
stencilMask += 128;
validTarget = isMaskInversed ? 0 : 128;
}
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
if (renderPass.isPassMasked) {
stencilMask += 127;
zpass = GL_INCR;
}

if (stencilMask != 0) {
glStencilFunc(GL_EQUAL, validTarget, stencilMask);
glStencilOp(GL_KEEP, GL_KEEP, zpass);
Copy link
Contributor

Choose a reason for hiding this comment

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

The modifications to the render method for handling stencil operations based on masking conditions are well-intended for enhancing rendering flexibility. However, consider the following:

  • The logic for calculating stencilMask and validTarget should be thoroughly tested to ensure it behaves as expected under all combinations of isMasked and renderPass.isPassMasked.
  • The choice of 128 and 127 for modifying stencilMask values appears arbitrary without context. Ensure these values are documented to explain their significance and how they contribute to the intended stencil operations.
  • Using GL_INCR for zpass assumes a specific usage pattern of the stencil buffer. Confirm that this approach is compatible with the overall rendering strategy and does not risk stencil buffer overflow, which could lead to rendering issues.

Adding detailed comments to explain the logic behind the chosen values and operations would greatly aid in the maintainability of this code. Additionally, consider edge cases where the combined stencil operations might not produce the expected results and adjust or document as necessary.

Comment on lines +137 to +145
bool multiselect,
bool selfMasked):
VectorLayerDescription(identifier, source, sourceId, minZoom, maxZoom, filter, renderPassIndex, interactable, multiselect, selfMasked),
style(style) {};

std::unique_ptr<VectorLayerDescription> clone() override {
return std::make_unique<LineVectorLayerDescription>(identifier, source, sourceLayer, minZoom, maxZoom,
filter ? filter->clone() : nullptr, style, renderPassIndex,
interactable ? interactable->clone() : nullptr, multiselect);
interactable ? interactable->clone() : nullptr, multiselect, selfMasked);
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of the selfMasked boolean parameter to the LineVectorLayerDescription constructor and its inclusion in the clone method is a significant enhancement, allowing for more detailed control over layer rendering properties. Ensure that:

  • The selfMasked parameter is correctly documented in the class header to explain its purpose and how it affects rendering behavior.
  • All usages of LineVectorLayerDescription throughout the codebase have been updated to account for the new parameter, ensuring that existing functionality is not inadvertently affected.

Consider implementing default values for the selfMasked parameter in scenarios where backward compatibility with existing code might be necessary. Additionally, unit tests should be updated or added to cover the new functionality introduced by this parameter.

@@ -144,7 +144,7 @@ class RasterVectorLayerDescription: public VectorLayerDescription {
bool underzoom,
bool overzoom,
std::optional<::RectCoord> bounds):
VectorLayerDescription(identifier, source, "", minZoom, maxZoom, nullptr, renderPassIndex, interactable, false),
VectorLayerDescription(identifier, source, "", minZoom, maxZoom, nullptr, renderPassIndex, interactable, false, false),
Copy link
Contributor

Choose a reason for hiding this comment

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

The introduction of an additional boolean parameter in the RasterVectorLayerDescription constructor to initialize VectorLayerDescription with false, false for the last two arguments is a notable change. Ensure that:

  • The purpose of these boolean parameters, especially the newly added one, is clearly documented in both the RasterVectorLayerDescription and VectorLayerDescription class headers. This will help developers understand their impact on layer behavior.
  • All instantiations of RasterVectorLayerDescription throughout the codebase have been reviewed to ensure that the correct values are being passed, maintaining the intended functionality.

Adding explicit documentation for the new parameter and its expected behavior would enhance code readability and maintainability. Consider reviewing related classes or methods that might be affected by this change to ensure consistency across the codebase.

Comment on lines +196 to +210
GLuint stencilMask = 0;
GLuint validTarget = 0;
GLenum zpass = GL_KEEP;
if (isMasked) {
glStencilFunc(GL_EQUAL, isMaskInversed ? 0 : 128, 128);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
stencilMask += 128;
validTarget = isMaskInversed ? 0 : 128;
}
if (renderPass.isPassMasked) {
stencilMask += 127;
zpass = GL_INCR;
}

if (stencilMask != 0) {
glStencilFunc(GL_EQUAL, validTarget, stencilMask);
glStencilOp(GL_KEEP, GL_KEEP, zpass);
Copy link
Contributor

Choose a reason for hiding this comment

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

The modifications to the render method in Quad2dOpenGl for handling stencil operations based on masking conditions are well-implemented. However, ensure that:

  • The logic for calculating stencilMask, validTarget, and zpass is thoroughly tested, especially considering the potential for both isMasked and renderPass.isPassMasked to be true simultaneously.
  • The values 128 and 127 used for stencilMask adjustments are clearly documented, explaining their significance and ensuring that they do not inadvertently exceed the stencil buffer's capacity.
  • The choice of GL_INCR for zpass is consistent with the overall rendering strategy and does not lead to stencil buffer overflow, which could cause rendering artifacts.

Adding comments to explain the rationale behind the chosen stencil operation values and ensuring that the implementation is robust against all possible combinations of masking conditions would improve code clarity and maintainability.

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

Successfully merging this pull request may close these issues.

2 participants