Fixed several renderer problems due to scenery sharing

This commit is contained in:
Michaël Lemaire 2013-12-15 18:44:54 +01:00
parent cc9c68bef9
commit 6b5a652d5c
4 changed files with 21 additions and 31 deletions

View file

@ -66,11 +66,11 @@ QGLWidget(parent)
_base_camera = camera; _base_camera = camera;
camera->copy(_current_camera); camera->copy(_current_camera);
_opengl_renderer = new OpenGLRenderer(scenery); _renderer = new OpenGLRenderer(scenery);
_opengl_renderer->prepare(); _renderer->prepare();
_opengl_renderer->render_quality = 3; _renderer->render_quality = 3;
_opengl_renderer->getLightingManager()->setSpecularity(false); _renderer->getLightingManager()->setSpecularity(false);
_opengl_renderer->disableClouds(); _renderer->disableClouds();
_inited = false; _inited = false;
_updated = false; _updated = false;
@ -92,7 +92,7 @@ WidgetExplorer::~WidgetExplorer()
delete _chunks[i]; delete _chunks[i];
} }
delete _current_camera; delete _current_camera;
delete _opengl_renderer; delete _renderer;
} }
void WidgetExplorer::startRendering() void WidgetExplorer::startRendering()
@ -102,12 +102,12 @@ void WidgetExplorer::startRendering()
double size = 400.0; double size = 400.0;
double chunksize = size / (double) chunks; double chunksize = size / (double) chunks;
double start = -size / 2.0; double start = -size / 2.0;
double water_height = _opengl_renderer->getWaterRenderer()->getHeightInfo().base_height; double water_height = _renderer->getWaterRenderer()->getHeightInfo().base_height;
for (int i = 0; i < chunks; i++) for (int i = 0; i < chunks; i++)
{ {
for (int j = 0; j < chunks; j++) for (int j = 0; j < chunks; j++)
{ {
ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_opengl_renderer, start + chunksize * (double) i, start + chunksize * (double) j, chunksize, chunks, water_height); ExplorerChunkTerrain* chunk = new ExplorerChunkTerrain(_renderer, start + chunksize * (double) i, start + chunksize * (double) j, chunksize, chunks, water_height);
_chunks.append(chunk); _chunks.append(chunk);
_updateQueue.append(chunk); _updateQueue.append(chunk);
} }
@ -116,7 +116,7 @@ void WidgetExplorer::startRendering()
// Add skybox // Add skybox
for (int orientation = 0; orientation < 5; orientation++) for (int orientation = 0; orientation < 5; orientation++)
{ {
ExplorerChunkSky* chunk = new ExplorerChunkSky(_opengl_renderer, 500.0, (SkyboxOrientation) orientation); ExplorerChunkSky* chunk = new ExplorerChunkSky(_renderer, 500.0, (SkyboxOrientation) orientation);
_chunks.append(chunk); _chunks.append(chunk);
_updateQueue.append(chunk); _updateQueue.append(chunk);
} }
@ -355,13 +355,13 @@ void WidgetExplorer::timerEvent(QTimerEvent*)
void WidgetExplorer::initializeGL() void WidgetExplorer::initializeGL()
{ {
_opengl_renderer->initialize(); _renderer->initialize();
} }
void WidgetExplorer::resizeGL(int w, int h) void WidgetExplorer::resizeGL(int w, int h)
{ {
_current_camera->setRenderSize(w, h); _current_camera->setRenderSize(w, h);
_opengl_renderer->resize(w, h); _renderer->resize(w, h);
} }
void WidgetExplorer::paintGL() void WidgetExplorer::paintGL()
@ -369,7 +369,11 @@ void WidgetExplorer::paintGL()
GLenum error_code; GLenum error_code;
QTime start_time; QTime start_time;
double frame_time; double frame_time;
WaterDefinition* water = _opengl_renderer->getScenery()->getWater(); WaterDefinition* water = _renderer->getScenery()->getWater();
// Don't do this at each frame, only on camera change
_renderer->getScenery()->setCamera(_current_camera);
_renderer->getScenery()->getCamera(_current_camera);
start_time = QTime::currentTime(); start_time = QTime::currentTime();
@ -385,7 +389,7 @@ void WidgetExplorer::paintGL()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render water // Render water
double water_height = _opengl_renderer->getTerrainRenderer()->getWaterHeight(); double water_height = _renderer->getTerrainRenderer()->getWaterHeight();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glColor3f(water->material->_rgb.r, water->material->_rgb.g, water->material->_rgb.b); glColor3f(water->material->_rgb.r, water->material->_rgb.g, water->material->_rgb.b);
glBegin(GL_QUADS); glBegin(GL_QUADS);

View file

@ -41,7 +41,7 @@ private:
CameraDefinition* _current_camera; CameraDefinition* _current_camera;
CameraDefinition* _base_camera; CameraDefinition* _base_camera;
OpenGLRenderer* _opengl_renderer; OpenGLRenderer* _renderer;
bool _inited; bool _inited;
bool _updated; bool _updated;

View file

@ -42,15 +42,10 @@ SoftwareRenderer::SoftwareRenderer(Scenery* scenery)
fluid_medium = new FluidMediumManager(this); fluid_medium = new FluidMediumManager(this);
lighting = new LightingManager(); lighting = new LightingManager();
this->scenery = new Scenery;
if (scenery) if (scenery)
{ {
this->scenery = scenery; scenery->copy(this->scenery);
own_scenery = false;
}
else
{
this->scenery = new Scenery;
own_scenery = true;
} }
} }
@ -68,19 +63,11 @@ SoftwareRenderer::~SoftwareRenderer()
delete fluid_medium; delete fluid_medium;
delete lighting; delete lighting;
if (own_scenery)
{
delete scenery; delete scenery;
}
} }
void SoftwareRenderer::setScenery(Scenery* scenery) void SoftwareRenderer::setScenery(Scenery* scenery)
{ {
if (!own_scenery)
{
this->scenery = new Scenery;
own_scenery = true;
}
scenery->copy(this->scenery); scenery->copy(this->scenery);
} }

View file

@ -98,7 +98,6 @@ public:
private: private:
Scenery* scenery; Scenery* scenery;
bool own_scenery;
FluidMediumManager* fluid_medium; FluidMediumManager* fluid_medium;
LightingManager* lighting; LightingManager* lighting;