render/wiiu: Code cleanup

* Remove unused functions
* Remove unneeded checks
* Uniform coding style with the rest of SDL
This commit is contained in:
rw-r-r-0644 2019-03-10 01:58:34 +01:00 committed by Ash Logan
parent 74a42de67b
commit d4f823db47
6 changed files with 187 additions and 212 deletions

View File

@ -62,7 +62,7 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
GX2RInvalidateSurface(&tdata->texture.surface, 0, 0);
}
/* Allocate attribute buffers */
/* Allocate attribute buffers */
a_position = WIIU_AllocRenderData(data, (GX2RBuffer) {
.flags =
GX2R_RESOURCE_BIND_VERTEX_BUFFER |
@ -78,13 +78,13 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
.elemCount = 4, // 4 corners
});
/* Compute vertex points */
/* Compute vertex points */
x_min = renderer->viewport.x + dstrect->x;
y_min = renderer->viewport.y + dstrect->y;
x_max = renderer->viewport.x + dstrect->x + dstrect->w;
y_max = renderer->viewport.y + dstrect->y + dstrect->h;
/* Save them */
/* Save them */
a_position_vals = GX2RLockBufferEx(a_position, 0);
a_position_vals[0] = (WIIUVec2){.x = x_min, .y = y_min};
a_position_vals[1] = (WIIUVec2){.x = x_max, .y = y_min};
@ -92,7 +92,7 @@ int WIIU_SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
a_position_vals[3] = (WIIUVec2){.x = x_min, .y = y_max};
GX2RUnlockBufferEx(a_position, 0);
/* Compute texture coords */
/* Compute texture coords */
a_texCoord_vals = GX2RLockBufferEx(a_texCoord, 0);
a_texCoord_vals[0] = (WIIUVec2) {
.x = srcrect->x,
@ -168,7 +168,7 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
GX2RInvalidateSurface(&tdata->texture.surface, 0, 0);
}
/* Allocate attribute buffers */
/* Allocate attribute buffers */
a_position = WIIU_AllocRenderData(data, (GX2RBuffer) {
.flags =
GX2R_RESOURCE_BIND_VERTEX_BUFFER |
@ -184,7 +184,7 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
.elemCount = 4, // 4 corners
});
/* Save vertex points */
/* Save vertex points */
a_position_vals = GX2RLockBufferEx(a_position, 0);
for (int i = 0; i < 4; i++) {
a_position_vals[i] = (WIIUVec2) {
@ -194,7 +194,7 @@ int WIIU_SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
}
GX2RUnlockBufferEx(a_position, 0);
/* Compute texture coords */
/* Compute texture coords */
a_texCoord_vals = GX2RLockBufferEx(a_texCoord, 0);
a_texCoord_vals[0] = (WIIUVec2) {
.x = srcrect->x,
@ -244,12 +244,12 @@ int WIIU_SDL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points
.a = (float)renderer->a / 255.0f,
};
/* Allocate attribute buffers */
/* Allocate attribute buffers */
a_position = WIIU_AllocRenderData(data, (GX2RBuffer) {
.flags =
GX2R_RESOURCE_BIND_VERTEX_BUFFER |
GX2R_RESOURCE_USAGE_CPU_WRITE,
.elemSize = sizeof(WIIUVec2), // float x/y for each point
.elemSize = sizeof(WIIUVec2), /* float x/y for each point */
.elemCount = count,
});
@ -295,7 +295,7 @@ int WIIU_SDL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
.flags =
GX2R_RESOURCE_BIND_VERTEX_BUFFER |
GX2R_RESOURCE_USAGE_CPU_WRITE,
.elemSize = sizeof(WIIUVec2), // float x/y for each point
.elemSize = sizeof(WIIUVec2), /* float x/y for each point */
.elemCount = count,
});
@ -380,22 +380,6 @@ int WIIU_SDL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, i
return 0;
}
/*void WIIU_SDL_RenderPresent(SDL_Renderer * renderer)
{
WIIU_RenderData *data = (WIIU_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
GX2Flush();
GX2DrawDone();
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, data->cbuf.surface.image, data->cbuf.surface.imageSize);
if (window) {
SDL_UpdateWindowSurface(window);
}
WIIU_FreeRenderData(data);
}*/
int WIIU_SDL_RenderClear(SDL_Renderer * renderer)
{
WIIU_RenderData* data = (WIIU_RenderData*) renderer->driverdata;
@ -448,7 +432,7 @@ static void WIIU_SDL_SetGX2BlendMode(SDL_BlendMode mode)
/* A = [srcA * 0] + [dstA * 1] */
GX2_BLEND_MODE_ZERO, GX2_BLEND_MODE_ONE,
GX2_BLEND_COMBINE_MODE_ADD);
}
}
}
#endif //SDL_VIDEO_RENDER_WIIU
#endif /* SDL_VIDEO_RENDER_WIIU */

View File

@ -1,7 +1,7 @@
/*
Simple DirectMedia Layer
Copyright (C) 2018-2018 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2018 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
Copyright (C) 2018-2019 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2019 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -26,18 +26,12 @@
#include "../../video/wiiu/SDL_wiiuvideo.h"
#include "../../video/wiiu/wiiu_shaders.h"
#include "../SDL_sysrender.h"
#include "SDL_hints.h"
#include "SDL_render_wiiu.h"
#include <gx2/registers.h>
#include <gx2r/surface.h>
#include <malloc.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
SDL_RenderDriver WIIU_RenderDriver;
@ -59,14 +53,12 @@ SDL_Renderer *WIIU_SDL_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}
// See sdl_render_wiiu.h for explanations of commented-out functions
/* Setup renderer functions */
renderer->WindowEvent = WIIU_SDL_WindowEvent;
renderer->GetOutputSize = WIIU_SDL_GetOutputSize;
renderer->CreateTexture = WIIU_SDL_CreateTexture;
renderer->SetTextureColorMod = WIIU_SDL_SetTextureColorMod;
renderer->SetTextureAlphaMod = WIIU_SDL_SetTextureAlphaMod;
//renderer->SetTextureBlendMode = WIIU_SDL_SetTextureBlendMode;
renderer->UpdateTexture = WIIU_SDL_UpdateTexture;
renderer->LockTexture = WIIU_SDL_LockTexture;
renderer->UnlockTexture = WIIU_SDL_UnlockTexture;
@ -87,38 +79,39 @@ SDL_Renderer *WIIU_SDL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->driverdata = data;
renderer->window = window;
// Prepare shaders
/* Prepare shaders */
wiiuInitTextureShader();
wiiuInitColorShader();
// List of attibutes to free after render
/* List of attibutes to free after render */
data->listfree = NULL;
// Setup line and point size
/* Setup line and point size */
GX2SetLineWidth(1.0f);
GX2SetPointSize(1.0f, 1.0f);
// Create a fresh context state
/* Create a fresh context state */
data->ctx = (GX2ContextState *) memalign(GX2_CONTEXT_STATE_ALIGNMENT, sizeof(GX2ContextState));
memset(data->ctx, 0, sizeof(GX2ContextState));
SDL_memset(data->ctx, 0, sizeof(GX2ContextState));
GX2SetupContextStateEx(data->ctx, TRUE);
GX2SetContextState(data->ctx);
// Setup some context state options
/* Setup some context state options */
GX2SetAlphaTest(TRUE, GX2_COMPARE_FUNC_GREATER, 0.0f);
GX2SetDepthOnlyControl(FALSE, FALSE, GX2_COMPARE_FUNC_NEVER);
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, FALSE, FALSE);
// Make a texture for the window
/* Make a texture for the window */
WIIU_SDL_CreateWindowTex(renderer, window);
// Setup colour buffer, rendering to the window
/* Setup colour buffer, rendering to the window */
WIIU_SDL_SetRenderTarget(renderer, NULL);
return renderer;
}
void WIIU_SDL_CreateWindowTex(SDL_Renderer * renderer, SDL_Window * window) {
void WIIU_SDL_CreateWindowTex(SDL_Renderer * renderer, SDL_Window * window)
{
WIIU_RenderData *data = (WIIU_RenderData *) renderer->driverdata;
if (data->windowTex.driverdata) {
@ -126,12 +119,15 @@ void WIIU_SDL_CreateWindowTex(SDL_Renderer * renderer, SDL_Window * window) {
data->windowTex = (SDL_Texture) {0};
}
// Allocate a buffer for the window
/* Allocate a buffer for the window */
data->windowTex = (SDL_Texture) {
.format = SDL_PIXELFORMAT_RGBA8888,
.r = 255, .g = 255, .b = 255, .a = 255,
};
SDL_GetWindowSize(window, &data->windowTex.w, &data->windowTex.h);
/* Setup texture and color buffer for the window */
WIIU_SDL_CreateTexture(renderer, &data->windowTex);
}
@ -139,31 +135,24 @@ int WIIU_SDL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
{
WIIU_RenderData *data = (WIIU_RenderData *) renderer->driverdata;
GX2ColorBuffer *target;
/* Set window or texture as target */
WIIU_TextureData *tdata = (WIIU_TextureData *)((texture) ? texture->driverdata
: data->windowTex.driverdata);
if (texture) {
// Set texture as target
WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata;
target = &tdata->cbuf;
} else {
// Set window texture as target
WIIU_TextureData *tdata = (WIIU_TextureData *) data->windowTex.driverdata;
target = &tdata->cbuf;
}
// Update u_viewSize
/* Update u_viewSize */
data->u_viewSize = (WIIUVec4) {
.x = (float)target->surface.width,
.y = (float)target->surface.height,
.x = (float)tdata->cbuf.surface.width,
.y = (float)tdata->cbuf.surface.height,
};
// Update context state
GX2SetColorBuffer(target, GX2_RENDER_TARGET_0);
// These may be unnecessary - see SDL_render.c: SDL_SetRenderTarget's calls
// to UpdateViewport and UpdateClipRect. TODO for once the render is
// basically working.
GX2SetViewport(0, 0, (float)target->surface.width, (float)target->surface.height, 0.0f, 1.0f);
GX2SetScissor(0, 0, (float)target->surface.width, (float)target->surface.height);
/* Update context state */
GX2SetColorBuffer(&tdata->cbuf, GX2_RENDER_TARGET_0);
/* These may be unnecessary - see SDL_render.c: SDL_SetRenderTarget's calls
to UpdateViewport and UpdateClipRect. TODO for once the render is
basically working */
GX2SetViewport(0, 0, (float)tdata->cbuf.surface.width, (float)tdata->cbuf.surface.height, 0.0f, 1.0f);
GX2SetScissor(0, 0, (float)tdata->cbuf.surface.width, (float)tdata->cbuf.surface.height);
return 0;
}
@ -192,8 +181,7 @@ int WIIU_SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
int ret;
/* NOTE: The rect is already adjusted according to the viewport by
* SDL_RenderReadPixels.
*/
SDL_RenderReadPixels */
if (rect->x < 0 || rect->x+rect->w > tdata->cbuf.surface.width ||
rect->y < 0 || rect->y+rect->h > tdata->cbuf.surface.height) {
@ -202,10 +190,11 @@ int WIIU_SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
src_image = GX2RLockSurfaceEx(&tdata->cbuf.surface, 0, GX2R_RESOURCE_LOCKED_READ_ONLY);
/* Convert and copy the pixels to target buffer */
ret = SDL_ConvertPixels(rect->w, rect->h, target->format,
src_image + rect->y * tdata->cbuf.surface.pitch + rect->x * 4,
tdata->cbuf.surface.pitch,
format, pixels, pitch);
src_image + rect->y * tdata->cbuf.surface.pitch + rect->x * 4,
tdata->cbuf.surface.pitch,
format, pixels, pitch);
GX2RUnlockSurfaceEx(&tdata->cbuf.surface, 0, GX2R_RESOURCE_LOCKED_READ_ONLY);
@ -213,7 +202,8 @@ int WIIU_SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
}
SDL_RenderDriver WIIU_RenderDriver = {
SDL_RenderDriver WIIU_RenderDriver =
{
.CreateRenderer = WIIU_SDL_CreateRenderer,
.info = {
.name = "WiiU GX2",

View File

@ -1,7 +1,7 @@
/*
Simple DirectMedia Layer
Copyright (C) 2018-2018 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2018 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
Copyright (C) 2018-2019 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2019 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,7 +19,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef SDL_render_wiiu_h
@ -29,41 +28,54 @@
#include "SDL_pixels.h"
#include <gx2/context.h>
#include <gx2/sampler.h>
#include <gx2/texture.h>
#include <gx2/surface.h>
#include <gx2r/buffer.h>
typedef struct {
/* Driver internal data structures */
typedef struct
{
union { float x, r; };
union { float y, g; };
} WIIUVec2;
typedef struct {
typedef struct
{
union { float x, r; };
union { float y, g; };
union { float z, b; };
} WIIUVec3;
typedef struct {
typedef struct
{
union { float x, r; };
union { float y, g; };
union { float z, b; };
union { float w, a; };
} WIIUVec4;
typedef struct
{
GX2SurfaceFormat fmt;
uint32_t compMap;
} WIIUPixFmt;
typedef struct
{
void *next;
GX2RBuffer buffer;
} WIIU_RenderAllocData;
//Driver internal data structures
typedef struct {
typedef struct
{
GX2ContextState *ctx;
WIIU_RenderAllocData *listfree;
WIIUVec4 u_viewSize;
SDL_Texture windowTex;
} WIIU_RenderData;
typedef struct {
typedef struct
{
GX2Sampler sampler;
GX2Texture texture;
GX2ColorBuffer cbuf;
@ -71,30 +83,7 @@ typedef struct {
WIIUVec4 u_mod;
} WIIU_TextureData;
static inline GX2RBuffer* WIIU_AllocRenderData(WIIU_RenderData *r, GX2RBuffer buffer) {
WIIU_RenderAllocData *rdata = SDL_malloc(sizeof(WIIU_RenderAllocData));
rdata->buffer = buffer;
if (!GX2RCreateBuffer(&rdata->buffer)) {
SDL_free(rdata);
return 0;
}
rdata->next = r->listfree;
r->listfree = rdata;
return &rdata->buffer;
}
static inline void WIIU_FreeRenderData(WIIU_RenderData *r) {
while (r->listfree) {
WIIU_RenderAllocData *ptr = r->listfree;
r->listfree = r->listfree->next;
GX2RDestroyBufferEx(&ptr->buffer, 0);
SDL_free(ptr);
}
}
//SDL_render API implementation
/* SDL_render API implementation */
SDL_Renderer *WIIU_SDL_CreateRenderer(SDL_Window * window, Uint32 flags);
void WIIU_SDL_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
@ -104,8 +93,6 @@ int WIIU_SDL_SetTextureColorMod(SDL_Renderer * renderer,
SDL_Texture * texture);
int WIIU_SDL_SetTextureAlphaMod(SDL_Renderer * renderer,
SDL_Texture * texture);
/*int WIIU_SDL_SetTextureBlendMode(SDL_Renderer * renderer,
SDL_Texture * texture);*/
int WIIU_SDL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
@ -133,38 +120,55 @@ void WIIU_SDL_RenderPresent(SDL_Renderer * renderer);
void WIIU_SDL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
void WIIU_SDL_DestroyRenderer(SDL_Renderer * renderer);
//Driver internal functions
/* Driver internal functions */
void WIIU_SDL_CreateWindowTex(SDL_Renderer * renderer, SDL_Window * window);
//Utility/helper functions
static inline Uint32 TextureNextPow2(Uint32 w) {
Uint32 n = 2;
if(w == 0)
/* Utility/helper functions */
static inline GX2RBuffer * WIIU_AllocRenderData(WIIU_RenderData *r, GX2RBuffer buffer)
{
WIIU_RenderAllocData *rdata = SDL_malloc(sizeof(WIIU_RenderAllocData));
rdata->buffer = buffer;
if (!GX2RCreateBuffer(&rdata->buffer)) {
SDL_free(rdata);
return 0;
while(w > n)
n <<= 1;
return n;
}
rdata->next = r->listfree;
r->listfree = rdata;
return &rdata->buffer;
}
typedef struct WIIUPixFmt {
GX2SurfaceFormat fmt;
uint32_t compMap;
} WIIUPixFmt;
static inline void WIIU_FreeRenderData(WIIU_RenderData *r)
{
while (r->listfree) {
WIIU_RenderAllocData *ptr = r->listfree;
r->listfree = r->listfree->next;
GX2RDestroyBufferEx(&ptr->buffer, 0);
SDL_free(ptr);
}
}
static inline SDL_Texture* WIIU_GetRenderTarget(SDL_Renderer* renderer) {
static inline SDL_Texture * WIIU_GetRenderTarget(SDL_Renderer* renderer)
{
WIIU_RenderData *data = (WIIU_RenderData *) renderer->driverdata;
if (renderer->target) return renderer->target;
if (renderer->target) {
return renderer->target;
}
return &data->windowTex;
}
static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format) {
static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format)
{
WIIUPixFmt outFmt = { /* sane defaults? */
.fmt = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8,
.compMap = 0x00010203,
};
switch (format) {
/* packed16 formats: 4 bits/channel */
/* packed16 formats: 4 bits/channel */
case SDL_PIXELFORMAT_RGB444: /* aka XRGB4444 */
case SDL_PIXELFORMAT_ARGB4444: {
outFmt.fmt = GX2_SURFACE_FORMAT_UNORM_R4_G4_B4_A4;
@ -187,7 +191,7 @@ static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format) {
break;
}
/* packed16 formats: 5 bits/channel */
/* packed16 formats: 5 bits/channel */
case SDL_PIXELFORMAT_RGB555: /* aka XRGB1555 */
case SDL_PIXELFORMAT_ARGB1555: {
outFmt.fmt = GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1;
@ -211,7 +215,7 @@ static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format) {
break;
}
/* packed16 formats: 565 */
/* packed16 formats: 565 */
case SDL_PIXELFORMAT_RGB565: {
outFmt.fmt = GX2_SURFACE_FORMAT_UNORM_R5_G6_B5;
outFmt.compMap = 0x00010203;
@ -223,7 +227,7 @@ static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format) {
break;
}
/* packed32 formats */
/* packed32 formats */
case SDL_PIXELFORMAT_RGBA8888:
case SDL_PIXELFORMAT_RGBX8888: {
outFmt.fmt = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
@ -253,7 +257,7 @@ static inline WIIUPixFmt SDLFormatToWIIUFormat(Uint32 format) {
break;
}
default: {
/* TODO return an error */
/* TODO return an error */
printf("SDL: WiiU format not recognised (SDL: %08X)\n", format);
break;
}

View File

@ -1,11 +1,30 @@
/*
Simple DirectMedia Layer
Copyright (C) 2018-2019 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2019 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_WIIU
#include "../../video/wiiu/SDL_wiiuvideo.h"
#include "../../video/wiiu/wiiu_shaders.h"
#include "../SDL_sysrender.h"
#include "SDL_hints.h"
#include "SDL_render_wiiu.h"
#include <whb/gfx.h>
@ -20,7 +39,8 @@
static const WIIUVec4 u_viewSize = {.x = (float)SCREEN_WIDTH, .y = (float)SCREEN_HEIGHT};
static void render_scene(SDL_Renderer * renderer) {
static void render_scene(SDL_Renderer * renderer)
{
WIIU_RenderData *data = (WIIU_RenderData *) renderer->driverdata;
WIIU_TextureData *tdata = (WIIU_TextureData *) data->windowTex.driverdata;
@ -30,13 +50,13 @@ static void render_scene(SDL_Renderer * renderer) {
GX2RBuffer *a_position, *a_texCoord;
WIIUVec2 *a_position_vals, *a_texCoord_vals;
/* Allocate attribute buffers */
/* Allocate attribute buffers */
a_position = WIIU_AllocRenderData(data, (GX2RBuffer) {
.flags =
GX2R_RESOURCE_BIND_VERTEX_BUFFER |
GX2R_RESOURCE_USAGE_CPU_WRITE,
.elemSize = sizeof(WIIUVec2), // float x/y for each corner
.elemCount = 4, // 4 corners
.elemSize = sizeof(WIIUVec2), /* float x/y for each corner */
.elemCount = 4, /* 4 corners */
});
a_texCoord = WIIU_AllocRenderData(data, (GX2RBuffer) {
.flags =
@ -46,14 +66,14 @@ static void render_scene(SDL_Renderer * renderer) {
.elemCount = 4, // 4 corners
});
/* Calculate and save positions */
/* Calculate and save positions */
if (SDL_GetWindowFlags(renderer->window) & SDL_WINDOW_FULLSCREEN) {
win_x = 0;
win_y = 0;
win_w = SCREEN_WIDTH;
win_h = SCREEN_HEIGHT;
} else {
/* Center */
/* Center */
SDL_GetWindowSize(renderer->window, &win_w, &win_h);
win_x = (SCREEN_WIDTH - win_w) / 2;
win_y = (SCREEN_HEIGHT - win_h) / 2;
@ -74,7 +94,7 @@ static void render_scene(SDL_Renderer * renderer) {
};
GX2RUnlockBufferEx(a_position, 0);
/* Compute texture coords */
/* Compute texture coords */
a_texCoord_vals = GX2RLockBufferEx(a_texCoord, 0);
a_texCoord_vals[0] = (WIIUVec2) {.x = 0.0f, .y = tex_h};
a_texCoord_vals[1] = (WIIUVec2) {.x = tex_w, .y = tex_h};
@ -82,6 +102,7 @@ static void render_scene(SDL_Renderer * renderer) {
a_texCoord_vals[3] = (WIIUVec2) {.x = 0.0f, .y = 0.0f};
GX2RUnlockBufferEx(a_texCoord, 0);
/* Render the window */
WHBGfxClearColor(0.0f, 0.0f, 0.0f, 1.0f);
wiiuSetTextureShader();
@ -107,7 +128,7 @@ void WIIU_SDL_RenderPresent(SDL_Renderer * renderer)
WHBGfxBeginRender();
/* Only render to TV if the window is *not* drc-only */
/* Only render to TV if the window is *not* drc-only */
if (!(flags & SDL_WINDOW_WIIU_GAMEPAD_ONLY)) {
WHBGfxBeginRenderTV();
render_scene(renderer);
@ -122,10 +143,11 @@ void WIIU_SDL_RenderPresent(SDL_Renderer * renderer)
WHBGfxFinishRender();
/* Free the list of render data */
WIIU_FreeRenderData(data);
/* Restore SDL context state */
/* Restore SDL context state */
GX2SetContextState(data->ctx);
}
#endif //SDL_VIDEO_RENDER_WIIU
#endif /* SDL_VIDEO_RENDER_WIIU */

View File

@ -1,7 +1,7 @@
/*
Simple DirectMedia Layer
Copyright (C) 2018-2018 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2018 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
Copyright (C) 2018-2019 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2019 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,9 +23,7 @@
#if SDL_VIDEO_RENDER_WIIU
#include "../../video/wiiu/SDL_wiiuvideo.h"
#include "../SDL_sysrender.h"
#include "SDL_hints.h"
#include "SDL_render_wiiu.h"
#include <gx2/context.h>
@ -36,21 +34,18 @@
#include <gx2r/resource.h>
#include <malloc.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
WIIUPixFmt gx2_fmt;
BOOL res;
WIIU_TextureData *tdata = (WIIU_TextureData *) SDL_calloc(1, sizeof(*tdata));
if (!tdata)
if (!tdata) {
return SDL_OutOfMemory();
}
// Setup sampler
/* Setup sampler */
if (texture->scaleMode == SDL_ScaleModeNearest) {
GX2InitSampler(&tdata->sampler, GX2_TEX_CLAMP_MODE_CLAMP, GX2_TEX_XY_FILTER_MODE_POINT);
} else {
@ -60,10 +55,11 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
gx2_fmt = SDLFormatToWIIUFormat(texture->format);
/* Setup GX2Texture */
tdata->texture.surface.width = texture->w;
tdata->texture.surface.height = texture->h;
tdata->texture.surface.format = gx2_fmt.fmt;
tdata->texture.surface.depth = 1; //?
tdata->texture.surface.depth = 1;
tdata->texture.surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
tdata->texture.surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
tdata->texture.surface.mipLevels = 1;
@ -73,11 +69,12 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
GX2CalcSurfaceSizeAndAlignment(&tdata->texture.surface);
GX2InitTextureRegs(&tdata->texture);
/* Setup GX2ColorBuffer */
tdata->cbuf.surface = tdata->texture.surface;
tdata->cbuf.viewNumSlices = 1;
GX2InitColorBufferRegs(&tdata->cbuf);
/* Allocate the texture's surface */
/* Allocate the texture's surface */
res = GX2RCreateSurface(
&tdata->texture.surface,
GX2R_RESOURCE_BIND_TEXTURE | GX2R_RESOURCE_BIND_COLOR_BUFFER |
@ -89,7 +86,7 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return SDL_OutOfMemory();
}
/* Allocate a colour buffer, using the same backing buffer */
/* Allocate a colour buffer, using the same backing buffer */
res = GX2RCreateSurfaceUserMemory(
&tdata->cbuf.surface,
tdata->texture.surface.image,
@ -102,11 +99,13 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return SDL_OutOfMemory();
}
/* Initialize texture size uniform */
tdata->u_texSize = (WIIUVec4) {
.x = texture->w,
.y = texture->h,
};
/* Initialize color modifier uniform */
tdata->u_mod = (WIIUVec4) {
.r = (float)texture->r / 255.0f,
.g = (float)texture->g / 255.0f,
@ -119,60 +118,44 @@ int WIIU_SDL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
// Somewhat adapted from SDL_render.c: SDL_LockTextureNative
// The app basically wants a pointer to a particular rectangle as well as
// write access to it. Easy GX2R!
/* Somewhat adapted from SDL_render.c: SDL_LockTextureNative
The app basically wants a pointer to a particular rectangle as well as
write access to it. Easy GX2R! */
int WIIU_SDL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
{
WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata;
Uint32 BytesPerPixel = SDL_BYTESPERPIXEL(texture->format);
void* pixel_buffer;
void* pixel_buffer = GX2RLockSurfaceEx(&tdata->texture.surface, 0, 0);
pixel_buffer = GX2RLockSurfaceEx(&tdata->texture.surface, 0, 0);
if (!pixel_buffer) {
//TODO real error handling
printf("SDL: Couldn't lock surface for texture!\n");
return -1;
}
// Calculate pointer to first pixel in rect
/* Calculate pointer to first pixel in rect */
*pixels = (void *) ((Uint8 *) pixel_buffer +
rect->y * (tdata->texture.surface.pitch * BytesPerPixel) +
rect->x * BytesPerPixel);
*pitch = (tdata->texture.surface.pitch * BytesPerPixel);
// Not sure we even need to bother keeping track of this
/* Not sure we even need to bother keeping track of this */
texture->locked_rect = *rect;
return 0;
}
void WIIU_SDL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata;
GX2RUnlockSurfaceEx(&tdata->texture.surface, 0, 0);
}
int WIIU_SDL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
Uint32 BytesPerPixel;
Uint8 *src, *dst;
int row, dst_pitch, rc;
size_t length;
Uint32 BytesPerPixel = SDL_BYTESPERPIXEL(texture->format);
size_t length = rect->w * BytesPerPixel;
Uint8 *src = (Uint8 *) pixels, *dst;
int row, dst_pitch;
BytesPerPixel = SDL_BYTESPERPIXEL(texture->format);
src = (Uint8 *) pixels;
length = rect->w * BytesPerPixel;
/* We write the rules, and we say all textures are streaming */
rc = WIIU_SDL_LockTexture(
renderer, texture, rect, (void**)&dst, &dst_pitch
);
if (rc < 0) {
return rc;
}
/* We write the rules, and we say all textures are streaming */
WIIU_SDL_LockTexture(renderer, texture, rect, (void**)&dst, &dst_pitch);
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
@ -209,10 +192,8 @@ int WIIU_SDL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
void WIIU_SDL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
WIIU_TextureData *tdata;
if (texture == NULL || texture->driverdata == NULL) return;
WIIU_TextureData *tdata = (WIIU_TextureData *) texture->driverdata;
tdata = (WIIU_TextureData *) texture->driverdata;
GX2RDestroySurfaceEx(&tdata->cbuf.surface, 0);
GX2RDestroySurfaceEx(&tdata->texture.surface, 0);

View File

@ -1,7 +1,7 @@
/*
Simple DirectMedia Layer
Copyright (C) 2018-2018 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2018 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
Copyright (C) 2018-2019 Ash Logan <ash@heyquark.com>
Copyright (C) 2018-2019 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -19,50 +19,44 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_WIIU
#include "../../video/wiiu/SDL_wiiuvideo.h"
#include "../SDL_sysrender.h"
#include "SDL_hints.h"
#include "SDL_render_wiiu.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
void WIIU_SDL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
{
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
// Re-init the colour buffer etc. for new window size
// TODO check: what if we're rendering to a texture when this happens?
// SDL may handle this already, see SDL_render.c: SDL_RendererEventWatch
/* Re-init the colour buffer etc. for new window size
TODO check: what if we're rendering to a texture when this happens?
SDL may handle this already, see SDL_render.c: SDL_RendererEventWatch */
WIIU_SDL_CreateWindowTex(renderer, renderer->window);
WIIU_SDL_SetRenderTarget(renderer, NULL);
}
}
// We always output at whatever res the window is.
// This may need to change if SDL_wiiuvideo is ever folded into SDL_render -
// see SDL_*WindowTexture from SDL_video.c for how this could be done
int WIIU_SDL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h) {
/* We always output at whatever res the window is.
This may need to change if SDL_wiiuvideo is ever folded into SDL_render -
see SDL_*WindowTexture from SDL_video.c for how this could be done */
int WIIU_SDL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_GetWindowSize(renderer->window, w, h);
return 0;
}
// We handle all viewport changes in the render functions and shaders, so we
// don't actually have to do anything here. SDL still requires we implement it.
int WIIU_SDL_UpdateViewport(SDL_Renderer * renderer) {
/* We handle all viewport changes in the render functions and shaders, so we
don't actually have to do anything here. SDL still requires we implement it. */
int WIIU_SDL_UpdateViewport(SDL_Renderer * renderer)
{
return 0;
}
// Ideally this should change the GX2SetScissor values, but SetRenderTarget
// needs refactoring first or these get overwritten.
int WIIU_SDL_UpdateClipRect(SDL_Renderer * renderer) {
/* Ideally this should change the GX2SetScissor values, but SetRenderTarget
needs refactoring first or these get overwritten. */
int WIIU_SDL_UpdateClipRect(SDL_Renderer * renderer)
{
return 0;
}