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

Go to the source code of this file.

Macros

#define OFFSET   2048.0f
 
#define START_OFFSET   2047.5625f
 
#define END_OFFSET   2048.5625f
 
#define DRAW_POINT_NREG   4
 
#define DRAW_POINT_REGLIST
 
#define DRAW_LINE_NREG   4
 
#define DRAW_LINE_REGLIST
 
#define DRAW_TRIANGLE_OUT_NREG   6
 
#define DRAW_TRIANGLE_OUT_REGLIST
 
#define DRAW_TRIANGLE_NREG   6
 
#define DRAW_TRIANGLE_REGLIST
 
#define DRAW_RECT_OUT_NREG   8
 
#define DRAW_RECT_OUT_REGLIST
 
#define DRAW_SPRITE_NREG   4
 
#define DRAW_SPRITE_REGLIST
 
#define DRAW_SPRITE_TEX_NREG   6
 
#define DRAW_SPRITE_TEX_REGLIST
 

Functions

void draw_enable_blending ()
 
void draw_disable_blending ()
 
qword_tdraw_point (qword_t *q, int context, point_t *point)
 
qword_tdraw_line (qword_t *q, int context, line_t *line)
 
qword_tdraw_triangle_outline (qword_t *q, int context, triangle_t *triangle)
 
qword_tdraw_triangle_filled (qword_t *q, int context, triangle_t *triangle)
 
qword_tdraw_rect_outline (qword_t *q, int context, rect_t *rect)
 
qword_tdraw_rect_filled (qword_t *q, int context, rect_t *rect)
 
qword_tdraw_rect_textured (qword_t *q, int context, texrect_t *rect)
 
qword_tdraw_rect_filled_strips (qword_t *q, int context, rect_t *rect)
 
qword_tdraw_rect_textured_strips (qword_t *q, int context, texrect_t *rect)
 
