mirror of
https://github.com/yawut/SDL.git
synced 2026-08-20 07:44:03 -05:00
wiiu/render: Move texture-related functions to own file
This commit is contained in:
@@ -130,37 +130,6 @@ WIIU_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
return renderer;
|
||||
}
|
||||
|
||||
static int
|
||||
WIIU_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
GX2Texture *wiiu_tex = (GX2Texture*) SDL_calloc(1, sizeof(*wiiu_tex));
|
||||
if (!wiiu_tex)
|
||||
return SDL_OutOfMemory();
|
||||
|
||||
wiiu_tex->surface.width = TextureNextPow2(texture->w);
|
||||
wiiu_tex->surface.height = TextureNextPow2(texture->h);
|
||||
wiiu_tex->surface.format = PixelFormatToWIIUFMT(texture->format);
|
||||
wiiu_tex->surface.depth = 1; //?
|
||||
wiiu_tex->surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
|
||||
wiiu_tex->surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
|
||||
wiiu_tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||
wiiu_tex->surface.mipLevels = 1;
|
||||
wiiu_tex->viewNumMips = 1;
|
||||
wiiu_tex->viewNumSlices = 1;
|
||||
wiiu_tex->compMap = 0x00010203;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&wiiu_tex->surface);
|
||||
wiiu_tex->surface.image = memalign(wiiu_tex->surface.alignment, wiiu_tex->surface.imageSize);
|
||||
if(!wiiu_tex->surface.image)
|
||||
{
|
||||
SDL_free(wiiu_tex);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
texture->driverdata = wiiu_tex;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
WIIU_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
@@ -272,38 +241,6 @@ WIIU_RenderPresent(SDL_Renderer * renderer)
|
||||
}
|
||||
}
|
||||
|
||||
static Uint32
|
||||
TextureNextPow2(Uint32 w)
|
||||
{
|
||||
if(w == 0)
|
||||
return 0;
|
||||
Uint32 n = 2;
|
||||
while(w > n)
|
||||
n <<= 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
//TODO: This could return a compMap to support stuff like ARGB or ABGR
|
||||
static GX2SurfaceFormat
|
||||
PixelFormatToWIIUFMT(Uint32 format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_PIXELFORMAT_RGBA8888:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
case SDL_PIXELFORMAT_RGBA4444:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R4_G4_B4_A4;
|
||||
case SDL_PIXELFORMAT_ABGR1555:
|
||||
return GX2_SURFACE_FORMAT_UNORM_A1_B5_G5_R5;
|
||||
case SDL_PIXELFORMAT_RGBA5551:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1;
|
||||
case SDL_PIXELFORMAT_RGB565:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R5_G6_B5;
|
||||
default:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
}
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
}
|
||||
|
||||
SDL_RenderDriver WIIU_RenderDriver = {
|
||||
.CreateRenderer = WIIU_CreateRenderer,
|
||||
.info = {
|
||||
|
||||
100
src/render/wiiu/SDL_rtexture_wiiu.c
Normal file
100
src/render/wiiu/SDL_rtexture_wiiu.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
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/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>
|
||||
|
||||
static int
|
||||
WIIU_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
GX2Texture *wiiu_tex = (GX2Texture*) SDL_calloc(1, sizeof(*wiiu_tex));
|
||||
if (!wiiu_tex)
|
||||
return SDL_OutOfMemory();
|
||||
|
||||
wiiu_tex->surface.width = TextureNextPow2(texture->w);
|
||||
wiiu_tex->surface.height = TextureNextPow2(texture->h);
|
||||
wiiu_tex->surface.format = PixelFormatToWIIUFMT(texture->format);
|
||||
wiiu_tex->surface.depth = 1; //?
|
||||
wiiu_tex->surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
|
||||
wiiu_tex->surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
|
||||
wiiu_tex->surface.use = GX2_SURFACE_USE_TEXTURE;
|
||||
wiiu_tex->surface.mipLevels = 1;
|
||||
wiiu_tex->viewNumMips = 1;
|
||||
wiiu_tex->viewNumSlices = 1;
|
||||
wiiu_tex->compMap = 0x00010203;
|
||||
|
||||
GX2CalcSurfaceSizeAndAlignment(&wiiu_tex->surface);
|
||||
wiiu_tex->surface.image = memalign(wiiu_tex->surface.alignment, wiiu_tex->surface.imageSize);
|
||||
if(!wiiu_tex->surface.image)
|
||||
{
|
||||
SDL_free(wiiu_tex);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
texture->driverdata = wiiu_tex;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Uint32
|
||||
TextureNextPow2(Uint32 w)
|
||||
{
|
||||
if(w == 0)
|
||||
return 0;
|
||||
Uint32 n = 2;
|
||||
while(w > n)
|
||||
n <<= 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
//TODO: This could return a compMap to support stuff like ARGB or ABGR
|
||||
static GX2SurfaceFormat
|
||||
PixelFormatToWIIUFMT(Uint32 format)
|
||||
{
|
||||
switch (format) {
|
||||
case SDL_PIXELFORMAT_RGBA8888:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
case SDL_PIXELFORMAT_RGBA4444:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R4_G4_B4_A4;
|
||||
case SDL_PIXELFORMAT_ABGR1555:
|
||||
return GX2_SURFACE_FORMAT_UNORM_A1_B5_G5_R5;
|
||||
case SDL_PIXELFORMAT_RGBA5551:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R5_G5_B5_A1;
|
||||
case SDL_PIXELFORMAT_RGB565:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R5_G6_B5;
|
||||
default:
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
}
|
||||
return GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
|
||||
}
|
||||
|
||||
#endif //SDL_VIDEO_RENDER_WIIU
|
||||
Reference in New Issue
Block a user