forked from 1b-agent/opencadstudio-upstream
Merge pull request #1741 from ramox81/codex/view-background-followups
This commit is contained in:
commit
798014c773
33 files changed
+555
-94
No files matched your search
+16
-1
@@ -336,6 +336,12 @@ impl Scene {
|
||||
|
||||
/// The visual style of the active Model tile's viewport record.
|
||||
pub fn active_visual_style(&self) -> Handle {
|
||||
if self.current_layout != "Model" {
|
||||
return match self.active_viewport.and_then(|handle| self.document.get_entity(handle)) {
|
||||
Some(EntityType::Viewport(value)) => value.visual_style_handle,
|
||||
_ => Handle::NULL,
|
||||
};
|
||||
}
|
||||
self.active_tile_vport_handle()
|
||||
.and_then(|handle| self.document.vports.iter().find(|value| value.handle == handle))
|
||||
.map_or(Handle::NULL, |value| value.visual_style_handle)
|
||||
@@ -348,7 +354,16 @@ impl Scene {
|
||||
codec::objects::ObjectType::VisualStyle(style) if style.description == name => Some(*handle),
|
||||
_ => None,
|
||||
});
|
||||
let (Some(style), Some(handle)) = (style, self.active_tile_vport_handle()) else { return };
|
||||
let Some(style) = style else { return };
|
||||
if self.current_layout != "Model" {
|
||||
if let Some(handle) = self.active_viewport {
|
||||
if let Some(EntityType::Viewport(value)) = self.document.get_entity_mut(handle) {
|
||||
value.visual_style_handle = style;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some(handle) = self.active_tile_vport_handle() else { return };
|
||||
if let Some(value) = self.document.vports.iter_mut().find(|value| value.handle == handle) {
|
||||
value.visual_style_handle = style;
|
||||
}
|
||||
|
||||
@@ -4013,7 +4013,8 @@ analytic={:.1} regular={:.1} blocks={:.1}",
|
||||
}
|
||||
let upload = |label: &'static str,
|
||||
image: Option<&crate::scene::model::image_model::DecodedImage>,
|
||||
fallback: [u8; 4]| {
|
||||
fallback: [u8; 4],
|
||||
format: wgpu::TextureFormat| {
|
||||
let (width, height, pixels) = image
|
||||
.map(|image| (image.width, image.height, image.pixels.as_slice()))
|
||||
.unwrap_or((1, 1, fallback.as_slice()));
|
||||
@@ -4027,7 +4028,7 @@ analytic={:.1} regular={:.1} blocks={:.1}",
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
format,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
view_formats: &[],
|
||||
});
|
||||
@@ -4047,8 +4048,21 @@ analytic={:.1} regular={:.1} blocks={:.1}",
|
||||
);
|
||||
texture
|
||||
};
|
||||
self.background_texture = upload("background.texture", background, [0, 0, 0, 255]);
|
||||
self.environment_texture = upload("environment.texture", environment, [128, 128, 128, 255]);
|
||||
// The background image is drawn as it is, like the solid and gradient
|
||||
// colours (an sRGB view would darken it a second time); the
|
||||
// environment map stays sRGB for lighting.
|
||||
self.background_texture = upload(
|
||||
"background.texture",
|
||||
background,
|
||||
[0, 0, 0, 255],
|
||||
wgpu::TextureFormat::Rgba8Unorm,
|
||||
);
|
||||
self.environment_texture = upload(
|
||||
"environment.texture",
|
||||
environment,
|
||||
[128, 128, 128, 255],
|
||||
wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
);
|
||||
self.rebuild_frame_bind_group(device);
|
||||
self.background_source_id = background_id;
|
||||
self.environment_source_id = environment_id;
|
||||
|
||||
@@ -3,3 +3,4 @@ pub mod dispatch;
|
||||
pub mod render;
|
||||
pub mod transform;
|
||||
pub mod viewport_pane;
|
||||
pub use render::device_scale;
|
||||
@@ -385,6 +385,7 @@ impl shader::Primitive for Primitive {
|
||||
pipeline.gpu_error_epoch = errors_at_entry;
|
||||
}
|
||||
let scale = viewport.scale_factor() as f32;
|
||||
DEVICE_SCALE.store(scale.to_bits(), std::sync::atomic::Ordering::Relaxed);
|
||||
let instance_ids: Vec<u64> = self.viewports.iter().map(|vp| vp.instance_id).collect();
|
||||
let slots = pipeline.resolve_slots(device, queue, &instance_ids);
|
||||
for (i, vp) in self.viewports.iter().enumerate() {
|
||||
@@ -5440,3 +5441,11 @@ mod layer0_inherit_tests {
|
||||
assert!(scene.document_render_env_cache.borrow().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
/// The display's device pixels per logical pixel, as the viewport last drew.
|
||||
static DEVICE_SCALE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0x3f80_0000);
|
||||
|
||||
/// Device pixels per logical pixel of the drawing viewport.
|
||||
pub fn device_scale() -> f32 {
|
||||
f32::from_bits(DEVICE_SCALE.load(std::sync::atomic::Ordering::Relaxed))
|
||||
}
|
||||
Reference in new issue
Block a user