Skip to content
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
6 changes: 3 additions & 3 deletions source/game/emancipation.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ float emancipationRectangleData[] = {1.0f, 1.0f, 0.0f,

u32* emancipationRectangleVertexData = NULL;

extern u32 __linear_heap;
#define emancipationBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define emancipationBaseAddr __ctru_linear_heap

int emancipationUniformTextureDimensions;

Expand Down Expand Up @@ -309,7 +309,7 @@ void drawEmancipationGrid(emancipationGrid_s* eg)
textureBind(&gridSurfaceTexture, GPU_TEXUNIT0);
GPU_SetFloatUniform(GPU_VERTEX_SHADER, emancipationUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 0.7f, l/8}, 1);

GPU_DrawArray(GPU_TRIANGLES, 12);
GPU_DrawArray(GPU_TRIANGLES, 0, 12);
gsPopMatrix();
}

Expand Down
10 changes: 5 additions & 5 deletions source/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ texture_s crosshairTexture;
DVLB_s* passthroughDvlb;
shaderProgram_s passthroughProgram;

extern u32 __linear_heap;
#define rectangleBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define rectangleBaseAddr __ctru_linear_heap

float rectangleData[] = {1.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
Expand Down Expand Up @@ -240,14 +240,14 @@ void drawPlayerGun(player_s* p)

gsSetShader(&passthroughProgram);

GPU_DrawArray(GPU_TRIANGLES, 6);
GPU_DrawArray(GPU_TRIANGLES, 0, 6);

GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL);

GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)crosshairVertexData-rectangleBaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_OFFSET, (u32)crosshairVertexData-rectangleBaseAddr);
textureBind(&crosshairTexture, GPU_TEXUNIT0);

GPU_DrawArray(GPU_TRIANGLES, 6);
GPU_DrawArray(GPU_TRIANGLES, 0, 6);

GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL);
gsSwitchRenderMode(md2GsMode);
Expand Down
20 changes: 10 additions & 10 deletions source/game/portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

DVLB_s* portalDvlb;
shaderProgram_s portalProgram;
extern u32 __linear_heap;
#define portalBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define portalBaseAddr __ctru_linear_heap

portal_s portals[NUM_PORTALS];

Expand Down Expand Up @@ -178,7 +178,7 @@ void GPU_SetScissorTest_(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h)
param[0x1]=0x0000000F;
param[0x2]=0x00000002;
param[0x3]=0x00000002;
GPUCMD_AddIncrementalWrites(GPUREG_0112, param, 0x00000004);
GPUCMD_AddIncrementalWrites(GPUREG_COLORBUFFER_READ, param, 0x00000004);
}

void getPortalBoundingBox(portal_s* p, camera_s* c, vect3Di_s* topleft, vect3Di_s* bottomright, float* depth)
Expand Down Expand Up @@ -282,7 +282,7 @@ void drawPortals(portal_s* portals[], int n, renderSceneCallback_t callback, cam

gsUpdateTransformation();

GPU_DrawArray(GPU_TRIANGLE_STRIP, portalNumVertices);
GPU_DrawArray(GPU_TRIANGLE_STRIP, 0, portalNumVertices);
gsPopMatrix();
}

Expand All @@ -295,10 +295,10 @@ void drawPortals(portal_s* portals[], int n, renderSceneCallback_t callback, cam
0xFFFFFFFF);

GPU_SetFloatUniform(GPU_VERTEX_SHADER, colorUniformLoc, (u32*)(float[]){1.0f, 1.0f, 1.0f, 1.0f}, 1);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)portalVertexData-portalBaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_OFFSET, (u32)portalVertexData-portalBaseAddr);

GPU_SetDepthTestAndWriteMask(true, GPU_GEQUAL, GPU_WRITE_COLOR);
GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_XOR);
GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_INVERT);

for(i=0; i<n; i++)
{
Expand All @@ -315,15 +315,15 @@ void drawPortals(portal_s* portals[], int n, renderSceneCallback_t callback, cam

gsUpdateTransformation();

GPU_DrawArray(GPU_TRIANGLE_STRIP, portalNumVertices);
GPU_DrawArray(GPU_TRIANGLE_STRIP, 0, portalNumVertices);
gsPopMatrix();
}

shaderInstanceSetBool(portalProgram.vertexShader, 0, false);
GPUCMD_AddWrite(GPUREG_VSH_BOOLUNIFORM, 0x7FFF0000|portalProgram.vertexShader->boolUniforms);

GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_DEPTH);
GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP);
GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);

