-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A dream about fbos summing using += operator #7130
base: master
Are you sure you want to change the base?
Conversation
love this idea. I would definitely consider removing the ofSetColor in the += incase you would want to do that explicitly. |
yeah I was in doubt about setcolor, I'll remove it now |
I like the idea of operators. |
It seems like good! Can we support more general rhs targets like ofImage, ofVideoPlayer, ofVideoGrabber? Yes, I know, making thing general makes complex. |
one question -- what happens when FBOs are not the same size? am a fan of the = ofColor approach that @NickHardeman suggested. |
@ofZach it can be drawin in 0,0 coordinate. top left |
I like the ofColor operator too! |
@NickHardeman I think it is OK to just overwrite if there is no transparency or blend mode enabled for the two images. |
This is just an idea.
And I think design of iostream is not so cool. (mainly about string formatting and iomanip...) like below: fbo << fbo1;
fbo << fbo2 << fbo3;
fbo << ofFboOpStyle::Fill << fbo4;
fbo << ofFboOpStyle::AspectFit << fbo5;
fbo << ofFboOpStyle::Offset(10, 10) << fbo6; I know those may be over-featured or non-intuitive... |
I really like this one |
f.draw(0,0); | ||
this->end(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to add a check that if the fbo isn't allocated you can an error/warning
or you could have if it is not allocated it gets allocated to match first?
libs/openFrameworks/gl/ofFbo.cpp
Outdated
@@ -302,6 +302,13 @@ ofFbo::ofFbo(const ofFbo & mom){ | |||
} | |||
} | |||
|
|||
//-------------------------------------------------------------- | |||
void ofFbo::operator+=(const ofFbo & f){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg should be fbo in header/cpp I think to be consistent.
this->begin(); | ||
f.draw(0,0); | ||
fbo.draw(0,0); | ||
this->end(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like it should be something like:
//if we aren't allocated lets allocate to be the same as the input
if (!this->isAllocated() && fbo.isAllocated()) {
this->allocate(fbo.settings);
}
if (fbo.isAllocated()) {
this->begin();
fbo.draw(0,0);
this->end();
}else{
ofLogWarning("ofFbo::operator+=") << " input fbo is not allocated, skipping += ";
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dimitre what do you think about the suggestion above?👆
This way it basically copies the fbo being += if the main fbo isn't allocated
what about [edit: of course I'm not specifically advocating the *= operator itself (although it feels not bad) but the principle] |
(posting like this as I'm not sure how to pull another user's branch then add to the PR?) ofFbo.h ofFbo & operator *=(const ofShader & shader) { return pass(shader); }
ofFbo & pass(const ofShader & shader);
std::unique_ptr<ofFbo> buffer; // sole overhead if method is unused is unallocated pointer ofFbo.cpp ofFbo & ofFbo::pass(const ofShader & shader) {
// lazy -- perhaps augment settings to make within allocate() if so desired
if (!buffer) buffer = std::make_unique<ofFbo>();
// conformant -- if compare is too costly at every frame, hook into allocate to maintain sync
if (buffer->settings != settings) buffer->allocate(settings);
buffer->begin();
ofClear(0,0,0,0);
shader.begin();
draw(0,0);
shader.end();
buffer->end();
// perhaps this could be "texture swapped" with some clever GL code?
begin();
buffer->draw(0,0);
end();
return *this; // to enable things like : flatten_fbo += (layer_fbo *= layer_shader);
} ofApp.cpp: fbo *= shader; |
Last night I dreamt about OF, ofFbo had a += operator so you could sum layers like this.
In fact this still makes sense to me, so I decided to make this quick PR
example