diff --git a/examples/gputest/source/main.c b/examples/gputest/source/main.c index cdf449e..1e2c558 100644 --- a/examples/gputest/source/main.c +++ b/examples/gputest/source/main.c @@ -10,7 +10,6 @@ #include "test_gsh.shader.h" #include "grass_bin.h" -#define VAR_3D_SLIDERSTATE (*(volatile float*)0x1FF81080) #define EXTENDED_TOPSCR_RESOLUTION #ifndef EXTENDED_TOPSCR_RESOLUTION @@ -37,7 +36,7 @@ typedef struct float color[3]; } vertex_t; -static const vertex_t vertices[] = +static const vertex_t vertex_list[] = { // First triangle {{-0.5f, +0.5f, -4.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, @@ -50,9 +49,11 @@ static const vertex_t vertices[] = {{-0.5f, +0.5f, -4.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, }; +#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) + #define FOVY (2.0f/15) -static C3D_VBO myVbo; +static void* myVbo; static C3D_Tex myTex; static void drawScene(float trX, float trY) @@ -73,7 +74,7 @@ static void drawScene(float trX, float trY) MtxStack_Update(&projMtx); MtxStack_Update(&mdlvMtx); - C3D_DrawArrays(GPU_TRIANGLES, 0, myVbo.vertexCount); + C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); C3D_Flush(); } @@ -96,7 +97,7 @@ static void drawSceneBottom(float trX, float trY) MtxStack_Update(&projMtx); MtxStack_Update(&mdlvMtx); - C3D_DrawArrays(GPU_TRIANGLES, 0, myVbo.vertexCount); + C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); C3D_Flush(); } @@ -144,13 +145,13 @@ int main() AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // vertex color // Configure VBO - C3D_VBOInit(&myVbo, sizeof(vertices)); - C3D_VBOAddData(&myVbo, vertices, sizeof(vertices), sizeof(vertices)/sizeof(vertex_t)); + myVbo = linearAlloc(sizeof(vertex_list)); + memcpy(myVbo, vertex_list, sizeof(vertex_list)); // Configure buffers C3D_BufInfo* bufInfo = C3D_GetBufInfo(); BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, myVbo.data, sizeof(vertex_t), 3, 0x210); + BufInfo_Add(bufInfo, myVbo, sizeof(vertex_t), 3, 0x210); // Clear renderbuffers C3D_RenderBufClear(&rbTop); @@ -184,7 +185,7 @@ int main() if (kHeld & KEY_R) zDist += 0.005f; - float slider = VAR_3D_SLIDERSTATE; + float slider = osGet3DSliderState(); float czDist = zDist*slider/2; drawScene(trX-czDist, trY); diff --git a/include/c3d/base.h b/include/c3d/base.h index f317117..96e2e82 100644 --- a/include/c3d/base.h +++ b/include/c3d/base.h @@ -3,6 +3,12 @@ #include "buffers.h" #define C3D_DEFAULT_CMDBUF_SIZE 0x40000 +enum +{ + C3D_UNSIGNED_BYTE = 0, + C3D_UNSIGNED_SHORT = 1, +}; + bool C3D_Init(size_t cmdBufSize); void C3D_FlushAsync(void); void C3D_Fini(void); diff --git a/include/c3d/buffers.h b/include/c3d/buffers.h index b8c8356..fe49dcb 100644 --- a/include/c3d/buffers.h +++ b/include/c3d/buffers.h @@ -19,35 +19,3 @@ int BufInfo_Add(C3D_BufInfo* info, const void* data, ptrdiff_t stride, int attr C3D_BufInfo* C3D_GetBufInfo(void); void C3D_SetBufInfo(C3D_BufInfo* info); - -typedef struct -{ - void* data; - size_t capacity; - size_t size; - int vertexCount; -} C3D_VBO; - -bool C3D_VBOInit(C3D_VBO* vbo, size_t capacity); -bool C3D_VBOAddData(C3D_VBO* vbo, const void* data, size_t size, int vertexCount); -void C3D_VBOFlush(C3D_VBO* vbo); -void C3D_VBODelete(C3D_VBO* vbo); - -typedef struct -{ - void* data; - int capacity; - int indexCount; - int format; -} C3D_IBO; - -enum -{ - C3D_UNSIGNED_BYTE = 0, - C3D_UNSIGNED_SHORT = 1, -}; - -bool C3D_IBOInit(C3D_IBO* ibo, int capacity, int format); -bool C3D_IBOAddData(C3D_IBO* ibo, const void* data, int indexCount); -void C3D_IBOFlush(C3D_IBO* ibo); -void C3D_IBODelete(C3D_IBO* ibo); diff --git a/source/ibo.c b/source/ibo.c deleted file mode 100644 index eb4afc5..0000000 --- a/source/ibo.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include "context.h" - -bool C3D_IBOCreate(C3D_IBO* ibo, int capacity, int format) -{ - if (ibo->data) return false; - - ibo->data = linearAlloc(capacity * (format+1)); - if (!ibo->data) return false; - ibo->capacity = capacity; - ibo->indexCount = 0; - ibo->format = format; - return true; -} - -bool C3D_IBOAddData(C3D_IBO* ibo, const void* data, int indexCount) -{ - int remaining = ibo->capacity - ibo->indexCount; - if (remaining < indexCount) return false; - int stride = ibo->format+1; - memcpy((u8*)ibo->data + ibo->indexCount*stride, data, indexCount*stride); - ibo->indexCount += indexCount; - return true; -} - -void C3D_IBOFlush(C3D_IBO* ibo) -{ - int stride = ibo->format+1; - GSPGPU_FlushDataCache(ibo->data, ibo->indexCount*stride); -} - -void C3D_IBODelete(C3D_IBO* ibo) -{ - if (!ibo->data) return; - linearFree(ibo->data); - ibo->data = NULL; -} diff --git a/source/vbo.c b/source/vbo.c deleted file mode 100644 index c7608ef..0000000 --- a/source/vbo.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include "context.h" - -bool C3D_VBOInit(C3D_VBO* vbo, size_t capacity) -{ - if (vbo->data) return false; - - vbo->data = linearAlloc(capacity); - if (!vbo->data) return false; - vbo->capacity = capacity; - vbo->size = 0; - vbo->vertexCount = 0; - return true; -} - -bool C3D_VBOAddData(C3D_VBO* vbo, const void* data, size_t size, int vertexCount) -{ - size_t remaining = vbo->capacity - vbo->size; - if (remaining < size) return false; - memcpy((u8*)vbo->data + vbo->size, data, size); - vbo->size += size; - vbo->vertexCount += vertexCount; - return true; -} - -void C3D_VBOFlush(C3D_VBO* vbo) -{ - if (vbo->data) - GSPGPU_FlushDataCache(vbo->data, vbo->size); -} - -void C3D_VBODelete(C3D_VBO* vbo) -{ - if (!vbo->data) return; - linearFree(vbo->data); - vbo->data = NULL; -}