2012-01-23 23:45:33 +00:00
|
|
|
#include "renderer.h"
|
2012-05-29 13:32:23 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "lighting.h"
|
2012-01-29 21:45:58 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "scenery.h"
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
RayCastingResult _RAYCASTING_NULL = {0};
|
2012-01-29 17:53:12 +00:00
|
|
|
HeightInfo _WATER_HEIGHT_INFO = {-1000000.0, -1000000.0, -1000000.0};
|
2012-01-24 13:16:20 +00:00
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
static void* _renderFirstPass(void* data)
|
|
|
|
{
|
|
|
|
Renderer* renderer = (Renderer*)data;
|
|
|
|
|
|
|
|
sceneryRenderFirstPass(renderer);
|
|
|
|
renderer->is_rendering = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
static int _addRenderProgress(Renderer* renderer, float progress)
|
2012-01-29 21:45:58 +00:00
|
|
|
{
|
2012-01-30 13:10:16 +00:00
|
|
|
return !renderer->render_interrupt;
|
2012-01-29 21:45:58 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
static float _getPrecision(Renderer* renderer, Vector3 location)
|
2012-01-29 21:45:58 +00:00
|
|
|
{
|
|
|
|
return 0.001;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
|
|
|
|
{
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
|
|
|
|
{
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _pushTriangle(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3)
|
|
|
|
{
|
|
|
|
Vector3 p1, p2, p3;
|
|
|
|
|
|
|
|
p1 = renderer->projectPoint(renderer, v1->location);
|
|
|
|
p2 = renderer->projectPoint(renderer, v2->location);
|
|
|
|
p3 = renderer->projectPoint(renderer, v3->location);
|
|
|
|
|
|
|
|
renderPushTriangle(renderer->render_area, v1, v2, v3, p1, p2, p3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _pushQuad(Renderer* renderer, Vertex* v1, Vertex* v2, Vertex* v3, Vertex* v4)
|
|
|
|
{
|
|
|
|
renderer->pushTriangle(renderer, v2, v3, v1);
|
|
|
|
renderer->pushTriangle(renderer, v4, v1, v3);
|
|
|
|
}
|
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static void _alterLight(Renderer* renderer, LightDefinition* light, Vector3 location)
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
2012-01-25 17:31:36 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
status->nblights = 0;
|
2012-01-25 17:31:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
|
2012-01-24 13:16:20 +00:00
|
|
|
{
|
2012-06-05 20:22:12 +00:00
|
|
|
return lightingApplyStatusToSurface(renderer, status, location, normal, material);
|
2012-01-24 13:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
|
|
|
|
{
|
|
|
|
return _RAYCASTING_NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
static float _getTerrainHeight(Renderer* renderer, float x, float z)
|
2012-01-24 13:16:20 +00:00
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-01-29 17:53:12 +00:00
|
|
|
static HeightInfo _getWaterHeightInfo(Renderer* renderer)
|
|
|
|
{
|
|
|
|
return _WATER_HEIGHT_INFO;
|
|
|
|
}
|
|
|
|
|
2012-06-15 09:31:11 +00:00
|
|
|
static Color _applyTextures(Renderer* renderer, Vector3 location, float precision)
|
2012-01-24 13:16:20 +00:00
|
|
|
{
|
|
|
|
return COLOR_TRANSPARENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Color _applyAtmosphere(Renderer* renderer, Vector3 location, Color base)
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Color _applyClouds(Renderer* renderer, Color base, Vector3 start, Vector3 end)
|
|
|
|
{
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
Renderer rendererCreate()
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
|
|
|
Renderer result;
|
2012-06-13 15:38:11 +00:00
|
|
|
RenderParams params = {1, 1, 1, 5};
|
2012-01-23 23:45:33 +00:00
|
|
|
|
|
|
|
result.render_quality = 5;
|
2012-01-29 21:45:58 +00:00
|
|
|
result.render_width = 1;
|
|
|
|
result.render_height = 1;
|
|
|
|
result.render_interrupt = 0;
|
|
|
|
result.render_progress = 0.0;
|
|
|
|
result.is_rendering = 0;
|
2012-01-31 11:20:52 +00:00
|
|
|
result.render_camera = cameraCreateDefinition();
|
|
|
|
result.camera_location = result.render_camera.location;
|
2012-01-29 21:45:58 +00:00
|
|
|
result.render_area = renderCreateArea();
|
2012-06-13 15:38:11 +00:00
|
|
|
|
|
|
|
renderSetParams(result.render_area, params);
|
2012-01-29 21:45:58 +00:00
|
|
|
|
|
|
|
result.addRenderProgress = _addRenderProgress;
|
|
|
|
result.getPrecision = _getPrecision;
|
|
|
|
result.projectPoint = _projectPoint;
|
|
|
|
result.unprojectPoint = _unprojectPoint;
|
|
|
|
result.pushTriangle = _pushTriangle;
|
|
|
|
result.pushQuad = _pushQuad;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-01-24 13:16:20 +00:00
|
|
|
result.rayWalking = _rayWalking;
|
|
|
|
result.getTerrainHeight = _getTerrainHeight;
|
2012-01-29 17:53:12 +00:00
|
|
|
result.getWaterHeightInfo = _getWaterHeightInfo;
|
2012-01-24 13:16:20 +00:00
|
|
|
result.applyTextures = _applyTextures;
|
|
|
|
result.applyAtmosphere = _applyAtmosphere;
|
|
|
|
result.applyClouds = _applyClouds;
|
2012-01-29 21:45:58 +00:00
|
|
|
|
2012-06-05 20:22:12 +00:00
|
|
|
result.alterLight = _alterLight;
|
|
|
|
result.getLightStatus = _getLightStatus;
|
|
|
|
result.applyLightStatus = _applyLightStatus;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2012-01-29 21:45:58 +00:00
|
|
|
|
|
|
|
void rendererDelete(Renderer* renderer)
|
|
|
|
{
|
|
|
|
renderDeleteArea(renderer->render_area);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
|
|
|
|
{
|
|
|
|
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
|
|
|
|
}
|
|
|
|
|
2012-06-13 15:38:11 +00:00
|
|
|
void rendererStart(Renderer* renderer, RenderParams params)
|
2012-01-29 21:45:58 +00:00
|
|
|
{
|
|
|
|
Thread* thread;
|
|
|
|
int loops;
|
|
|
|
int core_count = systemGetCoreCount();
|
|
|
|
|
2012-06-13 15:38:11 +00:00
|
|
|
params.antialias = (params.antialias < 1) ? 1 : params.antialias;
|
|
|
|
params.antialias = (params.antialias > 4) ? 4 : params.antialias;
|
|
|
|
|
|
|
|
renderer->render_quality = params.quality;
|
|
|
|
renderer->render_width = params.width * params.antialias;
|
|
|
|
renderer->render_height = params.height * params.antialias;
|
2012-01-29 21:45:58 +00:00
|
|
|
renderer->render_interrupt = 0;
|
|
|
|
renderer->render_progress = 0.0;
|
2012-01-31 11:20:52 +00:00
|
|
|
|
2012-06-13 15:38:11 +00:00
|
|
|
cameraSetRenderSize(&renderer->render_camera, renderer->render_width, renderer->render_height);
|
2012-01-31 11:20:52 +00:00
|
|
|
renderer->camera_location = renderer->render_camera.location;
|
2012-01-29 21:45:58 +00:00
|
|
|
|
|
|
|
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
2012-06-13 15:38:11 +00:00
|
|
|
renderSetParams(renderer->render_area, params);
|
2012-01-29 21:45:58 +00:00
|
|
|
renderClear(renderer->render_area);
|
|
|
|
|
|
|
|
renderer->is_rendering = 1;
|
|
|
|
thread = threadCreate(_renderFirstPass, renderer);
|
|
|
|
loops = 0;
|
|
|
|
|
|
|
|
while (renderer->is_rendering)
|
|
|
|
{
|
|
|
|
timeSleepMs(100);
|
|
|
|
|
|
|
|
if (++loops >= 10)
|
|
|
|
{
|
|
|
|
renderUpdate(renderer->render_area);
|
|
|
|
loops = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
threadJoin(thread);
|
|
|
|
|
|
|
|
renderer->is_rendering = 1;
|
|
|
|
renderPostProcess(renderer->render_area, renderer, core_count);
|
|
|
|
renderer->is_rendering = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rendererInterrupt(Renderer* renderer)
|
|
|
|
{
|
2012-01-30 13:10:16 +00:00
|
|
|
renderer->render_interrupt = 1;
|
2012-01-29 21:45:58 +00:00
|
|
|
}
|