-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCitroHelpers.cpp
More file actions
64 lines (53 loc) · 1.63 KB
/
CitroHelpers.cpp
File metadata and controls
64 lines (53 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "CitroHelpers.hpp"
namespace
{
C3D_MtxStack projectionMatrix, modelviewMatrix, textureMatrix;
}
void CitroInit(size_t commandBufferSize)
{
C3D_Init(commandBufferSize);
// Configure attributes for use with the vertex shader
C3D_AttrInfo* attrInfo = C3D_GetAttrInfo();
AttrInfo_Init(attrInfo);
AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 2); // v0=position
AttrInfo_AddLoader(attrInfo, 1, GPU_UNSIGNED_BYTE, 4); // v1=color
AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 2); // v2=texcoord
C3D_TexEnv* env = C3D_GetTexEnv(0);
C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0);
C3D_TexEnvOp(env, C3D_Both, 0, 0, 0);
C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE);
C3D_DepthTest(false, GPU_GEQUAL, GPU_WRITE_ALL);
C3D_CullFace(GPU_CULL_NONE);
}
void CitroDestroy()
{
C3D_Fini();
}
void CitroBindUniforms(shaderProgram_s* program)
{
int location;
location = shaderInstanceGetUniformLocation(program->vertexShader, "projection");
MtxStack_Bind(&projectionMatrix, GPU_VERTEX_SHADER, location, 4);
location = shaderInstanceGetUniformLocation(program->vertexShader, "modelview");
MtxStack_Bind(&modelviewMatrix, GPU_VERTEX_SHADER, location, 4);
location = shaderInstanceGetUniformLocation(program->vertexShader, "texture");
MtxStack_Bind(&textureMatrix, GPU_VERTEX_SHADER, location, 4);
}
void CitroUpdateMatrixStacks()
{
MtxStack_Update(&projectionMatrix);
MtxStack_Update(&modelviewMatrix);
MtxStack_Update(&textureMatrix);
}
C3D_MtxStack* CitroGetProjectionMatrix()
{
return &projectionMatrix;
}
C3D_MtxStack* CitroGetModelviewMatrix()
{
return &modelviewMatrix;
}
C3D_MtxStack* CitroGetTextureMatrix()
{
return &textureMatrix;
}