diff --git a/src/render/wiiu/SDL_rdraw_wiiu.c b/src/render/wiiu/SDL_rdraw_wiiu.c index 6c0e8f9e4..d2fbb52d8 100644 --- a/src/render/wiiu/SDL_rdraw_wiiu.c +++ b/src/render/wiiu/SDL_rdraw_wiiu.c @@ -46,6 +46,8 @@ #include #include +static void WIIU_SDL_SetGX2BlendMode(SDL_BlendMode mode); + int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { @@ -53,6 +55,7 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata; float *a_position = WIIU_AllocRenderData(data, sizeof(float) * 8); float *a_texCoord = WIIU_AllocRenderData(data, sizeof(float) * 8); + float *u_mod = WIIU_AllocRenderData(data, sizeof(float) * 4); /* Compute vertex points */ float x_min = renderer->viewport.x + dstrect->x; @@ -72,6 +75,12 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, a_texCoord[6] = srcrect->x; a_texCoord[7] = srcrect->y; GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, a_texCoord, sizeof(float) * 8); + /* Compute color/alpha mod */ + u_mod[0] = (float)texture->r / 255.0f; + u_mod[1] = (float)texture->g / 255.0f; + u_mod[2] = (float)texture->b / 255.0f; + u_mod[3] = (float)texture->a / 255.0f; + /* Render */ GX2SetContextState(data->ctx); wiiuSetTextureShader(); @@ -81,6 +90,8 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, GX2SetAttribBuffer(1, sizeof(float) * 8, sizeof(float) * 2, a_texCoord); GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)data->u_viewSize); GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[1].offset, 4, (uint32_t *)tdata->u_texSize); + GX2SetPixelUniformReg(wiiuTextureShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_mod); + WIIU_SDL_SetGX2BlendMode(texture->blendMode); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1); return 0; @@ -95,6 +106,7 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata; float *a_position = WIIU_AllocRenderData(data, sizeof(float) * 8); float *a_texCoord = WIIU_AllocRenderData(data, sizeof(float) * 8); + float *u_mod = WIIU_AllocRenderData(data, sizeof(float) * 4); /* Compute real vertex points */ float x_min = renderer->viewport.x + dstrect->x; @@ -123,6 +135,12 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, a_texCoord[6] = srcrect->x; a_texCoord[7] = srcrect->y; GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, a_texCoord, sizeof(float) * 8); + /* Compute color/alpha mod */ + u_mod[0] = (float)texture->r / 255.0f; + u_mod[1] = (float)texture->g / 255.0f; + u_mod[2] = (float)texture->b / 255.0f; + u_mod[3] = (float)texture->a / 255.0f; + /* Render */ GX2SetContextState(data->ctx); wiiuSetTextureShader(); @@ -132,6 +150,8 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, GX2SetAttribBuffer(1, sizeof(float) * 8, sizeof(float) * 2, a_texCoord); GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)data->u_viewSize); GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[1].offset, 4, (uint32_t *)tdata->u_texSize); + GX2SetPixelUniformReg(wiiuTextureShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_mod); + WIIU_SDL_SetGX2BlendMode(texture->blendMode); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1); return 0; @@ -162,6 +182,7 @@ int WIIU_SDL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points GX2SetAttribBuffer(0, sizeof(float) * 2 * count, sizeof(float) * 2, a_position); GX2SetVertexUniformReg(wiiuColorShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)data->u_viewSize); GX2SetPixelUniformReg(wiiuColorShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_color); + WIIU_SDL_SetGX2BlendMode(SDL_BLENDMODE_BLEND); GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, count, 0, 1); return 0; @@ -193,6 +214,7 @@ int WIIU_SDL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, GX2SetAttribBuffer(0, sizeof(float) * 2 * count, sizeof(float) * 2, a_position); GX2SetVertexUniformReg(wiiuColorShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)data->u_viewSize); GX2SetPixelUniformReg(wiiuColorShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_color); + WIIU_SDL_SetGX2BlendMode(SDL_BLENDMODE_BLEND); GX2DrawEx(GX2_PRIMITIVE_MODE_LINE_STRIP, count, 0, 1); return 0; @@ -231,6 +253,7 @@ int WIIU_SDL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, i GX2SetAttribBuffer(0, sizeof(float) * 8 * count, sizeof(float) * 2, a_position); GX2SetVertexUniformReg(wiiuColorShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)data->u_viewSize); GX2SetPixelUniformReg(wiiuColorShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_color); + WIIU_SDL_SetGX2BlendMode(SDL_BLENDMODE_BLEND); GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4 * count, 0, 1); return 0; @@ -263,4 +286,28 @@ int WIIU_SDL_RenderClear(SDL_Renderer * renderer) return 0; } +static void WIIU_SDL_SetGX2BlendMode(SDL_BlendMode mode) { + if (mode == SDL_BLENDMODE_NONE) { + GX2SetColorControl(GX2_LOGIC_OP_COPY, 0x00, FALSE, TRUE); + } else if (mode == SDL_BLENDMODE_BLEND || mode == SDL_BLENDMODE_MOD) { + GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, FALSE, TRUE); + GX2SetBlendControl(GX2_RENDER_TARGET_0, + /* Not sure this is correct - ALPHA, not COLOR? */ + GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_DST_ALPHA, + GX2_BLEND_COMBINE_MODE_ADD, + TRUE, + GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_DST_ALPHA, + GX2_BLEND_COMBINE_MODE_ADD); + } else if (mode == SDL_BLENDMODE_ADD) { + GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, FALSE, TRUE); + GX2SetBlendControl(GX2_RENDER_TARGET_0, + GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_DST_ALPHA, + GX2_BLEND_COMBINE_MODE_ADD, + TRUE, + GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_DST_ALPHA, + GX2_BLEND_COMBINE_MODE_ADD); + } +/* TODO: SDL_BLENDMODE_MOD support */ +} + #endif //SDL_VIDEO_RENDER_WIIU diff --git a/src/render/wiiu/SDL_render_wiiu.c b/src/render/wiiu/SDL_render_wiiu.c index b40da5a06..171d87d06 100644 --- a/src/render/wiiu/SDL_render_wiiu.c +++ b/src/render/wiiu/SDL_render_wiiu.c @@ -153,7 +153,6 @@ int WIIU_SDL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture) GX2SetAlphaTest(TRUE, GX2_COMPARE_FUNC_GREATER, 0.0f); GX2SetDepthOnlyControl(FALSE, FALSE, GX2_COMPARE_FUNC_NEVER); GX2SetColorControl(GX2_LOGIC_OP_COPY, 0xFF, FALSE, TRUE); - GX2SetBlendControl(GX2_RENDER_TARGET_0, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD, TRUE, GX2_BLEND_MODE_SRC_ALPHA, GX2_BLEND_MODE_INV_SRC_ALPHA, GX2_BLEND_COMBINE_MODE_ADD); GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, FALSE, FALSE); return 0; diff --git a/src/video/wiiu/SDL_wiiuvideo.c b/src/video/wiiu/SDL_wiiuvideo.c index 4f4d9f128..6a8392de7 100644 --- a/src/video/wiiu/SDL_wiiuvideo.c +++ b/src/video/wiiu/SDL_wiiuvideo.c @@ -62,6 +62,7 @@ static void WIIU_DestroyWindowFramebuffer(_THIS, SDL_Window *window); static const float u_viewSize[4] = {(float)SCREEN_WIDTH, (float)SCREEN_HEIGHT}; static const float u_texSize[4] = {(float)SCREEN_WIDTH, (float)SCREEN_HEIGHT}; +static const float u_mod[4] = {1.0f, 1.0f, 1.0f, 1.0f}; static const float tex_coord_vb[] = { @@ -183,8 +184,10 @@ static int WIIU_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *forma static void render_scene(WIIU_WindowData *data) { WHBGfxClearColor(0.0f, 0.0f, 0.0f, 1.0f); wiiuSetTextureShader(); + GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[0].offset, 4, (uint32_t *)u_viewSize); GX2SetVertexUniformReg(wiiuTextureShader.vertexShader->uniformVars[1].offset, 4, (uint32_t *)u_texSize); + GX2SetPixelUniformReg(wiiuTextureShader.pixelShader->uniformVars[0].offset, 4, (uint32_t*)u_mod); GX2RSetAttributeBuffer(&position_buffer, 0, position_buffer.elemSize, 0); GX2RSetAttributeBuffer(&tex_coord_buffer, 1, tex_coord_buffer.elemSize, 0); diff --git a/src/video/wiiu/shaders/textureShader.frag b/src/video/wiiu/shaders/textureShader.frag index 0c9703e02..502f7aafa 100644 --- a/src/video/wiiu/shaders/textureShader.frag +++ b/src/video/wiiu/shaders/textureShader.frag @@ -1,5 +1,7 @@ /* textureShader: fragment (pixel) shader (GLSL) */ /* compile with ShaderAnalyzer (rv770) + fix latte-assembler messages */ +/* NOTE: Ash knows R600 but not GLSL, so the .psh may have changes not in this + file. */ layout(location = 0) uniform sampler2D s_texture; /* texture sampler */ in vec2 texCoord; /* relative texture postion passed from vertex shader */ diff --git a/src/video/wiiu/shaders/textureShader.psh b/src/video/wiiu/shaders/textureShader.psh index 143e77137..faca2f53e 100644 --- a/src/video/wiiu/shaders/textureShader.psh +++ b/src/video/wiiu/shaders/textureShader.psh @@ -5,8 +5,18 @@ ; $NUM_SPI_PS_INPUT_CNTL = 1 ; $SPI_PS_INPUT_CNTL[0].semantic = 0 ; $SPI_PS_INPUT_CNTL[0].default_val = 1 +; $UNIFORM_VARS[0].name = "u_mod" +; $UNIFORM_VARS[0].type = "float4" +; $UNIFORM_VARS[0].count = 1 +; $UNIFORM_VARS[0].offset = 0 +; $UNIFORM_VARS[0].block = -1 -00 TEX: ADDR(32) CNT(1) VALID_PIX +00 TEX: ADDR(48) CNT(1) VALID_PIX 0 SAMPLE R0, R0.xy0x, t0, s0 -01 EXP_DONE: PIX0, R0 +01 ALU: ADDR(32) CNT(4) + 1 x: MUL R0.x, R0.x, C0.x + y: MUL R0.y, R0.y, C0.y + z: MUL R0.z, R0.z, C0.z + w: MUL R0.w, R0.w, C0.w +02 EXP_DONE: PIX0, R0 END_OF_PROGRAM diff --git a/src/video/wiiu/wiiu_shaders.c b/src/video/wiiu/wiiu_shaders.c index 0052208ec..341cb01f2 100644 --- a/src/video/wiiu/wiiu_shaders.c +++ b/src/video/wiiu/wiiu_shaders.c @@ -221,7 +221,7 @@ unsigned char wiiuTextureShaderData[] = { 0x7f, 0xe0, 0x1f, 0x81, 0x00, 0x01, 0x00, 0x40, 0xfe, 0x08, 0x00, 0x80, 0x90, 0x0c, 0x40, 0x20, 0x00, 0x00, 0x00, 0x80, 0x00, 0x0d, 0x00, 0x00, 0x42, 0x4c, 0x4b, 0x7b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x30, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x01, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -236,22 +236,26 @@ unsigned char wiiuTextureShaderData[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xd0, 0x60, 0x00, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xca, 0x70, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x73, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, - 0xd0, 0x60, 0x00, 0xd4, 0xca, 0x70, 0x00, 0xe8, 0x7d, 0x42, 0x4c, 0x4b, - 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0xd0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xd0, 0x60, 0x00, 0xf4, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xd0, 0x60, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xd0, 0x60, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xca, 0x70, 0x01, 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0x70, 0x01, 0x10, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x6d, 0x6f, + 0x64, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, + 0x65, 0x00, 0x00, 0x00, 0xd0, 0x60, 0x00, 0xbc, 0xd0, 0x60, 0x00, 0xd4, + 0xca, 0x70, 0x00, 0xe8, 0xca, 0x70, 0x00, 0xfc, 0x7d, 0x42, 0x4c, 0x4b, + 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, + 0xd0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xd0, 0x60, 0x01, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xd0, 0x60, 0x01, 0x1c, 0x42, 0x4c, 0x4b, 0x7b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x10, - 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x88, 0x06, 0x20, 0x94, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x01, 0x90, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa0, + 0x00, 0x00, 0x00, 0x00, 0x88, 0x06, 0x20, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -271,9 +275,19 @@ unsigned char wiiuTextureShaderData[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x04, 0xa0, 0x00, + 0x90, 0x00, 0x00, 0x20, 0x00, 0x08, 0x20, 0x01, 0x90, 0x00, 0x00, 0x40, + 0x00, 0x0c, 0xa0, 0x81, 0x90, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0d, 0xf0, 0x00, 0x00, 0x80, 0x10, - 0x00, 0x00, 0x00, 0x00, 0x42, 0x4c, 0x4b, 0x7b, 0x00, 0x00, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x0d, 0xf0, 0x00, 0x00, 0x80, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x42, 0x4c, 0x4b, 0x7b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 };