openframeworks / openframeworks/openFrameworks

OpenGL subroutines in ofShader

Open
#3,886 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core feature section-2D
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

I just played around with subroutines in glsl and already implemented basic info output in ofShader, like:

void printSubroutineNames( GLenum shadertype) const; 
void printSubroutineUniforms( GLenum shadertype) const; 

Since subroutine uniforms are handled completely different then normal uniforms I wanted to start a discussion on how to add them to the ofShader class.

Subroutines are part of the context state and not of the program object, which means every time we call something like glUseProgram the subroutine state is lost. Thus keeping internal track of shadertype ->subroutine uniform -> subroutine index mapping should be added and set every time begin() is called.

Here are just my thoughts on this, if the idea of adding subroutines isn't quashed.

  • interface for the mapping: void setSubroutineUniform( GLenum shadertype, string uniformName, string subroutineName ) , internally the uniform location and subroutine index are cached as with the normal uniforms and the array we need for glUniformSubroutinesuiv is updated accordingly.
  • call glUniformSubroutinesuiv in the begin function, like setUniformDefaults
  • check if there are subroutines after the program is created. If there are, query the necessary information and set default values.

Did I miss something beside that I have the feeling that it won't be used much?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing ofShader's existing uniform handling, especially begin() and setUniformDefaults, alongside the proposed subroutine methods. Clarify the intended interface and how subroutine state should be restored after glUseProgram; done means the project has an agreed design and corresponding implementation requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.