Skip to content
Snippets Groups Projects
Commit b99354a1 authored by sdegrande's avatar sdegrande
Browse files

Introduce a ProgramExtension class, as well as ProgramWrapper

A ProgramExtension is much smarter than the previously introduced
programConf. A programConf can only be used to preprocess a shader.
But we could also need to add uniforms in a shader and populate
program instance data during rendering, for instance.

A ProgramExtension not only defines a programConf but also implements
'hooks' called by Program. A 'ProgramExtension*' can be added as a second
parameter to setShaderProgram() and to setMaterial(). Ownership is
taken, hence the need to pass a pointer...

For instance :
  ProgramExtension* extension = new ProgramExtension(R"(
    { "fragment" : { "defines" : { "FOO" : 1 } } })");
  mesh->setShaderProgram("Texture", extension);

ProgramExtensions can be linked to create a chain of extensions. The
program configs are merged together.

For instance :
  ProgramExtension* extension = new ProgramExtension(R"(
    { "fragment" : { "defines" : { "FOO" : 1 } } })");
  extension->linkExtension(new ProgramExtension(R"(
    { "fragment" : { "defines" : { "BAR" : 1 } } })"));

-----------------------
Second part of the commit
---

ProgramExtensions can have instance data just as Programs.
Currently a Program's instance data (ProgramData) is stored in the
Renderer by Node::render(), and a bit later retrieved by
Program::setInstanceUniforms().
This can not easily be extended for ProgramExtension's instance data,
given that a Program can have several linked extensions.

This commit introduces ProgramWrapper, used as a FlyWeight containing
the actual Program (shared pointer), and all other shader related
data as well as the instance data.
A Primitive now only contain a ProgramWrapper.

Given that a ProgramWrapper contains the program instance data, it is
no more needed to send them through the Renderer.
parent 41928ffa
No related branches found
No related tags found
No related merge requests found
Showing
with 420 additions and 132 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment