Switched rendering lib to c++ compiling

This will allow to avoid #if __cplusplus directives, and C-apis.
This commit is contained in:
Michaël Lemaire 2013-11-02 16:43:43 +01:00
parent d2620ae2e3
commit abd463d29d
56 changed files with 197 additions and 197 deletions

View file

@ -754,7 +754,7 @@ static int _inscatterNWorker(ParallelWork* work, int layer, void* data)
{
UNUSED(work);
InscatterNParams* params = data;
InscatterNParams* params = (InscatterNParams*)data;
double r;
Color dhdH;

View file

@ -42,7 +42,7 @@ static AtmosphereDefinition* _createDefinition()
brunetonInit();
}
result = malloc(sizeof(AtmosphereDefinition));
result = new AtmosphereDefinition;
atmosphereAutoPreset(result, ATMOSPHERE_PRESET_CLEAR_DAY);
@ -51,7 +51,7 @@ static AtmosphereDefinition* _createDefinition()
static void _deleteDefinition(AtmosphereDefinition* definition)
{
free(definition);
delete definition;
}
static void _copyDefinition(AtmosphereDefinition* source, AtmosphereDefinition* destination)

View file

@ -222,8 +222,8 @@ static AtmosphereRenderer* _createRenderer()
{
AtmosphereRenderer* result;
result = malloc(sizeof(AtmosphereRenderer));
result->definition = AtmosphereDefinitionClass.create();
result = new AtmosphereRenderer;
result->definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
result->getLightingStatus = _fakeGetLightingStatus;
result->getSunDirection = _realGetSunDirection;
@ -236,7 +236,7 @@ static AtmosphereRenderer* _createRenderer()
static void _deleteRenderer(AtmosphereRenderer* renderer)
{
AtmosphereDefinitionClass.destroy(renderer->definition);
free(renderer);
delete renderer;
}
static void _bindRenderer(Renderer* renderer, AtmosphereDefinition* definition)

View file

@ -52,7 +52,7 @@ CameraDefinition* cameraCreateDefinition()
{
CameraDefinition* definition;
definition = malloc(sizeof (CameraDefinition));
definition = new CameraDefinition;
definition->location.x = 0.0;
definition->location.y = 0.0;
@ -76,7 +76,7 @@ CameraDefinition* cameraCreateDefinition()
void cameraDeleteDefinition(CameraDefinition* definition)
{
free(definition);
delete definition;
}
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)

View file

@ -10,7 +10,7 @@ static void _validateDefinition(CloudsDefinition* definition)
static CloudsDefinition* _createDefinition()
{
CloudsDefinition* definition = malloc(sizeof(CloudsDefinition));
CloudsDefinition* definition = new CloudsDefinition;
definition->layers = layersCreate(cloudsGetLayerType(), CLOUDS_MAX_LAYERS);
@ -20,7 +20,7 @@ static CloudsDefinition* _createDefinition()
static void _deleteDefinition(CloudsDefinition* definition)
{
layersDelete(definition->layers);
free(definition);
delete definition;
}
static void _copyDefinition(CloudsDefinition* source, CloudsDefinition* destination)
@ -125,7 +125,7 @@ CloudsLayerDefinition* cloudsLayerCreateDefinition()
{
CloudsLayerDefinition* result;
result = malloc(sizeof(CloudsLayerDefinition));
result = new CloudsLayerDefinition;
result->_coverage_by_altitude = curveCreate();
result->_coverage_noise = noiseCreateGenerator();
result->_shape_noise = noiseCreateGenerator();
@ -142,7 +142,7 @@ void cloudsLayerDeleteDefinition(CloudsLayerDefinition* definition)
noiseDeleteGenerator(definition->_coverage_noise);
noiseDeleteGenerator(definition->_shape_noise);
noiseDeleteGenerator(definition->_edge_noise);
free(definition);
delete definition;
}
void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinition* destination)

View file

@ -16,7 +16,7 @@ void cloudsAutoPreset(CloudsDefinition* definition, CloudsPreset preset)
if (preset == CLOUDS_PRESET_PARTLY_CLOUDY)
{
layer = layersAddLayer(definition->layers, NULL);
cloudsLayerAutoPreset(layersGetLayer(definition->layers, layer), CLOUDS_LAYER_PRESET_CIRRUS);
cloudsLayerAutoPreset((CloudsLayerDefinition*)layersGetLayer(definition->layers, layer), CLOUDS_LAYER_PRESET_CIRRUS);
}
}

View file

