mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-05 03:04:16 +01:00
Update triangle sample.
Still doesn't render correctly on hardware - will lead to the GPU hanging, maybe something wrong with our custom compiled shader.
This commit is contained in:
parent
43e1b0ab4f
commit
11940e076c
@ -2,24 +2,33 @@
|
||||
#include <defaultheap.h>
|
||||
#include <gx2/draw.h>
|
||||
#include <gx2/shaders.h>
|
||||
#include <gx2r/draw.h>
|
||||
#include <gx2r/buffer.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <whb/file.h>
|
||||
#include <whb/gfx.h>
|
||||
#include <whb/proc.h>
|
||||
#include <whb/sdcard.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
#include <coreinit/systeminfo.h>
|
||||
#include <coreinit/thread.h>
|
||||
#include <coreinit/time.h>
|
||||
|
||||
static const float sPositionData[] =
|
||||
{
|
||||
0.0f, -0.5f, 0.0f,
|
||||
-0.5f, 0.5f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f
|
||||
0.0f, -0.5f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f, 0.0f
|
||||
};
|
||||
|
||||
static const float sColourData[] =
|
||||
{
|
||||
1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -29,48 +38,62 @@ int main(int argc, char **argv)
|
||||
WHBGfxShaderGroup group = { 0 };
|
||||
void *buffer = NULL;
|
||||
char *gshFileData = NULL;
|
||||
char *sdRootPath = NULL;
|
||||
char path[256];
|
||||
int result = 0;
|
||||
|
||||
WHBProcInit();
|
||||
WHBLogUdpInit();
|
||||
WHBProcInit(TRUE);
|
||||
WHBGfxInit();
|
||||
|
||||
gshFileData = WHBReadWholeFile("pos_col_shader.gsh", NULL);
|
||||
|
||||
if (!WHBGfxLoadGFDShaderGroup(&group, 0, gshFileData)) {
|
||||
return -1;
|
||||
if (!WHBMountSdCard()) {
|
||||
result = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
WHBGfxInitShaderAttribute(&group, "aPosition", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
WHBGfxInitShaderAttribute(&group, "aColour", 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
|
||||
sdRootPath = WHBGetSdCardMountPath();
|
||||
sprintf(path, "%s/shaders/pos_colour.gsh", sdRootPath);
|
||||
|
||||
gshFileData = WHBReadWholeFile(path, NULL);
|
||||
if (!WHBGfxLoadGFDShaderGroup(&group, 0, gshFileData)) {
|
||||
result = -1;
|
||||
WHBLogPrintf("WHBGfxLoadGFDShaderGroup returned FALSE");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
WHBGfxInitShaderAttribute(&group, "aColour", 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32_32);
|
||||
WHBGfxInitShaderAttribute(&group, "aPosition", 1, 0, GX2_ATTRIB_FORMAT_FLOAT_32_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.elemSize = 4 * 4;
|
||||
positionBuffer.elemCount = 3;
|
||||
GX2RCreateBuffer(&positionBuffer);
|
||||
buffer = GX2RLockBufferEx(&positionBuffer, 0);
|
||||
memcpy(buffer, sPositionData, 4 * 3 * 3);
|
||||
memcpy(buffer, sPositionData, positionBuffer.elemSize * positionBuffer.elemCount);
|
||||
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.elemSize = 4 * 4;
|
||||
colourBuffer.elemCount = 3;
|
||||
GX2RCreateBuffer(&colourBuffer);
|
||||
buffer = GX2RLockBufferEx(&colourBuffer, 0);
|
||||
memcpy(buffer, sColourData, 4 * 3 * 3);
|
||||
memcpy(buffer, sColourData, colourBuffer.elemSize * colourBuffer.elemCount);
|
||||
GX2RUnlockBufferEx(&colourBuffer, 0);
|
||||
|
||||
while(WHBProcIsRunning()) {
|
||||
WHBLogPrintf("Begin rendering...");
|
||||
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);
|
||||
GX2RSetAttributeBuffer(&colourBuffer, 0, colourBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&positionBuffer, 1, positionBuffer.elemSize, 0);
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 3, 0, 1);
|
||||
WHBGfxFinishRenderTV();
|
||||
|
||||
@ -78,15 +101,20 @@ int main(int argc, char **argv)
|
||||
GX2SetFetchShader(&group.fetchShader);
|
||||
GX2SetVertexShader(group.vertexShader);
|
||||
GX2SetPixelShader(group.pixelShader);
|
||||
GX2RSetAttributeBuffer(&positionBuffer, 0, positionBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&colourBuffer, 1, colourBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&colourBuffer, 0, colourBuffer.elemSize, 0);
|
||||
GX2RSetAttributeBuffer(&positionBuffer, 1, positionBuffer.elemSize, 0);
|
||||
GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, 3, 0, 1);
|
||||
WHBGfxFinishRenderDRC();
|
||||
|
||||
WHBGfxFinishRender();
|
||||
}
|
||||
|
||||
exit:
|
||||
WHBLogPrintf("Exiting...");
|
||||
GX2RDestroyBufferEx(&positionBuffer, 0);
|
||||
GX2RDestroyBufferEx(&colourBuffer, 0);
|
||||
//WHBUnmountSdCard(); !! freezes on unmount for unkown reason !!
|
||||
WHBGfxShutdown();
|
||||
WHBProcShutdown();
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user