paysages : Started work for FSAA.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@346 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
cb929bcd87
commit
7f1e20544f
12 changed files with 131 additions and 111 deletions
24
cli/main.c
24
cli/main.c
|
@ -7,10 +7,10 @@
|
||||||
#include "../lib_paysages/render.h"
|
#include "../lib_paysages/render.h"
|
||||||
#include "../lib_paysages/scenery.h"
|
#include "../lib_paysages/scenery.h"
|
||||||
|
|
||||||
void startRender(Renderer* renderer, char* outputpath, int width, int height, int quality)
|
void startRender(Renderer* renderer, char* outputpath, RenderParams params)
|
||||||
{
|
{
|
||||||
printf("\rRendering %s ... \n", outputpath);
|
printf("\rRendering %s ... \n", outputpath);
|
||||||
rendererStart(renderer, width, height, quality);
|
rendererStart(renderer, params);
|
||||||
printf("\rSaving %s ... \n", outputpath);
|
printf("\rSaving %s ... \n", outputpath);
|
||||||
remove(outputpath);
|
remove(outputpath);
|
||||||
renderSaveToFile(renderer->render_area, outputpath);
|
renderSaveToFile(renderer->render_area, outputpath);
|
||||||
|
@ -26,6 +26,7 @@ void displayHelp()
|
||||||
printf(" -rw x Render width (int)\n");
|
printf(" -rw x Render width (int)\n");
|
||||||
printf(" -rh x Render height (int)\n");
|
printf(" -rh x Render height (int)\n");
|
||||||
printf(" -rq x Render quality (int, 1 to 10)\n");
|
printf(" -rq x Render quality (int, 1 to 10)\n");
|
||||||
|
printf(" -ra x Render anti-aliasing (int, 1 to 4)\n");
|
||||||
printf(" -di x Day start time (float, 0.0 to 1.0)\n");
|
printf(" -di x Day start time (float, 0.0 to 1.0)\n");
|
||||||
printf(" -ds x Day step time (float)\n");
|
printf(" -ds x Day step time (float)\n");
|
||||||
}
|
}
|
||||||
|
@ -40,9 +41,7 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Renderer renderer;
|
Renderer renderer;
|
||||||
char* conf_file_path = NULL;
|
char* conf_file_path = NULL;
|
||||||
int conf_render_width = 800;
|
RenderParams conf_render_params = {800, 600, 1, 5};
|
||||||
int conf_render_height = 600;
|
|
||||||
int conf_render_quality = 5;
|
|
||||||
int conf_nb_pictures = 1;
|
int conf_nb_pictures = 1;
|
||||||
double conf_daytime_start = 0.4;
|
double conf_daytime_start = 0.4;
|
||||||
double conf_daytime_step = 0.0;
|
double conf_daytime_step = 0.0;
|
||||||
|
@ -77,21 +76,28 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc--)
|
if (argc--)
|
||||||
{
|
{
|
||||||
conf_render_width = atoi(*(++argv));
|
conf_render_params.width = atoi(*(++argv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(*argv, "-rh") == 0 || strcmp(*argv, "--height") == 0)
|
else if (strcmp(*argv, "-rh") == 0 || strcmp(*argv, "--height") == 0)
|
||||||
{
|
{
|
||||||
if (argc--)
|
if (argc--)
|
||||||
{
|
{
|
||||||
conf_render_height = atoi(*(++argv));
|
conf_render_params.height = atoi(*(++argv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(*argv, "-rq") == 0 || strcmp(*argv, "--quality") == 0)
|
else if (strcmp(*argv, "-rq") == 0 || strcmp(*argv, "--quality") == 0)
|
||||||
{
|
{
|
||||||
if (argc--)
|
if (argc--)
|
||||||
{
|
{
|
||||||
conf_render_quality = atoi(*(++argv));
|
conf_render_params.quality = atoi(*(++argv));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strcmp(*argv, "-ra") == 0 || strcmp(*argv, "--antialias") == 0)
|
||||||
|
{
|
||||||
|
if (argc--)
|
||||||
|
{
|
||||||
|
conf_render_params.antialias = atoi(*(++argv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(*argv, "-di") == 0 || strcmp(*argv, "--daystart") == 0)
|
else if (strcmp(*argv, "-di") == 0 || strcmp(*argv, "--daystart") == 0)
|
||||||
|
@ -128,7 +134,7 @@ int main(int argc, char** argv)
|
||||||
autoSetDaytimeFraction(conf_daytime_start);
|
autoSetDaytimeFraction(conf_daytime_start);
|
||||||
|
|
||||||
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
||||||
startRender(&renderer, outputpath, conf_render_width, conf_render_height, conf_render_quality);
|
startRender(&renderer, outputpath, conf_render_params);
|
||||||
|
|
||||||
conf_daytime_start += conf_daytime_step;
|
conf_daytime_start += conf_daytime_step;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,22 +32,18 @@ static void _renderUpdate(double progress)
|
||||||
class RenderThread:public QThread
|
class RenderThread:public QThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderThread(Renderer* renderer, int width, int height, int quality):QThread()
|
RenderThread(Renderer* renderer, RenderParams params):QThread()
|
||||||
{
|
{
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
_width = width;
|
_params = params;
|
||||||
_height = height;
|
|
||||||
_quality = quality;
|
|
||||||
}
|
}
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
rendererStart(_renderer, _width, _height, _quality);
|
rendererStart(_renderer, _params);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Renderer* _renderer;
|
Renderer* _renderer;
|
||||||
int _width;
|
RenderParams _params;
|
||||||
int _height;
|
|
||||||
int _quality;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderArea:public QWidget
|
class RenderArea:public QWidget
|
||||||
|
@ -109,12 +105,12 @@ DialogRender::~DialogRender()
|
||||||
delete pixbuf;
|
delete pixbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogRender::startRender(int quality, int width, int height)
|
void DialogRender::startRender(RenderParams params)
|
||||||
{
|
{
|
||||||
applyRenderSize(width, height);
|
applyRenderSize(params.width, params.height);
|
||||||
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
|
rendererSetPreviewCallbacks(_renderer, _renderStart, _renderDraw, _renderUpdate);
|
||||||
|
|
||||||
render_thread = new RenderThread(_renderer, width, height, quality);
|
render_thread = new RenderThread(_renderer, params);
|
||||||
render_thread->start();
|
render_thread->start();
|
||||||
|
|
||||||
exec();
|
exec();
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
explicit DialogRender(QWidget *parent, Renderer* renderer);
|
explicit DialogRender(QWidget *parent, Renderer* renderer);
|
||||||
~DialogRender();
|
~DialogRender();
|
||||||
|
|
||||||
void startRender(int quality, int width, int height);
|
void startRender(RenderParams params);
|
||||||
void loadLastRender();
|
void loadLastRender();
|
||||||
|
|
||||||
QImage* pixbuf;
|
QImage* pixbuf;
|
||||||
|
|
|
@ -96,9 +96,10 @@ FormRender::FormRender(QWidget *parent) :
|
||||||
{
|
{
|
||||||
QPushButton* button;
|
QPushButton* button;
|
||||||
|
|
||||||
_quality = 5;
|
_params.quality = 5;
|
||||||
_width = 800;
|
_params.width = 800;
|
||||||
_height = 600;
|
_params.height = 600;
|
||||||
|
_params.antialias = 1;
|
||||||
_camera = cameraCreateDefinition();
|
_camera = cameraCreateDefinition();
|
||||||
|
|
||||||
_renderer_inited = false;
|
_renderer_inited = false;
|
||||||
|
@ -107,9 +108,10 @@ FormRender::FormRender(QWidget *parent) :
|
||||||
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
addPreview(_preview_landscape, QString(tr("Top-down preview")));
|
||||||
|
|
||||||
addInput(new InputCamera(this, tr("Camera"), &_camera));
|
addInput(new InputCamera(this, tr("Camera"), &_camera));
|
||||||
addInputInt(tr("Quality"), &_quality, 1, 10, 1, 1);
|
addInputInt(tr("Quality"), &_params.quality, 1, 10, 1, 1);
|
||||||
addInputInt(tr("Image width"), &_width, 100, 2000, 10, 100);
|
addInputInt(tr("Image width"), &_params.width, 100, 2000, 10, 100);
|
||||||
addInputInt(tr("Image height"), &_height, 100, 2000, 10, 100);
|
addInputInt(tr("Image height"), &_params.height, 100, 2000, 10, 100);
|
||||||
|
addInputInt(tr("Anti aliasing"), &_params.antialias, 1, 4, 1, 1);
|
||||||
|
|
||||||
button = addButton(tr("Start new render"));
|
button = addButton(tr("Start new render"));
|
||||||
connect(button, SIGNAL(clicked()), this, SLOT(startRender()));
|
connect(button, SIGNAL(clicked()), this, SLOT(startRender()));
|
||||||
|
@ -157,7 +159,8 @@ void FormRender::startQuickRender()
|
||||||
_renderer_inited = true;
|
_renderer_inited = true;
|
||||||
|
|
||||||
DialogRender* dialog = new DialogRender(this, &_renderer);
|
DialogRender* dialog = new DialogRender(this, &_renderer);
|
||||||
dialog->startRender(3, 400, 300);
|
RenderParams params = {400, 300, 1, 3};
|
||||||
|
dialog->startRender(params);
|
||||||
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +175,7 @@ void FormRender::startRender()
|
||||||
_renderer_inited = true;
|
_renderer_inited = true;
|
||||||
|
|
||||||
DialogRender* dialog = new DialogRender(this, &_renderer);
|
DialogRender* dialog = new DialogRender(this, &_renderer);
|
||||||
dialog->startRender(_quality, _width, _height);
|
dialog->startRender(_params);
|
||||||
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "baseform.h"
|
#include "baseform.h"
|
||||||
#include "../lib_paysages/camera.h"
|
#include "../lib_paysages/camera.h"
|
||||||
#include "../lib_paysages/renderer.h"
|
#include "../lib_paysages/renderer.h"
|
||||||
|
#include "../lib_paysages/render.h"
|
||||||
|
|
||||||
class FormRender : public BaseForm
|
class FormRender : public BaseForm
|
||||||
{
|
{
|
||||||
|
@ -27,9 +28,7 @@ private slots:
|
||||||
void saveRender();
|
void saveRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _quality;
|
RenderParams _params;
|
||||||
int _width;
|
|
||||||
int _height;
|
|
||||||
CameraDefinition _camera;
|
CameraDefinition _camera;
|
||||||
Renderer _renderer;
|
Renderer _renderer;
|
||||||
bool _renderer_inited;
|
bool _renderer_inited;
|
||||||
|
|
|
@ -250,7 +250,7 @@ Maintenir Ctrl : Plus lent</translation>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogRender</name>
|
<name>DialogRender</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/dialogrender.cpp" line="80"/>
|
<location filename="../gui_qt/dialogrender.cpp" line="76"/>
|
||||||
<source>Paysages 3D - Render</source>
|
<source>Paysages 3D - Render</source>
|
||||||
<translation>Paysages 3D - Rendu</translation>
|
<translation>Paysages 3D - Rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -511,57 +511,62 @@ Maintenir Ctrl : Plus rapide</translation>
|
||||||
<context>
|
<context>
|
||||||
<name>FormRender</name>
|
<name>FormRender</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="107"/>
|
<location filename="../gui_qt/formrender.cpp" line="108"/>
|
||||||
<source>Top-down preview</source>
|
<source>Top-down preview</source>
|
||||||
<translation>Aperçu plongeant</translation>
|
<translation>Aperçu plongeant</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="109"/>
|
<location filename="../gui_qt/formrender.cpp" line="110"/>
|
||||||
<source>Camera</source>
|
<source>Camera</source>
|
||||||
<translation>Caméra</translation>
|
<translation>Caméra</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="110"/>
|
<location filename="../gui_qt/formrender.cpp" line="111"/>
|
||||||
<source>Quality</source>
|
<source>Quality</source>
|
||||||
<translation>Qualité de rendu</translation>
|
<translation>Qualité de rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="111"/>
|
<location filename="../gui_qt/formrender.cpp" line="112"/>
|
||||||
<source>Image width</source>
|
<source>Image width</source>
|
||||||
<translation>Largeur de l'image</translation>
|
<translation>Largeur de l'image</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="112"/>
|
<location filename="../gui_qt/formrender.cpp" line="113"/>
|
||||||
<source>Image height</source>
|
<source>Image height</source>
|
||||||
<translation>Hauteur de l'image</translation>
|
<translation>Hauteur de l'image</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="114"/>
|
<location filename="../gui_qt/formrender.cpp" line="114"/>
|
||||||
|
<source>Anti aliasing</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../gui_qt/formrender.cpp" line="116"/>
|
||||||
<source>Start new render</source>
|
<source>Start new render</source>
|
||||||
<translation>Démarrer un rendu</translation>
|
<translation>Démarrer un rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="116"/>
|
<location filename="../gui_qt/formrender.cpp" line="118"/>
|
||||||
<source>Show last render</source>
|
<source>Show last render</source>
|
||||||
<translation>Voir le dernier rendu</translation>
|
<translation>Voir le dernier rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="118"/>
|
<location filename="../gui_qt/formrender.cpp" line="120"/>
|
||||||
<source>Save last render</source>
|
<source>Save last render</source>
|
||||||
<translation>Sauvegarder le dernier rendu</translation>
|
<translation>Sauvegarder le dernier rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="197"/>
|
<location filename="../gui_qt/formrender.cpp" line="200"/>
|
||||||
<source>Paysages 3D - Choose a filename to save the last render</source>
|
<source>Paysages 3D - Choose a filename to save the last render</source>
|
||||||
<translation>Paysages 3D - Choisissez un nom de fichier pour le rendu</translation>
|
<translation>Paysages 3D - Choisissez un nom de fichier pour le rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="197"/>
|
<location filename="../gui_qt/formrender.cpp" line="200"/>
|
||||||
<source>Images (*.png *.jpg)</source>
|
<source>Images (*.png *.jpg)</source>
|
||||||
<translation>Images (*.png *.jpg)</translation>
|
<translation>Images (*.png *.jpg)</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="210"/>
|
<location filename="../gui_qt/formrender.cpp" line="213"/>
|
||||||
<source>Can't write to file : %1</source>
|
<source>Can't write to file : %1</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -574,7 +579,7 @@ Maintenir Ctrl : Plus rapide</translation>
|
||||||
<translation type="obsolete">Choisissez un nom de fichier pour le rendu</translation>
|
<translation type="obsolete">Choisissez un nom de fichier pour le rendu</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../gui_qt/formrender.cpp" line="206"/>
|
<location filename="../gui_qt/formrender.cpp" line="209"/>
|
||||||
<source>The picture %1 has been saved.</source>
|
<source>The picture %1 has been saved.</source>
|
||||||
<translation>L'image %1 a été sauvegardée.</translation>
|
<translation>L'image %1 a été sauvegardée.</translation>
|
||||||
</message>
|
</message>
|
||||||
|
|
|
@ -168,10 +168,10 @@ CloudsLayerDefinition cloudsLayerCreateDefinition()
|
||||||
result.edge_length = 0.25;
|
result.edge_length = 0.25;
|
||||||
result.base_coverage = 0.35;
|
result.base_coverage = 0.35;
|
||||||
result.shape_noise = noiseCreateGenerator();
|
result.shape_noise = noiseCreateGenerator();
|
||||||
noiseGenerateBaseNoise(result.shape_noise, 20000);
|
noiseGenerateBaseNoise(result.shape_noise, 200000);
|
||||||
noiseAddLevelsSimple(result.shape_noise, 4, 1.0, 1.0);
|
noiseAddLevelsSimple(result.shape_noise, 4, 1.0, 1.0);
|
||||||
result.edge_noise = noiseCreateGenerator();
|
result.edge_noise = noiseCreateGenerator();
|
||||||
noiseGenerateBaseNoise(result.edge_noise, 20000);
|
noiseGenerateBaseNoise(result.edge_noise, 800000);
|
||||||
noiseAddLevelsSimple(result.edge_noise, 8, 1.0, 1.0);
|
noiseAddLevelsSimple(result.edge_noise, 8, 1.0, 1.0);
|
||||||
|
|
||||||
result._custom_coverage = _standardCoverageFunc;
|
result._custom_coverage = _standardCoverageFunc;
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
|
|
||||||
struct RenderArea
|
struct RenderArea
|
||||||
{
|
{
|
||||||
int width;
|
RenderParams params;
|
||||||
int height;
|
|
||||||
int pixel_count;
|
int pixel_count;
|
||||||
Array* pixels;
|
Array* pixels;
|
||||||
RenderFragment* scanline_up;
|
RenderFragment* scanline_up;
|
||||||
|
@ -53,8 +52,10 @@ RenderArea* renderCreateArea()
|
||||||
RenderArea* result;
|
RenderArea* result;
|
||||||
|
|
||||||
result = malloc(sizeof(RenderArea));
|
result = malloc(sizeof(RenderArea));
|
||||||
result->width = 1;
|
result->params.width = 1;
|
||||||
result->height = 1;
|
result->params.height = 1;
|
||||||
|
result->params.antialias = 1;
|
||||||
|
result->params.quality = 5;
|
||||||
result->pixel_count = 1;
|
result->pixel_count = 1;
|
||||||
result->pixels = malloc(sizeof(Array));
|
result->pixels = malloc(sizeof(Array));
|
||||||
arrayCreate(result->pixels, sizeof(RenderFragment));
|
arrayCreate(result->pixels, sizeof(RenderFragment));
|
||||||
|
@ -81,11 +82,11 @@ void renderDeleteArea(RenderArea* area)
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
for (x = 0; x < area->width; x++)
|
for (x = 0; x < area->params.width * area->params.antialias; x++)
|
||||||
{
|
{
|
||||||
for (y = 0; y < area->height; y++)
|
for (y = 0; y < area->params.height * area->params.antialias; y++)
|
||||||
{
|
{
|
||||||
arrayDelete(area->pixels + (y * area->width + x));
|
arrayDelete(area->pixels + (y * area->params.width * area->params.antialias + x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,21 +97,23 @@ void renderDeleteArea(RenderArea* area)
|
||||||
free(area);
|
free(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSetSize(RenderArea* area, int width, int height)
|
void renderSetParams(RenderArea* area, RenderParams params)
|
||||||
{
|
{
|
||||||
int x;
|
int x, y;
|
||||||
int y;
|
int width, height;
|
||||||
|
|
||||||
|
width = params.width * params.antialias;
|
||||||
|
height = params.height * params.antialias;
|
||||||
|
|
||||||
for (x = 0; x < area->width; x++)
|
for (x = 0; x < area->params.width * area->params.antialias; x++)
|
||||||
{
|
{
|
||||||
for (y = 0; y < area->height; y++)
|
for (y = 0; y < area->params.height * area->params.antialias; y++)
|
||||||
{
|
{
|
||||||
arrayDelete(area->pixels + (y * area->width + x));
|
arrayDelete(area->pixels + (y * area->params.width * area->params.antialias + x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
area->width = width;
|
area->params = params;
|
||||||
area->height = height;
|
|
||||||
area->pixels = realloc(area->pixels, sizeof(Array) * width * height);
|
area->pixels = realloc(area->pixels, sizeof(Array) * width * height);
|
||||||
area->pixel_count = width * height;
|
area->pixel_count = width * height;
|
||||||
|
|
||||||
|
@ -144,22 +147,22 @@ void renderClear(RenderArea* area)
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
for (x = 0; x < area->width; x++)
|
for (x = 0; x < area->params.width * area->params.antialias; x++)
|
||||||
{
|
{
|
||||||
for (y = 0; y < area->height; y++)
|
for (y = 0; y < area->params.height * area->params.antialias; y++)
|
||||||
{
|
{
|
||||||
arrayClear(area->pixels + (y * area->width + x));
|
arrayClear(area->pixels + (y * area->params.width * area->params.antialias + x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
area->scanline_left = 0;
|
area->scanline_left = 0;
|
||||||
area->scanline_right = area->width - 1;
|
area->scanline_right = area->params.width * area->params.antialias - 1;
|
||||||
|
|
||||||
area->callback_start(area->width, area->height, area->background_color);
|
area->callback_start(area->params.width, area->params.height, area->background_color);
|
||||||
|
|
||||||
area->dirty_left = area->width;
|
area->dirty_left = area->params.width * area->params.antialias;
|
||||||
area->dirty_right = -1;
|
area->dirty_right = -1;
|
||||||
area->dirty_down = area->height;
|
area->dirty_down = area->params.height * area->params.antialias;
|
||||||
area->dirty_up = -1;
|
area->dirty_up = -1;
|
||||||
area->dirty_count = 0;
|
area->dirty_count = 0;
|
||||||
}
|
}
|
||||||
|
@ -233,7 +236,7 @@ static void _processDirtyPixels(RenderArea* area)
|
||||||
{
|
{
|
||||||
for (x = area->dirty_left; x <= area->dirty_right; x++)
|
for (x = area->dirty_left; x <= area->dirty_right; x++)
|
||||||
{
|
{
|
||||||
pixel_data = area->pixels + y * area->width + x;
|
pixel_data = area->pixels + y * area->params.width * area->params.antialias + x;
|
||||||
if (pixel_data->dirty)
|
if (pixel_data->dirty)
|
||||||
{
|
{
|
||||||
col = _getPixelColor(area->background_color, pixel_data);
|
col = _getPixelColor(area->background_color, pixel_data);
|
||||||
|
@ -245,9 +248,9 @@ static void _processDirtyPixels(RenderArea* area)
|
||||||
|
|
||||||
area->callback_update(0.0);
|
area->callback_update(0.0);
|
||||||
|
|
||||||
area->dirty_left = area->width;
|
area->dirty_left = area->params.width * area->params.antialias;
|
||||||
area->dirty_right = -1;
|
area->dirty_right = -1;
|
||||||
area->dirty_down = area->height;
|
area->dirty_down = area->params.height * area->params.antialias;
|
||||||
area->dirty_up = -1;
|
area->dirty_up = -1;
|
||||||
area->dirty_count = 0;
|
area->dirty_count = 0;
|
||||||
}
|
}
|
||||||
|
@ -264,15 +267,15 @@ static void _setAllDirty(RenderArea* area)
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
area->dirty_left = 0;
|
area->dirty_left = 0;
|
||||||
area->dirty_right = area->width - 1;
|
area->dirty_right = area->params.width - 1;
|
||||||
area->dirty_down = 0;
|
area->dirty_down = 0;
|
||||||
area->dirty_up = area->height - 1;
|
area->dirty_up = area->params.height - 1;
|
||||||
|
|
||||||
for (y = area->dirty_down; y <= area->dirty_up; y++)
|
for (y = area->dirty_down; y <= area->dirty_up; y++)
|
||||||
{
|
{
|
||||||
for (x = area->dirty_left; x <= area->dirty_right; x++)
|
for (x = area->dirty_left; x <= area->dirty_right; x++)
|
||||||
{
|
{
|
||||||
(area->pixels + y * area->width + x)->dirty = 1;
|
(area->pixels + y * area->params.width * area->params.antialias + x)->dirty = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,9 +292,9 @@ void renderAddFragment(RenderArea* area, RenderFragment* fragment)
|
||||||
RenderFragment* fragments;
|
RenderFragment* fragments;
|
||||||
|
|
||||||
dirty = 0;
|
dirty = 0;
|
||||||
if (x >= 0 && x < area->width && y >= 0 && y < area->height && z > 1.0)
|
if (x >= 0 && x < area->params.width * area->params.antialias && y >= 0 && y < area->params.height * area->params.antialias && z > 1.0)
|
||||||
{
|
{
|
||||||
pixel_data = area->pixels + (y * area->width + x);
|
pixel_data = area->pixels + (y * area->params.width * area->params.antialias + x);
|
||||||
fragments = (RenderFragment*)pixel_data->data;
|
fragments = (RenderFragment*)pixel_data->data;
|
||||||
fragments_count = pixel_data->length;
|
fragments_count = pixel_data->length;
|
||||||
|
|
||||||
|
@ -389,7 +392,7 @@ static void __vertexInterpolate(Vertex* v1, Vertex* diff, double value, Vertex*
|
||||||
|
|
||||||
static void __pushScanLinePoint(RenderArea* area, RenderFragment point)
|
static void __pushScanLinePoint(RenderArea* area, RenderFragment point)
|
||||||
{
|
{
|
||||||
if (point.x < 0 || point.x >= area->width)
|
if (point.x < 0 || point.x >= area->params.width * area->params.antialias)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +439,7 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
|
||||||
{
|
{
|
||||||
__pushScanLineEdge(area, v2, v1, vertex2, vertex1);
|
__pushScanLineEdge(area, v2, v1, vertex2, vertex1);
|
||||||
}
|
}
|
||||||
else if (endx < 0 || startx >= area->width)
|
else if (endx < 0 || startx >= area->params.width * area->params.antialias)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -462,9 +465,9 @@ static void __pushScanLineEdge(RenderArea* area, Vector3 v1, Vector3 v2, Vertex*
|
||||||
{
|
{
|
||||||
startx = 0;
|
startx = 0;
|
||||||
}
|
}
|
||||||
if (endx >= area->width)
|
if (endx >= area->params.width * area->params.antialias)
|
||||||
{
|
{
|
||||||
endx = area->width - 1;
|
endx = area->params.width * area->params.antialias - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dx = v2.x - v1.x;
|
dx = v2.x - v1.x;
|
||||||
|
@ -499,9 +502,9 @@ static void __clearScanLines(RenderArea* area)
|
||||||
for (x = area->scanline_left; x <= area->scanline_right; x++)
|
for (x = area->scanline_left; x <= area->scanline_right; x++)
|
||||||
{
|
{
|
||||||
area->scanline_up[x].y = -1;
|
area->scanline_up[x].y = -1;
|
||||||
area->scanline_down[x].y = area->height;
|
area->scanline_down[x].y = area->params.height * area->params.antialias;
|
||||||
}
|
}
|
||||||
area->scanline_left = area->width;
|
area->scanline_left = area->params.width * area->params.antialias;
|
||||||
area->scanline_right = -1;
|
area->scanline_right = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +525,7 @@ static void __renderScanLines(RenderArea* area)
|
||||||
starty = down.y;
|
starty = down.y;
|
||||||
endy = up.y;
|
endy = up.y;
|
||||||
|
|
||||||
if (endy < 0 || starty >= area->height)
|
if (endy < 0 || starty >= area->params.height * area->params.antialias)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -531,9 +534,9 @@ static void __renderScanLines(RenderArea* area)
|
||||||
{
|
{
|
||||||
starty = 0;
|
starty = 0;
|
||||||
}
|
}
|
||||||
if (endy >= area->height)
|
if (endy >= area->params.height * area->params.antialias)
|
||||||
{
|
{
|
||||||
endy = area->height - 1;
|
endy = area->params.height * area->params.antialias - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dy = (double)(up.y - down.y);
|
dy = (double)(up.y - down.y);
|
||||||
|
@ -564,8 +567,8 @@ static void __renderScanLines(RenderArea* area)
|
||||||
|
|
||||||
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3)
|
void renderPushTriangle(RenderArea* area, Vertex* v1, Vertex* v2, Vertex* v3, Vector3 p1, Vector3 p2, Vector3 p3)
|
||||||
{
|
{
|
||||||
double limit_width = (double)(area->width - 1);
|
double limit_width = (double)(area->params.width * area->params.antialias - 1);
|
||||||
double limit_height = (double)(area->height - 1);
|
double limit_height = (double)(area->params.height * area->params.antialias - 1);
|
||||||
|
|
||||||
/* Filter if outside screen */
|
/* Filter if outside screen */
|
||||||
if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height))
|
if (p1.z < 1.0 || p2.z < 1.0 || p3.z < 1.0 || (p1.x < 0.0 && p2.x < 0.0 && p3.x < 0.0) || (p1.y < 0.0 && p2.y < 0.0 && p3.y < 0.0) || (p1.x > limit_width && p2.x > limit_width && p3.x > limit_width) || (p1.y > limit_height && p2.y > limit_height && p3.y > limit_height))
|
||||||
|
@ -603,14 +606,14 @@ void* _renderPostProcessChunk(void* data)
|
||||||
RenderChunk* chunk = (RenderChunk*)data;
|
RenderChunk* chunk = (RenderChunk*)data;
|
||||||
|
|
||||||
#ifdef RENDER_INVERSE
|
#ifdef RENDER_INVERSE
|
||||||
for (y = chunk->area->height - 1 - chunk->starty; y >= chunk->area->height - 1 - chunk->endy; y--)
|
for (y = chunk->area->params.height * chunk->area->params.antialias - 1 - chunk->starty; y >= chunk->area->params.height * chunk->area->params.antialias - 1 - chunk->endy; y--)
|
||||||
#else
|
#else
|
||||||
for (y = chunk->starty; y <= chunk->endy; y++)
|
for (y = chunk->starty; y <= chunk->endy; y++)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
for (x = chunk->startx; x <= chunk->endx; x++)
|
for (x = chunk->startx; x <= chunk->endx; x++)
|
||||||
{
|
{
|
||||||
pixel_data = chunk->area->pixels + (y * chunk->area->width + x);
|
pixel_data = chunk->area->pixels + (y * chunk->area->params.width * chunk->area->params.antialias + x);
|
||||||
fragments = (RenderFragment*)pixel_data->data;
|
fragments = (RenderFragment*)pixel_data->data;
|
||||||
dirty = 0;
|
dirty = 0;
|
||||||
for (i = 0; i < pixel_data->length; i++)
|
for (i = 0; i < pixel_data->length; i++)
|
||||||
|
@ -661,8 +664,8 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
|
||||||
|
|
||||||
nx = 10;
|
nx = 10;
|
||||||
ny = 10;
|
ny = 10;
|
||||||
dx = area->width / nx;
|
dx = area->params.width * area->params.antialias / nx;
|
||||||
dy = area->height / ny;
|
dy = area->params.height * area->params.antialias / ny;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
/*_progress_pixels = 0;*/
|
/*_progress_pixels = 0;*/
|
||||||
|
@ -703,7 +706,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
|
||||||
chunks[i].startx = x * dx;
|
chunks[i].startx = x * dx;
|
||||||
if (x == nx - 1)
|
if (x == nx - 1)
|
||||||
{
|
{
|
||||||
chunks[i].endx = area->width - 1;
|
chunks[i].endx = area->params.width * area->params.antialias - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -712,7 +715,7 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks)
|
||||||
chunks[i].starty = y * dy;
|
chunks[i].starty = y * dy;
|
||||||
if (y == ny - 1)
|
if (y == ny - 1)
|
||||||
{
|
{
|
||||||
chunks[i].endy = area->height - 1;
|
chunks[i].endy = area->params.height * area->params.antialias - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -753,23 +756,24 @@ int renderSaveToFile(RenderArea* area, const char* path)
|
||||||
Color result;
|
Color result;
|
||||||
ILuint x, y;
|
ILuint x, y;
|
||||||
ILuint rgba;
|
ILuint rgba;
|
||||||
ILuint data[area->height * area->width];
|
ILuint data[area->params.height * area->params.width];
|
||||||
ILenum error;
|
ILenum error;
|
||||||
Array* pixel_data;
|
Array* pixel_data;
|
||||||
int error_count;
|
int error_count;
|
||||||
|
|
||||||
for (y = 0; y < area->height; y++)
|
for (y = 0; y < area->params.height; y++)
|
||||||
{
|
{
|
||||||
for (x = 0; x < area->width; x++)
|
for (x = 0; x < area->params.width; x++)
|
||||||
{
|
{
|
||||||
pixel_data = area->pixels + (y * area->width + x);
|
/* TODO Anti-alias */
|
||||||
|
pixel_data = area->pixels + (y * area->params.width + x);
|
||||||
result = _getPixelColor(area->background_color, pixel_data);
|
result = _getPixelColor(area->background_color, pixel_data);
|
||||||
rgba = colorTo32BitRGBA(&result);
|
rgba = colorTo32BitRGBA(&result);
|
||||||
data[y * area->width + x] = rgba;
|
data[y * area->params.width + x] = rgba;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ilTexImage((ILuint)area->width, (ILuint)area->height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
ilTexImage((ILuint)area->params.width, (ILuint)area->params.height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
|
||||||
remove(path);
|
remove(path);
|
||||||
ilSaveImage(path);
|
ilSaveImage(path);
|
||||||
|
|
||||||
|
@ -790,7 +794,7 @@ void renderSetPreviewCallbacks(RenderArea* area, RenderCallbackStart start, Rend
|
||||||
area->callback_draw = draw ? draw : _callbackDraw;
|
area->callback_draw = draw ? draw : _callbackDraw;
|
||||||
area->callback_update = update ? update : _callbackUpdate;
|
area->callback_update = update ? update : _callbackUpdate;
|
||||||
|
|
||||||
area->callback_start(area->width, area->height, area->background_color);
|
area->callback_start(area->params.width, area->params.height, area->background_color);
|
||||||
|
|
||||||
_setAllDirty(area);
|
_setAllDirty(area);
|
||||||
_processDirtyPixels(area);
|
_processDirtyPixels(area);
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void renderInit();
|
void renderInit();
|
||||||
void renderQuit();
|
void renderQuit();
|
||||||
|
|
||||||
RenderArea* renderCreateArea();
|
RenderArea* renderCreateArea();
|
||||||
void renderDeleteArea(RenderArea* area);
|
void renderDeleteArea(RenderArea* area);
|
||||||
|
|
||||||
void renderSetSize(RenderArea* area, int width, int height);
|
void renderSetParams(RenderArea* area, RenderParams params);
|
||||||
void renderSetBackgroundColor(RenderArea* area, Color* col);
|
void renderSetBackgroundColor(RenderArea* area, Color* col);
|
||||||
void renderClear(RenderArea* area);
|
void renderClear(RenderArea* area);
|
||||||
void renderUpdate(RenderArea* area);
|
void renderUpdate(RenderArea* area);
|
||||||
|
|
|
@ -101,6 +101,7 @@ static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3
|
||||||
Renderer rendererCreate()
|
Renderer rendererCreate()
|
||||||
{
|
{
|
||||||
Renderer result;
|
Renderer result;
|
||||||
|
RenderParams params = {1, 1, 1, 5};
|
||||||
|
|
||||||
result.render_quality = 5;
|
result.render_quality = 5;
|
||||||
result.render_width = 1;
|
result.render_width = 1;
|
||||||
|
@ -111,7 +112,8 @@ Renderer rendererCreate()
|
||||||
result.render_camera = cameraCreateDefinition();
|
result.render_camera = cameraCreateDefinition();
|
||||||
result.camera_location = result.render_camera.location;
|
result.camera_location = result.render_camera.location;
|
||||||
result.render_area = renderCreateArea();
|
result.render_area = renderCreateArea();
|
||||||
renderSetSize(result.render_area, 1, 1);
|
|
||||||
|
renderSetParams(result.render_area, params);
|
||||||
|
|
||||||
result.addRenderProgress = _addRenderProgress;
|
result.addRenderProgress = _addRenderProgress;
|
||||||
result.getPrecision = _getPrecision;
|
result.getPrecision = _getPrecision;
|
||||||
|
@ -144,23 +146,26 @@ void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start,
|
||||||
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rendererStart(Renderer* renderer, int width, int height, int quality)
|
void rendererStart(Renderer* renderer, RenderParams params)
|
||||||
{
|
{
|
||||||
Thread* thread;
|
Thread* thread;
|
||||||
int loops;
|
int loops;
|
||||||
int core_count = systemGetCoreCount();
|
int core_count = systemGetCoreCount();
|
||||||
|
|
||||||
renderer->render_quality = quality;
|
params.antialias = (params.antialias < 1) ? 1 : params.antialias;
|
||||||
renderer->render_width = width;
|
params.antialias = (params.antialias > 4) ? 4 : params.antialias;
|
||||||
renderer->render_height = height;
|
|
||||||
|
renderer->render_quality = params.quality;
|
||||||
|
renderer->render_width = params.width * params.antialias;
|
||||||
|
renderer->render_height = params.height * params.antialias;
|
||||||
renderer->render_interrupt = 0;
|
renderer->render_interrupt = 0;
|
||||||
renderer->render_progress = 0.0;
|
renderer->render_progress = 0.0;
|
||||||
|
|
||||||
cameraSetRenderSize(&renderer->render_camera, width, height);
|
cameraSetRenderSize(&renderer->render_camera, renderer->render_width, renderer->render_height);
|
||||||
renderer->camera_location = renderer->render_camera.location;
|
renderer->camera_location = renderer->render_camera.location;
|
||||||
|
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
||||||
renderSetSize(renderer->render_area, width, height);
|
renderSetParams(renderer->render_area, params);
|
||||||
renderClear(renderer->render_area);
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
renderer->is_rendering = 1;
|
renderer->is_rendering = 1;
|
||||||
|
|
|
@ -50,7 +50,7 @@ struct Renderer
|
||||||
Renderer rendererCreate();
|
Renderer rendererCreate();
|
||||||
void rendererDelete(Renderer* renderer);
|
void rendererDelete(Renderer* renderer);
|
||||||
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update);
|
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update);
|
||||||
void rendererStart(Renderer* renderer, int width, int height, int quality);
|
void rendererStart(Renderer* renderer, RenderParams params);
|
||||||
void rendererInterrupt(Renderer* renderer);
|
void rendererInterrupt(Renderer* renderer);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -37,7 +37,9 @@ typedef struct
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
} RenderContext;
|
int antialias;
|
||||||
|
int quality;
|
||||||
|
} RenderParams;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue