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

Load external shader file at compile time via @:glFragmentSourceFile and @:glVertexSourceFile #2597

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

giuppe
Copy link
Contributor

@giuppe giuppe commented Oct 25, 2022

This PR adds a way to load an external file to be used as a shader (fragment or vertex).

Usage:

class MyShader extends Shader
{
// ...
@:glFragmentSourceFile("./shaders/myShader.frag")
// ...
}

This could help separate the actual GLSL code from its OpenFL management. Most IDEs can correctly highlight/format the syntax of an external shader file, while long strings (as the @:glFragmentSource() argument) are usually rendered as a uniform color and must be formatted by hand; so this could be a nice quality of life change.

This PR is changing the ShaderMacro.build() function so that:

  • it would check for the metas glFragmentSourceFile, :glFragmentSourceFile, glVertexSourceFile, and :glVertexSourceFile;
  • if one of the metas is found and the argument file exists, its content will be set as the glFragmentSource/glVertexSource, overriding the @:glFragmentSource/@:glVertexSource argument (if defined).
  • if the file does not exist or cannot be read, an error is returned at compile time.

@T1mL3arn
Copy link
Contributor

Completely and totally upvote this. Why is it still not merged?

@giuppe giuppe changed the title Load external shader file via @:glFragmentSourceFile and @:glVertexSourceFile Load external shader file at compile time via @:glFragmentSourceFile and @:glVertexSourceFile Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants