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 <kos/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 vertical scale factor.
119 \ingroup pvr_global
120
121 This function sets the vertical scale factor used when the PVR scene is
122 rendered to the framebuffer. Generally you want 1.0f or near-1.0f values
123 here. The default used by the PVR driver is 1.0f when using VGA, and 0.999f
124 otherwise. Having a value slightly below 1.0f gives the image a pleasant
125 smoothing.
126
127 \retval 0 On success
128 \retval -1 On invalid factor value
129*/
130int pvr_set_vertical_scale(float factor);
131
132/** \brief Set the translucent polygon sort mode for the next frame.
133 \ingroup pvr_scene_mgmt
134
135 This function sets the translucent polygon sort mode for the next frame of
136 output, potentially switching between autosort and presort mode.
137
138 For most programs, you'll probably want to set this at initialization time
139 (with the autosort_disabled field in the pvr_init_params_t structure) and
140 not mess with it per-frame. It is recommended that if you do use this
141 function to change the mode that you should set it each frame to ensure that
142 the mode is set properly.
143
144 \param presort Set to true to set the presort mode for translucent
145 polygons, set to false to use autosort mode.
146*/
147void pvr_set_presort_mode(bool presort);
148
149/** \brief Retrieve the current VBlank count.
150 \ingroup pvr_stats
151
152 This function retrieves the number of VBlank interrupts that have occurred
153 since the PVR was initialized.
154
155 \return The number of VBlanks since init
156*/
158
159/** \defgroup pvr_stats Profiling
160 \brief Rendering stats and metrics for profiling
161 \ingroup pvr
162*/
163
164/** \brief PVR statistics structure.
165 \ingroup pvr_stats
166
167 This structure is used to hold various statistics about the operation of the
168 PVR since initialization.
169*/
170typedef struct pvr_stats {
171 uint64_t frame_last_time; /**< \brief Ready-to-Ready length for the last frame in nanoseconds */
172 uint64_t reg_last_time; /**< \brief Registration time for the last frame in nanoseconds */
173 uint64_t rnd_last_time; /**< \brief Rendering time for the last frame in nanoseconds */
174 uint64_t buf_last_time; /**< \brief DMA buffer file time for the last frame in nanoseconds */
175 size_t frame_count; /**< \brief Total number of rendered/viewed frames */
176 size_t vbl_count; /**< \brief VBlank count */
177 size_t vtx_buffer_used; /**< \brief Number of bytes used in the vertex buffer for the last frame */
178 size_t vtx_buffer_used_max; /**< \brief Number of bytes used in the vertex buffer for the largest frame */
179 float frame_rate; /**< \brief Current frame rate (per second) */
180 uint32_t enabled_list_mask; /**< \brief Which lists are enabled? */
181 /* ... more later as it's implemented ... */
183
184/** \brief Get the current statistics from the PVR.
185 \ingroup pvr_stats
186
187 This function fills in the pvr_stats_t structure passed in with the current
188 statistics of the system.
189
190 \param stat The statistics structure to fill in. Must not be
191 NULL
192 \retval 0 On success
193 \retval -1 If the PVR is not initialized
194*/
196
197__END_DECLS
198
199#endif /* __DC_PVR_PVR_MISC_H */
Various common macros used throughout the codebase.
static uint32_t("Please see purupuru_effect_t for modern equivalent.") PURUPURU_EFFECT2_UINTENSITY(uint8_t x)
Definition purupuru.h:96
void pvr_set_zclip(float zc)
Set Z clipping depth.
void pvr_set_shadow_scale(bool enable, float scale_value)
Set cheap shadow parameters.
int pvr_set_vertical_scale(float factor)
Set the vertical scale factor.
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:170
size_t vtx_buffer_used
Number of bytes used in the vertex buffer for the last frame.
Definition pvr_misc.h:177
size_t vtx_buffer_used_max
Number of bytes used in the vertex buffer for the largest frame.
Definition pvr_misc.h:178
uint64_t buf_last_time
DMA buffer file time for the last frame in nanoseconds.
Definition pvr_misc.h:174
size_t frame_count
Total number of rendered/viewed frames.
Definition pvr_misc.h:175
uint64_t frame_last_time
Ready-to-Ready length for the last frame in nanoseconds.
Definition pvr_misc.h:171
float frame_rate
Current frame rate (per second)
Definition pvr_misc.h:179
uint32_t enabled_list_mask
Which lists are enabled?
Definition pvr_misc.h:180
size_t vbl_count
VBlank count.
Definition pvr_misc.h:176
uint64_t reg_last_time
Registration time for the last frame in nanoseconds.
Definition pvr_misc.h:172
uint64_t rnd_last_time
Rendering time for the last frame in nanoseconds.
Definition pvr_misc.h:173