Crates.io | glsl_compiler |
lib.rs | glsl_compiler |
version | 0.1.2 |
source | src |
created_at | 2024-11-07 18:22:52.858238 |
updated_at | 2024-11-22 00:05:50.055891 |
description | Write GLSL Code directly in a marco! |
homepage | |
repository | https://github.com/MaartenBehn/glsl_compiler |
max_upload_size | |
id | 1440032 |
size | 22,756 |
Write GLSL Code directly in a marco!
Finally, it's possible to write GLSL directly in Rust.
let bin_shader_code: &[u8] = glsl!{type = Compute, code = {
#version 450 core
layout(binding = 0, rgba8) uniform writeonly image2D img;
void main () {
uvec2 pos = gl_GlobalInvocationID.xy;
vec4 color = vec4(pos, 0.0, 1.0);
imageStore(img, ivec2(pos), color);
}
}};
let bin_shader_code: &[u8] = &[3, 2, 35, 7, 0, 0, 1, 0, 11, 0, 13, 0, 36, ...];
Mark shader type with type = <shader type>
in marco.
Possible types
glsl!{type = Compute, code = {
#version 450 core
void main () {
uvec2 pos = gl_GlobalInvocationID.xy;
vec4 color = vec4(pos, 0.0, 1.0);
imageStore(img, ivec2(pos), colo);
}
}};
error: undeclared identifier
|
13 | imageStore(img, ivec2(pos), colo);
| ^^^
error: undeclared identifier
|
13 | imageStore(img, ivec2(pos), colo);
| ^^^^
error: no matching overloaded function found
|
13 | imageStore(img, ivec2(pos), colo);
| ^^^^^^^^^^
let bin: &[u8] = glsl!{type = Compute, file = "shaders/test.glsl"};
Example Glsl File Name: "shaders/included.glsl"
let bin: &[u8] = glsl!{type = Compute, code = {
#version 450 core
#include "shaders/included.glsl"
layout(binding = 0, rgba8) uniform writeonly image2D img;
void main () {
uvec2 pos = gl_GlobalInvocationID.xy;
imageStore(img, ivec2(pos), COLOR);
}
}};
Example Rust File Name: "src/main.rs"
fn shader() {
let bin: &[u8] = glsl!{type = Compute, code = {
#version 450 core
#include "src/main.rs-included.glsl"
layout(binding = 0, rgba8) uniform writeonly image2D img;
void main () {
uvec2 pos = gl_GlobalInvocationID.xy;
imageStore(img, ivec2(pos), COLOR);
}
}};
println!("{:?}", bin)
}
#[allow(dead_code)]
fn included() {
glsl!{type = Include, name = "included.glsl", code = {
#define COLOR vec4(pos, 0.0, 1.0)
}};
}