-
-
Notifications
You must be signed in to change notification settings - Fork 715
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
Refactor usage of implicit parameter to an explicit one when rendering #5020
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5020 +/- ##
==========================================
- Coverage 89.25% 88.43% -0.82%
==========================================
Files 269 269
Lines 38286 38310 +24
Branches 2347 2478 +131
==========================================
- Hits 34172 33880 -292
- Misses 3117 3393 +276
- Partials 997 1037 +40 ☔ View full report in Codecov by Sentry. |
Thanks for cleaning up - I think this is a good path. To make it even more explicit what happens, can we maybe flip the bools, so that they're So effectively this: this.getProjectionData({
ignoreGlobeMatrix: true,
//ignoreTerrainMatrix: false hidden default value
}); Becomes this: this.getProjectionData({
//applyGlobeMatrix: false, hidden default value
applyTerrainMatrix: true
}); So it says what it does, not what it doesn't. |
I think this is great! Since we are in the middle of a breaking change version release, now would be a great time to move objects around and clean some historical bad decisions... |
863168e
to
0abf8a6
Compare
I've updated this PR with some of your suggestions:
I'll tackle removing |
src/render/painter.ts
Outdated
@@ -62,6 +72,11 @@ type PainterOptions = { | |||
fadeDuration: number; | |||
}; | |||
|
|||
export type RenderFlags = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Options" is used in the code. I would consider renaming this to "RenderOptions".
src/render/painter.ts
Outdated
switch (layer.type) { | ||
case 'symbol': | ||
drawSymbols(painter, sourceCache, layer as any, coords, this.style.placement.variableOffsets); | ||
switch (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this odd TBH, maybe a if ...else if... Will be better here? It might be just that I'm not used to it... IDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, to be fair it was a little bit weird. Changed it to an if...else
block and it feels better.
src/render/draw_background.ts
Outdated
import type {SourceCache} from '../source/source_cache'; | ||
import type {BackgroundStyleLayer} from '../style/style_layer/background_style_layer'; | ||
import {OverscaledTileID} from '../source/tile_id'; | ||
import {coveringTiles} from '../geo/projection/covering_tiles'; | ||
|
||
export function drawBackground(painter: Painter, sourceCache: SourceCache, layer: BackgroundStyleLayer, coords: Array<OverscaledTileID>, renderFlags: RenderFlags) { | ||
export function drawBackground(painter: Painter, sourceCache: SourceCache, layer: BackgroundStyleLayer, coords: Array<OverscaledTileID>, renderFlags: RenderOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to change the parameter name as well - renderOptions...
LGTM, thanks! |
@@ -47,7 +47,7 @@ export function drawBackground(painter: Painter, sourceCache: SourceCache, layer | |||
for (const tileID of tileIDs) { | |||
const projectionData = transform.getProjectionData({ | |||
overscaledTileID: tileID, | |||
ignoreGlobeMatrix: globeWithTerrain | |||
applyGlobeMatrix: !isRenderingToTexture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is an applyTerrainMatrix: true
missing here.
@@ -80,7 +81,7 @@ export function drawCircles(painter: Painter, sourceCache: SourceCache, layer: C | |||
const terrainData = painter.style.map.terrain && painter.style.map.terrain.getTerrainData(coord); | |||
const uniformValues = circleUniformValues(painter, tile, layer, translateForUniforms, radiusCorrectionFactor); | |||
|
|||
const projectionData = transform.getProjectionData({overscaledTileID: coord}); | |||
const projectionData = transform.getProjectionData({overscaledTileID: coord, applyGlobeMatrix: !isRenderingToTexture}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an applyTerrainMatrix missing here too?
const projectionData = transform.getProjectionData({ | ||
overscaledTileID: coord, | ||
ignoreGlobeMatrix: globeWithTerrain | ||
applyGlobeMatrix: !isRenderingToTexture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also, I'd expect applyTerrainMatrix: true
const projectionData = transform.getProjectionData({ | ||
overscaledTileID: coord, | ||
aligned: align, | ||
ignoreGlobeMatrix: globeWithTerrain | ||
applyGlobeMatrix: !isRenderingToTexture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too, I expected an additional applyTerrainMatrix: true
This PR aims to refactor our codebase a little bit in order to move away of what, IMHO, are code smells.
First, some context.
The Painter object mostly contains properties that describe how things are going to be rendered via the underlying rendering API (i.e. vertex and index buffers, stencil buffer definitions, depth range, etc.) but it also contains the
Style
object which in itself describes how things should look like.draw_*
functions (i.e. draw_background) get both thePainter
object andStyleLayer
object, which is basically the subset of theStyle
that we need to render a given layer.There are various places in the
draw_*
functions where we usepainter.style
to get information about the current rendering mode:painter.style.map.terrain
to know if we are rendering with terrainpainter.style.projection.name
to know if we are rendering usingglobe
ormercator
projectionsand change the drawing behaviour according to that. Since those properties are deep into the
Painter
object, you might get two similar-lookingdraw_*
calls with very different results.This PR replaces checks for terrain rendering via the
painter.style
property with an extrarenderLayer
parameter that tells a givendraw_*
function if it's being rendered to a texture.A follow-up idea would be to remove
style
entirely from thePainter
object and add all the properties that are needed for the variousdraw_*
functions into thePainter
object itself.Cc @birkskyum since we talked about this.
Launch Checklist
CHANGELOG.md
under the## main
section.