mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-05 03:24:17 +01:00
Add gx2 triangle hello world.
Shader assembled using the latte-assembler tool in decaf-emu repo.
This commit is contained in:
parent
2cb787fabf
commit
bf4ddae73d
@ -1,5 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(wut-samples)
|
||||
project(samples)
|
||||
|
||||
add_subdirectory(helloworld)
|
||||
add_subdirectory(pong)
|
||||
add_subdirectory(gx2)
|
||||
|
4
samples/gx2/CMakeLists.txt
Normal file
4
samples/gx2/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(samples-gx2)
|
||||
|
||||
add_subdirectory(triangle)
|
BIN
samples/gx2/content/pos_col_shader.gsh
Normal file
BIN
samples/gx2/content/pos_col_shader.gsh
Normal file
Binary file not shown.
9
samples/gx2/content/pos_col_shader.psh
Normal file
9
samples/gx2/content/pos_col_shader.psh
Normal file
@ -0,0 +1,9 @@
|
||||
; $MODE = "UniformRegister"
|
||||
; $SQ_PGM_RESOURCES_PS.NUM_GPRS = 1
|
||||
; $SPI_PS_IN_CONTROL_0.NUM_INTERP = 1
|
||||
; $NUM_SPI_PS_INPUT_CNTL = 1
|
||||
; $SPI_PS_INPUT_CNTL[0].SEMANTIC = 0
|
||||
; $SPI_PS_INPUT_CNTL[0].DEFAULT_VAL = 1
|
||||
|
||||
00 EXP_DONE: PIX0, R0.xyzw
|
||||
END_OF_PROGRAM
|
22
samples/gx2/content/pos_col_shader.vsh
Normal file
22
samples/gx2/content/pos_col_shader.vsh
Normal file
@ -0,0 +1,22 @@
|
||||
; $MODE = "UniformRegister"
|
||||
; $ATTRIB_VARS[0].name = "aColour"
|
||||
; $ATTRIB_VARS[0].type = "Float4"
|
||||
; $ATTRIB_VARS[0].location = 0
|
||||
; $ATTRIB_VARS[1].name = "aPosition"
|
||||
; $ATTRIB_VARS[1].type = "Float4"
|
||||
; $ATTRIB_VARS[1].location = 1
|
||||
; $SQ_PGM_RESOURCES_VS.NUM_GPRS = 3
|
||||
; $SQ_PGM_RESOURCES_VS.STACK_SIZE = 1
|
||||
; $NUM_SPI_VS_OUT_ID = 1
|
||||
; $SPI_VS_OUT_ID[0].SEMANTIC_0 = 0
|
||||
; $SQ_VTX_SEMANTIC_CLEAR.CLEAR = 0xFFFFFFFC
|
||||
; $NUM_SQ_VTX_SEMANTIC = 2
|
||||
; $SQ_VTX_SEMANTIC[0].SEMANTIC_ID = 0
|
||||
; $SQ_VTX_SEMANTIC[1].SEMANTIC_ID = 1
|
||||
; $VGT_VERTEX_REUSE_BLOCK_CNTL.VTX_REUSE_DEPTH = 14
|
||||
; $VGT_HOS_REUSE_DEPTH.REUSE_DEPTH = 16
|
||||
|
||||
00 CALL_FS NO_BARRIER
|
||||
01 EXP_DONE: POS0, R2.xyzw
|
||||
02 EXP_DONE: PARAM0, R1.xyzw NO_BARRIER
|
||||
END_OF_PROGRAM
|
14
samples/gx2/triangle/CMakeLists.txt
Normal file
14
samples/gx2/triangle/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(samples-gx2-triangle)
|
||||
|
||||
file(GLOB_RECURSE SOURCE_FILES src/*.c)
|
||||
file(GLOB_RECURSE HEADER_FILES src/*.h)
|
||||
|
||||
add_rpx_lite(triangle ${SOURCE_FILES} ${HEADER_FILES})
|
||||
target_link_libraries(triangle
|
||||
whb
|
||||
coreinit
|
||||
defaultheap
|
||||
gx2
|
||||
gfd
|
||||
proc_ui)
|
92
samples/gx2/triangle/src/main.c
Normal file
92
samples/gx2/triangle/src/main.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <gfd.h>
|
||||
#include <defaultheap.h>
|
||||
#include <gx2/draw.h>
|
||||
#include <gx2/shaders.h>
|
||||
#include <gx2r/buffer.h>
|
||||
#include <string.h>
|
||||
#include <whb/file.h>
|
||||
#include <whb/gfx.h>
|
||||
#include <whb/proc.h>
|
||||
|
||||
static const float sPositionData[] =
|
||||
{
|
||||
0.0f, -0.5f, 0.0f,
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f
|
||||
};
|
||||
|
||||
static const float sColourData[] =
|
||||
{
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
GX2RBuffer positionBuffer = { 0 };
|
||||
GX2RBuffer colourBuffer = { 0 };
|
||||
WHBGfxShaderGroup group = { 0 };
|
||||
void *buffer = NULL;
|
||||
char *gshFileData = NULL;
|
||||
|
||||
WHBProcInit();
|
||||
WHBGfxInit();
|
||||
|
||||
gshFileData = WHBReadWholeFile("pos_col_shader.gsh", NULL);
|
||||
|
||||
if (!WHBGfxLoadGFDShaderGroup(&group, 0, gshFileData)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
WHBGfxInitShaderAttribute(&group, "aPosition", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
WHBGfxInitShaderAttribute(&group, "aColour", 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
WHBGfxInitFetchShader(&group);
|
||||
|
||||
WHBFreeWholeFile(gshFileData);
|
||||
gshFileData = NULL;
|
||||
|
||||
positionBuffer.flags = GX2R_RESOURCE_BIND_VERTEX_BUFFER | GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ;
|
||||
positionBuffer.elemSize = 4 * 3;
|
||||
positionBuffer.elemCount = 3;
|
||||
GX2RCreateBuffer(&positionBuffer);
|
||||
buffer = GX2RLockBufferEx(&positionBuffer, 0);
|
||||
memcpy(buffer, sPositionData, 4 * 3 * 3);
|
||||
GX2RUnlockBufferEx(&positionBuffer, 0);
|
||||
|
||||
colourBuffer.flags = GX2R_RESOURCE_BIND_VERTEX_BUFFER | GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ;
|
||||
colourBuffer.elemSize = 4 * 3;
|
||||
colourBuffer.elemCount = 3;
|
||||
GX2RCreateBuffer(&colourBuffer);
|
||||
buffer = GX2RLockBufferEx(&colourBuffer, 0);
|
||||
memcpy(buffer, sColourData, 4 * 3 * 3);
|
||||
GX2RUnlockBufferEx(&colourBuffer, 0);
|
||||
|
||||
while(WHBProcIsRunning()) {
|
||||
WHBGfxBeginRender();
|
||||
|
||||
WHBGfxBeginRenderTV();
|
||||
GX2SetFetchShader(&group.fetchShader);
|
||||
GX2SetVertexShader(group.vertexShader);
|
||||
GX2SetPixelShader(group.pixelShader);
|
||||
GX2RSetAttributeBuffer(&positionBuffer, 0, positionBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&colourBuffer, 1, colourBuffer.elemSize, 0);
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 3, 0, 1);
|
||||
WHBGfxFinishRenderTV();
|
||||
|
||||
WHBGfxBeginRenderDRC();
|
||||
GX2SetFetchShader(&group.fetchShader);
|
||||
GX2SetVertexShader(group.vertexShader);
|
||||
GX2SetPixelShader(group.pixelShader);
|
||||
GX2RSetAttributeBuffer(&positionBuffer, 0, positionBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&colourBuffer, 1, colourBuffer.elemSize, 0);
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 3, 0, 1);
|
||||
WHBGfxFinishRenderDRC();
|
||||
|
||||
WHBGfxFinishRender();
|
||||
}
|
||||
|
||||
WHBGfxShutdown();
|
||||
WHBProcShutdown();
|
||||
return 0;
|
||||
}
|
@ -7,36 +7,28 @@
|
||||
|
||||
bool isAppRunning = true;
|
||||
|
||||
void
|
||||
static void
|
||||
SaveCallback()
|
||||
{
|
||||
OSSavesDone_ReadyToRelease(); // Required
|
||||
}
|
||||
|
||||
bool
|
||||
static bool
|
||||
AppRunning()
|
||||
{
|
||||
if(!OSIsMainCore())
|
||||
{
|
||||
if (!OSIsMainCore()) {
|
||||
ProcUISubProcessMessages(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ProcUIStatus status = ProcUIProcessMessages(true);
|
||||
|
||||
if(status == PROCUI_STATUS_EXITING)
|
||||
{
|
||||
|
||||
if (status == PROCUI_STATUS_EXITING) {
|
||||
// Being closed, deinit, free, and prepare to exit
|
||||
isAppRunning = false;
|
||||
ProcUIShutdown();
|
||||
}
|
||||
else if(status == PROCUI_STATUS_RELEASE_FOREGROUND)
|
||||
{
|
||||
} else if (status == PROCUI_STATUS_RELEASE_FOREGROUND) {
|
||||
// Free up MEM1 to next foreground app, deinit screen, etc.
|
||||
ProcUIDrawDoneRelease();
|
||||
}
|
||||
else if(status == PROCUI_STATUS_IN_FOREGROUND)
|
||||
{
|
||||
} else if(status == PROCUI_STATUS_IN_FOREGROUND) {
|
||||
// Executed while app is in foreground
|
||||
}
|
||||
}
|
||||
@ -44,7 +36,7 @@ AppRunning()
|
||||
return isAppRunning;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
CoreEntryPoint(int argc, const char **argv)
|
||||
{
|
||||
OSReport("Hello world from %s", argv[0]);
|
||||
@ -82,11 +74,11 @@ main(int argc, char **argv)
|
||||
|
||||
OSReport("Core 0 thread returned %d", resultCore0);
|
||||
OSReport("Core 2 thread returned %d", resultCore2);
|
||||
|
||||
|
||||
// Sends messages for ProcUI to release foreground, exit
|
||||
// and launch into the system menu immediately.
|
||||
SYSLaunchMenu();
|
||||
|
||||
|
||||
while(AppRunning());
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user