Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to print a list of sprite #85

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ add_object_library_macros(GS_PRIMITIVE_OBJS ee/gs/src/gsPrimitive.c
gsKit_prim_line_strip
gsKit_prim_line_strip_3d
gsKit_prim_sprite
gsKit_prim_list_sprite_gouraud_3d
gsKit_prim_list_sprite_flat
gsKit_prim_list_sprite_flat_color
gsKit_prim_triangle_3d
gsKit_prim_triangle_strip
gsKit_prim_triangle_strip_3d
Expand Down Expand Up @@ -186,6 +189,8 @@ add_object_library_macros(GS_TEXTURE_OBJS ee/gs/src/gsTexture.c
gsKit_prim_sprite_striped_texture_3d
gsKit_prim_triangle_texture_3d
gskit_prim_list_sprite_texture_uv_3d
gskit_prim_list_sprite_texture_uv_flat
gskit_prim_list_sprite_texture_uv_flat_color
gsKit_prim_triangle_goraud_texture_3d
gsKit_prim_list_triangle_goraud_texture_uv_3d
gsKit_prim_list_triangle_goraud_texture_stq_3d
Expand Down
41 changes: 32 additions & 9 deletions ee/gs/include/gsInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,58 +970,74 @@ typedef union {
u16 y;
u32 z;
};
} __attribute__((packed,aligned(8))) gs_xyz_t;
} __attribute__((packed)) gs_xyz_t;

typedef union {
u64 rgbaq;
u32 rgba;
struct {
u8 r;
u8 g;
u8 b;
u8 a;
};
} __attribute__((packed)) gs_rgba_t;

typedef union {
u64 rgbaq;
struct {
gs_rgba_t components;
float q;
};
} __attribute__((packed,aligned(8))) gs_rgbaq_t;
} __attribute__((packed)) gs_rgbaq_t;

typedef union {
u64 st;
struct {
float s;
float t;
};
} __attribute__((packed, aligned(8))) gs_stq_t;
} __attribute__((packed)) gs_stq_t;

typedef union {
u128 xyz2;
struct {
gs_xyz_t xyz;
u64 tag;
};
} __attribute__((packed,aligned(8))) gs_xyz2;
} __attribute__((packed)) gs_xyz2;

typedef union {
u128 rgbaq;
struct {
gs_rgbaq_t color;
u64 tag;
};
} __attribute__((packed,aligned(8))) gs_rgbaq;
} __attribute__((packed)) gs_rgbaq;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had wrong alignment it should be 16 instead, but let the compiler to take it based on u128


typedef union {
u64 uv;
struct {
u16 u;
u16 v;
u32 notused;
};
} __attribute__((packed)) gs_uv_t;

typedef union {
u128 uv;
struct {
u64 coord;
gs_uv_t coord;
u64 tag;
};
} __attribute__((packed,aligned(8))) gs_uv;
} __attribute__((packed)) gs_uv;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had wrong alignment it should be 16 instead, but let the compiler to take it based on u128


typedef union {
u128 stq;
struct {
gs_stq_t st;
u64 tag;
};
} __attribute__((packed, aligned(8))) gs_stq;
Copy link
Member Author

@fjtrujy fjtrujy Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had wrong alignment it should be 16 instead, but let the compiler to take it based on u128

} __attribute__((packed)) gs_stq;

/// gsKit Point Primitive Structure
/// This structure holds all relevant data for any
Expand All @@ -1041,6 +1057,13 @@ struct gsPrimUVPoint
};
typedef struct gsPrimUVPoint GSPRIMUVPOINT;

struct gsPrimUVPointFlat
{
gs_uv uv;
gs_xyz2 xyz2;
};
typedef struct gsPrimUVPointFlat GSPRIMUVPOINTFLAT;

struct gsPrimSTQPoint
{
gs_rgbaq rgbaq;
Expand Down
33 changes: 28 additions & 5 deletions ee/gs/include/gsInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,47 @@ static inline gs_rgbaq color_to_RGBAQ(uint8_t r, uint8_t g, uint8_t b, uint8_t a
{
gs_rgbaq res;

res.color.r = r;
res.color.g = g;
res.color.b = b;
res.color.a = a;
res.color.components.r = r;
res.color.components.g = g;
res.color.components.b = b;
res.color.components.a = a;
res.color.q = q;
res.tag = GS_RGBAQ;

return res;
}

// If STQ coordinates are used set q to 1.0f otherwise keep it as 0.0f
static inline gs_rgbaq rgba_to_RGBAQ(uint32_t rgba, float q)
{
gs_rgbaq res;

res.color.components.rgba = rgba;
res.color.q = q;
res.tag = GS_RGBAQ;

return res;
}

static inline gs_rgbaq rgbaq_to_RGBAQ(uint64_t rgbaq)
{
gs_rgbaq res;

res.color.rgbaq = rgbaq;
res.tag = GS_RGBAQ;

return res;
}

static inline gs_uv vertex_to_UV(const GSTEXTURE *Texture, float u, float v)
{
gs_uv res;

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

res.coord = GS_SETREG_UV(iu, iv);
res.coord.u = iu;
res.coord.v = iv;
res.tag = GS_UV;

return res;
Expand Down
3 changes: 3 additions & 0 deletions ee/gs/include/gsPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void gsKit_prim_line_strip(GSGLOBAL *gsGlobal, float *LineStrip, int segments, i
void gsKit_prim_line_strip_3d(GSGLOBAL *gsGlobal, float *LineStrip, int segments, u64 color);

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

void gsKit_prim_triangle_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
float x2, float y2, int iz2,
Expand Down
2 changes: 2 additions & 0 deletions ee/gs/include/gsTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ void gsKit_prim_sprite_striped_texture_3d(GSGLOBAL *gsGlobal, const GSTEXTURE *T
u64 color);

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

void gsKit_prim_triangle_texture_3d(GSGLOBAL *gsGlobal, GSTEXTURE *Texture,
float x1, float y1, int iz1, float u1, float v1,
Expand Down
21 changes: 10 additions & 11 deletions ee/gs/src/gsCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,29 +253,28 @@ void gsKit_remove_hsync_handler(int callback_id)
#endif

#if F_gsKit_clear
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
void gsKit_clear(GSGLOBAL *gsGlobal, u64 color)
{
u8 PrevZState;
u8 strips;
u8 remain;
u8 index;
u32 pos;
u8 slices = (gsGlobal->Width + 63)/ 64;
u32 count = (slices * 2) + 1;
u128 flat_content[count];

PrevZState = gsGlobal->Test->ZTST;
gsKit_set_test(gsGlobal, GS_ZTEST_OFF);
strips = gsGlobal->Width / 64;
remain = gsGlobal->Width % 64;
pos = 0;

strips++;
while(strips-- > 0)
flat_content[0] = (u128)rgbaq_to_RGBAQ(color).rgbaq;
for (index = 0; index < slices; index++)
{
gsKit_prim_sprite(gsGlobal, pos, 0, pos + 64, gsGlobal->Height, 0, color);
pos += 64;
}
if(remain > 0)
{
gsKit_prim_sprite(gsGlobal, pos, 0, remain + pos, gsGlobal->Height, 0, color);
flat_content[index * 2 + 1] = vertex_to_XYZ2(gsGlobal, index * 64, 0, 0).xyz2;
flat_content[index * 2 + 2] = (u128)vertex_to_XYZ2(gsGlobal, MIN((index + 1) * 64, gsGlobal->Width) , gsGlobal->Height, 0).xyz2;
}
gsKit_prim_list_sprite_flat(gsGlobal, count, flat_content);

gsGlobal->Test->ZTST = PrevZState;
gsKit_set_test(gsGlobal, 0);
Expand Down
83 changes: 83 additions & 0 deletions ee/gs/src/gsPrimitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,89 @@ void gsKit_prim_sprite(GSGLOBAL *gsGlobal, float x1, float y1, float x2, float y
}
#endif

#if F_gsKit_prim_list_sprite_gouraud_3d
void gsKit_prim_list_sprite_gouraud_3d(GSGLOBAL *gsGlobal, int count, const GSPRIMPOINT *vertices)
{
u64* p_store;
u64* p_data;
int qsize = (count*2) + 1;
int bytes = count * sizeof(GSPRIMPOINT);

p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);

if(p_store == gsGlobal->CurQueue->last_tag)
{
*p_data++ = GIF_TAG_AD(qsize);
*p_data++ = GIF_AD;
}

*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 1, 0, gsGlobal->PrimFogEnable,
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
0, gsGlobal->PrimContext, 0);

*p_data++ = GS_PRIM;

memcpy(p_data, vertices, bytes);
}
#endif

#if F_gsKit_prim_list_sprite_flat_color
void gsKit_prim_list_sprite_flat_color(GSGLOBAL *gsGlobal, gs_rgbaq color, int count, const gs_xyz2 *vertices)
{
u64* p_store;
u64* p_data;
int qsize = count + 2;
int bytes = count * sizeof(gs_xyz2);

p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);

if(p_store == gsGlobal->CurQueue->last_tag)
{
*p_data++ = GIF_TAG_AD(qsize);
*p_data++ = GIF_AD;
}

*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 0, gsGlobal->PrimFogEnable,
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
0, gsGlobal->PrimContext, 0);

*p_data++ = GS_PRIM;

// Copy color
memcpy(p_data, &color, sizeof(gs_rgbaq));
p_data += 2; // Advance 2 u64, which is 16 bytes the gs_rgbaq struct size
// Copy vertices
memcpy(p_data, vertices, bytes);
}
#endif

#if F_gsKit_prim_list_sprite_flat
void gsKit_prim_list_sprite_flat(GSGLOBAL *gsGlobal, int count, const u128 *flatContent)
{
u64* p_store;
u64* p_data;
int qsize = count + 1;
int bytes = count * sizeof(u128);

p_store = p_data = gsKit_heap_alloc(gsGlobal, qsize, (qsize*16), GIF_AD);

if(p_store == gsGlobal->CurQueue->last_tag)
{
*p_data++ = GIF_TAG_AD(qsize);
*p_data++ = GIF_AD;
}

*p_data++ = GS_SETREG_PRIM( GS_PRIM_PRIM_SPRITE, 0, 0, gsGlobal->PrimFogEnable,
gsGlobal->PrimAlphaEnable, gsGlobal->PrimAAEnable,
0, gsGlobal->PrimContext, 0);

*p_data++ = GS_PRIM;

memcpy(p_data, flatContent, bytes);
}
#endif


#if F_gsKit_prim_triangle_3d
void gsKit_prim_triangle_3d(GSGLOBAL *gsGlobal, float x1, float y1, int iz1,
float x2, float y2, int iz2,
Expand Down
Loading
Loading