Voxvision  1
Creating and manipulating voxel octrees
renderer.h
Go to the documentation of this file.
1 
5 #ifndef RENDERER_H
6 #define RENDERER_H
7 
8 #include <SDL2/SDL.h>
9 #include "../voxtrees/tree.h"
10 #include "camera.h"
11 #include "lights.h"
12 
13 #ifdef VOXRND_SOURCE
14 typedef Uint32 square[16] __attribute__((aligned(16)));
15 
16 #define VOX_TEXTURE_SIZE (32*32*32) /* VOX_TEXTURE_SIDE ^ 3 */
17 #define VOX_TEXTURE_SIDE 32 /* Power of 2 */
18 
19 enum vox_context_type
20 {
21  VOX_CTX_WO_WINDOW,
22  VOX_CTX_W_WINDOW
23 };
24 
25 struct vox_rnd_ctx
26 {
27  SDL_Window *window;
28  SDL_Surface *surface;
29  struct vox_node *scene;
30  struct vox_camera *camera;
31 
32  struct vox_light_manager *light_manager;
33  Uint8 *texture;
34  square *square_output;
35  unsigned int squares_num, ws;
36 
37  unsigned int hs, quality;
38 };
39 #else
40 
45 {
46  SDL_Window *window;
49  SDL_Surface *surface;
52  struct vox_node *scene;
59  struct vox_camera *camera;
66  struct vox_light_manager *light_manager;
72 };
73 #endif
74 
81 #define VOX_QUALITY_BEST 0b00
82 
91 #define VOX_QUALITY_FAST 0b01
92 
100 #define VOX_QUALITY_ADAPTIVE 0b10
101 
109 #define VOX_QUALITY_RAY_MERGE 0b0100
110 
117 #define VOX_QUALITY_RAY_MERGE_ACCURATE 0b1000
118 
122 #define VOX_QUALITY_RM_MASK 0b1100 /* RM stands for Ray Merge */
123 
127 #define VOX_QUALITY_MODE_MASK 0b11
128 
129 #ifdef VOXRND_SOURCE
130 #define VOX_QUALITY_RM_MAX 0b1000
131 #define VOX_QUALITY_MODE_MAX 0b10
132 #endif
133 
145 VOX_EXPORT struct vox_rnd_ctx* vox_make_context_from_surface (SDL_Surface *surface);
146 
161 VOX_EXPORT struct vox_rnd_ctx* vox_make_context_and_window (unsigned int width, unsigned int height);
162 
169 VOX_EXPORT void vox_redraw (struct vox_rnd_ctx *ctx);
170 
174 VOX_EXPORT void vox_context_set_scene (struct vox_rnd_ctx *ctx, struct vox_node *scene);
175 
179 VOX_EXPORT void vox_context_set_camera (struct vox_rnd_ctx *ctx, struct vox_camera *camera);
180 
184 VOX_EXPORT void vox_context_set_light_manager (struct vox_rnd_ctx *ctx,
185  struct vox_light_manager *light_manager);
186 
196 VOX_EXPORT int vox_context_set_quality (struct vox_rnd_ctx *ctx, unsigned int quality);
197 
201 VOX_EXPORT void vox_destroy_context (struct vox_rnd_ctx *ctx);
202 
208 VOX_EXPORT void vox_render (struct vox_rnd_ctx *ctx);
209 
210 #endif
Camera interface.
Light manager.
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.
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_scene(struct vox_rnd_ctx *ctx, struct vox_node *scene)
Scene setter for renderer context.
VOX_EXPORT void vox_destroy_context(struct vox_rnd_ctx *ctx)
Free context after use.
VOX_EXPORT void vox_redraw(struct vox_rnd_ctx *ctx)
Redraw a window associated with this context.
VOX_EXPORT struct vox_rnd_ctx * vox_make_context_from_surface(SDL_Surface *surface)
Make a renderer context from SDL surface.
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.
VOX_EXPORT void vox_render(struct vox_rnd_ctx *ctx)
Render a scene on SDL surface.
A generic camera class.
Definition: camera.h:135
Voxel tree/node data structure.
A renderer context.
Definition: renderer.h:45
struct vox_light_manager * light_manager
A light manager associated with the context.
Definition: renderer.h:66
SDL_Surface * surface
A surface the context will draw to.
Definition: renderer.h:49
SDL_Window * window
A window associated with the context, if any.
Definition: renderer.h:46
struct vox_node * scene
A scene associated with the context.
Definition: renderer.h:52
struct vox_camera * camera
A camera associated with the context.
Definition: renderer.h:59