1 /*===========================================================================*/
3 /* Mesa-3.0 DirectX 6 Driver */
7 /* http://www.altsoftware.com/ */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
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
)
24 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
25 DDSURFACEDESC2
*pddsd2
;
32 if ( mask
& GL_COLOR_BUFFER_BIT
)
34 /* Lock the surface to get the surface pointer. */
35 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
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
);
50 pScanLine
= ((UCHAR
*)pddsd2
->lpSurface
) +
51 ( (FLIP( pContext
->pShared
->dwHeight
, (y
+height
)) * pddsd2
->lPitch
) + (x
* pContext
->pShared
->pixel
.cb
) );
53 for( index
= 0; index
< height
; index
++, pScanLine
+= pddsd2
->lPitch
)
55 for( index2
= 0, pBuffer
= pScanLine
; index2
< width
; index2
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
56 memcpy( pBuffer
, &dwColor
, pContext
->pShared
->pixel
.cb
);
60 UnlockHAL( pContext
->pShared
, TRUE
);
63 return (mask
& ~GL_COLOR_BUFFER_BIT
);
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 /*===========================================================================*/
71 /*===========================================================================*/
72 void WSpanRGB( const GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
, const GLubyte rgb
[][3], const GLubyte mask
[] )
74 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
75 DDSURFACEDESC2
*pddsd2
;
80 /* Get the surface pointer and the pitch. */
81 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
88 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
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
);
102 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
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
);
113 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
121 /*===========================================================================*/
122 void WSpanRGBA( const GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
, const GLubyte rgba
[][4], const GLubyte mask
[] )
124 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
125 DDSURFACEDESC2
*pddsd2
;
130 /* Get the surface pointer and the pitch. */
131 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
138 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
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
);
152 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
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
);
163 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
172 /*===========================================================================*/
173 void WSpanRGBAMono( const GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
, const GLubyte mask
[] )
175 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
176 DDSURFACEDESC2
*pddsd2
;
181 /* Lock the surface to get the surface pointer and the pitch. */
182 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
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
);
194 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
196 memcpy( pBuffer
, &dwColor
, pContext
->pShared
->pixel
.cb
);
200 for( index
= 0; index
< n
; index
++, pBuffer
+= pContext
->pShared
->pixel
.cb
)
201 memcpy( pBuffer
, &dwColor
, pContext
->pShared
->pixel
.cb
);
205 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
213 /*===========================================================================*/
214 void WPixelsRGBA( const GLcontext
* ctx
, GLuint n
, const GLint x
[], const GLint y
[], const GLubyte rgba
[][4], const GLubyte mask
[] )
216 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
217 DDSURFACEDESC2
*pddsd2
;
222 /* Get the surface pointer and the pitch. */
223 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
227 for( index
= 0; index
< n
; index
++ )
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
);
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
);
244 for( index
= 0; index
< n
; index
++ )
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
);
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
);
258 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
267 /*===========================================================================*/
268 void WPixelsRGBAMono( const GLcontext
* ctx
, GLuint n
, const GLint x
[], const GLint y
[], const GLubyte mask
[] )
270 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
271 DDSURFACEDESC2
*pddsd2
;
276 /* Get the surface pointer and the pitch. */
277 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
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
++ )
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
);
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
++ )
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
);
309 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
320 /*===========================================================================*/
321 void RSpanRGBA( const GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
, GLubyte rgba
[][4] )
323 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
324 DDSURFACEDESC2
*pddsd2
;
329 /* Get the surface pointer and the pitch. */
330 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
);
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
)
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
);
347 UnlockHAL( pContext
->pShared
, TRUE
);
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 /*===========================================================================*/
358 /*===========================================================================*/
359 void RPixelsRGBA( const GLcontext
* ctx
, GLuint n
, const GLint x
[], const GLint y
[], GLubyte rgba
[][4], const GLubyte mask
[] )
361 D3DMESACONTEXT
*pContext
= (D3DMESACONTEXT
*)ctx
->DriverCtx
;
362 DDSURFACEDESC2
*pddsd2
;
366 /* Get the surface pointer and the pitch. */
367 pddsd2
= LockHAL( pContext
->pShared
, TRUE
);
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
++ )
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
);
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
++ )
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
);
398 UnlockHAL( pContext
->pShared
, TRUE
);