Browse Source

Add fbo source protection against not allocating in derived classes

master
Krisjanis Rijnieks 11 years ago
parent
commit
9e7d07e0c1
  1. 9
      src/Sources/FboSource.cpp
  2. 13
      src/Sources/FboSource.h

9
src/Sources/FboSource.cpp

@ -3,7 +3,7 @@
namespace ofx {
namespace piMapper {
FboSource::FboSource() : fbo(NULL) {
name = PIMAPPER_DEF_FBO_SOURCE_NAME;
name = PIMAPPER_FBO_SOURCE_DEF_NAME;
loadable = false;
loaded = false;
type = SourceType::SOURCE_TYPE_FBO;
@ -32,6 +32,13 @@ namespace ofx {
void FboSource::onAppSetup(ofEventArgs &args) {
ofRemoveListener(ofEvents().setup, this, &FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP);
setup();
// Check if FBO was allocated in user defined setup
// If not, show warning and alocate to avoid panic
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::onAppUpdate(ofEventArgs &args) {

13
src/Sources/FboSource.h

@ -10,7 +10,9 @@ class YourGenerativeSource : public FboSource {
#include "ofMain.h"
#include "BaseSource.h"
#define PIMAPPER_DEF_FBO_SOURCE_NAME "FBO Source"
#define PIMAPPER_FBO_SOURCE_DEF_NAME "FBO Source"
#define PIMAPPER_FBO_SOURCE_DEF_WIDTH 500
#define PIMAPPER_FBO_SOURCE_DEF_HEIGHT 500
namespace ofx {
namespace piMapper {
@ -38,12 +40,15 @@ namespace ofx {
virtual void draw() {}; // But this is the only place where you shoud do drawing
virtual void exit() {};
// Use these to set up FBo itself
void allocate(int width, int height);
void clear(); // The only method from BaseSource to be overriden
// The only method from BaseSource to be overriden
void clear();
protected:
ofFbo* fbo;
// Use this instead fbo->allocate as it sets other source related settings
// It is protected to force the user to create derived FBO sources from this
void allocate(int width, int height);
};
} // namespace piMapper
} // namespace ofx
Loading…
Cancel
Save