qword_tdraw_arc_outline (qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
 
qword_tdraw_arc_filled (qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
 
qword_tdraw_round_rect_filled (qword_t *q, int context, rect_t *rect)
 
qword_tdraw_round_rect_outline (qword_t *q, int context, rect_t *rect)
 

Variables

static char blending = 0
 

Macro Definition Documentation

◆ DRAW_LINE_NREG

#define DRAW_LINE_NREG   4

Definition at line 57 of file draw2d.c.

◆ DRAW_LINE_REGLIST

#define DRAW_LINE_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_XYZ2) << 12
#define GIF_REG_RGBAQ
Definition: gif_tags.h:44
#define GIF_REG_PRIM
Definition: gif_tags.h:42
#define GIF_REG_XYZ2
Definition: gif_tags.h:52
unsigned long u64
Definition: tamtypes.h:34

Definition at line 58 of file draw2d.c.

◆ DRAW_POINT_NREG

#define DRAW_POINT_NREG   4

Definition at line 20 of file draw2d.c.

◆ DRAW_POINT_REGLIST

#define DRAW_POINT_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_NOP) << 12
#define GIF_REG_NOP
Definition: gif_tags.h:74

Definition at line 21 of file draw2d.c.

◆ DRAW_RECT_OUT_NREG

#define DRAW_RECT_OUT_NREG   8

Definition at line 148 of file draw2d.c.

◆ DRAW_RECT_OUT_REGLIST

#define DRAW_RECT_OUT_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_XYZ2) << 12 | \
((u64)GIF_REG_XYZ2) << 16 | \
((u64)GIF_REG_XYZ2) << 20 | \
((u64)GIF_REG_XYZ2) << 24 | \
((u64)GIF_REG_NOP) << 28

Definition at line 149 of file draw2d.c.

◆ DRAW_SPRITE_NREG

#define DRAW_SPRITE_NREG   4

Definition at line 190 of file draw2d.c.

◆ DRAW_SPRITE_REGLIST

#define DRAW_SPRITE_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_XYZ2) << 12

Definition at line 191 of file draw2d.c.

◆ DRAW_SPRITE_TEX_NREG

#define DRAW_SPRITE_TEX_NREG   6

Definition at line 215 of file draw2d.c.

◆ DRAW_SPRITE_TEX_REGLIST

#define DRAW_SPRITE_TEX_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_UV) << 8 | \
((u64)GIF_REG_XYZ2) << 12 | \
((u64)GIF_REG_UV) << 16 | \
((u64)GIF_REG_XYZ2) << 20
#define GIF_REG_UV
Definition: gif_tags.h:48

Definition at line 216 of file draw2d.c.

◆ DRAW_TRIANGLE_NREG

#define DRAW_TRIANGLE_NREG   6

Definition at line 117 of file draw2d.c.

◆ DRAW_TRIANGLE_OUT_NREG

#define DRAW_TRIANGLE_OUT_NREG   6

Definition at line 82 of file draw2d.c.

◆ DRAW_TRIANGLE_OUT_REGLIST

#define DRAW_TRIANGLE_OUT_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_XYZ2) << 12 | \
((u64)GIF_REG_XYZ2) << 16 | \
((u64)GIF_REG_XYZ2) << 20

Definition at line 83 of file draw2d.c.

◆ DRAW_TRIANGLE_REGLIST

#define DRAW_TRIANGLE_REGLIST
Value:
((u64)GIF_REG_PRIM) << 0 | \
((u64)GIF_REG_RGBAQ) << 4 | \
((u64)GIF_REG_XYZ2) << 8 | \
((u64)GIF_REG_XYZ2) << 12 | \
((u64)GIF_REG_XYZ2) << 16 | \
((u64)GIF_REG_NOP) << 20

Definition at line 118 of file draw2d.c.

◆ END_OFFSET

#define END_OFFSET   2048.5625f

Definition at line 18 of file draw2d.c.

◆ OFFSET

#define OFFSET   2048.0f

Definition at line 12 of file draw2d.c.

◆ START_OFFSET

#define START_OFFSET   2047.5625f

Definition at line 15 of file draw2d.c.

Function Documentation

◆ draw_arc_filled()

qword_t* draw_arc_filled ( qword_t q,
int  context,
point_t center,
float  radius,
float  angle_start,
float  angle_end 
)

Draws multiple triangle fans

Definition at line 425 of file draw2d.c.

426 {
427 
428  qword_t *giftag;
429 
430  u64 *dw;
431  u64 pdw;
432 
433  int __xi0 = ftoi4(center->v0.x + OFFSET);
434  int __yi0 = ftoi4(center->v0.y + OFFSET);
435  int __xi1;
436  int __yi1;
437  float __arc_radians;
438 
439  // Start primitive
441  q++;
442 
444  q++;
445 
447  q++;
448 
449  giftag = q;
450  q++;
451 
452  dw = (u64*)q;
453 
454  // Fill vertex information
455  *dw++ = GIF_SET_XYZ(__xi0,__yi0,center->v0.z);
456 
457  for( ; angle_start <= angle_end; angle_start++)
458  {
459  __arc_radians = 0.017453293f * angle_start;
460  __xi1 = (int)((cosf(__arc_radians) * radius) * 16.0f);
461  __yi1 = (int)((sinf(__arc_radians) * radius) * 16.0f);
462  *dw++ = GIF_SET_XYZ(__xi0 + __xi1,__yi0 + __yi1,center->v0.z);
463  }
464 
465  // Copy the last vertex if we're uneven
466  if ((u32)dw % 16)
467  {
468 
469  pdw = *(dw-1);
470  *dw++ = pdw;
471 
472  }
473 
474  q = (qword_t*)dw;
475 
476  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
477 
478  return q;
479 
480 }
#define OFFSET
Definition: draw2d.c:12
static char blending
Definition: draw2d.c:27
#define DRAW_XYZ_REGLIST
Definition: draw3d.h:16
u8 context
Definition: main.c:71
#define PRIM_TRIANGLE_FAN
#define ftoi4(F)
Definition: draw_types.h:15
#define GIF_SET_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)
Definition: gif_tags.h:85
#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_SET_XYZ(X, Y, Z)
Definition: gif_tags.h:103
#define GIF_FLG_REGLIST
Definition: gif_tags.h:37
#define GIF_FLG_PACKED
Definition: gif_tags.h:35
vertex_t v0
Definition: draw2d.h:14
color_t color
Definition: draw2d.h:15
float y
Definition: draw_types.h:53
unsigned int z
Definition: draw_types.h:54
float x
Definition: draw_types.h:52
unsigned int u32
Definition: tamtypes.h:30
u64 rgbaq
Definition: draw_types.h:40

References blending, point_t::color, context, DRAW_XYZ_REGLIST, ftoi4, GIF_FLG_PACKED, GIF_FLG_REGLIST, GIF_REG_AD, GIF_REG_PRIM, GIF_REG_RGBAQ, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, OFFSET, PACK_GIFTAG, PRIM_TRIANGLE_FAN, color_t::rgbaq, point_t::v0, vertex_t::x, vertex_t::y, and vertex_t::z.

Referenced by draw_round_rect_filled().

◆ draw_arc_outline()

qword_t* draw_arc_outline ( qword_t q,
int  context,
point_t center,
float  radius,
float  angle_start,
float  angle_end 
)

Draws an arc using line primitives

Definition at line 370 of file draw2d.c.

371 {
372 
373  qword_t *giftag;
374 
375  u64 *dw;
376  u64 pdw;
377 
378  int __xi0 = ftoi4(center->v0.x + OFFSET);
379  int __yi0 = ftoi4(center->v0.y + OFFSET);
380  int __xi1;
381  int __yi1;
382  float __arc_radians;
383 
384  // Start primitive
386  q++;
387 
389  q++;
390 
392  q++;
393 
394  giftag = q;
395  q++;
396 
397  dw = (u64*)q;
398 
399  // Fill vertex information
400  for( ; angle_start <= angle_end; angle_start++)
401  {
402  __arc_radians = angle_start * 0.017453293f;
403  __xi1 = (int)((cosf(__arc_radians) * radius) * 16.0f);
404  __yi1 = (int)((sinf(__arc_radians) * radius) * 16.0f);
405  *dw++ = GIF_SET_XYZ(__xi0 + __xi1,__yi0 + __yi1,center->v0.z);
406  }
407 
408  // Copy the last 64-bits if we haven't completed the last qword
409  if ((u32)dw % 16)
410  {
411 
412  pdw = *(dw-1);
413  *dw++ = pdw;
414 
415  }
416 
417  q = (qword_t*)dw;
418 
419  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
420 
421  return q;
422 
423 }
#define PRIM_LINE_STRIP

References blending, point_t::color, context, DRAW_XYZ_REGLIST, ftoi4, GIF_FLG_PACKED, GIF_FLG_REGLIST, GIF_REG_AD, GIF_REG_PRIM, GIF_REG_RGBAQ, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, OFFSET, PACK_GIFTAG, PRIM_LINE_STRIP, color_t::rgbaq, point_t::v0, vertex_t::x, vertex_t::y, and vertex_t::z.

Referenced by draw_round_rect_outline().

◆ draw_disable_blending()

void draw_disable_blending ( )

Disables alpha blending

Definition at line 34 of file draw2d.c.

35 {
36  blending = 0;
37 }

References blending.

◆ draw_enable_blending()

void draw_enable_blending ( )

Enables alpha blending

Definition at line 29 of file draw2d.c.

30 {
31  blending = 1;
32 }

References blending.

◆ draw_line()

qword_t* draw_line ( qword_t q,
int  context,
line_t line 
)

Draws a single line

Definition at line 64 of file draw2d.c.

65 {
66 
68  q++;
69 
70  q->dw[0] = GIF_SET_PRIM(PRIM_LINE,0,0,0,blending,0,0,context,0);
71  q->dw[1] = line->color.rgbaq;
72  q++;
73 
74  q->dw[0] = GIF_SET_XYZ(ftoi4(line->v0.x + START_OFFSET),ftoi4(line->v0.y + START_OFFSET),line->v0.z);
75  q->dw[1] = GIF_SET_XYZ(ftoi4(line->v1.x + END_OFFSET),ftoi4(line->v1.y + END_OFFSET),line->v0.z);
76  q++;
77 
78  return q;
79 
80 }
#define START_OFFSET
Definition: draw2d.c:15
#define DRAW_LINE_REGLIST
Definition: draw2d.c:58
#define END_OFFSET
Definition: draw2d.c:18
#define DRAW_LINE_NREG
Definition: draw2d.c:57
#define PRIM_LINE
color_t color
Definition: draw2d.h:21
vertex_t v0
Definition: draw2d.h:19
vertex_t v1
Definition: draw2d.h:20
u64 dw[2]
Definition: tamtypes.h:85

References blending, line_t::color, context, DRAW_LINE_NREG, DRAW_LINE_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, PACK_GIFTAG, PRIM_LINE, color_t::rgbaq, START_OFFSET, line_t::v0, line_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

Referenced by draw_round_rect_outline().

◆ draw_point()

qword_t* draw_point ( qword_t q,
int  context,
point_t point 
)

Draws a single point

Definition at line 39 of file draw2d.c.

40 {
41 
43  q++;
44 
45  q->dw[0] = GIF_SET_PRIM(PRIM_POINT,0,0,0,blending,0,0,context,0);
46  q->dw[1] = point->color.rgbaq;
47  q++;
48 
49  q->dw[0] = GIF_SET_XYZ(ftoi4(point->v0.x + OFFSET),ftoi4(point->v0.y + OFFSET),point->v0.z);
50  q->dw[1] = 0;
51  q++;
52 
53  return q;
54 
55 }
#define DRAW_POINT_REGLIST
Definition: draw2d.c:21
#define DRAW_POINT_NREG
Definition: draw2d.c:20
#define PRIM_POINT

References blending, point_t::color, context, DRAW_POINT_NREG, DRAW_POINT_REGLIST, qword_t::dw, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, OFFSET, PACK_GIFTAG, PRIM_POINT, color_t::rgbaq, point_t::v0, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_rect_filled()

qword_t* draw_rect_filled ( qword_t q,
int  context,
rect_t rect 
)

Draws a single sprite

Definition at line 197 of file draw2d.c.

198 {
199 
201  q++;
202 
203  q->dw[0] = GIF_SET_PRIM(PRIM_SPRITE,0,0,0,blending,0,0,context,0);
204  q->dw[1] = rect->color.rgbaq;
205  q++;
206 
207  q->dw[0] = GIF_SET_XYZ(ftoi4(rect->v0.x + START_OFFSET),ftoi4(rect->v0.y + START_OFFSET),rect->v0.z);
208  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v1.x + END_OFFSET),ftoi4(rect->v1.y + END_OFFSET),rect->v0.z);
209  q++;
210 
211  return q;
212 
213 }
#define DRAW_SPRITE_NREG
Definition: draw2d.c:190
#define DRAW_SPRITE_REGLIST
Definition: draw2d.c:191
#define PRIM_SPRITE
vertex_t v1
Definition: draw2d.h:33
color_t color
Definition: draw2d.h:34
vertex_t v0
Definition: draw2d.h:32

