Switch to per-pixel texture lookup for paints.
This is a prerequisite for supporting gradients and images.
This commit is contained in:
parent
1e84ddf1ff
commit
b269723254
|
@ -1523,6 +1523,7 @@ dependencies = [
|
||||||
"arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pathfinder_color 0.1.0",
|
||||||
"pathfinder_geometry 0.4.0",
|
"pathfinder_geometry 0.4.0",
|
||||||
"pathfinder_simd 0.4.0",
|
"pathfinder_simd 0.4.0",
|
||||||
"smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -12,7 +12,7 @@ use pathfinder_simd::default::F32x4;
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
|
||||||
// TODO(pcwalton): Maybe this should be a u32?
|
// TODO(pcwalton): Maybe this should be a u32?
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct ColorU {
|
pub struct ColorU {
|
||||||
pub r: u8,
|
pub r: u8,
|
||||||
pub g: u8,
|
pub g: u8,
|
||||||
|
|
|
@ -10,6 +10,9 @@ bitflags = "1.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
smallvec = "0.6"
|
smallvec = "0.6"
|
||||||
|
|
||||||
|
[dependencies.pathfinder_color]
|
||||||
|
path = "../color"
|
||||||
|
|
||||||
[dependencies.pathfinder_geometry]
|
[dependencies.pathfinder_geometry]
|
||||||
path = "../geometry"
|
path = "../geometry"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// pathfinder/geometry/src/dash.rs
|
// pathfinder/content/src/dash.rs
|
||||||
//
|
//
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
// Copyright © 2019 The Pathfinder Project Developers.
|
||||||
//
|
//
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
// pathfinder/geometry/src/gradient.rs
|
||||||
|
//
|
||||||
|
// Copyright © 2020 The Pathfinder Project Developers.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
use crate::sorted_vector::SortedVector;
|
||||||
|
use pathfinder_color::ColorU;
|
||||||
|
use std::cmp::PartialOrd;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Gradient {
|
||||||
|
stops: SortedVector<ColorStop>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
|
||||||
|
pub struct ColorStop {
|
||||||
|
pub offset: f32,
|
||||||
|
pub color: ColorU,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Gradient {
|
||||||
|
#[inline]
|
||||||
|
pub fn add_color_stop(&mut self, stop: ColorStop) {
|
||||||
|
self.stops.push(stop);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn stops(&self) -> &[ColorStop] {
|
||||||
|
&self.stops.array
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,9 +19,11 @@ extern crate log;
|
||||||
|
|
||||||
pub mod clip;
|
pub mod clip;
|
||||||
pub mod dash;
|
pub mod dash;
|
||||||
|
pub mod gradient;
|
||||||
pub mod orientation;
|
pub mod orientation;
|
||||||
pub mod outline;
|
pub mod outline;
|
||||||
pub mod segment;
|
pub mod segment;
|
||||||
|
pub mod sorted_vector;
|
||||||
pub mod stroke;
|
pub mod stroke;
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// pathfinder/renderer/src/sorted_vector.rs
|
// pathfinder/content/src/sorted_vector.rs
|
||||||
//
|
//
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
// Copyright © 2020 The Pathfinder Project Developers.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
@ -21,7 +21,7 @@ use pathfinder_geometry::rect::RectI;
|
||||||
use pathfinder_geometry::transform3d::Transform4F;
|
use pathfinder_geometry::transform3d::Transform4F;
|
||||||
use pathfinder_geometry::vector::{Vector2I, Vector4F};
|
use pathfinder_geometry::vector::{Vector2I, Vector4F};
|
||||||
use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererOptions};
|
use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererOptions};
|
||||||
use pathfinder_renderer::gpu::renderer::RenderMode;
|
use pathfinder_renderer::gpu::renderer::PostprocessOptions;
|
||||||
use pathfinder_renderer::gpu_data::RenderCommand;
|
use pathfinder_renderer::gpu_data::RenderCommand;
|
||||||
use pathfinder_renderer::options::RenderTransform;
|
use pathfinder_renderer::options::RenderTransform;
|
||||||
use pathfinder_renderer::post::DEFRINGING_KERNEL_CORE_GRAPHICS;
|
use pathfinder_renderer::post::DEFRINGING_KERNEL_CORE_GRAPHICS;
|
||||||
|
@ -252,9 +252,9 @@ impl<W> DemoApp<W> where W: Window {
|
||||||
|
|
||||||
fn render_vector_scene(&mut self) {
|
fn render_vector_scene(&mut self) {
|
||||||
match self.scene_metadata.monochrome_color {
|
match self.scene_metadata.monochrome_color {
|
||||||
None => self.renderer.set_render_mode(RenderMode::Multicolor),
|
None => self.renderer.set_postprocess_options(None),
|
||||||
Some(fg_color) => {
|
Some(fg_color) => {
|
||||||
self.renderer.set_render_mode(RenderMode::Monochrome {
|
self.renderer.set_postprocess_options(Some(PostprocessOptions {
|
||||||
fg_color: fg_color.to_f32(),
|
fg_color: fg_color.to_f32(),
|
||||||
bg_color: self.background_color().to_f32(),
|
bg_color: self.background_color().to_f32(),
|
||||||
gamma_correction: self.ui_model.gamma_correction_effect_enabled,
|
gamma_correction: self.ui_model.gamma_correction_effect_enabled,
|
||||||
|
@ -264,7 +264,7 @@ impl<W> DemoApp<W> where W: Window {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,14 +56,10 @@ where
|
||||||
dest_framebuffer: DestFramebuffer<D>,
|
dest_framebuffer: DestFramebuffer<D>,
|
||||||
options: RendererOptions,
|
options: RendererOptions,
|
||||||
fill_program: FillProgram<D>,
|
fill_program: FillProgram<D>,
|
||||||
solid_multicolor_tile_program: SolidTileMulticolorProgram<D>,
|
solid_tile_program: SolidTileProgram<D>,
|
||||||
alpha_multicolor_tile_program: AlphaTileMulticolorProgram<D>,
|
alpha_tile_program: AlphaTileProgram<D>,
|
||||||
solid_monochrome_tile_program: SolidTileMonochromeProgram<D>,
|
solid_tile_vertex_array: SolidTileVertexArray<D>,
|
||||||
alpha_monochrome_tile_program: AlphaTileMonochromeProgram<D>,
|
alpha_tile_vertex_array: AlphaTileVertexArray<D>,
|
||||||
solid_multicolor_tile_vertex_array: SolidTileVertexArray<D>,
|
|
||||||
alpha_multicolor_tile_vertex_array: AlphaTileVertexArray<D>,
|
|
||||||
solid_monochrome_tile_vertex_array: SolidTileVertexArray<D>,
|
|
||||||
alpha_monochrome_tile_vertex_array: AlphaTileVertexArray<D>,
|
|
||||||
area_lut_texture: D::Texture,
|
area_lut_texture: D::Texture,
|
||||||
quad_vertex_positions_buffer: D::Buffer,
|
quad_vertex_positions_buffer: D::Buffer,
|
||||||
quad_vertex_indices_buffer: D::Buffer,
|
quad_vertex_indices_buffer: D::Buffer,
|
||||||
|
@ -97,7 +93,7 @@ where
|
||||||
pub debug_ui_presenter: DebugUIPresenter<D>,
|
pub debug_ui_presenter: DebugUIPresenter<D>,
|
||||||
|
|
||||||
// Extra info
|
// Extra info
|
||||||
render_mode: RenderMode,
|
postprocess_options: Option<PostprocessOptions>,
|
||||||
use_depth: bool,
|
use_depth: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,10 +108,8 @@ where
|
||||||
-> Renderer<D> {
|
-> Renderer<D> {
|
||||||
let fill_program = FillProgram::new(&device, resources);
|
let fill_program = FillProgram::new(&device, resources);
|
||||||
|
|
||||||
let solid_multicolor_tile_program = SolidTileMulticolorProgram::new(&device, resources);
|
let solid_tile_program = SolidTileProgram::new(&device, resources);
|
||||||
let alpha_multicolor_tile_program = AlphaTileMulticolorProgram::new(&device, resources);
|
let alpha_tile_program = AlphaTileProgram::new(&device, resources);
|
||||||
let solid_monochrome_tile_program = SolidTileMonochromeProgram::new(&device, resources);
|
|
||||||
let alpha_monochrome_tile_program = AlphaTileMonochromeProgram::new(&device, resources);
|
|
||||||
|
|
||||||
let postprocess_program = PostprocessProgram::new(&device, resources);
|
let postprocess_program = PostprocessProgram::new(&device, resources);
|
||||||
let stencil_program = StencilProgram::new(&device, resources);
|
let stencil_program = StencilProgram::new(&device, resources);
|
||||||
|
@ -145,27 +139,15 @@ where
|
||||||
&quad_vertex_positions_buffer,
|
&quad_vertex_positions_buffer,
|
||||||
&quad_vertex_indices_buffer,
|
&quad_vertex_indices_buffer,
|
||||||
);
|
);
|
||||||
let alpha_multicolor_tile_vertex_array = AlphaTileVertexArray::new(
|
let alpha_tile_vertex_array = AlphaTileVertexArray::new(
|
||||||
&device,
|
&device,
|
||||||
&alpha_multicolor_tile_program.alpha_tile_program,
|
&alpha_tile_program,
|
||||||
&quad_vertex_positions_buffer,
|
&quad_vertex_positions_buffer,
|
||||||
&quad_vertex_indices_buffer,
|
&quad_vertex_indices_buffer,
|
||||||
);
|
);
|
||||||
let solid_multicolor_tile_vertex_array = SolidTileVertexArray::new(
|
let solid_tile_vertex_array = SolidTileVertexArray::new(
|
||||||
&device,
|
&device,
|
||||||
&solid_multicolor_tile_program.solid_tile_program,
|
&solid_tile_program,
|
||||||
&quad_vertex_positions_buffer,
|
|
||||||
&quad_vertex_indices_buffer,
|
|
||||||
);
|
|
||||||
let alpha_monochrome_tile_vertex_array = AlphaTileVertexArray::new(
|
|
||||||
&device,
|
|
||||||
&alpha_monochrome_tile_program.alpha_tile_program,
|
|
||||||
&quad_vertex_positions_buffer,
|
|
||||||
&quad_vertex_indices_buffer,
|
|
||||||
);
|
|
||||||
let solid_monochrome_tile_vertex_array = SolidTileVertexArray::new(
|
|
||||||
&device,
|
|
||||||
&solid_monochrome_tile_program.solid_tile_program,
|
|
||||||
&quad_vertex_positions_buffer,
|
&quad_vertex_positions_buffer,
|
||||||
&quad_vertex_indices_buffer,
|
&quad_vertex_indices_buffer,
|
||||||
);
|
);
|
||||||
|
@ -198,14 +180,10 @@ where
|
||||||
dest_framebuffer,
|
dest_framebuffer,
|
||||||
options,
|
options,
|
||||||
fill_program,
|
fill_program,
|
||||||
solid_monochrome_tile_program,
|
solid_tile_program,
|
||||||
alpha_monochrome_tile_program,
|
alpha_tile_program,
|
||||||
solid_multicolor_tile_program,
|
solid_tile_vertex_array,
|
||||||
alpha_multicolor_tile_program,
|
alpha_tile_vertex_array,
|
||||||
solid_monochrome_tile_vertex_array,
|
|
||||||
alpha_monochrome_tile_vertex_array,
|
|
||||||
solid_multicolor_tile_vertex_array,
|
|
||||||
alpha_multicolor_tile_vertex_array,
|
|
||||||
area_lut_texture,
|
area_lut_texture,
|
||||||
quad_vertex_positions_buffer,
|
quad_vertex_positions_buffer,
|
||||||
quad_vertex_indices_buffer,
|
quad_vertex_indices_buffer,
|
||||||
|
@ -233,7 +211,7 @@ where
|
||||||
framebuffer_flags: FramebufferFlags::empty(),
|
framebuffer_flags: FramebufferFlags::empty(),
|
||||||
buffered_fills: vec![],
|
buffered_fills: vec![],
|
||||||
|
|
||||||
render_mode: RenderMode::default(),
|
postprocess_options: None,
|
||||||
use_depth: false,
|
use_depth: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,7 +254,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn end_scene(&mut self) {
|
pub fn end_scene(&mut self) {
|
||||||
if self.postprocessing_needed() {
|
if self.postprocess_options.is_some() {
|
||||||
self.postprocess();
|
self.postprocess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,8 +321,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_render_mode(&mut self, mode: RenderMode) {
|
pub fn set_postprocess_options(&mut self, new_options: Option<PostprocessOptions>) {
|
||||||
self.render_mode = mode;
|
self.postprocess_options = new_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -368,23 +346,33 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload_paint_data(&mut self, paint_data: &PaintData) {
|
fn upload_paint_data(&mut self, paint_data: &PaintData) {
|
||||||
|
// FIXME(pcwalton): This is a hack. We shouldn't be generating paint data at all on the
|
||||||
|
// renderer side.
|
||||||
|
let (paint_size, paint_texels): (Vector2I, &[u8]);
|
||||||
|
if self.postprocess_options.is_some() {
|
||||||
|
paint_size = Vector2I::splat(1);
|
||||||
|
paint_texels = &[255; 4];
|
||||||
|
} else {
|
||||||
|
paint_size = paint_data.size;
|
||||||
|
paint_texels = &paint_data.texels;
|
||||||
|
};
|
||||||
|
|
||||||
match self.paint_texture {
|
match self.paint_texture {
|
||||||
Some(ref paint_texture) if
|
Some(ref paint_texture) if self.device.texture_size(paint_texture) == paint_size => {}
|
||||||
self.device.texture_size(paint_texture) == paint_data.size => {}
|
|
||||||
_ => {
|
_ => {
|
||||||
let texture = self.device.create_texture(TextureFormat::RGBA8, paint_data.size);
|
let texture = self.device.create_texture(TextureFormat::RGBA8, paint_size);
|
||||||
self.paint_texture = Some(texture)
|
self.paint_texture = Some(texture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.device.upload_to_texture(self.paint_texture.as_ref().unwrap(),
|
self.device.upload_to_texture(self.paint_texture.as_ref().unwrap(),
|
||||||
RectI::new(Vector2I::default(), paint_data.size),
|
RectI::new(Vector2I::default(), paint_size),
|
||||||
TextureDataRef::U8(&paint_data.texels));
|
TextureDataRef::U8(paint_texels));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload_solid_tiles(&mut self, solid_tiles: &[SolidTileBatchPrimitive]) {
|
fn upload_solid_tiles(&mut self, solid_tiles: &[SolidTileBatchPrimitive]) {
|
||||||
self.device.allocate_buffer(
|
self.device.allocate_buffer(
|
||||||
&self.solid_tile_vertex_array().vertex_buffer,
|
&self.solid_tile_vertex_array.vertex_buffer,
|
||||||
BufferData::Memory(&solid_tiles),
|
BufferData::Memory(&solid_tiles),
|
||||||
BufferTarget::Vertex,
|
BufferTarget::Vertex,
|
||||||
BufferUploadMode::Dynamic,
|
BufferUploadMode::Dynamic,
|
||||||
|
@ -393,7 +381,7 @@ where
|
||||||
|
|
||||||
fn upload_alpha_tiles(&mut self, alpha_tiles: &[AlphaTileBatchPrimitive]) {
|
fn upload_alpha_tiles(&mut self, alpha_tiles: &[AlphaTileBatchPrimitive]) {
|
||||||
self.device.allocate_buffer(
|
self.device.allocate_buffer(
|
||||||
&self.alpha_tile_vertex_array().vertex_buffer,
|
&self.alpha_tile_vertex_array.vertex_buffer,
|
||||||
BufferData::Memory(&alpha_tiles),
|
BufferData::Memory(&alpha_tiles),
|
||||||
BufferTarget::Vertex,
|
BufferTarget::Vertex,
|
||||||
BufferUploadMode::Dynamic,
|
BufferUploadMode::Dynamic,
|
||||||
|
@ -480,47 +468,32 @@ where
|
||||||
fn draw_alpha_tiles(&mut self, count: u32) {
|
fn draw_alpha_tiles(&mut self, count: u32) {
|
||||||
let clear_color = self.clear_color_for_draw_operation();
|
let clear_color = self.clear_color_for_draw_operation();
|
||||||
|
|
||||||
let alpha_tile_vertex_array = self.alpha_tile_vertex_array();
|
|
||||||
let alpha_tile_program = self.alpha_tile_program();
|
|
||||||
|
|
||||||
let mut textures = vec![self.device.framebuffer_texture(&self.mask_framebuffer)];
|
let mut textures = vec![self.device.framebuffer_texture(&self.mask_framebuffer)];
|
||||||
let mut uniforms = vec![
|
let mut uniforms = vec![
|
||||||
(&alpha_tile_program.transform_uniform,
|
(&self.alpha_tile_program.transform_uniform,
|
||||||
UniformData::Mat4(self.tile_transform().to_columns())),
|
UniformData::Mat4(self.tile_transform().to_columns())),
|
||||||
(&alpha_tile_program.tile_size_uniform,
|
(&self.alpha_tile_program.tile_size_uniform,
|
||||||
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
|
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
|
||||||
(&alpha_tile_program.stencil_texture_uniform, UniformData::TextureUnit(0)),
|
(&self.alpha_tile_program.stencil_texture_uniform, UniformData::TextureUnit(0)),
|
||||||
(&alpha_tile_program.stencil_texture_size_uniform,
|
(&self.alpha_tile_program.stencil_texture_size_uniform,
|
||||||
UniformData::Vec2(F32x2::new(MASK_FRAMEBUFFER_WIDTH as f32,
|
UniformData::Vec2(F32x2::new(MASK_FRAMEBUFFER_WIDTH as f32,
|
||||||
MASK_FRAMEBUFFER_HEIGHT as f32))),
|
MASK_FRAMEBUFFER_HEIGHT as f32))),
|
||||||
];
|
];
|
||||||
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Multicolor => {
|
|
||||||
let paint_texture = self.paint_texture.as_ref().unwrap();
|
let paint_texture = self.paint_texture.as_ref().unwrap();
|
||||||
textures.push(paint_texture);
|
textures.push(paint_texture);
|
||||||
uniforms.push((&self.alpha_multicolor_tile_program.paint_texture_uniform,
|
uniforms.push((&self.alpha_tile_program.paint_texture_uniform,
|
||||||
UniformData::TextureUnit(1)));
|
UniformData::TextureUnit(1)));
|
||||||
uniforms.push((&self.alpha_multicolor_tile_program.paint_texture_size_uniform,
|
uniforms.push((&self.alpha_tile_program.paint_texture_size_uniform,
|
||||||
UniformData::Vec2(self.device
|
UniformData::Vec2(self.device
|
||||||
.texture_size(paint_texture)
|
.texture_size(paint_texture)
|
||||||
.0
|
.0
|
||||||
.to_f32x2())));
|
.to_f32x2())));
|
||||||
}
|
|
||||||
RenderMode::Monochrome { .. } if self.postprocessing_needed() => {
|
|
||||||
uniforms.push((&self.alpha_monochrome_tile_program.color_uniform,
|
|
||||||
UniformData::Vec4(F32x4::splat(1.0))));
|
|
||||||
}
|
|
||||||
RenderMode::Monochrome { fg_color, .. } => {
|
|
||||||
uniforms.push((&self.alpha_monochrome_tile_program.color_uniform,
|
|
||||||
UniformData::Vec4(fg_color.0)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.device.draw_elements_instanced(6, count, &RenderState {
|
self.device.draw_elements_instanced(6, count, &RenderState {
|
||||||
target: &self.draw_render_target(),
|
target: &self.draw_render_target(),
|
||||||
program: &alpha_tile_program.program,
|
program: &self.alpha_tile_program.program,
|
||||||
vertex_array: &alpha_tile_vertex_array.vertex_array,
|
vertex_array: &self.alpha_tile_vertex_array.vertex_array,
|
||||||
primitive: Primitive::Triangles,
|
primitive: Primitive::Triangles,
|
||||||
textures: &textures,
|
textures: &textures,
|
||||||
uniforms: &uniforms,
|
uniforms: &uniforms,
|
||||||
|
@ -542,43 +515,25 @@ where
|
||||||
fn draw_solid_tiles(&mut self, count: u32) {
|
fn draw_solid_tiles(&mut self, count: u32) {
|
||||||
let clear_color = self.clear_color_for_draw_operation();
|
let clear_color = self.clear_color_for_draw_operation();
|
||||||
|
|
||||||
let solid_tile_vertex_array = self.solid_tile_vertex_array();
|
|
||||||
let solid_tile_program = self.solid_tile_program();
|
|
||||||
|
|
||||||
let mut textures = vec![];
|
let mut textures = vec![];
|
||||||
let mut uniforms = vec![
|
let mut uniforms = vec![
|
||||||
(&solid_tile_program.transform_uniform,
|
(&self.solid_tile_program.transform_uniform,
|
||||||
UniformData::Mat4(self.tile_transform().to_columns())),
|
UniformData::Mat4(self.tile_transform().to_columns())),
|
||||||
(&solid_tile_program.tile_size_uniform,
|
(&self.solid_tile_program.tile_size_uniform,
|
||||||
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
|
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
|
||||||
];
|
];
|
||||||
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Multicolor => {
|
|
||||||
let paint_texture = self.paint_texture.as_ref().unwrap();
|
let paint_texture = self.paint_texture.as_ref().unwrap();
|
||||||
textures.push(paint_texture);
|
textures.push(paint_texture);
|
||||||
uniforms.push((&self.solid_multicolor_tile_program.paint_texture_uniform,
|
uniforms.push((&self.solid_tile_program.paint_texture_uniform,
|
||||||
UniformData::TextureUnit(0)));
|
UniformData::TextureUnit(0)));
|
||||||
uniforms.push((&self.solid_multicolor_tile_program.paint_texture_size_uniform,
|
uniforms.push((&self.solid_tile_program.paint_texture_size_uniform,
|
||||||
UniformData::Vec2(self.device
|
UniformData::Vec2(self.device.texture_size(paint_texture).0.to_f32x2())));
|
||||||
.texture_size(paint_texture)
|
|
||||||
.0
|
|
||||||
.to_f32x2())));
|
|
||||||
}
|
|
||||||
RenderMode::Monochrome { .. } if self.postprocessing_needed() => {
|
|
||||||
uniforms.push((&self.solid_monochrome_tile_program.color_uniform,
|
|
||||||
UniformData::Vec4(F32x4::splat(1.0))));
|
|
||||||
}
|
|
||||||
RenderMode::Monochrome { fg_color, .. } => {
|
|
||||||
uniforms.push((&self.solid_monochrome_tile_program.color_uniform,
|
|
||||||
UniformData::Vec4(fg_color.0)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.device.draw_elements_instanced(6, count, &RenderState {
|
self.device.draw_elements_instanced(6, count, &RenderState {
|
||||||
target: &self.draw_render_target(),
|
target: &self.draw_render_target(),
|
||||||
program: &solid_tile_program.program,
|
program: &self.solid_tile_program.program,
|
||||||
vertex_array: &solid_tile_vertex_array.vertex_array,
|
vertex_array: &self.solid_tile_vertex_array.vertex_array,
|
||||||
primitive: Primitive::Triangles,
|
primitive: Primitive::Triangles,
|
||||||
textures: &textures,
|
textures: &textures,
|
||||||
uniforms: &uniforms,
|
uniforms: &uniforms,
|
||||||
|
@ -600,21 +555,10 @@ where
|
||||||
clear_color = self.options.background_color;
|
clear_color = self.options.background_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (fg_color, bg_color, defringing_kernel, gamma_correction_enabled);
|
let postprocess_options = match self.postprocess_options {
|
||||||
match self.render_mode {
|
None => return,
|
||||||
RenderMode::Multicolor => return,
|
Some(ref options) => options,
|
||||||
RenderMode::Monochrome {
|
};
|
||||||
fg_color: fg,
|
|
||||||
bg_color: bg,
|
|
||||||
defringing_kernel: kernel,
|
|
||||||
gamma_correction,
|
|
||||||
} => {
|
|
||||||
fg_color = fg;
|
|
||||||
bg_color = bg;
|
|
||||||
defringing_kernel = kernel;
|
|
||||||
gamma_correction_enabled = gamma_correction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let postprocess_source_framebuffer = self.postprocess_source_framebuffer.as_ref().unwrap();
|
let postprocess_source_framebuffer = self.postprocess_source_framebuffer.as_ref().unwrap();
|
||||||
let source_texture = self
|
let source_texture = self
|
||||||
|
@ -630,13 +574,15 @@ where
|
||||||
(&self.postprocess_program.source_size_uniform,
|
(&self.postprocess_program.source_size_uniform,
|
||||||
UniformData::Vec2(source_texture_size.0.to_f32x2())),
|
UniformData::Vec2(source_texture_size.0.to_f32x2())),
|
||||||
(&self.postprocess_program.gamma_lut_uniform, UniformData::TextureUnit(1)),
|
(&self.postprocess_program.gamma_lut_uniform, UniformData::TextureUnit(1)),
|
||||||
(&self.postprocess_program.fg_color_uniform, UniformData::Vec4(fg_color.0)),
|
(&self.postprocess_program.fg_color_uniform,
|
||||||
(&self.postprocess_program.bg_color_uniform, UniformData::Vec4(bg_color.0)),
|
UniformData::Vec4(postprocess_options.fg_color.0)),
|
||||||
|
(&self.postprocess_program.bg_color_uniform,
|
||||||
|
UniformData::Vec4(postprocess_options.bg_color.0)),
|
||||||
(&self.postprocess_program.gamma_correction_enabled_uniform,
|
(&self.postprocess_program.gamma_correction_enabled_uniform,
|
||||||
UniformData::Int(gamma_correction_enabled as i32)),
|
UniformData::Int(postprocess_options.gamma_correction as i32)),
|
||||||
];
|
];
|
||||||
|
|
||||||
match defringing_kernel {
|
match postprocess_options.defringing_kernel {
|
||||||
Some(ref kernel) => {
|
Some(ref kernel) => {
|
||||||
uniforms.push((&self.postprocess_program.kernel_uniform,
|
uniforms.push((&self.postprocess_program.kernel_uniform,
|
||||||
UniformData::Vec4(F32x4::from_slice(&kernel.0))));
|
UniformData::Vec4(F32x4::from_slice(&kernel.0))));
|
||||||
|
@ -664,34 +610,6 @@ where
|
||||||
self.framebuffer_flags.insert(FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS);
|
self.framebuffer_flags.insert(FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solid_tile_program(&self) -> &SolidTileProgram<D> {
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Monochrome { .. } => &self.solid_monochrome_tile_program.solid_tile_program,
|
|
||||||
RenderMode::Multicolor => &self.solid_multicolor_tile_program.solid_tile_program,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn alpha_tile_program(&self) -> &AlphaTileProgram<D> {
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Monochrome { .. } => &self.alpha_monochrome_tile_program.alpha_tile_program,
|
|
||||||
RenderMode::Multicolor => &self.alpha_multicolor_tile_program.alpha_tile_program,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn solid_tile_vertex_array(&self) -> &SolidTileVertexArray<D> {
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Monochrome { .. } => &self.solid_monochrome_tile_vertex_array,
|
|
||||||
RenderMode::Multicolor => &self.solid_multicolor_tile_vertex_array,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn alpha_tile_vertex_array(&self) -> &AlphaTileVertexArray<D> {
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Monochrome { .. } => &self.alpha_monochrome_tile_vertex_array,
|
|
||||||
RenderMode::Multicolor => &self.alpha_multicolor_tile_vertex_array,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_stencil(&mut self, quad_positions: &[Vector4F]) {
|
fn draw_stencil(&mut self, quad_positions: &[Vector4F]) {
|
||||||
self.device.allocate_buffer(
|
self.device.allocate_buffer(
|
||||||
&self.stencil_vertex_array.vertex_buffer,
|
&self.stencil_vertex_array.vertex_buffer,
|
||||||
|
@ -774,7 +692,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_render_target(&self) -> RenderTarget<D> {
|
pub fn draw_render_target(&self) -> RenderTarget<D> {
|
||||||
if self.postprocessing_needed() {
|
if self.postprocess_options.is_some() {
|
||||||
RenderTarget::Framebuffer(self.postprocess_source_framebuffer.as_ref().unwrap())
|
RenderTarget::Framebuffer(self.postprocess_source_framebuffer.as_ref().unwrap())
|
||||||
} else {
|
} else {
|
||||||
self.dest_render_target()
|
self.dest_render_target()
|
||||||
|
@ -789,7 +707,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_postprocessing_framebuffer(&mut self) {
|
fn init_postprocessing_framebuffer(&mut self) {
|
||||||
if !self.postprocessing_needed() {
|
if !self.postprocess_options.is_some() {
|
||||||
self.postprocess_source_framebuffer = None;
|
self.postprocess_source_framebuffer = None;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -822,17 +740,6 @@ where
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn postprocessing_needed(&self) -> bool {
|
|
||||||
match self.render_mode {
|
|
||||||
RenderMode::Monochrome {
|
|
||||||
ref defringing_kernel,
|
|
||||||
gamma_correction,
|
|
||||||
..
|
|
||||||
} => defringing_kernel.is_some() || gamma_correction,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stencil_state(&self) -> Option<StencilState> {
|
fn stencil_state(&self) -> Option<StencilState> {
|
||||||
if !self.use_depth {
|
if !self.use_depth {
|
||||||
return None;
|
return None;
|
||||||
|
@ -847,7 +754,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_color_for_draw_operation(&mut self) -> Option<ColorF> {
|
fn clear_color_for_draw_operation(&mut self) -> Option<ColorF> {
|
||||||
let postprocessing_needed = self.postprocessing_needed();
|
let postprocessing_needed = self.postprocess_options.is_some();
|
||||||
let flag = if postprocessing_needed {
|
let flag = if postprocessing_needed {
|
||||||
FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS
|
FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS
|
||||||
} else {
|
} else {
|
||||||
|
@ -864,7 +771,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preserve_draw_framebuffer(&mut self) {
|
fn preserve_draw_framebuffer(&mut self) {
|
||||||
let flag = if self.postprocessing_needed() {
|
let flag = if self.postprocess_options.is_some() {
|
||||||
FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS
|
FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS
|
||||||
} else {
|
} else {
|
||||||
FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS
|
FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS
|
||||||
|
@ -874,13 +781,9 @@ where
|
||||||
|
|
||||||
pub fn draw_viewport(&self) -> RectI {
|
pub fn draw_viewport(&self) -> RectI {
|
||||||
let main_viewport = self.main_viewport();
|
let main_viewport = self.main_viewport();
|
||||||
match self.render_mode {
|
match self.postprocess_options {
|
||||||
RenderMode::Monochrome {
|
Some(PostprocessOptions { defringing_kernel: Some(_), .. }) => {
|
||||||
defringing_kernel: Some(..),
|
RectI::new(Vector2I::default(), main_viewport.size().scale_xy(Vector2I::new(3, 1)))
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let scale = Vector2I::new(3, 1);
|
|
||||||
RectI::new(Vector2I::default(), main_viewport.size().scale_xy(scale))
|
|
||||||
}
|
}
|
||||||
_ => main_viewport,
|
_ => main_viewport,
|
||||||
}
|
}
|
||||||
|
@ -1208,166 +1111,62 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SolidTileProgram<D>
|
struct SolidTileProgram<D> where D: Device {
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
program: D::Program,
|
program: D::Program,
|
||||||
transform_uniform: D::Uniform,
|
transform_uniform: D::Uniform,
|
||||||
tile_size_uniform: D::Uniform,
|
tile_size_uniform: D::Uniform,
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> SolidTileProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
fn new(device: &D, program_name: &str, resources: &dyn ResourceLoader) -> SolidTileProgram<D> {
|
|
||||||
let program = device.create_program_from_shader_names(
|
|
||||||
resources,
|
|
||||||
program_name,
|
|
||||||
program_name,
|
|
||||||
"tile_solid",
|
|
||||||
);
|
|
||||||
let transform_uniform = device.get_uniform(&program, "Transform");
|
|
||||||
let tile_size_uniform = device.get_uniform(&program, "TileSize");
|
|
||||||
SolidTileProgram { program, transform_uniform, tile_size_uniform }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SolidTileMulticolorProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
solid_tile_program: SolidTileProgram<D>,
|
|
||||||
paint_texture_uniform: D::Uniform,
|
paint_texture_uniform: D::Uniform,
|
||||||
paint_texture_size_uniform: D::Uniform,
|
paint_texture_size_uniform: D::Uniform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D> SolidTileMulticolorProgram<D>
|
impl<D> SolidTileProgram<D> where D: Device {
|
||||||
where
|
fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileProgram<D> {
|
||||||
D: Device,
|
let program = device.create_program(resources, "tile_solid");
|
||||||
{
|
let transform_uniform = device.get_uniform(&program, "Transform");
|
||||||
fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileMulticolorProgram<D> {
|
let tile_size_uniform = device.get_uniform(&program, "TileSize");
|
||||||
let solid_tile_program = SolidTileProgram::new(device, "tile_solid_multicolor", resources);
|
let paint_texture_uniform = device.get_uniform(&program, "PaintTexture");
|
||||||
let paint_texture_uniform = device.get_uniform(&solid_tile_program.program,
|
let paint_texture_size_uniform = device.get_uniform(&program, "PaintTextureSize");
|
||||||
"PaintTexture");
|
SolidTileProgram {
|
||||||
let paint_texture_size_uniform = device.get_uniform(&solid_tile_program.program,
|
program,
|
||||||
"PaintTextureSize");
|
transform_uniform,
|
||||||
SolidTileMulticolorProgram {
|
tile_size_uniform,
|
||||||
solid_tile_program,
|
|
||||||
paint_texture_uniform,
|
paint_texture_uniform,
|
||||||
paint_texture_size_uniform,
|
paint_texture_size_uniform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SolidTileMonochromeProgram<D>
|
struct AlphaTileProgram<D> where D: Device {
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
solid_tile_program: SolidTileProgram<D>,
|
|
||||||
color_uniform: D::Uniform,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> SolidTileMonochromeProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileMonochromeProgram<D> {
|
|
||||||
let solid_tile_program = SolidTileProgram::new(device, "tile_solid_monochrome", resources);
|
|
||||||
let color_uniform = device.get_uniform(&solid_tile_program.program, "Color");
|
|
||||||
SolidTileMonochromeProgram {
|
|
||||||
solid_tile_program,
|
|
||||||
color_uniform,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AlphaTileProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
program: D::Program,
|
program: D::Program,
|
||||||
transform_uniform: D::Uniform,
|
transform_uniform: D::Uniform,
|
||||||
tile_size_uniform: D::Uniform,
|
tile_size_uniform: D::Uniform,
|
||||||
stencil_texture_uniform: D::Uniform,
|
stencil_texture_uniform: D::Uniform,
|
||||||
stencil_texture_size_uniform: D::Uniform,
|
stencil_texture_size_uniform: D::Uniform,
|
||||||
|
paint_texture_uniform: D::Uniform,
|
||||||
|
paint_texture_size_uniform: D::Uniform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D> AlphaTileProgram<D>
|
impl<D> AlphaTileProgram<D> where D: Device {
|
||||||
where
|
fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileProgram<D> {
|
||||||
D: Device,
|
let program = device.create_program(resources, "tile_alpha");
|
||||||
{
|
|
||||||
fn new(device: &D, program_name: &str, resources: &dyn ResourceLoader) -> AlphaTileProgram<D> {
|
|
||||||
let program = device.create_program_from_shader_names(
|
|
||||||
resources,
|
|
||||||
program_name,
|
|
||||||
program_name,
|
|
||||||
"tile_alpha",
|
|
||||||
);
|
|
||||||
let transform_uniform = device.get_uniform(&program, "Transform");
|
let transform_uniform = device.get_uniform(&program, "Transform");
|
||||||
let tile_size_uniform = device.get_uniform(&program, "TileSize");
|
let tile_size_uniform = device.get_uniform(&program, "TileSize");
|
||||||
let stencil_texture_uniform = device.get_uniform(&program, "StencilTexture");
|
let stencil_texture_uniform = device.get_uniform(&program, "StencilTexture");
|
||||||
let stencil_texture_size_uniform = device.get_uniform(&program, "StencilTextureSize");
|
let stencil_texture_size_uniform = device.get_uniform(&program, "StencilTextureSize");
|
||||||
|
let paint_texture_uniform = device.get_uniform(&program, "PaintTexture");
|
||||||
|
let paint_texture_size_uniform = device.get_uniform(&program, "PaintTextureSize");
|
||||||
AlphaTileProgram {
|
AlphaTileProgram {
|
||||||
program,
|
program,
|
||||||
transform_uniform,
|
transform_uniform,
|
||||||
tile_size_uniform,
|
tile_size_uniform,
|
||||||
stencil_texture_uniform,
|
stencil_texture_uniform,
|
||||||
stencil_texture_size_uniform,
|
stencil_texture_size_uniform,
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AlphaTileMulticolorProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
alpha_tile_program: AlphaTileProgram<D>,
|
|
||||||
paint_texture_uniform: D::Uniform,
|
|
||||||
paint_texture_size_uniform: D::Uniform,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> AlphaTileMulticolorProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileMulticolorProgram<D> {
|
|
||||||
let alpha_tile_program = AlphaTileProgram::new(device, "tile_alpha_multicolor", resources);
|
|
||||||
let paint_texture_uniform =
|
|
||||||
device.get_uniform(&alpha_tile_program.program, "PaintTexture");
|
|
||||||
let paint_texture_size_uniform =
|
|
||||||
device.get_uniform(&alpha_tile_program.program, "PaintTextureSize");
|
|
||||||
AlphaTileMulticolorProgram {
|
|
||||||
alpha_tile_program,
|
|
||||||
paint_texture_uniform,
|
paint_texture_uniform,
|
||||||
paint_texture_size_uniform,
|
paint_texture_size_uniform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AlphaTileMonochromeProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
alpha_tile_program: AlphaTileProgram<D>,
|
|
||||||
color_uniform: D::Uniform,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> AlphaTileMonochromeProgram<D>
|
|
||||||
where
|
|
||||||
D: Device,
|
|
||||||
{
|
|
||||||
fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileMonochromeProgram<D> {
|
|
||||||
let alpha_tile_program = AlphaTileProgram::new(device, "tile_alpha_monochrome", resources);
|
|
||||||
let color_uniform = device.get_uniform(&alpha_tile_program.program, "Color");
|
|
||||||
AlphaTileMonochromeProgram {
|
|
||||||
alpha_tile_program,
|
|
||||||
color_uniform,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PostprocessProgram<D>
|
struct PostprocessProgram<D>
|
||||||
where
|
where
|
||||||
D: Device,
|
D: Device,
|
||||||
|
@ -1567,22 +1366,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Default)]
|
||||||
pub enum RenderMode {
|
pub struct PostprocessOptions {
|
||||||
Multicolor,
|
pub fg_color: ColorF,
|
||||||
Monochrome {
|
pub bg_color: ColorF,
|
||||||
fg_color: ColorF,
|
pub defringing_kernel: Option<DefringingKernel>,
|
||||||
bg_color: ColorF,
|
pub gamma_correction: bool,
|
||||||
defringing_kernel: Option<DefringingKernel>,
|
|
||||||
gamma_correction: bool,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RenderMode {
|
|
||||||
#[inline]
|
|
||||||
fn default() -> RenderMode {
|
|
||||||
RenderMode::Multicolor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
|
|
|
@ -25,7 +25,6 @@ pub mod scene;
|
||||||
|
|
||||||
mod allocator;
|
mod allocator;
|
||||||
mod builder;
|
mod builder;
|
||||||
mod sorted_vector;
|
|
||||||
mod tile_map;
|
mod tile_map;
|
||||||
mod tiles;
|
mod tiles;
|
||||||
mod z_buffer;
|
mod z_buffer;
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
use crate::builder::SceneBuilder;
|
use crate::builder::SceneBuilder;
|
||||||
use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive};
|
use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive};
|
||||||
use crate::paint::PaintMetadata;
|
use crate::paint::PaintMetadata;
|
||||||
use crate::sorted_vector::SortedVector;
|
use pathfinder_content::outline::{Contour, Outline, PointIndex};
|
||||||
|
use pathfinder_content::segment::Segment;
|
||||||
|
use pathfinder_content::sorted_vector::SortedVector;
|
||||||
use pathfinder_geometry::line_segment::LineSegment2F;
|
use pathfinder_geometry::line_segment::LineSegment2F;
|
||||||
use pathfinder_geometry::vector::{Vector2F, Vector2I};
|
use pathfinder_geometry::vector::{Vector2F, Vector2I};
|
||||||
use pathfinder_geometry::rect::{RectF, RectI};
|
use pathfinder_geometry::rect::{RectF, RectI};
|
||||||
use pathfinder_content::outline::{Contour, Outline, PointIndex};
|
|
||||||
use pathfinder_content::segment::Segment;
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,19 @@
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
uniform sampler2D uStencilTexture;
|
uniform sampler2D uStencilTexture;
|
||||||
|
uniform sampler2D uPaintTexture;
|
||||||
|
uniform vec2 uPaintTextureSize;
|
||||||
|
|
||||||
in vec2 vTexCoord;
|
in vec2 vMaskTexCoord;
|
||||||
|
in vec2 vColorTexCoord;
|
||||||
in float vBackdrop;
|
in float vBackdrop;
|
||||||
in vec4 vColor;
|
in vec4 vColor;
|
||||||
|
|
||||||
out vec4 oFragColor;
|
out vec4 oFragColor;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
float coverage = abs(texture(uStencilTexture, vTexCoord). r + vBackdrop);
|
float coverage = abs(texture(uStencilTexture, vMaskTexCoord). r + vBackdrop);
|
||||||
oFragColor = vec4(vColor . rgb, vColor . a * coverage);
|
vec4 color = texture(uPaintTexture, vColorTexCoord);
|
||||||
|
oFragColor = vec4(color . rgb, color . a * coverage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#version {{version}}
|
||||||
|
// Automatically generated from files in pathfinder/shaders/. Do not edit!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
uniform mat4 uTransform;
|
||||||
|
uniform vec2 uTileSize;
|
||||||
|
uniform vec2 uStencilTextureSize;
|
||||||
|
|
||||||
|
in uvec2 aTessCoord;
|
||||||
|
in uvec3 aTileOrigin;
|
||||||
|
in vec2 aColorTexCoord;
|
||||||
|
in int aBackdrop;
|
||||||
|
in int aTileIndex;
|
||||||
|
|
||||||
|
out vec2 vMaskTexCoord;
|
||||||
|
out vec2 vColorTexCoord;
|
||||||
|
out float vBackdrop;
|
||||||
|
|
||||||
|
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){
|
||||||
|
uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x);
|
||||||
|
uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
|
||||||
|
return vec2(tileOffset)* uTileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0;
|
||||||
|
vec2 position =(origin + vec2(aTessCoord))* uTileSize;
|
||||||
|
vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize . x);
|
||||||
|
vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize;
|
||||||
|
|
||||||
|
vMaskTexCoord = maskTexCoord / uStencilTextureSize;
|
||||||
|
vColorTexCoord = aColorTexCoord;
|
||||||
|
vBackdrop = float(aBackdrop);
|
||||||
|
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
|
@ -14,11 +14,14 @@
|
||||||
|
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
in vec4 vColor;
|
uniform sampler2D uPaintTexture;
|
||||||
|
uniform vec2 uPaintTextureSize;
|
||||||
|
|
||||||
|
in vec2 vColorTexCoord;
|
||||||
|
|
||||||
out vec4 oFragColor;
|
out vec4 oFragColor;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
oFragColor = vColor;
|
oFragColor = texture(uPaintTexture, vColorTexCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
#version {{version}}
|
||||||
|
// Automatically generated from files in pathfinder/shaders/. Do not edit!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
|
uniform mat4 uTransform;
|
||||||
|
uniform vec2 uTileSize;
|
||||||
|
|
||||||
|
in uvec2 aTessCoord;
|
||||||
|
in ivec2 aTileOrigin;
|
||||||
|
in vec2 aColorTexCoord;
|
||||||
|
|
||||||
|
out vec2 vColorTexCoord;
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
vec2 position = vec2(aTileOrigin + ivec2(aTessCoord))* uTileSize;
|
||||||
|
vColorTexCoord = aColorTexCoord;
|
||||||
|
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ struct spvDescriptorSetBuffer0
|
||||||
{
|
{
|
||||||
texture2d<float> uStencilTexture [[id(0)]];
|
texture2d<float> uStencilTexture [[id(0)]];
|
||||||
sampler uStencilTextureSmplr [[id(1)]];
|
sampler uStencilTextureSmplr [[id(1)]];
|
||||||
|
texture2d<float> uPaintTexture [[id(2)]];
|
||||||
|
sampler uPaintTextureSmplr [[id(3)]];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct main0_out
|
struct main0_out
|
||||||
|
@ -17,16 +19,17 @@ struct main0_out
|
||||||
|
|
||||||
struct main0_in
|
struct main0_in
|
||||||
{
|
{
|
||||||
float2 vTexCoord [[user(locn0)]];
|
float2 vMaskTexCoord [[user(locn0)]];
|
||||||
float vBackdrop [[user(locn1)]];
|
float2 vColorTexCoord [[user(locn1)]];
|
||||||
float4 vColor [[user(locn2)]];
|
float vBackdrop [[user(locn2)]];
|
||||||
};
|
};
|
||||||
|
|
||||||
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
|
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
|
||||||
{
|
{
|
||||||
main0_out out = {};
|
main0_out out = {};
|
||||||
float coverage = abs(spvDescriptorSet0.uStencilTexture.sample(spvDescriptorSet0.uStencilTextureSmplr, in.vTexCoord).x + in.vBackdrop);
|
float coverage = abs(spvDescriptorSet0.uStencilTexture.sample(spvDescriptorSet0.uStencilTextureSmplr, in.vMaskTexCoord).x + in.vBackdrop);
|
||||||
out.oFragColor = float4(in.vColor.xyz, in.vColor.w * coverage);
|
float4 color = spvDescriptorSet0.uPaintTexture.sample(spvDescriptorSet0.uPaintTextureSmplr, in.vColorTexCoord);
|
||||||
|
out.oFragColor = float4(color.xyz, color.w * coverage);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
// Automatically generated from files in pathfinder/shaders/. Do not edit!
|
||||||
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||||
|
|
||||||
|
#include <metal_stdlib>
|
||||||
|
#include <simd/simd.h>
|
||||||
|
|
||||||
|
using namespace metal;
|
||||||
|
|
||||||
|
struct spvDescriptorSetBuffer0
|
||||||
|
{
|
||||||
|
constant float2* uTileSize [[id(0)]];
|
||||||
|
constant float2* uStencilTextureSize [[id(1)]];
|
||||||
|
constant float4x4* uTransform [[id(2)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct main0_out
|
||||||
|
{
|
||||||
|
float2 vMaskTexCoord [[user(locn0)]];
|
||||||
|
float2 vColorTexCoord [[user(locn1)]];
|
||||||
|
float vBackdrop [[user(locn2)]];
|
||||||
|
float4 gl_Position [[position]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct main0_in
|
||||||
|
{
|
||||||
|
uint2 aTessCoord [[attribute(0)]];
|
||||||
|
uint3 aTileOrigin [[attribute(1)]];
|
||||||
|
float2 aColorTexCoord [[attribute(2)]];
|
||||||
|
int aBackdrop [[attribute(3)]];
|
||||||
|
int aTileIndex [[attribute(4)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
float2 computeTileOffset(thread const uint& tileIndex, thread const float& stencilTextureWidth, thread float2 uTileSize)
|
||||||
|
{
|
||||||
|
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
|
||||||
|
uint2 tileOffset = uint2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
|
||||||
|
return float2(tileOffset) * uTileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
|
||||||
|
{
|
||||||
|
main0_out out = {};
|
||||||
|
float2 origin = float2(in.aTileOrigin.xy) + (float2(float(in.aTileOrigin.z & 15u), float(in.aTileOrigin.z >> 4u)) * 256.0);
|
||||||
|
float2 position = (origin + float2(in.aTessCoord)) * (*spvDescriptorSet0.uTileSize);
|
||||||
|
uint param = uint(in.aTileIndex);
|
||||||
|
float param_1 = (*spvDescriptorSet0.uStencilTextureSize).x;
|
||||||
|
float2 maskTexCoordOrigin = computeTileOffset(param, param_1, (*spvDescriptorSet0.uTileSize));
|
||||||
|
float2 maskTexCoord = maskTexCoordOrigin + (float2(in.aTessCoord) * (*spvDescriptorSet0.uTileSize));
|
||||||
|
out.vMaskTexCoord = maskTexCoord / (*spvDescriptorSet0.uStencilTextureSize);
|
||||||
|
out.vColorTexCoord = in.aColorTexCoord;
|
||||||
|
out.vBackdrop = float(in.aBackdrop);
|
||||||
|
out.gl_Position = (*spvDescriptorSet0.uTransform) * float4(position, 0.0, 1.0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,12 @@
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
|
|
||||||
|
struct spvDescriptorSetBuffer0
|
||||||
|
{
|
||||||
|
texture2d<float> uPaintTexture [[id(0)]];
|
||||||
|
sampler uPaintTextureSmplr [[id(1)]];
|
||||||
|
};
|
||||||
|
|
||||||
struct main0_out
|
struct main0_out
|
||||||
{
|
{
|
||||||
float4 oFragColor [[color(0)]];
|
float4 oFragColor [[color(0)]];
|
||||||
|
@ -11,13 +17,13 @@ struct main0_out
|
||||||
|
|
||||||
struct main0_in
|
struct main0_in
|
||||||
{
|
{
|
||||||
float4 vColor [[user(locn0)]];
|
float2 vColorTexCoord [[user(locn0)]];
|
||||||
};
|
};
|
||||||
|
|
||||||
fragment main0_out main0(main0_in in [[stage_in]])
|
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
|
||||||
{
|
{
|
||||||
main0_out out = {};
|
main0_out out = {};
|
||||||
out.oFragColor = in.vColor;
|
out.oFragColor = spvDescriptorSet0.uPaintTexture.sample(spvDescriptorSet0.uPaintTextureSmplr, in.vColorTexCoord);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Automatically generated from files in pathfinder/shaders/. Do not edit!
|
||||||
|
#include <metal_stdlib>
|
||||||
|
#include <simd/simd.h>
|
||||||
|
|
||||||
|
using namespace metal;
|
||||||
|
|
||||||
|
struct spvDescriptorSetBuffer0
|
||||||
|
{
|
||||||
|
constant float2* uTileSize [[id(0)]];
|
||||||
|
constant float4x4* uTransform [[id(1)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct main0_out
|
||||||
|
{
|
||||||
|
float2 vColorTexCoord [[user(locn0)]];
|
||||||
|
float4 gl_Position [[position]];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct main0_in
|
||||||
|
{
|
||||||
|
uint2 aTessCoord [[attribute(0)]];
|
||||||
|
int2 aTileOrigin [[attribute(1)]];
|
||||||
|
float2 aColorTexCoord [[attribute(2)]];
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
|
||||||
|
{
|
||||||
|
main0_out out = {};
|
||||||
|
float2 position = float2(in.aTileOrigin + int2(in.aTessCoord)) * (*spvDescriptorSet0.uTileSize);
|
||||||
|
out.vColorTexCoord = in.aColorTexCoord;
|
||||||
|
out.gl_Position = (*spvDescriptorSet0.uTransform) * float4(position, 0.0, 1.0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
|
@ -18,20 +18,14 @@ SHADERS=\
|
||||||
stencil.fs.glsl \
|
stencil.fs.glsl \
|
||||||
stencil.vs.glsl \
|
stencil.vs.glsl \
|
||||||
tile_alpha.fs.glsl \
|
tile_alpha.fs.glsl \
|
||||||
tile_alpha_monochrome.vs.glsl \
|
tile_alpha.vs.glsl \
|
||||||
tile_alpha_multicolor.vs.glsl \
|
|
||||||
tile_solid.fs.glsl \
|
tile_solid.fs.glsl \
|
||||||
tile_solid_monochrome.vs.glsl \
|
tile_solid.vs.glsl \
|
||||||
tile_solid_multicolor.vs.glsl \
|
|
||||||
$(EMPTY)
|
$(EMPTY)
|
||||||
|
|
||||||
INCLUDES=\
|
INCLUDES=\
|
||||||
post_convolve.inc.glsl \
|
post_convolve.inc.glsl \
|
||||||
tile_alpha_vertex.inc.glsl \
|
|
||||||
tile_multicolor.inc.glsl \
|
|
||||||
post_gamma_correct.inc.glsl \
|
post_gamma_correct.inc.glsl \
|
||||||
tile_monochrome.inc.glsl \
|
|
||||||
tile_solid_vertex.inc.glsl \
|
|
||||||
$(EMPTY)
|
$(EMPTY)
|
||||||
|
|
||||||
OUT=\
|
OUT=\
|
||||||
|
|
|
@ -13,14 +13,18 @@
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
uniform sampler2D uStencilTexture;
|
uniform sampler2D uStencilTexture;
|
||||||
|
uniform sampler2D uPaintTexture;
|
||||||
|
uniform vec2 uPaintTextureSize;
|
||||||
|
|
||||||
in vec2 vTexCoord;
|
in vec2 vMaskTexCoord;
|
||||||
|
in vec2 vColorTexCoord;
|
||||||
in float vBackdrop;
|
in float vBackdrop;
|
||||||
in vec4 vColor;
|
in vec4 vColor;
|
||||||
|
|
||||||
out vec4 oFragColor;
|
out vec4 oFragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float coverage = abs(texture(uStencilTexture, vTexCoord).r + vBackdrop);
|
float coverage = abs(texture(uStencilTexture, vMaskTexCoord).r + vBackdrop);
|
||||||
oFragColor = vec4(vColor.rgb, vColor.a * coverage);
|
vec4 color = texture(uPaintTexture, vColorTexCoord);
|
||||||
|
oFragColor = vec4(color.rgb, color.a * coverage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// pathfinder/shaders/tile_alpha_vertex.inc.glsl
|
#version 330
|
||||||
|
|
||||||
|
// pathfinder/shaders/tile_alpha.vs.glsl
|
||||||
//
|
//
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
// Copyright © 2020 The Pathfinder Project Developers.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
@ -8,20 +10,21 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
uniform mat4 uTransform;
|
uniform mat4 uTransform;
|
||||||
uniform vec2 uTileSize;
|
uniform vec2 uTileSize;
|
||||||
uniform vec2 uStencilTextureSize;
|
uniform vec2 uStencilTextureSize;
|
||||||
|
|
||||||
in uvec2 aTessCoord;
|
in uvec2 aTessCoord;
|
||||||
in uvec3 aTileOrigin;
|
in uvec3 aTileOrigin;
|
||||||
|
in vec2 aColorTexCoord;
|
||||||
in int aBackdrop;
|
in int aBackdrop;
|
||||||
in int aTileIndex;
|
in int aTileIndex;
|
||||||
|
|
||||||
out vec2 vTexCoord;
|
out vec2 vMaskTexCoord;
|
||||||
|
out vec2 vColorTexCoord;
|
||||||
out float vBackdrop;
|
out float vBackdrop;
|
||||||
out vec4 vColor;
|
|
||||||
|
|
||||||
vec4 getColor();
|
|
||||||
|
|
||||||
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) {
|
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) {
|
||||||
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
|
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
|
||||||
|
@ -29,15 +32,14 @@ vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) {
|
||||||
return vec2(tileOffset) * uTileSize;
|
return vec2(tileOffset) * uTileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void computeVaryings() {
|
void main() {
|
||||||
vec2 origin = vec2(aTileOrigin.xy) + vec2(aTileOrigin.z & 15u, aTileOrigin.z >> 4u) * 256.0;
|
vec2 origin = vec2(aTileOrigin.xy) + vec2(aTileOrigin.z & 15u, aTileOrigin.z >> 4u) * 256.0;
|
||||||
vec2 position = (origin + vec2(aTessCoord)) * uTileSize;
|
vec2 position = (origin + vec2(aTessCoord)) * uTileSize;
|
||||||
vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize.x);
|
vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize.x);
|
||||||
vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize;
|
vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize;
|
||||||
|
|
||||||
vTexCoord = maskTexCoord / uStencilTextureSize;
|
vMaskTexCoord = maskTexCoord / uStencilTextureSize;
|
||||||
|
vColorTexCoord = aColorTexCoord;
|
||||||
vBackdrop = float(aBackdrop);
|
vBackdrop = float(aBackdrop);
|
||||||
vColor = getColor();
|
|
||||||
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
#version 330
|
|
||||||
|
|
||||||
// pathfinder/shaders/tile_alpha_monochrome.vs.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
|
||||||
|
|
||||||
precision highp float;
|
|
||||||
|
|
||||||
#include "tile_alpha_vertex.inc.glsl"
|
|
||||||
#include "tile_monochrome.inc.glsl"
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
computeVaryings();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
#version 330
|
|
||||||
|
|
||||||
// pathfinder/shaders/tile_alpha_multicolor.vs.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
|
||||||
|
|
||||||
precision highp float;
|
|
||||||
|
|
||||||
#include "tile_alpha_vertex.inc.glsl"
|
|
||||||
#include "tile_multicolor.inc.glsl"
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
computeVaryings();
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
// pathfinder/shaders/tile_monochrome.inc.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
uniform vec4 uColor;
|
|
||||||
|
|
||||||
vec4 getColor() {
|
|
||||||
return uColor;
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
// pathfinder/shaders/tile_multicolor.inc.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
uniform sampler2D uPaintTexture;
|
|
||||||
uniform vec2 uPaintTextureSize;
|
|
||||||
|
|
||||||
in vec2 aColorTexCoord;
|
|
||||||
|
|
||||||
vec4 getColor() {
|
|
||||||
return texture(uPaintTexture, aColorTexCoord);
|
|
||||||
}
|
|
|
@ -12,10 +12,13 @@
|
||||||
|
|
||||||
precision highp float;
|
precision highp float;
|
||||||
|
|
||||||
in vec4 vColor;
|
uniform sampler2D uPaintTexture;
|
||||||
|
uniform vec2 uPaintTextureSize;
|
||||||
|
|
||||||
|
in vec2 vColorTexCoord;
|
||||||
|
|
||||||
out vec4 oFragColor;
|
out vec4 oFragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
oFragColor = vColor;
|
oFragColor = texture(uPaintTexture, vColorTexCoord);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// pathfinder/shaders/tile_solid_vertex.inc.glsl
|
#version 330
|
||||||
|
|
||||||
|
// pathfinder/shaders/tile_solid.vs.glsl
|
||||||
//
|
//
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
// Copyright © 2019 The Pathfinder Project Developers.
|
||||||
//
|
//
|
||||||
|
@ -8,18 +10,19 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
|
||||||
uniform mat4 uTransform;
|
uniform mat4 uTransform;
|
||||||
uniform vec2 uTileSize;
|
uniform vec2 uTileSize;
|
||||||
|
|
||||||
in uvec2 aTessCoord;
|
in uvec2 aTessCoord;
|
||||||
in ivec2 aTileOrigin;
|
in ivec2 aTileOrigin;
|
||||||
|
in vec2 aColorTexCoord;
|
||||||
|
|
||||||
out vec4 vColor;
|
out vec2 vColorTexCoord;
|
||||||
|
|
||||||
vec4 getColor();
|
void main() {
|
||||||
|
|
||||||
void computeVaryings() {
|
|
||||||
vec2 position = vec2(aTileOrigin + ivec2(aTessCoord)) * uTileSize;
|
vec2 position = vec2(aTileOrigin + ivec2(aTessCoord)) * uTileSize;
|
||||||
vColor = getColor();
|
vColorTexCoord = aColorTexCoord;
|
||||||
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
gl_Position = uTransform * vec4(position, 0.0, 1.0);
|
||||||
}
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
#version 330
|
|
||||||
|
|
||||||
// pathfinder/shaders/tile_solid_monochrome.vs.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
|
||||||
|
|
||||||
precision highp float;
|
|
||||||
|
|
||||||
#include "tile_solid_vertex.inc.glsl"
|
|
||||||
#include "tile_monochrome.inc.glsl"
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
computeVaryings();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
#version 330
|
|
||||||
|
|
||||||
// pathfinder/shaders/tile_solid_multicolor.vs.glsl
|
|
||||||
//
|
|
||||||
// Copyright © 2019 The Pathfinder Project Developers.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#extension GL_GOOGLE_include_directive : enable
|
|
||||||
|
|
||||||
precision highp float;
|
|
||||||
|
|
||||||
#include "tile_solid_vertex.inc.glsl"
|
|
||||||
#include "tile_multicolor.inc.glsl"
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
computeVaryings();
|
|
||||||
}
|
|
Loading…
Reference in New Issue