paysages3d/src/interface/modeler/quickapp/OpenGLView.cpp

48 lines
913 B
C++
Raw Normal View History

#include "OpenGLView.h"
#include <QQuickWindow>
// TEMP
#include "OpenGLRenderer.h"
#include "Scenery.h"
static OpenGLRenderer renderer;
static Scenery scenery;
OpenGLView::OpenGLView(QQuickItem *parent) :
QQuickItem(parent)
{
initialized = false;
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
scenery.autoPreset();
2014-08-19 15:37:24 +00:00
renderer.setScenery(&scenery);
}
void OpenGLView::handleWindowChanged(QQuickWindow *win)
{
if (win)
{
connect(window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
win->setClearBeforeRendering(false);
initialized = false;
}
}
void OpenGLView::paint()
{
if (not initialized)
{
renderer.initialize();
initialized = true;
}
renderer.resize(width(), height());
renderer.paint();
window()->resetOpenGLState();
}