References blending, rect_t::color, context, DRAW_SPRITE_NREG, DRAW_SPRITE_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, PACK_GIFTAG, PRIM_SPRITE, color_t::rgbaq, START_OFFSET, rect_t::v0, rect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

Referenced by draw_round_rect_filled().

◆ draw_rect_filled_strips()

qword_t* draw_rect_filled_strips ( qword_t q,
int  context,
rect_t rect 
)

Draws multiple sprite primitives

Definition at line 248 of file draw2d.c.

249 {
250 
251  qword_t *giftag;
252 
253  int __xi0 = ftoi4(rect->v0.x);
254  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
255 
256  int __xi1 = ftoi4(rect->v1.x);
257  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
258 
259  // Start primitive
261  q++;
262 
264  q++;
265 
267  q++;
268 
269  giftag = q;
270  q++;
271 
272  // Fill vertex information in 32 pixel wide strips
273  while(__xi0 < __xi1)
274  {
275 
276  //q->dw[0] = GIF_SET_XYZ(ftoi4(__xf0 + START_OFFSET),__yi0,rect->v0.z);
277  q->dw[0] = GIF_SET_XYZ(__xi0 + ftoi4(START_OFFSET),__yi0,rect->v0.z);
278 
279  // 31<<4
280  __xi0 += 496;
281 
282  // Uneven...
283  if (__xi0 >= __xi1)
284  {
285  __xi0 = __xi1;
286  }
287 
288  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(END_OFFSET),__yi1,rect->v0.z);
289 
290  // 1<<4
291  __xi0 += 16;
292 
293  q++;
294 
295  }
296 
297  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_XYZ_REGLIST);
298 
299  return q;
300 
301 }

