ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
draw.h File Reference
#include <tamtypes.h>
#include <draw_blending.h>
#include <draw_buffers.h>
#include <draw_dithering.h>
#include <draw_fog.h>
#include <draw_masking.h>
#include <draw_primitives.h>
#include <draw_sampling.h>
#include <draw_tests.h>
#include <draw_types.h>
#include <draw2d.h>
#include <draw3d.h>
+ Include dependency graph for draw.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DRAW_DISABLE   0
 
#define DRAW_ENABLE   1
 

Functions

qword_tdraw_setup_environment (qword_t *q, int context, framebuffer_t *frame, zbuffer_t *z)
 
qword_tdraw_clear (qword_t *q, int context, float x, float y, float width, float height, int r, int g, int b)
 
qword_tdraw_finish (qword_t *q)
 
void draw_wait_finish (void)
 
qword_tdraw_texture_transfer (qword_t *q, void *src, int width, int height, int psm, int dest, int dest_width)
 
qword_tdraw_texture_flush (qword_t *q)
 

Detailed Description

Draw library main functions

Definition in file draw.h.

Macro Definition Documentation

◆ DRAW_DISABLE

#define DRAW_DISABLE   0

Definition at line 24 of file draw.h.

◆ DRAW_ENABLE

#define DRAW_ENABLE   1

Definition at line 25 of file draw.h.

Function Documentation

◆ draw_clear()

qword_t* draw_clear ( qword_t q,
int  context,
float  x,
float  y,
float  width,
float  height,
int  r,
int  g,
int  b 
)

Clear the screen based on the screen's origin, width, and height using the defined color.

Definition at line 148 of file draw.c.

149 {
150 
151  rect_t rect;
152 
153  union{
154  float fvalue;
155  u32 ivalue;
156  } q0 = {
157  1.0f
158  };
159 
160  rect.v0.x = x;
161  rect.v0.y = y;
162  rect.v0.z = 0x00000000;
163 
164  rect.color.rgbaq = GS_SET_RGBAQ(r,g,b,0x80,q0.ivalue);
165 
166  rect.v1.x = x + width - 0.9375f;
167  rect.v1.y = y + height - 0.9375f;
168  rect.v1.z = 0x00000000;
169 
170  PACK_GIFTAG(q, GIF_SET_TAG(2,0,0,0,0,1), GIF_REG_AD);
171  q++;
173  q++;
174  PACK_GIFTAG(q, GS_SET_PRMODE(0,0,0,0,0,0,context,1), GS_REG_PRMODE);
175  q++;
176 
177  q = draw_rect_filled_strips(q, context, &rect);
178 
179  PACK_GIFTAG(q, GIF_SET_TAG(1,0,0,0,0,1), GIF_REG_AD);
180  q++;
182  q++;
183 
184  return q;
185 
186 }
qword_t * draw_rect_filled_strips(qword_t *q, int context, rect_t *rect)
Definition: draw2d.c:248
u8 context
Definition: main.c:71
#define PRIM_OVERRIDE_ENABLE
#define PRIM_OVERRIDE_DISABLE
#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 GS_SET_PRMODECONT(CTRL)
Definition: gs_gp.h:250
#define GS_REG_PRMODECONT
Definition: gs_gp.h:61
#define GS_SET_PRMODE(IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)
Definition: gs_gp.h:244
#define GS_SET_RGBAQ(R, G, B, A, Q)
Definition: gs_gp.h:252
#define GS_REG_PRMODE
Definition: gs_gp.h:63
s32 x
Definition: libmouse.c:34
s32 y
Definition: libmouse.c:34
Definition: draw2d.h:31
vertex_t v1
Definition: draw2d.h:33
color_t color
Definition: draw2d.h:34
vertex_t v0
Definition: draw2d.h:32
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 rect_t::color, context, draw_rect_filled_strips(), GIF_REG_AD, GIF_SET_TAG, GS_REG_PRMODE, GS_REG_PRMODECONT, GS_SET_PRMODE, GS_SET_PRMODECONT, GS_SET_RGBAQ, PACK_GIFTAG, PRIM_OVERRIDE_DISABLE, PRIM_OVERRIDE_ENABLE, color_t::rgbaq, rect_t::v0, rect_t::v1, vertex_t::x, x, vertex_t::y, y, and vertex_t::z.

