WIP for 3DS, Wii/GameCube, Dreamcast

This commit is contained in:
UnknownShadow200 2023-09-29 13:51:03 +10:00
parent 100eae256f
commit 9b1d9ced16
12 changed files with 68 additions and 93 deletions

View File

@ -4,6 +4,8 @@ SOURCE_DIRS := src third_party/bearssl/src
C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c))
OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o)))
CFLAGS :=-g -O1 -pipe -fno-math-errno -Ithird_party/bearssl/inc
LDFLAGS=-g
LIBS=-lm
TARGET := ClassiCube-dc
@ -24,7 +26,7 @@ $(BUILD_DIR)/%.o: third_party/bearssl/src/%.c
$(TARGET).elf: $(OBJS)
kos-cc $^ -o $@
kos-cc $(LDFLAGS) $^ -o $@ $(LIBS)
$(TARGET).bin: $(TARGET).elf
sh-elf-objcopy -R .stack -O binary $(TARGET).elf $(TARGET).bin

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -366,7 +366,7 @@ static void LoadPlugins(void) {
}
#endif
void Game_Free(void* obj);
static void Game_Free(void* obj);
static void Game_Load(void) {
struct IGameComponent* comp;
Game_UpdateDimensions();

View File

@ -125,21 +125,37 @@ static void SetDefaultState(void) {
Gfx_SetAlphaTest(false);
Gfx_SetDepthWrite(true);
}
static GfxResourceID white_square;
void Gfx_Create(void) {
Gfx.MaxTexWidth = 512;
Gfx.MaxTexHeight = 512;
Gfx.Created = true;
gfx_vsync = true;
static void InitCitro3D(void) {
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS);
SetDefaultState();
InitDefaultResources();
AllocShaders();
}
static GfxResourceID white_square;
void Gfx_Create(void) {
if (!Gfx.Created) InitCitro3D();
Gfx.MaxTexWidth = 512;
Gfx.MaxTexHeight = 512;
Gfx.Created = true;
gfx_vsync = true;
Gfx_RestoreState();
}
void Gfx_Free(void) {
Gfx_FreeState();
// FreeShaders()
// C3D_Fini()
}
cc_bool Gfx_TryRestoreContext(void) { return true; }
void Gfx_RestoreState(void) {
InitDefaultResources();
// 8x8 dummy white texture
// (textures must be at least 8x8, see C3D_TexInitWithParams source)
@ -150,16 +166,11 @@ void Gfx_Create(void) {
white_square = Gfx_CreateTexture(&bmp, 0, false);
}
void Gfx_Free(void) {
FreeShaders();
void Gfx_FreeState(void) {
FreeDefaultResources();
Gfx_DeleteTexture(&white_square);
}
cc_bool Gfx_TryRestoreContext(void) { return true; }
void Gfx_RestoreState(void) { }
void Gfx_FreeState(void) { }
/*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/

View File

@ -19,9 +19,10 @@ static cc_bool renderingDisabled;
*---------------------------------------------------------General---------------------------------------------------------*
*#########################################################################################################################*/
void Gfx_Create(void) {
glKosInit();
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Gfx.MaxTexWidth);
Gfx.MaxTexHeight = Gfx.MaxTexWidth;
if (!Gfx.Created) glKosInit();
// NOTE: technically 1024 is supported by hardware
Gfx.MaxTexWidth = 512;
Gfx.MaxTexHeight = 512;
Gfx.Created = true;
Gfx_RestoreState();
}
@ -242,9 +243,10 @@ static unsigned Interleave(unsigned x) {
}
/*static int CalcTwiddledIndex(int x, int y, int w, int h) {
// Twiddled index looks like this (starting from lowest numbered bits):
// e.g. w > h: yx_yx_xx_xx
// e.g. h > w: yx_yx_yy_yy
// Twiddled index looks like this (lowest numbered bits are leftmost):
// - w = h: yxyx yxyx
// - w > h: yxyx xxxx
// - h > w: yxyx yyyy
// And can therefore be broken down into two components:
// 1) interleaved lower bits
// 2) masked and then shifted higher bits
@ -484,8 +486,6 @@ static CC_NOINLINE void UnshiftTextureCoords(int count) {
static void Gfx_FreeState(void) { FreeDefaultResources(); }
static void Gfx_RestoreState(void) {
InitDefaultResources();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
gfx_format = -1;
glAlphaFunc(GL_GREATER, 0.5f);
@ -519,10 +519,8 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
gfx_stride = strideSizes[fmt];
if (fmt == VERTEX_FORMAT_TEXTURED) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
} else {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
}

View File

@ -48,12 +48,13 @@ static void InitGX(void) {
}
void Gfx_Create(void) {
if (!Gfx.Created) InitGX();
Gfx.MaxTexWidth = 512;
Gfx.MaxTexHeight = 512;
Gfx.Created = true;
gfx_vsync = true;
InitGX();
Gfx_RestoreState();
}

View File

@ -16,6 +16,7 @@
#include <wiikeyboard/keyboard.h>
#endif
static cc_bool needsFBUpdate;
static cc_bool launcherMode;
static void* xfb;
static GXRModeObj* rmode;
@ -31,13 +32,7 @@ static void OnPowerOff(void) {
WindowInfo.Exists = false;
Window_Close();
}
void Window_Init(void) {
// TODO: SYS_SetResetCallback(reload); too? not sure how reset differs on GC/WII
#if defined HW_RVL
SYS_SetPowerCallback(OnPowerOff);
#endif
static void InitVideo(void) {
// Initialise the video system
VIDEO_Init();
@ -61,6 +56,14 @@ void Window_Init(void) {
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
}
void Window_Init(void) {
// TODO: SYS_SetResetCallback(reload); too? not sure how reset differs on GC/WII
#if defined HW_RVL
SYS_SetPowerCallback(OnPowerOff);
#endif
InitVideo();
DisplayInfo.Width = rmode->fbWidth;
DisplayInfo.Height = rmode->xfbHeight;
@ -81,8 +84,14 @@ void Window_Init(void) {
PAD_Init();
}
void Window_Create2D(int width, int height) { launcherMode = true; }
void Window_Create3D(int width, int height) { launcherMode = false; }
void Window_Create2D(int width, int height) {
needsFBUpdate = true;
launcherMode = true;
}
void Window_Create3D(int width, int height) {
launcherMode = false;
}
void Window_Close(void) {
Event_RaiseVoid(&WindowEvents.Closing);
@ -465,6 +474,13 @@ static u32 CvtRGB (u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2)
}
void Window_DrawFramebuffer(Rect2D r) {
// When coming back from the 3D game, framebuffer might have changed
if (needsFBUpdate) {
VIDEO_SetNextFramebuffer(xfb);
VIDEO_Flush();
needsFBUpdate = false;
}
VIDEO_WaitVSync();
r.X &= ~0x01; // round down to nearest even horizontal index

View File

@ -24,5 +24,5 @@ default: $(TARGET)
kos-cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -c $< -o $@
$(TARGET): $(OBJS)
kos-ar cr $@ $<
kos-ar cr $@ $^
kos-ranlib $@

View File

@ -97,11 +97,6 @@ __BEGIN_DECLS
/* Fog */
#define GL_FOG 0x0004 /* capability bit */
/* Client state caps */
#define GL_VERTEX_ARRAY 0x8074
#define GL_COLOR_ARRAY 0x8076
#define GL_TEXTURE_COORD_ARRAY 0x8078
#define GL_FRONT_AND_BACK 0x0408
#define GL_FRONT 0x0404
#define GL_BACK 0x0405
@ -126,9 +121,6 @@ __BEGIN_DECLS
#define GL_INVALID_OPERATION 0x0502
#define GL_OUT_OF_MEMORY 0x0505
/* GetPName */
#define GL_MAX_TEXTURE_SIZE 0x0D33
/* StringName */
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
@ -259,9 +251,6 @@ GLAPI void glVertexPointer(GLint size, GLenum type,
GLAPI void glDrawArrays(GLenum mode, GLint first, GLsizei count);
GLAPI void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
GLAPI void glEnableClientState(GLenum cap);
GLAPI void glDisableClientState(GLenum cap);
/* Transformation / Matrix Functions */
GLAPI void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

View File

@ -10,7 +10,6 @@
static void* VERTEX_PTR;
static GLsizei VERTEX_STRIDE;
static GLuint ENABLED_VERTEX_ATTRIBUTES;
extern GLboolean AUTOSORT_ENABLED;
@ -59,7 +58,7 @@ static void generateQuads(SubmissionTarget* target, const GLsizei first, const G
/* Copy the pos, uv and color directly in one go */
const GLubyte* pos = VERTEX_PTR;
const GLubyte* uv = (ENABLED_VERTEX_ATTRIBUTES & UV_ENABLED_FLAG) ? VERTEX_PTR : NULL;
const GLubyte* uv = TEXTURES_ENABLED ? VERTEX_PTR : NULL;
const GLubyte* col = VERTEX_PTR;
Vertex* dst = start;
@ -332,43 +331,7 @@ void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
submitVertices(mode, first, count);
}
void APIENTRY glEnableClientState(GLenum cap) {
TRACE();
switch(cap) {
case GL_VERTEX_ARRAY:
ENABLED_VERTEX_ATTRIBUTES |= VERTEX_ENABLED_FLAG;
break;
case GL_COLOR_ARRAY:
ENABLED_VERTEX_ATTRIBUTES |= DIFFUSE_ENABLED_FLAG;
break;
case GL_TEXTURE_COORD_ARRAY:
ENABLED_VERTEX_ATTRIBUTES |= UV_ENABLED_FLAG;
break;
default:
_glKosThrowError(GL_INVALID_ENUM, __func__);
}
}
void APIENTRY glDisableClientState(GLenum cap) {
TRACE();
switch(cap) {
case GL_VERTEX_ARRAY:
ENABLED_VERTEX_ATTRIBUTES &= ~VERTEX_ENABLED_FLAG;
break;
case GL_COLOR_ARRAY:
ENABLED_VERTEX_ATTRIBUTES &= ~DIFFUSE_ENABLED_FLAG;
break;
case GL_TEXTURE_COORD_ARRAY:
ENABLED_VERTEX_ATTRIBUTES &= ~UV_ENABLED_FLAG;
break;
default:
_glKosThrowError(GL_INVALID_ENUM, __func__);
}
}
void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) {
VERTEX_PTR = pointer;
VERTEX_STRIDE = stride;
}
}

View File

@ -41,8 +41,6 @@ extern void* memcpy4 (void *dest, const void *src, size_t count);
#define ST_ENABLED_FLAG (1 << 2)
#define DIFFUSE_ENABLED_FLAG (1 << 3)
#define MAX_TEXTURE_SIZE 1024
typedef struct {
unsigned int flags; /* Constant PVR_CMD_USERCLIP */
unsigned int d1, d2, d3; /* Ignored for this type */

View File

@ -467,9 +467,6 @@ void _glApplyScissor(bool force) {
void APIENTRY glGetIntegerv(GLenum pname, GLint *params) {
switch(pname) {
case GL_MAX_TEXTURE_SIZE:
*params = MAX_TEXTURE_SIZE;
break;
case GL_TEXTURE_FREE_MEMORY_ATI:
case GL_FREE_TEXTURE_MEMORY_KOS:
*params = _glFreeTextureMemory();