for(i=0; i<n; i++)
{
Expand All @@ -340,14 +340,14 @@ void drawPortals(portal_s* portals[], int n, renderSceneCallback_t callback, cam

gsUpdateTransformation();

GPU_DrawArray(GPU_TRIANGLE_STRIP, portalNumVertices);
GPU_DrawArray(GPU_TRIANGLE_STRIP, 0, portalNumVertices);
gsPopMatrix();
}

gsPopMatrix();

GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL);
GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP);
GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);

for(i=0; i<n; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions source/game/room.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

DVLB_s* roomDvlb;
shaderProgram_s roomProgram;
extern u32 __linear_heap;
#define roomBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define roomBaseAddr __ctru_linear_heap

int roomUniformTextureDimensions;

Expand Down Expand Up @@ -663,7 +663,7 @@ void drawRoom(room_s* r)
textureBind(r->indexBufferTextures[i], GPU_TEXUNIT0);
textureBind(r->lightingData.data.lightMap.texture, GPU_TEXUNIT1);
GPU_SetFloatUniform(GPU_VERTEX_SHADER, roomUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f / r->indexBufferTextures[i]->height, 1.0f / r->indexBufferTextures[i]->width}, 1);
GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)r->indexBuffers[i]-roomBaseAddr), r->numIndices[i]);
GPU_DrawElements(GPU_GEOMETRY_PRIM, (u32*)((u32)r->indexBuffers[i]-roomBaseAddr), r->numIndices[i]);
}

GPU_SetTextureEnable(GPU_TEXUNIT0);
Expand Down
6 changes: 3 additions & 3 deletions source/game/sludge.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int sludgeAnimationCounter=0;

extern shaderProgram_s roomProgram;
extern int roomUniformTextureDimensions;
extern u32 __linear_heap;
#define roomBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define roomBaseAddr __ctru_linear_heap

void drawSludge(room_s* r)
{
Expand Down Expand Up @@ -133,7 +133,7 @@ void drawSludge(room_s* r)

textureBind(&sludgeTexture, GPU_TEXUNIT0);
GPU_SetFloatUniform(GPU_VERTEX_SHADER, roomUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f / sludgeTexture.height, 1.0f / sludgeTexture.width}, 1);
GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)sludgeIndexBuffer-roomBaseAddr), sludgeNumIndices);
GPU_DrawElements(GPU_GEOMETRY_PRIM, (u32*)((u32)sludgeIndexBuffer-roomBaseAddr), sludgeNumIndices);

gsPopMatrix();
}
Expand Down
37 changes: 19 additions & 18 deletions source/gfx/gs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <malloc.h>
#include <3ds.h>
//#include <3ds/gpu/gx.h>

#include "gfx/gs.h"
#include "utils/math.h"
Expand Down Expand Up @@ -517,7 +518,7 @@ int gsVboPrecomputeCommands(gsVbo_s* vbo)
GPUCMD_SetBuffer(tmpBuffer, 128, 0);

// GPU_DrawArrayDirectly(GPU_TRIANGLES, vbo->data, vbo->numVertices);
GPU_DrawArrayDirectly(GPU_UNKPRIM, vbo->data, vbo->numVertices);
GPU_DrawArrayDirectly(GPU_GEOMETRY_PRIM, vbo->data, vbo->numVertices);

GPUCMD_GetBuffer(NULL, NULL, &vbo->commandsSize);
vbo->commands=memalign(0x4, vbo->commandsSize*4);
Expand Down Expand Up @@ -568,7 +569,7 @@ int gsVboDraw(gsVbo_s* vbo)
}

extern Handle gspEventThread;
extern Handle gspEvents[GSPEVENT_MAX];
extern Handle gspEvents[GSPGPU_EVENT_MAX];

//stolen from blargsnes
void gsSafeWait(Handle evt)
Expand Down Expand Up @@ -609,47 +610,47 @@ void gsDrawFrame()
{mtx44 m; loadIdentity44((float*)m); translateMatrix((float*)m, interaxial*0.5f, 0.0f, 0.0f); gsAdjustBufferMatrices(m);}