Referenced by clear_screen(), main(), render(), and run_demo().

◆ draw_finish()

qword_t* draw_finish ( qword_t q)

Signal that drawing is finished

Definition at line 188 of file draw.c.

189 {
190 
192  q++;
194  q++;
195 
196  return q;
197 
198 }
#define GIF_FLG_PACKED
Definition: gif_tags.h:35
#define GS_REG_FINISH
Definition: gs_gp.h:143

References GIF_FLG_PACKED, GIF_REG_AD, GIF_SET_TAG, GS_REG_FINISH, and PACK_GIFTAG.

Referenced by clear_screen(), draw_init_env(), flip_buffers(), init_drawing_environment(), render(), and run_demo().

◆ draw_setup_environment()

qword_t* draw_setup_environment ( qword_t q,
int  context,
framebuffer_t frame,
zbuffer_t z 
)

Sets up the drawing environment based on the framebuffer and zbuffer settings

Definition at line 11 of file draw.c.

12 {
13 
14  // Change this if modifying the gif packet after the giftag.
15  int qword_count = 15;
16 
17  atest_t atest;
18  dtest_t dtest;
19  ztest_t ztest;
20  blend_t blend;
21  texwrap_t wrap;
22 
23  atest.enable = DRAW_ENABLE;
25  atest.compval = 0x00;
27 
28  dtest.enable = DRAW_DISABLE;
29  dtest.pass = DRAW_DISABLE;
30 
31  // Enable or Disable ZBuffer
32  if (z->enable)
33  {
34  ztest.enable = DRAW_ENABLE;
35  ztest.method = z->method;
36  }
37  else
38  {
39  z->mask = 1;
40  ztest.enable = DRAW_ENABLE;
42  }
43 
44  // Setup alpha blending
45  blend.color1 = BLEND_COLOR_SOURCE;
46  blend.color2 = BLEND_COLOR_DEST;
47  blend.alpha = BLEND_ALPHA_SOURCE;
48  blend.color3 = BLEND_COLOR_DEST;
49  blend.fixed_alpha = 0x80;
50 
51  // Setup whole texture clamping
52  wrap.horizontal = WRAP_CLAMP;
53  wrap.vertical = WRAP_CLAMP;
54  wrap.minu = wrap.maxu = 0;
55  wrap.minv = wrap.maxv = 0;
56 
57  // Begin packed gif data packet with another qword.
58  PACK_GIFTAG(q,GIF_SET_TAG(qword_count,0,0,0,GIF_FLG_PACKED,1),GIF_REG_AD);
59  q++;
60  // Framebuffer setting
61  PACK_GIFTAG(q, GS_SET_FRAME(frame->address>>11,frame->width>>6,frame->psm,frame->mask), GS_REG_FRAME + context);
62  q++;
63  // ZBuffer setting
65  q++;
66  // Override Primitive Control
68  q++;
69  // Primitive coordinate offsets
71  q++;
72  // Scissoring area
73  PACK_GIFTAG(q, GS_SET_SCISSOR(0,frame->width-1,0,frame->height-1), GS_REG_SCISSOR + context);
74  q++;
75  // Pixel testing
76  PACK_GIFTAG(q, GS_SET_TEST(atest.enable,atest.method,atest.compval,atest.keep,
77  dtest.enable,dtest.pass,
78  ztest.enable,ztest.method), GS_REG_TEST + context);
79  q++;
80  // Fog Color
82  q++;
83  // Per-pixel Alpha Blending (Blends if MSB of ALPHA is true)
85  q++;
86  // Alpha Blending
87  PACK_GIFTAG(q, GS_SET_ALPHA(blend.color1,blend.color2,blend.alpha,
88  blend.color3,blend.fixed_alpha), GS_REG_ALPHA + context);
89  q++;
90  // Dithering
92  q++;
93  PACK_GIFTAG(q, GS_SET_DIMX(4,2,5,3,0,6,1,7,5,3,4,2,1,7,0,6), GS_REG_DIMX);
94  q++;
95  // Color Clamp
97  q++;
98  // Alpha Correction
99  if ((frame->psm == GS_PSM_16) || (frame->psm == GS_PSM_16S))
100  {
102  q++;
103  }
104  else
105  {
107  q++;
108  }
109  // Texture wrapping/clamping
110  PACK_GIFTAG(q, GS_SET_CLAMP(wrap.horizontal,wrap.vertical,wrap.minu,
111  wrap.maxu,wrap.minv,wrap.maxv), GS_REG_CLAMP + context);
112  q++;
114  q++;
115 
116  return q;
117 
118 }
#define DRAW_ENABLE
Definition: draw.h:25
#define DRAW_DISABLE
Definition: draw.h:24
#define BLEND_COLOR_DEST
Definition: draw_blending.h:15
#define BLEND_ALPHA_SOURCE
Definition: draw_blending.h:18
#define ALPHA_CORRECT_RGBA16
Definition: draw_blending.h:24
#define ALPHA_CORRECT_RGBA32
Definition: draw_blending.h:23
#define BLEND_COLOR_SOURCE
Definition: draw_blending.h:14
#define WRAP_CLAMP
Definition: draw_sampling.h:31
#define ALPHA_EXPAND_NORMAL
Definition: draw_sampling.h:36
#define ATEST_KEEP_FRAMEBUFFER
Definition: draw_tests.h:24
#define ATEST_METHOD_NOTEQUAL
Definition: draw_tests.h:20
#define ZTEST_METHOD_ALLPASS
Definition: draw_tests.h:33
#define ftoi4(F)
Definition: draw_types.h:15
#define GS_SET_TEXA(A0, AM, A1)
Definition: gs_gp.h:300
#define GS_REG_SCISSOR
Definition: gs_gp.h:87
#define GS_REG_DTHE
Definition: gs_gp.h:101
#define GS_REG_ZBUF
Definition: gs_gp.h:125
#define GS_SET_DTHE(ENABLE)
Definition: gs_gp.h:197
#define GS_SET_DIMX(D00, D01, D02, D03, D10, D11, D12, D13, D20, D21, D22, D23, D30, D31, D32, D33)
Definition: gs_gp.h:187
#define GS_REG_FBA
Definition: gs_gp.h:113
#define GS_SET_XYOFFSET(X, Y)
Definition: gs_gp.h:323
#define GS_SET_COLCLAMP(CLAMP)
Definition: gs_gp.h:185
#define GS_REG_TEXA
Definition: gs_gp.h:81
#define GS_SET_FRAME(FBA, FBW, PSM, FMSK)
Definition: gs_gp.h:209
#define GS_REG_CLAMP
Definition: gs_gp.h:31
#define GS_REG_TEST
Definition: gs_gp.h:105
#define GS_REG_DIMX
Definition: gs_gp.h:99
#define GS_SET_ZBUF(ZBA, ZSM, ZMSK)
Definition: gs_gp.h:334
#define GS_SET_SCISSOR(X0, X1, Y0, Y1)
Definition: gs_gp.h:259
#define GS_SET_TEST(ATEN, ATMETH, ATREF, ATFAIL, DATEN, DATMD, ZTEN, ZTMETH)
Definition: gs_gp.h:269
#define GS_SET_FOGCOL(R, G, B)
Definition: gs_gp.h:205
#define GS_SET_CLAMP(WMS, WMT, MINU, MAXU, MINV, MAXV)
Definition: gs_gp.h:180
#define GS_REG_FOGCOL
Definition: gs_gp.h:83
#define GS_REG_XYOFFSET
Definition: gs_gp.h:55
#define GS_REG_PABE
Definition: gs_gp.h:111
#define GS_SET_PABE(ENABLE)
Definition: gs_gp.h:235
#define GS_REG_COLCLAMP
Definition: gs_gp.h:103
#define GS_REG_FRAME
Definition: gs_gp.h:119
#define GS_SET_ALPHA(A, B, C, D, ALPHA)
Definition: gs_gp.h:170
#define GS_SET_FBA(ALPHA)
Definition: gs_gp.h:199
#define GS_REG_ALPHA
Definition: gs_gp.h:93
#define GS_PSM_16S
Definition: gs_psm.h:17
#define GS_PSM_16
Definition: gs_psm.h:15
#define GS_ENABLE
Definition: libgs.h:63
#define GS_DISABLE
Definition: libgs.h:62
unsigned char compval
Definition: draw_tests.h:40
unsigned char enable
Definition: draw_tests.h:38
unsigned char method
Definition: draw_tests.h:39
unsigned char keep
Definition: draw_tests.h:41
char alpha
Definition: draw_blending.h:29
unsigned char fixed_alpha
Definition: draw_blending.h:31
char color3
Definition: draw_blending.h:30
char color2
Definition: draw_blending.h:28
char color1
Definition: draw_blending.h:27
unsigned char pass
Definition: draw_tests.h:46
unsigned char enable
Definition: draw_tests.h:45
unsigned int address
Definition: draw_buffers.h:41
unsigned int height
Definition: draw_buffers.h:43
unsigned int psm
Definition: draw_buffers.h:44
unsigned int mask
Definition: draw_buffers.h:45
unsigned int width
Definition: draw_buffers.h:42
unsigned char vertical
Definition: draw_sampling.h:60
unsigned char horizontal
Definition: draw_sampling.h:59
unsigned int mask
Definition: draw_buffers.h:53
unsigned int method
Definition: draw_buffers.h:50
unsigned int address
Definition: draw_buffers.h:51
unsigned int enable
Definition: draw_buffers.h:49
unsigned int zsm
Definition: draw_buffers.h:52
unsigned char method
Definition: draw_tests.h:51
unsigned char enable
Definition: draw_tests.h:50

References framebuffer_t::address, zbuffer_t::address, blend_t::alpha, ALPHA_CORRECT_RGBA16, ALPHA_CORRECT_RGBA32, ALPHA_EXPAND_NORMAL, ATEST_KEEP_FRAMEBUFFER, ATEST_METHOD_NOTEQUAL, BLEND_ALPHA_SOURCE, BLEND_COLOR_DEST, BLEND_COLOR_SOURCE, blend_t::color1, blend_t::color2, blend_t::color3, atest_t::compval, context, DRAW_DISABLE, DRAW_ENABLE, zbuffer_t::enable, atest_t::enable, dtest_t::enable, ztest_t::enable, blend_t::fixed_alpha, ftoi4, GIF_FLG_PACKED, GIF_REG_AD, GIF_SET_TAG, GS_DISABLE, GS_ENABLE, GS_PSM_16, GS_PSM_16S, GS_REG_ALPHA, GS_REG_CLAMP, GS_REG_COLCLAMP, GS_REG_DIMX, GS_REG_DTHE, GS_REG_FBA, GS_REG_FOGCOL, GS_REG_FRAME, GS_REG_PABE, GS_REG_PRMODECONT, GS_REG_SCISSOR, GS_REG_TEST, GS_REG_TEXA, GS_REG_XYOFFSET, GS_REG_ZBUF, GS_SET_ALPHA, GS_SET_CLAMP, GS_SET_COLCLAMP, GS_SET_DIMX, GS_SET_DTHE, GS_SET_FBA, GS_SET_FOGCOL, GS_SET_FRAME, GS_SET_PABE, GS_SET_PRMODECONT, GS_SET_SCISSOR, GS_SET_TEST, GS_SET_TEXA, GS_SET_XYOFFSET, GS_SET_ZBUF, framebuffer_t::height, texwrap_t::horizontal, atest_t::keep, framebuffer_t::mask, zbuffer_t::mask, texwrap_t::maxu, texwrap_t::maxv, zbuffer_t::method, atest_t::method, ztest_t::method, texwrap_t::minu, texwrap_t::minv, PACK_GIFTAG, dtest_t::pass, PRIM_OVERRIDE_DISABLE, framebuffer_t::psm, texwrap_t::vertical, framebuffer_t::width, WRAP_CLAMP, zbuffer_t::zsm, and ZTEST_METHOD_ALLPASS.

