Add IndexBuffer abstraction

This commit is contained in:
Wez Furlong committed 2022-11-18 10:03:49 -07:00
1 parent d712559b72
commit 334fb8a2ed
2 files changed
+21 -5

No files matched your search

+20 -4
View File
@@ -5,7 +5,9 @@ use crate::termwindow::webgpu::WebGpuState;
use ::window::bitmaps::atlas::OutOfTextureSpace;
use ::window::glium::backend::Context as GliumContext;
use ::window::glium::buffer::{BufferMutSlice, Mapping};
use ::window::glium::{CapabilitiesSource, IndexBuffer, VertexBuffer as GliumVertexBuffer};
use ::window::glium::{
CapabilitiesSource, IndexBuffer as GliumIndexBuffer, VertexBuffer as GliumVertexBuffer,
};
use ::window::*;
use anyhow::Context;
use std::cell::{Ref, RefCell, RefMut};
@@ -15,6 +17,20 @@ use wgpu::util::DeviceExt;
const INDICES_PER_CELL: usize = 6;
pub enum IndexBuffer {
Glium(GliumIndexBuffer<u32>),
WebGpu(WebGpuIndexBuffer),
}
impl IndexBuffer {
pub fn glium(&self) -> &GliumIndexBuffer<u32> {
match self {
Self::Glium(g) => g,
_ => unreachable!(),
}
}
}
pub enum VertexBuffer {
Glium(GliumVertexBuffer<Vertex>),
WebGpu(WebGpuVertexBuffer),
@@ -161,7 +177,7 @@ impl<'a> QuadAllocator for MappedQuads<'a> {
pub struct TripleVertexBuffer {
pub index: RefCell<usize>,
pub bufs: RefCell<[VertexBuffer; 3]>,
pub indices: IndexBuffer<u32>,
pub indices: IndexBuffer,
pub capacity: usize,
pub next_quad: RefCell<usize>,
}
@@ -326,11 +342,11 @@ impl RenderLayer {
VertexBuffer::Glium(GliumVertexBuffer::dynamic(context, &verts)?),
]),
capacity: num_quads,
indices: IndexBuffer::new(
indices: IndexBuffer::Glium(GliumIndexBuffer::new(
context,
glium::index::PrimitiveType::TrianglesList,
&indices,
)?,
)?),
next_quad: RefCell::new(0),
};
+1 -1
View File
@@ -2000,7 +2000,7 @@ impl super::TermWindow {
frame.draw(
vertices.glium().slice(0..vertex_count).unwrap(),
vb.indices.slice(0..index_count).unwrap(),
vb.indices.glium().slice(0..index_count).unwrap(),
&gl_state.glyph_prog,
&uniforms,
if subpixel_aa {