Skip to content

Commit

Permalink
All graphics backends can now see if in 2D mode or not
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 16, 2024
1 parent 2d5e0e2 commit a5dfd2e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion misc/dreamcast/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LDFLAGS=-g
LIBS=-lm $(GLDC_LIB) -lppp -lkosfat

TARGET := ClassiCube-dc
CC_TEXTURES = classicube.zip
CC_TEXTURES = misc/dreamcast/classicube.zip

ifeq ($(strip $(KOS_BASE)),)
$(error "Please set KOS variables in your environment.")
Expand Down
9 changes: 4 additions & 5 deletions src/Graphics_PS1.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ static RenderBuffer buffers[2];
static cc_uint8* next_packet;
static int active_buffer;
static RenderBuffer* buffer;
static cc_bool rendering2D;
static void* lastPoly;
static cc_bool cullingEnabled;

Expand Down Expand Up @@ -805,9 +804,9 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
}*/

static void DrawQuads(int verticesCount, int startVertex) {
if (rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
if (gfx_rendering2D && gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads2D(verticesCount, startVertex);
} else if (rendering2D) {
} else if (gfx_rendering2D) {
DrawColouredQuads2D(verticesCount, startVertex);
} else if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads3D(verticesCount, startVertex);
Expand Down Expand Up @@ -869,12 +868,12 @@ void Gfx_GetApiInfo(cc_string* info) {
cc_bool Gfx_TryRestoreContext(void) { return true; }

void Gfx_Begin2D(int width, int height) {
rendering2D = true;
gfx_rendering2D = true;
Gfx_SetAlphaBlending(true);
}

void Gfx_End2D(void) {
rendering2D = false;
gfx_rendering2D = false;
Gfx_SetAlphaBlending(false);
}
#endif
35 changes: 31 additions & 4 deletions src/Graphics_Saturn.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void Gfx_Create(void) {
_primitive_init();
}

Gfx.MinTexWidth = 8;
Gfx.MinTexHeight = 8;
Gfx.MaxTexWidth = 128;
Gfx.MaxTexHeight = 128;
Gfx.Created = true;
Expand Down Expand Up @@ -314,7 +316,32 @@ static void Transform(Vec3* result, struct VertexTextured* a, const struct Matri

#define IsPointCulled(vec) vec.x < -10000 || vec.x > 10000 || vec.y < -10000 || vec.y > 10000 || vec.z < 0 || vec.z > 1024

static void DrawTexturedQuads(int verticesCount, int startVertex) {
static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;

int16_vec2_t points[4];
points[0].x = v[0].X; points[0].y = v[0].Y;
points[1].x = v[1].X; points[1].y = v[1].Y;
points[2].x = v[2].X; points[2].y = v[2].Y;
points[3].x = v[3].X; points[3].y = v[3].Y;

int R = PackedCol_R(v->Col);
int G = PackedCol_G(v->Col);
int B = PackedCol_B(v->Col);

vdp1_cmdt_t* cmd;

cmd = NextPrimitive();
vdp1_cmdt_polygon_set(cmd);
vdp1_cmdt_color_set(cmd, RGB1555(1, R >> 3, G >> 3, B >> 3));
vdp1_cmdt_draw_mode_set(cmd, _primitive_draw_mode);
vdp1_cmdt_vtx_set(cmd, points);
}
}

static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
for (int i = 0; i < verticesCount; i += 4)
{
struct VertexTextured* v = (struct VertexTextured*)gfx_vertices + startVertex + i;
Expand Down Expand Up @@ -352,18 +379,18 @@ static void DrawTexturedQuads(int verticesCount, int startVertex) {

void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads(verticesCount, startVertex);
DrawTexturedQuads3D(verticesCount, startVertex);
}
}

void Gfx_DrawVb_IndexedTris(int verticesCount) {
if (gfx_format == VERTEX_FORMAT_TEXTURED) {
DrawTexturedQuads(verticesCount, 0);
DrawTexturedQuads3D(verticesCount, 0);
}
}

void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
DrawTexturedQuads(verticesCount, startVertex);
DrawTexturedQuads3D(verticesCount, startVertex);
}


Expand Down
5 changes: 5 additions & 0 deletions src/_GraphicsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static int gfx_stride, gfx_format = -1;

static cc_bool gfx_vsync, gfx_fogEnabled;
static float gfx_minFrameMs;
static cc_bool gfx_rendering2D;


/*########################################################################################################################*
Expand Down Expand Up @@ -284,14 +285,18 @@ void Gfx_Begin2D(int width, int height) {

Gfx_SetDepthTest(false);
Gfx_SetAlphaBlending(true);

gfx_hadFog = Gfx_GetFog();
if (gfx_hadFog) Gfx_SetFog(false);
gfx_rendering2D = true;
}

void Gfx_End2D(void) {
Gfx_SetDepthTest(true);
Gfx_SetAlphaBlending(false);

if (gfx_hadFog) Gfx_SetFog(true);
gfx_rendering2D = false;
}
#endif

Expand Down

0 comments on commit a5dfd2e

Please sign in to comment.