ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
draw3d.c
Go to the documentation of this file.
1 #include <gif_tags.h>
2 
3 #include <gs_gp.h>
4 #include <gs_privileged.h>
5 
6 #include <draw.h>
7 
8 // Starting position of primitive
10 
12 {
13 
14  // Set the primitive register in packed mode, but don't end the packet
16  q++;
20  q++;
22  q++;
23 
24  // Save the position for the reglist giftag that draw_primitive_end will add
25  __prim_start = q;
26  q++;
27 
28  // Return the current qword pointer
29  return q;
30 
31 }
32 
33 qword_t *draw_prim_end(qword_t *q, int nreg, u64 reglist)
34 {
35 
36  u32 vertex_qwords;
37  u32 vertex_loops;
38 
39  // Determine number qwords that were needed minus the reglist giftag
40  vertex_qwords = q - __prim_start - 1;
41 
42  // Determine number of loops based on qwords used and number of regs per loop
43  vertex_loops = (vertex_qwords * 2) / nreg;
44 
45  // Now set the giftag of the vertex reglist chain
46  __prim_start->dw[0] = GIF_SET_TAG(vertex_loops,1,0,0,GIF_FLG_REGLIST,nreg);
47 
48  // Set the higher 64bits to the reglist
49  __prim_start->dw[1] = reglist;
50 
51  // Return the current qword pointer
52  return q;
53 
54 }
55 
56 int draw_convert_rgbq(color_t *output, int count, vertex_f_t *vertices, color_f_t *colours, unsigned char alpha)
57 {
58 
59  int i;
60  float q = 1.00f;
61 
62  // For each colour...
63  for (i=0;i<count;i++)
64  {
65 
66  // Calculate the Q value.
67  if (vertices[i].w != 0)
68  {
69 
70  q = 1 / vertices[i].w;
71 
72  }
73 
74  // Calculate the RGBA values.
75  output[i].r = (int)(colours[i].r * 128.0f);
76  output[i].g = (int)(colours[i].g * 128.0f);
77  output[i].b = (int)(colours[i].b * 128.0f);
78  output[i].a = alpha;
79  output[i].q = q;
80 
81  }
82 
83  // End function.
84  return 0;
85 
86 }
87 
89 {
90 
91  int i;
92  float q = 1.00f;
93 
94  // For each colour...
95  for (i=0;i<count;i++)
96  {
97 
98  // Calculate the Q value.
99  if (vertices[i].w != 0)
100  {
101 
102  q = 1 / vertices[i].w;
103 
104  }
105 
106  // Calculate the RGBA values.
107  output[i].r = (int)(colours[i].r * 128.0f);
108  output[i].g = (int)(colours[i].g * 128.0f);
109  output[i].b = (int)(colours[i].b * 128.0f);
110  output[i].a = (int)(colours[i].a * 128.0f);
111  output[i].q = q;
112 
113  }
114 
115  // End function.
116  return 0;
117 
118 }
119 
120 int draw_convert_st(texel_t *output, int count, vertex_f_t *vertices, texel_f_t *coords)
121 {
122 
123  int i = 0;
124  float q = 1.00f;
125 
126  // For each coordinate...
127  for (i=0;i<count;i++)
128  {
129 
130  // Calculate the Q value.
131  if (vertices[i].w != 0)
132  {
133  q = 1 / vertices[i].w;
134  }
135 
136  // Calculate the S and T values.
137  output[i].s = coords[i].s * q;
138  output[i].t = coords[i].t * q;
139 
140  }
141 
142  // End function.
143  return 0;
144 
145 }
146 
147 int draw_convert_xyz(xyz_t *output, float x, float y, int z, int count, vertex_f_t *vertices)
148 {
149 
150  int i;
151 
152  int center_x;
153  int center_y;
154 
155  unsigned int max_z;
156 
157  center_x = ftoi4(x);
158  center_y = ftoi4(y);
159 
160  max_z = 1 << (z - 1);
161 
162  // For each colour...
163  for (i=0;i<count;i++)
164  {
165 
166  // Calculate the XYZ values.
167  output[i].x = (short)((vertices[i].x + 1.0f) * center_x);
168  output[i].y = (short)((vertices[i].y + 1.0f) * -center_y);
169  output[i].z = (unsigned int)((vertices[i].z + 1.0f) * max_z);
170 
171  }
172 
173  // End function.
174  return 0;
175 
176 }
VECTOR vertices[24]
Definition: mesh_data.c:31
VECTOR colours[24]
Definition: mesh_data.c:58
int draw_convert_st(texel_t *output, int count, vertex_f_t *vertices, texel_f_t *coords)
Definition: draw3d.c:120
qword_t * draw_prim_start(qword_t *q, int context, prim_t *prim, color_t *color)
Definition: draw3d.c:11
int draw_convert_rgbq(color_t *output, int count, vertex_f_t *vertices, color_f_t *colours, unsigned char alpha)
Definition: draw3d.c:56
int draw_convert_xyz(xyz_t *output, float x, float y, int z, int count, vertex_f_t *vertices)
Definition: draw3d.c:147
qword_t * draw_prim_end(qword_t *q, int nreg, u64 reglist)
Definition: draw3d.c:33
int draw_convert_rgbaq(color_t *output, int count, vertex_f_t *vertices, color_f_t *colours)
Definition: draw3d.c:88
static qword_t * __prim_start
Definition: draw3d.c:9
prim_t prim
Definition: main.c:74
u8 context
Definition: main.c:71
#define ftoi4(F)
Definition: draw_types.h:15
#define GIF_REG_RGBAQ
Definition: gif_tags.h:44
#define PACK_GIFTAG(Q, D0, D1)
Definition: gif_tags.h:76
#define GIF_SET_TAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
Definition: gif_tags.h:80
#define GIF_REG_AD
Definition: gif_tags.h:72
#define GIF_FLG_REGLIST
Definition: gif_tags.h:37
#define GIF_FLG_PACKED
Definition: gif_tags.h:35
#define GS_SET_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)
Definition: gs_gp.h:237
#define GS_REG_PRIM
Definition: gs_gp.h:13
s32 x
Definition: libmouse.c:34
s32 y
Definition: libmouse.c:34
unsigned char type
unsigned char blending
unsigned char antialiasing
unsigned char colorfix
unsigned char shading
unsigned char fogging
unsigned char mapping_type
unsigned char mapping
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30
unsigned long u64
Definition: tamtypes.h:34
float q
Definition: draw_types.h:46
u64 rgbaq
Definition: draw_types.h:40
u64 dw[2]
Definition: tamtypes.h:85
float t
Definition: draw_types.h:61
float s
Definition: draw_types.h:60
float t
Definition: draw_types.h:31
float s
Definition: draw_types.h:30
u32 z
Definition: draw_types.h:23
u16 y
Definition: draw_types.h:22
u16 x
Definition: draw_types.h:21