paysages : Fixed some crash when starting renders.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@487 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-12-24 14:13:19 +00:00 committed by ThunderK
parent a50b0a25c2
commit 67eadf9048
5 changed files with 37 additions and 28 deletions

View file

@ -3,10 +3,10 @@
BaseExplorerChunk::BaseExplorerChunk(Renderer* renderer) BaseExplorerChunk::BaseExplorerChunk(Renderer* renderer)
{ {
_renderer = renderer; _renderer = renderer;
priority = 0.0; priority = 0.0;
_reset_needed = false; _reset_needed = false;
_texture = new QImage(1, 1, QImage::Format_ARGB32); _texture = new QImage(1, 1, QImage::Format_ARGB32);
_texture_id = 0; _texture_id = 0;
_texture_changed = false; _texture_changed = false;
@ -24,7 +24,7 @@ BaseExplorerChunk::~BaseExplorerChunk()
bool BaseExplorerChunk::maintain() bool BaseExplorerChunk::maintain()
{ {
bool subchanged; bool subchanged;
_lock_data.lock(); _lock_data.lock();
if (_reset_needed) if (_reset_needed)
{ {
@ -33,9 +33,9 @@ bool BaseExplorerChunk::maintain()
onResetEvent(); onResetEvent();
} }
_lock_data.unlock(); _lock_data.unlock();
subchanged = onMaintainEvent(); subchanged = onMaintainEvent();
// Improve texture resolution // Improve texture resolution
if (_texture_current_size < _texture_max_size) if (_texture_current_size < _texture_max_size)
{ {
@ -60,7 +60,7 @@ bool BaseExplorerChunk::maintain()
_texture_current_size = new_texture_size; _texture_current_size = new_texture_size;
_texture_changed = true; _texture_changed = true;
_lock_data.unlock(); _lock_data.unlock();
return true; return true;
} }
else else
@ -108,7 +108,7 @@ void BaseExplorerChunk::render(QGLWidget* widget)
glBindTexture(GL_TEXTURE_2D, _texture_id); glBindTexture(GL_TEXTURE_2D, _texture_id);
} }
_lock_data.unlock(); _lock_data.unlock();
// Delegate poly rendering to subclass // Delegate poly rendering to subclass
onRenderEvent(widget); onRenderEvent(widget);
} }
@ -123,7 +123,7 @@ void BaseExplorerChunk::setMaxTextureSize(int size)
_texture_max_size = size; _texture_max_size = size;
} }
void BaseExplorerChunk::onCameraEvent(CameraDefinition* camera) void BaseExplorerChunk::onCameraEvent(CameraDefinition*)
{ {
} }
@ -136,16 +136,16 @@ bool BaseExplorerChunk::onMaintainEvent()
return false; return false;
} }
void BaseExplorerChunk::onRenderEvent(QGLWidget* widget) void BaseExplorerChunk::onRenderEvent(QGLWidget*)
{ {
} }
double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition* camera) double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition*)
{ {
return 0.0; return 0.0;
} }
Color BaseExplorerChunk::getTextureColor(double x, double y) Color BaseExplorerChunk::getTextureColor(double, double)
{ {
return COLOR_TRANSPARENT; return COLOR_TRANSPARENT;
} }

View file

@ -21,18 +21,18 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad
QWidget* form; QWidget* form;
QGridLayout* form_layout; QGridLayout* form_layout;
QLabel* label; QLabel* label;
_base = gradation; _base = gradation;
_current = colorGradationCreate(); _current = colorGradationCreate();
colorGradationCopy(_base, _current); colorGradationCopy(_base, _current);
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
form = new QWidget(this); form = new QWidget(this);
form_layout = new QGridLayout(); form_layout = new QGridLayout();
form->setLayout(form_layout); form->setLayout(form_layout);
layout()->addWidget(form); layout()->addWidget(form);
label = new QLabel(tr("This is the curve editor for color components.\nClick on a component preview below to edit it.\nClick on points and drag them to move them.\nDouble click to add a new point.\nRight click on a point to delete it."), form); label = new QLabel(tr("This is the curve editor for color components.\nClick on a component preview below to edit it.\nClick on points and drag them to move them.\nDouble click to add a new point.\nRight click on a point to delete it."), form);
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
label->setMinimumWidth(150); label->setMinimumWidth(150);
@ -94,11 +94,11 @@ DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* grad
_preview_final->setMaximumHeight(60); _preview_final->setMaximumHeight(60);
_preview_final->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); _preview_final->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
form_layout->addWidget(_preview_final, 4, 0); form_layout->addWidget(_preview_final, 4, 0);
buttons = new QWidget(this); buttons = new QWidget(this);
layout()->addWidget(buttons); layout()->addWidget(buttons);
buttons->setLayout(new QHBoxLayout()); buttons->setLayout(new QHBoxLayout());
_button_accept = new QPushButton(tr("Validate"), buttons); _button_accept = new QPushButton(tr("Validate"), buttons);
buttons->layout()->addWidget(_button_accept); buttons->layout()->addWidget(_button_accept);
QObject::connect(_button_accept, SIGNAL(clicked()), this, SLOT(accept())); QObject::connect(_button_accept, SIGNAL(clicked()), this, SLOT(accept()));
@ -137,7 +137,7 @@ bool DialogColorGradation::getGradation(QWidget* parent, ColorGradation* gradati
return (result != 0) ? true : false; return (result != 0) ? true : false;
} }
void DialogColorGradation::closeEvent(QCloseEvent* e) void DialogColorGradation::closeEvent(QCloseEvent*)
{ {
reject(); reject();
} }
@ -182,10 +182,10 @@ void DialogColorGradation::selectBlue()
void DialogColorGradation::updateColors() void DialogColorGradation::updateColors()
{ {
Curve* curve; Curve* curve;
curve = curveCreate(); curve = curveCreate();
_curve_editor->getCurve(curve); _curve_editor->getCurve(curve);
switch (_selected) switch (_selected)
{ {
case 0: case 0:
@ -209,7 +209,7 @@ void DialogColorGradation::updateColors()
; ;
} }
_preview_final->update(); _preview_final->update();
curveDelete(curve); curveDelete(curve);
} }

