From c7cec2c79299a77b17649f9074ee35118dee35ff Mon Sep 17 00:00:00 2001 From: Ivan Epifanov Date: Mon, 11 Jan 2021 20:45:12 +0300 Subject: [PATCH] Add more texture formats --- src/render/vitagxm/SDL_render_vita_gxm.c | 32 +++++++++++++++++-- .../vitagxm/SDL_render_vita_gxm_tools.c | 3 -- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c index d3c2f9dac..d861c11a3 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm.c +++ b/src/render/vitagxm/SDL_render_vita_gxm.c @@ -109,15 +109,41 @@ SDL_RenderDriver VITA_GXM_RenderDriver = { .info = { .name = "VITA gxm", .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE, - .num_texture_formats = 1, + .num_texture_formats = 6, .texture_formats = { - [0] = SDL_PIXELFORMAT_ABGR8888, // TODO: support more formats? ARGB8888 should be enough? + [0] = SDL_PIXELFORMAT_ABGR8888, + [1] = SDL_PIXELFORMAT_ARGB8888, + [2] = SDL_PIXELFORMAT_RGB888, + [3] = SDL_PIXELFORMAT_BGR888, + [2] = SDL_PIXELFORMAT_RGB565, + [3] = SDL_PIXELFORMAT_BGR565 }, .max_texture_width = 1024, .max_texture_height = 1024, } }; +static int +PixelFormatToVITAFMT(Uint32 format) +{ + switch (format) { + case SDL_PIXELFORMAT_ARGB8888: + return SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB; + case SDL_PIXELFORMAT_RGB888: + return SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ARGB; + case SDL_PIXELFORMAT_BGR888: + return SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + case SDL_PIXELFORMAT_ABGR8888: + return SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + case SDL_PIXELFORMAT_RGB565: + return SCE_GXM_TEXTURE_FORMAT_U5U6U5_RGB; + case SDL_PIXELFORMAT_BGR565: + return SCE_GXM_TEXTURE_FORMAT_U5U6U5_BGR; + default: + return SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + } +} + void StartDrawing(SDL_Renderer *renderer) { @@ -258,7 +284,7 @@ VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) return SDL_OutOfMemory(); } - vita_texture->tex = create_gxm_texture(data, texture->w, texture->h, SCE_GXM_TEXTURE_FORMAT_A8B8G8R8, (texture->access == SDL_TEXTUREACCESS_TARGET)); + vita_texture->tex = create_gxm_texture(data, texture->w, texture->h, PixelFormatToVITAFMT(texture->format), (texture->access == SDL_TEXTUREACCESS_TARGET)); if (!vita_texture->tex) { SDL_free(vita_texture); diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.c b/src/render/vitagxm/SDL_render_vita_gxm_tools.c index 411c70ca4..f410f08c5 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm_tools.c +++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.c @@ -1046,12 +1046,9 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc const int tex_size = ((w + 7) & ~ 7) * h * tex_format_to_bytespp(format); void *texture_data; - format = SCE_GXM_TEXTURE_FORMAT_A8B8G8R8; - if (!texture) return NULL; - /* Allocate a GPU buffer for the texture */ texture_data = mem_gpu_alloc( SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,