Skip to content

Commit fe1d47e

Browse files
committed
Add flat API
1 parent b37348b commit fe1d47e

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ struct gsPrimUVPoint
10481048
};
10491049
typedef struct gsPrimUVPoint GSPRIMUVPOINT;
10501050

1051+
struct gsPrimUVPointFlat
1052+
{
1053+
gs_uv uv;
1054+
gs_xyz2 xyz2;
1055+
};
1056+
typedef struct gsPrimUVPointFlat GSPRIMUVPOINTFLAT;
1057+
10511058
struct gsPrimSTQPoint
10521059
{
10531060
gs_rgbaq rgbaq;

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/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,

ee/gs/src/gsTexture.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,101 @@ void gskit_prim_list_sprite_texture_uv_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *T
734734
}
735735
#endif
736736

737+
#if F_gskit_prim_list_sprite_texture_uv_flat
738+
void gskit_prim_list_sprite_texture_uv_flat(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, int count, const u128 *flatContent)
739+
{
740+
u64* p_data;
741+
u64* p_store;
742+
int tw, th;
743+
744+
int qsize = (count) + 2;
745+
int bytes = count * sizeof(u128);
746+
747+
gsKit_set_texfilter(gsGlobal, Texture->Filter);
748+
gsKit_set_tw_th(Texture, &tw, &th);
749+
750+
p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);
751+
752+
if(p_store == gsGlobal->CurQueue->last_tag)
753+
{
754+
*p_data++ = GIF_TAG_AD(qsize);
755+
*p_data++ = GIF_AD;
756+
}
757+
758+
if(Texture->VramClut == 0)
759+
{
760+
*p_data++ = GS_SETREG_TEX0(Texture->Vram/256, Texture->TBW, Texture->PSM,
761+
tw, th, gsGlobal->PrimAlphaEnable, 0,
762+
0, 0, 0, 0, GS_CLUT_STOREMODE_NOLOAD);
763+
}
764+
else
765+
{
766+
*p_data++ = GS_SETREG_TEX0(Texture->Vram/256, Texture->TBW, Texture->PSM,
767+
tw, th, gsGlobal->PrimAlphaEnable, 0,
768+
Texture->VramClut/256, Texture->ClutPSM, 0, 0, GS_CLUT_STOREMODE_LOAD);
769+
}
770+
*p_data++ = GS_TEX0_1 + gsGlobal->PrimContext;
771+
772+
*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 1, gsGlobal->PrimFogEnable,
773+
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
774+
1, gsGlobal->PrimContext, 0);
775+
776+
*p_data++ = GS_PRIM;
777+
778+
memcpy(p_data, flatContent, bytes);
779+
}
780+
#endif
781+
782+
#if F_gskit_prim_list_sprite_texture_uv_flat_color
783+
void gskit_prim_list_sprite_texture_uv_flat_color(GSGLOBAL *gsGlobal, const GSTEXTURE *Texture, gs_rgbaq color, int count, const GSPRIMUVPOINTFLAT *vertices)
784+
{
785+
u64* p_data;
786+
u64* p_store;
787+
int tw, th;
788+
789+
int qsize = (count * 2) + 3;
790+
int bytes = count * sizeof(GSPRIMUVPOINTFLAT);
791+
792+
gsKit_set_texfilter(gsGlobal, Texture->Filter);
793+
gsKit_set_tw_th(Texture, &tw, &th);
794+
795+
p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);
796+
797+
if(p_store == gsGlobal->CurQueue->last_tag)
798+
{
799+
*p_data++ = GIF_TAG_AD(qsize);
800+
*p_data++ = GIF_AD;
801+
}
802+
803+
if(Texture->VramClut == 0)
804+
{
805+
*p_data++ = GS_SETREG_TEX0(Texture->Vram/256, Texture->TBW, Texture->PSM,
806+
tw, th, gsGlobal->PrimAlphaEnable, 0,
807+
0, 0, 0, 0, GS_CLUT_STOREMODE_NOLOAD);
808+
}
809+
else
810+
{
811+
*p_data++ = GS_SETREG_TEX0(Texture->Vram/256, Texture->TBW, Texture->PSM,
812+
tw, th, gsGlobal->PrimAlphaEnable, 0,
813+
Texture->VramClut/256, Texture->ClutPSM, 0, 0, GS_CLUT_STOREMODE_LOAD);
814+
}
815+
*p_data++ = GS_TEX0_1 + gsGlobal->PrimContext;
816+
817+
*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 1, gsGlobal->PrimFogEnable,
818+
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
819+
1, gsGlobal->PrimContext, 0);
820+
821+
*p_data++ = GS_PRIM;
822+
823+
// Copy color
824+
memcpy(p_data, &color, sizeof(gs_rgbaq));
825+
p_data += 2; // Advance 2 u64, which is 16 bytes the gs_rgbaq struct size
826+
// Copy vertices
827+
memcpy(p_data, vertices, bytes);
828+
}
829+
#endif
830+
831+
737832
#if F_gsKit_prim_triangle_texture_3d
738833
void gsKit_prim_triangle_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
739834
float x1, float y1, int iz1, float u1, float v1,

0 commit comments

Comments
 (0)