Referenced by draw_init_env(), init_drawing_environment(), and main().

◆ draw_texture_flush()

qword_t* draw_texture_flush ( qword_t q)

Flush the texture cache

Definition at line 208 of file draw.c.

209 {
210 
211  // Flush texture buffer
212  DMATAG_END(q,2,0,0,0);
213  q++;
215  q++;
217  q++;
218 
219  return q;
220 
221 }
#define DMATAG_END(Q, QWC, SPR, W2, W3)
Definition: dma_tags.h:75
#define GS_REG_TEXFLUSH
Definition: gs_gp.h:85

References DMATAG_END, GIF_FLG_PACKED, GIF_REG_AD, GIF_SET_TAG, GS_REG_TEXFLUSH, and PACK_GIFTAG.

Referenced by init_texture(), load_texture(), and send_texture().

◆ draw_texture_transfer()

qword_t* draw_texture_transfer ( qword_t q,
void *  src,
int  width,
int  height,
int  psm,
int  dest,
int  dest_width 
)

Creates a dma chain filled with image information

Definition at line 223 of file draw.c.

224 {
225 
226  int i;
227  int remaining;
228  int qwords = 0;
229 
230  switch (psm)
231  {
232  case GS_PSM_8:
233  {
234  qwords = (width*height)>>4;
235  break;
236  }
237 
238  case GS_PSM_32:
239  case GS_PSM_24:
240  {
241  qwords = (width*height)>>2;
242  break;
243  }
244 
245  case GS_PSM_4:
246  {
247  qwords = (width*height)>>5;
248  break;
249  }
250 
251  case GS_PSM_16:
252  case GS_PSM_16S:
253  {
254  qwords = (width*height)>>3;
255  break;
256  }
257 
258  default:
259  {
260  switch (psm)
261  {
262  case GS_PSM_8H:
263  {
264  qwords = (width*height)>>4;
265  break;
266  }
267 
268  case GS_PSMZ_32:
269  case GS_PSMZ_24:
270  {
271  qwords = (width*height)>>2;
272  break;
273  }
274 
275  case GS_PSMZ_16:
276  case GS_PSMZ_16S:
277  {
278  qwords = (width*height)>>3;
279  break;
280  }
281 
282  case GS_PSM_4HL:
283  case GS_PSM_4HH:
284  {
285  qwords = (width*height)>>5;
286  break;
287  }
288  }
289  break;
290  }
291  }
292 
293  // Determine number of iterations based on the number of qwords
294  // that can be handled per dmatag
295  i = qwords / GIF_BLOCK_SIZE;
296 
297  // Now calculate the remaining image data left over
298  remaining = qwords % GIF_BLOCK_SIZE;
299 
300  // Setup the transfer
301  DMATAG_CNT(q,5,0,0,0);
302  q++;
304  q++;
305  PACK_GIFTAG(q,GS_SET_BITBLTBUF(0,0,0,dest>>6,dest_width>>6,psm),GS_REG_BITBLTBUF);
306  q++;
308  q++;
309  PACK_GIFTAG(q,GS_SET_TRXREG(width,height),GS_REG_TRXREG);
310  q++;
312  q++;
313 
314 
315  while(i-- > 0)
316  {
317 
318  // Setup image data dma chain
319  DMATAG_CNT(q,1,0,0,0);
320  q++;
321  PACK_GIFTAG(q,GIF_SET_TAG(GIF_BLOCK_SIZE,0,0,0,2,0),0);
322  q++;
323  DMATAG_REF(q,GIF_BLOCK_SIZE,(unsigned int)src,0,0,0);
324  q++;
325 
326  //Now increment the address by the number of qwords in bytes
327  src += (GIF_BLOCK_SIZE*16);
328 
329  }
330 
331  if(remaining)
332  {
333 
334  // Setup remaining image data dma chain
335  DMATAG_CNT(q,1,0,0,0);
336  q++;
337  PACK_GIFTAG(q,GIF_SET_TAG(remaining,0,0,0,2,0),0);
338  q++;
339  DMATAG_REF(q,remaining,(unsigned int)src,0,0,0);
340  q++;
341 
342  }
343 
344  return q;
345 
346 }
#define DMATAG_REF(Q, QWC, ADDR, SPR, W2, W3)
Definition: dma_tags.h:93
#define DMATAG_CNT(Q, QWC, SPR, W2, W3)
Definition: dma_tags.h:57
#define GIF_BLOCK_SIZE
Definition: gif_tags.h:12
#define GS_SET_TRXREG(W, H)
Definition: gs_gp.h:317
#define GS_REG_TRXREG
Definition: gs_gp.h:135
#define GS_SET_BITBLTBUF(SBA, SBW, SPSM, DBA, DBW, DPSM)
Definition: gs_gp.h:175
#define GS_SET_TRXPOS(SX, SY, DX, DY, DIR)
Definition: gs_gp.h:312
#define GS_REG_TRXPOS
Definition: gs_gp.h:133
#define GS_REG_BITBLTBUF
Definition: gs_gp.h:131
#define GS_REG_TRXDIR
Definition: gs_gp.h:137
#define GS_SET_TRXDIR(DIR)
Definition: gs_gp.h:308
#define GS_PSM_4HH
Definition: gs_psm.h:29
#define GS_PSM_4
Definition: gs_psm.h:23
#define GS_PSMZ_16S
Definition: gs_psm.h:37
#define GS_PSMZ_24
Definition: gs_psm.h:33
#define GS_PSMZ_32
Definition: gs_psm.h:31
#define GS_PSM_4HL
Definition: gs_psm.h:27
#define GS_PSM_8H
Definition: gs_psm.h:25
#define GS_PSM_32
Definition: gs_psm.h:11
#define GS_PSMZ_16
Definition: gs_psm.h:35
#define GS_PSM_24
Definition: gs_psm.h:13
#define GS_PSM_8
Definition: gs_psm.h:21

