Mesh working, lua broken

This commit is contained in:
2026-02-05 08:21:19 -06:00
parent 67bf825cc9
commit 5cf299a1c7
7 changed files with 126 additions and 82 deletions

View File

@@ -38,4 +38,4 @@ else
end end
localeSet(DUSK_LOCALE_EN_US) localeSet(DUSK_LOCALE_EN_US)
sceneSet('scene/initial.dsf') -- sceneSet('scene/initial.dsf')

View File

@@ -67,7 +67,6 @@ void cameraPushMatrix(camera_t *camera) {
break; break;
case CAMERA_PROJECTION_TYPE_PERSPECTIVE: case CAMERA_PROJECTION_TYPE_PERSPECTIVE:
case CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED:
guPerspective( guPerspective(
guProjection, guProjection,
// FOV is in degrees. // FOV is in degrees.
@@ -79,6 +78,10 @@ void cameraPushMatrix(camera_t *camera) {
); );
break; break;
case CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED:
assertUnreachable("Flipped perspective not implemented on Dolphin");
break;
default: default:
assertUnreachable("Invalid camera projection type"); assertUnreachable("Invalid camera projection type");
} }
@@ -104,12 +107,15 @@ void cameraPushMatrix(camera_t *camera) {
break; break;
case CAMERA_VIEW_TYPE_MATRIX: case CAMERA_VIEW_TYPE_MATRIX:
assertUnreachable("Matrix camera not implemented");
break; break;
case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT: case CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT:
assertUnreachable("Pixel perfect camera not implemented");
break; break;
case CAMERA_VIEW_TYPE_2D: case CAMERA_VIEW_TYPE_2D:
assertUnreachable("2D camera not implemented");
break; break;
default: default:

View File

@@ -22,39 +22,44 @@
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include <math.h> #include <math.h>
#include <gccore.h>
display_t DISPLAY = { 0 }; display_t DISPLAY = { 0 };
static vu8 readyForCopy; #if DOLPHIN
PADStatus pads[4]; static vu8 readyForCopy;
Mtx view; #define FIFO_SIZE (256*1024)
Mtx44 projection; static void copy_buffers(u32 count __attribute__ ((unused)))
#define FIFO_SIZE (256*1024) {
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;
}
}
#endif
float_t vertices[] ATTRIBUTE_ALIGN(32) = { meshvertex_t vertices[3] = {
0, 15, 0, {
-15, -15, 0, .color = COLOR_RED_4B,
15, -15, 0}; .uv = { 0.5f, 1.0f },
.pos = { 0.0f, 15.0f, 0.0f }
},
{
.color = COLOR_GREEN_4B,
.uv = { 0.0f, 0.0f },
.pos = { -15.0f, -15.0f, 0.0f }
},
u8 colors[] ATTRIBUTE_ALIGN(32) = { {
255, 0, 0, 255, .color = COLOR_BLUE_4B,
0, 255, 0, 255, .uv = { 1.0f, 0.0f },
0, 0, 255, 255 .pos = { 15.0f, -15.0f, 0.0f }
}
}; };
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) { errorret_t displayInit(void) {
#if DISPLAY_SDL2 #if DISPLAY_SDL2
uint32_t flags = SDL_INIT_VIDEO; uint32_t flags = SDL_INIT_VIDEO;
@@ -149,29 +154,12 @@ errorret_t displayInit(void) {
//? //?
GX_CopyDisp(DISPLAY.frameBuffer, GX_TRUE); 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 #endif
quadInit(); quadInit();
frameBufferInitBackbuffer(); frameBufferInitBackbuffer();
spriteBatchInit(); spriteBatchInit();
errorChain(textInit()); // errorChain(textInit());
screenInit(); screenInit();
errorOk(); errorOk();
@@ -225,39 +213,8 @@ errorret_t displayUpdate(void) {
); );
errorChain(sceneRender()); 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 // Render UI
uiRender(); // uiRender();
// Finish up // Finish up
screenUnbind(); screenUnbind();

View File

@@ -130,6 +130,9 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
); );
#elif DOLPHIN #elif DOLPHIN
GX_InvVtxCache();
GX_InvalidateTexAll();
GX_SetViewport( GX_SetViewport(
0, 0, 0, 0,
frameBufferGetWidth(framebuffer), frameBufferGetWidth(framebuffer),

View File

@@ -69,6 +69,37 @@ void meshDraw(
0, 0,
count count
); );
#elif DOLPHIN
// Prepare Vertex descriptor
GX_ClearVtxDesc();// Just clears so may be un-needed?
GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
// GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);
GX_SetVtxDesc(GX_VA_CLR0, GX_INDEX16);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
// GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
const u8 stride = (u8)sizeof(meshvertex_t);
GX_SetArray(GX_VA_POS, &mesh->vertices[offset].pos[0], stride);
// GX_SetArray(GX_VA_TEX0, &mesh->vertices[offset].uv[0], stride);
GX_SetArray(GX_VA_CLR0, &mesh->vertices[offset].color, stride);
GX_SetNumChans(1);// How many color channels are used
GX_SetNumTexGens(0);// How many texture coordinate generators are used
// Basically the shader setup
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
GX_Begin(mesh->primitiveType, GX_VTXFMT0, (uint16_t)count);
for(u16 i = 0; i < (u16)count; ++i) {
GX_Position1x16(i);
// GX_TexCoord1x16(i);
GX_Color1x16(i);
}
GX_End();
#endif #endif
} }

