Added pause of opengl renderer while rendering picture

This commit is contained in:
Michaël Lemaire 2015-08-18 19:12:54 +02:00
parent 0cf2add322
commit e96fdd9721
7 changed files with 64 additions and 2 deletions

View file

@ -8,6 +8,7 @@
#include "Thread.h" #include "Thread.h"
#include "Canvas.h" #include "Canvas.h"
#include "CanvasPreview.h" #include "CanvasPreview.h"
#include "OpenGLRenderer.h"
class RenderThread: public Thread class RenderThread: public Thread
{ {
@ -89,6 +90,9 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config)
image->setProperty("height", preview_size.height()); image->setProperty("height", preview_size.height());
} }
// Pause OpenGL renderer
window->getRenderer()->pause();
// Start render thread // Start render thread
render_thread = new RenderThread(renderer); render_thread = new RenderThread(renderer);
render_thread->start(); render_thread->start();
@ -145,6 +149,8 @@ void RenderProcess::timerEvent(QTimerEvent *)
render_thread->join(); render_thread->join();
delete render_thread; delete render_thread;
render_thread = NULL; render_thread = NULL;
window->getRenderer()->resume();
} }
if (renderer) if (renderer)

View file

@ -295,6 +295,11 @@ void ExplorerChunkTerrain::askInterrupt()
interrupt = true; interrupt = true;
} }
void ExplorerChunkTerrain::askResume()
{
interrupt = false;
}
Color ExplorerChunkTerrain::getTextureColor(double x, double y) Color ExplorerChunkTerrain::getTextureColor(double x, double y)
{ {
Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size}; Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size};

View file

@ -29,6 +29,7 @@ public:
void askReset(bool topology = true, bool texture = true); void askReset(bool topology = true, bool texture = true);
void askInterrupt(); void askInterrupt();
void askResume();
Color getTextureColor(double x, double y); Color getTextureColor(double x, double y);

View file

@ -16,6 +16,7 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
SoftwareRenderer(scenery) SoftwareRenderer(scenery)
{ {
ready = false; ready = false;
paused = false;
vp_width = 1; vp_width = 1;
vp_height = 1; vp_height = 1;
@ -129,7 +130,7 @@ void OpenGLRenderer::resize(int width, int height)
void OpenGLRenderer::paint() void OpenGLRenderer::paint()
{ {
if (ready) if (ready and not paused)
{ {
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -145,6 +146,18 @@ void OpenGLRenderer::paint()
} }
} }
void OpenGLRenderer::pause()
{
paused = true;
terrain->pause();
}
void OpenGLRenderer::resume()
{
paused = false;
terrain->resume();
}
void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera) void OpenGLRenderer::cameraChangeEvent(CameraDefinition *camera)
{ {
// Get camera info // Get camera info

View file

@ -26,6 +26,17 @@ public:
void resize(int width, int height); void resize(int width, int height);
void paint(); void paint();
/**
* Pause the rendering process.
*
* This will prevent paintings and stop background tasks, until resume() is called.
*/
void pause();
/**
* Resume the rendering process, put on hold by pause().
*/
void resume();
/** /**
* Change the camera location. * Change the camera location.
* *
@ -42,6 +53,7 @@ public:
private: private:
bool ready; bool ready;
bool paused;
int vp_width; int vp_width;
int vp_height; int vp_height;

View file

@ -24,7 +24,11 @@ public:
{ {
while (running) while (running)
{ {
terrain->performChunksMaintenance(); if (not terrain->isPaused())
{
terrain->performChunksMaintenance();
}
Thread::timeSleepMs(10); Thread::timeSleepMs(10);
} }
} }
@ -37,6 +41,7 @@ OpenGLTerrain::OpenGLTerrain(OpenGLRenderer *renderer):
OpenGLPart(renderer) OpenGLPart(renderer)
{ {
work = new ChunkMaintenanceThreads(this); work = new ChunkMaintenanceThreads(this);
paused = false;
} }
OpenGLTerrain::~OpenGLTerrain() OpenGLTerrain::~OpenGLTerrain()
@ -105,6 +110,21 @@ void OpenGLTerrain::interrupt()
} }
} }
void OpenGLTerrain::pause()
{
paused = true;
interrupt();
}
void OpenGLTerrain::resume()
{
for (auto &chunk: _chunks)
{
chunk->askResume();
}
paused = false;
}
void OpenGLTerrain::resetTextures() void OpenGLTerrain::resetTextures()
{ {
for (auto &chunk: _chunks) for (auto &chunk: _chunks)

View file

@ -24,6 +24,10 @@ public:
virtual void render() override; virtual void render() override;
virtual void interrupt() override; virtual void interrupt() override;
void pause();
void resume();
inline bool isPaused() const { return paused; }
/** /**
* Reset the color textures, without changing the tessellation. * Reset the color textures, without changing the tessellation.
*/ */
@ -36,6 +40,7 @@ private:
OpenGLShaderProgram* program; OpenGLShaderProgram* program;
ParallelPool* work; ParallelPool* work;
bool paused;
QVector<ExplorerChunkTerrain*> _chunks; QVector<ExplorerChunkTerrain*> _chunks;
QList<ExplorerChunkTerrain*> _updateQueue; QList<ExplorerChunkTerrain*> _updateQueue;