Move u_globals to shared included file

Former-commit-id: b6122177ce98cd52bc032e2d8414671d3bcb9b5c
This commit is contained in:
robojumper 2019-05-12 11:10:13 +02:00
parent 95a0c27d7d
commit ee9f54bacd
13 changed files with 64 additions and 114 deletions

8
Cargo.lock generated
View File

@ -906,11 +906,11 @@ dependencies = [
[[package]] [[package]]
name = "glsl-include" name = "glsl-include"
version = "0.2.3" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -2361,7 +2361,7 @@ dependencies = [
"gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_device_gl 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_device_gl 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_window_glutin 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_window_glutin 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glsl-include 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
"guillotiere 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "guillotiere 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2680,7 +2680,7 @@ dependencies = [
"checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5" "checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"
"checksum glib 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "81f514a8abd315ede0e94e39ce5987fdb99191c5f812e5066bc5bdb965104fc4" "checksum glib 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "81f514a8abd315ede0e94e39ce5987fdb99191c5f812e5066bc5bdb965104fc4"
"checksum glib-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8826cbc94631507bdd91ee40f7e099bfaa3cc4f43c086b4d1c15cff5b4e8220b" "checksum glib-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8826cbc94631507bdd91ee40f7e099bfaa3cc4f43c086b4d1c15cff5b4e8220b"
"checksum glsl-include 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31c109a006ad24fd612da10d185b51000ef502155578f3634416f102f0d63b6c" "checksum glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "daa2afb1631e7ab4543e0dde0e3fc68bb49c58fee89c07f30a26553b1f684ab6"
"checksum glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "535c6eda58adbb227604b2db10a022ffd6339d7ea3e970f338e7d98aeb24fcc3" "checksum glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "535c6eda58adbb227604b2db10a022ffd6339d7ea3e970f338e7d98aeb24fcc3"
"checksum gobject-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "87373f64e136e9ea192ff5d3ef676a51e9ac6ab06b629223a081e0523c5f04e2" "checksum gobject-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "87373f64e136e9ea192ff5d3ef676a51e9ac6ab06b629223a081e0523c5f04e2"
"checksum gtk 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78d69fb7425fd6efba3b0c99f952b130fa4a0fdfdffbceb2b40ba018b2ed6a77" "checksum gtk 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78d69fb7425fd6efba3b0c99f952b130fa4a0fdfdffbceb2b40ba018b2ed6a77"

View File

@ -31,7 +31,7 @@ specs = "0.14"
vek = "0.9" vek = "0.9"
# Utility # Utility
glsl-include = "0.2" glsl-include = "0.3"
failure = "0.1" failure = "0.1"
lazy_static = "1.1" lazy_static = "1.1"
log = "0.4" log = "0.4"

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 f_pos; in vec3 f_pos;
in vec3 f_norm; in vec3 f_norm;
in vec3 f_col; in vec3 f_col;
@ -10,18 +12,6 @@ uniform u_locals {
mat4 model_mat; mat4 model_mat;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
struct BoneData { struct BoneData {
mat4 bone_mat; mat4 bone_mat;
}; };

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 v_pos; in vec3 v_pos;
in vec3 v_norm; in vec3 v_norm;
in vec3 v_col; in vec3 v_col;
@ -10,18 +12,6 @@ uniform u_locals {
mat4 model_mat; mat4 model_mat;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
struct BoneData { struct BoneData {
mat4 bone_mat; mat4 bone_mat;
}; };

View File

@ -0,0 +1,11 @@
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
uniform sampler2D src_color; uniform sampler2D src_color;
in vec2 f_pos; in vec2 f_pos;
@ -9,18 +11,6 @@ uniform u_locals {
vec4 nul; vec4 nul;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec4 tgt_color; out vec4 tgt_color;
/** /**

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec2 v_pos; in vec2 v_pos;
layout (std140) layout (std140)
@ -7,18 +9,6 @@ uniform u_locals {
vec4 nul; vec4 nul;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec2 f_pos; out vec2 f_pos;
void main() { void main() {

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 f_pos; in vec3 f_pos;
layout (std140) layout (std140)
@ -7,18 +9,6 @@ uniform u_locals {
vec4 nul; vec4 nul;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec4 tgt_color; out vec4 tgt_color;
const float PI = 3.141592; const float PI = 3.141592;

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 v_pos; in vec3 v_pos;
layout (std140) layout (std140)
@ -7,18 +9,6 @@ uniform u_locals {
vec4 nul; vec4 nul;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec3 f_pos; out vec3 f_pos;
void main() { void main() {

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 f_pos; in vec3 f_pos;
in vec3 f_norm; in vec3 f_norm;
in vec3 f_col; in vec3 f_col;
@ -9,18 +11,6 @@ uniform u_locals {
vec3 model_offs; vec3 model_offs;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec4 tgt_color; out vec4 tgt_color;
void main() { void main() {

View File

@ -1,5 +1,7 @@
#version 330 core #version 330 core
#include <globals.glsl>
in vec3 v_pos; in vec3 v_pos;
in vec3 v_norm; in vec3 v_norm;
in vec3 v_col; in vec3 v_col;
@ -9,18 +11,6 @@ uniform u_locals {
vec3 model_offs; vec3 model_offs;
}; };
layout (std140)
uniform u_globals {
mat4 view_mat;
mat4 proj_mat;
vec4 cam_pos;
vec4 focus_pos;
vec4 view_distance;
vec4 time_of_day;
vec4 tick;
vec4 screen_res;
};
out vec3 f_pos; out vec3 f_pos;
out vec3 f_norm; out vec3 f_norm;
out vec3 f_col; out vec3 f_col;

View File

@ -41,6 +41,7 @@ pub enum RenderError {
TexUpdateError(gfx::UpdateError<[u16; 3]>), TexUpdateError(gfx::UpdateError<[u16; 3]>),
CombinedError(gfx::CombinedError), CombinedError(gfx::CombinedError),
BufferCreationError(gfx::buffer::CreationError), BufferCreationError(gfx::buffer::CreationError),
IncludeError(glsl_include::Error),
} }
/// Used to represent a specific rendering configuration. /// Used to represent a specific rendering configuration.

View File

@ -12,6 +12,7 @@ use gfx::{
handle::Sampler, handle::Sampler,
traits::{Device, Factory, FactoryExt}, traits::{Device, Factory, FactoryExt},
}; };
use glsl_include::Context as IncludeContext;
use vek::*; use vek::*;
/// Represents the format of the pre-processed color target. /// Represents the format of the pre-processed color target.
@ -74,50 +75,63 @@ impl Renderer {
win_color_view: WinColorView, win_color_view: WinColorView,
win_depth_view: WinDepthView, win_depth_view: WinDepthView,
) -> Result<Self, RenderError> { ) -> Result<Self, RenderError> {
let globals = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/shaders/include/globals.glsl"
));
let mut include_ctx = IncludeContext::new();
include_ctx.include("globals.glsl", globals);
// Construct a pipeline for rendering skyboxes // Construct a pipeline for rendering skyboxes
let skybox_pipeline = create_pipeline( let skybox_pipeline = create_pipeline(
&mut factory, &mut factory,
skybox::pipe::new(), skybox::pipe::new(),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.vert")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.vert")),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.frag")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.frag")),
&include_ctx,
)?; )?;
// Construct a pipeline for rendering figures // Construct a pipeline for rendering figures
let figure_pipeline = create_pipeline( let figure_pipeline = create_pipeline(
&mut factory, &mut factory,
figure::pipe::new(), figure::pipe::new(),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.vert")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.vert")),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.frag")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.frag")),
&include_ctx,
)?; )?;
// Construct a pipeline for rendering terrain // Construct a pipeline for rendering terrain
let terrain_pipeline = create_pipeline( let terrain_pipeline = create_pipeline(
&mut factory, &mut factory,
terrain::pipe::new(), terrain::pipe::new(),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.vert")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.vert")),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.frag")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.frag")),
&include_ctx,
)?; )?;
// Construct a pipeline for rendering UI elements // Construct a pipeline for rendering UI elements
let ui_pipeline = create_pipeline( let ui_pipeline = create_pipeline(
&mut factory, &mut factory,
ui::pipe::new(), ui::pipe::new(),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.vert")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.vert")),
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.frag")), include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.frag")),
&include_ctx,
)?; )?;
// Construct a pipeline for rendering our post-processing // Construct a pipeline for rendering our post-processing
let postprocess_pipeline = create_pipeline( let postprocess_pipeline = create_pipeline(
&mut factory, &mut factory,
postprocess::pipe::new(), postprocess::pipe::new(),
include_bytes!(concat!( include_str!(concat!(
env!("CARGO_MANIFEST_DIR"), env!("CARGO_MANIFEST_DIR"),
"/shaders/postprocess.vert" "/shaders/postprocess.vert"
)), )),
include_bytes!(concat!( include_str!(concat!(
env!("CARGO_MANIFEST_DIR"), env!("CARGO_MANIFEST_DIR"),
"/shaders/postprocess.frag" "/shaders/postprocess.frag"
)), )),
&include_ctx,
)?; )?;
let dims = win_color_view.get_dimensions(); let dims = win_color_view.get_dimensions();
@ -407,11 +421,15 @@ struct GfxPipeline<P: gfx::pso::PipelineInit> {
fn create_pipeline<'a, P: gfx::pso::PipelineInit>( fn create_pipeline<'a, P: gfx::pso::PipelineInit>(
factory: &mut gfx_backend::Factory, factory: &mut gfx_backend::Factory,
pipe: P, pipe: P,
vs: &[u8], vs: &str,
fs: &[u8], fs: &str,
ctx: &IncludeContext,
) -> Result<GfxPipeline<P>, RenderError> { ) -> Result<GfxPipeline<P>, RenderError> {
let vs = ctx.expand(vs).map_err(RenderError::IncludeError)?;
let fs = ctx.expand(fs).map_err(RenderError::IncludeError)?;
let program = factory let program = factory
.link_program(vs, fs) .link_program(vs.as_bytes(), fs.as_bytes())
.map_err(|err| RenderError::PipelineError(gfx::PipelineStateError::Program(err)))?; .map_err(|err| RenderError::PipelineError(gfx::PipelineStateError::Program(err)))?;
Ok(GfxPipeline { Ok(GfxPipeline {