My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
gpu.h
Go to the documentation of this file.
1 #pragma once
2 
3 void GPU_Init(Handle *gsphandle);
4 void GPU_Reset(u32* gxbuf, u32* gpuBuf, u32 gpuBufSize);
5 
6 void GPUCMD_SetBuffer(u32* adr, u32 size, u32 offset);
7 void GPUCMD_SetBufferOffset(u32 offset);
8 void GPUCMD_GetBuffer(u32** adr, u32* size, u32* offset);
9 void GPUCMD_AddRawCommands(u32* cmd, u32 size);
10 void GPUCMD_Run(u32* gxbuf);
11 void GPUCMD_FlushAndRun(u32* gxbuf);
12 void GPUCMD_Add(u32 cmd, u32* param, u32 paramlength);
13 void GPUCMD_AddSingleParam(u32 cmd, u32 param);
14 void GPUCMD_Finalize();
15 
16 //tex param
17 #define GPU_TEXTURE_MAG_FILTER(v) (((v)&0x1)<<1) //takes a GPU_TEXTURE_FILTER_PARAM
18 #define GPU_TEXTURE_MIN_FILTER(v) (((v)&0x1)<<2) //takes a GPU_TEXTURE_FILTER_PARAM
19 #define GPU_TEXTURE_WRAP_S(v) (((v)&0x3)<<8) //takes a GPU_TEXTURE_WRAP_PARAM
20 #define GPU_TEXTURE_WRAP_T(v) (((v)&0x3)<<12) //takes a GPU_TEXTURE_WRAP_PARAM
21 
22 typedef enum
23 {
24  GPU_NEAREST = 0x0,
25  GPU_LINEAR = 0x1,
27 
28 typedef enum
29 {
31  GPU_REPEAT = 0x2,
33 
34 typedef enum
35 {
36  GPU_TEXUNIT0 = 0x1,
37  GPU_TEXUNIT1 = 0x2,
39 } GPU_TEXUNIT;
40 
41 typedef enum{
42  GPU_RGBA8=0x0,
43  GPU_RGB8=0x1,
46  GPU_RGBA4=0x4,
47  GPU_LA8=0x5,
48  GPU_HILO8=0x6,
49  GPU_L8=0x7,
50  GPU_A8=0x8,
51  GPU_LA4=0x9,
52  GPU_L4=0xA,
53  GPU_ETC1=0xB,
56 
57 typedef enum
58 {
59  GPU_NEVER = 0,
61  GPU_EQUAL = 2,
63  GPU_LESS = 4,
68 
69 typedef enum
70 {
71  GPU_SCISSOR_DISABLE = 0, // disable scissor test
72  GPU_SCISSOR_INVERT = 1, // exclude pixels inside the scissor box
73  // 2 is the same as 0
74  GPU_SCISSOR_NORMAL = 3, // exclude pixels outside of the scissor box
75 
77 
78 typedef enum
79 {
80  GPU_KEEP = 0, // keep destination value
81  GPU_AND_NOT = 1, // destination & ~source
82  GPU_XOR = 5, // destination ^ source
83  // 2 is the same as 1. Other values are too weird to even be usable.
85 
86 typedef enum
87 {
88  GPU_WRITE_RED = 0x01,
93 
97 
98 typedef enum
99 {
106 
107 typedef enum
108 {
109  GPU_ZERO = 0,
110  GPU_ONE = 1,
125 
126 typedef enum
127 {
144 } GPU_LOGICOP;
145 
146 typedef enum{
147  GPU_BYTE = 0,
151 }GPU_FORMATS;
152 
153 //defines for CW ?
154 typedef enum{
158 }GPU_CULLMODE;
159 
160 #define GPU_ATTRIBFMT(i, n, f) (((((n)-1)<<2)|((f)&3))<<((i)*4))
161 
162 typedef enum{
164  GPU_TEXTURE0 = 0x03,
165  GPU_TEXTURE1 = 0x04,
166  GPU_TEXTURE2 = 0x05,
167  GPU_TEXTURE3 = 0x06,
168  GPU_CONSTANT = 0x0E,
169  GPU_PREVIOUS = 0x0F,
170 }GPU_TEVSRC;
171 
172 typedef enum{
173  GPU_REPLACE = 0x00,
174  GPU_MODULATE = 0x01,
175  GPU_ADD = 0x02,
178  GPU_SUBTRACT = 0x05,
179  GPU_DOT3_RGB = 0x06 //RGB only
181 
182 #define GPU_TEVSOURCES(a,b,c) (((a))|((b)<<4)|((c)<<8))
183 #define GPU_TEVOPERANDS(a,b,c) (((a))|((b)<<4)|((c)<<8))
184 
185 typedef enum{
186  GPU_TRIANGLES = 0x0000,
189  GPU_UNKPRIM = 0x0300 // ?
191 
192 void GPU_SetUniform(u32 startreg, u32* data, u32 numreg);
193 
194 void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h);
195 
196 void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h);
197 
198 void GPU_DepthRange(float nearVal, float farVal);
199 void GPU_SetAlphaTest(bool enable, GPU_TESTFUNC function, u8 ref);
200 void GPU_SetDepthTestAndWriteMask(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask); // GPU_WRITEMASK values can be ORed together
201 void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref, u8 mask, u8 replace);
204 
205 // these two can't be used together
206 void GPU_SetAlphaBlending(GPU_BLENDEQUATION colorEquation, GPU_BLENDEQUATION alphaEquation,
207  GPU_BLENDFACTOR colorSrc, GPU_BLENDFACTOR colorDst,
208  GPU_BLENDFACTOR alphaSrc, GPU_BLENDFACTOR alphaDst);
210 
211 void GPU_SetBlendingColor(u8 r, u8 g, u8 b, u8 a);
212 
213 void GPU_SetAttributeBuffers(u8 totalAttributes, u32* baseAddress, u64 attributeFormats, u16 attributeMask, u64 attributePermutation, u8 numBuffers, u32 bufferOffsets[], u64 bufferPermutations[], u8 bufferNumAttributes[]);
214 
215 void GPU_SetTextureEnable(GPU_TEXUNIT units); // GPU_TEXUNITx values can be ORed together to enable multiple texture units
216 void GPU_SetTexture(GPU_TEXUNIT unit, u32* data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType);
217 void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor);
218 
219 void GPU_DrawArray(GPU_Primitive_t primitive, u32 n);
220 void GPU_DrawElements(GPU_Primitive_t primitive, u32* indexArray, u32 n);
221 
222 void GPU_FinishDrawing();
Definition: gpu.h:49
Definition: gpu.h:47
Definition: gpu.h:149
Definition: gpu.h:60
void GPU_SetAlphaBlending(GPU_BLENDEQUATION colorEquation, GPU_BLENDEQUATION alphaEquation, GPU_BLENDFACTOR colorSrc, GPU_BLENDFACTOR colorDst, GPU_BLENDFACTOR alphaSrc, GPU_BLENDFACTOR alphaDst)
Definition: gpu.c:349
void GPU_DrawArray(GPU_Primitive_t primitive, u32 n)
Definition: gpu.c:467
GPU_LOGICOP
Definition: gpu.h:126
Definition: gpu.h:43
void GPUCMD_SetBufferOffset(u32 offset)
Definition: gpu.c:27
void GPU_SetDepthTestAndWriteMask(bool enable, GPU_TESTFUNC function, GPU_WRITEMASK writemask)
Definition: gpu.c:344
void GPU_SetTexture(GPU_TEXUNIT unit, u32 *data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType)
Definition: gpu.c:374
uint16_t u16
Definition: types.h:22
void GPUCMD_FlushAndRun(u32 *gxbuf)
Definition: gpu.c:56
void GPUCMD_AddRawCommands(u32 *cmd, u32 size)
Definition: gpu.c:39
void GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h)
Definition: gpu.c:312
GPU_BLENDFACTOR
Definition: gpu.h:107
void GPU_SetStencilOp(GPU_STENCILOP sfail, GPU_STENCILOP dfail, GPU_STENCILOP pass)
Definition: gpu.c:339
void GPUCMD_GetBuffer(u32 **adr, u32 *size, u32 *offset)
Definition: gpu.c:32
Definition: gpu.h:59
Definition: gpu.h:53
Definition: gpu.h:150
u32 Handle
Definition: types.h:41
Definition: gpu.h:52
void GPU_DepthRange(float nearVal, float farVal)
Definition: gpu.c:322
Definition: gpu.h:64
void GPU_SetAttributeBuffers(u8 totalAttributes, u32 *baseAddress, u64 attributeFormats, u16 attributeMask, u64 attributePermutation, u8 numBuffers, u32 bufferOffsets[], u64 bufferPermutations[], u8 bufferNumAttributes[])
Definition: gpu.c:403
uint8_t u8
Definition: types.h:21
void GPU_FinishDrawing()
Definition: gpu.c:510
uint64_t u64
Definition: types.h:24
void GPU_SetBlendingColor(u8 r, u8 g, u8 b, u8 a)
Definition: gpu.c:363
GPU_FORMATS
Definition: gpu.h:146
Definition: gpu.h:50
void GPU_SetAlphaTest(bool enable, GPU_TESTFUNC function, u8 ref)
Definition: gpu.c:329
GPU_TESTFUNC
Definition: gpu.h:57
GPU_WRITEMASK
Definition: gpu.h:86
uint32_t u32
Definition: types.h:23
void GPU_SetTextureEnable(GPU_TEXUNIT units)
Definition: gpu.c:368
Definition: gpu.h:48
Definition: gpu.h:175
void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor)
Definition: gpu.c:452
GPU_TEVSRC
Definition: gpu.h:162
GPU_Primitive_t
Definition: gpu.h:185
Definition: gpu.h:63
GPU_TEXTURE_FILTER_PARAM
Definition: gpu.h:22
void GPU_SetUniform(u32 startreg, u32 *data, u32 numreg)
Definition: gpu.c:225
GPU_TEXCOLOR
Definition: gpu.h:41
Definition: gpu.h:80
Definition: gpu.h:54
void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref, u8 mask, u8 replace)
Definition: gpu.c:334
void GPU_SetColorLogicOp(GPU_LOGICOP op)
Definition: gpu.c:357
Definition: gpu.h:31
Definition: gpu.h:51
void GPUCMD_AddSingleParam(u32 cmd, u32 param)
Definition: gpu.c:88
void GPU_SetFaceCulling(GPU_CULLMODE mode)
Definition: gpu.c:445
void GPU_SetViewport(u32 *depthBuffer, u32 *colorBuffer, u32 x, u32 y, u32 w, u32 h)
Definition: gpu.c:270
Definition: gpu.h:42
Definition: gpu.h:25
void GPU_Reset(u32 *gxbuf, u32 *gpuBuf, u32 gpuBufSize)
Definition: gpu.c:104
Definition: gpu.h:110
GPU_STENCILOP
Definition: gpu.h:78
GPU_TEXUNIT
Definition: gpu.h:34
GPU_CULLMODE
Definition: gpu.h:154
GPU_SCISSORMODE
Definition: gpu.h:69
Definition: gpu.h:45
Definition: gpu.h:82
GPU_BLENDEQUATION
Definition: gpu.h:98
void GPUCMD_Finalize()
Definition: gpu.c:93
void GPUCMD_Add(u32 cmd, u32 *param, u32 paramlength)
Definition: gpu.c:63
Definition: gpu.h:61
Definition: gpu.h:66
Definition: gpu.h:147
void GPU_DrawElements(GPU_Primitive_t primitive, u32 *indexArray, u32 n)
Definition: gpu.c:489
void GPUCMD_Run(u32 *gxbuf)
Definition: gpu.c:47
void GPU_Init(Handle *gsphandle)
Definition: gpu.c:13
Definition: gpu.h:46
GPU_COMBINEFUNC
Definition: gpu.h:172
void GPUCMD_SetBuffer(u32 *adr, u32 size, u32 offset)
Definition: gpu.c:20
Definition: gpu.h:109
GPU_TEXTURE_WRAP_PARAM
Definition: gpu.h:28