//draw left framebuffer
GPUCMD_FlushAndRun(NULL);
GPUCMD_FlushAndRun();

//while GPU starts drawing the left buffer, adjust right one for 3D !
GPUCMD_SetBuffer(gsGpuCmdRight, gsGpuCmdSize, offset);
{mtx44 m; loadIdentity44((float*)m); translateMatrix((float*)m, -interaxial*0.5f, 0.0f, 0.0f); gsAdjustBufferMatrices(m);}

//we wait for the left buffer to finish drawing
gsSafeWait(gspEvents[GSPEVENT_P3D]);
GX_SetDisplayTransfer(NULL, (u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPEVENT_PPF]);
gsSafeWait(gspEvents[GSPGPU_EVENT_P3D]);
GX_DisplayTransfer((u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPGPU_EVENT_PPF]);

//we draw the right buffer, wait for it to finish and then switch back to left one
//clear the screen
GX_SetMemoryFill(NULL, (u32*)gsGpuOut, gsBackgroundColor, (u32*)&gsGpuOut[0x2EE00], 0x201, (u32*)gsGpuDOut, 0x00000000, (u32*)&gsGpuDOut[0x2EE00], 0x201);
gsSafeWait(gspEvents[GSPEVENT_PSC0]);
GX_MemoryFill((u32*)gsGpuOut, gsBackgroundColor, (u32*)&gsGpuOut[0x2EE00], 0x201, (u32*)gsGpuDOut, 0x00000000, (u32*)&gsGpuDOut[0x2EE00], 0x201);
gsSafeWait(gspEvents[GSPGPU_EVENT_PSC0]);

//draw the right framebuffer
GPUCMD_FlushAndRun(NULL);
gsSafeWait(gspEvents[GSPEVENT_P3D]);
GPUCMD_FlushAndRun();
gsSafeWait(gspEvents[GSPGPU_EVENT_P3D]);

//transfer from GPU output buffer to actual framebuffer
GX_SetDisplayTransfer(NULL, (u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPEVENT_PPF]);
GX_DisplayTransfer((u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPGPU_EVENT_PPF]);
GPUCMD_SetBuffer(gsGpuCmd, gsGpuCmdSize, 0);
}else{
//boring old 2D !

//draw the frame
GPUCMD_FlushAndRun(NULL);
gsSafeWait(gspEvents[GSPEVENT_P3D]);
GPUCMD_FlushAndRun();
gsSafeWait(gspEvents[GSPGPU_EVENT_P3D]);

//transfer from GPU output buffer to actual framebuffer
GX_SetDisplayTransfer(NULL, (u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPEVENT_PPF]);
GX_DisplayTransfer((u32*)gsGpuOut, 0x019000F0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019000F0, 0x00001000);
gsSafeWait(gspEvents[GSPGPU_EVENT_PPF]);
}

gsDrawBottom(NULL, NULL);

//clear the screen
GX_SetMemoryFill(NULL, (u32*)gsGpuOut, gsBackgroundColor, (u32*)&gsGpuOut[0x2EE00], 0x201, (u32*)gsGpuDOut, 0x00000000, (u32*)&gsGpuDOut[0x2EE00], 0x201);
gsSafeWait(gspEvents[GSPEVENT_PSC0]);
GX_MemoryFill((u32*)gsGpuOut, gsBackgroundColor, (u32*)&gsGpuOut[0x2EE00], 0x201, (u32*)gsGpuDOut, 0x00000000, (u32*)&gsGpuDOut[0x2EE00], 0x201);
gsSafeWait(gspEvents[GSPGPU_EVENT_PSC0]);
gfxSwapBuffersGpu();

}
Expand Down
12 changes: 6 additions & 6 deletions source/gfx/md2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ u8 normalPermutation[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,

DVLB_s* md2Dvlb;
shaderProgram_s md2Program;
extern u32 __linear_heap;
#define md2BaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define md2BaseAddr __ctru_linear_heap

int md2UniformScale0;
int md2UniformTranslation0;
Expand Down Expand Up @@ -324,11 +324,11 @@ void md2RenderFrame(md2_model_t *mdl, int n1, int n2, float interp, float alpha,

textureBind(t, GPU_TEXUNIT0);

GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)mdl->frames[n1].verts-md2BaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER1_CONFIG0, (u32)mdl->frames[n2].verts-md2BaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER2_CONFIG0, (u32)mdl->texcoords-md2BaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_OFFSET, (u32)mdl->frames[n1].verts-md2BaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER1_OFFSET, (u32)mdl->frames[n2].verts-md2BaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER2_OFFSET, (u32)mdl->texcoords-md2BaseAddr);

