Skip to content

Commit 5e784b1

Browse files
authored
Merge pull request #85 from fjtrujy/sprite_list
Add a way to print a list of sprite
2 parents 843ab0a + 33c17ca commit 5e784b1

File tree

9 files changed

+260
-30
lines changed

9 files changed

+260
-30
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ add_object_library_macros(GS_PRIMITIVE_OBJS ee/gs/src/gsPrimitive.c
152152
gsKit_prim_line_strip
153153
gsKit_prim_line_strip_3d
154154
gsKit_prim_sprite
155+
gsKit_prim_list_sprite_gouraud_3d
156+
gsKit_prim_list_sprite_flat
157+
gsKit_prim_list_sprite_flat_color
155158
gsKit_prim_triangle_3d
156159
gsKit_prim_triangle_strip
157160
gsKit_prim_triangle_strip_3d
@@ -186,6 +189,8 @@ add_object_library_macros(GS_TEXTURE_OBJS ee/gs/src/gsTexture.c
186189
gsKit_prim_sprite_striped_texture_3d
187190
gsKit_prim_triangle_texture_3d
188191
gskit_prim_list_sprite_texture_uv_3d
192+
gskit_prim_list_sprite_texture_uv_flat
193+
gskit_prim_list_sprite_texture_uv_flat_color
189194
gsKit_prim_triangle_goraud_texture_3d
190195
gsKit_prim_list_triangle_goraud_texture_uv_3d
191196
gsKit_prim_list_triangle_goraud_texture_stq_3d

ee/gs/include/gsInit.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -970,58 +970,74 @@ typedef union {
970970
u16 y;
971971
u32 z;
972972
};
973-
} __attribute__((packed,aligned(8))) gs_xyz_t;
973+
} __attribute__((packed)) gs_xyz_t;
974974

975975
typedef union {
976-
u64 rgbaq;
976+
u32 rgba;
977977
struct {
978978
u8 r;
979979
u8 g;
980980
u8 b;
981981
u8 a;
982+
};
983+
} __attribute__((packed)) gs_rgba_t;
984+
985+
typedef union {
986+
u64 rgbaq;
987+
struct {
988+
gs_rgba_t components;
982989
float q;
983990
};
984-
} __attribute__((packed,aligned(8))) gs_rgbaq_t;
991+
} __attribute__((packed)) gs_rgbaq_t;
985992

986993
typedef union {
987994
u64 st;
988995
struct {
989996
float s;
990997
float t;
991998
};
992-
} __attribute__((packed, aligned(8))) gs_stq_t;
999+
} __attribute__((packed)) gs_stq_t;
9931000

9941001
typedef union {
9951002
u128 xyz2;
9961003
struct {
9971004
gs_xyz_t xyz;
9981005
u64 tag;
9991006
};
1000-
} __attribute__((packed,aligned(8))) gs_xyz2;
1007+
} __attribute__((packed)) gs_xyz2;
10011008

10021009
typedef union {
10031010
u128 rgbaq;
10041011
struct {
10051012
gs_rgbaq_t color;
10061013
u64 tag;
10071014
};
1008-
} __attribute__((packed,aligned(8))) gs_rgbaq;
1015+
} __attribute__((packed)) gs_rgbaq;
1016+
1017+
typedef union {
1018+
u64 uv;
1019+
struct {
1020+
u16 u;
1021+
u16 v;
1022+
u32 notused;
1023+
};
1024+
} __attribute__((packed)) gs_uv_t;
10091025

10101026
typedef union {
10111027
u128 uv;
10121028
struct {
1013-
u64 coord;
1029+
gs_uv_t coord;
10141030
u64 tag;
10151031
};
1016-
} __attribute__((packed,aligned(8))) gs_uv;
1032+
} __attribute__((packed)) gs_uv;
10171033

10181034
typedef union {
10191035
u128 stq;
10201036
struct {
10211037
gs_stq_t st;
10221038
u64 tag;
10231039
};
1024-
} __attribute__((packed, aligned(8))) gs_stq;
1040+
} __attribute__((packed)) gs_stq;
10251041

10261042
/// gsKit Point Primitive Structure
10271043
/// This structure holds all relevant data for any
@@ -1041,6 +1057,13 @@ struct gsPrimUVPoint
10411057
};
10421058
typedef struct gsPrimUVPoint GSPRIMUVPOINT;
10431059

