gspSprite2D.3p
8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
.TH gspSprite2D 3P local "Silicon Graphics, Inc."
.SH NAME
.upperok
gspSprite2D, gspSprite2D.dram, gspSprite2D.fifo
\- high-quality 2D sprite geometry RSP microcode.
.SH DESCRIPTION
This is the optimized, full-featured 2D sprite geometry RSP microcode.
It supports automatic subdivision and loading of arbitrarily sized
dram resident images of all supported texture format sizes and types
into
.IR gSPTextureRectangle (3P)
commands sent directly to the
RDP. Additionally, images can be optionally scaled up or mirrored in
the X or Y directions.
.SH USAGE
The sprite microcode is accessed through a combination of 4 new commands.
The first command,
.IR guSprite2DInit (3P)
is used to initialize a sprite structure with user specified values which
are then passed to the
.IR gSPSprite2DBase (3P)
command for actual processing of the sprite structure by the microcode. The
.IR guSprite2DInit (3P)
command is merely
a convenience function and can be avoided by having the application
initialize the sprite structure directly.
.IR gSPSprite2DBase (3P)
is used to initialize the base or common sprite parameters. No actual
drawing occurs.
.IR gSPSprite2DScaleFlip (3P)
is used to specify X/Y scaling or flipping parameters for a sprite. No
actual drawing occurs.
.IR gSPSprite2DDraw (3P)
specifies the screen coordinates for where the
sprite should be drawn, and triggers the actual rendering of the sprite
using parameters previously specified with
.IR gSPSprite2DBase (3P)
and
.IR gSPSprite2DScaleFlip (3P)
A sample code fragment for specifying a sprite would be:
.nf
\f3#include "gu.h"
\f3#include "gbi.h"
uSprite MySprite;
guSprite2DInit(&MySprite, ImagePointer, TlutPointer,
ImageWidth, RectangleWidth, RectangleHeight,
ImageType, ImageSize,
TextureStartS, TextureStartT);
gSPSprite2DBase(glistp++, OS_K0_TO_PHYSICAL(&MySprite));
gSPSprite2DScaleFlip(glistp++, ScaleX, ScaleY,
FlipTextureX, FlipTextureY);
gSPSprite2DDraw(glistp++, PScreenX, PScreenY);
\fP
.fi
\f1
These parameters are explained below.
.SH C SPECIFICATION
.nf
\f3
typedef struct {
void *SourceImagePointer;
void *TlutPointer;
short Stride;
short SubImageWidth;
short SubImageHeight;
char SourceImageType;
char SourceImageBitSize;
short SourceImageOffsetS;
short SourceImageOffsetT;
/* 20 bytes for above */
/* padding to bring structure size to 64 bit allignment */
char dummy[4];
} uSprite_t;
typedef union {
uSprite_t s;
/* Need to make sure this is 64 bit aligned */
long long int force_structure_allignment[3];
} uSprite;
void guSprite2DInit(uSprite *SpritePointer,
void *SourceImagePointer,
void *TlutPointer,
int Stride,
int SubImageWidth,
int SubImageHeight,
int SourceImageType,
int SourceImageBitSize,
int SourceImageOffsetS,
int SourceImageOffsetT);
\f1
\fP
.fi
.SH PARAMETERS
.I SpritePointer
The address of the sprite structure into which the parameters will
be written.
.I SourceImagePointer
The address of the base of the texture image in memory out of which
a subrectangle is to be displayed.
.I TlutPointer
The address of an optional color index table for used with CI images.
Use Null for non-CI images.
.I Stride
The width in texels of the original base image in memory.
.I SubImageWidth
The width in texels of the subimage which is to be displayed.
.I SubImageHeight
The height in texels of the subimage which is to be displayed.
.I SourceImageType
The format of the texture image in memory. All supported hardware texture formats
are allowed, such as
\f3 G_IM_FMT_RGBA \f1 or \f3 G_IM_FMT_CI\f1.
.I SourceImageBitSize
The number of bits per texel of the input image. All supported hardware texture
sizes are allowed, such as
\f3 G_IM_SIZ_32b \f1 or \f3 G_IM_SIZ_4b\f1.
.I ScaleX
The s5.10 fixed point X axis
.I texture to pixel
scaling ratio
which is to be applied to the input
image. A value of 1024 specifies 1 to 1 scaling. A value of 512 specifies that
each input texel should be scaled up to 2 output screen pixels. Scale values
should be <= 1024 in order to prevent sampling artifacts from occuring. Scale
values must be positive, use the
.I FlipTextureX
parameter to create negatively scaled images.
.I ScaleY
The s5.10 fixed point Y axis
.I texture to pixel
scaling ratio
which is to be applied to the input
image. A value of 1024 specifies 1 to 1 scaling. A value of 512 specifies that
each input row should be scaled up to 2 output screen rows. Scale values
should be <= 1024 in order to prevent sampling artifacts from occuring. Scale
values must be positive, use the
.I FlipTextureY
parameter to create negatively scaled images.
.I FlipTextureX
Specifies whether the image should be mirrored in the X direction before display
.I FlipTextureY
Specifies whether the image should be mirrored in the Y direction before display
.I SourceImageOffsetS
The offset in texel columns from the origin of the input base
image where the texture subrectangle which is to be displayed starts.
.I SourceImageOffsetT
The offset in texel rows from the origin of the input base
image where the texture subrectangle which is to be displayed starts.
.I PScreenX
Specifies the starting X location in screen coordinates of the output image.
The origin is in the upper left corner of the screen.
.I PScreenY
Specifies the starting Y location in screen coordinates of the output image.
The origin is in the upper left corner of the screen.
.SH GBI
The following GBI commands are
.I not
supported with this microcode:
.IR gSPLine3D (3P)
.IR gSP1Triangle (3P)
.SH NOTE
The sprite microcode has no direct support for ZBuffering. This is unecessary as
ZBuffering can be accomplished outside of the sprite microcode by setting up the
proper rendering mode and making use of the hardware primitive depth register.
A code fragment for doing ZBuffered sprites is:
.nf
\f3
gDPSetRenderMode(glistp++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
gDPSetDepthSource(glistp++, G_ZS_PRIM);
gDPSetCombineMode(glistp++, G_CC_DECALRGB, G_CC_DECALRGB);
gDPSetPrimDepth(glistp++, ZBufferValue, 0);
guSprite2DInit(&MySprite, ImagePointer, TlutPointer,
ImageWidth, RectangleWidth, RectangleHeight,
ImageType, ImageSize,
TextureStartS, TextureStartT);
gSPSprite2DBase(glistp++, OS_K0_TO_PHYSICAL(&MySprite));
gSPSprite2DScaleFlip(glistp++, ScaleX, ScaleY,
FlipTextureX, FlipTextureY);
gSPSprite2DDraw(glistp++, PScreenX, PScreenY);
\fP
.fi
\f1
.SH WARNINGS, LIMITATIONS, BUGS, WORKAROUNDS
Images which have been non-unit scaled and flipped in the Y axis will
not translate vertically by sub-pixel amounts smoothly, they will
exhibit a certain amount of jumping. The solution is to translate
non-unit scaled Y
flipped images by unit amounts in the vertical direction.
The Sprite Microcode was designed to handle images which have been
optionally scaled up. Images can also be scaled down with some attendant
artifacts. Beware that the
.I ScaleX
and
.I ScaleY
parameters are s5.10, however they are restricted to being positive,
thus the largest usuable scale value is 32767, which corresponds to
a texel to pixel ratio of 31.999.
Texture images which are either scaled in the Y axis or placed on a
subpixel scanline boundary require filtering by the hardware texture
filter unit. This filtering requires that at least 1 extra row of the
input image be loaded into the texture memory so that the filtering
can occur. Since the texture memory is limited to 4KB, this means that
the following restrictions are in effect:
32 bit subrectangles which are scaled in the Y direction
are clamped by the microcode to being a maximum of 512 texels wide.
additionally,
32 bit subrectangles which are placed starting on a subpixel
boundary in the Y direction and are larger than 512 texels in width
are clamped by the microcode to being on an integral scan line
boundary.
Note that this filtering requirement also means that when displaying a
Y scaled image, you will need to offset your starting T value by 1 to
prevent artifacts resulting from filtering with out of bound texels.
Y flipped Images which have been scaled vertically by non power of 2
amounts will be slightly different heights than their non-flipped
versions. If doing an animation involving scaled flipped and
non-flipped textures, restrict the Y scale value to being a power of 2.
.SH SEE ALSO
.IR gspLine3D (3P),
.IR gspTurbo3D (3P)
.IR gspFast3D (3P)
.IR osSpTaskStart (3P)
.IR gSPSprite2DBase (3P)
.IR gSPSprite2DScaleFlip (3P)
.IR gSPSprite2DDraw (3P)