recp
recp

Reputation: 393

Which states does framebuffer store?

I created a off-screen framebuffer and added two render target to it.

Each render target has its own blending mode. I set it by glBlendFunci:

glBlendFunci(accum->buffId,     GL_ONE,  GL_ONE);
glBlendFunci(revealage->buffId, GL_ZERO, GL_ONE_MINUS_SRC_COLOR);

Does framebuffer stores this blending mode? Because it is specific to a buffer. Should I set this in every frame or just in initialization code?

Also off-screen framebuffer doesn't write to depth so I disabled it by glDepthMask(GL_FALSE); but it seems it is global state rather than framebuffer state.

I don't know how many or which states framebuffer stores. Especially I want to know about these states which about framebuffer's attachments:

  1. glBlendFunci
  2. glBlendFunc
  3. glEnable(GL_BLEND)
  4. glEnable(GL_DEPTH_TEST)
  5. glDepthMask

Does framebuffer store any of these states? Also I would like to know other states if you would like to share it.

I know VAO object stores some states about vertex attributes so I thought that maybe framebuffer also stores some states which related to its attachments

EDIT: I updated glBlendFunci parameter to use draw index, I was used bufferId/objectId

glBlendFunci(accum->drawIndex,     GL_ONE,  GL_ONE);
glBlendFunci(revealage->drawIndex, GL_ZERO, GL_ONE_MINUS_SRC_COLOR);

Upvotes: 1

Views: 411

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473407

The best way to know what state framebuffer objects deal with is to look at the OpenGL 4.5 DSA-based APIs. Any function of the form glNamedFramebuffer* affects a framebuffer object. And if there is no function of that form, then the state behind it does not affect framebuffer state. And therefore, the equivalent non-DSA form also doesn't affect the framebuffer's state.

Notably, there is no glNamedFramebufferBlendFunc call. Or *DepthMask. Indeed, none of the state you mention are a part of the framebuffer.

I know VAO object stores some states about vertex attributes so I thought that maybe framebuffer also stores some states which related to its attachments

But that's the thing; these things don't relate to the attachments of a framebuffer. It's kind of complicated.

See, when you call glBlendFunci, you pass an index. This sets the blending mode for a particular index. If you pass zero, then you modify the blending mode for index 0. That index matches the FS output location 0.

But index 0 is not GL_COLOR_ATTACHMENT0. It is the draw buffer index 0. Depending on what you specified when you called glNamedFramebufferDrawBuffers, draw buffer index 0 could refer to GL_COLOR_ATTACHMENT2.

Because these indices do not specific framebuffer attachments directly, it would be incorrect to claim that setting blending state directly affects the framebuffer attachment.

Upvotes: 6

Related Questions