Jo Engine 2026.11.1
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#ifdef JO_COMPILE_WITH_SOFTWARE_RENDERER_SUPPORT
40
41/*
42 ██████╗ ██████╗ ██████╗ ███████╗
43██╔════╝██╔═══██╗██╔══██╗██╔════╝
44██║ ██║ ██║██████╔╝█████╗
45██║ ██║ ██║██╔══██╗██╔══╝
46╚██████╗╚██████╔╝██║ ██║███████╗
47 ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
48*/
49
50/*
51 Jo Engine Software Rendering XYZ axes
52
53 Z-
54 /
55 /
56 0------> X+ (width)
57 /|
58 / |
59 Z+ V
60 Y+ (height)
61*/
62
70
78
90
106
114
122jo_software_renderer_gfx *jo_software_renderer_create_ex(unsigned short width, unsigned short height, const jo_scroll_screen screen, const bool enable_zbuffer);
123
130static __jo_force_inline jo_software_renderer_gfx *jo_software_renderer_create(unsigned short width, unsigned short height, const jo_scroll_screen screen)
131{
132 return (jo_software_renderer_create_ex(width, height, screen, true));
133}
134
140
145
146/*
147██████╗ █████╗ ███████╗██╗ ██████╗ ██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
148██╔══██╗██╔══██╗██╔════╝██║██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
149██████╔╝███████║███████╗██║██║ ██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
150██╔══██╗██╔══██║╚════██║██║██║ ██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
151██████╔╝██║ ██║███████║██║╚██████╗ ██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
152╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
153*/
154
160
167void jo_software_renderer_draw_pixel2D(const jo_software_renderer_gfx * const gfx, const jo_fixed x, const jo_fixed y, const jo_color color);
168
176void 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);
177
190 jo_fixed x0, jo_fixed y0, jo_fixed z0,
191 jo_fixed x1, jo_fixed y1, jo_fixed z1,
192 const jo_color color0, const jo_color color1);
193
194/*
195████████╗██████╗ ██╗ █████╗ ███╗ ██╗ ██████╗ ██╗ ███████╗
196╚══██╔══╝██╔══██╗██║██╔══██╗████╗ ██║██╔════╝ ██║ ██╔════╝
197 ██║ ██████╔╝██║███████║██╔██╗ ██║██║ ███╗██║ █████╗
198 ██║ ██╔══██╗██║██╔══██║██║╚██╗██║██║ ██║██║ ██╔══╝
199 ██║ ██║ ██║██║██║ ██║██║ ╚████║╚██████╔╝███████╗███████╗
200 ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚══════╝
201*/
202
211
213 const jo_software_renderer_triangle * const triangle,
214 const jo_matrix * const transform_matrix);
215
221{
223 triangle->v0.pos.x, triangle->v0.pos.y, triangle->v0.pos.z,
224 triangle->v1.pos.x, triangle->v1.pos.y, triangle->v1.pos.z,
225 triangle->v0.color, triangle->v1.color);
227 triangle->v1.pos.x, triangle->v1.pos.y, triangle->v1.pos.z,
228 triangle->v2.pos.x, triangle->v2.pos.y, triangle->v2.pos.z,
229 triangle->v1.color, triangle->v2.color);
231 triangle->v2.pos.x, triangle->v2.pos.y, triangle->v2.pos.z,
232 triangle->v0.pos.x, triangle->v0.pos.y, triangle->v0.pos.z,
233 triangle->v2.color, triangle->v0.color);
234}
235
236#endif // JO_COMPILE_WITH_SOFTWARE_RENDERER_SUPPORT
237
238#endif /* !__JO_SOFTWARE_RENDERER_H__ */
239
240/*
241** END OF FILE
242*/
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:206
void * vram
Definition software_renderer.h:100
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:101
jo_software_renderer_draw_mode draw_mode
Definition software_renderer.h:103
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:220
jo_vector2_fixed uv_texture_mapping
Definition software_renderer.h:111
jo_size clipping_size
Definition software_renderer.h:94
int sprite_id
Definition software_renderer.h:209
jo_software_renderer_face_culling_mode face_culling_mode
Definition software_renderer.h:104
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:95
jo_color * color_buffer
Definition software_renderer.h:98
jo_color color
Definition software_renderer.h:112
jo_software_renderer_depth_mode
Z-BUFFER Computation mode.
Definition software_renderer.h:81
@ JO_SR_DEPTH_EQUAL
Definition software_renderer.h:88
@ JO_SR_DEPTH_NOT_EQUAL
Definition software_renderer.h:87
@ JO_SR_DEPTH_LESS_OR_EQUAL
Definition software_renderer.h:84
@ JO_SR_DEPTH_IGNORE
Definition software_renderer.h:82
@ JO_SR_DEPTH_LESS
Definition software_renderer.h:83
@ JO_SR_DEPTH_GREATER
Definition software_renderer.h:86
@ JO_SR_DEPTH_GREATER_OR_EQUAL
Definition software_renderer.h:85
jo_software_renderer_vertex v2
Definition software_renderer.h:208
unsigned int depth_buffer_dword_size
Definition software_renderer.h:97
jo_vector4_fixed pos
Definition software_renderer.h:110
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:102
jo_software_renderer_draw_mode
Draw mode.
Definition software_renderer.h:65
@ JO_SR_DRAW_TEXTURED
Definition software_renderer.h:66
@ JO_SR_DRAW_WIREFRAME
Definition software_renderer.h:68
@ JO_SR_DRAW_FLAT
Definition software_renderer.h:67
unsigned int color_buffer_size
Definition software_renderer.h:99
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:96
jo_software_renderer_vertex v1
Definition software_renderer.h:207
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:130
jo_software_renderer_face_culling_mode
Face culling mode.
Definition software_renderer.h:73
@ JO_SR_FRONT_FACE_CULLING
Definition software_renderer.h:75
@ JO_SR_NO_FACE_CULLING
Definition software_renderer.h:76
@ JO_SR_BACK_FACE_CULLING
Definition software_renderer.h:74
This is the main struct that handle everything for drawing.
Definition software_renderer.h:93
Triangle definition.
Definition software_renderer.h:205
Vertex.
Definition software_renderer.h:109
#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:42
int jo_fixed
Fixed point Q16.16 number.
Definition types.h:48
struct __jo_size jo_size
Size struct.
jo_scroll_screen
Sega Saturn Scroll Screen Ids.
Definition types.h:322
Vector for 2D computation using fixed number.
Definition types.h:161
Vector4 for 3D computation using fixed number.
Definition types.h:170
4x4 MATRIX for 3D computation using fixed number
Definition types.h:191