This commit is contained in:
2026-02-05 00:42:04 -06:00
parent 56e1696cd4
commit 67bf825cc9
5 changed files with 224 additions and 12 deletions

View File

@@ -16,9 +16,45 @@
#include "debug/debug.h"
#include "display/text.h"
#include "assert/assert.h"
#include "util/memory.h"
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <gccore.h>
display_t DISPLAY = { 0 };
static vu8 readyForCopy;
PADStatus pads[4];
Mtx view;
Mtx44 projection;
#define FIFO_SIZE (256*1024)
float_t vertices[] ATTRIBUTE_ALIGN(32) = {
0, 15, 0,
-15, -15, 0,
15, -15, 0};
u8 colors[] ATTRIBUTE_ALIGN(32) = {
255, 0, 0, 255,
0, 255, 0, 255,
0, 0, 255, 255
};
static void copy_buffers(u32 count __attribute__ ((unused)))
{
if (readyForCopy==GX_TRUE) {
GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GX_SetColorUpdate(GX_TRUE);
GX_CopyDisp(DISPLAY.frameBuffer,GX_TRUE);
GX_Flush();
readyForCopy = GX_FALSE;
}
}
errorret_t displayInit(void) {
#if DISPLAY_SDL2
uint32_t flags = SDL_INIT_VIDEO;
@@ -81,11 +117,55 @@ errorret_t displayInit(void) {
VIDEO_Configure(DISPLAY.screenMode);
VIDEO_SetNextFramebuffer(DISPLAY.frameBuffer);
VIDEO_SetPostRetraceCallback(copy_buffers);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
// VIDEO_WaitVSync();
// if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
DISPLAY.fifoBuffer = MEM_K0_TO_K1(memalign(32, FIFO_SIZE));
memoryZero(DISPLAY.fifoBuffer, FIFO_SIZE);
GX_Init(DISPLAY.fifoBuffer, FIFO_SIZE);
// This seems to be mostly related to interlacing vs progressive
GX_SetDispCopyYScale(
(f32)DISPLAY.screenMode->xfbHeight /
(f32)DISPLAY.screenMode->efbHeight
);
GX_SetScissor(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
GX_SetDispCopySrc(0,0,DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->efbHeight);
GX_SetDispCopyDst(DISPLAY.screenMode->fbWidth,DISPLAY.screenMode->xfbHeight);
GX_SetCopyFilter(DISPLAY.screenMode->aa,DISPLAY.screenMode->sample_pattern,
GX_TRUE,DISPLAY.screenMode->vfilter);
GX_SetFieldMode(DISPLAY.screenMode->field_rendering, (
(DISPLAY.screenMode->viHeight == 2 * DISPLAY.screenMode->xfbHeight) ?
GX_ENABLE : GX_DISABLE
));
// Setup cull modes
GX_SetCullMode(GX_CULL_NONE);
GX_SetDispCopyGamma(GX_GM_1_0);
//?
GX_CopyDisp(DISPLAY.frameBuffer, GX_TRUE);
// Set up view and projection matrices
guPerspective(projection, 60, 1.33F, 10.0F, 300.0F);
GX_LoadProjectionMtx(projection, GX_PERSPECTIVE);
// Prepare Vertex descriptor
GX_ClearVtxDesc();
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX8);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
GX_SetArray(GX_VA_POS, vertices, 3*sizeof(float_t));
GX_SetArray(GX_VA_CLR0, colors, 4*sizeof(u8));
GX_SetNumChans(1);
GX_SetNumTexGens(0);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
#endif
quadInit();
@@ -145,6 +225,37 @@ errorret_t displayUpdate(void) {
);
errorChain(sceneRender());
GX_InvVtxCache();
GX_InvalidateTexAll();
// This seems to setup camera
// guVector camera = {0.0F, 0.0F, 0.0F};
// guVector up = {0.0F, 1.0F, 0.0F};
// guVector look = {0.0F, 0.0F, -1.0F};
// guLookAt(view, &camera, &up, &look);
// Mtx modelView;
// guMtxIdentity(modelView);
// guMtxTransApply(modelView, modelView, 0.0F, 0.0F, -50.0F);
// guMtxConcat(view,modelView,modelView);
// // This seems to load the matrix into the GX pipeline?
// GX_LoadPosMtxImm(modelView, GX_PNMTX0);
camera_t camera;
cameraInitPerspective(&camera);
camera.lookat.position[0] = 32;
camera.lookat.position[1] = 32;
camera.lookat.position[2] = 32;
cameraPushMatrix(&camera);
GX_Begin(GX_TRIANGLES, GX_VTXFMT0, 3);
GX_Position1x8(0);
GX_Color1x8(0);
GX_Position1x8(1);
GX_Color1x8(1);
GX_Position1x8(2);
GX_Color1x8(2);
GX_End();
cameraPopMatrix();
// Render UI
uiRender();
@@ -160,8 +271,11 @@ errorret_t displayUpdate(void) {
debugPrint("GL Error: %d\n", err);
}
#elif DOLPHIN
GX_DrawDone();
readyForCopy = GX_TRUE;
VIDEO_WaitVSync();
if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
// if(DISPLAY.screenMode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
#endif