Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
software_renderer.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
35
36#ifndef __JO_SOFTWARE_RENDERER_H__
37# define __JO_SOFTWARE_RENDERER_H__
38
39/*
40 ██████╗ ██████╗ ██████╗ ███████╗
41██╔════╝██╔═══██╗██╔══██╗██╔════╝
42██║ ██║ ██║██████╔╝█████╗
43██║ ██║ ██║██╔══██╗██╔══╝
44╚██████╗╚██████╔╝██║ ██║███████╗
45 ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
46*/
47
48/*
49 Jo Engine Software Rendering XYZ axes
50
51 Z-
52 /
53 /
54 0------> X+ (width)
55 /|
56 / |
57 Z+ V
58 Y+ (height)
59*/
60
72
80
92
94typedef struct
95{
101 unsigned int color_buffer_size;
102 void *vram;
107 jo_color *__texture_cache[4]; // (internal) the textures of the frame copied in RAM
108 unsigned int __texture_cache_size[4];// (internal) their blocks (texels)
109 short __texture_cache_id[4]; // (internal) their sprites (-1: none)
110 int __texture_cache_next; // (internal) the next entry replaced
112
120
128jo_software_renderer_gfx *jo_software_renderer_create_ex(unsigned short width, unsigned short height, const jo_scroll_screen screen, const bool enable_zbuffer);
129
136static __jo_force_inline jo_software_renderer_gfx *jo_software_renderer_create(unsigned short width, unsigned short height, const jo_scroll_screen screen)
137{
138 return (jo_software_renderer_create_ex(width, height, screen, true));
139}
140
146
151
152/*
153██████╗ █████╗ ███████╗██╗ ██████╗ ██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
154██╔══██╗██╔══██╗██╔════╝██║██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
155██████╔╝███████║███████╗██║██║ ██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
156██╔══██╗██╔══██║╚════██║██║██║ ██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
157██████╔╝██║ ██║███████║██║╚██████╗ ██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
158╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
159*/
160
166
173void jo_software_renderer_draw_pixel2D(const jo_software_renderer_gfx * const gfx, const jo_fixed x, const jo_fixed y, const jo_color color);
174
182void jo_software_renderer_draw_pixel3D(const jo_software_renderer_gfx * const gfx, const jo_fixed x, const jo_fixed y, const jo_fixed z, const jo_color color);
183
196 jo_fixed x0, jo_fixed y0, jo_fixed z0,
197 jo_fixed x1, jo_fixed y1, jo_fixed z1,
198 const jo_color color0, const jo_color color1);
199
200/*
201████████╗██████╗ ██╗ █████╗ ███╗ ██╗ ██████╗ ██╗ ███████╗
202╚══██╔══╝██╔══██╗██║██╔══██╗████╗ ██║██╔════╝ ██║ ██╔════╝
203 ██║ ██████╔╝██║███████║██╔██╗ ██║██║ ███╗██║ █████╗
204 ██║ ██╔══██╗██║██╔══██║██║╚██╗██║██║ ██║██║ ██╔══╝
205 ██║ ██║ ██║██║██║ ██║██║ ╚████║╚██████╔╝███████╗███████╗
206 ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚══════╝
207*/
208
217
219 const jo_software_renderer_triangle * const triangle,
220 const jo_matrix * const transform_matrix);
221
227{
229 triangle->v0.pos.x, triangle->v0.pos.y, triangle->v0.pos.z,
230 triangle->v1.pos.x, triangle->v1.pos.y, triangle->v1.pos.z,
231 triangle->v0.color, triangle->v1.color);
233 triangle->v1.pos.x, triangle->v1.pos.y, triangle->v1.pos.z,
234 triangle->v2.pos.x, triangle->v2.pos.y, triangle->v2.pos.z,
235 triangle->v1.color, triangle->v2.color);
237 triangle->v2.pos.x, triangle->v2.pos.y, triangle->v2.pos.z,
238 triangle->v0.pos.x, triangle->v0.pos.y, triangle->v0.pos.z,
239 triangle->v2.color, triangle->v0.color);
240}
241
242#endif /* !__JO_SOFTWARE_RENDERER_H__ */
243
244/*
245** END OF FILE
246*/
int height
Definition entity.h:4
void jo_software_renderer_flush(jo_software_renderer_gfx *const gfx)
Copy the buffer into VDP1/2 VRAM.
void jo_software_renderer_draw_line3D(const jo_software_renderer_gfx *const gfx, jo_fixed x0, jo_fixed y0, jo_fixed z0, jo_fixed x1, jo_fixed y1, jo_fixed z1, const jo_color color0, const jo_color color1)
Draw a line.
jo_software_renderer_vertex v0
Definition software_renderer.h:212
void * vram
Definition software_renderer.h:102
jo_software_renderer_gfx * jo_software_renderer_create_ex(unsigned short width, unsigned short height, const jo_scroll_screen screen, const bool enable_zbuffer)
Create a full-color rendering surface.
jo_size vram_size
Definition software_renderer.h:103
jo_software_renderer_draw_mode draw_mode
Definition software_renderer.h:105
static __jo_force_inline void jo_software_renderer_draw_triangle_wireframe(const jo_software_renderer_gfx *const gfx, const jo_software_renderer_triangle *const triangle)
Draw a triangle in wireframe.
Definition software_renderer.h:226
jo_vector2_fixed uv_texture_mapping
Definition software_renderer.h:117
jo_size clipping_size
Definition software_renderer.h:96
int sprite_id
Definition software_renderer.h:215
jo_software_renderer_face_culling_mode face_culling_mode
Definition software_renderer.h:106
unsigned int __texture_cache_size[4]
Definition software_renderer.h:108
void jo_software_renderer_clear(const jo_software_renderer_gfx *const gfx, const jo_color color)
Clear the buffer with the given color.
void jo_software_renderer_draw_triangle(const jo_software_renderer_gfx *const gfx, const jo_software_renderer_triangle *const triangle, const jo_matrix *const transform_matrix)
int sprite_id
Definition software_renderer.h:97
jo_color * color_buffer
Definition software_renderer.h:100
int __texture_cache_next
Definition software_renderer.h:110
jo_color color
Definition software_renderer.h:118
jo_software_renderer_depth_mode
Z-BUFFER Computation mode.
Definition software_renderer.h:83
@ JO_SR_DEPTH_EQUAL
Definition software_renderer.h:90
@ JO_SR_DEPTH_NOT_EQUAL
Definition software_renderer.h:89
@ JO_SR_DEPTH_LESS_OR_EQUAL
Definition software_renderer.h:86
@ JO_SR_DEPTH_IGNORE
Definition software_renderer.h:84
@ JO_SR_DEPTH_LESS
Definition software_renderer.h:85
@ JO_SR_DEPTH_GREATER
Definition software_renderer.h:88
@ JO_SR_DEPTH_GREATER_OR_EQUAL
Definition software_renderer.h:87
jo_software_renderer_vertex v2
Definition software_renderer.h:214
unsigned int depth_buffer_dword_size
Definition software_renderer.h:99
jo_color * __texture_cache[4]
Definition software_renderer.h:107
jo_vector4_fixed pos
Definition software_renderer.h:116
void jo_software_renderer_draw_pixel3D(const jo_software_renderer_gfx *const gfx, const jo_fixed x, const jo_fixed y, const jo_fixed z, const jo_color color)
Draw a pixel.
jo_software_renderer_depth_mode depth_mode_testing
Definition software_renderer.h:104
short __texture_cache_id[4]
Definition software_renderer.h:109
jo_software_renderer_draw_mode
Draw mode.
Definition software_renderer.h:63
@ JO_SR_DRAW_TEXTURED
Definition software_renderer.h:67
@ JO_SR_DRAW_WIREFRAME
Definition software_renderer.h:70
@ JO_SR_DRAW_FLAT
Definition software_renderer.h:69
unsigned int color_buffer_size
Definition software_renderer.h:101
void jo_software_renderer_draw_pixel2D(const jo_software_renderer_gfx *const gfx, const jo_fixed x, const jo_fixed y, const jo_color color)
Draw a pixel without handling the Z-Buffer.
void jo_software_renderer_free(jo_software_renderer_gfx *const gfx)
Free the rendering surface.
jo_fixed * depth_buffer
Definition software_renderer.h:98
jo_software_renderer_vertex v1
Definition software_renderer.h:213
static __jo_force_inline jo_software_renderer_gfx * jo_software_renderer_create(unsigned short width, unsigned short height, const jo_scroll_screen screen)
Create a full-color rendering surface.
Definition software_renderer.h:136
jo_software_renderer_face_culling_mode
Face culling mode.
Definition software_renderer.h:75
@ JO_SR_FRONT_FACE_CULLING
Definition software_renderer.h:77
@ JO_SR_NO_FACE_CULLING
Definition software_renderer.h:78
@ JO_SR_BACK_FACE_CULLING
Definition software_renderer.h:76
This is the main struct that handle everything for drawing.
Definition software_renderer.h:95
Triangle definition.
Definition software_renderer.h:211
Vertex.
Definition software_renderer.h:115
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
unsigned short jo_color
15 bits color type
Definition types.h:53
int jo_fixed
Fixed point Q16.16 number.
Definition types.h:59
struct __jo_size jo_size
Size struct.
jo_scroll_screen
Sega Saturn Scroll Screen Ids.
Definition types.h:340
Vector for 2D computation using fixed number.
Definition types.h:172
Vector4 for 3D computation using fixed number.
Definition types.h:181
4x4 MATRIX for 3D computation using fixed number
Definition types.h:202