Added ground texture resetting while changing time of day

This commit is contained in:
Michaël Lemaire 2015-07-26 18:30:30 +02:00
parent e84698dbb3
commit fc15f7d9b8
6 changed files with 38 additions and 14 deletions

View file

@ -5,6 +5,7 @@
#include "AtmosphereDefinition.h" #include "AtmosphereDefinition.h"
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "OpenGLSkybox.h" #include "OpenGLSkybox.h"
#include "OpenGLTerrain.h"
AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main): AtmosphereModeler::AtmosphereModeler(MainModelerWindow *main):
main(main) main(main)
@ -23,4 +24,7 @@ void AtmosphereModeler::daytimeChanged(double value)
main->getRenderer()->getScenery()->setAtmosphere(main->getScenery()->getAtmosphere()); main->getRenderer()->getScenery()->setAtmosphere(main->getScenery()->getAtmosphere());
main->getRenderer()->getSkybox()->update(); main->getRenderer()->getSkybox()->update();
// Update terrain textures according to new lighting
main->getRenderer()->getTerrain()->resetTextures();
} }

View file

@ -90,7 +90,7 @@ void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
{ {
render_process->stopRender(); render_process->stopRender();
rootObject()->setProperty("state", QString("Init")); setState("Init");
} }
else if (event->key() == Qt::Key_Q) else if (event->key() == Qt::Key_Q)
{ {

View file

@ -13,7 +13,8 @@ ExplorerChunkTerrain::ExplorerChunkTerrain(OpenGLRenderer* renderer, double x, d
_renderer(renderer) _renderer(renderer)
{ {
priority = 0.0; priority = 0.0;
_reset_needed = false; _reset_topology = false;
_reset_texture = false;
interrupt = false; interrupt = false;
@ -58,13 +59,17 @@ bool ExplorerChunkTerrain::maintain()
bool subchanged; bool subchanged;
_lock_data.lock(); _lock_data.lock();
if (_reset_needed) if (_reset_topology)
{ {
_reset_needed = false; _reset_topology = false;
_texture_current_size = 0;
_tessellation_current_size = 0; _tessellation_current_size = 0;
overwater = false; overwater = false;
} }
if (_reset_texture)
{
_reset_texture = false;
_texture_current_size = 0;
}
_lock_data.unlock(); _lock_data.unlock();
// Improve heightmap resolution // Improve heightmap resolution
@ -103,7 +108,7 @@ bool ExplorerChunkTerrain::maintain()
tessellated->setGridVertex(tessellation_count, i, j, v); tessellated->setGridVertex(tessellation_count, i, j, v);
} }
} }
if (interrupt or _reset_needed) if (interrupt or _reset_topology)
{ {
return false; return false;
} }
@ -143,7 +148,7 @@ bool ExplorerChunkTerrain::maintain()
} }
} }
if (interrupt or _reset_needed) if (interrupt or _reset_texture)
{ {
return false; return false;
} }
@ -216,7 +221,7 @@ void ExplorerChunkTerrain::updatePriority(CameraDefinition* camera)
} }
// Update priority // Update priority
if (_reset_needed || (_texture_max_size > 1 && _texture_current_size <= 1)) if (_reset_topology || _reset_texture || (_texture_max_size > 1 && _texture_current_size <= 1))
{ {
priority = 1000.0; priority = 1000.0;
} }
@ -259,7 +264,7 @@ void ExplorerChunkTerrain::render(QOpenGLShaderProgram* program, OpenGLFunctions
_lock_data.unlock(); _lock_data.unlock();
// Render tessellated mesh // Render tessellated mesh
if (!_reset_needed) if (!_reset_topology)
{ {
_lock_data.lock(); _lock_data.lock();
int tessellation_size = _tessellation_current_size; int tessellation_size = _tessellation_current_size;
@ -280,9 +285,10 @@ void ExplorerChunkTerrain::render(QOpenGLShaderProgram* program, OpenGLFunctions
} }
} }
void ExplorerChunkTerrain::askReset() void ExplorerChunkTerrain::askReset(bool topology, bool texture)
{ {
_reset_needed = true; _reset_topology = _reset_topology or topology;
_reset_texture = _reset_texture or texture;
} }
void ExplorerChunkTerrain::askInterrupt() void ExplorerChunkTerrain::askInterrupt()

View file

@ -27,7 +27,7 @@ public:
void updatePriority(CameraDefinition* camera); void updatePriority(CameraDefinition* camera);
void render(QOpenGLShaderProgram* program, OpenGLFunctions* functions); void render(QOpenGLShaderProgram* program, OpenGLFunctions* functions);
void askReset(); void askReset(bool topology = true, bool texture = true);
void askInterrupt(); void askInterrupt();
Color getTextureColor(double x, double y); Color getTextureColor(double x, double y);
@ -54,7 +54,8 @@ private:
OpenGLRenderer* _renderer; OpenGLRenderer* _renderer;
bool _reset_needed; bool _reset_topology;
bool _reset_texture;
bool interrupt; bool interrupt;
QImage* _texture; QImage* _texture;

View file

@ -95,12 +95,20 @@ void OpenGLTerrain::render()
void OpenGLTerrain::interrupt() void OpenGLTerrain::interrupt()
{ {
for (auto chunk: _chunks) for (auto &chunk: _chunks)
{ {
chunk->askInterrupt(); chunk->askInterrupt();
} }
} }
void OpenGLTerrain::resetTextures()
{
for (auto &chunk: _chunks)
{
chunk->askReset(false, true);
}
}
static bool _cmpChunks(const ExplorerChunkTerrain* c1, const ExplorerChunkTerrain* c2) static bool _cmpChunks(const ExplorerChunkTerrain* c1, const ExplorerChunkTerrain* c2)
{ {
return c1->priority > c2->priority; return c1->priority > c2->priority;

View file

@ -23,6 +23,11 @@ public:
virtual void render() override; virtual void render() override;
virtual void interrupt() override; virtual void interrupt() override;
/**
* Reset the color textures, without changing the tessellation.
*/
void resetTextures();
void performChunksMaintenance(); void performChunksMaintenance();
private: private: