PDA

View Full Version : shader related problem



laggyluk
20-10-2014, 02:02 PM
This is not really shader thing bu't I'm facing this in shader related context :P
I need to load shader from file and be able to use it's uniforms without hardcoding (at least so much as possible).
to update the uniform I need to know it's type to use proper GL call from dglOpenGL.pas
for example updating mat4 needs glUniformMatrix4fv and updating a vec3 needs glUniform3fv.
Is it possible to keep and read this procedure name from file with shader definition?
for example:



<shader vert="default" frag="default" >
<layouts>
<layout location="0" type="vec4" name="position" />
</layouts>
<uniforms>
<uniform name="color" type="vec4" method="glUniform4fv" update="frame" editorVisible="true"/>
</uniforms>
</shader>

where 'method' property holds the 'update method' name. I know that I could use the 'type' with milion ifs to choose proper one but it's not something i'd like to do.
Another problem is calling this method later. Different methods have different 'footprint' so I can't really declare a single method type like this:

TUniformMehodFv = procedure(location: GLint; count: GLsizei; transpose: GLboolean; value: PGLfloat); {$IFDEF DGL_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}this would compile for few methods with same parameter count and type.

So how do you guys do it in your engines? We gonna need shader managment in PGDCE too at some point so maybe we can start talking about it?

Mirage
23-10-2014, 07:35 PM
I'd not to put information about an implementation of renderer into shader storage format.
My vision:
Renderer has a part of it which manages the uniforms.
Shader contains information which uniforms it needs. Position, matrix, etc. Renderer knows that say "position" is 3d vector and "MVP" is 4x4 matrix. And renderer also knows where to get the corresponding value and with which routine to bind it.
So even uniform name is enough for binding.
If a uniform is not a standard one, i.e. renderer doesn't know what it is, there should be a special handler for THIS shader (lets call it Effect) which knows it.
Actually, effect (if exists) queried first, than checked for standard list and if no match an error is raised.