References blending, rect_t::color, context, DRAW_XYZ_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_PACKED, GIF_FLG_REGLIST, GIF_REG_AD, GIF_REG_PRIM, GIF_REG_RGBAQ, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, PACK_GIFTAG, PRIM_SPRITE, color_t::rgbaq, START_OFFSET, rect_t::v0, rect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

Referenced by draw_clear(), and draw_round_rect_filled().

◆ draw_rect_outline()

qword_t* draw_rect_outline ( qword_t q,
int  context,
rect_t rect 
)

Draws a rectangle using line primitives

Definition at line 159 of file draw2d.c.

160 {
161 
162  int __xi0 = ftoi4(rect->v0.x + START_OFFSET);
163  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
164  int __xi1 = ftoi4(rect->v1.x + END_OFFSET);
165  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
166 
168  q++;
169 
170  q->dw[0] = GIF_SET_PRIM(PRIM_LINE_STRIP,0,0,0,blending,0,0,context,0);
171  q->dw[1] = rect->color.rgbaq;
172  q++;
173 
174  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,rect->v0.z);
175  q->dw[1] = GIF_SET_XYZ(__xi1,__yi0,rect->v0.z);
176  q++;
177 
178  q->dw[0] = GIF_SET_XYZ(__xi1,__yi1,rect->v0.z);
179  q->dw[1] = GIF_SET_XYZ(__xi0,__yi1,rect->v0.z);
180  q++;
181 
182  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,rect->v0.z);
183  q->dw[1] = 0;
184  q++;
185 
186  return q;
187 
188 }
#define DRAW_RECT_OUT_NREG
Definition: draw2d.c:148
#define DRAW_RECT_OUT_REGLIST
Definition: draw2d.c:149

