libgui/include/gui/gx2_ext.h

162 lines
6.7 KiB
C
Raw Normal View History

2018-06-21 20:44:58 +02:00
#ifndef __GX2_EXTENSION_H
2022-02-05 14:28:08 +01:00
#define __GX2_EXTENSION_H
2018-06-21 20:44:58 +02:00
#ifdef __cplusplus
extern "C" {
#endif
#include <gx2/draw.h>
#include <gx2/enum.h>
#include <gx2/mem.h>
#include <gx2/registers.h>
#include <gx2/sampler.h>
#include <gx2/shaders.h>
#include <gx2/surface.h>
#include <gx2/texture.h>
2022-02-05 14:28:08 +01:00
#define GX2_AA_BUFFER_CLEAR_VALUE 0xCC
2018-06-21 20:44:58 +02:00
2022-02-05 14:28:08 +01:00
#define GX2_COMP_SEL_NONE 0x04040405
#define GX2_COMP_SEL_X001 0x00040405
#define GX2_COMP_SEL_XY01 0x00010405
#define GX2_COMP_SEL_XYZ1 0x00010205
#define GX2_COMP_SEL_XYZW 0x00010203
#define GX2_COMP_SEL_XXXX 0x00000000
#define GX2_COMP_SEL_YYYY 0x01010101
#define GX2_COMP_SEL_ZZZZ 0x02020202
#define GX2_COMP_SEL_WWWW 0x03030303
#define GX2_COMP_SEL_WZYX 0x03020100
#define GX2_COMP_SEL_WXYZ 0x03000102
2018-06-21 20:44:58 +02:00
2018-06-23 13:52:46 +02:00
typedef struct _GX2Color {
uint8_t r, g, b, a;
} GX2Color;
typedef struct _GX2ColorF32 {
float r, g, b, a;
} GX2ColorF32;
2018-06-21 20:44:58 +02:00
static const uint32_t attribute_dest_comp_selector[20] = {
2020-08-13 12:38:07 +02:00
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_X001,
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1,
2022-02-05 14:28:08 +01:00
GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW};
2018-06-21 20:44:58 +02:00
static const uint32_t texture_comp_selector[54] = {
2020-08-13 12:38:07 +02:00
GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_X001,
GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_WZYX, GX2_COMP_SEL_X001, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01, GX2_COMP_SEL_NONE,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_WZYX, GX2_COMP_SEL_XY01, GX2_COMP_SEL_XY01,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW,
GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_X001,
GX2_COMP_SEL_XY01, GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_NONE, GX2_COMP_SEL_XYZ1,
2022-02-05 14:28:08 +01:00
GX2_COMP_SEL_XYZ1, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_XYZW, GX2_COMP_SEL_X001, GX2_COMP_SEL_XY01};
2018-06-21 20:44:58 +02:00
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa) {
2022-02-05 14:28:08 +01:00
depthBuffer->surface.dim = dim;
depthBuffer->surface.width = width;
depthBuffer->surface.height = height;
depthBuffer->surface.depth = depth;
2018-06-21 20:44:58 +02:00
depthBuffer->surface.mipLevels = 1;
2022-02-05 14:28:08 +01:00
depthBuffer->surface.format = format;
depthBuffer->surface.aa = aa;
depthBuffer->surface.use = (GX2SurfaceUse) (((format == GX2_SURFACE_FORMAT_UNORM_R24_X8) || (format == GX2_SURFACE_FORMAT_FLOAT_D24_S8)) ? GX2_SURFACE_USE_DEPTH_BUFFER : (GX2_SURFACE_USE_DEPTH_BUFFER | GX2_SURFACE_USE_TEXTURE));
depthBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
depthBuffer->surface.swizzle = 0;
depthBuffer->viewMip = 0;
depthBuffer->viewFirstSlice = 0;
depthBuffer->viewNumSlices = depth;
depthBuffer->depthClear = 1.0f;
depthBuffer->stencilClear = 0;
depthBuffer->hiZPtr = NULL;
depthBuffer->hiZSize = 0;
2018-06-21 20:44:58 +02:00
GX2CalcSurfaceSizeAndAlignment(&depthBuffer->surface);
GX2InitDepthBufferRegs(depthBuffer);
}
static inline void GX2InitColorBuffer(GX2ColorBuffer *colorBuffer, GX2SurfaceDim dim, uint32_t width, uint32_t height, uint32_t depth, GX2SurfaceFormat format, GX2AAMode aa) {
2022-02-05 14:28:08 +01:00
colorBuffer->surface.dim = dim;
colorBuffer->surface.width = width;
colorBuffer->surface.height = height;
colorBuffer->surface.depth = depth;
colorBuffer->surface.mipLevels = 1;
colorBuffer->surface.format = format;
colorBuffer->surface.aa = aa;
colorBuffer->surface.use = GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV;
colorBuffer->surface.imageSize = 0;
colorBuffer->surface.image = NULL;
2018-06-21 20:44:58 +02:00
colorBuffer->surface.mipmapSize = 0;
2022-02-05 14:28:08 +01:00
colorBuffer->surface.mipmaps = NULL;
colorBuffer->surface.tileMode = GX2_TILE_MODE_DEFAULT;
colorBuffer->surface.swizzle = 0;
colorBuffer->surface.alignment = 0;
colorBuffer->surface.pitch = 0;
2018-06-21 20:44:58 +02:00
uint32_t i;
2020-08-13 12:58:19 +02:00
for (i = 0; i < 13; i++) {
2018-06-21 20:44:58 +02:00
colorBuffer->surface.mipLevelOffset[i] = 0;
2020-08-13 12:58:19 +02:00
}
2022-02-05 14:28:08 +01:00
colorBuffer->viewMip = 0;
2018-06-21 20:44:58 +02:00
colorBuffer->viewFirstSlice = 0;
2022-02-05 14:28:08 +01:00
colorBuffer->viewNumSlices = depth;
colorBuffer->aaBuffer = NULL;
colorBuffer->aaSize = 0;
2020-08-13 12:58:19 +02:00
for (i = 0; i < 5; i++) {
2018-06-21 20:44:58 +02:00
colorBuffer->regs[i] = 0;
2020-08-13 12:58:19 +02:00
}
2018-06-21 20:44:58 +02:00
GX2CalcSurfaceSizeAndAlignment(&colorBuffer->surface);
GX2InitColorBufferRegs(colorBuffer);
}
2020-08-13 12:38:07 +02:00
static inline void GX2InitAttribStream(GX2AttribStream *attr, uint32_t location, uint32_t buffer, uint32_t offset, GX2AttribFormat format) {
2022-02-05 14:28:08 +01:00
attr->location = location;
attr->buffer = buffer;
attr->offset = offset;
attr->format = format;
attr->type = GX2_ATTRIB_INDEX_PER_VERTEX;
2018-06-21 20:44:58 +02:00
attr->aluDivisor = 0;
2022-02-05 14:28:08 +01:00
attr->mask = attribute_dest_comp_selector[format & 0xff];
2020-08-13 12:38:07 +02:00
attr->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
2018-06-21 20:44:58 +02:00
}
static inline void GX2InitTexture(GX2Texture *tex, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tile) {
2022-02-05 14:28:08 +01:00
tex->surface.dim = dim;
tex->surface.width = width;
tex->surface.height = height;
tex->surface.depth = depth;
tex->surface.mipLevels = mipLevels;
tex->surface.format = format;
tex->surface.aa = GX2_AA_MODE1X;
tex->surface.use = GX2_SURFACE_USE_TEXTURE;
tex->surface.imageSize = 0;
tex->surface.image = NULL;
2018-06-21 20:44:58 +02:00
tex->surface.mipmapSize = 0;
2022-02-05 14:28:08 +01:00
tex->surface.mipmaps = NULL;
tex->surface.tileMode = tile;
tex->surface.swizzle = 0;
tex->surface.alignment = 0;
tex->surface.pitch = 0;
2018-06-21 20:44:58 +02:00
uint32_t i;
2020-08-13 12:58:19 +02:00
for (i = 0; i < 13; i++) {
2018-06-21 20:44:58 +02:00
tex->surface.mipLevelOffset[i] = 0;
2020-08-13 12:58:19 +02:00
}
2022-02-05 14:28:08 +01:00
tex->viewFirstMip = 0;
tex->viewNumMips = mipLevels;
2018-06-21 20:44:58 +02:00
tex->viewFirstSlice = 0;
2022-02-05 14:28:08 +01:00
tex->viewNumSlices = depth;
tex->compMap = texture_comp_selector[format & 0x3f];
2020-08-13 12:58:19 +02:00
for (i = 0; i < 5; i++) {
2018-06-21 20:44:58 +02:00
tex->regs[i] = 0;
2020-08-13 12:58:19 +02:00
}
2018-06-21 20:44:58 +02:00
GX2CalcSurfaceSizeAndAlignment(&tex->surface);
GX2InitTextureRegs(tex);
}
#ifdef __cplusplus
}
#endif
2018-06-23 13:52:46 +02:00
#endif