Browse Source
Additionally refactor the code according to oF guidelines. To be done for the rest of the code.master
2 changed files with 143 additions and 125 deletions
@ -1,88 +1,115 @@ |
|||||
#include "FboSource.h" |
#include "FboSource.h" |
||||
|
|
||||
namespace ofx { |
namespace ofx { |
||||
namespace piMapper { |
namespace piMapper { |
||||
FboSource::FboSource() : fbo(NULL) { |
|
||||
name = PIMAPPER_FBO_SOURCE_DEF_NAME; |
FboSource::FboSource() : fbo(NULL) { |
||||
loadable = false; |
name = PIMAPPER_FBO_SOURCE_DEF_NAME; |
||||
loaded = false; |
loadable = false; |
||||
type = SourceType::SOURCE_TYPE_FBO; |
loaded = false; |
||||
ofAddListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
type = SourceType::SOURCE_TYPE_FBO; |
||||
} |
ofAddListener(ofEvents().setup, this, |
||||
|
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
||||
FboSource::~FboSource() { |
} |
||||
removeAppListeners(); |
|
||||
clear(); |
FboSource::~FboSource() { |
||||
} |
removeAppListeners(); |
||||
|
clear(); |
||||
void FboSource::addAppListeners() { |
} |
||||
ofLogNotice("FboSource") << "Adding app listeners"; |
|
||||
ofAddListener(ofEvents().update, this, &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
void FboSource::addAppListeners() { |
||||
ofAddListener(ofEvents().draw, this, &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
ofLogNotice("FboSource") << "Adding app listeners"; |
||||
ofAddListener(ofEvents().exit, this, &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
ofAddListener(ofEvents().update, this, |
||||
} |
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
ofAddListener(ofEvents().draw, this, |
||||
void FboSource::removeAppListeners() { |
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
||||
ofLogNotice("FboSource") << "Removing app listeners"; |
ofAddListener(ofEvents().exit, this, |
||||
ofRemoveListener(ofEvents().update, this, &FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
||||
ofRemoveListener(ofEvents().draw, this, &FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
} |
||||
ofRemoveListener(ofEvents().exit, this, &FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
|
||||
} |
void FboSource::removeAppListeners() { |
||||
|
ofLogNotice("FboSource") << "Removing app listeners"; |
||||
void FboSource::onAppSetup(ofEventArgs &args) { |
ofRemoveListener(ofEvents().update, this, |
||||
ofRemoveListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
||||
setup(); |
ofRemoveListener(ofEvents().draw, this, |
||||
|
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
||||
// Check if FBO was allocated in user defined setup
|
ofRemoveListener(ofEvents().exit, this, |
||||
// If not, show warning and alocate to avoid panic
|
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
||||
if (!fbo->isAllocated()) { |
} |
||||
ofLogWarning("FboSource::onAppSetup") << "FBO not allocated, allocating with default values"; |
|
||||
allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, PIMAPPER_FBO_SOURCE_DEF_HEIGHT); |
void FboSource::onAppSetup(ofEventArgs &args) { |
||||
} |
ofRemoveListener(ofEvents().setup, this, |
||||
} |
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
||||
|
setup(); |
||||
void FboSource::onAppUpdate(ofEventArgs &args) { |
|
||||
if (fbo == NULL || !fbo->isAllocated()) { |
// Check if FBO was allocated in user defined setup
|
||||
ofLogWarning("FboSource") << "FBO not allocated"; |
// If not, show warning and alocate to avoid panic
|
||||
return; |
if (!fbo->isAllocated()) { |
||||
} |
ofLogWarning("FboSource::onAppSetup") << |
||||
update(); |
"FBO not allocated, allocating with default values"; |
||||
} |
allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, |
||||
|
PIMAPPER_FBO_SOURCE_DEF_HEIGHT); |
||||
void FboSource::onAppDraw(ofEventArgs &args) { |
} |
||||
if (fbo == NULL || !fbo->isAllocated()) { |
} |
||||
ofLogWarning("FboSource") << "FBO not allocated"; |
|
||||
return; |
void FboSource::onAppUpdate(ofEventArgs &args) { |
||||
} |
if (fbo == NULL || !fbo->isAllocated()) { |
||||
fbo->begin(); |
ofLogWarning("FboSource") << "FBO not allocated"; |
||||
draw(); |
return; |
||||
fbo->end(); |
} |
||||
} |
update(); |
||||
|
} |
||||
void FboSource::onAppExit(ofEventArgs &args) { |
|
||||
exit(); |
void FboSource::onAppDraw(ofEventArgs &args) { |
||||
} |
if (fbo == NULL || !fbo->isAllocated()) { |
||||
|
ofLogWarning("FboSource") << "FBO not allocated"; |
||||
void FboSource::allocate(int width, int height) { |
return; |
||||
clear(); |
} |
||||
fbo = new ofFbo(); |
fbo->begin(); |
||||
fbo->allocate(width, height); |
draw(); |
||||
|
fbo->end(); |
||||
// Clear FBO
|
} |
||||
fbo->begin(); |
|
||||
ofClear(0); |
void FboSource::onAppExit(ofEventArgs &args) { |
||||
fbo->end(); |
exit(); |
||||
|
} |
||||
texture = &(fbo->getTextureReference()); |
|
||||
} |
void FboSource::allocate(int width, int height) { |
||||
|
clear(); |
||||
void FboSource::clear() { |
fbo = new ofFbo(); |
||||
texture = NULL; |
fbo->allocate(width, height); |
||||
if (fbo != NULL) { |
|
||||
delete fbo; |
// Clear FBO
|
||||
fbo = NULL; |
fbo->begin(); |
||||
} |
ofClear(0); |
||||
} |
fbo->end(); |
||||
|
|
||||
} // namespace piMapper
|
texture = &(fbo->getTextureReference()); |
||||
|
} |
||||
|
|
||||
|
void FboSource::clear() { |
||||
|
texture = NULL; |
||||
|
if (fbo != NULL) { |
||||
|
delete fbo; |
||||
|
fbo = NULL; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int FboSource::getWidth() { |
||||
|
if (fbo->isAllocated()) { |
||||
|
return fbo->getWidth(); |
||||
|
} else { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int FboSource::getHeight() { |
||||
|
if (fbo->isAllocated()) { |
||||
|
return fbo->getHeight(); |
||||
|
} else { |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
} // namespace ofx
|
} // namespace ofx
|
Loading…
Reference in new issue