References blending, rect_t::color, context, DRAW_RECT_OUT_NREG, DRAW_RECT_OUT_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, PACK_GIFTAG, PRIM_LINE_STRIP, color_t::rgbaq, START_OFFSET, rect_t::v0, rect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_rect_textured()

qword_t* draw_rect_textured ( qword_t q,
int  context,
texrect_t rect 
)

Draws a single texture mapped sprite

Definition at line 224 of file draw2d.c.

225 {
226 
227  // Start primitive
229  q++;
230 
231  // Fill vertex information
233  q->dw[1] = rect->color.rgbaq;
234  q++;
235 
236  q->dw[0] = GIF_SET_UV(ftoi4(rect->t0.u),ftoi4(rect->t0.v));
237  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v0.x + START_OFFSET),ftoi4(rect->v0.y + START_OFFSET),rect->v0.z);
238  q++;
239 
240  q->dw[0] = GIF_SET_UV(ftoi4(rect->t1.u),ftoi4(rect->t1.v));
241  q->dw[1] = GIF_SET_XYZ(ftoi4(rect->v1.x + END_OFFSET),ftoi4(rect->v1.y + END_OFFSET),rect->v0.z);
242  q++;
243 
244  return q;
245 
246 }
#define DRAW_SPRITE_TEX_NREG
Definition: draw2d.c:215
#define DRAW_SPRITE_TEX_REGLIST
Definition: draw2d.c:216
#define DRAW_ENABLE
Definition: draw.h:25
#define PRIM_MAP_UV
#define GIF_SET_UV(U, V)
Definition: gif_tags.h:100
vertex_t v0
Definition: draw2d.h:38
color_t color
Definition: draw2d.h:42
texel_t t1
Definition: draw2d.h:41
vertex_t v1
Definition: draw2d.h:40
texel_t t0
Definition: draw2d.h:39
float u
Definition: draw_types.h:34
float v
Definition: draw_types.h:35

References blending, texrect_t::color, context, DRAW_ENABLE, DRAW_SPRITE_TEX_NREG, DRAW_SPRITE_TEX_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_UV, GIF_SET_XYZ, PACK_GIFTAG, PRIM_MAP_UV, PRIM_SPRITE, color_t::rgbaq, START_OFFSET, texrect_t::t0, texrect_t::t1, texel_t::u, texel_t::v, texrect_t::v0, texrect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_rect_textured_strips()

qword_t* draw_rect_textured_strips ( qword_t q,
int  context,
texrect_t rect 
)

Draws multiple strips to render a large texture width must be multiple of 32 - 0.9375

Definition at line 303 of file draw2d.c.

304 {
305 
306  qword_t *giftag;
307 
308  // Texel coordinates
309  float __uf0 = rect->t0.u;
310  int __vi0 = ftoi4(rect->t0.v);
311  int __vi1 = ftoi4(rect->t1.v);
312 
313  // Primitive coordinates
314  int __xi0 = ftoi4(rect->v0.x);
315  int __yi0 = ftoi4(rect->v0.y + START_OFFSET);
316 
317  int __xi1 = ftoi4(rect->v1.x);
318  int __yi1 = ftoi4(rect->v1.y + END_OFFSET);
319  float strip = 0.0f;
320 
321  // Start primitive
323  q++;
324 
326  q++;
327 
329  q++;
330 
331  giftag = q;
332  q++;
333 
334  // Fill vertex information in 32 pixel wide strips along with texel information
335  while(__xi0 < __xi1)
336  {
337 
338  q->dw[0] = GIF_SET_UV(ftoi4(__uf0),__vi0);
339  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(START_OFFSET),__yi0,rect->v0.z);
340  q++;
341 
342  // Due to the GS DDA, 0-32 only draws pixels 0-31
343  // Due to the above, texels 0.5 - 30.5 will map 0-31
344 
345  strip += 32.0f;
346 
347  __xi0 += 496;
348 
349  if (__xi0 >= __xi1)
350  {
351  __xi0 = __xi1;
352  }
353 
354  __uf0 = rect->t0.u + (strip - 1.5f);
355 
356  q->dw[0] = GIF_SET_UV(ftoi4(__uf0),__vi1);
357  q->dw[1] = GIF_SET_XYZ(__xi0 + ftoi4(END_OFFSET),__yi1,rect->v0.z);
358 
359  __xi0 += 16;
360  q++;
361 
362  }
363 
364  PACK_GIFTAG(giftag,GIF_SET_TAG(q-giftag-1,0,0,0,GIF_FLG_REGLIST,2),DRAW_UV_REGLIST);
365 
366  return q;
367 
368 }
#define DRAW_UV_REGLIST
Definition: draw3d.h:24

