Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could I write customized shader for SWGL? #4257

Open
kaiwk opened this issue Feb 9, 2021 · 6 comments
Open

Could I write customized shader for SWGL? #4257

kaiwk opened this issue Feb 9, 2021 · 6 comments

Comments

@kaiwk
Copy link

kaiwk commented Feb 9, 2021

When use OpenGL, I can create shader like below:

mod shaders {
...
    pub static VERT_SHADER: &'static [u8] = b"#version 330 core

layout (location = 0) in vec3 position;

void main()
{
    gl_Position = vec4(position.x, position.y, position.z, 1.0);
}
\0";
...
}

...
    let vert_shader = gl.create_shader(gl::VERTEX_SHADER);
    gl.shader_source(vert_shader, &[shaders::VERT_SHADER]);
    gl.compile_shader(vert_shader);
...
    let program = gl.create_program();
    gl.attach_shader(program, vert_shader);
    gl.link_program(program);
    gl.use_program(program);

How to do that with swgl? Seems like swgl have its own syntax?

@kvark
Copy link
Member

kvark commented Feb 9, 2021

IIRC, SWGL translates our GLSL sources, so you should be able to have your custom shaders, as long as they do roughly the same or similar things to the existing shaders (or otherwise you might hit limitations of the implementation).

@kaiwk
Copy link
Author

kaiwk commented Feb 10, 2021

I can see prefix // shader: is used for debug, but if // shader: missing, shader_source will panic.

@kvark
Copy link
Member

kvark commented Feb 11, 2021

It was added for debugging purposes, and then SWGL decided to piggy back on it without adjusting the comment.
Maybe @lsalzman can chime in.

@kaiwk
Copy link
Author

kaiwk commented Feb 19, 2021

I can see that SWGL use glsl-to-cxx translating glsl to C/C++. It happens during compiling, and I thought I can translate glsl during runtime.

Maybe I can specify the shader_dir to my own directory.

@kaiwk
Copy link
Author

kaiwk commented Apr 3, 2021

I tried put the customized glsl in res directory, looks like SWGL doesn't support some new OpenGL API. I also find a bug of SWGL, see: #4325

@lsalzman
Copy link
Contributor

lsalzman commented Apr 5, 2021

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1703069 to fix this

We can close this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants