mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
rect per glyph, buffer size bugfix
This commit is contained in:
parent
d89bf1c0af
commit
c82119e6d8
3 changed files with 51 additions and 37 deletions
|
@ -11,7 +11,7 @@
|
|||
use crate::buffer::create_rect_buffers;
|
||||
use crate::text::{build_glyph_brush, Text};
|
||||
use crate::vertex::Vertex;
|
||||
use crate::rect::{convert_rect};
|
||||
use crate::rect::{Rect};
|
||||
use ortho::{init_ortho, update_ortho_buffer, OrthoResources};
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
|
@ -19,7 +19,6 @@ use std::path::Path;
|
|||
use winit::event;
|
||||
use winit::event::{Event, ModifiersState};
|
||||
use winit::event_loop::ControlFlow;
|
||||
use wgpu_glyph::{ab_glyph};
|
||||
|
||||
pub mod ast;
|
||||
mod buffer;
|
||||
|
@ -196,40 +195,36 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
|||
.expect("Failed to acquire next SwapChainFrame")
|
||||
.output;
|
||||
|
||||
let text_bounds_rect_opt = queue_all_text(
|
||||
let glyph_bounds_rects = queue_all_text(
|
||||
&size,
|
||||
&text_state,
|
||||
&mut glyph_brush,
|
||||
);
|
||||
|
||||
match text_bounds_rect_opt {
|
||||
Some(ab_bounds_rect) => {
|
||||
let rect_buffers = create_rect_buffers(
|
||||
&gpu_device,
|
||||
&mut encoder,
|
||||
&[convert_rect(ab_bounds_rect, [255.0, 255.0, 255.0])],
|
||||
);
|
||||
if !glyph_bounds_rects.is_empty() {
|
||||
let rect_buffers = create_rect_buffers(
|
||||
&gpu_device,
|
||||
&mut encoder,
|
||||
&glyph_bounds_rects,
|
||||
);
|
||||
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations::default(),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations::default(),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
|
||||
render_pass.set_pipeline(&rect_pipeline);
|
||||
render_pass.set_bind_group(0, &ortho.bind_group, &[]);
|
||||
render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..));
|
||||
render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..));
|
||||
render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1);
|
||||
render_pass.set_pipeline(&rect_pipeline);
|
||||
render_pass.set_bind_group(0, &ortho.bind_group, &[]);
|
||||
render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..));
|
||||
render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..));
|
||||
render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1);
|
||||
|
||||
drop(render_pass);
|
||||
},
|
||||
None =>
|
||||
(),
|
||||
};
|
||||
drop(render_pass);
|
||||
}
|
||||
|
||||
// draw all text
|
||||
glyph_brush
|
||||
|
@ -330,7 +325,7 @@ fn queue_all_text(
|
|||
size: &winit::dpi::PhysicalSize<u32>,
|
||||
text_state: &str,
|
||||
glyph_brush: &mut wgpu_glyph::GlyphBrush<()>,
|
||||
) -> Option<ab_glyph::Rect> {
|
||||
) -> Vec<Rect> {
|
||||
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||
|
||||
let main_label = Text {
|
||||
|
@ -353,9 +348,7 @@ fn queue_all_text(
|
|||
|
||||
text::queue_text_draw(&main_label, glyph_brush);
|
||||
|
||||
let code_bounds_rect_opt = text::queue_text_draw(&code_text, glyph_brush);
|
||||
|
||||
code_bounds_rect_opt
|
||||
text::queue_text_draw(&code_text, glyph_brush)
|
||||
}
|
||||
|
||||
fn update_text_state(text_state: &mut String, received_char: &char) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue