Skip to content

Commit

Permalink
Merge pull request #8 from HudHud-Maps/fix_depth_buffer
Browse files Browse the repository at this point in the history
fix depth buffer
  • Loading branch information
yousifd authored Jan 23, 2025
2 parents adb017b + 6b5525e commit 350f210
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 318 deletions.
6 changes: 5 additions & 1 deletion .github/actions/get-pr-number/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: 'get-pr-number'
description: 'Gets the PR number from an artifact'
inputs:
platform-name:
description: "Name of the target platform"
required: true
outputs:
pr-number:
description: "PR number or empty string"
Expand All @@ -9,7 +13,7 @@ runs:
steps:
- uses: ./.github/actions/download-workflow-run-artifact
with:
artifact-name: pr-number
artifact-name: pr-number-${{ inputs.platform-name }}

- run: touch ./pr_number
shell: bash
Expand Down
6 changes: 5 additions & 1 deletion .github/actions/save-pr-number/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: 'save-pr-number'
description: 'Saves the current PR number as artifact'
inputs:
platform-name:
description: "Name of the target platform"
required: true
runs:
using: "composite"
steps:
Expand All @@ -12,5 +16,5 @@ runs:
- name: Upload pr_number
uses: actions/upload-artifact@v4
with:
name: pr-number
name: pr-number-${{ inputs.platform-name }}
path: ./pr_number
2 changes: 2 additions & 0 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ jobs:
- if: github.event_name == 'pull_request'
uses: ./.github/actions/save-pr-number
with:
platform-name: "android"

- name: Build Instrumentation Tests, copy to platform/android
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/android-device-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:

- uses: ./.github/actions/get-pr-number
id: get-pr-number
with:
platform-name: "android"

- name: Generate token
id: generate_token
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ jobs:

- if: github.event_name == 'pull_request'
uses: ./.github/actions/save-pr-number
with:
platform-name: "ios"

- name: Build DocC documentation
working-directory: .
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ jobs:

- if: github.event_name == 'pull_request'
uses: ./.github/actions/save-pr-number
with:
platform-name: "linux-${{ matrix.renderer }}"

linux-coverage:
runs-on: ubuntu-22.04
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-bloaty-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
- uses: ./.github/actions/get-pr-number
id: get-pr-number
with:
platform-name: "ios"

- uses: ./.github/actions/download-workflow-run-artifact
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr-linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- uses: ./.github/actions/get-pr-number
id: get-pr-number
with:
platform-name: "linux-vulkan"

- uses: ./.github/actions/download-workflow-run-artifact
with:
Expand Down Expand Up @@ -134,6 +136,8 @@ jobs:

- uses: ./.github/actions/get-pr-number
id: get-pr-number
with:
platform-name: "linux-vulkan"

- uses: ./.github/actions/download-workflow-run-artifact
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct CustomLayerRenderParameters {
double pitch;
double fieldOfView;
std::array<double, 16> projectionMatrix;
std::array<double, 16> nearClippedProjMatrix;

CustomLayerRenderParameters(const PaintParameters&);
};
Expand Down
1 change: 1 addition & 0 deletions platform/darwin/src/MLNCustomStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct MLNStyleLayerDrawingContext {
CGFloat pitch;
CGFloat fieldOfView;
MLNMatrix4 projectionMatrix;
MLNMatrix4 nearClippedProjMatrix;
} MLNStyleLayerDrawingContext;

MLN_EXPORT
Expand Down
3 changes: 2 additions & 1 deletion platform/darwin/src/MLNCustomStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ void render(const mbgl::style::CustomLayerRenderParameters& parameters) {
.direction = mbgl::util::wrap(parameters.bearing, 0., 360.),
.pitch = static_cast<CGFloat>(parameters.pitch),
.fieldOfView = static_cast<CGFloat>(parameters.fieldOfView),
.projectionMatrix = MLNMatrix4Make(parameters.projectionMatrix)
.projectionMatrix = MLNMatrix4Make(parameters.projectionMatrix),
.nearClippedProjMatrix = MLNMatrix4Make(parameters.nearClippedProjMatrix)
};
if (layer.mapView) {
[layer drawInMapView:layer.mapView withContext:drawingContext];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace maplibre { namespace gltf {
// TBD: These are placeholders as we noodle how to integrate with ML
// Depth descriptor: If this is null, then use an internal depth
id<MTLTexture> _depthStencilTexture = nullptr;

id<MTLTexture> _colorTexture = nullptr;
};

}}
Expand Down
17 changes: 8 additions & 9 deletions platform/darwin/src/gltf/GLTFModelLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -300,38 +300,38 @@ - (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingCon
_manager->setProjectionCallback(^Cartesian3D(const Coordinate2D & coordinate){
Cartesian3D tempResult;

tempResult._x = 0;
tempResult._y = 0;
tempResult._x = 5198170.102753558;
tempResult._y = 2832006.4886368043;
tempResult._z = 0;

tempResult._x = coordinate._lon * DEG_RAD;
double lat = coordinate._lat * DEG_RAD;
// if (lat < -PoleLimit) lat = -PoleLimit;
// if (lat > PoleLimit) lat = PoleLimit;
tempResult._y = log((1.0f+sin(lat))/cos(lat));

double metersScale = 20037508.34;
tempResult._x = tempResult._x * metersScale / M_PI;
tempResult._y = tempResult._y * metersScale / M_PI;
return tempResult;

});

loadModels = true;
}

_metalEnvironment->_currentFOVDEG = context.fieldOfView * RAD_DEG;
_metalEnvironment->_currentProjectionMatrix = toSimdMatrix4D(context.projectionMatrix);
_metalEnvironment->_currentProjectionMatrix = toSimdMatrix4D(context.nearClippedProjMatrix);
_metalEnvironment->_currentZoomLevel = context.zoomLevel;
_metalEnvironment->_currentCommandEncoder = self.renderEncoder;
_metalEnvironment->_currentCommandBuffer = resource.commandBuffer;
_metalEnvironment->_metalDevice = resource.mtkView.device;
_metalEnvironment->_currentDrawable = resource.mtkView.currentDrawable;
_metalEnvironment->_currentRenderPassDescriptor = resource.mtkView.currentRenderPassDescriptor;
_metalEnvironment->_depthStencilTexture = resource.mtkView.currentRenderPassDescriptor.depthAttachment.texture;
_metalEnvironment->_colorTexture = resource.mtkView.currentRenderPassDescriptor.colorAttachments[0].texture;

if (self.lightSet) {
_metalEnvironment->_lightDirection = simd_make_float3(_lightX, _lightY, _lightZ);
}

// TODO: Remove this.. This is legacy
_manager->setRenderingEnvironmentVariables(_metalEnvironment);

Expand All @@ -354,7 +354,6 @@ - (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingCon

// Render the image
_manager->render();

}

- (void)willMoveFromMapView:(MLNMapView *)mapView {
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/gltf/GLTFRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void GLTFRenderer::update(float timeSinceLastDraw) {
}

// Render
void GLTFRenderer::render() {
void GLTFRenderer::render() {
// Base class does nothing
}

Expand Down
Loading

0 comments on commit 350f210

Please sign in to comment.