Refactored TerrainRasterized

This commit is contained in:
Michaël Lemaire 2013-12-05 16:44:18 +01:00 committed by Michael Lemaire
parent e32738564b
commit 0afeb7707d
7 changed files with 96 additions and 70 deletions

View file

@ -7,12 +7,12 @@
#include "AtmosphereDefinition.h"
#include "CloudsRenderer.h"
#include "SkyRasterizer.h"
#include "TerrainRasterizer.h"
// Legacy compatibility
#include "renderer.h"
#include "terrain/public.h"
#include "terrain/ter_raster.h"
#include "textures/public.h"
#include "water/public.h"
static AtmosphereResult _legacyApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base)
@ -134,7 +134,9 @@ void SoftwareRenderer::prepare()
void SoftwareRenderer::rasterize()
{
terrainRenderSurface(this);
TerrainRasterizer terrain(this);
terrain.renderSurface();
waterRenderSurface(this);
SkyRasterizer sky(this);

View file

@ -1,21 +1,20 @@
#include "public.h"
#include "private.h"
#include "ter_raster.h"
#include "TerrainRasterizer.h"
#include <cstdlib>
#include <cmath>
#include "SoftwareRenderer.h"
#include "BoundingBox.h"
#include "../tools/parallel.h"
#include "../renderer.h"
#include "water/public.h"
#include "textures/public.h"
#include "CameraDefinition.h"
/*
* Terrain rasterization.
*/
#include "tools/parallel.h"
#include "terrain/public.h"
#include "water/public.h"
#include "textures/public.h"
static inline Vector3 _getPoint(TerrainDefinition*, Renderer* renderer, double x, double z)
TerrainRasterizer::TerrainRasterizer(SoftwareRenderer* renderer):
renderer(renderer)
{
}
static inline Vector3 _getPoint(TerrainDefinition*, SoftwareRenderer* renderer, double x, double z)
{
Vector3 result;
@ -26,9 +25,10 @@ static inline Vector3 _getPoint(TerrainDefinition*, Renderer* renderer, double x
return result;
}
static Color _postProcessFragment(Renderer* renderer, Vector3 point, void*)
static Color _postProcessFragment(Renderer* renderer_, Vector3 point, void*)
{
double precision;
SoftwareRenderer* renderer = (SoftwareRenderer*)renderer_;
point = _getPoint(renderer->terrain->definition, renderer, point.x, point.z);
@ -65,7 +65,7 @@ static void _renderQuad(Renderer* renderer, double x, double z, double size, dou
}
}
void terrainTessellateChunk(Renderer* renderer, TerrainChunkInfo* chunk, int detail)
void TerrainRasterizer::tessellateChunk(TerrainChunkInfo* chunk, int detail)
{
if (detail < 1)
{
@ -88,7 +88,7 @@ void terrainTessellateChunk(Renderer* renderer, TerrainChunkInfo* chunk, int det
}
}
static void _getChunk(Renderer* renderer, TerrainChunkInfo* chunk, double x, double z, double size, int displaced)
static void _getChunk(Renderer* renderer, TerrainRasterizer::TerrainChunkInfo* chunk, double x, double z, double size, int displaced)
{
chunk->point_nw = renderer->terrain->getResult(renderer, x, z, 1, displaced).location;
chunk->point_sw = renderer->terrain->getResult(renderer, x, z + size, 1, displaced).location;
@ -141,7 +141,7 @@ static void _getChunk(Renderer* renderer, TerrainChunkInfo* chunk, double x, dou
}
}
void terrainGetTessellationInfo(Renderer* renderer, FuncTerrainTessellationCallback callback, int displaced)
void TerrainRasterizer::getTessellationInfo(int displaced)
{
TerrainChunkInfo chunk;
int chunk_factor, chunk_count, i;
@ -168,25 +168,25 @@ void terrainGetTessellationInfo(Renderer* renderer, FuncTerrainTessellationCallb
for (i = 0; i < chunk_count - 1; i++)
{
_getChunk(renderer, &chunk, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, displaced);
if (!callback(renderer, &chunk, progress))
if (!processChunk(&chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, displaced);
if (!callback(renderer, &chunk, progress))
if (!processChunk(&chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, displaced);
if (!callback(renderer, &chunk, progress))
if (!processChunk(&chunk, progress))
{
return;
}
_getChunk(renderer, &chunk, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, displaced);
if (!callback(renderer, &chunk, progress))
if (!processChunk(&chunk, progress))
{
return;
}
@ -206,8 +206,8 @@ void terrainGetTessellationInfo(Renderer* renderer, FuncTerrainTessellationCallb
typedef struct
{
Renderer* renderer;
TerrainChunkInfo chunk;
TerrainRasterizer* rasterizer;
TerrainRasterizer::TerrainChunkInfo chunk;
} ParallelRasterInfo;
static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping)
@ -216,18 +216,18 @@ static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping)
if (!stopping)
{
terrainTessellateChunk(info->renderer, &info->chunk, info->chunk.detail_hint);
info->rasterizer->tessellateChunk(&info->chunk, info->chunk.detail_hint);
}
free(data);
return 0;
}
static int _standardTessellationCallback(Renderer* renderer, TerrainChunkInfo* chunk, double progress)
int TerrainRasterizer::processChunk(TerrainChunkInfo* chunk, double progress)
{
ParallelRasterInfo* info = new ParallelRasterInfo;
info->renderer = renderer;
info->rasterizer = this;
info->chunk = *chunk;
if (!parallelQueueAddJob((ParallelQueue*)renderer->customData[0], _parallelJobCallback, info))
@ -239,7 +239,7 @@ static int _standardTessellationCallback(Renderer* renderer, TerrainChunkInfo* c
return !renderer->render_interrupt;
}
void terrainRenderSurface(Renderer* renderer)
void TerrainRasterizer::renderSurface()
{
ParallelQueue* queue;
queue = parallelQueueCreate(0);
@ -248,7 +248,7 @@ void terrainRenderSurface(Renderer* renderer)
renderer->customData[0] = queue;
renderer->render_progress = 0.0;
terrainGetTessellationInfo(renderer, _standardTessellationCallback, 0);
getTessellationInfo(0);
renderer->render_progress = 0.05;
parallelQueueWait(queue);

View file

@ -0,0 +1,57 @@
#ifndef TERRAINRASTERIZER_H
#define TERRAINRASTERIZER_H
#include "software_global.h"
#include "Vector3.h"
namespace paysages {
namespace software {
class SOFTWARESHARED_EXPORT TerrainRasterizer
{
public:
typedef struct
{
Vector3 point_nw;
Vector3 point_sw;
Vector3 point_se;
Vector3 point_ne;
int detail_hint;
} TerrainChunkInfo;
public:
TerrainRasterizer(SoftwareRenderer* renderer);
/**
* Method called for each chunk tessellated by getTessellationInfo.
*/
int processChunk(TerrainChunkInfo* chunk, double progress);
/**
* Tessellate the terrain, calling processChunk for each chunk.
*
* The terrain will be broken in chunks, most detailed near the camera.
*/
void getTessellationInfo(int displaced);
/**
* Tessellate a terrain chunk, pushing the quads in the render area.
*/
void tessellateChunk(TerrainChunkInfo* chunk, int detail);
/**
* Start the final rasterization of terrain.
*
* This will push the rasterized quads in the render area, waiting for post process.
*/
void renderSurface();
private:
SoftwareRenderer* renderer;
};
}
}
#endif // TERRAINRASTERIZER_H

View file

@ -22,7 +22,8 @@ SOURCES += SoftwareRenderer.cpp \
SkyRasterizer.cpp \
CloudBasicLayerRenderer.cpp \
clouds/BaseCloudsModel.cpp \
clouds/CloudModelStratoCumulus.cpp
clouds/CloudModelStratoCumulus.cpp \
TerrainRasterizer.cpp
HEADERS += SoftwareRenderer.h\
software_global.h \
@ -34,7 +35,8 @@ HEADERS += SoftwareRenderer.h\
SkyRasterizer.h \
CloudBasicLayerRenderer.h \
clouds/BaseCloudsModel.h \
clouds/CloudModelStratoCumulus.h
clouds/CloudModelStratoCumulus.h \
TerrainRasterizer.h
unix:!symbian {
maemo5 {

View file

@ -25,6 +25,9 @@ namespace software {
class CloudsRenderer;
class BaseCloudLayerRenderer;
class BaseCloudsModel;
class SkyRasterizer;
class TerrainRasterizer;
}
}

View file

@ -14,7 +14,6 @@ SOURCES += main.cpp \
atmosphere/atm_render.cpp \
atmosphere/atm_bruneton.cpp \
terrain/ter_render.cpp \
terrain/ter_raster.cpp \
terrain/ter_painting.cpp \
textures/tex_tools.cpp \
textures/tex_rendering.cpp \
@ -35,7 +34,6 @@ HEADERS += \
atmosphere/public.h \
atmosphere/private.h \
shared/types.h \
terrain/ter_raster.h \
terrain/public.h \
terrain/private.h \
textures/tex_preview.h \

View file

@ -1,36 +0,0 @@
#ifndef _RENDERING_TERRAIN_RASTER_H_
#define _RENDERING_TERRAIN_RASTER_H_
#include "../rendering_global.h"
typedef struct
{
Vector3 point_nw;
Vector3 point_sw;
Vector3 point_se;
Vector3 point_ne;
int detail_hint;
} TerrainChunkInfo;
typedef int (*FuncTerrainTessellationCallback)(Renderer* renderer, TerrainChunkInfo* chunk, double progress);
/**
* Tessellate the terrain, yielding chunks information.
*
* The terrain will be broken in chunks, most detailed near the camera.
*/
RENDERINGSHARED_EXPORT void terrainGetTessellationInfo(Renderer* renderer, FuncTerrainTessellationCallback callback, int displaced);
/**
* Tessellate a terrain chunk, pushing the quads in the render area.
*/
RENDERINGSHARED_EXPORT void terrainTessellateChunk(Renderer* renderer, TerrainChunkInfo* chunk, int detail);
/**
* Start the final rasterization of terrain.
*
* This will push the rasterized quads in the render area, waiting for post process.
*/
RENDERINGSHARED_EXPORT void terrainRenderSurface(Renderer* renderer);
#endif