Added an initial loading screen

This commit is contained in:
Michaël Lemaire 2015-09-14 19:25:54 +02:00
parent 84cb69e127
commit 20c03f84b7
11 changed files with 64 additions and 8 deletions

View file

@ -12,6 +12,7 @@ OpenGLView::OpenGLView(QQuickItem *parent) :
initialized = false; initialized = false;
window = NULL; window = NULL;
renderer = NULL; renderer = NULL;
delayed = 10;
setAcceptedMouseButtons(Qt::AllButtons); setAcceptedMouseButtons(Qt::AllButtons);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -44,6 +45,11 @@ void OpenGLView::handleWindowChanged(QQuickWindow *win)
void OpenGLView::paint() void OpenGLView::paint()
{ {
if (delayed > 1)
{
return;
}
if (not initialized or not renderer) if (not initialized or not renderer)
{ {
renderer->initialize(); renderer->initialize();
@ -132,6 +138,19 @@ void OpenGLView::hoverMoveEvent(QHoverEvent *event)
void OpenGLView::timerEvent(QTimerEvent *) void OpenGLView::timerEvent(QTimerEvent *)
{ {
if (delayed > 1)
{
delayed--;
}
else if (delayed == 1)
{
if (renderer->isDisplayed())
{
delayed = 0;
window->setState("Init");
}
}
if (window) if (window)
{ {
window->update(); window->update();

View file

@ -32,6 +32,7 @@ private:
double getSpeedFactor(QInputEvent *event); double getSpeedFactor(QInputEvent *event);
private: private:
int delayed;
bool initialized; bool initialized;
bool resized; bool resized;
MainModelerWindow *window; MainModelerWindow *window;

View file

@ -3,7 +3,7 @@ import Paysages 1.0
OpenGLView { OpenGLView {
id: main_ui id: main_ui
state: "Init" state: "Loading"
property string previous_state property string previous_state
width: 1280 width: 1280
@ -157,6 +157,19 @@ OpenGLView {
anchors.fill: parent anchors.fill: parent
} }
BaseRectangle {
id: loader
enabled: false
anchors.fill: parent
color: "#222429"
Text {
color: "#dddddd"
text: "Welcome to Paysages 3D..."
anchors.centerIn: parent
}
}
onStateChanged: { onStateChanged: {
if (state != "Render Dialog") if (state != "Render Dialog")
{ {
@ -165,6 +178,14 @@ OpenGLView {
} }
states: [ states: [
State {
name: "Loading"
PropertyChanges {
target: loader
enabled: true
}
},
State { State {
name: "Water Mode" name: "Water Mode"
when: primary_toolbar.current === tool_water when: primary_toolbar.current === tool_water

View file

@ -30,7 +30,7 @@ void OpenGLPart::interrupt()
OpenGLShaderProgram* OpenGLPart::createShader(QString name) OpenGLShaderProgram* OpenGLPart::createShader(QString name)
{ {
OpenGLShaderProgram* program = new OpenGLShaderProgram(name, renderer); OpenGLShaderProgram* program = new OpenGLShaderProgram(name.toStdString(), renderer);
if (!shaders.contains(name)) if (!shaders.contains(name))
{ {

View file

@ -17,6 +17,7 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
{ {
ready = false; ready = false;
paused = false; paused = false;
displayed = false;
vp_width = 1; vp_width = 1;
vp_height = 1; vp_height = 1;
@ -160,6 +161,8 @@ void OpenGLRenderer::paint()
{ {
Logs::warning() << "[OpenGL] ERROR : " << error_code << std::endl; Logs::warning() << "[OpenGL] ERROR : " << error_code << std::endl;
} }
displayed = true;
} }
} }

View file

@ -22,6 +22,7 @@ public:
inline OpenGLSkybox *getSkybox() const {return skybox;} inline OpenGLSkybox *getSkybox() const {return skybox;}
inline OpenGLWater *getWater() const {return water;} inline OpenGLWater *getWater() const {return water;}
inline OpenGLTerrain *getTerrain() const {return terrain;} inline OpenGLTerrain *getTerrain() const {return terrain;}
inline bool isDisplayed() const {return displayed;}
void initialize(); void initialize();
void prepareOpenGLState(); void prepareOpenGLState();
@ -75,6 +76,7 @@ private:
private: private:
bool ready; bool ready;
bool paused; bool paused;
bool displayed;
int vp_width; int vp_width;
int vp_height; int vp_height;

View file

@ -11,7 +11,7 @@
#include "Color.h" #include "Color.h"
#include "Logs.h" #include "Logs.h"
OpenGLShaderProgram::OpenGLShaderProgram(QString name, OpenGLRenderer* renderer): OpenGLShaderProgram::OpenGLShaderProgram(const std::string &name, OpenGLRenderer* renderer):
renderer(renderer), name(name) renderer(renderer), name(name)
{ {
program = new QOpenGLShaderProgram(); program = new QOpenGLShaderProgram();
@ -57,11 +57,11 @@ void OpenGLShaderProgram::compile()
if (not program->link()) if (not program->link())
{ {
qWarning() << "Error while compiling shader " << name << "\n" << program->log() << "\n"; Logs::warning() << "Error while compiling shader " << name << std::endl << program->log().toStdString() << std::endl;
} }
else if (program->log().length() > 0) else if (program->log().length() > 0)
{ {
qDebug() << "Shader " << name << " compilation output:\n" << program->log() << "\n"; Logs::debug() << "Shader " << name << " compilation output:" << std::endl << program->log().toStdString() << std::endl;
} }
} }

View file

@ -13,7 +13,7 @@ namespace opengl {
class OPENGLSHARED_EXPORT OpenGLShaderProgram class OPENGLSHARED_EXPORT OpenGLShaderProgram
{ {
public: public:
OpenGLShaderProgram(QString name, OpenGLRenderer* renderer); OpenGLShaderProgram(const std::string &name, OpenGLRenderer* renderer);
~OpenGLShaderProgram(); ~OpenGLShaderProgram();
void addVertexSource(QString path); void addVertexSource(QString path);
@ -38,7 +38,7 @@ private:
OpenGLRenderer* renderer; OpenGLRenderer* renderer;
QString name; std::string name;
QOpenGLShaderProgram* program; QOpenGLShaderProgram* program;
OpenGLFunctions* functions; OpenGLFunctions* functions;

View file

@ -67,7 +67,7 @@ void OpenGLSkybox::render()
{ {
program->drawTriangleStrip(vertices, 14); program->drawTriangleStrip(vertices, 14);
} }
#include "Logs.h"
void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff *) void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff *)
{ {
if (node->getPath() == "/atmosphere/daytime") if (node->getPath() == "/atmosphere/daytime")

View file

@ -1,5 +1,7 @@
#include "Logs.h" #include "Logs.h"
#include "Time.h"
static std::ostream NULL_STREAM(0); static std::ostream NULL_STREAM(0);
static bool enabled = true; static bool enabled = true;
@ -46,6 +48,11 @@ std::ostream &Logs::error()
} }
} }
void Logs::debugTimestamp(const std::string &message)
{
debug() << Time::getRelativeTimeMs() << " - " << message << std::endl;
}
void Logs::disable() void Logs::disable()
{ {
enabled = false; enabled = false;

View file

@ -18,6 +18,9 @@ public:
static std::ostream &warning(); static std::ostream &warning();
static std::ostream &error(); static std::ostream &error();
// Log a timestamp on the debug output
static void debugTimestamp(const std::string &message);
// Disable all logs from now on // Disable all logs from now on
static void disable(); static void disable();
}; };