libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
Shader.h
1/****************************************************************************
2 * Platform Abstraction Layer (WUT driver)
3 * Daryl Borth 2026
4 * Shader.h
5 ***************************************************************************/
6#ifndef WUT_SHADER_H_
7#define WUT_SHADER_H_
8
9#include <string.h>
10#include <stdint.h>
11#include <gx2/state.h>
12#include <gx2/context.h>
13#include <gx2/display.h>
14#include <gx2/clear.h>
15#include <gx2/draw.h>
16#include <gx2/registers.h>
17#include <gx2/shaders.h>
18#include <gx2/mem.h>
19#include <gx2/surface.h>
20#include <gx2/sampler.h>
21#include <gx2/texture.h>
22
25static inline void GX2InitAttribStream(GX2AttribStream *attrib, uint32_t location, uint32_t buffer, uint32_t offset, GX2AttribFormat format)
26{
27 attrib->location = location;
28 attrib->buffer = buffer;
29 attrib->offset = offset;
30 attrib->format = format;
31 attrib->type = GX2_ATTRIB_INDEX_PER_VERTEX;
32 attrib->aluDivisor = 0;
33 attrib->mask = 0x00010203; // identity component mapping
34 attrib->endianSwap = GX2_ENDIAN_SWAP_DEFAULT;
35}
36
39static inline void GX2InitTexture(GX2Texture *texture, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, GX2SurfaceFormat format, GX2SurfaceDim dim, GX2TileMode tileMode)
40{
41 memset(texture, 0, sizeof(GX2Texture));
42 texture->surface.dim = dim;
43 texture->surface.width = width;
44 texture->surface.height = height;
45 texture->surface.depth = (depth == 0) ? 1 : depth;
46 texture->surface.mipLevels = (mipLevels == 0) ? 1 : mipLevels;
47 texture->surface.format = format;
48 texture->surface.aa = GX2_AA_MODE1X;
49 texture->surface.use = GX2_SURFACE_USE_TEXTURE;
50 texture->surface.tileMode = tileMode;
51 GX2CalcSurfaceSizeAndAlignment(&texture->surface);
52
53 texture->viewFirstMip = 0;
54 texture->viewNumMips = texture->surface.mipLevels;
55 texture->viewFirstSlice = 0;
56 texture->viewNumSlices = 1;
57 texture->compMap = 0x00010203; // identity RGBA swizzle
58
59 GX2InitTextureRegs(texture);
60}
61
65class Shader
66{
67 protected:
68 Shader() {}
69 virtual ~Shader() {}
70 public:
72 static const uint16_t cuVertexAttrSize = sizeof(float) * 3;
74 static const uint16_t cuTexCoordAttrSize = sizeof(float) * 2;
76 static const uint16_t cuColorAttrSize = sizeof(uint8_t) * 4;
77
81 static void draw(int32_t primitive = GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount = 4)
82 {
83 GX2DrawEx(static_cast<GX2PrimitiveMode>(primitive), vtxCount, 0, 1);
84 }
85};
86
87#endif // WUT_SHADER_H_
static const uint16_t cuVertexAttrSize
Size in bytes of one position vertex (3 floats)
Definition Shader.h:72
static const uint16_t cuTexCoordAttrSize
Size in bytes of one texture coordinate (2 floats)
Definition Shader.h:74
static void draw(int32_t primitive=GX2_PRIMITIVE_MODE_QUADS, uint32_t vtxCount=4)
Issues the draw call for the currently bound shaders and attribute buffers.
Definition Shader.h:81
static const uint16_t cuColorAttrSize
Size in bytes of one vertex color (4 bytes, RGBA)
Definition Shader.h:76