ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
draw3d.c File Reference
#include <gif_tags.h>
#include <gs_gp.h>
#include <gs_privileged.h>
#include <draw.h>
+ Include dependency graph for draw3d.c:

Go to the source code of this file.

Functions

qword_tdraw_prim_start (qword_t *q, int context, prim_t *prim, color_t *color)
 
qword_tdraw_prim_end (qword_t *q, int nreg, u64 reglist)
 
int draw_convert_rgbq (color_t *output, int count, vertex_f_t *vertices, color_f_t *colours, unsigned char alpha)
 
int draw_convert_rgbaq (color_t *output, int count, vertex_f_t *vertices, color_f_t *colours)
 
int draw_convert_st (texel_t *output, int count, vertex_f_t *vertices, texel_f_t *coords)
 
int draw_convert_xyz (xyz_t *output, float x, float y, int z, int count, vertex_f_t *vertices)
 

Variables

static qword_t__prim_start = NULL
 

Function Documentation

◆ draw_convert_rgbaq()

int draw_convert_rgbaq ( color_t output,
int  count,
vertex_f_t vertices,
color_f_t colours 
)

Converts floating point color and calculates q value

Definition at line 88 of file draw3d.c.

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 }
VECTOR vertices[24]
Definition: mesh_data.c:31
VECTOR colours[24]
Definition: mesh_data.c:58
float q
Definition: draw_types.h:46

References color_t::a, color_t::b, colours, color_t::g, color_t::q, color_t::r, and vertices.

◆ draw_convert_rgbq()

int draw_convert_rgbq ( color_t output,
int  count,
vertex_f_t vertices,
color_f_t colours,
unsigned char  alpha 
)

Converts floating point color, replacing alpha with constant value, and calculates q

Definition at line 56 of file draw3d.c.

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 }

References color_t::a, color_t::b, colours, color_t::g, color_t::q, color_t::r, and vertices.

Referenced by render(), and render_teapot().

◆ draw_convert_st()

int draw_convert_st ( texel_t output,
int  count,
vertex_f_t vertices,
texel_f_t coords 
)

Calculates the st coordinates from the perspective coordinate q = 1/w

Definition at line 120 of file draw3d.c.

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 }
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

References texel_t::s, texel_f_t::s, texel_t::t, texel_f_t::t, and vertices.

Referenced by render().

◆ draw_convert_xyz()

int draw_convert_xyz ( xyz_t output,
float  x,
float  y,
int  z,
int  count,
vertex_f_t vertices 
)

Converts and translates floating point vertices to fixed point vertices

Definition at line 147 of file draw3d.c.

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 }
#define ftoi4(F)
Definition: draw_types.h:15
s32 x
Definition: libmouse.c:34
s32 y
Definition: libmouse.c:34
u32 z
Definition: draw_types.h:23
u16 y
Definition: draw_types.h:22
u16 x
Definition: draw_types.h:21

References ftoi4, vertices, xyz_t::x, x, xyz_t::y, y, and xyz_t::z.

Referenced by render(), and render_teapot().

◆ draw_prim_end()

qword_t* draw_prim_end ( qword_t q,
int  nreg,
u64  reglist 
)

Ends a primitive by calculating the number of qwords used, the number of registers, the register list

Definition at line 33 of file draw3d.c.

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 }
static qword_t * __prim_start
Definition: draw3d.c:9
#define GIF_SET_TAG(NLOOP, EOP, PRE, PRIM, FLG, NREG)
Definition: gif_tags.h:80
#define GIF_FLG_REGLIST
Definition: gif_tags.h:37
unsigned int u32
Definition: tamtypes.h:30
u64 dw[2]
Definition: tamtypes.h:85

References __prim_start, qword_t::dw, GIF_FLG_REGLIST, and GIF_SET_TAG.

Referenced by fontstudio_print_string(), fontx_print_ascii(), fontx_print_sjis(), render(), and render_teapot().

◆ draw_prim_start()

qword_t* draw_prim_start ( qword_t q,
int  context,
prim_t prim,
color_t color 
)

Begins a primitive, allowing for vertex data to be filled in the packet directly

Definition at line 11 of file draw3d.c.

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 }
prim_t prim
Definition: main.c:74
u8 context
Definition: main.c:71
#define GIF_REG_RGBAQ
Definition: gif_tags.h:44
#define PACK_GIFTAG(Q, D0, D1)
Definition: gif_tags.h:76
#define GIF_REG_AD
Definition: gif_tags.h:72
#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
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
u64 rgbaq
Definition: draw_types.h:40

References __prim_start, prim_t::antialiasing, prim_t::blending, prim_t::colorfix, context, prim_t::fogging, GIF_FLG_PACKED, GIF_REG_AD, GIF_REG_RGBAQ, GIF_SET_TAG, GS_REG_PRIM, GS_SET_PRIM, prim_t::mapping, prim_t::mapping_type, PACK_GIFTAG, prim, color_t::rgbaq, prim_t::shading, and prim_t::type.

Referenced by fontstudio_print_string(), fontx_print_ascii(), fontx_print_sjis(), render(), and render_teapot().

Variable Documentation

◆ __prim_start

qword_t* __prim_start = NULL
static

Definition at line 9 of file draw3d.c.

Referenced by draw_prim_end(), and draw_prim_start().