KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pvr_txr.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/pvr/pvr_txr.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 Copyright (C) 2024 Andress Barajas
9*/
10
11/** \file dc/pvr/pvr_txr.h
12 \brief Texture management with the PVR 3D API
13 \ingroup pvr_txr_mgmt
14
15 \author Megan Potter
16 \author Roger Cattermole
17 \author Paul Boese
18 \author Brian Paul
19 \author Lawrence Sebald
20 \author Benoit Miller
21 \author Ruslan Rostovtsev
22 \author Falco Girgis
23*/
24
25#ifndef __DC_PVR_PVR_TEXTURE_H
26#define __DC_PVR_PVR_TEXTURE_H
27
28#include <stdbool.h>
29#include <stdint.h>
30
31#include <kos/cdefs.h>
32__BEGIN_DECLS
33
34#include <kos/img.h>
35
36/** \defgroup pvr_txr_mgmt Texturing
37 \brief API for managing PowerVR textures
38 \ingroup pvr
39
40 Helper functions for handling texture tasks of various kinds.
41*/
42
43/** \brief Set the global stride width for non-power-of-two textures in PVR RAM.
44 \ingroup pvr_txr_mgmt
45
46 This function configures the register `PVR_TEXTURE_MODULO`, whose
47 first five bits define the row width in VRAM for non-power-of-two
48 textures. The setting applies to all textures rendered with the
49 `PVR_TXRFMT_X32_STRIDE` flag in the same frame.
50
51 The stride width configured here is **only supported for textures
52 with widths that are multiples of 32 pixels** and up to a maximum
53 of 992 pixels.
54
55 \warning
56 - Textures that are twiddled cannot use the `PVR_TXRFMT_X32_STRIDE`
57 flag so the stride set here will not apply to them. This includes
58 all paletted and mipmap textures.
59
60 \param texture_width The width of the texture in pixels. Must be a
61 multiple of 32 and up to 992 pixels.
62
63 \sa pvr_txr_get_stride()
64*/
65void pvr_txr_set_stride(size_t texture_width);
66
67/** \brief Get the current texture stride width in pixels as set in the PVR.
68 \ingroup pvr_txr_mgmt
69
70 This function reads the `PVR_TEXTURE_MODULO` register and calculates the
71 texture stride width in pixels. The value returned is the width in pixels
72 that has been configured for all textures using the `PVR_TXRFMT_X32_STRIDE`
73 flag in the same frame.
74
75 The stride width is computed by taking the current multiplier in
76 `PVR_TEXTURE_MODULO` (which stores the width divided by 32), and
77 multiplying it back by 32 to return the full width in pixels.
78
79 \return The current texture stride width in pixels.
80 Or 0 if not set
81 \sa pvr_txr_set_stride()
82*/
83size_t pvr_txr_get_stride(void);
84
85/** \brief Load raw texture data from an SH-4 buffer into PVR RAM.
86 \ingroup pvr_txr_mgmt
87
88 This essentially just acts as a memcpy() from main RAM to PVR RAM, using
89 the Store Queues and 64-bit TA bus.
90
91 \param src The location in main RAM holding the texture.
92 \param dst The location in PVR RAM to copy to.
93 \param count The size of the texture in bytes (must be a multiple
94 of 32).
95*/
96void pvr_txr_load(const void *src, pvr_ptr_t dst, size_t count);
97
98/** \defgroup pvr_txrload_constants Flags
99 \brief Texture loading constants
100 \ingroup pvr_txr_mgmt
101
102 These are constants for the flags parameter to pvr_txr_load_ex() or
103 pvr_txr_load_kimg().
104
105 @{
106*/
107#define PVR_TXRLOAD_4BPP 0x01 /**< \brief 4BPP format */
108#define PVR_TXRLOAD_8BPP 0x02 /**< \brief 8BPP format */
109#define PVR_TXRLOAD_16BPP 0x03 /**< \brief 16BPP format */
110#define PVR_TXRLOAD_FMT_MASK 0x0f /**< \brief Bits used for basic formats */
111
112#define PVR_TXRLOAD_VQ_LOAD 0x10 /**< \brief Do VQ encoding (not supported yet, if ever) */
113#define PVR_TXRLOAD_INVERT_Y 0x20 /**< \brief Invert the Y axis while loading */
114#define PVR_TXRLOAD_FMT_VQ 0x40 /**< \brief Texture is already VQ encoded */
115#define PVR_TXRLOAD_FMT_TWIDDLED 0x80 /**< \brief Texture is already twiddled */
116#define PVR_TXRLOAD_FMT_NOTWIDDLE 0x80 /**< \brief Don't twiddle the texture while loading */
117#define PVR_TXRLOAD_DMA 0x8000 /**< \brief Use DMA to load the texture */
118#define PVR_TXRLOAD_NONBLOCK 0x4000 /**< \brief Use non-blocking loads (only for DMA) */
119#define PVR_TXRLOAD_SQ 0x2000 /**< \brief Use Store Queues to load */
120/** @} */
121
122/** \brief Load texture data from an SH-4 buffer into PVR RAM, twiddling it in
123 the process.
124 \ingroup pvr_txr_mgmt
125
126 This function loads a texture to the PVR's RAM with the specified set of
127 flags. It will currently always twiddle the data, whether you ask it to or
128 not, and many of the parameters are just plain not supported at all...
129 Pretty much the only supported flag, other than the format ones is the
130 PVR_TXRLOAD_INVERT_Y one.
131
132 This will be slower than using pvr_txr_load() in pretty much all cases, so
133 unless you need to twiddle your texture, just use that instead.
134
135 \param src The location to copy from.
136 \param dst The location to copy to.
137 \param w The width of the texture, in pixels.
138 \param h The height of the texture, in pixels.
139 \param flags Some set of flags, ORed together.
140
141 \see pvr_txrload_constants
142*/
143void pvr_txr_load_ex(const void *src, pvr_ptr_t dst,
144 uint32_t w, uint32_t h, uint32_t flags);
145
146/** \brief Load a KOS Platform Independent Image (subject to constraint
147 checking).
148 \ingroup pvr_txr_mgmt
149
150 This function loads a KOS Platform Independent image to the PVR's RAM with
151 the specified set of flags. This function, unlike pvr_txr_load_ex() supports
152 everything in the flags available, other than what's explicitly marked as
153 not supported.
154
155 \param img The image to load.
156 \param dst The location to copy to.
157 \param flags Some set of flags, ORed together.
158
159 \see pvr_txrload_constants
160 \note Unless you explicitly tell this function to not
161 twiddle the texture (by ORing
162 \ref PVR_TXRLOAD_FMT_NOTWIDDLE or it's equivalent
163 \ref PVR_TXRLOAD_FMT_TWIDDLED with flags), this
164 function will twiddle the texture while loading.
165 Keep that in mind when setting the texture format in
166 polygon headers later.
167 \note You cannot specify both
168 \ref PVR_TXRLOAD_FMT_NOTWIDDLE (or equivalently
169 \ref PVR_TXRLOAD_FMT_TWIDDLED) and
170 \ref PVR_TXRLOAD_INVERT_Y in the flags.
171 \note DMA and Store Queue based loading is not available
172 from this function if it twiddles the texture while
173 loading.
174*/
175void pvr_txr_load_kimg(const kos_img_t *img, pvr_ptr_t dst, uint32_t flags);
176
177__END_DECLS
178#endif /* __DC_PVR_PVR_TEXTURE_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_txr_load_kimg(const kos_img_t *img, pvr_ptr_t dst, uint32_t flags)
Load a KOS Platform Independent Image (subject to constraint checking).
void pvr_txr_load_ex(const void *src, pvr_ptr_t dst, uint32_t w, uint32_t h, uint32_t flags)
Load texture data from an SH-4 buffer into PVR RAM, twiddling it in the process.
void pvr_txr_load(const void *src, pvr_ptr_t dst, size_t count)
Load raw texture data from an SH-4 buffer into PVR RAM.
size_t pvr_txr_get_stride(void)
Get the current texture stride width in pixels as set in the PVR.
void pvr_txr_set_stride(size_t texture_width)
Set the global stride width for non-power-of-two textures in PVR RAM.
void * pvr_ptr_t
PVR texture memory pointer.
Definition pvr_mem.h:45
Platform-independent image type.
Platform-indpendent image type.
Definition img.h:51