mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-24 11:58:32 +00:00
Commit shaders so they don't need to be missing on non-Windows platforms
This commit is contained in:
parent
b97bb58a56
commit
fdc8a6a4e2
@ -21,7 +21,6 @@ travis-ci = { repository = "Gekkio/imgui-rs" }
|
|||||||
gfx = "0.18"
|
gfx = "0.18"
|
||||||
imgui = { version = "0.0.24-pre", path = "../" }
|
imgui = { version = "0.0.24-pre", path = "../" }
|
||||||
imgui-sys = { version = "0.0.24-pre", path = "../imgui-sys", features = ["gfx"] }
|
imgui-sys = { version = "0.0.24-pre", path = "../imgui-sys", features = ["gfx"] }
|
||||||
cfg-if = "0.1"
|
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winapi = { version = "0.3", features = ["d3dcompiler"] }
|
winapi = { version = "0.3", features = ["d3dcompiler"] }
|
||||||
|
|||||||
@ -1,34 +1,41 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
hlsl_build::compile_hlsl_shaders();
|
{
|
||||||
|
// Note: When building on Windows, this build script will automatically recompile the HLSL shaders.
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
let src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("src");
|
||||||
|
|
||||||
|
hlsl_build::update_hlsl_shaders(
|
||||||
|
&src_dir.join("shader").join("sm_40.hlsl"),
|
||||||
|
&src_dir.join("data").join("vertex.fx"),
|
||||||
|
&src_dir.join("data").join("pixel.fx"),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod hlsl_build {
|
mod hlsl_build {
|
||||||
use std::env;
|
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
pub fn compile_hlsl_shaders() {
|
pub fn update_hlsl_shaders(
|
||||||
let source_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
|
source_path: &Path,
|
||||||
.join("src")
|
vertex_destination: &Path,
|
||||||
.join("shader")
|
pixel_destination: &Path,
|
||||||
.join("sm_40.hlsl");
|
) {
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed={}", source_path.display());
|
println!("cargo:rerun-if-changed={}", source_path.display());
|
||||||
|
|
||||||
let src_data = fs::read_to_string(&source_path).unwrap();
|
let src_data = fs::read_to_string(&source_path).unwrap();
|
||||||
|
|
||||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
||||||
|
|
||||||
fs::write(
|
fs::write(
|
||||||
out_dir.join("hlsl_vertex_shader_bytecode"),
|
vertex_destination,
|
||||||
compile_shader(&src_data, &source_path, "VertexMain", "vs_4_0").unwrap_or_else(
|
compile_shader(&src_data, &source_path, "VertexMain", "vs_4_0").unwrap_or_else(
|
||||||
|error_message| {
|
|error_message| {
|
||||||
eprintln!("{}", error_message);
|
eprintln!("{}", error_message);
|
||||||
@ -39,7 +46,7 @@ mod hlsl_build {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
fs::write(
|
fs::write(
|
||||||
out_dir.join("hlsl_pixel_shader_bytecode"),
|
pixel_destination,
|
||||||
compile_shader(&src_data, &source_path, "PixelMain", "ps_4_0").unwrap_or_else(
|
compile_shader(&src_data, &source_path, "PixelMain", "ps_4_0").unwrap_or_else(
|
||||||
|error_message| {
|
|error_message| {
|
||||||
eprintln!("{}", error_message);
|
eprintln!("{}", error_message);
|
||||||
|
|||||||
BIN
imgui-gfx-renderer/src/data/pixel.fx
Normal file
BIN
imgui-gfx-renderer/src/data/pixel.fx
Normal file
Binary file not shown.
BIN
imgui-gfx-renderer/src/data/vertex.fx
Normal file
BIN
imgui-gfx-renderer/src/data/vertex.fx
Normal file
Binary file not shown.
@ -167,21 +167,10 @@ impl Shaders {
|
|||||||
include_bytes!("shader/glsles_100.vert"),
|
include_bytes!("shader/glsles_100.vert"),
|
||||||
include_bytes!("shader/glsles_100.frag"),
|
include_bytes!("shader/glsles_100.frag"),
|
||||||
),
|
),
|
||||||
HlslSm40 => {
|
HlslSm40 => (
|
||||||
cfg_if::cfg_if! {
|
include_bytes!("data/pixel.fx"),
|
||||||
if #[cfg(all(feature = "directx", windows))] {
|
include_bytes!("data/vertex.fx"),
|
||||||
const HLSL_BYTECODE: (&[u8], &[u8]) = (
|
),
|
||||||
include_bytes!(concat!(env!("OUT_DIR"), "/hlsl_vertex_shader_bytecode")),
|
|
||||||
include_bytes!(concat!(env!("OUT_DIR"), "/hlsl_pixel_shader_bytecode")),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// panic instead?
|
|
||||||
const HLSL_BYTECODE: (&[u8], &[u8]) = (&[0], &[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HLSL_BYTECODE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
cbuffer Constants : register(b0) {
|
cbuffer Constants : register(b0) {
|
||||||
float4x4 matrix_;
|
float4x4 matrix_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D tex;
|
Texture2D tex;
|
||||||
SamplerState tex_;
|
SamplerState tex_;
|
||||||
|
|
||||||
struct VIn {
|
struct VIn {
|
||||||
float2 position : pos;
|
float2 position : pos;
|
||||||
float2 uv : uv;
|
float2 uv : uv;
|
||||||
float4 color : col;
|
float4 color : col;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VOut
|
struct VOut
|
||||||
@ -30,5 +30,5 @@ VOut VertexMain(VIn vertex)
|
|||||||
|
|
||||||
float4 PixelMain(VOut vout) : SV_TARGET
|
float4 PixelMain(VOut vout) : SV_TARGET
|
||||||
{
|
{
|
||||||
return vout.color * tex.Sample(tex_, vout.uv);
|
return vout.color * tex.Sample(tex_, vout.uv);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user