Skip to content
Permalink
Browse files

Merge pull request #2015 from Haydelj/streamShot

#937 actually works again
  • Loading branch information...
dcwhite committed Nov 26, 2019
2 parents a82d8ec + 4ceaa62 commit 431d76f55534547f179b02616a2672a47d7f15df
@@ -39,8 +39,7 @@
namespace SCIRun {
namespace Render {

ESCore::ESCore() : mCoreSequence(0), mCurrentTime(0.0f), mFPS(0.0f), mLastRealTime(0.0f),
r_(0.0f), g_(0.0f), b_(0.0f), a_(0.0f)
ESCore::ESCore() : mCurrentTime(0.0f), r_(0.0f), g_(0.0f), b_(0.0f), a_(0.0f)
{
// Register common systems.
gen::registerAll(*this);
@@ -120,23 +119,23 @@ bool ESCore::hasGeomPromise() const
return false;
}

void ESCore::execute(double currentTime, double constantFrameTime)
bool ESCore::hasShaderPromise() const
{
++mCoreSequence;

const int fpsAvgLength = 60;
if (mCoreSequence % fpsAvgLength == 0)
for(auto& comp : mComponents)
{
mFPS /= fpsAvgLength;
//std::cout << toString("");
//std::cout << "FPS: " << mFPS << "\n";
mFPS = 0.0f;
if(comp.second->getNumComponents() > 0)
{
if(mComponentIDNameMap.find(comp.first) != mComponentIDNameMap.end() &&
mComponentIDNameMap.at(comp.first) == "ren:ShaderPromiseVF")
return true;
}
}
return false;
}

// Add up FPS. Will average when we loop back around.
mFPS += 1.0f / (static_cast<float>(currentTime) - mLastRealTime);
mLastRealTime = static_cast<float>(currentTime);

void ESCore::execute(double currentTime, double constantFrameTime)
{
mCurrentTime += constantFrameTime;
// Update the current static time component before renormalization.
{
gen::StaticGlobalTime globalTime;
@@ -145,15 +144,8 @@ void ESCore::execute(double currentTime, double constantFrameTime)

// Modify 'input'. If it doesn't already exist in the system, create it.
gen::StaticGlobalTime* esGlobalTime = getStaticComponent<gen::StaticGlobalTime>();

if (esGlobalTime == nullptr)
{
addStaticComponent(globalTime);
}
else
{
*esGlobalTime = globalTime;
}
if (esGlobalTime == nullptr) addStaticComponent(globalTime);
else *esGlobalTime = globalTime;
}

// Ensure all systems are appropriately added and removed.
@@ -184,8 +176,6 @@ void ESCore::execute(double currentTime, double constantFrameTime)
// Perform execution of systems.
uint64_t timeInMS = static_cast<uint64_t>(mCurrentTime * 1000.0);
mSystems->runSystems(*this, timeInMS);

mCurrentTime += constantFrameTime;
}

void ESCore::setBackgroundColor(float r, float g, float b, float a)
@@ -47,19 +47,14 @@ namespace Render {
void execute(double currentTime, double constantFrameTime);
void setBackgroundColor(float r, float g, float b, float a);
void runGCOnNextExecution(){runGC = true;}
bool hasShaderPromise() const;

private:
bool hasGeomPromise() const;

int64_t mCoreSequence; ///< Sequence number (frame) since start.
spire::GLState mDefaultGLState; ///< Default OpenGL state.
double mCurrentTime; ///< Current system time calculated from constant frame time.

float mFPS; ///< Actual FPS of system.
float mLastRealTime; ///< Last realtime passed into the core.

bool runGC;

float r_, g_, b_, a_;
};

@@ -65,11 +65,11 @@
#include "comp/StaticWorldLight.h"
#include "comp/LightingUniforms.h"
#include "comp/ClippingPlaneUniforms.h"

using namespace SCIRun;
using namespace SCIRun::Core::Datatypes;
using namespace SCIRun::Graphics::Datatypes;
using namespace SCIRun::Core::Geometry;

using namespace std::placeholders;

namespace fs = spire;
@@ -184,6 +184,7 @@ namespace SCIRun {
// hash multimap with a list which assigns ids to names.
uint64_t getEntityIDForName(const std::string& name, int port);
Core::Geometry::BBox getSceneBox() {return mSceneBBox;}
bool hasShaderPromise() const {return mCore.hasShaderPromise();}

//---------------- Rendering -----------------------------------------------------------------
void doFrame(double currentTime, double constantDeltaTime); // Performs a frame.
@@ -388,10 +389,10 @@ namespace SCIRun {
glm::vec2 autoRotateVector {0.0, 0.0};
float autoRotateSpeed {0.01f};

const int frameInitLimit_ {};
QOpenGLContext* mContext {};
std::shared_ptr<spire::ArcBall> widgetBall_ {};
std::unique_ptr<SRCamera> mCamera; // Primary camera.
const int frameInitLimit_ {};
QOpenGLContext* mContext {};
std::shared_ptr<spire::ArcBall> widgetBall_ {};
std::unique_ptr<SRCamera> mCamera; // Primary camera.

};

Binary file not shown.
@@ -0,0 +1,40 @@
/*
For more information, please see: http://software.sci.utah.edu
The MIT License
Copyright (c) 2015 Scientific Computing and Imaging Institute,
University of Utah.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#ifdef OPENGL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif

void main()
{
gl_FragColor = vec4(0.0);
}
@@ -0,0 +1,33 @@
/*
For more information, please see: http://software.sci.utah.edu

The MIT License

Copyright (c) 2015 Scientific Computing and Imaging Institute,
University of Utah.


Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

attribute vec3 aPos;
void main( void )
{
gl_Position = vec4(aPos, 1.0);
}
@@ -70,12 +70,20 @@ GLWidget::~GLWidget()
void GLWidget::initializeGL()
{
spire::glPlatformInit();
}
}

void GLWidget::paintGL()
{
mCurrentTime += updateTime;
mGraphics->doFrame(mCurrentTime, updateTime);
//set to 200ms to force promise fullfilment every frame if a good frame as been requested
double lUpdateTime = mFrameRequested ? 0.2 : updateTime;
mCurrentTime += lUpdateTime;
mGraphics->doFrame(mCurrentTime, lUpdateTime);

if(mFrameRequested && !mGraphics->hasShaderPromise())
{
mFrameRequested = false;
finishedFrame();
}
}

//------------------------------------------------------------------------------
@@ -70,9 +70,11 @@ class GLWidget : public QOpenGLWidget
void setLockZoom(bool lock) { mGraphics->setLockZoom(lock); }
void setLockPanning(bool lock) { mGraphics->setLockPanning(lock); }
void setLockRotation(bool lock) { mGraphics->setLockRotation(lock); }
void requestFrame() {mFrameRequested = true;}

Q_SIGNALS:
void fatalError(const QString& message);
void finishedFrame();

public Q_SLOTS:
// Only use when not using threading.
@@ -94,11 +96,12 @@ public Q_SLOTS:
/// Retrieve SRInterface mouse button from mouse event.
Render::SRInterface::MouseButton getSpireButton(QMouseEvent* event);

std::shared_ptr<Render::SRInterface> mGraphics {}; ///< Interface to spire.
QTimer* mTimer {};
double mFrameTime {0.0};
std::shared_ptr<Render::SRInterface> mGraphics {}; ///< Interface to spire.
QTimer* mTimer {};
double mFrameTime {0.0};
bool mFrameRequested {false};

double mCurrentTime {0.0};
double mCurrentTime {0.0};
};

} // end of namespace Gui
@@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE.
#include <Core/GeometryPrimitives/Transform.h>
#include <Core/Logging/Log.h>
#include <Graphics/Datatypes/GeometryImpl.h>
#include <Core/GeometryPrimitives/Transform.h>
#include <Core/Thread/Mutex.h>
#include <Graphics/Glyphs/GlyphGeom.h>
#include <Interface/Modules/Render/ES/SRInterface.h>
#include <Interface/Modules/Render/GLWidget.h>
@@ -86,6 +88,7 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
ModuleDialogGeneric(state, parent),
gid_(new DialogIdGenerator(name))
{
//lock
setupUi(this);
setWindowTitle(QString::fromStdString(name));
setFocusPolicy(Qt::StrongFocus);
@@ -101,6 +104,7 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
mGLWidget->setFormat(format);

connect(mGLWidget, SIGNAL(fatalError(const QString&)), this, SIGNAL(fatalError(const QString&)));
connect(mGLWidget, SIGNAL(finishedFrame()), this, SLOT(frameFinished()));
connect(this, SIGNAL(mousePressSignalForTestingGeometryObjectFeedback(int, int, const std::string&)), this, SLOT(sendGeometryFeedbackToState(int, int, const std::string&)));

mSpire = std::weak_ptr<SRInterface>(mGLWidget->getSpire());
@@ -131,7 +135,7 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
setInitialLightValues();

state->connectSpecificStateChanged(Parameters::GeomData,[this](){Q_EMIT newGeometryValueForwarder();});
connect(this, SIGNAL(newGeometryValueForwarder()), this, SLOT(updateAllGeometries()));
connect(this, SIGNAL(newGeometryValueForwarder()), this, SLOT(updateModifiedGeometriesAndSendScreenShot()));

state->connectSpecificStateChanged(Modules::Render::ViewScene::CameraRotation,[this](){Q_EMIT cameraRotationChangeForwarder();});
connect(this, SIGNAL(cameraRotationChangeForwarder()), this, SLOT(pullCameraRotation()));
@@ -142,6 +146,10 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
state->connectSpecificStateChanged(Modules::Render::ViewScene::CameraDistance,[this](){Q_EMIT cameraDistnaceChangeForwarder();});
connect(this, SIGNAL(cameraDistnaceChangeForwarder()), this, SLOT(pullCameraDistance()));

state->connectSpecificStateChanged(Parameters::VSMutex, [this](){Q_EMIT lockMutexForwarder();});
connect(this, SIGNAL(lockMutexForwarder()), this, SLOT(lockMutex()));
lockMutex();

std::string filesystemRoot = Application::Instance().executablePath().string();
std::string sep;
sep += boost::filesystem::path::preferred_separator;
@@ -663,20 +671,30 @@ QColor ViewSceneDialog::checkColorSetting(std::string& rgb, QColor defaultColor)
//---------------- New Geometry --------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::updateAllGeometries()
{
//If a render parameter changes we must update all of the geometries by removing and readding them.
//This must be foreced because the IDs will not have changed
newGeometryValue(true);
}

//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::updateModifiedGeometries()
{
//if we are looking for a new geoetry the ID will have changed therefore we can find the
//geometries that have changed and only remove those
newGeometryValue(false);
}

//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::updateModifiedGeometriesAndSendScreenShot()
{
newGeometryValue(false);
if(mGLWidget->isVisible() && mGLWidget->isValid()) mGLWidget->requestFrame();
else unblockExecution();
}

//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::newGeometryValue(bool forceAllObjectsToUpdate)
{
@@ -686,8 +704,7 @@ void ViewSceneDialog::newGeometryValue(bool forceAllObjectsToUpdate)
Guard lock(Modules::Render::ViewScene::mutex_.get());

auto spire = mSpire.lock();
if (!spire)
return;
if (!spire) return;

if(!mGLWidget->isValid()) return;
spire->setContext(mGLWidget->context());
@@ -752,10 +769,33 @@ void ViewSceneDialog::newGeometryValue(bool forceAllObjectsToUpdate)
}
}

sendScreenshotDownstreamForTesting();
if (saveScreenshotOnNewGeometry_) screenshotClicked();
}

if (saveScreenshotOnNewGeometry_)
screenshotClicked();
//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::lockMutex()
{
auto screenShotMutex = state_->getTransientValue(Parameters::VSMutex);
auto mutex = transient_value_cast<Mutex*>(screenShotMutex);
if(mutex) mutex->lock();
}

void ViewSceneDialog::unblockExecution()
{
auto screenShotMutex = state_->getTransientValue(Parameters::VSMutex);
auto mutex = transient_value_cast<Mutex*>(screenShotMutex);
if(mutex)
{
mutex->unlock();
std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1));
mutex->lock();
}
}

void ViewSceneDialog::frameFinished()
{
sendScreenshotDownstreamForTesting();
unblockExecution();
}

//--------------------------------------------------------------------------------------------------
@@ -794,7 +834,7 @@ void ViewSceneDialog::showEvent(QShowEvent* evt)
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
ModuleDialogGeneric::showEvent(evt);

updateModifiedGeometries();
updateModifiedGeometriesAndSendScreenShot();
}

//--------------------------------------------------------------------------------------------------
@@ -873,6 +913,7 @@ void ViewSceneDialog::mouseReleaseEvent(QMouseEvent* event)
selected_ = false;
auto selName = restoreObjColor();
updateModifiedGeometries();
unblockExecution();
Q_EMIT mousePressSignalForTestingGeometryObjectFeedback(event->x(), event->y(), selName);
}

0 comments on commit 431d76f

Please sign in to comment.
You can’t perform that action at this time.