Browse Source

added ability not to update/draw fbo sources when they are not actively displayed

master
Theodoros Papatheodorou 8 years ago
parent
commit
5531170862
  1. 4
      src/MediaServer/MediaServer.cpp
  2. 15
      src/Sources/BaseSource.cpp
  3. 7
      src/Sources/BaseSource.h
  4. 18
      src/Surfaces/SurfaceManager.cpp
  5. 3
      src/Surfaces/SurfaceManager.h

4
src/MediaServer/MediaServer.cpp

@ -37,13 +37,13 @@ void MediaServer::setup(){
void MediaServer::update(){ void MediaServer::update(){
for(int i = 0; i < fboSources.size(); ++i){ for(int i = 0; i < fboSources.size(); ++i){
fboSources[i]->updateFbo(); if (fboSources[i]->isActive() || fboSources[i]->runsInBackground()) fboSources[i]->updateFbo();
} }
} }
void MediaServer::draw(){ void MediaServer::draw(){
for(int i = 0; i < fboSources.size(); ++i){ for(int i = 0; i < fboSources.size(); ++i){
fboSources[i]->drawFbo(); if (fboSources[i]->isActive() || fboSources[i]->runsInBackground()) fboSources[i]->drawFbo();
} }
} }

15
src/Sources/BaseSource.cpp

@ -6,6 +6,7 @@ namespace piMapper {
BaseSource::BaseSource(){ BaseSource::BaseSource(){
//cout << "BaseSource" << endl; //cout << "BaseSource" << endl;
init(); init();
runInBackground = false;
} }
BaseSource::BaseSource(ofTexture * newTexture){ BaseSource::BaseSource(ofTexture * newTexture){
@ -49,6 +50,18 @@ void BaseSource::init(){
referenceCount = 1; // We have one instance on init referenceCount = 1; // We have one instance on init
} }
void BaseSource::setActive(bool value){
displayed = value;
}
bool BaseSource::isActive(){
return displayed;
}
bool BaseSource::runsInBackground(){
return runInBackground;
}
void BaseSource::setNameFromPath(string & fullPath){ void BaseSource::setNameFromPath(string & fullPath){
vector <string> pathParts; vector <string> pathParts;
//cout << "fullPath: " << fullPath << endl; //cout << "fullPath: " << fullPath << endl;
@ -58,4 +71,4 @@ void BaseSource::setNameFromPath(string & fullPath){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

7
src/Sources/BaseSource.h

@ -20,6 +20,9 @@ class BaseSource {
string & getPath(); string & getPath();
virtual void clear(){} virtual void clear(){}
virtual void togglePause(){} virtual void togglePause(){}
bool isActive();
bool runsInBackground();
void setActive(bool);
virtual void reset(){} // called by surfaceManager to optionally allow users to reset a source's variables virtual void reset(){} // called by surfaceManager to optionally allow users to reset a source's variables
@ -28,7 +31,7 @@ class BaseSource {
int referenceCount; int referenceCount;
private: private:
void init(); void init();
protected: protected:
void setNameFromPath(string & fullPath); void setNameFromPath(string & fullPath);
@ -38,6 +41,8 @@ class BaseSource {
bool loadable; // If the source can be loaded from disk like image and video bool loadable; // If the source can be loaded from disk like image and video
bool loaded; // Is the source loaded? bool loaded; // Is the source loaded?
SourceType type; SourceType type;
bool displayed;
bool runInBackground;
}; };
} // namespace piMapper } // namespace piMapper

18
src/Surfaces/SurfaceManager.cpp

@ -134,6 +134,8 @@ bool SurfaceManager::loadXmlSettings(string fileName){
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
bool success = SettingsLoader::instance()->load(*this, *mediaServer, fileName); bool success = SettingsLoader::instance()->load(*this, *mediaServer, fileName);
setPresetSourcesActiveState(_activePresetIndex, true);
return success; return success;
} }
@ -451,6 +453,14 @@ void SurfaceManager::setNextPreset(){
// TODO: Create command for this. // TODO: Create command for this.
} }
void SurfaceManager::setPresetSourcesActiveState(unsigned int presetIndex, bool state){
// tell sources associated with current preset that they are not displayed any more
// this is so that we can optionally update the buffers or not.
for (int j=0; j<_presets[presetIndex]->getSurfaces().size(); j++){
_presets[_activePresetIndex]->getSurfaces()[j]->getSource()->setActive(state);
}
}
void SurfaceManager::setPreset(unsigned int i){ void SurfaceManager::setPreset(unsigned int i){
if(_presets.size() <= 1){ if(_presets.size() <= 1){
throw runtime_error("ofxPiMapper: No presets to set."); throw runtime_error("ofxPiMapper: No presets to set.");
@ -460,7 +470,13 @@ void SurfaceManager::setPreset(unsigned int i){
throw runtime_error("ofxPiMapper: Preset index out of bounds."); throw runtime_error("ofxPiMapper: Preset index out of bounds.");
} }
_activePresetIndex = i; //let sources associated with OLD preset know that they are not being displayed any more
setPresetSourcesActiveState(_activePresetIndex, false);
//change preset
_activePresetIndex = i;
//let sources associated with NEW preset know that they are now being displayed
setPresetSourcesActiveState(_activePresetIndex, true);
//when preset it changed, call reset on all sources, if it's defined //when preset it changed, call reset on all sources, if it's defined
for (int i=0; i<_presets[_activePresetIndex]->getSurfaces().size(); i++){ for (int i=0; i<_presets[_activePresetIndex]->getSurfaces().size(); i++){

3
src/Surfaces/SurfaceManager.h

@ -76,6 +76,7 @@ class SurfaceManager {
void setPreset(unsigned int i); void setPreset(unsigned int i);
void cloneActivePreset(); void cloneActivePreset();
void eraseActivePreset(); void eraseActivePreset();
void setPresetSourcesActiveState(unsigned int presetIndex, bool state);
private: private:
BaseSurface * selectedSurface; BaseSurface * selectedSurface;
@ -90,4 +91,4 @@ class SurfaceManager {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

Loading…
Cancel
Save