View File

@@ -22,13 +22,21 @@ typedef enum {
#define MESH_VERTEX_UV_SIZE 2 #define MESH_VERTEX_UV_SIZE 2
#define MESH_VERTEX_POS_SIZE 3 #define MESH_VERTEX_POS_SIZE 3
typedef struct { #if DOLPHIN
typedef struct ATTRIBUTE_ALIGN(32) {
#else
typedef struct {
#endif
color4b_t color; color4b_t color;
float uv[MESH_VERTEX_UV_SIZE]; float uv[MESH_VERTEX_UV_SIZE];
float pos[MESH_VERTEX_POS_SIZE]; float pos[MESH_VERTEX_POS_SIZE];
} meshvertex_t; } meshvertex_t;
typedef struct { #if DOLPHIN
typedef struct ATTRIBUTE_ALIGN(32) {
#else
typedef struct {
#endif
const meshvertex_t *vertices; const meshvertex_t *vertices;
int32_t vertexCount; int32_t vertexCount;
meshprimitivetype_t primitiveType; meshprimitivetype_t primitiveType;

View File

@@ -41,10 +41,49 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
backpackInit(); backpackInit();
// Run the initial script. // Run the initial script.
// scriptcontext_t ctx; scriptcontext_t ctx;
// errorChain(scriptContextInit(&ctx)); errorChain(scriptContextInit(&ctx));
// errorChain(scriptContextExecFile(&ctx, "init.dsf")); // errorChain(scriptContextExecFile(&ctx, "init.dsf"));
// scriptContextDispose(&ctx);
errorChain(scriptContextExec(&ctx,
"printf('Lua still working')"
// "module('platform')\n"
// "module('input')\n"
// "module('scene')\n"
// "module('locale')\n"
// "if PLATFORM == \"psp\" then\n"
// " inputBind(\"up\", INPUT_ACTION_UP)\n"
// " inputBind(\"down\", INPUT_ACTION_DOWN)\n"
// " inputBind(\"left\", INPUT_ACTION_LEFT)\n"
// " inputBind(\"right\", INPUT_ACTION_RIGHT)\n"
// " inputBind(\"circle\", INPUT_ACTION_CANCEL)\n"
// " inputBind(\"cross\", INPUT_ACTION_ACCEPT)\n"
// " inputBind(\"select\", INPUT_ACTION_RAGEQUIT)\n"
// " inputBind(\"lstick_up\", INPUT_ACTION_UP)\n"
// " inputBind(\"lstick_down\", INPUT_ACTION_DOWN)\n"
// " inputBind(\"lstick_left\", INPUT_ACTION_LEFT)\n"
// " inputBind(\"lstick_right\", INPUT_ACTION_RIGHT)\n"
// "else\n"
// " if INPUT_KEYBOARD then\n"
// " inputBind(\"w\", INPUT_ACTION_UP)\n"
// " inputBind(\"s\", INPUT_ACTION_DOWN)\n"
// " inputBind(\"a\", INPUT_ACTION_LEFT)\n"
// " inputBind(\"d\", INPUT_ACTION_RIGHT)\n"
// " inputBind(\"left\", INPUT_ACTION_LEFT)\n"
// " inputBind(\"right\", INPUT_ACTION_RIGHT)\n"
// " inputBind(\"up\", INPUT_ACTION_UP)\n"
// " inputBind(\"down\", INPUT_ACTION_DOWN)\n"
// " inputBind(\"enter\", INPUT_ACTION_ACCEPT)\n"
// " inputBind(\"e\", INPUT_ACTION_ACCEPT)\n"
// " inputBind(\"q\", INPUT_ACTION_CANCEL)\n"
// " inputBind(\"escape\", INPUT_ACTION_RAGEQUIT)\n"
// " end \n"
// "end\n"
// "localeSet(DUSK_LOCALE_EN_US)\n"
// "print('Good here')"
));
scriptContextDispose(&ctx);
errorOk(); errorOk();
} }