GPU_DrawElements(GPU_UNKPRIM, (u32*)((u32)mdl->indices-md2BaseAddr), mdl->header.num_tris*3);
GPU_DrawElements(GPU_GEOMETRY_PRIM, (u32*)((u32)mdl->indices-md2BaseAddr), mdl->header.num_tris*3);
}

void md2InstanceInit(md2_instance_t* mi, md2_model_t* mdl, texture_s* t)
Expand Down
8 changes: 4 additions & 4 deletions source/gfx/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
DVLB_s* textDvlb;
shaderProgram_s textProgram;
texture_s textTexture;
extern u32 __linear_heap;
#define textBaseAddr __linear_heap
extern u32 __ctru_linear_heap;
#define textBaseAddr __ctru_linear_heap

int textUniformOffset;

Expand Down Expand Up @@ -80,9 +80,9 @@ void textDrawString(float x, float y, const char* s)
if(!s)return;
if((u32)s < textBaseAddr)return;

GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)s-textBaseAddr);
GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_OFFSET, (u32)s-textBaseAddr);

GPU_SetFloatUniform(GPU_GEOMETRY_SHADER, textUniformOffset, (u32*)(float[]){1.0f, 0.0f, x, y}, 1);

GPU_DrawArray(GPU_UNKPRIM, strlen(s));
GPU_DrawArray(GPU_GEOMETRY_PRIM, 0, strlen(s));
}
2 changes: 1 addition & 1 deletion source/gfx/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void textureBind(texture_s* t, GPU_TEXUNIT unit)
if(!t)return;

GPU_SetTexture(unit, (u32*)osConvertVirtToPhys((u32)t->data), t->width, t->height, t->param, t->format);
GPUCMD_AddWrite(GPUREG_0084, t->mipmap<<16);
GPUCMD_AddWrite(GPUREG_TEXUNIT0_LOD, t->mipmap<<16);
}

void textureFree(texture_s* t)
Expand Down
13 changes: 7 additions & 6 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <malloc.h>
#include <math.h>
#include <3ds.h>
//#include <3ds/services/gsp.h>

#include "gfx/gs.h"
#include "gfx/text.h"
Expand Down Expand Up @@ -104,12 +105,12 @@ void renderFrame(u32* outBuffer, u32* outDepthBuffer)
GPU_DepthMap(-1.0f, 0.0f);
GPU_SetFaceCulling(GPU_CULL_FRONT_CCW);
GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00);
GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP);
GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);
GPU_SetBlendingColor(0,0,0,0);
GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL);

GPUCMD_AddMaskedWrite(GPUREG_0062, 0x1, 0);
GPUCMD_AddWrite(GPUREG_0118, 0);
GPUCMD_AddMaskedWrite(GPUREG_EARLYDEPTH_TEST1, 0x1, 0);
GPUCMD_AddWrite(GPUREG_EARLYDEPTH_TEST2, 0);

GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA);
GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00);
Expand Down Expand Up @@ -344,7 +345,7 @@ bool gameFrame()

gsDrawFrame();

gspWaitForEvent(GSPEVENT_VBlank0, true);
gspWaitForEvent(GSPGPU_EVENT_VBlank0, true);

return false;
}
Expand Down Expand Up @@ -378,7 +379,7 @@ int main(int argc, char** argv)
gfxSet3D(true);

aptOpenSession();
APT_SetAppCpuTimeLimit(NULL, 30);
APT_SetAppCpuTimeLimit(30);
aptCloseSession();

//init fs
Expand Down Expand Up @@ -440,7 +441,7 @@ int main(int argc, char** argv)
}

aptOpenSession();
APT_SetAppCpuTimeLimit(NULL, 0);
APT_SetAppCpuTimeLimit(0);
aptCloseSession();

gfxExit();
Expand Down
Loading