2014-08-19 13:49:08 +00:00
|
|
|
#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();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-19 15:01:42 +00:00
|
|
|
renderer.resize(width(), height());
|
2014-08-19 13:49:08 +00:00
|
|
|
renderer.paint();
|
2014-08-19 15:01:42 +00:00
|
|
|
|
|
|
|
window()->resetOpenGLState();
|
2014-08-19 13:49:08 +00:00
|
|
|
}
|