openframeworks / openframeworks/openFrameworks

Rendering ofFbo to float textures with ES 2.0

Open
#5,300 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

ofTexture is setup so that it can take parameters to create a float texture targeting ES 2.0 like so:
void ofTexture::allocate(int w, int h, int glInternalFormat, int glFormat, int pixelType)
or in use:
tex.allocate(width, height, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA);

I could be missing something, but from what I can tell if you want to have an ofFbo render into a float texture, currently you will have to modify the createAndAttachTexture() function inside ofFbo.

Right now it looks like this:

void ofFbo::createAndAttachTexture(GLenum internalFormat, GLenum attachmentPoint) {

    ofTextureData texData;

    texData.textureTarget = settings.textureTarget;
    texData.width = settings.width;
    texData.height = settings.height;
    texData.glInternalFormat = internalFormat;
    texData.bFlipTexture = false;
    texData.wrapModeHorizontal = settings.wrapModeHorizontal;
    texData.wrapModeVertical = settings.wrapModeVertical;
    texData.magFilter = settings.maxFilter;
    texData.minFilter = settings.minFilter;

    ofTexture tex;
    tex.allocate(texData);

    attachTexture(tex, internalFormat, attachmentPoint);
    dirty.push_back(true);
    activeDrawBuffers.push_back(GL_COLOR_ATTACHMENT0 + attachmentPoint);
}

But neither ofTextureData or ofFbo::Settings seem to have a glFormat attribute. So you could do something terrible like this and make all your fbo textures float textures :

void ofFbo::createAndAttachTexture(GLenum internalFormat, GLenum attachmentPoint) {

    ofTexture tex;
    tex.allocate(settings.width, settings.height,  GL_RGBA,  GL_RGBA, GL_HALF_FLOAT_OES);

    attachTexture(tex, internalFormat, attachmentPoint);
    dirty.push_back(true);
    activeDrawBuffers.push_back(GL_COLOR_ATTACHMENT0 + attachmentPoint);
}

Or perhaps a better way would just be to add the glFormat attribute to both ofTextureData and ofFbo::Settings. And then if there is a glFormat in ofTextureData it can just bubble down to fill in the glType.

This isn't an issue with GL ES > 2.0 since when you allocate a fbo you can give it the GL_RGBA32F, but since that doesn't exist in 2.0 we have this problem.

Is this just something that was overlooked? Am I overlooking the solution? Or just too niche of a scenario for anyone to have noticed until now?

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 tracing ofFbo::createAndAttachTexture and compare its ofTextureData setup with the ofTexture::allocate signature and ES 2.0 usage shown in the issue. Inspect ofTextureData and ofFbo::Settings for how texture format and type are represented. Done means an ofFbo can render to a float texture under ES 2.0 without modifying the function with hardcoded allocation parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.