Voxvision  1
Creating and manipulating voxel octrees
Data Structures | Macros | Functions
renderer.h File Reference

The renderer. More...

#include <SDL2/SDL.h>
#include "../voxtrees/tree.h"
#include "camera.h"
#include "lights.h"

Go to the source code of this file.

Data Structures

struct  vox_rnd_ctx
 A renderer context. More...
 

Macros

#define VOX_QUALITY_BEST   0b00
 Best rendering quality. More...
 
#define VOX_QUALITY_FAST   0b01
 Fast rendering, middle quality. More...
 
#define VOX_QUALITY_ADAPTIVE   0b10
 Average rendering speed, good quality. More...
 
#define VOX_QUALITY_RAY_MERGE   0b0100
 Enable ray merging mode. More...
 
#define VOX_QUALITY_RAY_MERGE_ACCURATE   0b1000
 Accurate ray merging mode. More...
 
#define VOX_QUALITY_RM_MASK   0b1100 /* RM stands for Ray Merge */
 Ray merging mode mask.
 
#define VOX_QUALITY_MODE_MASK   0b11
 Rendering mode mask.
 

Functions

VOX_EXPORT struct vox_rnd_ctxvox_make_context_from_surface (SDL_Surface *surface)
 Make a renderer context from SDL surface. More...
 
VOX_EXPORT struct vox_rnd_ctxvox_make_context_and_window (unsigned int width, unsigned int height)
 Create a window and attach context to it. More...
 
VOX_EXPORT void vox_redraw (struct vox_rnd_ctx *ctx)
 Redraw a window associated with this context. More...
 
VOX_EXPORT void vox_context_set_scene (struct vox_rnd_ctx *ctx, struct vox_node *scene)
 Scene setter for renderer context.
 
VOX_EXPORT void vox_context_set_camera (struct vox_rnd_ctx *ctx, struct vox_camera *camera)
 Camera setter for renderer context.
 
VOX_EXPORT void vox_context_set_light_manager (struct vox_rnd_ctx *ctx, struct vox_light_manager *light_manager)
 Light manager setter for renderer context.
 
VOX_EXPORT int vox_context_set_quality (struct vox_rnd_ctx *ctx, unsigned int quality)
 Set quality of the renderer. More...
 
VOX_EXPORT void vox_destroy_context (struct vox_rnd_ctx *ctx)
 Free context after use.
 
VOX_EXPORT void vox_render (struct vox_rnd_ctx *ctx)
 Render a scene on SDL surface. More...
 

Detailed Description

The renderer.

Macro Definition Documentation

◆ VOX_QUALITY_ADAPTIVE

#define VOX_QUALITY_ADAPTIVE   0b10

Average rendering speed, good quality.

This settings tells the renderer to choose between VOX_QUALITY_FAST and VOX_QUALITY_BEST settings for each block of 4x4 pixels.

◆ VOX_QUALITY_BEST

#define VOX_QUALITY_BEST   0b00

Best rendering quality.

This quality setting forces the renderer to perform a full search for every rendered pixel starting from root of the tree.

◆ VOX_QUALITY_FAST

#define VOX_QUALITY_FAST   0b01

Fast rendering, middle quality.

This quality setting enables the renderer to reuse the tree leafs from a previous search to find an intersection of a ray from the camera and the tree. This may cause artifacts on edges of rendered objects.

◆ VOX_QUALITY_RAY_MERGE

#define VOX_QUALITY_RAY_MERGE   0b0100

Enable ray merging mode.

This mode allows a ray which belongs to every second column on the screen to be merged with a ray from every first if this ray travels a long distance from the origin. This mode works ONLY in conjunction with adaptive mode.

◆ VOX_QUALITY_RAY_MERGE_ACCURATE

#define VOX_QUALITY_RAY_MERGE_ACCURATE   0b1000

Accurate ray merging mode.

This mode is like standard ray merging mode, but it disables ray merging on edges of objects.

Function Documentation

◆ vox_context_set_quality()

VOX_EXPORT int vox_context_set_quality ( struct vox_rnd_ctx ctx,
unsigned int  quality 
)

Set quality of the renderer.

Parameters
ctxThe renderer's context.
qualityCurrently one of QUALITY_BEST, QUALITY_FAST or QUALITY_ADAPTIVE.
Returns
1 on success, 0 otherwise. Function call is unsuccessfull when quality parameter is wrong.

◆ vox_make_context_and_window()

VOX_EXPORT struct vox_rnd_ctx* vox_make_context_and_window ( unsigned int  width,
unsigned int  height 
)

Create a window and attach context to it.

This function creates a window and a context associated with it. vox_render() will render frames to an internal surface which can be shown on window with vox_redraw(). User must free it with vox_destroy_context() after use.

Parameters
widthWidth of the window.
heightHeight of the window.
Returns
Context or NULL in case of SDL error.

NB: width must be multiple of 16 and heigth must be multiple of 4. If this does not hold, function silently returns NULL.

◆ vox_make_context_from_surface()

VOX_EXPORT struct vox_rnd_ctx* vox_make_context_from_surface ( SDL_Surface *  surface)

Make a renderer context from SDL surface.

This function creates a renderer context based upon earlier created SDL surface. vox_render() will render frames to that surface. User must free it with vox_destroy_context() after use. The underlying surface will not be freed.

NB: Surface width must be multiple of 16 and surface heigth must be multiple of 4. If this does not hold, function silently returns NULL.

◆ vox_redraw()

VOX_EXPORT void vox_redraw ( struct vox_rnd_ctx ctx)

Redraw a window associated with this context.

This function will redraw window after call to vox_render() if context has a window.

◆ vox_render()

VOX_EXPORT void vox_render ( struct vox_rnd_ctx ctx)

Render a scene on SDL surface.

Parameters
ctxa renderer context