KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pvr_misc.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/pvr/pvr_misc.h
4 Copyright (C) 2002 Megan Potter
5 Copyright (C) 2014 Lawrence Sebald
6 Copyright (C) 2023 Ruslan Rostovtsev
7 Copyright (C) 2024 Falco Girgis
8*/
9
10/** \file dc/pvr/pvr_misc.h
11 \brief Miscellaneous utilities for the PVR API
12 \ingroup pvr
13
14 \author Megan Potter
15 \author Roger Cattermole
16 \author Paul Boese
17 \author Brian Paul
18 \author Lawrence Sebald
19 \author Benoit Miller
20 \author Ruslan Rostovtsev
21 \author Falco Girgis
22*/
23
24#ifndef __DC_PVR_PVR_MISC_H
25#define __DC_PVR_PVR_MISC_H
26
27#include <stdint.h>
28
29#include <sys/cdefs.h>
30__BEGIN_DECLS
31
32
33/** \brief Pack four floating point color values into a 32-bit integer form.
34
35 All of the color values should be between 0 and 1.
36
37 \param a Alpha value
38 \param r Red value
39 \param g Green value
40 \param b Blue value
41 \return The packed color value
42*/
43#define PVR_PACK_COLOR(a, r, g, b) ( \
44 ( ((uint8_t)( (a) * 255 ) ) << 24 ) | \
45 ( ((uint8_t)( (r) * 255 ) ) << 16 ) | \
46 ( ((uint8_t)( (g) * 255 ) ) << 8 ) | \
47 ( ((uint8_t)( (b) * 255 ) ) << 0 ) )
48
49/** \brief Pack two floating point coordinates into one 32-bit value,
50 truncating them to 16-bits each.
51
52 \param u First coordinate to pack
53 \param v Second coordinate to pack
54 \return The packed coordinates
55*/
56static inline uint32_t PVR_PACK_16BIT_UV(float u, float v) {
57 union {
58 float f;
59 uint32_t i;
60 } u2, v2;
61
62 u2.f = u;
63 v2.f = v;
64
65 return (u2.i & 0xFFFF0000) | (v2.i >> 16);
66}
67
68
69/** \defgroup pvr_global Global State
70 \brief PowerVR functionality which is managed globally
71 \ingroup pvr
72
73 These are miscellaneous parameters you can set which affect the
74 rendering process.
75*/
76
77/** \brief Set the background plane color.
78 \ingroup pvr_global
79
80 This function sets the color of the area of the screen not covered by any
81 other polygons.
82
83 \param r Red component of the color to set
84 \param g Green component of the color to set
85 \param b Blue component of the color to set
86*/
87void pvr_set_bg_color(float r, float g, float b);
88
89/** \brief Set cheap shadow parameters.
90 \ingroup pvr_global
91
92 This function sets up the PVR cheap shadow parameters for use. You can only
93 specify one scale value per frame, so the effect that you can get from this
94 is somewhat limited, but if you want simple shadows, this is the easiest way
95 to do it.
96
97 Polygons affected by a shadow modifier volume will effectively multiply
98 their final color by the scale value set here when shadows are enabled and
99 the polygon is inside the modifier (or outside for exclusion volumes).
100
101 \param enable Set to true to enable cheap shadow mode.
102 \param scale_value Floating point value (between 0 and 1) representing
103 how colors of polygons affected by and inside the
104 volume will be modified by the shadow volume.
105*/
106void pvr_set_shadow_scale(bool enable, float scale_value);
107
108/** \brief Set Z clipping depth.
109 \ingroup pvr_global
110
111 This function sets the Z clipping depth. The default value for this is
112 0.0001.
113
114 \param zc The new value to set the z clip parameter to.
115*/
116void pvr_set_zclip(float zc);
117
118/** \brief Set the translucent polygon sort mode for the next frame.
119 \ingroup pvr_scene_mgmt
120
121 This function sets the translucent polygon sort mode for the next frame of
122 output, potentially switching between autosort and presort mode.
123
124 For most programs, you'll probably want to set this at initialization time
125 (with the autosort_disabled field in the pvr_init_params_t structure) and
126 not mess with it per-frame. It is recommended that if you do use this
127 function to change the mode that you should set it each frame to ensure that
128 the mode is set properly.
129
130 \param presort Set to true to set the presort mode for translucent
131 polygons, set to false to use autosort mode.
132*/
133void pvr_set_presort_mode(bool presort);
134
135/** \brief Retrieve the current VBlank count.
136 \ingroup pvr_stats
137
138 This function retrieves the number of VBlank interrupts that have occurred
139 since the PVR was initialized.
140
141 \return The number of VBlanks since init
142*/
144
145/** \defgroup pvr_stats Profiling
146 \brief Rendering stats and metrics for profiling
147 \ingroup pvr
148*/
149
150/** \brief PVR statistics structure.
151 \ingroup pvr_stats
152
153 This structure is used to hold various statistics about the operation of the
154 PVR since initialization.
155*/
156typedef struct pvr_stats {
157 uint64_t frame_last_time; /**< \brief Ready-to-Ready length for the last frame in nanoseconds */
158 uint64_t reg_last_time; /**< \brief Registration time for the last frame in nanoseconds */
159 uint64_t rnd_last_time; /**< \brief Rendering time for the last frame in nanoseconds */
160 uint64_t buf_last_time; /**< \brief DMA buffer file time for the last frame in nanoseconds */
161 size_t frame_count; /**< \brief Total number of rendered/viewed frames */
162 size_t vbl_count; /**< \brief VBlank count */
163 size_t vtx_buffer_used; /**< \brief Number of bytes used in the vertex buffer for the last frame */
164 size_t vtx_buffer_used_max; /**< \brief Number of bytes used in the vertex buffer for the largest frame */
165 float frame_rate; /**< \brief Current frame rate (per second) */
166 uint32_t enabled_list_mask; /**< \brief Which lists are enabled? */
167 /* ... more later as it's implemented ... */
169
170/** \brief Get the current statistics from the PVR.
171 \ingroup pvr_stats
172
173 This function fills in the pvr_stats_t structure passed in with the current
174 statistics of the system.
175
176 \param stat The statistics structure to fill in. Must not be
177 NULL
178 \retval 0 On success
179 \retval -1 If the PVR is not initialized
180*/
182
183__END_DECLS
184
185#endif /* __DC_PVR_PVR_MISC_H */
void pvr_set_zclip(float zc)
Set Z clipping depth.
void pvr_set_shadow_scale(bool enable, float scale_value)
Set cheap shadow parameters.
void pvr_set_bg_color(float r, float g, float b)
Set the background plane color.
void pvr_set_presort_mode(bool presort)
Set the translucent polygon sort mode for the next frame.
int pvr_get_vbl_count(void)
Retrieve the current VBlank count.
int pvr_get_stats(pvr_stats_t *stat)
Get the current statistics from the PVR.
static uint32_t PVR_PACK_16BIT_UV(float u, float v)
Pack two floating point coordinates into one 32-bit value, truncating them to 16-bits each.
Definition pvr_misc.h:56
PVR statistics structure.
Definition pvr_misc.h:156
size_t vtx_buffer_used
Number of bytes used in the vertex buffer for the last frame.
Definition pvr_misc.h:163
size_t vtx_buffer_used_max
Number of bytes used in the vertex buffer for the largest frame.
Definition pvr_misc.h:164
uint64_t buf_last_time
DMA buffer file time for the last frame in nanoseconds.
Definition pvr_misc.h:160
size_t frame_count
Total number of rendered/viewed frames.
Definition pvr_misc.h:161
uint64_t frame_last_time
Ready-to-Ready length for the last frame in nanoseconds.
Definition pvr_misc.h:157
float frame_rate
Current frame rate (per second)
Definition pvr_misc.h:165
uint32_t enabled_list_mask
Which lists are enabled?
Definition pvr_misc.h:166
size_t vbl_count
VBlank count.
Definition pvr_misc.h:162
uint64_t reg_last_time
Registration time for the last frame in nanoseconds.
Definition pvr_misc.h:158
uint64_t rnd_last_time
Rendering time for the last frame in nanoseconds.
Definition pvr_misc.h:159