Hey Guys,
i’ve developed a pre compiler for OpenGL Shader Code, called ShaderFile. With the ShaderFile Project you be able to manage large shader code and produce a simple and small output file. The generated code is normally interpreted, compiled and linked by an OpenGL shader object.
a short overview over the most important commands and features:
- as known from the normal pre compiler you can use if commands to add another path to the code generation
- using the include command, you can spread your code over more than one file
- with the class command you can define a class like strukture to manage your shader code; within a class you can overwrite member methods from base classes
- you can define properties which values are set inside the application code to control the shader code generation
- and much more…
The project is written in FPC. It can be used directly in your FPC project or as shared library. The shared library is available for Windows and Linux as 32bit and 64bit binary. The library also includes header files for C, C++, FPC and Delphi.
a simple example for a class:
{$CLASS Color}
{$PROPERTY UseColorMap 'false'}
{$END}
{$CLASS ColorFrag $EXTENDS Color}
/* you can also define code here. It will be added when the code for the class is generated */
{$FUNC 'vec4' GetColor $INLINE}
{$IF UseColorMap}
{$VAR 'vec2' '_texCoord' 'gl_TexCoord[0].st'}
{$UNIFORM 'sampler2D' 'uColorMap'}
return texture2D(uColorMap, _texCoord);
{$ELSE}
return gl_Color;
{$END}
{$END}
{$MAIN}
gl_FragColor = {$CALL GetColor};
{$END}
{$END}
{$CLASS ColorVert $EXTENDS Color}
{$MAIN}
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
{$IF UseColorMap}
gl_TexCoord[0] = gl_MultiTexCoord0;
{$ELSE}
gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
{$END}
{$END}
{$END}
resulting code for ColorFrag with UseColorMap = true:
/* you can also define code here. It will be added when the code for the class is generated */
uniform sampler2D uColorMap;
vec2 _texCoord = gl_TexCoord[0].st;
void main(void)
{
gl_FragColor = (texture2D(uColorMap, _texCoord));
}
Unfortunately i can not add any links to this post. So if you are interested in this project please contact me or reply to this post.
Greetings Bergmann89.