overflow: hidden/scroll scissor support, remove depth

This commit is contained in:
Aleksander
2025-09-25 23:21:11 +02:00
parent 8f75d451e4
commit eb12a6a319
28 changed files with 299 additions and 182 deletions

View File

@@ -242,7 +242,7 @@ impl Context {
drawing::RenderPrimitive::Rectangle(extent, rectangle) => {
pass
.rect_renderer
.add_rect(extent.boundary, *rectangle, &extent.transform, extent.depth);
.add_rect(extent.boundary, *rectangle, &extent.transform);
}
drawing::RenderPrimitive::Text(extent, text) => {
pass.text_areas.push(TextArea {
@@ -253,7 +253,6 @@ impl Context {
scale: self.pixel_scale,
default_color: cosmic_text::Color::rgb(0, 0, 0),
custom_glyphs: &[],
depth: extent.depth,
transform: extent.transform,
});
}
@@ -266,7 +265,6 @@ impl Context {
scale: self.pixel_scale,
custom_glyphs: sprites.as_slice(),
default_color: cosmic_text::Color::rgb(255, 0, 255),
depth: extent.depth,
transform: extent.transform,
});
}

View File

@@ -30,8 +30,6 @@ pub struct RectVertex {
pub in_border_color: u32,
#[format(R32_UINT)]
pub round_border_gradient: [u8; 4],
#[format(R32_SFLOAT)]
pub depth: f32,
}
/// Cloneable pipeline & shaders to be shared between `RectRenderer` instances.
@@ -68,7 +66,7 @@ pub struct RectRenderer {
pipeline: RectPipeline,
rect_vertices: Vec<RectVertex>,
vert_buffer: Subbuffer<[RectVertex]>,
vert_buffer_size: usize,
vert_buffer_len: usize,
model_buffer: ModelBuffer,
pass: Option<CachedPass>,
}
@@ -77,16 +75,17 @@ impl RectRenderer {
pub fn new(pipeline: RectPipeline) -> anyhow::Result<Self> {
const BUFFER_SIZE: usize = 32;
let vert_buffer = pipeline
.gfx
.empty_buffer(BufferUsage::VERTEX_BUFFER | BufferUsage::TRANSFER_DST, BUFFER_SIZE as _)?;
let vert_buffer = pipeline.gfx.empty_buffer(
BufferUsage::VERTEX_BUFFER | BufferUsage::TRANSFER_DST,
(std::mem::size_of::<RectVertex>() * BUFFER_SIZE) as _,
)?;
Ok(Self {
model_buffer: ModelBuffer::new(&pipeline.gfx)?,
pipeline,
rect_vertices: vec![],
vert_buffer,
vert_buffer_size: BUFFER_SIZE,
vert_buffer_len: BUFFER_SIZE,
pass: None,
})
}
@@ -96,7 +95,7 @@ impl RectRenderer {
self.model_buffer.begin();
}
pub fn add_rect(&mut self, boundary: Boundary, rectangle: Rectangle, transform: &Mat4, depth: f32) {
pub fn add_rect(&mut self, boundary: Boundary, rectangle: Rectangle, transform: &Mat4) {
let in_model_idx = self
.model_buffer
.register_pos_size(&boundary.pos, &boundary.size, transform);
@@ -113,18 +112,17 @@ impl RectRenderer {
rectangle.gradient as u8,
0, // unused
],
depth,
});
}
fn upload_verts(&mut self) -> anyhow::Result<()> {
if self.vert_buffer_size < self.rect_vertices.len() {
let new_size = self.vert_buffer_size * 2;
self.vert_buffer = self
.pipeline
.gfx
.empty_buffer(BufferUsage::VERTEX_BUFFER | BufferUsage::TRANSFER_DST, new_size as _)?;
self.vert_buffer_size = new_size;
if self.vert_buffer_len < self.rect_vertices.len() {
let new_size = self.vert_buffer_len * 2;
self.vert_buffer = self.pipeline.gfx.empty_buffer(
BufferUsage::VERTEX_BUFFER | BufferUsage::TRANSFER_DST,
(std::mem::size_of::<RectVertex>() * new_size) as _,
)?;
self.vert_buffer_len = new_size;
}
self.vert_buffer.write()?[0..self.rect_vertices.len()].clone_from_slice(&self.rect_vertices);

View File

@@ -9,7 +9,6 @@ layout(location = 2) in uint in_color;
layout(location = 3) in uint in_color2;
layout(location = 4) in uint in_border_color;
layout(location = 5) in uint round_border_gradient;
layout(location = 6) in float depth;
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_color2;
@@ -41,8 +40,7 @@ void main() {
out_rect_size = rect_size;
gl_Position =
uniforms.projection * model_matrix * vec4(corner_pos, depth, 1.0);
gl_Position = uniforms.projection * model_matrix * vec4(corner_pos, 0.0, 1.0);
out_border_color =
vec4(float((in_border_color & 0x00ff0000u) >> 16u) / 255.0,

View File

@@ -8,7 +8,6 @@ layout(location = 1) in uint in_rect_dim;
layout(location = 2) in uint in_uv;
layout(location = 3) in uint in_color;
layout(location = 4) in uint in_content_type;
layout(location = 5) in float depth;
layout(location = 7) in float scale;
layout(location = 0) out vec4 out_color;
@@ -41,7 +40,7 @@ void main() {
mat4 model_matrix = model_buffer.models[in_model_idx];
gl_Position =
uniforms.projection * model_matrix * vec4(corner_pos * scale, depth, 1.0);
uniforms.projection * model_matrix * vec4(corner_pos * scale, 0.0, 1.0);
out_content_type = in_content_type & 0xffffu;

View File

@@ -5,9 +5,7 @@ pub mod text_renderer;
use std::{cell::RefCell, rc::Rc, sync::LazyLock};
use cosmic_text::{
Align, Attrs, Buffer, Color, FontSystem, Metrics, Style, SwashCache, Weight, Wrap,
};
use cosmic_text::{Align, Attrs, Buffer, Color, FontSystem, Metrics, Style, SwashCache, Weight, Wrap};
use custom_glyph::{ContentType, CustomGlyph};
use etagere::AllocId;
use glam::Mat4;
@@ -15,10 +13,8 @@ use parking_lot::Mutex;
use crate::drawing::{self};
pub static FONT_SYSTEM: LazyLock<Mutex<FontSystem>> =
LazyLock::new(|| Mutex::new(FontSystem::new()));
pub static SWASH_CACHE: LazyLock<Mutex<SwashCache>> =
LazyLock::new(|| Mutex::new(SwashCache::new()));
pub static FONT_SYSTEM: LazyLock<Mutex<FontSystem>> = LazyLock::new(|| Mutex::new(FontSystem::new()));
pub static SWASH_CACHE: LazyLock<Mutex<SwashCache>> = LazyLock::new(|| Mutex::new(SwashCache::new()));
/// Used in case no `font_size` is defined
const DEFAULT_FONT_SIZE: f32 = 14.;
@@ -26,10 +22,8 @@ const DEFAULT_FONT_SIZE: f32 = 14.;
/// In case no `line_height` is defined, use `font_size` * `DEFAULT_LINE_HEIGHT_RATIO`
const DEFAULT_LINE_HEIGHT_RATIO: f32 = 1.43;
pub(crate) const DEFAULT_METRICS: Metrics = Metrics::new(
DEFAULT_FONT_SIZE,
DEFAULT_FONT_SIZE * DEFAULT_LINE_HEIGHT_RATIO,
);
pub(crate) const DEFAULT_METRICS: Metrics =
Metrics::new(DEFAULT_FONT_SIZE, DEFAULT_FONT_SIZE * DEFAULT_LINE_HEIGHT_RATIO);
#[derive(Default, Clone)]
pub struct TextStyle {
@@ -66,11 +60,7 @@ impl From<&TextStyle> for Metrics {
impl From<&TextStyle> for Wrap {
fn from(value: &TextStyle) -> Self {
if value.wrap {
Self::WordOrGlyph
} else {
Self::None
}
if value.wrap { Self::WordOrGlyph } else { Self::None }
}
}
@@ -155,11 +145,7 @@ impl From<cosmic_text::Color> for drawing::Color {
// glyphon types below
pub(super) enum GpuCacheStatus {
InAtlas {
x: u16,
y: u16,
content_type: ContentType,
},
InAtlas { x: u16, y: u16, content_type: ContentType },
SkipRasterization,
}
@@ -215,8 +201,6 @@ pub struct TextArea<'a> {
pub default_color: Color,
/// Additional custom glyphs to render.
pub custom_glyphs: &'a [CustomGlyph],
/// Distance from camera, 0.0..=1.0
pub depth: f32,
/// Text transformation
pub transform: Mat4,
}

View File

@@ -42,10 +42,7 @@ impl TextPipeline {
true,
)?;
Ok(Self {
gfx,
inner: pipeline,
})
Ok(Self { gfx, inner: pipeline })
}
}
@@ -63,8 +60,6 @@ pub struct GlyphVertex {
#[format(R32_UINT)]
pub in_content_type: [u16; 2], // 2 bytes unused! TODO
#[format(R32_SFLOAT)]
pub depth: f32,
#[format(R32_SFLOAT)]
pub scale: f32,
}
@@ -86,12 +81,7 @@ impl InnerAtlas {
const INITIAL_SIZE: u32 = 256;
fn new(common: TextPipeline, kind: Kind) -> anyhow::Result<Self> {
let max_texture_dimension_2d = common
.gfx
.device
.physical_device()
.properties()
.max_image_dimension2_d;
let max_texture_dimension_2d = common.gfx.device.physical_device().properties().max_image_dimension2_d;
let size = Self::INITIAL_SIZE.min(max_texture_dimension_2d);
let packer = BucketedAtlasAllocator::new(size2(size as i32, size as i32));
@@ -180,11 +170,7 @@ impl InnerAtlas {
self.kind.num_channels()
}
pub(super) fn grow(
&mut self,
font_system: &mut FontSystem,
cache: &mut SwashCache,
) -> anyhow::Result<bool> {
pub(super) fn grow(&mut self, font_system: &mut FontSystem, cache: &mut SwashCache) -> anyhow::Result<bool> {
const GROWTH_FACTOR: u32 = 2;
if self.size >= self.max_texture_dimension_2d {
@@ -327,10 +313,7 @@ impl TextAtlas {
Ok(did_grow)
}
pub(super) const fn inner_for_content_mut(
&mut self,
content_type: ContentType,
) -> &mut InnerAtlas {
pub(super) const fn inner_for_content_mut(&mut self, content_type: ContentType) -> &mut InnerAtlas {
match content_type {
ContentType::Color => &mut self.color_atlas,
ContentType::Mask => &mut self.mask_atlas,

View File

@@ -116,7 +116,6 @@ impl TextRenderer {
bounds_min_y,
bounds_max_x,
bounds_max_y,
depth: text_area.depth,
transform: &text_area.transform,
},
|_cache, _font_system| -> Option<GetGlyphImageResult> {
@@ -192,7 +191,6 @@ impl TextRenderer {
bounds_min_y,
bounds_max_x,
bounds_max_y,
depth: text_area.depth,
transform: &text_area.transform,
},
|cache, font_system| -> Option<GetGlyphImageResult> {
@@ -319,7 +317,6 @@ struct PrepareGlyphParams<'a> {
bounds_min_y: i32,
bounds_max_x: i32,
bounds_max_y: i32,
depth: f32,
}
#[allow(clippy::too_many_lines)]
@@ -484,7 +481,6 @@ fn prepare_glyph(
content_type as u16,
0, // unused (TODO!)
],
depth: par.depth,
scale: par.glyph_scale,
}))
}