libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
ColorShader.cpp
1/****************************************************************************
2 * Platform Abstraction Layer (WUT driver)
3 * Daryl Borth 2026
4 * ColorShader.cpp
5 ***************************************************************************/
6#include <malloc.h>
7#include <string.h>
8#include "ColorShader.h"
9
10static const uint32_t cpVertexShaderProgram[] =
11{
12 0x00000000,0x00008009,0x20000000,0x000078a0,
13 0x3c200000,0x88060094,0x00c00000,0x88062014,
14 0x00000000,0x00000000,0x00000000,0x00000000,
15 0x00000000,0x00000000,0x00000000,0x00000000,
16 0x00000000,0x00000000,0x00000000,0x00000000,
17 0x00000000,0x00000000,0x00000000,0x00000000,
18 0x00000000,0x00000000,0x00000000,0x00000000,
19 0x00000000,0x00000000,0x00000000,0x00000000,
20 0x00000000,0x00000000,0x00000000,0x00000000,
21 0x00000000,0x00000000,0x00000000,0x00000000,
22 0x00000000,0x00000000,0x00000000,0x00000000,
23 0x00000000,0x00000000,0x00000000,0x00000000,
24 0x00000000,0x00000000,0x00000000,0x00000000,
25 0x00000000,0x00000000,0x00000000,0x00000000,
26 0x00000000,0x00000000,0x00000000,0x00000000,
27 0x00000000,0x00000000,0x00000000,0x00000000,
28 0x00a11f00,0xfc00620f,0x02490001,0x80000040,
29 0xfd041f80,0x900c0060,0x83f9223e,0x0000803f,
30 0xfe282001,0x10000040,0xfe001f80,0x00080060,
31 0xfeac9f80,0xfd00624f,0xdb0f49c0,0xdb0fc940,
32 0xfea81f80,0x9000e02f,0x83f9223e,0x00000000,
33 0xfe041f80,0x00370000,0xffa01f00,0x80000000,
34 0xff101f00,0x800c0020,0x7f041f80,0x80370000,
35 0x0000103f,0x00000000,0x02c51f00,0x80000000,
36 0xfea41f00,0x80000020,0xffa09f00,0x80000040,
37 0xff001f80,0x800c0060,0x398ee33f,0x0000103f,
38 0x02c41f00,0x9000e00f,0x02c59f01,0x80000020,
39 0xfea81f00,0x80000040,0x02c19f80,0x9000e06f,
40 0x398ee33f,0x00000000,0x02c11f01,0x80000000,
41 0x02c49f80,0x80000060,0x02e08f01,0xfe0c620f,
42 0x02c01f80,0x7f00622f,0xfe242000,0x10000000,
43 0xfe20a080,0x10000020,0xf2178647,0x49c0e9fb,
44 0xfbbdb2ab,0x768ac733
45};
46
47static const uint32_t cpVertexShaderRegs[] = {
48 0x00000103,0x00000000,0x00000000,0x00000001,
49 0xffffff00,0xffffffff,0xffffffff,0xffffffff,
50 0xffffffff,0xffffffff,0xffffffff,0xffffffff,
51 0xffffffff,0xffffffff,0x00000000,0xfffffffc,
52 0x00000002,0x00000001,0x00000000,0x000000ff,
53 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
54 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
55 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
56 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
57 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
58 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
59 0x000000ff,0x000000ff,0x000000ff,0x000000ff,
60 0x000000ff,0x00000000,0x0000000e,0x00000010
61};
62
63static const uint32_t cpPixelShaderProgram[] =
64{
65 0x20000000,0x00000ca0,0x00000000,0x88062094,
66 0x00000000,0x00000000,0x00000000,0x00000000,
67 0x00000000,0x00000000,0x00000000,0x00000000,
68 0x00000000,0x00000000,0x00000000,0x00000000,
69 0x00000000,0x00000000,0x00000000,0x00000000,
70 0x00000000,0x00000000,0x00000000,0x00000000,
71 0x00000000,0x00000000,0x00000000,0x00000000,
72 0x00000000,0x00000000,0x00000000,0x00000000,
73 0x00000000,0x00000000,0x00000000,0x00000000,
74 0x00000000,0x00000000,0x00000000,0x00000000,
75 0x00000000,0x00000000,0x00000000,0x00000000,
76 0x00000000,0x00000000,0x00000000,0x00000000,
77 0x00000000,0x00000000,0x00000000,0x00000000,
78 0x00000000,0x00000000,0x00000000,0x00000000,
79 0x00000000,0x00000000,0x00000000,0x00000000,
80 0x00000000,0x00000000,0x00000000,0x00000000,
81 0x00002000,0x90000000,0x0004a000,0x90000020,
82 0x00082001,0x90000040,0x000ca081,0x90000060,
83 0xbb7dd898,0x9746c59c,0xc69b00e7,0x03c36218
84};
85static const uint32_t cpPixelShaderRegs[] = {
86 0x00000001,0x00000002,0x14000001,0x00000000,
87 0x00000001,0x00000100,0x00000000,0x00000000,
88 0x00000000,0x00000000,0x00000000,0x00000000,
89 0x00000000,0x00000000,0x00000000,0x00000000,
90 0x00000000,0x00000000,0x00000000,0x00000000,
91 0x00000000,0x00000000,0x00000000,0x00000000,
92 0x00000000,0x00000000,0x00000000,0x00000000,
93 0x00000000,0x00000000,0x00000000,0x00000000,
94 0x00000000,0x00000000,0x00000000,0x00000000,
95 0x00000000,0x0000000f,0x00000001,0x00000010,
96 0x00000000
97};
98
99ColorShader * ColorShader::shaderInstance = nullptr;
100
101ColorShader::ColorShader()
102 : vertexShader(cuAttributeCount)
103{
104 pixelShader.setProgram(cpPixelShaderProgram, sizeof(cpPixelShaderProgram), cpPixelShaderRegs, sizeof(cpPixelShaderRegs));
105
106 colorIntensityLocation = 0;
107 pixelShader.addUniformVar((GX2UniformVar){ "unf_color_intensity", GX2_SHADER_VAR_TYPE_FLOAT4, 1, colorIntensityLocation, -1 });
108
109 vertexShader.setProgram(cpVertexShaderProgram, sizeof(cpVertexShaderProgram), cpVertexShaderRegs, sizeof(cpVertexShaderRegs));
110
111 angleLocation = 0;
112 offsetLocation = 4;
113 scaleLocation = 8;
114 vertexShader.addUniformVar((GX2UniformVar){ "unf_angle", GX2_SHADER_VAR_TYPE_FLOAT, 1, angleLocation, -1 });
115 vertexShader.addUniformVar((GX2UniformVar){ "unf_offset", GX2_SHADER_VAR_TYPE_FLOAT3, 1, offsetLocation, -1 });
116 vertexShader.addUniformVar((GX2UniformVar){ "unf_scale", GX2_SHADER_VAR_TYPE_FLOAT3, 1, scaleLocation, -1 });
117
118 colorLocation = 1;
119 positionLocation = 0;
120 vertexShader.addAttribVar((GX2AttribVar){ "attr_color", GX2_SHADER_VAR_TYPE_FLOAT4, 0, colorLocation });
121 vertexShader.addAttribVar((GX2AttribVar){ "attr_position", GX2_SHADER_VAR_TYPE_FLOAT3, 0, positionLocation });
122
123 GX2InitAttribStream(vertexShader.getAttributeBuffer(0), positionLocation, 0, 0, GX2_ATTRIB_FORMAT_FLOAT_32_32_32);
124 GX2InitAttribStream(vertexShader.getAttributeBuffer(1), colorLocation, 1, 0, GX2_ATTRIB_FORMAT_UNORM_8_8_8_8);
125
126 fetchShader = new FetchShader(vertexShader.getAttributeBuffer(), vertexShader.getAttributesCount());
127
128 positionVtxs = static_cast<float *>(memalign(GX2_VERTEX_BUFFER_ALIGNMENT, cuPositionVtxsSize));
129 if(positionVtxs)
130 {
131 int i = 0;
132 positionVtxs[i++] = -1.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 0.0f;
133 positionVtxs[i++] = 1.0f; positionVtxs[i++] = -1.0f; positionVtxs[i++] = 0.0f;
134 positionVtxs[i++] = 1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f;
135 positionVtxs[i++] = -1.0f; positionVtxs[i++] = 1.0f; positionVtxs[i++] = 0.0f;
136 GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, positionVtxs, cuPositionVtxsSize);
137 }
138
139 colorBuffer.flags = static_cast<GX2RResourceFlags>(
140 GX2R_RESOURCE_BIND_VERTEX_BUFFER | GX2R_RESOURCE_USAGE_CPU_WRITE | GX2R_RESOURCE_USAGE_GPU_READ);
141 colorBuffer.elemSize = cuColorVtxsSize;
142 colorBuffer.elemCount = cuMaxColorDraws;
143 GX2RCreateBuffer(&colorBuffer);
144 colorSlot = 0;
145}
146
147ColorShader::~ColorShader()
148{
149 free(positionVtxs);
150 if(GX2RBufferExists(&colorBuffer))
151 GX2RDestroyBufferEx(&colorBuffer, static_cast<GX2RResourceFlags>(0));
152 delete fetchShader;
153}
Flat-color quad shader (rectangles, keyboard/dialog chrome), used via WutGlyphRenderer's drawFeature(...
Definition ColorShader.h:20
Owns the GX2 fetch shader program that binds vertex attribute streams to a vertex shader.
Definition FetchShader.h:17