RetroArch/source/texture_callbacks.c
Francisco José García García 8838992085 Squashed 'deps/vitaGL/' changes from 2934af8af0..81403e2751
81403e2751 Fix error requiring HAVE_SHARK to be enabled to build. (#45)
58551e1f52 Added possibility to change runtime shader compiler optimization flags.
77ab50a7b1 Added GL_BGR and GL_BGRA texture formats support.
0ac2793bcf Fix error in texture wrapping options. (#42)
0d2110ac7b Improvements to GL buffer support. (#41)
cf86149a85 Added proper compressed texture support. (#40)
8b0a0f735a Unbinded textures and texture units concepts.
1b04851efc Added glUniform2i and glUniform2f implementations.
9a65397ef6 Properly checking for uniform locations existence.
91c557f35d Added support for GL_SHORT attribute types for shaders.
3237fd3fe3 Added vglTexImageDepthBuffer function.
f58b3818f2 Typo fix on mag filter setting.
ee11f7e1d0 Added vglHasRuntimeShaderCompiler function.
3596242f73 Add PowerVR texture compression (PVRTC) support (#39)
2ae694df4b Added support for mipmaps filtering.
af7804b44c Added vglGetGxmTexture implementation.
54b1df4ca2 Removed unused arguments.
7c2ed742ee Allow to call vglBind*Location funcs with wrong param names.
8be84ff698 Fixed RGB565 color conversion.
234ff57f65 Properly setting a single stream with packed attributes.
d3b28a5e32 Fix for correct vglBindAttribLocation behaviour.
46e72d3564 Use a single stream for packed attributes.
72a39315e9 Properly dealing with missing attrs in glGetUniformLocation.
a6269ce574 Added TEXUNIT1 support for custom shaders.
824d43073e Resetting custom shaders uniforms only when invalidated.
d242570161 Minor fix in glShaderSource.
bc28bd946d Added glGetShaderInfoLog implementation.

git-subtree-dir: deps/vitaGL
git-subtree-split: 81403e2751c4dc28cf17cc89a5ab053eb2c5af67
2020-10-16 20:24:43 +02:00

161 lines
4.3 KiB
C

/*
* This file is part of vitaGL
* Copyright 2017, 2018, 2019, 2020 Rinnegatamante
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* texture_callbacks.c:
* Implementation for texture data reading/writing callbacks
*/
#include <stdlib.h>
#include <vitasdk.h>
#include "vitaGL.h"
#include "texture_callbacks.h"
#define convert_u16_to_u32_cspace(color, lshift, rshift, mask) ((((color << lshift) >> rshift) & mask) * 0xFF) / mask
// Read callback for 32bpp unsigned ABGR format
uint32_t readBGRA(void *data) {
uint32_t res;
memcpy_neon(&res, data, 4);
uint8_t *p = (uint8_t *)&res;
uint8_t tmp = p[0];
p[0] = p[2];
p[2] = tmp;
return res;
}
// Read callback for 32bpp unsigned RGBA format
uint32_t readRGBA(void *data) {
uint32_t res;
memcpy_neon(&res, data, 4);
return res;
}
// Read callback for 16bpp unsigned RGBA5551 format
uint32_t readRGBA5551(void *data) {
uint16_t clr;
uint32_t r, g, b, a;
memcpy_neon(&clr, data, 2);
r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
g = convert_u16_to_u32_cspace(clr, 5, 11, 0x1F);
b = convert_u16_to_u32_cspace(clr, 10, 11, 0x1F);
a = convert_u16_to_u32_cspace(clr, 15, 15, 0x01);
return ((a << 24) | (b << 16) | (g << 8) | r);
}
// Read callback for 16bpp unsigned RGBA4444 format
uint32_t readRGBA4444(void *data) {
uint16_t clr;
uint32_t r, g, b, a;
memcpy_neon(&clr, data, 2);
r = convert_u16_to_u32_cspace(clr, 0, 12, 0x0F);
g = convert_u16_to_u32_cspace(clr, 4, 12, 0x0F);
b = convert_u16_to_u32_cspace(clr, 8, 12, 0x0F);
a = convert_u16_to_u32_cspace(clr, 12, 12, 0x0F);
return ((a << 24) | (b << 16) | (g << 8) | r);
}
// Read callback for 16bpp unsigned RGB565 format
uint32_t readRGB565(void *data) {
uint16_t clr;
uint32_t r, g, b;
memcpy_neon(&clr, data, 2);
r = convert_u16_to_u32_cspace(clr, 0, 11, 0x1F);
g = convert_u16_to_u32_cspace(clr, 5, 10, 0x3F);
b = convert_u16_to_u32_cspace(clr, 11, 11, 0x1F);
return ((0xFF << 24) | (b << 16) | (g << 8) | r);
}
// Read callback for 24bpp unsigned BGR format
uint32_t readBGR(void *data) {
uint32_t res = 0xFFFFFFFF;
uint8_t *src = (uint8_t *)data;
uint8_t *dst = (uint8_t *)res;
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
return res;
}
// Read callback for 24bpp unsigned RGB format
uint32_t readRGB(void *data) {
uint32_t res = 0xFFFFFFFF;
memcpy_neon(&res, data, 3);
return res;
}
// Read callback for 16bpp unsigned RG format
uint32_t readRG(void *data) {
uint32_t res = 0xFFFFFFFF;
memcpy_neon(&res, data, 2);
return res;
}
// Read callback for 8bpp unsigned R format
uint32_t readR(void *data) {
uint32_t res = 0xFFFFFFFF;
memcpy_neon(&res, data, 1);
return res;
}
// Write callback for 32bpp unsigned RGBA format
void writeRGBA(void *data, uint32_t color) {
memcpy_neon(data, &color, 4);
}
// Write callback for 32bpp unsigned BGRA format
void writeBGRA(void *data, uint32_t color) {
memcpy_neon(data, &color, 4);
uint8_t *p = (uint8_t *)data;
uint8_t tmp = p[0];
p[0] = p[2];
p[2] = tmp;
}
// Write callback for 24bpp unsigned RGB format
void writeRGB(void *data, uint32_t color) {
memcpy_neon(data, &color, 3);
}
// Write callback for 24bpp unsigned BGR format
void writeBGR(void *data, uint32_t color) {
uint8_t *src = (uint8_t *)&color;
uint8_t *dst = (uint8_t *)data;
dst[0] = src[2];
dst[1] = src[1];
dst[2] = src[0];
}
// Write callback for 16bpp unsigned RG format
void writeRG(void *data, uint32_t color) {
memcpy_neon(data, &color, 2);
}
// Write callback for 16bpp unsigned RA format
void writeRA(void *data, uint32_t color) {
uint8_t *dst = (uint8_t *)data;
uint8_t *src = (uint8_t *)&color;
dst[0] = src[0];
dst[1] = src[3];
}
// Write callback for 8bpp unsigned R format
void writeR(void *data, uint32_t color) {
memcpy_neon(data, &color, 1);
}