365e9811ac3457c78bdf84e253238d2a416fa37c
[mesa.git] / src / mesa / drivers / dri / common / stenciltmp.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/common/stenciltmp.h,v 1.3 2001/03/21 16:14:20 dawes Exp $ */
2
3 #ifndef DBG
4 #define DBG 0
5 #endif
6
7 #ifndef HW_WRITE_LOCK
8 #define HW_WRITE_LOCK() HW_LOCK()
9 #endif
10 #ifndef HW_WRITE_UNLOCK
11 #define HW_WRITE_UNLOCK() HW_UNLOCK()
12 #endif
13
14 #ifndef HW_READ_LOCK
15 #define HW_READ_LOCK() HW_LOCK()
16 #endif
17 #ifndef HW_READ_UNLOCK
18 #define HW_READ_UNLOCK() HW_UNLOCK()
19 #endif
20
21 static void TAG(WriteStencilSpan)( GLcontext *ctx,
22 GLuint n, GLint x, GLint y,
23 const GLstencil *stencil,
24 const GLubyte mask[] )
25 {
26 HW_WRITE_LOCK()
27 {
28 GLint x1;
29 GLint n1;
30 LOCAL_STENCIL_VARS;
31
32 y = Y_FLIP(y);
33
34 HW_CLIPLOOP()
35 {
36 GLint i = 0;
37 CLIPSPAN(x,y,n,x1,n1,i);
38
39 if (DBG) fprintf(stderr, "WriteStencilSpan %d..%d (x1 %d)\n",
40 (int)i, (int)n1, (int)x1);
41
42 if (mask)
43 {
44 for (;i<n1;i++,x1++)
45 if (mask[i])
46 WRITE_STENCIL( x1, y, stencil[i] );
47 }
48 else
49 {
50 for (;i<n1;i++,x1++)
51 WRITE_STENCIL( x1, y, stencil[i] );
52 }
53 }
54 HW_ENDCLIPLOOP();
55 }
56 HW_WRITE_UNLOCK();
57 }
58
59
60 static void TAG(WriteStencilPixels)( GLcontext *ctx,
61 GLuint n,
62 const GLint x[],
63 const GLint y[],
64 const GLstencil stencil[],
65 const GLubyte mask[] )
66 {
67 HW_WRITE_LOCK()
68 {
69 GLint i;
70 LOCAL_STENCIL_VARS;
71
72 if (DBG) fprintf(stderr, "WriteStencilPixels\n");
73
74 HW_CLIPLOOP()
75 {
76 for (i=0;i<n;i++)
77 {
78 if (mask[i]) {
79 const int fy = Y_FLIP(y[i]);
80 if (CLIPPIXEL(x[i],fy))
81 WRITE_STENCIL( x[i], fy, stencil[i] );
82 }
83 }
84 }
85 HW_ENDCLIPLOOP();
86 }
87 HW_WRITE_UNLOCK();
88 }
89
90
91 /* Read stencil spans and pixels
92 */
93 static void TAG(ReadStencilSpan)( GLcontext *ctx,
94 GLuint n, GLint x, GLint y,
95 GLstencil stencil[])
96 {
97 HW_READ_LOCK()
98 {
99 GLint x1,n1;
100 LOCAL_STENCIL_VARS;
101
102 y = Y_FLIP(y);
103
104 if (DBG) fprintf(stderr, "ReadStencilSpan\n");
105
106 HW_CLIPLOOP()
107 {
108 GLint i = 0;
109 CLIPSPAN(x,y,n,x1,n1,i);
110 for (;i<n1;i++)
111 READ_STENCIL( stencil[i], (x1+i), y );
112 }
113 HW_ENDCLIPLOOP();
114 }
115 HW_READ_UNLOCK();
116 }
117
118 static void TAG(ReadStencilPixels)( GLcontext *ctx, GLuint n,
119 const GLint x[], const GLint y[],
120 GLstencil stencil[] )
121 {
122 HW_READ_LOCK()
123 {
124 GLint i;
125 LOCAL_STENCIL_VARS;
126
127 if (DBG) fprintf(stderr, "ReadStencilPixels\n");
128
129 HW_CLIPLOOP()
130 {
131 for (i=0;i<n;i++) {
132 int fy = Y_FLIP( y[i] );
133 if (CLIPPIXEL( x[i], fy ))
134 READ_STENCIL( stencil[i], x[i], fy );
135 }
136 }
137 HW_ENDCLIPLOOP();
138 }
139 HW_READ_UNLOCK();
140 }
141
142
143
144
145 #undef WRITE_STENCIL
146 #undef READ_STENCIL
147 #undef TAG