Convert crlf->lf line endings.
[mesa.git] / src / mesa / drivers / d3d / DDrawPROCS.c
1 /*===========================================================================*/
2 /* */
3 /* Mesa-3.0 DirectX 6 Driver */
4 /* */
5 /* By Leigh McRae */
6 /* */
7 /* http://www.altsoftware.com/ */
8 /* */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
11 #include "D3DMesa.h"
12 /*===========================================================================*/
13 /* This call will clear the render surface using the pixel info built from */
14 /* the surface at creation time. The call uses Lock/Unlock to access the */
15 /* surface. The call also special cases a full clear or a dirty rectangle. */
16 /* Finally the call returns the new clear mask that reflects that the color */
17 /* buffer was cleared. */
18 /*===========================================================================*/
19 /* RETURN: the original mask with the bits cleared that represents the buffer*/
20 /* or buffers we just cleared. */
21 /*===========================================================================*/
22 GLbitfield ClearBuffers( GLcontext *ctx, GLbitfield mask, GLboolean all, GLint x, GLint y, GLint width, GLint height )
23 {
24 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
25 DDSURFACEDESC2 *pddsd2;
26 UCHAR *pBuffer,
27 *pScanLine;
28 int index,
29 index2;
30 DWORD dwColor;
31
32 if ( mask & GL_COLOR_BUFFER_BIT )
33 {
34 /* Lock the surface to get the surface pointer. */
35 pddsd2 = LockHAL( pContext->pShared, TRUE );
36
37 /* Solve the color once only. */
38 dwColor = ( ((DWORD)((float)pContext->rClear * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
39 dwColor |= ( ((DWORD)((float)pContext->gClear * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
40 dwColor |= ( ((DWORD)((float)pContext->bClear * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
41
42 if ( all )
43 {
44 for( index = 0, pScanLine = (UCHAR *)pddsd2->lpSurface; index < pContext->pShared->dwHeight; index++, pScanLine += pddsd2->lPitch )
45 for( pBuffer = pScanLine, index2 = 0; index2 < pContext->pShared->dwWidth; index2++, pBuffer += pContext->pShared->pixel.cb )
46 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
47 }
48 else
49 {
50 pScanLine = ((UCHAR *)pddsd2->lpSurface) +
51 ( (FLIP( pContext->pShared->dwHeight, (y+height)) * pddsd2->lPitch) + (x * pContext->pShared->pixel.cb) );
52
53 for( index = 0; index < height; index++, pScanLine += pddsd2->lPitch )
54 {
55 for( index2 = 0, pBuffer = pScanLine; index2 < width; index2++, pBuffer += pContext->pShared->pixel.cb )
56 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
57 }
58 }
59
60 UnlockHAL( pContext->pShared, TRUE );
61 }
62
63 return (mask & ~GL_COLOR_BUFFER_BIT);
64 }
65 /*===========================================================================*/
66 /* This proc (as all others) has been written for the general case. I use */
67 /* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */
68 /* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */
69 /*===========================================================================*/
70 /* RETURN: */
71 /*===========================================================================*/
72 void WSpanRGB( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgb[][3], const GLubyte mask[] )
73 {
74 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
75 DDSURFACEDESC2 *pddsd2;
76 UCHAR *pBuffer;
77 int index;
78 DWORD dwColor;
79
80 /* Get the surface pointer and the pitch. */
81 pddsd2 = LockHAL( pContext->pShared, TRUE );
82
83 /* Find the start of the span. Invert y for Windows. */
84 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb);
85
86 if ( mask )
87 {
88 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
89 {
90 if ( mask[index] )
91 {
92 /* Pack the color components. */
93 dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
94 dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
95 dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
96 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
97 }
98 }
99 }
100 else
101 {
102 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
103 {
104 /* Pack the color components. */
105 dwColor = ( ((DWORD)((float)rgb[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
106 dwColor |= ( ((DWORD)((float)rgb[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
107 dwColor |= ( ((DWORD)((float)rgb[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
108 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
109 }
110 }
111
112 /* Giver back. */
113 UnlockHAL( pContext->pShared, TRUE );
114 }
115 /*===========================================================================*/
116 /* This proc (as all others) has been written for the general case. I use */
117 /* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */
118 /* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */
119 /*===========================================================================*/
120 /* RETURN: */
121 /*===========================================================================*/
122 void WSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte rgba[][4], const GLubyte mask[] )
123 {
124 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
125 DDSURFACEDESC2 *pddsd2;
126 UCHAR *pBuffer;
127 int index;
128 DWORD dwColor;
129
130 /* Get the surface pointer and the pitch. */
131 pddsd2 = LockHAL( pContext->pShared, TRUE );
132
133 /* Find the start of the span. Invert y for Windows. */
134 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb);
135
136 if ( mask )
137 {
138 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
139 {
140 if ( mask[index] )
141 {
142 /* Pack the color components. */
143 dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
144 dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
145 dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
146 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
147 }
148 }
149 }
150 else
151 {
152 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
153 {
154 /* Pack the color components. */
155 dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
156 dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
157 dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
158 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
159 }
160 }
161
162 /* Giver back. */
163 UnlockHAL( pContext->pShared, TRUE );
164 }
165 /*===========================================================================*/
166 /* This proc (as all others) has been written for the general case. I use */
167 /* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */
168 /* Screen render surface uses. The color is solved once from the current */
169 /* color components. The alpha is ignored as Mesa is doing it in SW. */
170 /*===========================================================================*/
171 /* RETURN: */
172 /*===========================================================================*/
173 void WSpanRGBAMono( const GLcontext* ctx, GLuint n, GLint x, GLint y, const GLubyte mask[] )
174 {
175 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
176 DDSURFACEDESC2 *pddsd2;
177 UCHAR *pBuffer;
178 int index;
179 DWORD dwColor;
180
181 /* Lock the surface to get the surface pointer and the pitch. */
182 pddsd2 = LockHAL( pContext->pShared, TRUE );
183
184 /* Solve the color once only. (no alpha) */
185 dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
186 dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
187 dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
188
189 /* Find the start of the span. Invert y for Windows. */
190 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) + (x*pContext->pShared->pixel.cb);
191
192 if ( mask )
193 {
194 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
195 if ( mask[index] )
196 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
197 }
198 else
199 {
200 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
201 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
202 }
203
204 /* Giver back. */
205 UnlockHAL( pContext->pShared, TRUE );
206 }
207 /*===========================================================================*/
208 /* This proc (as all others) has been written for the general case. I use */
209 /* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */
210 /* Screen render surface uses. The alpha is ignored as Mesa does it in SW. */
211 /*===========================================================================*/
212 /* RETURN: */
213 /*===========================================================================*/
214 void WPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte rgba[][4], const GLubyte mask[] )
215 {
216 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
217 DDSURFACEDESC2 *pddsd2;
218 UCHAR *pBuffer;
219 int index;
220 DWORD dwColor;
221
222 /* Get the surface pointer and the pitch. */
223 pddsd2 = LockHAL( pContext->pShared, TRUE );
224
225 if ( mask )
226 {
227 for( index = 0; index < n; index++ )
228 {
229 if ( mask[index] )
230 {
231 /* Pack the color components. */
232 dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
233 dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
234 dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
235
236 /* Find the pixel. Invert y for Windows. */
237 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb);
238 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
239 }
240 }
241 }
242 else
243 {
244 for( index = 0; index < n; index++ )
245 {
246 /* Pack the color components. */
247 dwColor = ( ((DWORD)((float)rgba[index][RCOMP] * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
248 dwColor |= ( ((DWORD)((float)rgba[index][GCOMP] * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
249 dwColor |= ( ((DWORD)((float)rgba[index][BCOMP] * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
250
251 /* Find the pixel. Invert y for Windows. */
252 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb);
253 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
254 }
255 }
256
257 /* Giver back. */
258 UnlockHAL( pContext->pShared, TRUE );
259 }
260 /*===========================================================================*/
261 /* This proc (as all others) has been written for the general case. I use */
262 /* the PIXELINFO structure to pack the pixel from RGB24 to whatever the Off- */
263 /* Screen render surface uses. The color is solved once from the current */
264 /* color components. The alpha is ignored as Mesa is doing it in SW. */
265 /*===========================================================================*/
266 /* RETURN: */
267 /*===========================================================================*/
268 void WPixelsRGBAMono( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], const GLubyte mask[] )
269 {
270 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
271 DDSURFACEDESC2 *pddsd2;
272 UCHAR *pBuffer;
273 int index;
274 DWORD dwColor;
275
276 /* Get the surface pointer and the pitch. */
277 pddsd2 = LockHAL( pContext->pShared, TRUE );
278
279 /* Solve the color once only. I don't uses the alpha. */
280 dwColor = ( ((DWORD)((float)pContext->rCurrent * pContext->pShared->pixel.rScale)) << pContext->pShared->pixel.rShift );
281 dwColor |= ( ((DWORD)((float)pContext->gCurrent * pContext->pShared->pixel.gScale)) << pContext->pShared->pixel.gShift );
282 dwColor |= ( ((DWORD)((float)pContext->bCurrent * pContext->pShared->pixel.bScale)) << pContext->pShared->pixel.bShift );
283
284 if ( mask )
285 {
286 /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */
287 for( index = 0; index < n; index++ )
288 {
289 if ( mask[index] )
290 {
291 /* Find the pixel. Invert y for Windows. */
292 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb);
293 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
294 }
295 }
296 }
297 else
298 {
299 /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */
300 for( index = 0; index < n; index++ )
301 {
302 /* Find the pixel. Invert y for Windows. */
303 pBuffer = (UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb);
304 memcpy( pBuffer, &dwColor, pContext->pShared->pixel.cb );
305 }
306 }
307
308 /* Giver back. */
309 UnlockHAL( pContext->pShared, TRUE );
310 }
311 /*===========================================================================*/
312 /* This proc isn't written for speed rather its to handle the general case. */
313 /* I grab each pixel from the surface and unpack the info using the PIXELINFO*/
314 /* structure that was generated from the OffScreen surface pixelformat. The */
315 /* function will not fill in the alpha value as Mesa I have Mesa allocate its*/
316 /* own alpha channel when the context was created. I did this as I didn't */
317 /* feel that it was worth the effort to try and get HW to work (bus bound). */
318 /*===========================================================================*/
319 /* RETURN: */
320 /*===========================================================================*/
321 void RSpanRGBA( const GLcontext* ctx, GLuint n, GLint x, GLint y, GLubyte rgba[][4] )
322 {
323 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
324 DDSURFACEDESC2 *pddsd2;
325 UCHAR *pBuffer;
326 int index;
327 DWORD *pdwColor;
328
329 /* Get the surface pointer and the pitch. */
330 pddsd2 = LockHAL( pContext->pShared, TRUE );
331
332 /* Find the start of the span. Invert y for Windows. */
333 pBuffer = (UCHAR *)pddsd2->lpSurface +
334 (FLIP(pContext->pShared->dwHeight,y) * pddsd2->lPitch) +
335 (x*pContext->pShared->pixel.cb);
336
337 /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */
338 for( index = 0; index < n; index++, pBuffer += pContext->pShared->pixel.cb )
339 {
340 pdwColor = (DWORD *)pBuffer;
341 rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale);
342 rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale);
343 rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale);
344 }
345
346 /* Giver back. */
347 UnlockHAL( pContext->pShared, TRUE );
348 }
349 /*===========================================================================*/
350 /* This proc isn't written for speed rather its to handle the general case. */
351 /* I grab each pixel from the surface and unpack the info using the PIXELINFO*/
352 /* structure that was generated from the OffScreen surface pixelformat. The */
353 /* function will not fill in the alpha value as Mesa I have Mesa allocate its*/
354 /* own alpha channel when the context was created. I did this as I didn't */
355 /* feel that it was worth the effort to try and get HW to work (bus bound). */
356 /*===========================================================================*/
357 /* RETURN: */
358 /*===========================================================================*/
359 void RPixelsRGBA( const GLcontext* ctx, GLuint n, const GLint x[], const GLint y[], GLubyte rgba[][4], const GLubyte mask[] )
360 {
361 D3DMESACONTEXT *pContext = (D3DMESACONTEXT *)ctx->DriverCtx;
362 DDSURFACEDESC2 *pddsd2;
363 int index;
364 DWORD *pdwColor;
365
366 /* Get the surface pointer and the pitch. */
367 pddsd2 = LockHAL( pContext->pShared, TRUE );
368
369 if ( mask )
370 {
371 /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */
372 for( index = 0; index < n; index++ )
373 {
374 if ( mask[index] )
375 {
376 /* Find the start of the pixel. Invert y for Windows. */
377 pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb));
378 rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale);
379 rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale);
380 rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale);
381 }
382 }
383 }
384 else
385 {
386 /* We store the surface pointer as a UCHAR so that pixel.cb (count in btyles) will work for all. */
387 for( index = 0; index < n; index++ )
388 {
389 /* Find the start of the pixel. Invert y for Windows. */
390 pdwColor = (DWORD *)((UCHAR *)pddsd2->lpSurface + (FLIP(pContext->pShared->dwHeight,y[index]) * pddsd2->lPitch) + (x[index]*pContext->pShared->pixel.cb));
391 rgba[index][RCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwRMask) >> pContext->pShared->pixel.rShift) / pContext->pShared->pixel.rScale);
392 rgba[index][GCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwGMask) >> pContext->pShared->pixel.gShift) / pContext->pShared->pixel.gScale);
393 rgba[index][BCOMP] = (GLubyte)((float)((*pdwColor & pContext->pShared->pixel.dwBMask) >> pContext->pShared->pixel.bShift) / pContext->pShared->pixel.bScale);
394 }
395 }
396
397 /* Giver back. */
398 UnlockHAL( pContext->pShared, TRUE );
399 }