References blending, texrect_t::color, context, DRAW_ENABLE, DRAW_UV_REGLIST, qword_t::dw, END_OFFSET, ftoi4, GIF_FLG_PACKED, GIF_FLG_REGLIST, GIF_REG_AD, GIF_REG_PRIM, GIF_REG_RGBAQ, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_UV, GIF_SET_XYZ, PACK_GIFTAG, PRIM_MAP_UV, PRIM_SPRITE, color_t::rgbaq, START_OFFSET, texrect_t::t0, texrect_t::t1, texel_t::u, texel_t::v, texrect_t::v0, texrect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_round_rect_filled()

qword_t* draw_round_rect_filled ( qword_t q,
int  context,
rect_t rect 
)

Draws filled round rectangle, buggy with partial coordinates

Definition at line 482 of file draw2d.c.

483 {
484 
485  rect_t rect_center;
486  rect_t rect_side;
487  point_t point_corner;
488 
489  int center_width;
490  int center_height;
491 
492  float corner_size = 15.0f;
493 
494  int width = rect->v1.x - rect->v0.x;
495  int height = rect->v1.y - rect->v0.y;
496 
497  center_width = width - (int)(2.0f*corner_size);
498  center_height = height - (int)(2.0f*corner_size);
499 
500  rect_center.color = rect->color;
501  rect_side.color = rect->color;
502  rect_center.v0.z = rect->v0.z;
503  rect_side.v0.z = rect->v0.z;
504 
505  // Inside rectangle
506  rect_center.v0.x = rect->v0.x + corner_size;
507  rect_center.v0.y = rect->v0.y + corner_size;
508  rect_center.v1.x = rect_center.v0.x + (float)center_width;
509  rect_center.v1.y = rect_center.v0.y + (float)center_height;
510 
511  q = draw_rect_filled_strips(q,context,&rect_center);
512 
513  // sides
514  // top
515  rect_side.v0.x = rect_center.v0.x;
516  rect_side.v0.y = rect_center.v0.y - corner_size;
517  rect_side.v1.x = rect_center.v1.x;
518  rect_side.v1.y = rect_center.v0.y - 1.0f;
519 
520  q = draw_rect_filled_strips(q,context,&rect_side);
521 
522  // right
523  rect_side.v0.x = rect_center.v1.x + 1.0f;
524  rect_side.v0.y = rect_center.v0.y;
525  rect_side.v1.x = rect_center.v1.x + corner_size;
526  rect_side.v1.y = rect_center.v1.y;
527 
528  q = draw_rect_filled(q,context,&rect_side);
529 
530  // bottom
531  rect_side.v0.x = rect_center.v0.x;
532  rect_side.v0.y = rect_center.v1.y + 1.0f;
533  rect_side.v1.x = rect_center.v1.x;
534  rect_side.v1.y = rect_center.v1.y + corner_size;
535 
536  q = draw_rect_filled_strips(q,context,&rect_side);
537 
538  // left
539  rect_side.v0.x = rect_center.v0.x - corner_size;
540  rect_side.v0.y = rect_center.v0.y;
541  rect_side.v1.x = rect_center.v0.x - 1.0f;
542  rect_side.v1.y = rect_center.v1.y;
543 
544  q = draw_rect_filled(q,context,&rect_side);
545 
546  // corners
547  // top right
548  point_corner.v0.x = rect_center.v1.x + 1.0f;
549  point_corner.v0.y = rect_center.v0.y;
550  point_corner.color = rect->color;
551 
552  q = draw_arc_filled(q,context,&point_corner,corner_size,270.0f,360.0f);
553 
554  // bottom right
555  point_corner.v0.x = rect_center.v1.x + 1.0f;
556  point_corner.v0.y = rect_center.v1.y + 1.0f;
557  point_corner.color = rect->color;
558 
559  q = draw_arc_filled(q,context,&point_corner,corner_size,0.0f,90.0f);
560 
561  // bottom left
562  point_corner.v0.x = rect_center.v0.x;
563  point_corner.v0.y = rect_center.v1.y + 1.0f;
564  point_corner.color = rect->color;
565 
566  q = draw_arc_filled(q,context,&point_corner,corner_size,90.0f,180.0f);
567 
568  // top left
569  point_corner.v0.x = rect_center.v0.x;
570  point_corner.v0.y = rect_center.v0.y;
571  point_corner.color = rect->color;
572 
573  q = draw_arc_filled(q,context,&point_corner,corner_size,180.0f,270.0f);
574 
575  return q;
576 
577 }
qword_t * draw_rect_filled(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:197
qword_t * draw_arc_filled(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
Definition: draw2d.c:425
qword_t * draw_rect_filled_strips(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:248
Definition: draw2d.h:13
Definition: draw2d.h:31

References point_t::color, rect_t::color, context, draw_arc_filled(), draw_rect_filled(), draw_rect_filled_strips(), point_t::v0, rect_t::v0, rect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_round_rect_outline()

qword_t* draw_round_rect_outline ( qword_t q,
int  context,
rect_t rect 
)

Draws a hollow round rectangle, buggy with partial coordinates

Definition at line 579 of file draw2d.c.

580 {
581 
582  rect_t rect_center;
583  line_t line_side;
584  point_t point_corner;
585 
586  int center_width;
587  int center_height;
588 
589  float corner_size = 15.0f;
590 
591  int width = rect->v1.x - rect->v0.x;
592  int height = rect->v1.y - rect->v0.y;
593 
594  center_width = width - (int)(2.0f*corner_size);
595  center_height = height - (int)(2.0f*corner_size);
596 
597  rect_center.color = rect->color;
598  line_side.color = rect->color;
599  rect_center.v0.z = rect->v0.z;
600  line_side.v0.z = rect->v0.z;
601 
602  // Inside rectangle
603  rect_center.v0.x = rect->v0.x + corner_size;
604  rect_center.v0.y = rect->v0.y + corner_size;
605  rect_center.v1.x = rect_center.v0.x + (float)center_width;
606  rect_center.v1.y = rect_center.v0.y + (float)center_height;
607 
608  //q = draw_rect_filled_strips(q,context,&rect_center);
609 
610  // sides
611  // top
612  line_side.v0.x = rect_center.v0.x;
613  line_side.v0.y = rect_center.v0.y - corner_size + 1.0f;
614  line_side.v1.x = rect_center.v1.x;
615  line_side.v1.y = rect_center.v0.y - corner_size;
616 
617  q = draw_line(q,context,&line_side);
618 
619  // right
620  line_side.v0.x = rect_center.v1.x + corner_size;
621  line_side.v0.y = rect_center.v0.y;
622  line_side.v1.x = rect_center.v1.x + corner_size - 1.0f;
623  line_side.v1.y = rect_center.v1.y;
624 
625  q = draw_line(q,context,&line_side);
626 
627  // bottom
628  line_side.v0.x = rect_center.v0.x;
629  line_side.v0.y = rect_center.v1.y + corner_size + 1.0f;
630  line_side.v1.x = rect_center.v1.x;
631  line_side.v1.y = rect_center.v1.y + corner_size;
632 
633  q = draw_line(q,context,&line_side);
634 
635  // left
636  line_side.v0.x = rect_center.v0.x - corner_size;
637  line_side.v0.y = rect_center.v0.y;
638  line_side.v1.x = rect_center.v0.x - corner_size - 1.0f;
639  line_side.v1.y = rect_center.v1.y;
640 
641  q = draw_line(q,context,&line_side);
642 
643  // corners
644  // top right
645  point_corner.v0.x = rect_center.v1.x;
646  point_corner.v0.y = rect_center.v0.y;
647  point_corner.color = rect->color;
648 
649  q = draw_arc_outline(q,context,&point_corner,corner_size,270.0f,360.0f);
650 
651  // bottom right
652  point_corner.v0.x = rect_center.v1.x;
653  point_corner.v0.y = rect_center.v1.y;
654  point_corner.color = rect->color;
655 
656  q = draw_arc_outline(q,context,&point_corner,corner_size,0.0f,90.0f);
657 
658  // bottom left
659  point_corner.v0.x = rect_center.v0.x;
660  point_corner.v0.y = rect_center.v1.y;
661  point_corner.color = rect->color;
662 
663  q = draw_arc_outline(q,context,&point_corner,corner_size,90.0f,180.0f);
664 
665  // top left
666  point_corner.v0.x = rect_center.v0.x;
667  point_corner.v0.y = rect_center.v0.y;
668  point_corner.color = rect->color;
669 
670  q = draw_arc_outline(q,context,&point_corner,corner_size,180.0f,270.0f);
671 
672  return q;
673 
674 }
qword_t * draw_line(qword_t *q, int context, line_t *line)
Definition: draw2d.c:64
qword_t * draw_arc_outline(qword_t *q, int context, point_t *center, float radius, float angle_start, float angle_end)
Definition: draw2d.c:370
Definition: draw2d.h:18

References point_t::color, line_t::color, rect_t::color, context, draw_arc_outline(), draw_line(), point_t::v0, line_t::v0, rect_t::v0, line_t::v1, rect_t::v1, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_triangle_filled()

qword_t* draw_triangle_filled ( qword_t q,
int  context,
triangle_t triangle 
)

Draws a single triangle

Definition at line 126 of file draw2d.c.

127 {
128 
130  q++;
131 
132  q->dw[0] = GIF_SET_PRIM(PRIM_TRIANGLE,0,0,0,blending,0,0,context,0);
133  q->dw[1] = triangle->color.rgbaq;
134  q++;
135 
136  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v0.x + OFFSET),ftoi4(triangle->v0.y + OFFSET),triangle->v0.z);
137  q->dw[1] = GIF_SET_XYZ(ftoi4(triangle->v1.x + OFFSET ),ftoi4(triangle->v1.y + OFFSET),triangle->v0.z);
138  q++;
139 
140  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v2.x + OFFSET),ftoi4(triangle->v2.y + OFFSET),triangle->v0.z);
141  q->dw[1] = 0;
142  q++;
143 
144  return q;
145 
146 }
#define DRAW_TRIANGLE_REGLIST
Definition: draw2d.c:118
#define DRAW_TRIANGLE_NREG
Definition: draw2d.c:117
#define PRIM_TRIANGLE
vertex_t v2
Definition: draw2d.h:27
vertex_t v1
Definition: draw2d.h:26
vertex_t v0
Definition: draw2d.h:25
color_t color
Definition: draw2d.h:28