References DMATAG_CNT, DMATAG_REF, GIF_BLOCK_SIZE, GIF_FLG_PACKED, GIF_REG_AD, GIF_SET_TAG, GS_PSM_16, GS_PSM_16S, GS_PSM_24, GS_PSM_32, GS_PSM_4, GS_PSM_4HH, GS_PSM_4HL, GS_PSM_8, GS_PSM_8H, GS_PSMZ_16, GS_PSMZ_16S, GS_PSMZ_24, GS_PSMZ_32, GS_REG_BITBLTBUF, GS_REG_TRXDIR, GS_REG_TRXPOS, GS_REG_TRXREG, GS_SET_BITBLTBUF, GS_SET_TRXDIR, GS_SET_TRXPOS, GS_SET_TRXREG, and PACK_GIFTAG.

Referenced by init_texture(), load_texture(), and send_texture().

◆ draw_wait_finish()

void draw_wait_finish ( void  )

Wait until finish event occurs

Definition at line 200 of file draw.c.

201 {
202 
203  while(!(*GS_REG_CSR & 2));
204  *GS_REG_CSR |= 2;
205 
206 }
#define GS_REG_CSR
Definition: gs_privileged.h:45

References GS_REG_CSR.

Referenced by clear_screen(), flip_buffers(), init_drawing_environment(), render(), and run_demo().