library: generalise the Moon globe to every planetary body
- Commit
be2cfba535313a6499a5601e34ef123610458b5c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 23:50 UTC (1 day ago)
- Parents
957fd7d
MapBody now lists Earth, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune and Moon. The Moon raster path becomes the body raster path: MoonTextures gains DEM packing (offset/unit), relief strength and an optional radial ring strip; MapNative gains setBodyTextures beside setMoonTextures; the Rust renderer stores BodyParams (host-testable in body_params.rs, moved out of the Android-only vulkan tree so cargo test covers it), uploads a third ring image (1x1 transparent dummy for ringless bodies) and record_moon pushes the packing/ring parameters to moon.frag. moon.frag now decodes any body's DEM packing, skips relief for DEM-less bodies, and projects equatorial rings orthographically: the annulus outside the disc, with the front arc blended over the disc where the ring point is nearer than the sphere surface. The quad widens to the ring outer radius for ringed bodies (moon.vert reads the extent from push morph.y). Verified: cargo test -p map_renderer --lib (585 tests), :library:map:lint, :library:map:testDebugUnitTest.
Diff
library/map/AGENTS.md
diff --git a/library/map/AGENTS.md b/library/map/AGENTS.mdindex bd0d34bc66..59f1dea71d 100644--- a/library/map/AGENTS.md+++ b/library/map/AGENTS.md@@ -43,6 +43,7 @@ - com/vayunmathur/library/map/Mercator.kt - com/vayunmathur/library/map/Projection.kt - com/vayunmathur/library/map/FrameStatsOverlay.kt+- Raster body globes (maps-only): `MapBody` in MapOptions.kt, `MoonTextures` holder in SurfaceMapFrame.kt, JNI `setBodyTextures`/`setMoonTextures` in MapNative.kt, Rust `bridge/moon.rs` + `vulkan/renderer/record_moon.rs`/`upload_moon.rs` (`BodyParams`: DEM packing, relief, ring radii/opacity) + `shaders/moon.frag` (disc + equatorial ring projection) ## Verify (this module only) ```
library/map/src/androidTest/java/com/vayunmathur/library/map/MapRendererInstrumentedTest.kt
diff --git a/library/map/src/androidTest/java/com/vayunmathur/library/map/MapRendererInstrumentedTest.kt b/library/map/src/androidTest/java/com/vayunmathur/library/map/MapRendererInstrumentedTest.ktindex ac260f074d..9a52b96117 100644--- a/library/map/src/androidTest/java/com/vayunmathur/library/map/MapRendererInstrumentedTest.kt+++ b/library/map/src/androidTest/java/com/vayunmathur/library/map/MapRendererInstrumentedTest.kt@@ -69,7 +69,7 @@ class MapRendererInstrumentedTest { renderer.setRegionMask(null) renderer.setTrafficSpeeds(longArrayOf(1L), intArrayOf(-65536)) renderer.clearTraffic()- renderer.setMoonTextures(ByteArray(4), 1, 1, ByteArray(2), 1, 1)+ renderer.setMoonTextures(MoonTextures(ByteArray(4), 1, 1, ByteArray(2), 1, 1)) renderer.clearMoonTextures() renderer.renderFrame() renderer.invalidate()
library/map/src/main/java/com/vayunmathur/library/map/MapNative.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/MapNative.kt b/library/map/src/main/java/com/vayunmathur/library/map/MapNative.ktindex ebd9eea1c5..96dd0caab7 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/MapNative.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/MapNative.kt@@ -128,6 +128,31 @@ internal object MapNative { demHeight: Int, ) + /**+ * Upload a non-Earth body's raster set, generalising [setMoonTextures]:+ * the DEM packing (`demOffset`/`demUnitMetres`), the relief strength, and+ * an optional ring strip ([ringRgba] is `ringWidth x 1` RGBA8, empty when+ * the body has no rings; radii in planetary radii). Called once after+ * attach (and again after any re-attach); bytes are copied to the GPU.+ */+ external fun setBodyTextures(+ handle: Long,+ colorRgba: ByteArray,+ width: Int,+ height: Int,+ demRg: ByteArray,+ demWidth: Int,+ demHeight: Int,+ demOffset: Float,+ demUnitMetres: Float,+ relief: Float,+ ringRgba: ByteArray,+ ringWidth: Int,+ ringInner: Float,+ ringOuter: Float,+ ringOpacity: Float,+ )+ /** Drop the Moon raster pair from the GPU; a Moon frame draws the clear colour until the next push. */ external fun clearMoonTextures(handle: Long)
library/map/src/main/java/com/vayunmathur/library/map/MapOptions.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/MapOptions.kt b/library/map/src/main/java/com/vayunmathur/library/map/MapOptions.ktindex 5965d0983e..a1b957f475 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/MapOptions.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/MapOptions.kt@@ -83,14 +83,21 @@ data class MapOptions( /** * Which planetary body the map draws. *- * Earth is the vector basemap this library has always drawn. Moon is the NASA- * SVS CGI Moon Kit raster pair (LROC color + LOLA elevation) bent onto the same- * globe path — maps-only, session-scoped, and only meaningful while the globe- * is active (zoomed out). Every other host keeps the default without knowing- * this exists.+ * Earth is the vector basemap this library has always drawn. Every other body+ * is a bundled raster set (colour mosaic, plus a packed DEM for the rocky+ * bodies) bent onto the same globe path — maps-only, session-scoped, and only+ * meaningful while the globe is active (zoomed out). Every other host keeps+ * the default without knowing this exists. */ enum class MapBody { Earth,+ Mercury,+ Venus,+ Mars,+ Jupiter,+ Saturn,+ Uranus,+ Neptune, Moon, }
library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapFrame.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapFrame.kt b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapFrame.ktindex 4a4914f6d8..767ac978e9 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapFrame.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapFrame.kt@@ -92,10 +92,15 @@ internal fun drawFrame( } /**- * The Moon raster pair the host pushes for the lunar globe: converted LROC- * color (RGBA8) + converted LDEM (RG8 packed uint16). Plain holder so the- * renderer can remember and replay it across re-attach like every other- * deferred state.+ * The raster set the host pushes for a non-Earth globe: equirectangular colour+ * (RGBA8), an RG8 packed-uint16 DEM for the rocky bodies (a 1x1 dummy when the+ * body has none), and an optional radial ring strip (RGBA8, `ringWidth x 1`)+ * for the ringed giants. Plain holder so the renderer can remember and replay+ * it across re-attach like every other deferred state.+ *+ * DEM packing: `packed = metres / demUnitMetres + demOffset`, decoded in the+ * shader as `(packed - demOffset) * demUnitMetres`. The Moon's historical+ * packing (half-metres + 20000) is the default. */ data class MoonTextures( val colorRgba: ByteArray,@@ -104,13 +109,30 @@ data class MoonTextures( val demRg: ByteArray, val demWidth: Int, val demHeight: Int,+ val demOffset: Float = 20_000f,+ val demUnitMetres: Float = 0.5f,+ /** Normal-nudge per metre of DEM gradient; 0 for DEM-less bodies. */+ val relief: Float = 0.02f,+ val ringRgba: ByteArray? = null,+ val ringWidth: Int = 0,+ /** Ring inner/outer radii in planetary radii; outer 0 means no rings. */+ val ringInner: Float = 0f,+ val ringOuter: Float = 0f,+ val ringOpacity: Float = 0f, ) {+ val hasDem: Boolean get() = demWidth > 1 && demHeight > 1+ override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is MoonTextures) return false return width == other.width && height == other.height && demWidth == other.demWidth && demHeight == other.demHeight &&- colorRgba.contentEquals(other.colorRgba) && demRg.contentEquals(other.demRg)+ demOffset == other.demOffset && demUnitMetres == other.demUnitMetres &&+ relief == other.relief && ringWidth == other.ringWidth &&+ ringInner == other.ringInner && ringOuter == other.ringOuter &&+ ringOpacity == other.ringOpacity &&+ colorRgba.contentEquals(other.colorRgba) && demRg.contentEquals(other.demRg) &&+ (ringRgba?.contentEquals(other.ringRgba ?: ByteArray(0)) ?: (other.ringRgba == null)) } override fun hashCode(): Int {@@ -120,6 +142,7 @@ data class MoonTextures( result = 31 * result + demHeight result = 31 * result + colorRgba.contentHashCode() result = 31 * result + demRg.contentHashCode()+ result = 31 * result + (ringRgba?.contentHashCode() ?: 0) return result } }
library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.ktindex 74bd94ddef..0fce7f7655 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/SurfaceMapRenderer.kt@@ -276,7 +276,7 @@ class SurfaceMapRenderer( */ var globeEnabled: Boolean = false - /** Which body the globe draws: Earth (default) or the maps-pushed Moon raster pair. */+ /** Which body the globe draws: Earth (default) or a maps-pushed raster body. */ var body: MapBody = MapBody.Earth /**@@ -285,15 +285,8 @@ class SurfaceMapRenderer( * RGBA8, [demRg] is `demWidth x demHeight` RG8 packed uint16. The ~36 MB upload runs on * the render thread. */- fun setMoonTextures(- colorRgba: ByteArray,- width: Int,- height: Int,- demRg: ByteArray,- demWidth: Int,- demHeight: Int,- ) {- moonTextures = MoonTextures(colorRgba, width, height, demRg, demWidth, demHeight)+ fun setMoonTextures(textures: MoonTextures) {+ moonTextures = textures applyMoonTextures() invalidate() }@@ -545,7 +538,7 @@ class SurfaceMapRenderer( widthDp = viewport.width, heightDp = viewport.height, globe = globe,- moon = globe && state.body == MapBody.Moon,+ moon = globe && state.body != MapBody.Earth, ) } if (widthPx <= 0 || heightPx <= 0 || density <= 0f) return null@@ -555,7 +548,7 @@ class SurfaceMapRenderer( widthDp = widthPx / density, heightDp = heightPx / density, globe = globe,- moon = globe && body == MapBody.Moon,+ moon = globe && body != MapBody.Earth, ) } @@ -817,10 +810,13 @@ class SurfaceMapRenderer( private fun applyMoonTextures() { val moon = moonTextures ?: return onRenderThread { h ->- MapNative.setMoonTextures(+ MapNative.setBodyTextures( h, moon.colorRgba, moon.width, moon.height, moon.demRg, moon.demWidth, moon.demHeight,+ moon.demOffset, moon.demUnitMetres, moon.relief,+ moon.ringRgba ?: ByteArray(0), moon.ringWidth,+ moon.ringInner, moon.ringOuter, moon.ringOpacity, ) } }
library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt b/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.ktindex 112f3f9b9c..7190dc9f10 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/VulkanMapSurface.kt@@ -286,14 +286,7 @@ internal fun VulkanMapSurface( if (moon == null) { renderer.clearMoonTextures() } else {- renderer.setMoonTextures(- moon.colorRgba,- moon.width,- moon.height,- moon.demRg,- moon.demWidth,- moon.demHeight- )+ renderer.setMoonTextures(moon) } }
library/map/src/main/rust/shaders/moon.frag
diff --git a/library/map/src/main/rust/shaders/moon.frag b/library/map/src/main/rust/shaders/moon.fragindex 075896a324..d77786bebb 100644--- a/library/map/src/main/rust/shaders/moon.frag+++ b/library/map/src/main/rust/shaders/moon.frag@@ -1,20 +1,33 @@ #version 450 -// Moon fragment: LROC color textured by selenographic lon/lat, shaded by the-// LDEM-derived normal with a fixed sun direction.+// Body fragment: equirectangular colour textured by planetographic lon/lat,+// shaded by the DEM-derived normal with a fixed sun direction, plus an+// optional equatorial ring strip for the ringed giants. //-// `inDisc` is -1..1 across the disc's bounding square (y down, Vulkan clip).-// Outside the unit circle is discarded; inside, the orthographic hemisphere z-// and the sphere normal are recovered per fragment, and the lon/lat inverts-// through the same east/north/up basis the globe math uses-// (`globe_point`/`globe_lonlat`). The color texture is equirectangular-// -180..180/-90..90. The DEM (same layout, RG-packed uint16 half-metres +-// 20000) perturbs the normal for relief shading.+// `inDisc` is -1..1 across the disc's bounding square (y down, Vulkan clip),+// scaled by the ring extent for ringed bodies. Inside the unit circle the+// orthographic hemisphere z and the sphere normal are recovered per fragment+// in the view frame, the camera view rotation (bearing/pitch) is undone, and+// the lon/lat then inverts through the same east/north/up basis the globe+// math uses (`globe_point`/`globe_lonlat`). The colour texture is+// equirectangular -180..180/-90..90. The DEM (same layout, RG-packed uint16,+// packing pushed per body) perturbs the normal for relief shading. DEM-less+// bodies push a 1x1 DEM with unit 0 and skip relief. //-// Lighting is a single fixed sun from the east-equatorial direction: enough to-// read relief, deliberately not a day/night terminator (no sun-position input-// exists on this path yet). Limb darkening fakes the spherical falloff the-// flat texture lacks.+// Rings live in the body's equatorial plane. The ring point at a screen+// pixel is solved in the centre-facing frame: undo the view rotation, then+// require the point to lie in the equatorial plane (its centre-facing+// coordinates dotted with the body pole are zero), which fixes its view+// depth. Its centre-facing length is the equatorial radius. Outside the+// disc the ring draws on its own; inside, a ring point nearer (in view+// depth) than the sphere surface blends over the planet (the front arc),+// and a farther one is hidden by the planet. Rings therefore roll and tip+// with the disc under bearing/pitch instead of staying screen-aligned.+//+// Lighting is a single fixed sun from the east-equatorial direction: enough+// to read relief, deliberately not a day/night terminator (no sun-position+// input exists on this path yet). Limb darkening fakes the spherical falloff+// the flat texture lacks. layout(location = 0) in vec2 inDisc; layout(location = 0) out vec4 outColor;@@ -23,16 +36,33 @@ layout(push_constant) uniform Push { mat4 tileToClip; // xy: camera centre lon/lat (degrees) — the visible-hemisphere centre. vec4 color;+ // x: DEM packing offset, y: DEM metres per packed unit (0 = no DEM),+ // z: ring inner radius, w: ring outer radius (planetary radii). vec4 line;- // z: DEM relief strength (normal nudge per metre).+ // xy: camera bearing/pitch (degrees) for the view rotation,+ // z: DEM relief strength (normal nudge per metre), w: time (seconds). vec4 misc;+ // x: ring opacity (0 = no rings), y: quad extent in radii (vertex only). vec4 morph; } push; layout(set = 0, binding = 0) uniform sampler2D moonColor; layout(set = 0, binding = 1) uniform sampler2D moonDem;+layout(set = 0, binding = 2) uniform sampler2D bodyRing; const float PI = 3.141592653589793; +// Undo the camera view rotation (mirrors `globe_view_unrotate`): undo the+// pitch tip about the screen-east axis, then undo the bearing roll about+// the view axis. Both zero is the identity.+vec3 viewUnrotate(vec3 v) {+ float vb = radians(push.misc.x);+ float vp = radians(push.misc.y);+ if (vb == 0.0 && vp == 0.0) return v;+ float y1 = cos(vp) * v.y + sin(vp) * v.z;+ float z1 = -sin(vp) * v.y + cos(vp) * v.z;+ return vec3(cos(vb) * v.x + sin(vb) * y1, -sin(vb) * v.x + cos(vb) * y1, z1);+}+ // The height bytes are split across R and G, so filtering would blend the high // byte of one texel with another's and spike at every byte rollover. Fetch the // exact texel instead: longitude wraps, latitude clamps at the poles.@@ -42,28 +72,65 @@ float demMetres(vec2 uv) { int(fract(uv.x) * float(size.x)) % size.x, clamp(int(uv.y * float(size.y)), 0, size.y - 1)); vec4 t = texelFetch(moonDem, p, 0);- return (round(t.r * 255.0) * 256.0 + round(t.g * 255.0) - 20000.0) * 0.5;+ return (round(t.r * 255.0) * 256.0 + round(t.g * 255.0) - push.line.x) * push.line.y;+}++// Ring sample at this screen point, or alpha 0 when the point misses the+// ring annulus. `depth` returns the ring point's view depth (sphere-normal+// z units) for the front/back test against the planet.+vec4 ringSample(vec2 en, float cLatR, out float depth) {+ depth = 0.0;+ if (push.morph.x <= 0.0 || push.line.w <= push.line.z) return vec4(0.0);+ float sy = sin(cLatR);+ float cy = cos(cLatR);+ float vb = radians(push.misc.x);+ float vp = radians(push.misc.y);+ float cb = cos(vb);+ float sb = sin(vb);+ float cp = cos(vp);+ float sp = sin(vp);+ // Centre-facing point pc = viewUnrotate(vec3(en, depth)); the body pole+ // in that frame is (0, cy, sy), so the equatorial plane is+ // cy * pc.y + sy * pc.z == 0. pc.y/pc.z are linear in depth:+ // pc.y = -sb * en.x + cb * (cp * en.y + sp * depth)+ // pc.z = -sp * en.y + cp * depth+ // Solve for depth. Near a pole-on view the ring collapses to a line:+ // clamp the coefficient so the annulus stays finite (and thin).+ float coeff = cy * cb * sp + sy * cp;+ float denom = abs(coeff) < 0.03 ? (coeff < 0.0 ? -0.03 : 0.03) : coeff;+ float constant = cy * (-sb * en.x + cb * cp * en.y) - sy * sp * en.y;+ depth = -constant / denom;+ vec3 pc = viewUnrotate(vec3(en, depth));+ float radius = length(pc);+ float u = (radius - push.line.z) / (push.line.w - push.line.z);+ if (u < 0.0 || u > 1.0) return vec4(0.0);+ vec4 ring = texture(bodyRing, vec2(u, 0.5));+ return vec4(ring.rgb, ring.a * push.morph.x); } void main() { // Disc y-down to north-up. vec2 en = vec2(inDisc.x, -inDisc.y); float r2 = dot(en, en);- if (r2 > 1.0) discard;+ float cLatR = radians(push.color.y);++ if (r2 > 1.0) {+ // Off the disc: only a ring can draw here.+ float ringDepth;+ vec4 ring = ringSample(en, cLatR, ringDepth);+ if (ring.a < 0.004) discard;+ gl_FragDepth = 1.0 - clamp(ringDepth, -1.0, 1.0) * 0.5;+ outColor = vec4(ring.rgb * 0.9, ring.a);+ return;+ } float z = sqrt(1.0 - r2); vec3 sphereNormal = vec3(en, z); // Nearer (larger z) wins LESS, matching the globe tiles' depth regime. gl_FragDepth = 1.0 - z * 0.5; - // Undo the camera view rotation (push.line.xy: bearing/pitch degrees;- // mirrors `globe_view_unrotate`), then invert the east/north/up basis+ // Undo the camera view rotation, then invert the east/north/up basis // (mirrors `globe_lonlat`). Shading keeps the view-frame normal above.- float vb = radians(push.line.x);- float vp = radians(push.line.y);- float y1 = cos(vp) * en.y + sin(vp) * z;- float z1 = -sin(vp) * en.y + cos(vp) * z;- vec3 basis = vec3(cos(vb) * en.x + sin(vb) * y1, -sin(vb) * en.x + cos(vb) * y1, z1);- float cLatR = radians(push.color.y);+ vec3 basis = viewUnrotate(sphereNormal); float sy = sin(cLatR); float cy = cos(cLatR); float ey = cy * basis.y + sy * basis.z;@@ -74,18 +141,31 @@ void main() { vec2 uv = vec2((lon + 180.0) / 360.0, (90.0 - lat) / 180.0); vec3 albedo = texture(moonColor, uv).rgb; - // Forward differences one DEM texel east and south. Equirectangular texels- // span equal angles on both axes, so the two gradients share one scale.- vec2 texel = 1.0 / vec2(textureSize(moonDem, 0));- float hC = demMetres(uv);- float hX = demMetres(uv + vec2(texel.x, 0.0));- float hY = demMetres(uv + vec2(0.0, texel.y));- float relief = push.misc.z;- // Rising east tilts the normal west; rising south (uv.y grows southward)- // tilts it north.- vec3 n = normalize(sphereNormal + vec3(-(hX - hC), hY - hC, 0.0) * relief);+ vec3 n = sphereNormal;+ if (push.line.y > 0.0) {+ // Forward differences one DEM texel east and south. Equirectangular+ // texels span equal angles on both axes, so the gradients share a scale.+ vec2 texel = 1.0 / vec2(textureSize(moonDem, 0));+ float hC = demMetres(uv);+ float hX = demMetres(uv + vec2(texel.x, 0.0));+ float hY = demMetres(uv + vec2(0.0, texel.y));+ float relief = push.misc.z;+ // Rising east tilts the normal west; rising south (uv.y grows+ // southward) tilts it north.+ n = normalize(sphereNormal + vec3(-(hX - hC), hY - hC, 0.0) * relief);+ } vec3 sun = normalize(vec3(0.8, 0.25, 0.55)); float diff = clamp(dot(n, sun), 0.0, 1.0); float shade = (0.25 + 0.75 * diff) * (0.35 + 0.65 * z);- outColor = vec4(albedo * shade, 1.0);+ vec3 col = albedo * shade;++ // The ring's front arc crosses the disc: blend it over the planet where+ // the ring point sits nearer than the sphere surface at this pixel.+ // Both depths are view-frame z, so the test survives the view rotation.+ float ringDepth;+ vec4 ring = ringSample(en, cLatR, ringDepth);+ if (ring.a >= 0.004 && ringDepth > z) {+ col = mix(col, ring.rgb * 0.9, clamp(ring.a, 0.0, 1.0));+ }+ outColor = vec4(col, 1.0); }
library/map/src/main/rust/shaders/moon.vert
diff --git a/library/map/src/main/rust/shaders/moon.vert b/library/map/src/main/rust/shaders/moon.vertindex a0285128e9..e0c4451aea 100644--- a/library/map/src/main/rust/shaders/moon.vert+++ b/library/map/src/main/rust/shaders/moon.vert@@ -11,6 +11,7 @@ // Push layout (the stock `Push` block): // `tileToClip` the disc matrix described above. // `color.xy` the camera centre lon/lat (degrees), read by the fragment stage.+// `line` the DEM packing + ring radii, `misc.xy` the bearing/pitch and // `misc.z` the DEM relief strength, read by the fragment stage. layout(location = 0) in vec3 inLocal; layout(location = 0) out vec2 outDisc;@@ -23,6 +24,8 @@ layout(push_constant) uniform Push { } push; void main() {- outDisc = inLocal.xy;+ // morph.y: quad extent in planetary radii (>1 only for ringed bodies,+ // whose annulus spills past the disc's bounding square).+ outDisc = inLocal.xy * push.morph.y; gl_Position = push.tileToClip * vec4(inLocal.xy, 0.0, 1.0); }
library/map/src/main/rust/src/body_params.rs
diff --git a/library/map/src/main/rust/src/body_params.rs b/library/map/src/main/rust/src/body_params.rsnew file mode 100644index 0000000000..e2baa9ea97--- /dev/null+++ b/library/map/src/main/rust/src/body_params.rs@@ -0,0 +1,127 @@+//! Per-body raster parameters for the non-Earth globes (host-testable).+//!+//! DEM packing mirrors the asset sidecars: the shader decodes a packed uint16+//! as `(packed - dem_offset) * dem_unit_metres`. Ring radii are in planetary+//! radii; `ring_outer <= ring_inner` means the body has no rings.++/// Per-body raster parameters pushed with a body's texture set.+///+/// DEM packing mirrors the asset sidecars: the shader decodes a packed uint16+/// as `(packed - dem_offset) * dem_unit_metres`. Ring radii are in planetary+/// radii; `ring_outer <= ring_inner` means the body has no rings.+#[derive(Clone, Copy, PartialEq, Debug)]+pub struct BodyParams {+ pub dem_offset: f32,+ pub dem_unit_metres: f32,+ pub relief: f32,+ pub ring_inner: f32,+ pub ring_outer: f32,+ pub ring_opacity: f32,+}++impl BodyParams {+ /// The Moon's historical packing (half-metres + 20000, SVS 4720 LDEM).+ pub const MOON: Self = Self {+ dem_offset: 20_000.0,+ dem_unit_metres: 0.5,+ relief: 0.02,+ ring_inner: 0.0,+ ring_outer: 0.0,+ ring_opacity: 0.0,+ };++ pub fn has_rings(&self) -> bool {+ self.ring_outer > self.ring_inner && self.ring_inner >= 1.0 && self.ring_opacity > 0.0+ }+}++/// Validate a body upload's byte counts against its declared dimensions.+pub fn check_body_upload(+ color_len: usize,+ width: u32,+ height: u32,+ dem_len: usize,+ dem_width: u32,+ dem_height: u32,+ ring_len: usize,+ ring_width: u32,+ params: &BodyParams,+) -> Result<(), String> {+ if color_len != (width as usize) * (height as usize) * 4 {+ return Err(format!("body color is {color_len} bytes for a {width}x{height} RGBA image"));+ }+ if dem_len != (dem_width as usize) * (dem_height as usize) * 2 {+ return Err(format!("body dem is {dem_len} bytes for a {dem_width}x{dem_height} RG image"));+ }+ if params.has_rings() {+ if ring_width == 0 || ring_len != (ring_width as usize) * 4 {+ return Err(format!("body ring is {ring_len} bytes for a {ring_width}x1 RGBA strip"));+ }+ } else if ring_len != 0 && ring_len != (ring_width as usize) * 4 {+ return Err(format!("body ring is {ring_len} bytes for a {ring_width}x1 RGBA strip"));+ }+ if params.dem_unit_metres < 0.0+ || params.relief < 0.0+ || !(0.0..=1.0).contains(¶ms.ring_opacity)+ {+ return Err("body params out of range".to_string());+ }+ Ok(())+}++#[cfg(test)]+mod tests {+ use super::{check_body_upload, BodyParams};++ #[test]+ fn moon_packing_validates() {+ assert!(check_body_upload(+ 32 * 1024 * 1024,+ 4096,+ 2048,+ 4 * 1024 * 1024,+ 2048,+ 1024,+ 0,+ 0,+ &BodyParams::MOON+ )+ .is_ok());+ assert!(check_body_upload(+ 100,+ 4096,+ 2048,+ 4 * 1024 * 1024,+ 2048,+ 1024,+ 0,+ 0,+ &BodyParams::MOON+ )+ .is_err());+ }++ #[test]+ fn ringed_body_requires_matching_strip() {+ let saturn = BodyParams {+ ring_inner: 1.24,+ ring_outer: 2.27,+ ring_opacity: 1.0,+ ..BodyParams::MOON+ };+ assert!(saturn.has_rings());+ assert!(+ check_body_upload(8 * 1024 * 1024, 2048, 1024, 2, 1, 1, 4096, 1024, &saturn).is_ok()+ );+ assert!(+ check_body_upload(8 * 1024 * 1024, 2048, 1024, 2, 1, 1, 100, 1024, &saturn).is_err()+ );+ assert!(!BodyParams::MOON.has_rings());+ }++ #[test]+ fn out_of_range_params_rejected() {+ let bad = BodyParams { ring_opacity: 2.0, ..BodyParams::MOON };+ assert!(check_body_upload(4, 1, 1, 2, 1, 1, 0, 0, &bad).is_err());+ }+}
library/map/src/main/rust/src/bridge/moon.rs
diff --git a/library/map/src/main/rust/src/bridge/moon.rs b/library/map/src/main/rust/src/bridge/moon.rsindex 57dec67c53..0318236d9e 100644--- a/library/map/src/main/rust/src/bridge/moon.rs+++ b/library/map/src/main/rust/src/bridge/moon.rs@@ -1,32 +1,48 @@-//! Moon raster pair upload (maps-only lunar globe).+//! Body raster upload (maps-only non-Earth globes). //!-//! Pure JNI entry point; the GPU work lives in `Renderer::set_moon_textures`+//! Pure JNI entry points; the GPU work lives in `Renderer::set_moon_textures` //! (upload path) and the Moon record branch (draw path). use super::handle::handle_mut; use super::log::log;+use crate::body_params::BodyParams; use jni::objects::{JByteArray, JClass};-use jni::sys::{jint, jlong};+use jni::sys::{jfloat, jint, jlong}; use jni::EnvUnowned; use jni_bridge::jni_direct;-/// Upload the Moon raster pair: the converted LROC color (RGBA8) and the-/// converted LDEM (RG8 packed uint16, see `analysis/convert_moon.py`).++/// Read a Java byte array into a fresh buffer of exactly `len` bytes.+fn read_array(env: &mut EnvUnowned, array: &JByteArray, len: usize) -> Option<Vec<u8>> {+ let mut buf = vec![0u8; len];+ env.with_env(|env| {+ Ok::<bool, jni::errors::Error>(+ env.get_byte_array_region(array, 0, bytemuck_cast(&mut buf)).is_ok(),+ )+ })+ .resolve::<jni::errors::LogErrorAndDefault>()+ .then_some(buf)+}++/// Reinterpret a `&mut [u8]` as `&mut [i8]` for the JNI byte-array read. ///-/// Two bulk byte arrays plus their dimensions — the same convention as the-/// marker/route pushes: one crossing, no per-pixel traffic. The renderer copies-/// them to GPU textures (replacing any previous pair, retiring the old images-/// through the frames-in-flight grace queue); unreadable arrays leave the-/// previous pair unchanged rather than blanking the Moon.-#[no_mangle]-pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMoonTextures<'l>(- mut env: EnvUnowned<'l>,- _class: JClass<'l>,+/// `get_byte_array_region` takes `&mut [i8]` (Java bytes are signed); the bit+/// pattern is what matters and the cast keeps it. Sound: `u8` and `i8` share+/// size and alignment, and the length is preserved.+fn bytemuck_cast(bytes: &mut [u8]) -> &mut [i8] {+ unsafe { std::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut i8, bytes.len()) }+}++#[allow(clippy::too_many_arguments)]+fn upload_body(+ env: EnvUnowned, handle: jlong,- color_rgba: JByteArray<'l>,+ color_rgba: JByteArray, width: jint, height: jint,- dem_rg: JByteArray<'l>,+ dem_rg: JByteArray, dem_width: jint, dem_height: jint,+ params: BodyParams,+ ring_rgba: Option<(JByteArray, jint)>, ) { let Some(map) = handle_mut(handle) else { return;@@ -34,38 +50,50 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMoonTexture let (width, height) = (width.max(0) as usize, height.max(0) as usize); let (dem_width, dem_height) = (dem_width.max(0) as usize, dem_height.max(0) as usize); if width == 0 || height == 0 || dem_width == 0 || dem_height == 0 {- log("moon textures: refusing a zero-sized upload");+ log("body textures: refusing a zero-sized upload"); return; } if width.checked_mul(height).and_then(|n| n.checked_mul(4)).is_none() || dem_width.checked_mul(dem_height).and_then(|n| n.checked_mul(2)).is_none() {- log("moon textures: refusing an overflowing size");+ log("body textures: refusing an overflowing size"); return; } let color_len = width * height * 4; let dem_len = dem_width * dem_height * 2;- // Cap the crossing at the converted asset sizes (32MB + 4MB): anything- // larger is a caller bug, and the transient allocation lands on the frame- // thread's host heap.+ // Cap the crossing at the converted asset sizes (32MB + 4MB colour/DEM,+ // 4KB ring strip): anything larger is a caller bug, and the transient+ // allocation lands on the frame thread's host heap. if color_len > 64 * 1024 * 1024 || dem_len > 16 * 1024 * 1024 {- log("moon textures: refusing an oversized upload");+ log("body textures: refusing an oversized upload"); return; }- let mut color_buf = vec![0u8; color_len];- let mut dem_buf = vec![0u8; dem_len];- let read_ok: bool = env- .with_env(|env| {- Ok::<bool, jni::errors::Error>(- env.get_byte_array_region(&color_rgba, 0, bytemuck_cast(&mut color_buf)).is_ok()- && env.get_byte_array_region(&dem_rg, 0, bytemuck_cast(&mut dem_buf)).is_ok(),- )- })- .resolve::<jni::errors::LogErrorAndDefault>();- if !read_ok {- log("moon textures: arrays could not be read; leaving the Moon unchanged");+ let mut env = env;+ let Some(color_buf) = read_array(&mut env, &color_rgba, color_len) else {+ log("body textures: colour array could not be read; leaving the body unchanged"); return;- }+ };+ let Some(dem_buf) = read_array(&mut env, &dem_rg, dem_len) else {+ log("body textures: DEM array could not be read; leaving the body unchanged");+ return;+ };+ let ring = match ring_rgba {+ Some((array, ring_width)) if ring_width > 0 => {+ let ring_len = (ring_width.max(0) as usize) * 4;+ if ring_len > 1024 * 1024 {+ log("body textures: refusing an oversized ring strip");+ return;+ }+ match read_array(&mut env, &array, ring_len) {+ Some(buf) => Some((buf, ring_width as u32)),+ None => {+ log("body textures: ring array could not be read; leaving the body unchanged");+ return;+ }+ }+ }+ _ => None,+ }; if let Err(e) = map.renderer.set_moon_textures( &color_buf, width as u32,@@ -73,23 +101,80 @@ pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMoonTexture &dem_buf, dem_width as u32, dem_height as u32,+ params,+ ring.as_ref().map(|(buf, w)| (buf.as_slice(), *w)), ) {- log(&format!("moon textures: upload failed: {e}"));+ log(&format!("body textures: upload failed: {e}")); } } -/// Reinterpret a `&mut [u8]` as `&mut [i8]` for the JNI byte-array read.+/// Upload the Moon raster pair: the converted LROC color (RGBA8) and the+/// converted LDEM (RG8 packed uint16, see `analysis/convert_moon.py`). ///-/// `get_byte_array_region` takes `&mut [i8]` (Java bytes are signed); the bit-/// pattern is what matters and the cast keeps it. Sound: `u8` and `i8` share-/// size and alignment, and the length is preserved.-fn bytemuck_cast(bytes: &mut [u8]) -> &mut [i8] {- unsafe { std::slice::from_raw_parts_mut(bytes.as_mut_ptr() as *mut i8, bytes.len()) }+/// Two bulk byte arrays plus their dimensions — the same convention as the+/// marker/route pushes: one crossing, no per-pixel traffic. The renderer copies+/// them to GPU textures (replacing any previous pair, retiring the old images+/// through the frames-in-flight grace queue); unreadable arrays leave the+/// previous pair unchanged rather than blanking the Moon.+#[no_mangle]+pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setMoonTextures<'l>(+ env: EnvUnowned<'l>,+ _class: JClass<'l>,+ handle: jlong,+ color_rgba: JByteArray<'l>,+ width: jint,+ height: jint,+ dem_rg: JByteArray<'l>,+ dem_width: jint,+ dem_height: jint,+) {+ upload_body(+ env,+ handle,+ color_rgba,+ width,+ height,+ dem_rg,+ dem_width,+ dem_height,+ BodyParams::MOON,+ None,+ );+}++/// Upload any non-Earth body's raster set: colour + packed DEM (1x1 dummy for+/// DEM-less bodies), the DEM packing and relief, and an optional ring strip.+#[no_mangle]+#[allow(clippy::too_many_arguments)]+pub extern "system" fn Java_com_vayunmathur_library_map_MapNative_setBodyTextures<'l>(+ env: EnvUnowned<'l>,+ _class: JClass<'l>,+ handle: jlong,+ color_rgba: JByteArray<'l>,+ width: jint,+ height: jint,+ dem_rg: JByteArray<'l>,+ dem_width: jint,+ dem_height: jint,+ dem_offset: jfloat,+ dem_unit_metres: jfloat,+ relief: jfloat,+ ring_rgba: JByteArray<'l>,+ ring_width: jint,+ ring_inner: jfloat,+ ring_outer: jfloat,+ ring_opacity: jfloat,+) {+ let params =+ BodyParams { dem_offset, dem_unit_metres, relief, ring_inner, ring_outer, ring_opacity };+ let ring = if ring_width > 0 { Some((ring_rgba, ring_width)) } else { None };+ upload_body(+ env, handle, color_rgba, width, height, dem_rg, dem_width, dem_height, params, ring,+ ); } -jni_direct! { /// Drop the Moon raster pair (~40 MB of GPU images) when the host leaves the Moon; a later-/// [`setMoonTextures`](Java_com_vayunmathur_library_map_MapNative_setMoonTextures) uploads it-/// again.+jni_direct! { /// Drop the body raster set (~40 MB of GPU images) when the host leaves the body; a later+/// upload pushes it again. Java_com_vayunmathur_library_map_MapNative_clearMoonTextures; (_class: JClass<'l>, handle: jlong) { if let Some(map) = handle_mut(handle) { map.renderer.clear_moon_textures();
library/map/src/main/rust/src/lib.rs
diff --git a/library/map/src/main/rust/src/lib.rs b/library/map/src/main/rust/src/lib.rsindex 9d67ee6f35..899f0640c3 100644--- a/library/map/src/main/rust/src/lib.rs+++ b/library/map/src/main/rust/src/lib.rs@@ -34,6 +34,7 @@ //! `cargo test` covers tessellation, tile selection, the cache and the camera maths //! with no device attached. +pub mod body_params; pub mod camera; pub mod camera_extra; pub mod camera_extra2;
library/map/src/main/rust/src/vulkan/pipeline/pipelines_moon.rs
diff --git a/library/map/src/main/rust/src/vulkan/pipeline/pipelines_moon.rs b/library/map/src/main/rust/src/vulkan/pipeline/pipelines_moon.rsindex b544282dae..0de6b032ea 100644--- a/library/map/src/main/rust/src/vulkan/pipeline/pipelines_moon.rs+++ b/library/map/src/main/rust/src/vulkan/pipeline/pipelines_moon.rs@@ -31,6 +31,11 @@ pub(super) fn moon_layouts( .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) .descriptor_count(1) .stage_flags(vk::ShaderStageFlags::FRAGMENT),+ vk::DescriptorSetLayoutBinding::default()+ .binding(2)+ .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER)+ .descriptor_count(1)+ .stage_flags(vk::ShaderStageFlags::FRAGMENT), ]; let ds_info = vk::DescriptorSetLayoutCreateInfo::default().bindings(&moon_bindings); let ds_layout = device
library/map/src/main/rust/src/vulkan/renderer/mod.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/mod.rs b/library/map/src/main/rust/src/vulkan/renderer/mod.rsindex d40003a6ac..076e838de3 100644--- a/library/map/src/main/rust/src/vulkan/renderer/mod.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/mod.rs@@ -34,7 +34,7 @@ mod record_symbol; mod suppression; mod upload; mod upload_extra;-pub(super) mod upload_moon;+pub(crate) mod upload_moon; mod upload_pool; mod upload_tail;
library/map/src/main/rust/src/vulkan/renderer/mod_extra.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/mod_extra.rs b/library/map/src/main/rust/src/vulkan/renderer/mod_extra.rsindex 1dc5a5326d..f880de0d6f 100644--- a/library/map/src/main/rust/src/vulkan/renderer/mod_extra.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/mod_extra.rs@@ -38,6 +38,10 @@ pub struct Renderer { /// colour rather than failing the frame. pub(crate) moon_color: Option<SampledImage>, pub(crate) moon_dem: Option<SampledImage>,+ /// Ring strip for the current body (1x1 transparent dummy when ringless).+ pub(crate) moon_ring: Option<SampledImage>,+ /// DEM packing / relief / ring parameters for the current body.+ pub(crate) body_params: crate::body_params::BodyParams, /// Moon-owned descriptor pool + sets (color set 0, DEM set 1) for the Moon /// pipeline's two-image layout. `None` until the first `set_moon_textures` /// push; recreated (old pool destroyed) on every re-push, so a re-attach
library/map/src/main/rust/src/vulkan/renderer/rebuild.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/rebuild.rs b/library/map/src/main/rust/src/vulkan/renderer/rebuild.rsindex f002e83ce7..4461c6d30a 100644--- a/library/map/src/main/rust/src/vulkan/renderer/rebuild.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/rebuild.rs@@ -93,6 +93,9 @@ impl Drop for Renderer { if let Some(image) = &self.moon_dem { image.destroy(&self.context.device); }+ if let Some(image) = &self.moon_ring {+ image.destroy(&self.context.device);+ } if let Some(pool) = &self.moon_pool { self.context.device.destroy_descriptor_pool(*pool, None); }
library/map/src/main/rust/src/vulkan/renderer/record_moon.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs b/library/map/src/main/rust/src/vulkan/renderer/record_moon.rsindex e3e2b41b65..410d6df7c9 100644--- a/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/record_moon.rs@@ -138,7 +138,12 @@ impl Renderer { // rect, so no new vertex path. The quad vertices are -1..1 already; the // matrix maps them to the disc: scale = globe diameter in clip units, // centred on the viewport centre.+ let params = self.body_params; let r_dp = crate::camera::globe_radius(camera.zoom, camera.center_lat);+ // Ringed bodies draw past the disc: widen the quad to the ring's+ // outer radius (in planetary radii) so the annulus has fragments.+ let ring_extent = if params.has_rings() { params.ring_outer } else { 1.0 } as f64;+ let r_dp = r_dp * ring_extent; let kx = 2.0 / camera.width_dp as f64; let ky = 2.0 / camera.height_dp as f64; let disc = [@@ -163,12 +168,21 @@ impl Renderer { tile_to_clip: disc, // xy: visible-hemisphere centre lon/lat (degrees) for the texture basis. color: [camera.center_lon as f32, camera.center_lat as f32, 0.0, 1.0],- // xy: camera bearing/pitch (degrees) for the fragment view rotation.- line: [camera.bearing_deg as f32, camera.pitch_deg as f32, 0.0, 0.0],- // z: DEM relief strength (normal nudge per metre, tuned for the- // ±10km LDEM range at globe zoom).- misc: [0.0, 0.0, 0.02, camera.time_seconds],- morph: [0.0; 4],+ // DEM packing (offset, metres per unit) + ring radii in planetary+ // radii, read by `moon.frag`.+ line: [params.dem_offset, params.dem_unit_metres, params.ring_inner, params.ring_outer],+ // xy: camera bearing/pitch (degrees) for the fragment view+ // rotation (the `line` slot the globe path used now carries the+ // body DEM/ring parameters, so the view rotation rides here);+ // z: DEM relief strength (normal nudge per metre, tuned per body).+ misc: [+ camera.bearing_deg as f32,+ camera.pitch_deg as f32,+ params.relief,+ camera.time_seconds,+ ],+ // x: ring opacity (0 = no rings); y: quad extent in radii.+ morph: [params.ring_opacity, ring_extent as f32, 0.0, 0.0], }; device.cmd_bind_pipeline( command_buffer,
library/map/src/main/rust/src/vulkan/renderer/upload_extra.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/upload_extra.rs b/library/map/src/main/rust/src/vulkan/renderer/upload_extra.rsindex bb773e03bd..b950205acc 100644--- a/library/map/src/main/rust/src/vulkan/renderer/upload_extra.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/upload_extra.rs@@ -165,6 +165,8 @@ impl Renderer { sprite_set, moon_color: None, moon_dem: None,+ moon_ring: None,+ body_params: crate::body_params::BodyParams::MOON, moon_pool: None, moon_set: None, command_pool,
library/map/src/main/rust/src/vulkan/renderer/upload_moon.rs
diff --git a/library/map/src/main/rust/src/vulkan/renderer/upload_moon.rs b/library/map/src/main/rust/src/vulkan/renderer/upload_moon.rsindex 4a1e912e22..9c1534ddd2 100644--- a/library/map/src/main/rust/src/vulkan/renderer/upload_moon.rs+++ b/library/map/src/main/rust/src/vulkan/renderer/upload_moon.rs@@ -6,6 +6,8 @@ //! replaced wholesale on every push, with the old images retired through the //! frames-in-flight grace queue. use super::{Renderer, TransientBuffers, FRAMES_IN_FLIGHT};+pub use crate::body_params::{check_body_upload, BodyParams};+ use crate::vulkan::context::Context; use crate::vulkan::images::SampledImage; use ash::vk;@@ -26,6 +28,7 @@ impl Renderer { /// destroyed only after its sets are no longer referenced, which the same /// grace guarantees. On failure the previous pair (if any) stays live /// rather than half-set.+ #[allow(clippy::too_many_arguments)] pub fn set_moon_textures( &mut self, color_rgba: &[u8],@@ -34,21 +37,30 @@ impl Renderer { dem_rg: &[u8], dem_width: u32, dem_height: u32,+ params: BodyParams,+ ring_rgba: Option<(&[u8], u32)>, ) -> Result<(), String> {- if color_rgba.len() != (width as usize) * (height as usize) * 4 {- return Err(format!(- "moon color is {} bytes for a {width}x{height} RGBA image",- color_rgba.len()- ));- }- if dem_rg.len() != (dem_width as usize) * (dem_height as usize) * 2 {- return Err(format!(- "moon dem is {} bytes for a {dem_width}x{dem_height} RG image",- dem_rg.len()- ));- }+ let (ring_bytes, ring_width) = ring_rgba.unwrap_or((&[], 0));+ check_body_upload(+ color_rgba.len(),+ width,+ height,+ dem_rg.len(),+ dem_width,+ dem_height,+ ring_bytes.len(),+ ring_width,+ ¶ms,+ )?; // SAFETY: fresh GPU images; the old ones retire below.- let (color, dem) = unsafe {+ let (color, dem, ring) = unsafe {+ // Ringless bodies still need a binding-2 image: a 1x1 transparent+ // dummy keeps the descriptor set valid.+ let (ring_pixels, rw, rh): (&[u8], u32, u32) = if params.has_rings() {+ (ring_bytes, ring_width, 1)+ } else {+ (&[0, 0, 0, 0], 1, 1)+ }; ( upload_moon_image( &self.context,@@ -59,19 +71,28 @@ impl Renderer { vk::Format::R8G8B8A8_UNORM, )?, upload_moon_rg(&self.context, self.command_pool, dem_rg, dem_width, dem_height)?,+ upload_moon_image(+ &self.context,+ self.command_pool,+ ring_pixels,+ rw,+ rh,+ vk::Format::R8G8B8A8_UNORM,+ )?, ) }; // Moon-owned pool for exactly 2 combined-image-sampler descriptors. let pool = unsafe { let size = vk::DescriptorPoolSize::default() .ty(vk::DescriptorType::COMBINED_IMAGE_SAMPLER)- .descriptor_count(2);+ .descriptor_count(3); let info = vk::DescriptorPoolCreateInfo::default() .pool_sizes(std::slice::from_ref(&size)) .max_sets(1); self.context.device.create_descriptor_pool(&info, None).map_err(|e| { color.destroy(&self.context.device); dem.destroy(&self.context.device);+ ring.destroy(&self.context.device); format!("create_descriptor_pool(moon) {e:?}") })? };@@ -87,6 +108,7 @@ impl Renderer { self.context.device.destroy_descriptor_pool(pool, None); color.destroy(&self.context.device); dem.destroy(&self.context.device);+ ring.destroy(&self.context.device); format!("allocate_descriptor_sets(moon) {e:?}") })? .into_iter()@@ -95,6 +117,7 @@ impl Renderer { self.context.device.destroy_descriptor_pool(pool, None); color.destroy(&self.context.device); dem.destroy(&self.context.device);+ ring.destroy(&self.context.device); "moon descriptor pool gave no sets".to_string() })?; let color_info = vk::DescriptorImageInfo::default()@@ -105,6 +128,10 @@ impl Renderer { .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) .image_view(dem.view) .sampler(dem.sampler);+ let ring_info = vk::DescriptorImageInfo::default()+ .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)+ .image_view(ring.view)+ .sampler(ring.sampler); let writes = [ vk::WriteDescriptorSet::default() .dst_set(set)@@ -116,6 +143,11 @@ impl Renderer { .dst_binding(1) .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) .image_info(std::slice::from_ref(&dem_info)),+ vk::WriteDescriptorSet::default()+ .dst_set(set)+ .dst_binding(2)+ .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER)+ .image_info(std::slice::from_ref(&ring_info)), ]; self.context.device.update_descriptor_sets(&writes, &[]); set@@ -129,6 +161,10 @@ impl Renderer { if let Some(old_dem) = self.moon_dem.replace(dem) { self.retire_moon_image(old_dem); }+ if let Some(old_ring) = self.moon_ring.replace(ring) {+ self.retire_moon_image(old_ring);+ }+ self.body_params = params; if let Some(old_pool) = self.moon_pool.replace(pool) { self.retire_moon_pool(old_pool); }@@ -147,6 +183,10 @@ impl Renderer { if let Some(dem) = self.moon_dem.take() { self.retire_moon_image(dem); }+ if let Some(ring) = self.moon_ring.take() {+ self.retire_moon_image(ring);+ }+ self.body_params = BodyParams::MOON; if let Some(pool) = self.moon_pool.take() { self.retire_moon_pool(pool); }
library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt
diff --git a/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt b/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.ktindex 36d36aec42..4241be62c9 100644--- a/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt+++ b/library/map/src/test/java/com/vayunmathur/library/map/MapOptionsTest.kt@@ -37,6 +37,13 @@ class MapOptionsTest { assertEquals(LayerOptions(), o.layerOptions) } + @Test fun mapBody_entries() {+ assertEquals(+ listOf("Earth", "Mercury", "Venus", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Moon"),+ MapBody.entries.map { it.name },+ )+ }+ @Test fun trafficTable_contentEqualityAndEmpty() { val a = TrafficColorTable(longArrayOf(1L, 2L), intArrayOf(10, 20)) val b = TrafficColorTable(longArrayOf(1L, 2L), intArrayOf(10, 20))
library/map/src/test/java/com/vayunmathur/library/map/RendererStateTest.kt
diff --git a/library/map/src/test/java/com/vayunmathur/library/map/RendererStateTest.kt b/library/map/src/test/java/com/vayunmathur/library/map/RendererStateTest.ktindex 66826f3593..72f35f4e1c 100644--- a/library/map/src/test/java/com/vayunmathur/library/map/RendererStateTest.kt+++ b/library/map/src/test/java/com/vayunmathur/library/map/RendererStateTest.kt@@ -46,7 +46,7 @@ class RendererStateTest { @Test fun moonAndLifecycle_noSurface() { val r = renderer()- r.setMoonTextures(ByteArray(4), 1, 1, ByteArray(2), 1, 1)+ r.setMoonTextures(MoonTextures(ByteArray(4), 1, 1, ByteArray(2), 1, 1)) r.clearMoonTextures() r.globeEnabled = true; r.body = MapBody.Moon assertTrue(r.globeEnabled)