View file

@ -15,9 +15,12 @@ static DialogRender* _current_dialog;
static void _renderStart(int width, int height, Color background) static void _renderStart(int width, int height, Color background)
{ {
_current_dialog->pixbuf_lock->lock();
delete _current_dialog->pixbuf; delete _current_dialog->pixbuf;
_current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32); _current_dialog->pixbuf = new QImage(width, height, QImage::Format_ARGB32);
_current_dialog->pixbuf->fill(colorToQColor(background).rgb()); _current_dialog->pixbuf->fill(colorToQColor(background).rgb());
_current_dialog->pixbuf_lock->unlock();
_current_dialog->tellRenderSize(width, height); _current_dialog->tellRenderSize(width, height);
} }
@ -61,18 +64,21 @@ public:
void paintEvent(QPaintEvent*) void paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
_current_dialog->pixbuf_lock->lock();
painter.drawImage(0, 0, *_current_dialog->pixbuf); painter.drawImage(0, 0, *_current_dialog->pixbuf);
_current_dialog->pixbuf_lock->unlock();
} }
}; };
DialogRender::DialogRender(QWidget *parent, Renderer* renderer): DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
QDialog(parent, Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint) QDialog(parent, Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint)
{ {
pixbuf_lock = new QMutex();
pixbuf = new QImage(1, 1, QImage::Format_ARGB32); pixbuf = new QImage(1, 1, QImage::Format_ARGB32);
_current_dialog = this; _current_dialog = this;
_render_thread = NULL; _render_thread = NULL;
_renderer = renderer; _renderer = renderer;
setModal(true); setModal(true);
setWindowTitle(tr("Paysages 3D - Render")); setWindowTitle(tr("Paysages 3D - Render"));
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
@ -82,21 +88,21 @@ DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
area = new RenderArea(_scroll); area = new RenderArea(_scroll);
_scroll->setWidget(area); _scroll->setWidget(area);
layout()->addWidget(_scroll); layout()->addWidget(_scroll);
_info = new QWidget(this); _info = new QWidget(this);
_info->setLayout(new QHBoxLayout()); _info->setLayout(new QHBoxLayout());
layout()->addWidget(_info); layout()->addWidget(_info);
_timer = new QLabel(QString("0:00.00"), _info); _timer = new QLabel(QString("0:00.00"), _info);
_info->layout()->addWidget(_timer); _info->layout()->addWidget(_timer);
_progress = new QProgressBar(_info); _progress = new QProgressBar(_info);
_progress->setMaximumHeight(12); _progress->setMaximumHeight(12);
_progress->setMinimum(0); _progress->setMinimum(0);
_progress->setMaximum(1000); _progress->setMaximum(1000);
_progress->setValue(0); _progress->setValue(0);
_info->layout()->addWidget(_progress); _info->layout()->addWidget(_progress);
connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int))); connect(this, SIGNAL(renderSizeChanged(int, int)), this, SLOT(applyRenderSize(int, int)));
connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double))); connect(this, SIGNAL(progressChanged(double)), this, SLOT(applyProgress(double)));
} }
@ -111,6 +117,7 @@ DialogRender::~DialogRender()
delete _render_thread; delete _render_thread;
} }
delete pixbuf; delete pixbuf;
delete pixbuf_lock;
} }
void DialogRender::tellRenderSize(int width, int height) void DialogRender::tellRenderSize(int width, int height)
@ -126,7 +133,7 @@ void DialogRender::tellProgressChange(double value)
void DialogRender::startRender(RenderParams params) void DialogRender::startRender(RenderParams params)
{ {
_started = time(NULL); _started = time(NULL);
//applyRenderSize(params.width, params.height); //applyRenderSize(params.width, params.height);
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate); rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);

View file

@ -7,6 +7,7 @@
#include <QProgressBar> #include <QProgressBar>
#include <QScrollArea> #include <QScrollArea>
#include <QLabel> #include <QLabel>
#include <QMutex>
#include "../lib_paysages/renderer.h" #include "../lib_paysages/renderer.h"
class DialogRender : public QDialog class DialogRender : public QDialog
@ -22,12 +23,13 @@ public:
void loadLastRender(); void loadLastRender();
QImage* pixbuf; QImage* pixbuf;
QMutex* pixbuf_lock;
QWidget* area; QWidget* area;
private slots: private slots:
void applyRenderSize(int width, int height); void applyRenderSize(int width, int height);
void applyProgress(double value); void applyProgress(double value);
signals: signals:
void renderSizeChanged(int width, int height); void renderSizeChanged(int width, int height);
void progressChanged(double value); void progressChanged(double value);

View file

@ -91,7 +91,7 @@ private:
lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status); lightingGetStatus((LightingDefinition*)renderer->customData[2], renderer, location, status);
} }
static Color _applyAerialPerspective(Renderer* renderer, Vector3 location, Color base) static Color _applyAerialPerspective(Renderer*, Vector3, Color base)
{ {
return base; return base;
} }