Remove the rustache dependency.

1/3 reduction in binary size for `canvas_minimal`.

Closes #158.
This commit is contained in:
Patrick Walton 2019-05-26 13:02:52 -07:00
parent e04cc273ee
commit bc713a5181
10 changed files with 73 additions and 164 deletions

102
Cargo.lock generated
View File

@ -5,14 +5,6 @@ name = "adler32"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "aho-corasick"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "aho-corasick"
version = "0.7.3"
@ -851,15 +843,6 @@ dependencies = [
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "khronos"
version = "0.1.2"
@ -983,14 +966,6 @@ dependencies = [
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.2.0"
@ -1251,7 +1226,6 @@ dependencies = [
"pathfinder_gpu 0.1.0",
"pathfinder_renderer 0.1.0",
"pathfinder_simd 0.3.0",
"rustache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1261,7 +1235,6 @@ dependencies = [
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pathfinder_geometry 0.3.0",
"pathfinder_simd 0.3.0",
"rustache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1599,18 +1572,6 @@ dependencies = [
"redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "0.1.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.1.6"
@ -1623,11 +1584,6 @@ dependencies = [
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "regex-syntax"
version = "0.6.6"
@ -1644,25 +1600,11 @@ dependencies = [
"xmlparser 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustache"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -1963,23 +1905,6 @@ dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread-id"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.6"
@ -2048,11 +1973,6 @@ dependencies = [
"unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "utf8-ranges"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "utf8-ranges"
version = "1.0.2"
@ -2137,11 +2057,6 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.7"
@ -2151,11 +2066,6 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@ -2240,7 +2150,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c"
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c"
"checksum andrew 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9b7f09f89872c2b6b29e319377b1fbe91c6f5947df19a25596e121cf19a7b35e"
"checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407"
@ -2326,7 +2235,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum jni 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "294eca097d1dc0bf59de5ab9f7eafa5f77129e9f6464c957ed3ddeb705fb4292"
"checksum jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
"checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum khronos 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c0711aaa80e6ba6eb1fa8978f1f46bfcb38ceb2f3f33f3736efbff39dac89f50"
"checksum khronos_api 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "037ab472c33f67b5fbd3e9163a2645319e5356fcd355efa6d4eb7fff4bbcb554"
"checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
@ -2343,7 +2251,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum lyon_path 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e9dc8e0746b7cca11960b602f7fe037bb067746a01eab4aa502fed1494544843"
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
@ -2394,14 +2301,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96"
"checksum roxmltree 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "02660467d0c2da1b6276042501aee6e15ec5b8ff59423243f185b294cd53acf3"
"checksum rustache 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c86de9443c1a5618e0d51bbd8eb6227ead9916446eb8952575a70d1ef7e00209"
"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusttype 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "25951e85bb2647960969f72c559392245a5bd07446a589390bf427dda31cdc4a"
"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f"
@ -2437,8 +2340,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
@ -2448,7 +2349,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum usvg 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ebf4d5244ba2e8305caf9de7949377794ecdea5a9e3c84fc5610d78d21f5ee"
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
@ -2459,9 +2359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum wayland-protocols 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ccddf6a4407d982898e0f0a1172217843f3d40fe4272f828060b56a2d40d81"
"checksum wayland-scanner 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "63bc5efa7dcdb8f04d2e5d1571c0d0577fc47076d133d68e056bdb299f1b60e2"
"checksum wayland-sys 0.21.12 (registry+https://github.com/rust-lang/crates.io-index)" = "e76af81a601b84d400744f85f083381daa77ac01f6c8711e57e662dc3a35d69d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -9,7 +9,6 @@ crate-type = ["rlib", "staticlib"]
[dependencies]
gl = "0.6"
rustache = "0.1"
[dependencies.image]
version = "0.21"

View File

@ -16,14 +16,13 @@ extern crate log;
use gl::types::{GLboolean, GLchar, GLenum, GLfloat, GLint, GLsizei, GLsizeiptr, GLuint, GLvoid};
use pathfinder_geometry::basic::point::Point2DI32;
use pathfinder_geometry::basic::rect::RectI32;
use pathfinder_gpu::resources::ResourceLoader;
use pathfinder_gpu::{BlendState, BufferData, BufferTarget, BufferUploadMode, ClearParams};
use pathfinder_gpu::{DepthFunc, Device, Primitive, RenderState, ShaderKind, StencilFunc};
use pathfinder_gpu::{TextureFormat, UniformData, VertexAttrClass};
use pathfinder_gpu::{VertexAttrDescriptor, VertexAttrType};
use pathfinder_simd::default::F32x4;
use rustache::{HashBuilder, Render};
use std::ffi::CString;
use std::io::Cursor;
use std::mem;
use std::ptr;
use std::str;
@ -223,18 +222,18 @@ impl Device for GLDevice {
}
fn create_shader_from_source(&self,
resources: &dyn ResourceLoader,
name: &str,
source: &[u8],
kind: ShaderKind,
mut template_input: HashBuilder)
includes: &[&str])
-> GLShader {
// FIXME(pcwalton): Do this once and cache it.
let glsl_version_spec = self.version.to_glsl_version_spec();
template_input = template_input.insert("version", glsl_version_spec);
let mut output = Cursor::new(vec![]);
template_input.render(str::from_utf8(source).unwrap(), &mut output).unwrap();
let source = output.into_inner();
let mut output = vec![];
self.preprocess(&mut output, resources, source, includes, glsl_version_spec);
let source = output;
let gl_shader_kind = match kind {
ShaderKind::Vertex => gl::VERTEX_SHADER,
@ -268,6 +267,7 @@ impl Device for GLDevice {
}
fn create_program_from_shaders(&self,
resources: &dyn ResourceLoader,
name: &str,
vertex_shader: GLShader,
fragment_shader: GLShader)
@ -644,6 +644,41 @@ impl Device for GLDevice {
}
}
impl GLDevice {
fn preprocess(&self,
output: &mut Vec<u8>,
resources: &dyn ResourceLoader,
source: &[u8],
includes: &[&str],
version: &str) {
let mut index = 0;
while index < source.len() {
if source[index..].starts_with(b"{{") {
let end_index = source[index..].iter()
.position(|character| *character == b'}')
.expect("Expected `}`!") + index;
assert_eq!(source[end_index + 1], b'}');
let ident = String::from_utf8_lossy(&source[(index + 2)..end_index]);
if ident == "version" {
output.extend_from_slice(version.as_bytes());
} else if ident.starts_with("include_") {
let include_name = &ident["include_".len()..];
if includes.iter().any(|include| *include == include_name) {
let include_source = self.load_shader_include(resources, include_name);
self.preprocess(output, resources, &include_source, includes, version);
}
} else {
panic!("unknown template variable: `{}`", ident);
}
index = end_index + 2;
} else {
output.push(source[index]);
index += 1;
}
}
}
}
pub struct GLVertexArray {
pub gl_vertex_array: GLuint,
}
@ -891,3 +926,5 @@ fn ck() {
#[cfg(not(debug))]
fn ck() {}
// Shader preprocessing

View File

@ -5,7 +5,6 @@ authors = ["Patrick Walton <pcwalton@mimiga.net>"]
edition = "2018"
[dependencies]
rustache = "0.1"
[dependencies.image]
version = "0.21"

View File

@ -17,11 +17,19 @@ use pathfinder_geometry::basic::rect::RectI32;
use pathfinder_geometry::basic::transform3d::Transform3DF32;
use pathfinder_geometry::color::ColorF;
use pathfinder_simd::default::F32x4;
use rustache::HashBuilder;
use std::time::Duration;
pub mod resources;
static INCLUDES: [&str; 6] = [
"tile_alpha_vertex",
"tile_monochrome",
"tile_multicolor",
"tile_solid_vertex",
"post_convolve",
"post_gamma_correct",
];
pub trait Device {
type Buffer;
type Framebuffer;
@ -37,14 +45,16 @@ pub trait Device {
fn create_texture_from_data(&self, size: Point2DI32, data: &[u8]) -> Self::Texture;
fn create_shader_from_source(
&self,
resources: &dyn ResourceLoader,
name: &str,
source: &[u8],
kind: ShaderKind,
template_input: HashBuilder,
includes: &[&str],
) -> Self::Shader;
fn create_vertex_array(&self) -> Self::VertexArray;
fn create_program_from_shaders(
&self,
resources: &dyn ResourceLoader,
name: &str,
vertex_shader: Self::Shader,
fragment_shader: Self::Shader,
@ -109,39 +119,8 @@ pub trait Device {
ShaderKind::Vertex => 'v',
ShaderKind::Fragment => 'f',
};
let source = resources
.slurp(&format!("shaders/{}.{}s.glsl", name, suffix))
.unwrap();
let mut load_include_tile_alpha_vertex =
|_| load_shader_include(resources, "tile_alpha_vertex");
let mut load_include_tile_monochrome =
|_| load_shader_include(resources, "tile_monochrome");
let mut load_include_tile_multicolor =
|_| load_shader_include(resources, "tile_multicolor");
let mut load_include_tile_solid_vertex =
|_| load_shader_include(resources, "tile_solid_vertex");
let mut load_include_post_convolve = |_| load_shader_include(resources, "post_convolve");
let mut load_include_post_gamma_correct =
|_| load_shader_include(resources, "post_gamma_correct");
let template_input = HashBuilder::new()
.insert_lambda(
"include_tile_alpha_vertex",
&mut load_include_tile_alpha_vertex,
)
.insert_lambda("include_tile_monochrome", &mut load_include_tile_monochrome)
.insert_lambda("include_tile_multicolor", &mut load_include_tile_multicolor)
.insert_lambda(
"include_tile_solid_vertex",
&mut load_include_tile_solid_vertex,
)
.insert_lambda("include_post_convolve", &mut load_include_post_convolve)
.insert_lambda(
"include_post_gamma_correct",
&mut load_include_post_gamma_correct,
);
self.create_shader_from_source(name, &source, kind, template_input)
let source = resources.slurp(&format!("shaders/{}.{}s.glsl", name, suffix)).unwrap();
self.create_shader_from_source(resources, name, &source, kind, &INCLUDES)
}
fn create_program_from_shader_names(
@ -154,12 +133,16 @@ pub trait Device {
let vertex_shader = self.create_shader(resources, vertex_shader_name, ShaderKind::Vertex);
let fragment_shader =
self.create_shader(resources, fragment_shader_name, ShaderKind::Fragment);
self.create_program_from_shaders(program_name, vertex_shader, fragment_shader)
self.create_program_from_shaders(resources, program_name, vertex_shader, fragment_shader)
}
fn create_program(&self, resources: &dyn ResourceLoader, name: &str) -> Self::Program {
self.create_program_from_shader_names(resources, name, name, name)
}
fn load_shader_include(&self, resources: &dyn ResourceLoader, include_name: &str) -> Vec<u8> {
resources.slurp(&format!("shaders/{}.inc.glsl", include_name)).unwrap()
}
}
#[derive(Clone, Copy, Debug)]
@ -338,10 +321,3 @@ pub enum VertexAttrClass {
FloatNorm,
Int,
}
fn load_shader_include(resources: &dyn ResourceLoader, include_name: &str) -> String {
let resource = resources
.slurp(&format!("shaders/{}.inc.glsl", include_name))
.unwrap();
String::from_utf8_lossy(&resource).to_string()
}

View File

@ -25,8 +25,8 @@ in vec2 vTexCoord;
out vec4 oFragColor;
{{{include_post_gamma_correct}}}
{{{include_post_convolve}}}
{{include_post_gamma_correct}}
{{include_post_convolve}}
// Convolve horizontally in this pass.
float sample1Tap(float offset) {

View File

@ -12,8 +12,8 @@
precision highp float;
{{{include_tile_alpha_vertex}}}
{{{include_tile_monochrome}}}
{{include_tile_alpha_vertex}}
{{include_tile_monochrome}}
void main() {
computeVaryings();

View File

@ -12,8 +12,8 @@
precision highp float;
{{{include_tile_alpha_vertex}}}
{{{include_tile_multicolor}}}
{{include_tile_alpha_vertex}}
{{include_tile_multicolor}}
void main() {
computeVaryings();

View File

@ -12,8 +12,8 @@
precision highp float;
{{{include_tile_solid_vertex}}}
{{{include_tile_monochrome}}}
{{include_tile_solid_vertex}}
{{include_tile_monochrome}}
void main() {
computeVaryings();

View File

@ -12,8 +12,8 @@
precision highp float;
{{{include_tile_solid_vertex}}}
{{{include_tile_multicolor}}}
{{include_tile_solid_vertex}}
{{include_tile_multicolor}}
void main() {
computeVaryings();