References blending, triangle_t::color, context, DRAW_TRIANGLE_NREG, DRAW_TRIANGLE_REGLIST, qword_t::dw, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, OFFSET, PACK_GIFTAG, PRIM_TRIANGLE, color_t::rgbaq, triangle_t::v0, triangle_t::v1, triangle_t::v2, vertex_t::x, vertex_t::y, and vertex_t::z.

◆ draw_triangle_outline()

qword_t* draw_triangle_outline ( qword_t q,
int  context,
triangle_t triangle 
)

Draws a triangle using a line strip

Definition at line 91 of file draw2d.c.

92 {
93 
94  int __xi0 = ftoi4(triangle->v0.x + OFFSET);
95  int __yi0 = ftoi4(triangle->v0.y + OFFSET);
96 
98  q++;
99 
100  q->dw[0] = GIF_SET_PRIM(PRIM_LINE_STRIP,0,0,0,blending,0,0,context,0);
101  q->dw[1] = triangle->color.rgbaq;
102  q++;
103 
104  q->dw[0] = GIF_SET_XYZ(__xi0,__yi0,triangle->v0.z);
105  q->dw[1] = GIF_SET_XYZ(ftoi4(triangle->v1.x + OFFSET),ftoi4(triangle->v1.y + OFFSET),triangle->v0.z);
106  q++;
107 
108  q->dw[0] = GIF_SET_XYZ(ftoi4(triangle->v2.x + OFFSET),ftoi4(triangle->v2.y + OFFSET),triangle->v0.z);
109  q->dw[1] = GIF_SET_XYZ(__xi0,__yi0,triangle->v0.z);
110  q++;
111 
112 
113  return q;
114 
115 }
#define DRAW_TRIANGLE_OUT_NREG
Definition: draw2d.c:82
#define DRAW_TRIANGLE_OUT_REGLIST
Definition: draw2d.c:83

References blending, triangle_t::color, context, DRAW_TRIANGLE_OUT_NREG, DRAW_TRIANGLE_OUT_REGLIST, qword_t::dw, ftoi4, GIF_FLG_REGLIST, GIF_SET_PRIM, GIF_SET_TAG, GIF_SET_XYZ, OFFSET, PACK_GIFTAG, PRIM_LINE_STRIP, color_t::rgbaq, triangle_t::v0, triangle_t::v1, triangle_t::v2, vertex_t::x, vertex_t::y, and vertex_t::z.

Variable Documentation

◆ blending