1060+
struct gsPrimUVPointFlat
1061+
{
1062+
gs_uv uv;
1063+
gs_xyz2 xyz2;
1064+
};
1065+
typedef struct gsPrimUVPointFlat GSPRIMUVPOINTFLAT;
1066+
10441067
struct gsPrimSTQPoint
10451068
{
10461069
gs_rgbaq rgbaq;

ee/gs/include/gsInline.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,47 @@ static inline gs_rgbaq color_to_RGBAQ(uint8_t r, uint8_t g, uint8_t b, uint8_t a
173173
{
174174
gs_rgbaq res;
175175

176-
res.color.r = r;
177-
res.color.g = g;
178-
res.color.b = b;
179-
res.color.a = a;
176+
res.color.components.r = r;
177+
res.color.components.g = g;
178+
res.color.components.b = b;
179+
res.color.components.a = a;
180180
res.color.q = q;
181181
res.tag = GS_RGBAQ;
182182

183183
return res;
184184
}
185185

186+
// If STQ coordinates are used set q to 1.0f otherwise keep it as 0.0f
187+
static inline gs_rgbaq rgba_to_RGBAQ(uint32_t rgba, float q)
188+
{
189+
gs_rgbaq res;
190+
191+
res.color.components.rgba = rgba;
192+
res.color.q = q;
193+
res.tag = GS_RGBAQ;
194+
195+
return res;
196+
}
197+
198+
static inline gs_rgbaq rgbaq_to_RGBAQ(uint64_t rgbaq)
199+
{
200+
gs_rgbaq res;
201+
202+
res.color.rgbaq = rgbaq;
203+
res.tag = GS_RGBAQ;
204+
205+
return res;
206+
}
207+
186208
static inline gs_uv vertex_to_UV(const GSTEXTURE *Texture, float u, float v)
187209
{
188210
gs_uv res;
189211

190212
int iu = gsKit_float_to_int_u(Texture, u);
191213
int iv = gsKit_float_to_int_v(Texture, v);
192214

193-
res.coord = GS_SETREG_UV(iu, iv);
215+
res.coord.u = iu;
216+
res.coord.v = iv;
194217
res.tag = GS_UV;
195218

196219
return res;

ee/gs/include/gsPrimitive.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void gsKit_prim_line_strip(GSGLOBAL *gsGlobal, float *LineStrip, int segments, i
4646
void gsKit_prim_line_strip_3d(GSGLOBAL *gsGlobal, float *LineStrip, int segments, u64 color);
4747

4848
void gsKit_prim_sprite(GSGLOBAL *gsGlobal, float x1, float y1, float x2, float y2, int iz, u64 color);
49+
void gsKit_prim_list_sprite_gouraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices);
50+
void gsKit_prim_list_sprite_flat(GSGLOBAL *gsGlobal, int count, const u128 *flatContent);
51+
void gsKit_prim_list_sprite_flat_color(GSGLOBAL *gsGlobal, gs_rgbaq color, int count, const gs_xyz2 *vertices);
4952

5053
void gsKit_prim_triangle_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
5154
float x2, float y2, int iz2,

ee/gs/include/gsTexture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ void gsKit_prim_sprite_striped_texture_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *T
127127
u64 color);
128128

129129
void gskit_prim_list_sprite_texture_uv_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, int count, const GSPRIMUVPOINT *vertices);
130+
void gskit_prim_list_sprite_texture_uv_flat(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, int count, const u128 *flatContent);
131+
void gskit_prim_list_sprite_texture_uv_flat_color(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, gs_rgbaq color, int count, const GSPRIMUVPOINTFLAT *vertices);
130132

131133
void gsKit_prim_triangle_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
132134
float x1, float y1, int iz1, float u1, float v1,

ee/gs/src/gsCore.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,28 @@ void gsKit_remove_hsync_handler(int callback_id)
253253
#endif
254254

255255
#if F_gsKit_clear
256+
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
256257
void gsKit_clear(GSGLOBAL *gsGlobal, u64 color)
257258
{
258259
u8 PrevZState;
259260
u8 strips;
260261
u8 remain;
262+
u8 index;
261263
u32 pos;
264+
u8 slices = (gsGlobal->Width + 63)/ 64;
265+
u32 count = (slices * 2) + 1;
266+
u128 flat_content[count];
262267

263268
PrevZState = gsGlobal->Test->ZTST;
264269
gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
265-
strips = gsGlobal->Width / 64;
266-
remain = gsGlobal->Width % 64;
267-
pos = 0;
268270

269-
strips++;
270-
while(strips-- > 0)
271+
flat_content[0] = (u128)rgbaq_to_RGBAQ(color).rgbaq;
272+
for (index = 0; index < slices; index++)
271273
{
272-
gsKit_prim_sprite(gsGlobal, pos, 0, pos + 64, gsGlobal->Height, 0, color);
273-
pos += 64;
274-
}
275-
if(remain > 0)
276-
{
277-
gsKit_prim_sprite(gsGlobal, pos, 0, remain + pos, gsGlobal->Height, 0, color);
274+
flat_content[index * 2 + 1] = vertex_to_XYZ2(gsGlobal, index * 64, 0, 0).xyz2;
275+
flat_content[index * 2 + 2] = (u128)vertex_to_XYZ2(gsGlobal, MIN((index + 1) * 64, gsGlobal->Width) , gsGlobal->Height, 0).xyz2;
278276
}
277+
gsKit_prim_list_sprite_flat(gsGlobal, count, flat_content);
279278

280279
gsGlobal->Test->ZTST = PrevZState;
281280
gsKit_set_test(gsGlobal, 0);

ee/gs/src/gsPrimitive.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,89 @@ void gsKit_prim_sprite(GSGLOBAL *gsGlobal, float x1, float y1, float x2, float y
268268
}
269269
#endif
270270

271+
#if F_gsKit_prim_list_sprite_gouraud_3d
272+
void gsKit_prim_list_sprite_gouraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices)
273+
{
274+
u64* p_store;
275+
u64* p_data;
276+
int qsize = (count*2) + 1;
277+
int bytes = count * sizeof(GSPRIMPOINT);
278+
279+
p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);
280+
281+
if(p_store == gsGlobal->CurQueue->last_tag)
282+
{
283+
*p_data++ = GIF_TAG_AD(qsize);
284+
*p_data++ = GIF_AD;
285+
}
286+
287+
*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 1, 0, gsGlobal->PrimFogEnable,
288+
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
289+
0, gsGlobal->PrimContext, 0);
290+
291+
*p_data++ = GS_PRIM;
292+
293+
memcpy(p_data, vertices, bytes);
294+
}
295+
#endif
296+
297+
#if F_gsKit_prim_list_sprite_flat_color
298+
void gsKit_prim_list_sprite_flat_color(GSGLOBAL *gsGlobal, gs_rgbaq color, int count, const gs_xyz2 *vertices)
299+
{
300+
u64* p_store;
301+
u64* p_data;
302+
int qsize = count + 2;
303+
int bytes = count * sizeof(gs_xyz2);
304+
305+
p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);
306+
307+
if(p_store == gsGlobal->CurQueue->last_tag)
308+
{
309+
*p_data++ = GIF_TAG_AD(qsize);
310+
*p_data++ = GIF_AD;
311+
}
312+
313+
*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 0, gsGlobal->PrimFogEnable,
314+
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
315+
0, gsGlobal->PrimContext, 0);
316+
317+
*p_data++ = GS_PRIM;
318+
319+
// Copy color
320+
memcpy(p_data, &color, sizeof(gs_rgbaq));
321+
p_data += 2; // Advance 2 u64, which is 16 bytes the gs_rgbaq struct size
322+
// Copy vertices
323+
memcpy(p_data, vertices, bytes);
324+
}
325+
#endif
326+
327+
#if F_gsKit_prim_list_sprite_flat
328+
void gsKit_prim_list_sprite_flat(GSGLOBAL *gsGlobal, int count, const u128 *flatContent)
329+
{
330+
u64* p_store;
331+
u64* p_data;
332+
int qsize = count + 1;
333+
int bytes = count * sizeof(u128);
334+
335+
p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);
336+
337+
if(p_store == gsGlobal->CurQueue->last_tag)
338+
{
339+
*p_data++ = GIF_TAG_AD(qsize);
340+
*p_data++ = GIF_AD;
341+
}
342+
343+
*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 0, gsGlobal->PrimFogEnable,
344+
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
345+
0, gsGlobal->PrimContext, 0);
346+
347+
*p_data++ = GS_PRIM;
348+
349+
memcpy(p_data, flatContent, bytes);
350+
}
351+
#endif
352+
353+
271354
#if F_gsKit_prim_triangle_3d
272355
void gsKit_prim_triangle_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
273356
float x2, float y2, int iz2,

0 commit comments

Comments
 (0)