@ -130,7 +130,7 @@ void cloudsPreviewMaterialBindLayer(Renderer* renderer, CloudsLayerDefinition* l
CloudsRendererClass.bind(renderer, definition);
CloudsDefinitionClass.destroy(definition);
layer = layersGetLayer(renderer->clouds->definition->layers, 0);
layer = (CloudsLayerDefinition*)layersGetLayer(renderer->clouds->definition->layers, 0);
layer->thickness = layer->shape_scaling;
layer->lower_altitude = -layer->thickness / 2.0;
@ -140,7 +140,7 @@ void cloudsPreviewMaterialBindLayer(Renderer* renderer, CloudsLayerDefinition* l
Color cloudsPreviewMaterialGetPixel(Renderer* renderer, double x, double y)
{
Vector3 start, end;
CloudsLayerDefinition* layer = layersGetLayer(renderer->clouds->definition->layers, 0);
CloudsLayerDefinition* layer = (CloudsLayerDefinition*)layersGetLayer(renderer->clouds->definition->layers, 0);
double thickness = layer->thickness;
start.x = x * thickness * 0.5;

View file

@ -248,8 +248,8 @@ static CloudsRenderer* _createRenderer()
{
CloudsRenderer* result;
result = malloc(sizeof(CloudsRenderer));
result->definition = CloudsDefinitionClass.create();
result = new CloudsRenderer;
result->definition = (CloudsDefinition*)CloudsDefinitionClass.create();
result->getColor = _fakeGetColor;
result->alterLight = (FuncLightingAlterLight)_fakeAlterLight;
@ -262,7 +262,7 @@ static CloudsRenderer* _createRenderer()
static void _deleteRenderer(CloudsRenderer* renderer)
{
CloudsDefinitionClass.destroy(renderer->definition);
free(renderer);
delete renderer;
}
static void _bindRenderer(Renderer* renderer, CloudsDefinition* definition)

View file

@ -73,7 +73,7 @@ NoiseGenerator* noiseCreateGenerator()
NoiseGenerator* result;
/* initialize */
result = malloc(sizeof(NoiseGenerator));
result = new NoiseGenerator;
result->function.algorithm = NOISE_FUNCTION_SIMPLEX;
result->function.ridge_factor = 0.0;
result->function.curve_factor = 0.0;
@ -88,7 +88,7 @@ NoiseGenerator* noiseCreateGenerator()
void noiseDeleteGenerator(NoiseGenerator* generator)
{
free(generator);
delete generator;
}
void noiseSaveGenerator(PackStream* stream, NoiseGenerator* generator)

View file

@ -17,7 +17,7 @@ void noiseNaiveInit()
int i;
_noise_pool_size = 1048576;
_noise_pool = malloc(sizeof(double) * _noise_pool_size);
_noise_pool = new double[_noise_pool_size];
for (i = 0; i < _noise_pool_size; i++)
{
@ -27,7 +27,7 @@ void noiseNaiveInit()
void noiseNaiveQuit()
{
free(_noise_pool);
delete[] _noise_pool;
}
void noiseNaiveSave(PackStream* stream)
@ -46,7 +46,8 @@ void noiseNaiveLoad(PackStream* stream)
int i;
packReadInt(stream, &_noise_pool_size);
_noise_pool = realloc(_noise_pool, sizeof(double) * _noise_pool_size);
delete[] _noise_pool;
_noise_pool = new double[_noise_pool_size];
for (i = 0; i < _noise_pool_size; i++)
{
packReadDouble(stream, _noise_pool + i);

View file

@ -1,4 +1,4 @@
#include "noisesimplex.h"
#include "noiseperlin.h"
/*
* Perlin noise implementation.

View file

@ -89,9 +89,9 @@ typedef struct
RenderArea* area;
} RenderChunk;
static void _callbackStart(int width, int height, Color background) {}
static void _callbackDraw(int x, int y, Color col) {}
static void _callbackUpdate(double progress) {}
static void _callbackStart(int, int, Color) {}
static void _callbackDraw(int, int, Color) {}
static void _callbackUpdate(double) {}
void renderInit()
{
@ -105,7 +105,7 @@ RenderArea* renderCreateArea(Renderer* renderer)
{
RenderArea* result;
result = malloc(sizeof(RenderArea));
result = new RenderArea;
result->renderer = renderer;
result->hdr_mapping = colorProfileCreate();
result->params.width = 1;
@ -113,7 +113,7 @@ RenderArea* renderCreateArea(Renderer* renderer)
result->params.antialias = 1;
result->params.quality = 5;
result->pixel_count = 1;
result->pixels = malloc(sizeof(RenderFragment));
result->pixels = new RenderFragment[1];
result->fragment_callbacks_count = 0;
result->background_color = COLOR_TRANSPARENT;
result->dirty_left = 1;
@ -153,7 +153,8 @@ void renderSetParams(RenderArea* area, RenderParams params)
height = params.height * params.antialias;
area->params = params;
area->pixels = realloc(area->pixels, sizeof(RenderFragment) * width * height);
delete[] area->pixels;
area->pixels = new RenderFragment[width * height];
area->pixel_count = width * height;
area->dirty_left = width;
@ -562,8 +563,8 @@ void renderPushTriangle(RenderArea* area, Vector3 pixel1, Vector3 pixel2, Vector
int width = area->params.width * area->params.antialias;
scanlines.left = width;
scanlines.right = -1;
scanlines.up = malloc(sizeof(ScanPoint) * width);
scanlines.down = malloc(sizeof(ScanPoint) * width);
scanlines.up = new ScanPoint[width];
scanlines.down = new ScanPoint[width];
for (x = 0; x < width; x++)
{
/* TODO Do not initialize whole width each time, init only when needed on point push */

View file

@ -120,7 +120,7 @@ static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color c
Renderer* rendererCreate()
{
Renderer* result = malloc(sizeof (Renderer));
Renderer* result = new Renderer;
RenderParams params = {1, 1, 1, 5};
result->render_quality = 5;
@ -152,11 +152,11 @@ Renderer* rendererCreate()
result->lighting = lightingManagerCreate();
result->atmosphere = AtmosphereRendererClass.create();
result->clouds = CloudsRendererClass.create();
result->terrain = TerrainRendererClass.create();
result->textures = TexturesRendererClass.create();
result->water = WaterRendererClass.create();
result->atmosphere = (AtmosphereRenderer*)AtmosphereRendererClass.create();
result->clouds = (CloudsRenderer*)CloudsRendererClass.create();
result->terrain = (TerrainRenderer*)TerrainRendererClass.create();
result->textures = (TexturesRenderer*)TexturesRendererClass.create();
result->water = (WaterRenderer*)WaterRendererClass.create();
return result;
}
@ -174,7 +174,7 @@ void rendererDelete(Renderer* renderer)
renderDeleteArea(renderer->render_area);
free(renderer);
delete renderer;
}
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)

View file

@ -9,58 +9,58 @@ CONFIG(release, debug|release): DEFINES += NDEBUG
INCLUDEPATH += $$PWD/..
SOURCES += main.c \
tools.c \
renderer.c \
render.c \
opencl.c \
noisesimplex.c \
noiseperlin.c \
noisenaive.c \
noise.c \
geoarea.c \
camera.c \
atmosphere/atm_render.c \
atmosphere/atm_raster.c \
atmosphere/atm_preview.c \
atmosphere/atm_presets.c \
atmosphere/atm_definition.c \
atmosphere/atm_bruneton.c \
clouds/clo_walking.c \
clouds/clo_rendering.c \
clouds/clo_preview.c \
clouds/clo_presets.c \
clouds/clo_density.c \
clouds/clo_definition.c \
shared/preview.c \
terrain/ter_render.c \
terrain/ter_raster.c \
terrain/ter_preview.c \
terrain/ter_presets.c \
terrain/ter_painting.c \
terrain/ter_definition.c \
textures/tex_tools.c \
textures/tex_rendering.c \
textures/tex_preview.c \
textures/tex_presets.c \
textures/tex_definition.c \
tools/zone.c \
tools/texture.c \
tools/parallel.c \
tools/memory.c \
tools/lighting.c \
tools/euclid.c \
tools/data.c \
tools/curve.c \
tools/color.c \
tools/cache.c \
tools/boundingbox.c \
tools/array.c \
water/wat_render.c \
water/wat_raster.c \
water/wat_preview.c \
water/wat_presets.c \
water/wat_definition.c \
SOURCES += main.cpp \
tools.cpp \
renderer.cpp \
render.cpp \
opencl.cpp \
noisesimplex.cpp \
noiseperlin.cpp \
noisenaive.cpp \
noise.cpp \
geoarea.cpp \
camera.cpp \
atmosphere/atm_render.cpp \
atmosphere/atm_raster.cpp \
atmosphere/atm_preview.cpp \
atmosphere/atm_presets.cpp \
atmosphere/atm_definition.cpp \
atmosphere/atm_bruneton.cpp \
clouds/clo_walking.cpp \
clouds/clo_rendering.cpp \
clouds/clo_preview.cpp \
clouds/clo_presets.cpp \
clouds/clo_density.cpp \
clouds/clo_definition.cpp \
shared/preview.cpp \
terrain/ter_render.cpp \
terrain/ter_raster.cpp \
terrain/ter_preview.cpp \
terrain/ter_presets.cpp \
terrain/ter_painting.cpp \
terrain/ter_definition.cpp \
textures/tex_tools.cpp \
textures/tex_rendering.cpp \
textures/tex_preview.cpp \
textures/tex_presets.cpp \
textures/tex_definition.cpp \
tools/zone.cpp \
tools/texture.cpp \
tools/parallel.cpp \
tools/memory.cpp \
tools/lighting.cpp \
tools/euclid.cpp \
tools/data.cpp \
tools/curve.cpp \
tools/color.cpp \
tools/cache.cpp \
tools/boundingbox.cpp \
tools/array.cpp \
water/wat_render.cpp \
water/wat_raster.cpp \
water/wat_preview.cpp \
water/wat_presets.cpp \
water/wat_definition.cpp \
Scenery.cpp
HEADERS += \

View file

@ -25,7 +25,7 @@ static void _validateDefinition(TerrainDefinition* definition)
static TerrainDefinition* _createDefinition()
{
TerrainDefinition* definition = malloc(sizeof(TerrainDefinition));
TerrainDefinition* definition = new TerrainDefinition;
definition->height = 1.0;
definition->scaling = 1.0;
@ -46,7 +46,7 @@ static void _deleteDefinition(TerrainDefinition* definition)
{
terrainHeightmapDelete(definition->height_map);
noiseDeleteGenerator(definition->_height_noise);
free(definition);
delete definition;
}
static void _copyDefinition(TerrainDefinition* source, TerrainDefinition* destination)

View file

@ -43,7 +43,7 @@ struct TerrainHeightMap
static void _initData(HeightMapData* data)
{
data->rows_count = 0;
data->rows = malloc(1);
data->rows = new HeightMapRow[1];
data->memsize = 0;
}
@ -59,14 +59,15 @@ static void _clearData(HeightMapData* data)
free(data->rows[i].pixel_groups);
}
data->rows_count = 0;
data->rows = realloc(data->rows, 1);
delete[] data->rows;
data->rows = new HeightMapRow[1];
data->memsize = 0;
}
static void _deleteData(HeightMapData* data)
{
_clearData(data);
free(data->rows);
delete[] data->rows;
}
static void _copyData(HeightMapData* source, HeightMapData* destination)
@ -80,14 +81,14 @@ static void _copyData(HeightMapData* source, HeightMapData* destination)
if (destination->rows_count > 0)
{
size = sizeof(HeightMapRow) * destination->rows_count;
destination->rows = realloc(destination->rows, size);
destination->rows = (HeightMapRow*)realloc(destination->rows, size);
destination->memsize += size;
for (i = 0; i < destination->rows_count; i++)
{
destination->rows[i].z = source->rows[i].z;
destination->rows[i].pixel_groups_count = source->rows[i].pixel_groups_count;
size = sizeof(HeightMapPixelGroup) * destination->rows[i].pixel_groups_count;
destination->rows[i].pixel_groups = malloc(size);
destination->rows[i].pixel_groups = (HeightMapPixelGroup*)malloc(size);
destination->memsize += size;
for (j = 0; j < destination->rows[i].pixel_groups_count; j++)
{
@ -95,7 +96,7 @@ static void _copyData(HeightMapData* source, HeightMapData* destination)
destination->rows[i].pixel_groups[j].xend = source->rows[i].pixel_groups[j].xend;
n = destination->rows[i].pixel_groups[j].xend - destination->rows[i].pixel_groups[j].xstart + 1;
size = sizeof(double) * n;
destination->rows[i].pixel_groups[j].height = malloc(size);
destination->rows[i].pixel_groups[j].height = (double*)malloc(size);
destination->memsize += size;
memcpy(destination->rows[i].pixel_groups[j].height, source->rows[i].pixel_groups[j].height, size);
}
@ -134,14 +135,14 @@ static void _loadData(PackStream* stream, HeightMapData* data)
if (data->rows_count > 0)
{
size = sizeof(HeightMapRow) * data->rows_count;
data->rows = realloc(data->rows, size);
data->rows = (HeightMapRow*)realloc(data->rows, size);
data->memsize += size;
for (i = 0; i < data->rows_count; i++)
{
packReadInt(stream, &data->rows[i].z);
packReadInt(stream, &data->rows[i].pixel_groups_count);
size = sizeof(HeightMapPixelGroup) * data->rows[i].pixel_groups_count;
data->rows[i].pixel_groups = malloc(size);
data->rows[i].pixel_groups = (HeightMapPixelGroup*)malloc(size);
data->memsize += size;
for (j = 0; j < data->rows[i].pixel_groups_count; j++)
{
@ -149,7 +150,7 @@ static void _loadData(PackStream* stream, HeightMapData* data)
packReadInt(stream, &data->rows[i].pixel_groups[j].xend);
n = data->rows[i].pixel_groups[j].xend - data->rows[i].pixel_groups[j].xstart;
size = sizeof(double) * n;
data->rows[i].pixel_groups[j].height = malloc(size);
data->rows[i].pixel_groups[j].height = (double*)malloc(size);
data->memsize += size;
for (k = 0; k < n; k++)
{
@ -183,11 +184,11 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData*
}
else if (grow)
{
row = naiveArrayInsert((void**)&data->rows, sizeof(HeightMapRow), data->rows_count, i);
row = (HeightMapRow*)naiveArrayInsert((void**)&data->rows, sizeof(HeightMapRow), data->rows_count, i);
row->z = z;
row->pixel_groups_count = 0;
row->pixel_groups = malloc(1);
row->pixel_groups = (HeightMapPixelGroup*)malloc(1);
data->rows_count++;
data->memsize += sizeof(HeightMapRow);
@ -236,11 +237,11 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData*
}
/* Create the pixel group with one pixel */
pixel_group = naiveArrayInsert((void**)&row->pixel_groups, sizeof(HeightMapPixelGroup), row->pixel_groups_count, i);
pixel_group = (HeightMapPixelGroup*)naiveArrayInsert((void**)&row->pixel_groups, sizeof(HeightMapPixelGroup), row->pixel_groups_count, i);
pixel_group->xstart = x;
pixel_group->xend = x;
pixel_group->height = malloc(sizeof(double));
pixel_group->height = (double*)malloc(sizeof(double));
pixel = pixel_group->height;
@ -256,7 +257,7 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData*
/* Extend the rowgroup at start */
pixel_group->xstart--;
pixel = naiveArrayInsert((void**)&pixel_group->height, sizeof(double), pixel_group->xend - pixel_group->xstart, 0);
pixel = (double*)naiveArrayInsert((void**)&pixel_group->height, sizeof(double), pixel_group->xend - pixel_group->xstart, 0);
data->memsize += sizeof(double);
}
else if (x == pixel_group->xend + 1)
@ -268,7 +269,7 @@ static double* _getDataPointer(HeightMapData* data, int x, int z, HeightMapData*
/* Extend the rowgroup at end */
pixel_group->xend++;
pixel = naiveArrayInsert((void**)&pixel_group->height, sizeof(double), pixel_group->xend - pixel_group->xstart, pixel_group->xend - pixel_group->xstart);
pixel = (double*)naiveArrayInsert((void**)&pixel_group->height, sizeof(double), pixel_group->xend - pixel_group->xstart, pixel_group->xend - pixel_group->xstart);
data->memsize += sizeof(double);
}
else
@ -322,7 +323,7 @@ TerrainHeightMap* terrainHeightMapCreate(TerrainDefinition* terrain)
{
TerrainHeightMap* result;
result = malloc(sizeof(TerrainHeightMap));
result = new TerrainHeightMap;
result->terrain = terrain;
_initData(&result->merged_data);
_initData(&result->brush_data);
@ -334,7 +335,7 @@ void terrainHeightmapDelete(TerrainHeightMap* heightmap)
{
_deleteData(&heightmap->merged_data);
_deleteData(&heightmap->brush_data);
free(heightmap);
delete heightmap;
}
void terrainHeightmapCopy(TerrainHeightMap* source, TerrainHeightMap* destination)
@ -516,7 +517,7 @@ void terrainBrushElevation(TerrainHeightMap* heightmap, TerrainBrush* brush, dou
_applyBrush(heightmap, brush, value, NULL, _applyBrushElevation);
}
static double _applyBrushFlatten(TerrainHeightMap* heightmap, TerrainBrush* brush, double x, double z, double basevalue, double influence, double force, void* data)
static double _applyBrushFlatten(TerrainHeightMap* heightmap, TerrainBrush* brush, double, double, double basevalue, double influence, double force, void* data)
{
UNUSED(heightmap);
UNUSED(brush);

View file

@ -58,9 +58,9 @@ Renderer* terrainCreatePreviewRenderer()
result->atmosphere->getLightingStatus = _getLightingStatus;
TexturesDefinition* textures;
textures = TexturesDefinitionClass.create();
textures = (TexturesDefinition*)TexturesDefinitionClass.create();
layersClear(textures->layers);
TexturesLayerDefinition* layer = layersGetLayer(textures->layers, layersAddLayer(textures->layers, NULL));
TexturesLayerDefinition* layer = (TexturesLayerDefinition*)layersGetLayer(textures->layers, layersAddLayer(textures->layers, NULL));
zoneClear(layer->terrain_zone);
layer->displacement_height = 0.0;
layer->material.base = colorToHSL(COLOR_WHITE);

View file

@ -26,7 +26,7 @@ static inline Vector3 _getPoint(TerrainDefinition* definition, Renderer* rendere
return result;
}
static Color _postProcessFragment(Renderer* renderer, Vector3 point, void* data)
static Color _postProcessFragment(Renderer* renderer, Vector3 point, void*)
{
double precision;
@ -228,14 +228,14 @@ static int _parallelJobCallback(ParallelQueue* queue, int job_id, void* data, in
static int _standardTessellationCallback(Renderer* renderer, TerrainChunkInfo* chunk, double progress)
{
ParallelRasterInfo* info = malloc(sizeof(ParallelRasterInfo));
ParallelRasterInfo* info = new ParallelRasterInfo;
info->renderer = renderer;
info->chunk = *chunk;
if (!parallelQueueAddJob(renderer->customData[0], _parallelJobCallback, info))
if (!parallelQueueAddJob((ParallelQueue*)renderer->customData[0], _parallelJobCallback, info))
{
free(info);
delete info;
}
renderer->render_progress = 0.05 * progress;

View file

@ -311,8 +311,8 @@ static TerrainRenderer* _createRenderer()
{
TerrainRenderer* result;
result = malloc(sizeof (TerrainRenderer));
result->definition = TerrainDefinitionClass.create();
result = new TerrainRenderer;
result->definition = (TerrainDefinition*)TerrainDefinitionClass.create();
result->castRay = _fakeCastRay;
result->getHeight = _fakeGetHeight;
@ -326,7 +326,7 @@ static TerrainRenderer* _createRenderer()
static void _deleteRenderer(TerrainRenderer* renderer)
{
TerrainDefinitionClass.destroy(renderer->definition);
free(renderer);
delete renderer;
}
static void _bindRenderer(Renderer* renderer, TerrainDefinition* definition)

View file

@ -11,7 +11,7 @@ static void _validateDefinition(TexturesDefinition* definition)
static TexturesDefinition* _createDefinition()
{
TexturesDefinition* definition = malloc(sizeof(TexturesDefinition));
TexturesDefinition* definition = new TexturesDefinition;
definition->layers = layersCreate(texturesGetLayerType(), TEXTURES_MAX_LAYERS);
@ -21,7 +21,7 @@ static TexturesDefinition* _createDefinition()
static void _deleteDefinition(TexturesDefinition* definition)
{
layersDelete(definition->layers);
free(definition);
delete definition;
}
static void _copyDefinition(TexturesDefinition* source, TexturesDefinition* destination)
@ -82,7 +82,7 @@ static TexturesLayerDefinition* _layerCreateDefinition()
{
TexturesLayerDefinition* result;
result = malloc(sizeof(TexturesLayerDefinition));
result = new TexturesLayerDefinition;
result->terrain_zone = zoneCreate();
result->_displacement_noise = noiseCreateGenerator();
@ -100,7 +100,7 @@ static void _layerDeleteDefinition(TexturesLayerDefinition* definition)
zoneDelete(definition->terrain_zone);
noiseDeleteGenerator(definition->_displacement_noise);
noiseDeleteGenerator(definition->_detail_noise);
free(definition);
delete definition;
}
static void _layerCopyDefinition(TexturesLayerDefinition* source, TexturesLayerDefinition* destination)

View file

@ -5,45 +5,45 @@ void texturesAutoPreset(TexturesDefinition* definition, TexturesPreset preset)
TexturesLayerDefinition* layer;
layersClear(definition->layers);
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_MUD);
layersSetName(definition->layers, 0, "Mud");
if (preset == TEXTURES_PRESET_FULL)
{
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_ROCK);
layersSetName(definition->layers, 1, "Ground");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_GRASS);
layersSetName(definition->layers, 2, "Grass");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_SAND);
layersSetName(definition->layers, 3, "Sand");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_SNOW);
layersSetName(definition->layers, 4, "Snow");
}
else if (preset == TEXTURES_PRESET_IRELAND)
{
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_ROCK);
layersSetName(definition->layers, 1, "Ground");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_GRASS);
layersSetName(definition->layers, 2, "Grass");
}
else if (preset == TEXTURES_PRESET_ALPS)
{
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_ROCK);
layersSetName(definition->layers, 1, "Ground");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
layer = (TexturesLayerDefinition*)layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_SNOW);
layersSetName(definition->layers, 2, "Snow");
}

View file

@ -1,13 +1,13 @@
#ifndef TEX_PREVIEW_H
#define TEX_PREVIEW_H
#include "rendering/renderer.h"
#include "rendering/textures/public.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "rendering/renderer.h"
#include "rendering/textures/public.h"
/* Single layer coverage */
RENDERINGSHARED_EXPORT void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition);
RENDERINGSHARED_EXPORT Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double y, double scaling, int layer);

View file

@ -91,7 +91,7 @@ static Vector3 _realDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
n = layersCount(textures->layers);
for (i = 0; i < n; i++)
{
TexturesLayerDefinition* layer = layersGetLayer(textures->layers, i);
TexturesLayerDefinition* layer = (TexturesLayerDefinition*)layersGetLayer(textures->layers, i);
if (layer->displacement_height > 0.0)
{
@ -106,7 +106,7 @@ static Vector3 _realDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
static double _realGetBasePresence(Renderer* renderer, int layer, TerrainResult terrain)
{
TexturesLayerDefinition* layerdef = layersGetLayer(renderer->textures->definition->layers, layer);
TexturesLayerDefinition* layerdef = (TexturesLayerDefinition*)layersGetLayer(renderer->textures->definition->layers, layer);
return texturesGetLayerBasePresence(layerdef, terrain);
}
@ -126,7 +126,7 @@ static TexturesResult _realApplyToTerrain(Renderer* renderer, double x, double z
for (i = 0; i < n; i++)
{
TexturesLayerResult* info = result.layers + i;
info->layer = layersGetLayer(textures->layers, i);
info->layer = (TexturesLayerDefinition*)layersGetLayer(textures->layers, i);
info->presence = renderer->textures->getBasePresence(renderer, i, terrain);
if (info->presence > 0.0)
{
@ -195,8 +195,8 @@ static TexturesRenderer* _createRenderer()
{
TexturesRenderer* result;
result = malloc(sizeof(TexturesRenderer));
result->definition = TexturesDefinitionClass.create();
result = new TexturesRenderer;
result->definition = (TexturesDefinition*)TexturesDefinitionClass.create();
result->displaceTerrain = _fakeDisplaceTerrain;
result->getBasePresence = _fakeGetBasePresence;
@ -208,7 +208,7 @@ static TexturesRenderer* _createRenderer()
static void _deleteRenderer(TexturesRenderer* renderer)
{
TexturesDefinitionClass.destroy(renderer->definition);
free(renderer);
delete renderer;
}
static void _bindRenderer(Renderer* renderer, TexturesDefinition* definition)

View file

@ -40,7 +40,7 @@ double texturesGetMaximalDisplacement(TexturesDefinition* textures)
n = layersCount(textures->layers);
for (i = 0; i < n; i++)
{
TexturesLayerDefinition* layer = layersGetLayer(textures->layers, i);
TexturesLayerDefinition* layer = (TexturesLayerDefinition*)layersGetLayer(textures->layers, i);
if (layer->displacement_height > 0.0)
{

View file

@ -14,9 +14,9 @@ CacheFile* cacheFileCreateAccessor(const char* module, const char* ext, const ch
{
CacheFile* result;
result = (CacheFile*)malloc(sizeof(CacheFile));
result->datapath = malloc(sizeof(char) * 501);
result->filepath = malloc(sizeof(char) * 501);
result = new CacheFile;
result->datapath = (char*)malloc(sizeof(char) * 501);
result->filepath = (char*)malloc(sizeof(char) * 501);
snprintf(result->datapath, 500, "/usr/share/paysages3d/%s-%s-%d-%d-%d-%d-%d.%s", module, tag1, tag2, tag3, tag4, tag5, tag6, ext);
snprintf(result->filepath, 500, "./cache/%s-%s-%d-%d-%d-%d-%d.%s", module, tag1, tag2, tag3, tag4, tag5, tag6, ext);
@ -28,7 +28,7 @@ void cacheFileDeleteAccessor(CacheFile* cache)
{
free(cache->datapath);
free(cache->filepath);
free(cache);
delete cache;
}
int cacheFileIsReadable(CacheFile* cache)

View file

@ -223,7 +223,7 @@ ColorProfile* colorProfileCreate()
{
ColorProfile* profile;
profile = malloc(sizeof (ColorProfile));
profile = new ColorProfile;
colorProfileSetToneMapping(profile, TONE_MAPPING_UNCHARTED, 2.0);
colorProfileClear(profile);
@ -233,7 +233,7 @@ ColorProfile* colorProfileCreate()
void colorProfileDelete(ColorProfile* profile)
{
free(profile);
delete profile;
}
static inline double _uncharted2Tonemap(double x)
@ -347,7 +347,7 @@ ColorGradation* colorGradationCreate()
{
ColorGradation* result;
result = malloc(sizeof (ColorGradation));
result = new ColorGradation;
result->red = curveCreate();
result->green = curveCreate();
result->blue = curveCreate();
@ -360,7 +360,7 @@ void colorGradationDelete(ColorGradation* gradation)
curveDelete(gradation->red);
curveDelete(gradation->green);
curveDelete(gradation->blue);
free(gradation);
delete gradation;
}
void colorGradationCopy(ColorGradation* source, ColorGradation* destination)

View file

@ -17,7 +17,7 @@ Curve* curveCreate()
{
Curve* result;
result = malloc(sizeof(Curve));
result = new Curve;
result->nbpoints = 0;
result->default_value = 0.0;
@ -26,7 +26,7 @@ Curve* curveCreate()
void curveDelete(Curve* curve)
{
free(curve);
delete curve;
}
void curveCopy(Curve* source, Curve* destination)

View file

@ -10,7 +10,7 @@ static int _tryDataPath(const char* path)
{
char* buffer;
buffer = malloc(sizeof (char) * (strlen(path) + 30));
buffer = (char*)malloc(sizeof (char) * (strlen(path) + 30));
strcpy(buffer, path);
strcat(buffer, "/.paysages_data");

View file

@ -34,7 +34,7 @@ LightingManager* lightingManagerCreate()
{
LightingManager* result;
result = malloc(sizeof(LightingManager));
result = new LightingManager;
result->callbacks_count = 0;
result->specularity_enabled = 1;
@ -43,7 +43,7 @@ LightingManager* lightingManagerCreate()
void lightingManagerDelete(LightingManager* filter)
{
free(filter);
delete filter;
}
void lightingManagerRegisterFilter(LightingManager* filter, FuncLightingAlterLight callback, void* data)
@ -76,7 +76,7 @@ LightStatus* lightingCreateStatus(LightingManager* manager, Vector3 location, Ve
{
LightStatus* result;
result = malloc(sizeof(LightStatus));
result = new LightStatus;
result->manager = manager;
result->location = location;
result->eye = eye;
@ -87,7 +87,7 @@ LightStatus* lightingCreateStatus(LightingManager* manager, Vector3 location, Ve
void lightingDeleteStatus(LightStatus* status)
{
free(status);
delete status;
}
void lightingPushLight(LightStatus* status, LightDefinition* light)

View file

@ -50,8 +50,3 @@ void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int
free(data);
return result;
}
void memory2dScrolling(void* data, int datasize, int xsize, int ysize, int xoffset, int yoffset)
{
/* TODO */
}

View file

@ -12,7 +12,6 @@ extern "C" {
#endif
RENDERINGSHARED_EXPORT void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset);
RENDERINGSHARED_EXPORT void memory2dScrolling(void* data, int datasize, int xsize, int ysize, int xoffset, int yoffset);
#ifdef __cplusplus
}

View file

@ -239,13 +239,13 @@ ParallelQueue* parallelQueueCreate(int collect)
assert(!collect); /* Not fully implemented yet ! */
ParallelQueue* queue = malloc(sizeof(ParallelQueue));
ParallelQueue* queue = new ParallelQueue;
queue->collect = collect;
queue->stopping = 0;
queue->lock = mutexCreate();
queue->jobs = malloc(sizeof(ParallelJob) * QUEUE_SIZE);
queue->jobs = new ParallelJob[QUEUE_SIZE];
for (i = 0; i < QUEUE_SIZE; i++)
{
queue->jobs[i].state = JOB_STATE_FREE;
@ -258,7 +258,7 @@ ParallelQueue* parallelQueueCreate(int collect)
/* Start workers */
queue->workers_count = systemGetCoreCount();
queue->workers = malloc(sizeof(Thread*) * queue->workers_count);
queue->workers = new Thread*[queue->workers_count];
for (i = 0; i < queue->workers_count; i++)
{
queue->workers[i] = threadCreate((ThreadFunction)_queueThreadCallback, queue);
@ -275,9 +275,9 @@ void parallelQueueDelete(ParallelQueue* queue)
assert(queue->jobs_count == 0);
mutexDestroy(queue->lock);
free(queue->jobs);
free(queue->workers);
free(queue);
delete[] queue->jobs;
delete[] queue->workers;
delete queue;
}
void parallelQueueInterrupt(ParallelQueue* queue)
@ -350,7 +350,7 @@ int parallelQueueAddJob(ParallelQueue* queue, FuncParallelJob func_process, void
return job.id;
}
int parallelQueueCollectJobs(FuncParallelJob func_collect)
int parallelQueueCollectJobs(FuncParallelJob)
{
/* TODO */
return 0;

View file

@ -51,18 +51,18 @@ Texture2D* texture2DCreate(int xsize, int ysize)
assert(xsize > 0 && ysize > 0);
result = (Texture2D*)malloc(sizeof(Texture2D));
result = new Texture2D;
result->xsize = xsize;
result->ysize = ysize;
result->data = malloc(sizeof(Color) * xsize * ysize);
result->data = new Color[xsize * ysize];
return result;
}
void texture2DDelete(Texture2D* tex)
{
free(tex->data);
free(tex);
delete[] tex->data;
delete tex;
}
void texture2DGetSize(Texture2D* tex, int* xsize, int* ysize)
@ -186,7 +186,8 @@ void texture2DLoad(PackStream* stream, Texture2D* tex)
packReadInt(stream, &tex->xsize);
packReadInt(stream, &tex->ysize);
n = tex->xsize * tex->ysize;
tex->data = realloc(tex->data, sizeof(Color) * n);
delete[] tex->data;
tex->data = new Color[n];
for (i = 0; i < n; i++)
{
colorLoad(stream, tex->data + i);
@ -207,19 +208,19 @@ Texture3D* texture3DCreate(int xsize, int ysize, int zsize)
assert(xsize > 0 && ysize > 0 && zsize > 0);
result = (Texture3D*)malloc(sizeof(Texture3D));
result = new Texture3D;
result->xsize = xsize;
result->ysize = ysize;
result->zsize = zsize;
result->data = malloc(sizeof(Color) * xsize * ysize * zsize);
result->data = new Color[xsize * ysize * zsize];
return result;
}
void texture3DDelete(Texture3D* tex)
{
free(tex->data);
free(tex);
delete[] tex->data;
delete tex;
}
void texture3DGetSize(Texture3D* tex, int* xsize, int* ysize, int* zsize)
@ -368,7 +369,8 @@ void texture3DLoad(PackStream* stream, Texture3D* tex)
packReadInt(stream, &tex->ysize);
packReadInt(stream, &tex->zsize);
n = tex->xsize * tex->ysize * tex->zsize;
tex->data = realloc(tex->data, sizeof(Color) * n);
delete[] tex->data;
tex->data = new Color[n];
for (i = 0; i < n; i++)
{
colorLoad(stream, tex->data + i);
@ -400,20 +402,20 @@ Texture4D* texture4DCreate(int xsize, int ysize, int zsize, int wsize)
assert(xsize > 0 && ysize > 0 && zsize > 0 && wsize > 0);
result = (Texture4D*)malloc(sizeof(Texture4D));
result = new Texture4D;
result->xsize = xsize;
result->ysize = ysize;
result->zsize = zsize;
result->wsize = wsize;
result->data = malloc(sizeof(Color) * xsize * ysize * zsize * wsize);
result->data = new Color[xsize * ysize * zsize * wsize];
return result;
}
void texture4DDelete(Texture4D* tex)
{
free(tex->data);
free(tex);
delete[] tex->data;
delete tex;
}
void texture4DGetSize(Texture4D* tex, int* xsize, int* ysize, int* zsize, int* wsize)
@ -595,7 +597,8 @@ void texture4DLoad(PackStream* stream, Texture4D* tex)
packReadInt(stream, &tex->zsize);
packReadInt(stream, &tex->wsize);
n = tex->xsize * tex->ysize * tex->zsize * tex->wsize;
tex->data = realloc(tex->data, sizeof(Color) * n);
delete[] tex->data;
tex->data = new Color[n];
for (i = 0; i < n; i++)
{
colorLoad(stream, tex->data + i);

View file

@ -5,14 +5,14 @@
* Pixel based textures.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "../rendering_global.h"
#include "color.h"
#include "PackStream.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct Texture2D Texture2D;
typedef struct Texture3D Texture3D;
typedef struct Texture4D Texture4D;

View file

@ -23,7 +23,7 @@ static void _validateDefinition(WaterDefinition* definition)
static WaterDefinition* _createDefinition()
{
WaterDefinition* definition = malloc(sizeof(WaterDefinition));
WaterDefinition* definition = new WaterDefinition;
definition->_waves_noise = noiseCreateGenerator();
@ -35,7 +35,7 @@ static WaterDefinition* _createDefinition()
static void _deleteDefinition(WaterDefinition* definition)
{
noiseDeleteGenerator(definition->_waves_noise);
free(definition);
delete definition;
}
static void _copyDefinition(WaterDefinition* source, WaterDefinition* destination)

View file

@ -99,7 +99,7 @@ void waterRenderSurface(Renderer* renderer)
for (i = 0; i < chunk_count - 1; i++)
{
info = malloc(sizeof(ParallelRasterInfo));
info = new ParallelRasterInfo;
info->renderer = renderer;
info->cx = cx;
@ -111,7 +111,7 @@ void waterRenderSurface(Renderer* renderer)
if (!parallelQueueAddJob(queue, _parallelJobCallback, info))
{
free(info);
delete info;
}
}

View file

@ -302,8 +302,8 @@ static WaterRenderer* _createRenderer()
{
WaterRenderer* result;
result = malloc(sizeof(WaterRenderer));
result->definition = WaterDefinitionClass.create();
result = new WaterRenderer;
result->definition = (WaterDefinition*)WaterDefinitionClass.create();
result->getHeightInfo = _fakeGetHeightInfo;
result->getHeight = _fakeGetHeight;
@ -315,7 +315,7 @@ static WaterRenderer* _createRenderer()
static void _deleteRenderer(WaterRenderer* renderer)
{
WaterDefinitionClass.destroy(renderer->definition);
free(renderer);
delete renderer;
}
static void _bindRenderer(Renderer* renderer, WaterDefinition* definition)