Added pause of opengl renderer while rendering picture
This commit is contained in:
parent
0cf2add322
commit
e96fdd9721
7 changed files with 64 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "Thread.h"
|
||||
#include "Canvas.h"
|
||||
#include "CanvasPreview.h"
|
||||
#include "OpenGLRenderer.h"
|
||||
|
||||
class RenderThread: public Thread
|
||||
{
|
||||
|
@ -89,6 +90,9 @@ void RenderProcess::startRender(Scenery *scenery, const RenderConfig &config)
|
|||
image->setProperty("height", preview_size.height());
|
||||
}
|
||||
|
||||
// Pause OpenGL renderer
|
||||
window->getRenderer()->pause();
|
||||
|
||||
// Start render thread
|
||||
render_thread = new RenderThread(renderer);
|
||||
render_thread->start();
|
||||
|
@ -145,6 +149,8 @@ void RenderProcess::timerEvent(QTimerEvent *)
|
|||
render_thread->join();
|
||||
delete render_thread;
|
||||
render_thread = NULL;
|
||||
|
||||
window->getRenderer()->resume();
|
||||
}
|
||||
|
||||
if (renderer)
|
||||
|
|
|
@ -295,6 +295,11 @@ void ExplorerChunkTerrain::askInterrupt()
|
|||
interrupt = true;
|
||||
}
|
||||
|
||||
void ExplorerChunkTerrain::askResume()
|
||||
{
|
||||
interrupt = false;
|
||||
}
|
||||
|
||||
Color ExplorerChunkTerrain::getTextureColor(double x, double y)
|
||||
{
|
||||
Vector3 location = {_startx + x * _size, 0.0, _startz + y * _size};
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
void askReset(bool topology = true, bool texture = true);
|
||||
void askInterrupt();
|
||||
void askResume();
|
||||
|
||||
Color getTextureColor(double x, double y);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
|
|||
SoftwareRenderer(scenery)
|
||||
{
|
||||
ready = false;
|
||||
paused = false;
|
||||
vp_width = 1;
|
||||
vp_height = 1;
|
||||
|
||||
|
@ -129,7 +130,7 @@ void OpenGLRenderer::resize(int width, int height)
|
|||
|
||||
void OpenGLRenderer::paint()
|
||||
{
|
||||
if (ready)
|
||||
if (ready and not paused)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Get camera info
|
||||
|
|
|
@ -26,6 +26,17 @@ public:
|
|||
void resize(int width, int height);
|
||||
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.
|
||||
*
|
||||
|
@ -42,6 +53,7 @@ public:
|
|||
|
||||
private:
|
||||
bool ready;
|
||||
bool paused;
|
||||
int vp_width;
|
||||
int vp_height;
|
||||
|
||||
|
|
|
@ -23,8 +23,12 @@ public:
|
|||
virtual void work() override
|
||||
{
|
||||
while (running)
|
||||
{
|
||||
if (not terrain->isPaused())
|
||||
{
|
||||
terrain->performChunksMaintenance();
|
||||
}
|
||||
|
||||
Thread::timeSleepMs(10);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +41,7 @@ OpenGLTerrain::OpenGLTerrain(OpenGLRenderer *renderer):
|
|||
OpenGLPart(renderer)
|
||||
{
|
||||
work = new ChunkMaintenanceThreads(this);
|
||||
paused = false;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
for (auto &chunk: _chunks)
|
||||
|
|
|
@ -24,6 +24,10 @@ public:
|
|||
virtual void render() override;
|
||||
virtual void interrupt() override;
|
||||
|
||||
void pause();
|
||||
void resume();
|
||||
inline bool isPaused() const { return paused; }
|
||||
|
||||
/**
|
||||
* Reset the color textures, without changing the tessellation.
|
||||
*/
|
||||
|
@ -36,6 +40,7 @@ private:
|
|||
OpenGLShaderProgram* program;
|
||||
|
||||
ParallelPool* work;
|
||||
bool paused;
|
||||
|
||||
QVector<ExplorerChunkTerrain*> _chunks;
|
||||
QList<ExplorerChunkTerrain*> _updateQueue;
|
||||
|
|
Loading…
Reference in a new issue