Fixed pixel color component problem and clear code for 24-bit Windows

devices.  (Jeff Lewis)
This commit is contained in:
Karl Schultz 2002-01-15 18:14:34 +00:00
parent 807aea838b
commit f2e5c19a2f
2 changed files with 178 additions and 158 deletions

View File

@ -24,6 +24,10 @@
/* /*
* $Log: colors.h,v $ * $Log: colors.h,v $
* Revision 1.3 2002/01/15 18:14:34 kschultz
* Fixed pixel color component problem and clear code for 24-bit Windows
* devices. (Jeff Lewis)
*
* Revision 1.2 2002/01/15 18:11:36 kschultz * Revision 1.2 2002/01/15 18:11:36 kschultz
* Remove trailing CR's. No logical changes. * Remove trailing CR's. No logical changes.
* *
@ -42,6 +46,10 @@
/* /*
* $Log: colors.h,v $ * $Log: colors.h,v $
* Revision 1.3 2002/01/15 18:14:34 kschultz
* Fixed pixel color component problem and clear code for 24-bit Windows
* devices. (Jeff Lewis)
*
* Revision 1.2 2002/01/15 18:11:36 kschultz * Revision 1.2 2002/01/15 18:11:36 kschultz
* Remove trailing CR's. No logical changes. * Remove trailing CR's. No logical changes.
* *
@ -60,6 +68,10 @@
/* /*
* $Log: colors.h,v $ * $Log: colors.h,v $
* Revision 1.3 2002/01/15 18:14:34 kschultz
* Fixed pixel color component problem and clear code for 24-bit Windows
* devices. (Jeff Lewis)
*
* Revision 1.2 2002/01/15 18:11:36 kschultz * Revision 1.2 2002/01/15 18:11:36 kschultz
* Remove trailing CR's. No logical changes. * Remove trailing CR's. No logical changes.
* *
@ -126,7 +138,8 @@ char ColorMap16[] = {
#else #else
#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10))) #define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10)))
#endif #endif
#define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8) #define BGR24(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
#define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) #define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))

View File

@ -1,4 +1,4 @@
/* $Id: wmesa.c,v 1.23 2001/11/01 22:44:47 kschultz Exp $ */ /* $Id: wmesa.c,v 1.24 2002/01/15 18:14:34 kschultz Exp $ */
/* /*
* Windows (Win32) device driver for Mesa 3.4 * Windows (Win32) device driver for Mesa 3.4
@ -370,166 +370,173 @@ static void clear_color( GLcontext* ctx, const GLchan color[4] )
} }
/*
* Clear the specified region of the color buffer using the clear color
* or index as specified by one of the two functions above.
*
* This procedure clears either the front and/or the back COLOR buffers.
* Only the "left" buffer is cleared since we are not stereo.
* Clearing of the other non-color buffers is left to the swrast.
* We also only clear the color buffers if the color masks are all 1's.
* Otherwise, we let swrast do it.
*/
/* static clear(GLcontext* ctx, GLbitfield mask,
* Clear the specified region of the color buffer using the clear color GLboolean all, GLint x, GLint y, GLint width, GLint height)
* or index as specified by one of the two functions above. {
* const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask;
* This procedure clears either the front and/or the back COLOR buffers.
* Only the "left" buffer is cleared since we are not stereo. if (all){
* Clearing of the other non-color buffers is left to the swrast. x=y=0;
* We also only clear the color buffers if the color masks are all 1's. width=Current->width;
* Otherwise, we let swrast do it. height=Current->height;
*/ }
/* sanity check - can't have right(stereo) buffers */
assert((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_RIGHT_BIT)) == 0);
if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
if (mask & DD_BACK_LEFT_BIT) {
#if defined(USE_GDI_TO_CLEAR)
#if defined(DDRAW)
// D.R.S. 10/29/01 on my system (Pentium 4 with nvidia GeForce2 MX card,
// this is almose 100 times faster that the code below
HDC DC=NULL;
HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
HPEN Old_Pen=NULL;
HBRUSH Old_Brush=NULL;
Current->lpDDSOffScreen->lpVtbl->Unlock(Current->lpDDSOffScreen,NULL);
Current->lpDDSOffScreen->lpVtbl->GetDC(Current->lpDDSOffScreen,&DC);
Old_Pen=SelectObject(DC,Pen);
Old_Brush=SelectObject(DC,Brush);
Rectangle(DC,x,y,x+width,y+height);
SelectObject(DC,Old_Pen);
SelectObject(DC,Old_Brush);
DeleteObject(Pen);
DeleteObject(Brush);
Current->lpDDSOffScreen->lpVtbl->ReleaseDC(Current->lpDDSOffScreen,DC);
while (Current->lpDDSOffScreen->lpVtbl->Lock(Current->lpDDSOffScreen,NULL, &(Current->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING);
static clear(GLcontext* ctx, GLbitfield mask, mask &= ~DD_BACK_LEFT_BIT;
GLboolean all, GLint x, GLint y, GLint width, GLint height) #else
{ /* single-buffer */
const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask; HDC DC=DD_GETDC;
HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
if (all){ HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
x=y=0; HPEN Old_Pen=SelectObject(DC,Pen);
width=Current->width; HBRUSH Old_Brush=SelectObject(DC,Brush);
height=Current->height; Rectangle(DC,x+Current->rectSurface.left,Current->rectSurface.top+y,x+width+Current->rectSurface.left,y+height+Current->rectSurface.top);
}
SelectObject(DC,Old_Pen);
SelectObject(DC,Old_Brush);
/* sanity check - can't have right(stereo) buffers */ DeleteObject(Pen);
assert((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_RIGHT_BIT)) == 0); DeleteObject(Brush);
DD_RELEASEDC;
if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) { mask &= ~DD_BACK_LEFT_BIT;
if (mask & DD_BACK_LEFT_BIT) { #endif // DDRAW
#if defined(USE_GDI_TO_CLEAR) #else
#if defined(DDRAW) DWORD dwColor;
// D.R.S. 10/29/01 on my system (Pentium 4 with nvidia GeForce2 MX card, WORD wColor;
// this is almose 100 times faster that the code below BYTE bColor;
HDC DC=NULL; LPDWORD lpdw = (LPDWORD)Current->pbPixels;
HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel); LPWORD lpw = (LPWORD)Current->pbPixels;
HBRUSH Brush=CreateSolidBrush(Current->clearpixel); LPBYTE lpb = Current->pbPixels;
HPEN Old_Pen=NULL; int lines;
HBRUSH Old_Brush=NULL; /* Double-buffering - clear back buffer */
Current->lpDDSOffScreen->lpVtbl->Unlock(Current->lpDDSOffScreen,NULL); UINT nBypp = Current->cColorBits / 8;
Current->lpDDSOffScreen->lpVtbl->GetDC(Current->lpDDSOffScreen,&DC); int i = 0;
Old_Pen=SelectObject(DC,Pen); int iSize = 0;
Old_Brush=SelectObject(DC,Brush); int mult = 4;
Rectangle(DC,x,y,x+width,y+height);
SelectObject(DC,Old_Pen);
SelectObject(DC,Old_Brush); assert(Current->db_flag==GL_TRUE); /* we'd better be double buffer */
DeleteObject(Pen); if(nBypp ==1 ){
DeleteObject(Brush); iSize = Current->width/4;
Current->lpDDSOffScreen->lpVtbl->ReleaseDC(Current->lpDDSOffScreen,DC); bColor = BGR8(GetRValue(Current->clearpixel),
while (Current->lpDDSOffScreen->lpVtbl->Lock(Current->lpDDSOffScreen,NULL, &(Current->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING); GetGValue(Current->clearpixel),
mask &= ~DD_BACK_LEFT_BIT; GetBValue(Current->clearpixel));
#else wColor = MAKEWORD(bColor,bColor);
/* single-buffer */ dwColor = MAKELONG(wColor, wColor);
HDC DC=DD_GETDC; }
HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel); else if(nBypp == 2){
HBRUSH Brush=CreateSolidBrush(Current->clearpixel); iSize = Current->width / 2;
HPEN Old_Pen=SelectObject(DC,Pen); wColor = BGR16(GetRValue(Current->clearpixel),
HBRUSH Old_Brush=SelectObject(DC,Brush); GetGValue(Current->clearpixel),
Rectangle(DC,x+Current->rectSurface.left,Current->rectSurface.top+y,x+width+Current->rectSurface.left,y+height+Current->rectSurface.top); GetBValue(Current->clearpixel));
SelectObject(DC,Old_Pen); dwColor = MAKELONG(wColor, wColor);
SelectObject(DC,Old_Brush); }
DeleteObject(Pen); else if(nBypp == 3){
DeleteObject(Brush); BYTE r, g, b;
DD_RELEASEDC; r = GetRValue(Current->clearpixel);
mask &= ~DD_BACK_LEFT_BIT; g = GetGValue(Current->clearpixel);
#endif // DDRAW b = GetBValue(Current->clearpixel);
#else iSize = Current->width;
DWORD dwColor; while (i < iSize) {
WORD wColor; *lpb++ = r;
BYTE bColor; *lpb++ = g;
LPDWORD lpdw = (LPDWORD)Current->pbPixels; *lpb++ = b;
LPWORD lpw = (LPWORD)Current->pbPixels; i++;
LPBYTE lpb = Current->pbPixels; }
int lines; lpb = Current->pbPixels + Current->ScanWidth;
/* Double-buffering - clear back buffer */ mult = 3;
UINT nBypp = Current->cColorBits / 8; }
int i = 0; else if(nBypp == 4){
int iSize = 0; iSize = Current->width;
dwColor = BGR32(GetRValue(Current->clearpixel),
assert(Current->db_flag==GL_TRUE); /* we'd better be double buffer */ GetGValue(Current->clearpixel),
if(nBypp ==1 ){ GetBValue(Current->clearpixel));
iSize = Current->width/4; }
bColor = BGR8(GetRValue(Current->clearpixel),
GetGValue(Current->clearpixel), if (nBypp != 3)
GetBValue(Current->clearpixel)); {
wColor = MAKEWORD(bColor,bColor); /* clear a line */
dwColor = MAKELONG(wColor, wColor); while(i < iSize){
} *lpdw = dwColor;
if(nBypp == 2){ lpdw++;
iSize = Current->width / 2; i++;
wColor = BGR16(GetRValue(Current->clearpixel), }
GetGValue(Current->clearpixel), }
GetBValue(Current->clearpixel));
dwColor = MAKELONG(wColor, wColor); i = 0;
} if (stereo_flag)
else if(nBypp == 4){ lines = height /2;
iSize = Current->width; else
dwColor = BGR32(GetRValue(Current->clearpixel), lines = height;
GetGValue(Current->clearpixel), /* copy cleared line to other lines in buffer */
GetBValue(Current->clearpixel)); do {
} memcpy(lpb, Current->pbPixels, iSize*mult);
lpb += Current->ScanWidth;
/* clear a line */ i++;
while(i < iSize){ }
*lpdw = dwColor; while (i<lines-1);
lpdw++; mask &= ~DD_BACK_LEFT_BIT;
i++; #endif // defined(USE_GDI_TO_CLEAR)
} } /* double-buffer */
/* This is the 24bit case */
if (nBypp == 3) {
iSize = Current->width *3/4;
dwColor = BGR24(GetRValue(Current->clearpixel),
GetGValue(Current->clearpixel),
GetBValue(Current->clearpixel));
while(i < iSize){
*lpdw = dwColor;
lpb += nBypp;
lpdw = (LPDWORD)lpb;
i++;
}
}
i = 0;
if (stereo_flag)
lines = height /2;
else
lines = height;
/* copy cleared line to other lines in buffer */
do {
memcpy(lpb, Current->pbPixels, iSize*4);
lpb += Current->ScanWidth;
i++;
}
while (i<lines-1);
mask &= ~DD_BACK_LEFT_BIT;
#endif // defined(USE_GDI_TO_CLEAR)
} /* double-buffer */
if (mask & DD_FRONT_LEFT_BIT) { if (mask & DD_FRONT_LEFT_BIT) {
/* single-buffer */ /* single-buffer */
HDC DC=DD_GETDC; HDC DC=DD_GETDC;
HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel); HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
HBRUSH Brush=CreateSolidBrush(Current->clearpixel); HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
HPEN Old_Pen=SelectObject(DC,Pen); HPEN Old_Pen=SelectObject(DC,Pen);
HBRUSH Old_Brush=SelectObject(DC,Brush); HBRUSH Old_Brush=SelectObject(DC,Brush);
Rectangle(DC,x+Current->rectSurface.left,Current->rectSurface.top+y,x+width+Current->rectSurface.left,y+height+Current->rectSurface.top); Rectangle(DC,x+Current->rectSurface.left,Current->rectSurface.top+y,x+width+Current->rectSurface.left,y+height+Current->rectSurface.top);
SelectObject(DC,Old_Pen);
SelectObject(DC,Old_Brush); SelectObject(DC,Old_Pen);
DeleteObject(Pen); SelectObject(DC,Old_Brush);
DeleteObject(Brush); DeleteObject(Pen);
DD_RELEASEDC; DeleteObject(Brush);
mask &= ~DD_FRONT_LEFT_BIT; DD_RELEASEDC;
} /* single-buffer */ mask &= ~DD_FRONT_LEFT_BIT;
} /* if masks are all 1's */ } /* single-buffer */
} /* if masks are all 1's */
/* Call swrast if there is anything left to clear (like DEPTH) */ /* Call swrast if there is anything left to clear (like DEPTH) */
if (mask) if (mask)
_swrast_Clear( ctx, mask, all, x, y, width, height ); _swrast_Clear( ctx, mask, all, x, y, width, height );
} }
static void enable( GLcontext* ctx, GLenum pname, GLboolean enable ) static void enable( GLcontext* ctx, GLenum pname, GLboolean enable )