magic-lang / ooc-kean

ooc port of parts of Kean.
MIT License
6 stars 30 forks source link

Text replacement instead of ESSL macros #838

Open davidpiuva opened 8 years ago

davidpiuva commented 8 years ago

Having to change macros that are hardcoded in shader code makes it hard to separate settings from code. It would be cleaner to insert text replacements together with the shader code when creating a shader. We already have the replaceAll function as used in DateTime. Giving the input argument Replacement new("<DEBUG>", debugFlag toString()) into the shader's constructor would let each occurence of <DEBUG> be replaced by the value of debugFlag.

davidpiuva commented 8 years ago

@emilwestergren Does this sound good enough or do you have a better idea?

emilwestergren commented 8 years ago

Sounds good, do we want a general Replacement structure or a specialized just for flags?

OpenGLMap new(frag, vert, VectorList<ShaderFlag>)
davidpiuva commented 8 years ago

I have quite a lot of integers that would allow being both fast and flexible with any data type.

emilwestergren commented 8 years ago

I see, are you replacing the uploads of constants?

davidpiuva commented 8 years ago

Some of the uniform integers could be more efficient that way by rolling loops in compile time. The same blur shader could be compiled for each radius for unrolling.

emilwestergren commented 8 years ago

I agree but then again it sounds like a minor optimization. Should this be prioritized at the moment?

davidpiuva commented 8 years ago

It is not a priority right now but in the long run, this could increase our productivity when testing the contrast by having all settings on the same place.

emilwestergren commented 8 years ago

Can't you just use uniforms for that?

davidpiuva commented 8 years ago

Then a glitch in the phone's memory might accidentally turn on debug views and expose our algorithms.

davidpiuva commented 8 years ago

@emilwestergren Giving macros to shaders from the CPU is now required to flip images of different coordinate systems without affecting performance for the majority of shaders that never get an input image of non-standard scan order. Either we implement this feature and reserve a field for built in macros or let the header of each shader including version be generated from the abstraction layer.

davidpiuva commented 8 years ago

It seems like GLES do not even have a real pre-compiler since token pasting is not allowed and then I cannot mangle a name for an image's sampling transform. This is yet another feature that is needed then.

davidpiuva commented 8 years ago

Since coordinate systems moved from Kean, this is again not a priority.