From 1b890849a80504585ddd873ab95f36ba45b3c871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 11 Jun 2013 12:03:50 +0200 Subject: [PATCH] Added renderer to RenderArea to gain access to camera --- src/rendering/render.c | 16 ++++++++-------- src/rendering/render.h | 4 ++-- src/rendering/renderer.c | 4 ++-- src/testing/test_render.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/rendering/render.c b/src/rendering/render.c index 3acfefc..e044ba9 100644 --- a/src/rendering/render.c +++ b/src/rendering/render.c @@ -45,6 +45,7 @@ typedef struct struct RenderArea { ColorProfile* hdr_mapping; + Renderer* renderer; RenderParams params; int pixel_count; int pixel_done; @@ -77,7 +78,6 @@ typedef struct { int pixel_done; Thread* thread; RenderArea* area; - Renderer* renderer; } RenderChunk; #define RENDER_INVERSE 1 @@ -94,11 +94,12 @@ void renderQuit() { } -RenderArea* renderCreateArea() +RenderArea* renderCreateArea(Renderer* renderer) { RenderArea* result; result = malloc(sizeof(RenderArea)); + result->renderer = renderer; result->hdr_mapping = colorProfileCreate(); result->params.width = 1; result->params.height = 1; @@ -605,7 +606,7 @@ void* _renderPostProcessChunk(void* data) callback = chunk->area->fragment_callbacks[fragment->flags.callback]; if (callback.function) { - col = callback.function(chunk->renderer, fragment->data.location, callback.data); + col = callback.function(chunk->area->renderer, fragment->data.location, callback.data); /*colorNormalize(&col);*/ } else @@ -635,7 +636,7 @@ void* _renderPostProcessChunk(void* data) } #define MAX_CHUNKS 8 -void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) +void renderPostProcess(RenderArea* area, int nbchunks) { volatile RenderChunk chunks[MAX_CHUNKS]; int i; @@ -663,12 +664,11 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) { chunks[i].thread = NULL; chunks[i].area = area; - chunks[i].renderer = renderer; } running = 0; loops = 0; - while ((y < ny && !renderer->render_interrupt) || running > 0) + while ((y < ny && !area->renderer->render_interrupt) || running > 0) { timeSleepMs(100); @@ -682,13 +682,13 @@ void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks) chunks[i].thread = NULL; running--; } - else if (renderer->render_interrupt) + else if (area->renderer->render_interrupt) { chunks[i].interrupt = 1; } } - if (y < ny && !chunks[i].thread && !renderer->render_interrupt) + if (y < ny && !chunks[i].thread && !area->renderer->render_interrupt) { chunks[i].finished = 0; chunks[i].interrupt = 0; diff --git a/src/rendering/render.h b/src/rendering/render.h index b246c06..0479951 100644 --- a/src/rendering/render.h +++ b/src/rendering/render.h @@ -28,7 +28,7 @@ typedef struct void renderInit(); void renderQuit(); -RenderArea* renderCreateArea(); +RenderArea* renderCreateArea(Renderer* renderer); void renderDeleteArea(RenderArea* area); void renderSetParams(RenderArea* area, RenderParams params); @@ -39,7 +39,7 @@ void renderUpdate(RenderArea* area); void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector3 pixel3, Vector3 location1, Vector3 location2, Vector3 location3, f_RenderFragmentCallback callback, void* callback_data); -void renderPostProcess(RenderArea* area, Renderer* renderer, int nbchunks); +void renderPostProcess(RenderArea* area, int nbchunks); int renderSaveToFile(RenderArea* area, const char* path); void renderSetPreviewCallbacks(RenderArea* area, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update); diff --git a/src/rendering/renderer.c b/src/rendering/renderer.c index 5fdd257..e0bb993 100644 --- a/src/rendering/renderer.c +++ b/src/rendering/renderer.c @@ -122,7 +122,7 @@ Renderer* rendererCreate() result->render_progress = 0.0; result->is_rendering = 0; result->render_camera = cameraCreateDefinition(); - result->render_area = renderCreateArea(); + result->render_area = renderCreateArea(result); renderSetParams(result->render_area, params); @@ -213,7 +213,7 @@ void rendererStart(Renderer* renderer, RenderParams params) threadJoin(thread); renderer->is_rendering = 1; - renderPostProcess(renderer->render_area, renderer, core_count); + renderPostProcess(renderer->render_area, core_count); renderer->is_rendering = 0; } diff --git a/src/testing/test_render.c b/src/testing/test_render.c index e0d4751..3a1c05a 100644 --- a/src/testing/test_render.c +++ b/src/testing/test_render.c @@ -49,7 +49,7 @@ START_TEST(test_render_quad) renderClear(renderer->render_area); renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL); - renderPostProcess(renderer->render_area, renderer, tests_cpu_count); + renderPostProcess(renderer->render_area, tests_cpu_count); renderSaveToFile(renderer->render_area, "./output/test_render_quad.png");