Skip to content
Permalink
Browse files

window opens but cant render to it

  • Loading branch information
Haydelj
Haydelj committed Aug 21, 2019
1 parent 9d8a98f commit ad00751de34b6dd547aa61472dc3aa35f6c91386
@@ -6,6 +6,7 @@
*.swp
*.vcxproj*
*DS_Store
src/.ccls-cache
src/Documentation/*/*/*.aux
src/Documentation/*/*/*.blg
src/Documentation/*/*/*.bbl
@@ -47,19 +47,16 @@ const int RendererUpdateInMS = 1000 / 60;
const double updateTime = RendererUpdateInMS / 1000.0;

//------------------------------------------------------------------------------
GLWidget::GLWidget(QtGLContext* context, QWidget* parent) :
QGLWidget(context, parent),
mContext(new GLContext(this))
GLWidget::GLWidget(QWidget* parent) :
QOpenGLWidget(parent)
{
makeCurrent();
spire::glPlatformInit();
mGraphics.reset(new Render::SRInterface());

mTimer = new QTimer(this);
connect(mTimer, SIGNAL(timeout()), this, SLOT(updateRenderer()));
mTimer->start(RendererUpdateInMS);

setAutoBufferSwap(false);
//setAutoBufferSwap(false);
}

//------------------------------------------------------------------------------
@@ -75,6 +72,12 @@ GLWidget::~GLWidget()
//------------------------------------------------------------------------------
void GLWidget::initializeGL()
{

}

void GLWidget::paintGL()
{

}

//------------------------------------------------------------------------------
@@ -144,7 +147,7 @@ void GLWidget::resizeGL(int width, int height)
makeCurrent();
mGraphics->eventResize(static_cast<size_t>(width),
static_cast<size_t>(height));
updateRenderer();
//updateRenderer();
}

//------------------------------------------------------------------------------
@@ -154,38 +157,24 @@ void GLWidget::closeEvent(QCloseEvent *evt)
{
mGraphics.reset();
}
QGLWidget::closeEvent(evt);
}

//------------------------------------------------------------------------------
void GLWidget::makeCurrent()
{
mContext->makeCurrent();
QOpenGLWidget::closeEvent(evt);
}

//------------------------------------------------------------------------------
void GLWidget::updateRenderer()
{
mCurrentTime += updateTime;

#if 0
#ifdef QT5_BUILD
//idea--needs QWindow wrapper
if (!isExposed())
return;
#endif
#endif

try
if(isValid())
{
//QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
// f->glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
//f->glClear(GL_COLOR_BUFFER_BIT);
std::cout << "frame\n";
mCurrentTime += updateTime;
makeCurrent();
mGraphics->doFrame(mCurrentTime, updateTime);
mContext->swapBuffers();
}
catch (const SCIRun::Render::SRInterfaceFailure& e)
{
Q_EMIT fatalError(e.what());
mTimer->stop();
std::cout << "surface width: " << context()->surface()->size().width() << "\n";
std::cout << "surface height: " << context()->surface()->size().height() << "\n";
context()->swapBuffers(context()->surface());//mContext->swapBuffers();
}
}

@@ -46,26 +46,26 @@

#include <Interface/Modules/Render/ES/SRInterface.h>
#endif
#include <QtOpenGL/QGLWidget>
//#include <QtOpenGL/QGLWidget>
#include <QOpenGLWidget>

namespace SCIRun {
namespace Gui {

class QtGLContext;

class GLWidget : public QGLWidget
class GLWidget : public QOpenGLWidget
{
Q_OBJECT

public:
GLWidget(QtGLContext* context, QWidget* parent);
GLWidget(QWidget* parent);
~GLWidget();

std::shared_ptr<Render::SRInterface> getSpire() const {return mGraphics;}

/// Required function for single threaded interfaces that have multiple
/// contexts running on the same thread.
void makeCurrent();

void setLockZoom(bool lock) { mGraphics->setLockZoom(lock); }
void setLockPanning(bool lock) { mGraphics->setLockPanning(lock); }
@@ -86,14 +86,14 @@ public Q_SLOTS:
virtual void keyPressEvent(QKeyEvent* event);
virtual void keyReleaseEvent(QKeyEvent* event);
virtual void initializeGL();
virtual void paintGL();
virtual void resizeGL(int width, int height);
void closeEvent(QCloseEvent *evt);

private:
/// Retrieve SRInterface mouse button from mouse event.
Render::SRInterface::MouseButton getSpireButton(QMouseEvent* event);

std::shared_ptr<GLContext> mContext {}; ///< Graphics context.
std::shared_ptr<Render::SRInterface> mGraphics {}; ///< Interface to spire.
QTimer* mTimer {};
double mFrameTime {0.0};
@@ -93,23 +93,24 @@ ViewSceneDialog::ViewSceneDialog(const std::string& name, ModuleStateHandle stat
setupClippingPlanes();

// Setup Qt OpenGL widget.
QGLFormat fmt;
fmt.setAlpha(false);
fmt.setRgba(true);
fmt.setDepth(true);
fmt.setDoubleBuffer(true);
fmt.setDepthBufferSize(24);

mGLWidget = new GLWidget(new QtGLContext(fmt), parentWidget());
//QGLFormat fmt;
//fmt.setAlpha(false);
//fmt.setRgba(true);
//fmt.setDepth(true);
//fmt.setDoubleBuffer(true);
//fmt.setDepthBufferSize(24);

mGLWidget = new GLWidget(parentWidget());
QSurfaceFormat format;
format.setDepthBufferSize(24);
//format.setVersion(3, 3);
format.setProfile(QSurfaceFormat::CoreProfile);
mGLWidget->setFormat(format);
//mGLWidget->show();

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

if (!mGLWidget->isValid())
{
delete mGLWidget;
return;
}

mSpire = std::weak_ptr<SRInterface>(mGLWidget->getSpire());

//Set background Color
@@ -2141,17 +2142,17 @@ void ViewSceneDialog::setTransparencySortTypeLists(bool index)
//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::screenshotClicked()
{
takeScreenshot();
screenshotTaker_->saveScreenshot();
//takeScreenshot();
//screenshotTaker_->saveScreenshot();
}

//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::takeScreenshot()
{
if (!screenshotTaker_)
screenshotTaker_ = new Screenshot(mGLWidget, this);
// if (!screenshotTaker_)
// screenshotTaker_ = new Screenshot(mGLWidget, this);

screenshotTaker_->takeScreenshot();
// screenshotTaker_->takeScreenshot();
}

//--------------------------------------------------------------------------------------------------
@@ -2163,8 +2164,8 @@ void ViewSceneDialog::saveNewGeometryChanged(int state)
//--------------------------------------------------------------------------------------------------
void ViewSceneDialog::sendScreenshotDownstreamForTesting()
{
takeScreenshot();
state_->setTransientValue(Parameters::ScreenshotData, screenshotTaker_->toMatrix(), false);
//takeScreenshot();
//state_->setTransientValue(Parameters::ScreenshotData, screenshotTaker_->toMatrix(), false);
}

//--------------------------------------------------------------------------------------------------

0 comments on commit ad00751

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