5 * Display driver for Mesa 2.3 under
6 * Windows95 and WindowsNT
8 * Copyright (C) 1996- Li Wei
9 * Address : Institute of Artificial Intelligence
11 * : Xi'an Jiaotong University
12 * Email : liwei@aiar.xjtu.edu.cn
13 * Web page : http://sun.aiar.xjtu.edu.cn
15 * This file and its associations are partially borrowed from the
16 * Windows NT driver for Mesa 1.8 , written by Mark Leaming
22 * $Log: wmesaOld.c,v $
23 * Revision 1.3 2001/03/03 20:33:29 brianp
24 * lots of gl_*() to _mesa_*() namespace clean-up
26 * Revision 1.2 2000/11/05 18:41:00 keithw
27 * - Changes for new software rasterizer modules
28 * - Remove support for choosing software fallbacks from core code
29 * - Remove partial fallback code from vbrender.c -- drivers are now
30 * expected to be able to find a triangle/quad function for every state,
31 * even if they have to use _swsetup_Triangle or _swsetup_Quad.
32 * - Marked derived variables in the GLcontext struct with a leading
35 * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
38 * Revision 1.2 1999/01/03 03:08:57 brianp
41 * Revision 1.0 1997/06/14 17:51:00 CST by Li Wei(liwei@aiar.xjtu.edu.cn)
42 * New display driver for Mesa 2.x using Microsoft Direct Draw
47 #define WMESA_STEREO_C
62 // #include "profile.h"
72 #define CopyMemory memcpy
74 #include "mesa_extend.h"
77 #if !defined(NO_STEREO)
83 #if !defined(NO_PARALLEL)
84 // #include "parallel.h"
87 struct DISPLAY_OPTIONS displayOptions
;
89 GLenum stereoCompile
= GL_FALSE
;
90 GLenum stereoShowing
= GL_FALSE
;
91 GLenum stereoBuffer
= GL_FALSE
;
92 #if !defined(NO_STEREO)
93 GLint displayList
= MAXIMUM_DISPLAY_LIST
;
95 GLint stereo_flag
= 0 ;
97 /* end of added code*/
99 static PWMC Current
= NULL
;
100 WMesaContext WC
= NULL
;
103 #define assert(ignore) ((void) 0)
105 void Mesa_Assert(void *Cond
,void *File
,unsigned Line
)
108 sprintf(Msg
,"%s %s %d",Cond
,File
,Line
);
109 MessageBox(NULL
,Msg
,"Assertion failed.",MB_OK
);
112 #define assert(e) if (!e) Mesa_Assert(#e,__FILE__,__LINE__);
115 //#define DD_GETDC (Current->hDC )
116 #define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
117 //#define DD_GETDC ((Current->db_flag) ? Current->hDCPrimary : Current->hDCBack )
120 //#define BEGINGDICALL if(Current->rgb_flag)wmFlushBits(Current);
122 //#define ENDGDICALL if(Current->rgb_flag)wmGetBits(Current);
125 //#define FLIP(Y) (Current->dither_flag? Y : Current->height-(Y)-1)
126 //#define FLIP(Y) (Current->height-(Y)-1)
128 #define FLIP(Y) (Current->db_flag? Y: Current->height-(Y)-1)
130 #define ENDPROFILE(PARA)
132 #define DITHER_RGB_TO_8BIT_SETUP \
133 GLubyte pixelDithered;
135 #define DITHER_RGB_TO_8BIT(red, green, blue, pixel, scanline) \
137 char unsigned redtemp, greentemp, bluetemp, paletteindex; \
138 redtemp = aDividedBy51[red] \
139 + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 \
141 greentemp = aDividedBy51[(char unsigned)green] \
142 + (aModulo51[green] > aHalftone8x8[ \
143 (pixel%8)*8 + scanline%8]); \
144 bluetemp = aDividedBy51[(char unsigned)blue] \
145 + (aModulo51[blue] > aHalftone8x8[ \
146 (pixel%8)*8 +scanline%8]); \
147 paletteindex = redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; \
148 pixelDithered = aWinGHalftoneTranslation[paletteindex]; \
153 static BOOL
DDInit( WMesaContext wc
, HWND hwnd
);
154 static void DDFree( WMesaContext wc
);
155 static HRESULT
DDRestoreAll( WMesaContext wc
);
156 static void DDDeleteOffScreen(WMesaContext wc
);
157 static BOOL
DDCreateOffScreen(WMesaContext wc
);
160 static void FlushToFile(PWMC pwc
, PSTR szFile
);
162 BOOL
wmCreateBackingStore(PWMC pwc
, long lxSize
, long lySize
);
163 BOOL
wmDeleteBackingStore(PWMC pwc
);
164 void wmCreatePalette( PWMC pwdc
);
165 BOOL
wmSetDibColors(PWMC pwc
);
166 void wmSetPixel(PWMC pwc
, int iScanLine
, int iPixel
, BYTE r
, BYTE g
, BYTE b
);
168 void wmCreateDIBSection(
170 PWMC pwc
, // handle of device context
171 CONST BITMAPINFO
*pbmi
, // address of structure containing bitmap size, format, and color data
172 UINT iUsage
// color data type indicator: RGB values or palette indices
176 void WMesaViewport( GLcontext
*ctx
,
177 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
179 static triangle_func
choose_triangle_function( GLcontext
*ctx
);
181 static void wmSetPixelFormat( PWMC wc
, HDC hDC
)
184 wc
->cColorBits
= GetDeviceCaps(hDC
, BITSPIXEL
);
187 switch(wc
->cColorBits
){
189 if(wc
->dither_flag
!= GL_TRUE
)
190 wc
->pixelformat
= PF_INDEX8
;
192 wc
->pixelformat
= PF_DITHER8
;
195 wc
->pixelformat
= PF_5R6G5B
;
198 wc
->pixelformat
= PF_8R8G8B
;
201 wc
->pixelformat
= PF_BADFORMAT
;
206 // This function sets the color table of a DIB section
207 // to match that of the destination DC
209 BOOL
/*WINAPI*/ wmSetDibColors(PWMC pwc
)
211 RGBQUAD
*pColTab
, *pRGB
;
212 PALETTEENTRY
*pPal
, *pPE
;
217 /* Build a color table in the DIB that maps to the
218 selected palette in the DC.
220 nColors
= 1 << pwc
->cColorBits
;
221 pPal
= (PALETTEENTRY
*)malloc( nColors
* sizeof(PALETTEENTRY
));
222 memset( pPal
, 0, nColors
* sizeof(PALETTEENTRY
) );
223 GetPaletteEntries( pwc
->hGLPalette
, 0, nColors
, pPal
);
224 pColTab
= (RGBQUAD
*)malloc( nColors
* sizeof(RGBQUAD
));
225 for (i
= 0, pRGB
= pColTab
, pPE
= pPal
; i
< nColors
; i
++, pRGB
++, pPE
++) {
226 pRGB
->rgbRed
= pPE
->peRed
;
227 pRGB
->rgbGreen
= pPE
->peGreen
;
228 pRGB
->rgbBlue
= pPE
->peBlue
;
231 bRet
= SetDIBColorTable(pwc
->dib
.hDC
, 0, nColors
, pColTab
);
234 dwErr
= GetLastError();
244 // Free up the dib section that was created
246 BOOL
wmDeleteBackingStore(PWMC pwc
)
248 SelectObject(pwc
->dib
.hDC
, pwc
->hOldBitmap
);
249 DeleteDC(pwc
->dib
.hDC
);
250 DeleteObject(pwc
->hbmDIB
);
251 UnmapViewOfFile(pwc
->dib
.base
);
252 CloseHandle(pwc
->dib
.hFileMap
);
258 // This function creates the DIB section that is used for combined
261 BOOL
/*WINAPI*/ wmCreateBackingStore(PWMC pwc
, long lxSize
, long lySize
)
264 LPBITMAPINFO pbmi
= &(pwc
->bmi
);
267 pbmi
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
268 pbmi
->bmiHeader
.biWidth
= lxSize
;
269 pbmi
->bmiHeader
.biHeight
= -lySize
;
270 pbmi
->bmiHeader
.biPlanes
= 1;
272 pbmi
->bmiHeader
.biBitCount
= GetDeviceCaps(pwc
->hDC
, BITSPIXEL
);
274 pbmi
->bmiHeader
.biBitCount
= 8;
275 pbmi
->bmiHeader
.biCompression
= BI_RGB
;
276 pbmi
->bmiHeader
.biSizeImage
= 0;
277 pbmi
->bmiHeader
.biXPelsPerMeter
= 0;
278 pbmi
->bmiHeader
.biYPelsPerMeter
= 0;
279 pbmi
->bmiHeader
.biClrUsed
= 0;
280 pbmi
->bmiHeader
.biClrImportant
= 0;
282 iUsage
= (pbmi
->bmiHeader
.biBitCount
<= 8) ? DIB_PAL_COLORS
: DIB_RGB_COLORS
;
284 pwc
->cColorBits
= pbmi
->bmiHeader
.biBitCount
;
285 pwc
->ScanWidth
= pwc
->pitch
= lxSize
;
287 wmCreateDIBSection(hdc
, pwc
, pbmi
, iUsage
);
289 if ((iUsage
== DIB_PAL_COLORS
) && !(pwc
->hGLPalette
)) {
290 wmCreatePalette( pwc
);
291 wmSetDibColors( pwc
);
293 wmSetPixelFormat(pwc
, pwc
->hDC
);
300 // This function copies one scan line in a DIB section to another
302 BOOL GLWINAPI
wmSetDIBits(PWMC pwc
, UINT uiScanWidth
, UINT uiNumScans
, UINT nBypp
, UINT uiNewWidth
, LPBYTE pBits
)
305 LPBYTE pDest
= pwc
->pbPixels
;
306 DWORD dwNextScan
= uiScanWidth
;
307 DWORD dwNewScan
= uiNewWidth
;
308 DWORD dwScanWidth
= (uiScanWidth
* nBypp
);
311 // We need to round up to the nearest DWORD
312 // and multiply by the number of bytes per
315 dwNextScan
= (((dwNextScan
* nBypp
)+ 3) & ~3);
316 dwNewScan
= (((dwNewScan
* nBypp
)+ 3) & ~3);
318 for(uiScans
= 0; uiScans
< uiNumScans
; uiScans
++){
319 CopyMemory(pDest
, pBits
, dwScanWidth
);
329 BOOL
wmFlush(PWMC pwc
);
333 Modified from file osmesa.c
337 #define PIXELADDR(X,Y) ((GLubyte *)Current->pbPixels + (Current->height-Y-1)* Current->ScanWidth + (X)*nBypp)
338 #define PIXELADDR1( X, Y ) \
339 ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X))
340 #define PIXELADDR2( X, Y ) \
341 ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*2)
342 #define PIXELADDR4( X, Y ) \
343 ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*4)
346 BYTE
DITHER_RGB_2_8BIT( int r
, int g
, int b
, int x
, int y
);
348 /* Finish all pending operations and synchronize. */
349 static void finish(GLcontext
* ctx
)
356 // We cache all gl draw routines until a flush is made
358 static void flush(GLcontext
* ctx
)
361 if((Current
->rgb_flag
/*&& !(Current->dib.fFlushed)*/&&!(Current
->db_flag
))
362 ||(!Current
->rgb_flag
))
373 * Set the color index used to clear the color buffer.
375 static void clear_index(GLcontext
* ctx
, GLuint index
)
378 Current
->clearpixel
= index
;
379 ENDPROFILE(clear_index
)
385 * Set the color used to clear the color buffer.
387 static void clear_color( GLcontext
* ctx
, GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
390 Current
->clearpixel
=RGB(r
, g
, b
);
391 ENDPROFILE(clear_color
)
397 * Clear the specified region of the color buffer using the clear color
398 * or index as specified by one of the two functions above.
400 static void clear(GLcontext
* ctx
,
401 GLboolean all
,GLint x
, GLint y
, GLint width
, GLint height
)
406 LPDWORD lpdw
= (LPDWORD
)Current
->pbPixels
;
407 LPWORD lpw
= (LPWORD
)Current
->pbPixels
;
408 LPBYTE lpb
= Current
->pbPixels
;
415 width
=Current
->width
;
416 height
=Current
->height
;
418 if(Current
->db_flag
==GL_TRUE
){
419 UINT nBypp
= Current
->cColorBits
/ 8;
424 /* Need rectification */
425 iSize
= Current
->width
/4;
426 bColor
= BGR8(GetRValue(Current
->clearpixel
),
427 GetGValue(Current
->clearpixel
),
428 GetBValue(Current
->clearpixel
));
429 wColor
= MAKEWORD(bColor
,bColor
);
430 dwColor
= MAKELONG(wColor
, wColor
);
433 iSize
= Current
->width
/ 2;
434 wColor
= BGR16(GetRValue(Current
->clearpixel
),
435 GetGValue(Current
->clearpixel
),
436 GetBValue(Current
->clearpixel
));
437 dwColor
= MAKELONG(wColor
, wColor
);
440 iSize
= Current
->width
;
441 dwColor
= BGR32(GetRValue(Current
->clearpixel
),
442 GetGValue(Current
->clearpixel
),
443 GetBValue(Current
->clearpixel
));
453 // This is the 24bit case
456 iSize
= Current
->width
*3/4;
457 dwColor
= BGR24(GetRValue(Current
->clearpixel
),
458 GetGValue(Current
->clearpixel
),
459 GetBValue(Current
->clearpixel
));
469 if(stereo_flag
) lines
= height
/2;
472 lpb
+= Current
->ScanWidth
;
473 memcpy(lpb
, Current
->pbPixels
, iSize
*4);
478 else{ // For single buffer
480 HPEN Pen
=CreatePen(PS_SOLID
,1,Current
->clearpixel
);
481 HBRUSH Brush
=CreateSolidBrush(Current
->clearpixel
);
482 HPEN Old_Pen
=SelectObject(DC
,Pen
);
483 HBRUSH Old_Brush
=SelectObject(DC
,Brush
);
484 Rectangle(DC
,x
,y
,x
+width
,y
+height
);
485 SelectObject(DC
,Old_Pen
);
486 SelectObject(DC
,Old_Brush
);
499 /* Set the current color index. */
500 static void set_index(GLcontext
* ctx
, GLuint index
)
503 Current
->pixel
=index
;
504 ENDPROFILE(set_index
)
509 /* Set the current RGBA color. */
510 static void set_color( GLcontext
* ctx
, GLubyte r
, GLubyte g
, GLubyte b
, GLubyte a
)
513 Current
->pixel
= RGB( r
, g
, b
);
514 ENDPROFILE(set_color
)
519 /* Set the index mode bitplane mask. */
520 static GLboolean
index_mask(GLcontext
* ctx
, GLuint mask
)
522 /* can't implement */
528 /* Set the RGBA drawing mask. */
529 static GLboolean
color_mask( GLcontext
* ctx
,
530 GLboolean rmask
, GLboolean gmask
,
531 GLboolean bmask
, GLboolean amask
)
533 /* can't implement */
540 * Set the pixel logic operation. Return GL_TRUE if the device driver
541 * can perform the operation, otherwise return GL_FALSE. If GL_FALSE
542 * is returned, the logic op will be done in software by Mesa.
544 GLboolean
logicop( GLcontext
* ctx
, GLenum op
)
546 /* can't implement */
551 static void dither( GLcontext
* ctx
, GLboolean enable
)
553 if(enable
== GL_FALSE
){
554 Current
->dither_flag
= GL_FALSE
;
555 if(Current
->cColorBits
== 8)
556 Current
->pixelformat
= PF_INDEX8
;
559 if (Current
->rgb_flag
&& Current
->cColorBits
== 8){
560 Current
->pixelformat
= PF_DITHER8
;
561 Current
->dither_flag
= GL_TRUE
;
564 Current
->dither_flag
= GL_FALSE
;
570 static GLboolean
set_buffer( GLcontext
* ctx
, GLenum mode
)
573 /* TODO: this could be better */
574 if (mode
==GL_FRONT
|| mode
==GL_BACK
) {
580 ENDPROFILE(set_buffer
)
585 /* Return characteristics of the output buffer. */
586 static void buffer_size( GLcontext
* ctx
, GLuint
*width
, GLuint
*height
/*, GLuint *depth */)
593 GetClientRect(Current
->Window
,&CR
);
597 // *depth = Current->depth;
599 New_Size
=((*width
)!=Current
->width
) || ((*height
)!=Current
->height
);
602 Current
->width
=*width
;
603 Current
->height
=*height
;
604 Current
->ScanWidth
=Current
->width
;
605 if ((Current
->ScanWidth
%sizeof(long))!=0)
606 Current
->ScanWidth
+=(sizeof(long)-(Current
->ScanWidth
%sizeof(long)));
608 if (Current
->db_flag
){
610 DDDeleteOffScreen(Current
);
611 DDCreateOffScreen(Current
);
613 if (Current
->rgb_flag
==GL_TRUE
&& Current
->dither_flag
!=GL_TRUE
){
614 wmDeleteBackingStore(Current
);
615 wmCreateBackingStore(Current
, Current
->width
, Current
->height
);
620 // Resize OsmesaBuffer if in Parallel mode
621 #if !defined(NO_PARALLEL)
623 PRSizeRenderBuffer(Current
->width
, Current
->height
,Current
->ScanWidth
,
624 Current
->rgb_flag
== GL_TRUE
? Current
->pbPixels
: Current
->ScreenMem
);
627 ENDPROFILE(buffer_size
)
632 /**********************************************************************/
633 /***** Accelerated point, line, polygon rendering *****/
634 /**********************************************************************/
637 static void fast_rgb_points( GLcontext
* ctx
, GLuint first
, GLuint last
)
645 if (Current
->gl_ctx
->VB
->MonoColor
) {
646 /* all drawn with current color */
647 for (i
=first
;i
<=last
;i
++) {
648 if (!Current
->gl_ctx
->VB
->ClipMask
[i
]) {
650 x
= (GLint
) Current
->gl_ctx
->VB
->Win
[i
][0];
651 y
= FLIP( (GLint
) Current
->gl_ctx
->VB
->Win
[i
][1] );
652 wmSetPixel(pwc
, y
,x
,GetRValue(Current
->pixel
),
653 GetGValue(Current
->pixel
), GetBValue(Current
->pixel
));
658 /* draw points of different colors */
659 for (i
=first
;i
<=last
;i
++) {
660 if (!Current
->gl_ctx
->VB
->ClipMask
[i
]) {
662 unsigned long pixel
=RGB(Current
->gl_ctx
->VB
->Color
[i
][0]*255.0,
663 Current
->gl_ctx
->VB
->Color
[i
][1]*255.0,
664 Current
->gl_ctx
->VB
->Color
[i
][2]*255.0);
665 x
= (GLint
) Current
->gl_ctx
->VB
->Win
[i
][0];
666 y
= FLIP( (GLint
) Current
->gl_ctx
->VB
->Win
[i
][1] );
667 wmSetPixel(pwc
, y
,x
,Current
->gl_ctx
->VB
->Color
[i
][0]*255.0,
668 Current
->gl_ctx
->VB
->Color
[i
][1]*255.0,
669 Current
->gl_ctx
->VB
->Color
[i
][2]*255.0);
674 ENDPROFILE(fast_rgb_points
)
679 /* Return pointer to accerated points function */
680 extern points_func
choose_points_function( GLcontext
* ctx
)
683 if (ctx
->Point
.Size
==1.0 && !ctx
->Point
.SmoothFlag
&& ctx
->_RasterMask
==0
684 && !ctx
->Texture
.Enabled
&& ctx
->Visual
->RGBAflag
) {
685 ENDPROFILE(choose_points_function
)
686 return fast_rgb_points
;
689 ENDPROFILE(choose_points_function
)
696 /* Draw a line using the color specified by Current->gl_ctx->VB->Color[pv] */
697 static void fast_flat_rgb_line( GLcontext
* ctx
, GLuint v0
, GLuint v1
, GLuint pv
)
706 if (Current
->gl_ctx
->VB
->MonoColor
) {
707 pixel
= Current
->pixel
; /* use current color */
710 pixel
= RGB(Current
->gl_ctx
->VB
->Color
[pv
][0]*255.0, Current
->gl_ctx
->VB
->Color
[pv
][1]*255.0, Current
->gl_ctx
->VB
->Color
[pv
][2]*255.0);
713 x0
= (int) Current
->gl_ctx
->VB
->Win
[v0
][0];
714 y0
= FLIP( (int) Current
->gl_ctx
->VB
->Win
[v0
][1] );
715 x1
= (int) Current
->gl_ctx
->VB
->Win
[v1
][0];
716 y1
= FLIP( (int) Current
->gl_ctx
->VB
->Win
[v1
][1] );
721 Pen
=CreatePen(PS_SOLID
,1,pixel
);
722 Old_Pen
=SelectObject(DC
,Pen
);
723 MoveToEx(DC
,x0
,y0
,NULL
);
725 SelectObject(DC
,Old_Pen
);
731 ENDPROFILE(fast_flat_rgb_line
)
736 /* Return pointer to accerated line function */
737 static line_func
choose_line_function( GLcontext
* ctx
)
740 if (ctx
->Line
.Width
==1.0 && !ctx
->Line
.SmoothFlag
&& !ctx
->Line
.StippleFlag
741 && ctx
->Light
.ShadeModel
==GL_FLAT
&& ctx
->_RasterMask
==0
742 && !ctx
->Texture
.Enabled
&& Current
->rgb_flag
) {
743 ENDPROFILE(choose_line_function
)
744 return fast_flat_rgb_line
;
747 ENDPROFILE(choose_line_function
)
753 /**********************************************************************/
754 /***** Span-based pixel drawing *****/
755 /**********************************************************************/
758 /* Write a horizontal span of color-index pixels with a boolean mask. */
759 static void write_index_span( GLcontext
* ctx
,
760 GLuint n
, GLint x
, GLint y
,
761 const GLuint index
[],
762 const GLubyte mask
[] )
766 PBYTE Mem
=Current
->ScreenMem
+FLIP(y
)*Current
->ScanWidth
+x
;
767 assert(Current
->rgb_flag
==GL_FALSE
);
771 ENDPROFILE(write_index_span
)
777 * Write a horizontal span of pixels with a boolean mask. The current
778 * color index is used for all pixels.
780 static void write_monoindex_span(GLcontext
* ctx
,
781 GLuint n
,GLint x
,GLint y
,
782 const GLubyte mask
[])
786 BYTE
*Mem
=Current
->ScreenMem
+FLIP(y
)*Current
->ScanWidth
+x
;
787 assert(Current
->rgb_flag
==GL_FALSE
);
790 Mem
[i
]=Current
->pixel
;
791 ENDPROFILE(write_monoindex_span
)
795 To improve the performance of this routine, frob the data into an actual scanline
796 and call bitblt on the complete scan line instead of SetPixel.
799 /* Write a horizontal span of color pixels with a boolean mask. */
800 static void write_color_span( GLcontext
* ctx
,
801 GLuint n
, GLint x
, GLint y
,
803 red
[], const GLubyte green
[],
804 const GLubyte blue
[], const GLubyte alpha
[],
805 const GLubyte mask
[] )
811 if (pwc
->rgb_flag
==GL_TRUE
)
820 wmSetPixel(pwc
, y
, x
+ i
,red
[i
], green
[i
], blue
[i
]);
825 wmSetPixel(pwc
, y
, x
+ i
, red
[i
], green
[i
], blue
[i
]);
835 BYTE
*Mem
=Current
->ScreenMem
+y
*Current
->ScanWidth
+x
;
840 Mem
[i
]=GetNearestPaletteIndex(Current
->hPal
,RGB(red
[i
],green
[i
],blue
[i
]));
844 Mem
[i
]=GetNearestPaletteIndex(Current
->hPal
,RGB(red
[i
],green
[i
],blue
[i
]));
847 ENDPROFILE(write_color_span
)
852 * Write a horizontal span of pixels with a boolean mask. The current color
853 * is used for all pixels.
855 static void write_monocolor_span( GLcontext
* ctx
,
856 GLuint n
, GLint x
, GLint y
,
857 const GLubyte mask
[])
864 assert(Current
->rgb_flag
==GL_TRUE
);
867 if(Current
->rgb_flag
==GL_TRUE
){
871 wmSetPixel(pwc
,y
,x
+i
,GetRValue(Current
->pixel
), GetGValue(Current
->pixel
), GetBValue(Current
->pixel
));
876 SetPixel(DC
, y
, x
+i
, Current
->pixel
);
881 ENDPROFILE(write_monocolor_span
)
886 /**********************************************************************/
887 /***** Array-based pixel drawing *****/
888 /**********************************************************************/
891 /* Write an array of pixels with a boolean mask. */
892 static void write_index_pixels( GLcontext
* ctx
,
893 GLuint n
, const GLint x
[], const GLint y
[],
894 const GLuint index
[], const GLubyte mask
[] )
898 assert(Current
->rgb_flag
==GL_FALSE
);
899 for (i
=0; i
<n
; i
++) {
901 BYTE
*Mem
=Current
->ScreenMem
+FLIP(y
[i
])*Current
->ScanWidth
+x
[i
];
905 ENDPROFILE(write_index_pixels
)
911 * Write an array of pixels with a boolean mask. The current color
912 * index is used for all pixels.
914 static void write_monoindex_pixels( GLcontext
* ctx
,
916 const GLint x
[], const GLint y
[],
917 const GLubyte mask
[] )
921 assert(Current
->rgb_flag
==GL_FALSE
);
922 for (i
=0; i
<n
; i
++) {
924 BYTE
*Mem
=Current
->ScreenMem
+FLIP(y
[i
])*Current
->ScanWidth
+x
[i
];
925 *Mem
= Current
->pixel
;
928 ENDPROFILE(write_monoindex_pixels
)
933 /* Write an array of pixels with a boolean mask. */
934 static void write_color_pixels( GLcontext
* ctx
,
935 GLuint n
, const GLint x
[], const GLint y
[],
936 const GLubyte r
[], const GLubyte g
[],
937 const GLubyte b
[], const GLubyte a
[],
938 const GLubyte mask
[] )
944 assert(Current
->rgb_flag
==GL_TRUE
);
947 wmSetPixel(pwc
, FLIP(y
[i
]),x
[i
],r
[i
],g
[i
],b
[i
]);
949 ENDPROFILE(write_color_pixels
)
955 * Write an array of pixels with a boolean mask. The current color
956 * is used for all pixels.
958 static void write_monocolor_pixels( GLcontext
* ctx
,
960 const GLint x
[], const GLint y
[],
961 const GLubyte mask
[] )
967 assert(Current
->rgb_flag
==GL_TRUE
);
970 wmSetPixel(pwc
, FLIP(y
[i
]),x
[i
],GetRValue(Current
->pixel
),
971 GetGValue(Current
->pixel
), GetBValue(Current
->pixel
));
973 ENDPROFILE(write_monocolor_pixels
)
978 /**********************************************************************/
979 /***** Read spans/arrays of pixels *****/
980 /**********************************************************************/
983 /* Read a horizontal span of color-index pixels. */
984 static void read_index_span( GLcontext
* ctx
, GLuint n
, GLint x
, GLint y
, GLuint index
[])
988 BYTE
*Mem
=Current
->ScreenMem
+FLIP(y
)*Current
->ScanWidth
+x
;
989 assert(Current
->rgb_flag
==GL_FALSE
);
992 ENDPROFILE(read_index_span
)
999 /* Read an array of color index pixels. */
1000 static void read_index_pixels( GLcontext
* ctx
,
1001 GLuint n
, const GLint x
[], const GLint y
[],
1002 GLuint indx
[], const GLubyte mask
[] )
1006 assert(Current
->rgb_flag
==GL_FALSE
);
1007 for (i
=0; i
<n
; i
++) {
1009 indx
[i
]=*(Current
->ScreenMem
+FLIP(y
[i
])*Current
->ScanWidth
+x
[i
]);
1012 ENDPROFILE(read_index_pixels
)
1017 /* Read a horizontal span of color pixels. */
1018 static void read_color_span( GLcontext
* ctx
,
1019 GLuint n
, GLint x
, GLint y
,
1020 GLubyte red
[], GLubyte green
[],
1021 GLubyte blue
[], GLubyte alpha
[] )
1027 assert(Current
->rgb_flag
==GL_TRUE
);
1031 Color
=GetPixel(DC
,x
+i
,y
);
1032 red
[i
]=GetRValue(Color
);
1033 green
[i
]=GetGValue(Color
);
1034 blue
[i
]=GetBValue(Color
);
1038 memset(alpha
,0,n
*sizeof(GLint
));
1039 ENDPROFILE(read_color_span
)
1043 /* Read an array of color pixels. */
1044 static void read_color_pixels( GLcontext
* ctx
,
1045 GLuint n
, const GLint x
[], const GLint y
[],
1046 GLubyte red
[], GLubyte green
[],
1047 GLubyte blue
[], GLubyte alpha
[],
1048 const GLubyte mask
[] )
1054 assert(Current
->rgb_flag
==GL_TRUE
);
1055 for (i
=0; i
<n
; i
++) {
1057 Color
=GetPixel(DC
,x
[i
],FLIP(y
[i
]));
1058 red
[i
]=GetRValue(Color
);
1059 green
[i
]=GetGValue(Color
);
1060 blue
[i
]=GetBValue(Color
);
1065 memset(alpha
,0,n
*sizeof(GLint
));
1066 ENDPROFILE(read_color_pixels
)
1071 /**********************************************************************/
1072 /**********************************************************************/
1076 void setup_DD_pointers( GLcontext
* ctx
)
1078 ctx
->Driver
.UpdateState
= setup_DD_pointers
;
1079 ctx
->Driver
.GetBufferSize
= buffer_size
;
1080 ctx
->Driver
.Finish
= finish
;
1081 ctx
->Driver
.Flush
= flush
;
1083 ctx
->Driver
.ClearIndex
= clear_index
;
1084 ctx
->Driver
.ClearColor
= clear_color
;
1085 ctx
->Driver
.Clear
= clear
;
1087 ctx
->Driver
.Index
= set_index
;
1088 ctx
->Driver
.Color
= set_color
;
1089 ctx
->Driver
.IndexMask
= index_mask
;
1090 ctx
->Driver
.ColorMask
= color_mask
;
1092 ctx
->Driver
.LogicOp
= logicop
;
1093 ctx
->Driver
.Dither
= dither
;
1095 ctx
->Driver
.SetBuffer
= set_buffer
;
1096 ctx
->Driver
.GetBufferSize
= buffer_size
;
1098 ctx
->Driver
.PointsFunc
= choose_points_function(ctx
);
1099 ctx
->Driver
.LineFunc
= choose_line_function(ctx
);
1100 ctx
->Driver
.TriangleFunc
= choose_triangle_function( ctx
);
1102 /* Pixel/span writing functions: */
1103 ctx
->Driver
.WriteColorSpan
= write_color_span
;
1104 ctx
->Driver
.WriteMonocolorSpan
= write_monocolor_span
;
1105 ctx
->Driver
.WriteColorPixels
= write_color_pixels
;
1106 ctx
->Driver
.WriteMonocolorPixels
= write_monocolor_pixels
;
1107 ctx
->Driver
.WriteIndexSpan
= write_index_span
;
1108 ctx
->Driver
.WriteMonoindexSpan
= write_monoindex_span
;
1109 ctx
->Driver
.WriteIndexPixels
= write_index_pixels
;
1110 ctx
->Driver
.WriteMonoindexPixels
= write_monoindex_pixels
;
1112 /* Pixel/span reading functions: */
1113 ctx
->Driver
.ReadIndexSpan
= read_index_span
;
1114 ctx
->Driver
.ReadColorSpan
= read_color_span
;
1115 ctx
->Driver
.ReadIndexPixels
= read_index_pixels
;
1116 ctx
->Driver
.ReadColorPixels
= read_color_pixels
;
1120 /**********************************************************************/
1121 /***** WMesa API Functions *****/
1122 /**********************************************************************/
1126 #define PAL_SIZE 256
1127 static void GetPalette(HPALETTE Pal
,RGBQUAD
*aRGB
)
1135 WORD NumberOfEntries
;
1136 PALETTEENTRY aEntries
[PAL_SIZE
];
1144 GetPaletteEntries(Pal
,0,PAL_SIZE
,Palette
.aEntries
);
1146 GetSystemPaletteEntries(hdc
,0,PAL_SIZE
,Palette
.aEntries
);
1147 if (GetSystemPaletteUse(hdc
) == SYSPAL_NOSTATIC
)
1149 for(i
= 0; i
<PAL_SIZE
; i
++)
1150 Palette
.aEntries
[i
].peFlags
= PC_RESERVED
;
1151 Palette
.aEntries
[255].peRed
= 255;
1152 Palette
.aEntries
[255].peGreen
= 255;
1153 Palette
.aEntries
[255].peBlue
= 255;
1154 Palette
.aEntries
[255].peFlags
= 0;
1155 Palette
.aEntries
[0].peRed
= 0;
1156 Palette
.aEntries
[0].peGreen
= 0;
1157 Palette
.aEntries
[0].peBlue
= 0;
1158 Palette
.aEntries
[0].peFlags
= 0;
1164 nStaticColors
= GetDeviceCaps(hdc
, NUMCOLORS
)/2;
1165 for (i
=0; i
<nStaticColors
; i
++)
1166 Palette
.aEntries
[i
].peFlags
= 0;
1167 nUsableColors
= PAL_SIZE
-nStaticColors
;
1168 for (; i
<nUsableColors
; i
++)
1169 Palette
.aEntries
[i
].peFlags
= PC_RESERVED
;
1170 for (; i
<PAL_SIZE
-nStaticColors
; i
++)
1171 Palette
.aEntries
[i
].peFlags
= PC_RESERVED
;
1172 for (i
=PAL_SIZE
-nStaticColors
; i
<PAL_SIZE
; i
++)
1173 Palette
.aEntries
[i
].peFlags
= 0;
1175 ReleaseDC(NULL
,hdc
);
1176 for (i
=0; i
<PAL_SIZE
; i
++)
1178 aRGB
[i
].rgbRed
=Palette
.aEntries
[i
].peRed
;
1179 aRGB
[i
].rgbGreen
=Palette
.aEntries
[i
].peGreen
;
1180 aRGB
[i
].rgbBlue
=Palette
.aEntries
[i
].peBlue
;
1181 aRGB
[i
].rgbReserved
=Palette
.aEntries
[i
].peFlags
;
1183 ENDPROFILE(GetPalette
)
1187 WMesaContext
WMesaCreateContext( HWND hWnd
, HPALETTE
* Pal
,
1193 GLboolean true_color_flag
;
1194 c
= (struct wmesa_context
* ) calloc(1,sizeof(struct wmesa_context
));
1199 c
->hDC
= GetDC(hWnd
);
1200 true_color_flag
= GetDeviceCaps(c
->hDC
, BITSPIXEL
) > 8;
1202 if(true_color_flag
) c
->rgb_flag
= rgb_flag
= GL_TRUE
;
1207 if ((true_color_flag
==GL_FALSE
) && (rgb_flag
== GL_TRUE
)){
1208 c
->dither_flag
= GL_TRUE
;
1209 c
->hPalHalfTone
= WinGCreateHalftonePalette();
1212 c
->dither_flag
= GL_FALSE
;
1214 c
->dither_flag
= GL_FALSE
;
1218 if (rgb_flag
==GL_FALSE
)
1220 c
->rgb_flag
= GL_FALSE
;
1222 c
->db_flag
= db_flag
=GL_TRUE
; // WinG requires double buffering
1223 printf("Single buffer is not supported in color index mode, setting to double buffer.\n");
1227 c
->rgb_flag
= GL_TRUE
;
1230 GetClientRect(c
->Window
,&CR
);
1232 c
->height
=CR
.bottom
;
1236 /* Double buffered */
1238 // if (c->rgb_flag==GL_TRUE && c->dither_flag != GL_TRUE )
1240 wmCreateBackingStore(c
, c
->width
, c
->height
);
1247 /* Single Buffered */
1252 if (DDInit(c
,hWnd
) == GL_FALSE
) {
1259 c
->gl_visual
= gl_create_visual(rgb_flag
,
1260 GL_FALSE
, /* software alpha */
1261 db_flag
, /* db_flag */
1262 16, /* depth_bits */
1263 8, /* stencil_bits */
1266 255.0, 255.0, 255.0, 255.0,
1269 if (!c
->gl_visual
) {
1273 /* allocate a new Mesa context */
1274 c
->gl_ctx
= gl_create_context( c
->gl_visual
, NULL
,c
);
1277 gl_destroy_visual( c
->gl_visual
);
1282 c
->gl_buffer
= gl_create_framebuffer( c
->gl_visual
);
1283 if (!c
->gl_buffer
) {
1284 gl_destroy_visual( c
->gl_visual
);
1285 gl_destroy_context( c
->gl_ctx
);
1289 // setup_DD_pointers(c->gl_ctx);
1294 void WMesaDestroyContext( void )
1296 WMesaContext c
= Current
;
1297 ReleaseDC(c
->Window
,c
->hDC
);
1299 if(c
->hPalHalfTone
!= NULL
)
1300 DeleteObject(c
->hPalHalfTone
);
1301 gl_destroy_visual( c
->gl_visual
);
1302 gl_destroy_framebuffer( c
->gl_buffer
);
1303 gl_destroy_context( c
->gl_ctx
);
1309 wmDeleteBackingStore(c
);
1312 //Following code is added to enable parallel render
1313 // Parallel render only work in double buffer mode
1314 #if !defined(NO_PARALLEL)
1316 PRDestroyRenderBuffer();
1323 void /*APIENTRY*/ WMesaMakeCurrent( WMesaContext c
)
1331 // A little optimization
1332 // If it already is current,
1333 // don't set it again
1338 //gl_set_context( c->gl_ctx );
1339 gl_make_current(c
->gl_ctx
, c
->gl_buffer
);
1341 setup_DD_pointers(c
->gl_ctx
);
1342 if (Current
->gl_ctx
->Viewport
.Width
==0) {
1343 /* initialize viewport to window size */
1344 _mesa_set_viewport( Current
->gl_ctx
,
1345 0, 0, Current
->width
, Current
->height
);
1347 if ((c
->cColorBits
<= 8 ) && (c
->rgb_flag
== GL_TRUE
)){
1348 WMesaPaletteChange(c
->hPalHalfTone
);
1354 void /*APIENTRY*/ WMesaSwapBuffers( void )
1356 HDC DC
= Current
->hDC
;
1357 if (Current
->db_flag
)
1363 void /*APIENTRY*/ WMesaPaletteChange(HPALETTE Pal
)
1366 LPPALETTEENTRY pPal
;
1367 if (Current
&& (Current
->rgb_flag
==GL_FALSE
|| Current
->dither_flag
== GL_TRUE
))
1369 pPal
= (PALETTEENTRY
*)malloc( 256 * sizeof(PALETTEENTRY
));
1371 // GetPaletteEntries( Pal, 0, 256, pPal );
1372 GetPalette( Pal
, pPal
);
1374 Current
->lpDD
->lpVtbl
->CreatePalette(Current
->lpDD
,DDPCAPS_8BIT
,
1375 pPal
, &(Current
->lpDDPal
), NULL
);
1376 if (Current
->lpDDPal
)
1377 Current
->lpDDSPrimary
->lpVtbl
->SetPalette(Current
->lpDDSPrimary
,Current
->lpDDPal
);
1379 vRet
= SetDIBColorTable(Current
->dib
.hDC
,0,256,pPal
);
1389 static unsigned char threeto8
[8] = {
1390 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
1393 static unsigned char twoto8
[4] = {
1397 static unsigned char oneto8
[2] = {
1401 static unsigned char componentFromIndex(UCHAR i
, UINT nbits
, UINT shift
)
1418 return threeto8
[val
];
1425 void /*WINAPI*/ wmCreatePalette( PWMC pwdc
)
1427 /* Create a compressed and re-expanded 3:3:2 palette */
1430 BYTE rb
, rs
, gb
, gs
, bb
, bs
;
1432 pwdc
->nColors
= 0x100;
1434 pPal
= (PLOGPALETTE
)malloc(sizeof(LOGPALETTE
) + pwdc
->nColors
* sizeof(PALETTEENTRY
));
1435 memset( pPal
, 0, sizeof(LOGPALETTE
) + pwdc
->nColors
* sizeof(PALETTEENTRY
) );
1437 pPal
->palVersion
= 0x300;
1446 if (pwdc
->db_flag
) {
1448 /* Need to make two palettes: one for the screen DC and one for the DIB. */
1449 pPal
->palNumEntries
= pwdc
->nColors
;
1450 for (i
= 0; i
< pwdc
->nColors
; i
++) {
1451 pPal
->palPalEntry
[i
].peRed
= componentFromIndex( i
, rb
, rs
);
1452 pPal
->palPalEntry
[i
].peGreen
= componentFromIndex( i
, gb
, gs
);
1453 pPal
->palPalEntry
[i
].peBlue
= componentFromIndex( i
, bb
, bs
);
1454 pPal
->palPalEntry
[i
].peFlags
= 0;
1456 pwdc
->hGLPalette
= CreatePalette( pPal
);
1457 pwdc
->hPalette
= CreatePalette( pPal
);
1461 pPal
->palNumEntries
= pwdc
->nColors
;
1462 for (i
= 0; i
< pwdc
->nColors
; i
++) {
1463 pPal
->palPalEntry
[i
].peRed
= componentFromIndex( i
, rb
, rs
);
1464 pPal
->palPalEntry
[i
].peGreen
= componentFromIndex( i
, gb
, gs
);
1465 pPal
->palPalEntry
[i
].peBlue
= componentFromIndex( i
, bb
, bs
);
1466 pPal
->palPalEntry
[i
].peFlags
= 0;
1468 pwdc
->hGLPalette
= CreatePalette( pPal
);
1475 void /*WINAPI*/ wmSetPixel(PWMC pwc
, int iScanLine
, int iPixel
, BYTE r
, BYTE g
, BYTE b
)
1477 if(Current
->db_flag
){
1478 LPBYTE lpb
= pwc
->pbPixels
;
1481 UINT nBypp
= pwc
->cColorBits
/ 8;
1482 UINT nOffset
= iPixel
% nBypp
;
1484 // Move the pixel buffer pointer to the scanline that we
1487 // pwc->dib.fFlushed = FALSE;
1489 lpb
+= pwc
->ScanWidth
* iScanLine
;
1490 // Now move to the desired pixel
1491 lpb
+= iPixel
* nBypp
;
1492 lpb
= PIXELADDR(iPixel
, iScanLine
);
1493 lpdw
= (LPDWORD
)lpb
;
1497 if(pwc
->dither_flag
)
1498 *lpb
= DITHER_RGB_2_8BIT(r
,g
,b
,iScanLine
,iPixel
);
1503 *lpw
= BGR16(r
,g
,b
);
1504 else if (nBypp
== 3){
1505 *lpdw
= BGR24(r
,g
,b
);
1507 else if (nBypp
== 4)
1508 *lpdw
= BGR32(r
,g
,b
);
1512 SetPixel(DC
, iPixel
, iScanLine
, RGB(r
,g
,b
));
1517 void /*WINAPI*/ wmCreateDIBSection(
1519 PWMC pwc
, // handle of device context
1520 CONST BITMAPINFO
*pbmi
, // address of structure containing bitmap size, format, and color data
1521 UINT iUsage
// color data type indicator: RGB values or palette indices
1526 UINT nBypp
= pwc
->cColorBits
/ 8;
1529 dwScanWidth
= (((pwc
->ScanWidth
* nBypp
)+ 3) & ~3);
1531 pwc
->ScanWidth
=pwc
->pitch
= dwScanWidth
;
1534 pwc
->ScanWidth
= 2* pwc
->pitch
;
1536 dwSize
= sizeof(BITMAPINFO
) + (dwScanWidth
* pwc
->height
);
1538 pwc
->dib
.hFileMap
= CreateFileMapping((HANDLE
)PAGE_FILE
,
1540 PAGE_READWRITE
| SEC_COMMIT
,
1545 if (!pwc
->dib
.hFileMap
)
1548 pwc
->dib
.base
= MapViewOfFile(pwc
->dib
.hFileMap
,
1549 FILE_MAP_ALL_ACCESS
,
1555 CloseHandle(pwc
->dib
.hFileMap
);
1559 // pwc->pbPixels = pwc->addrOffScreen = ((LPBYTE)pwc->dib.base) + sizeof(BITMAPINFO);
1561 // pwc->dib.hDC = CreateCompatibleDC(hDC);
1563 CopyMemory(pwc
->dib
.base
, pbmi
, sizeof(BITMAPINFO
));
1565 hic
= CreateIC("display", NULL
, NULL
, NULL
);
1566 pwc
->dib
.hDC
= CreateCompatibleDC(hic
);
1569 /* pwc->hbmDIB = CreateDIBitmap(hic,
1570 &(pwc->bmi.bmiHeader),
1576 pwc
->hbmDIB
= CreateDIBSection(hic
,
1578 (iUsage
? DIB_PAL_COLORS
: DIB_RGB_COLORS
),
1583 pwc->hbmDIB = CreateDIBSection(hic,
1590 pwc
->ScreenMem
= pwc
->addrOffScreen
= pwc
->pbPixels
;
1591 pwc
->hOldBitmap
= SelectObject(pwc
->dib
.hDC
, pwc
->hbmDIB
);
1600 // Blit memory DC to screen DC
1602 BOOL
/*WINAPI*/ wmFlush(PWMC pwc
)
1608 // Now search through the torus frames and mark used colors
1611 if (pwc
->lpDDSOffScreen
== NULL
)
1612 if(DDCreateOffScreen(pwc
) == GL_FALSE
)
1615 pwc
->lpDDSOffScreen
->lpVtbl
->Unlock(pwc
->lpDDSOffScreen
, NULL
);
1619 ddrval
= pwc
->lpDDSPrimary
->lpVtbl
->Blt( pwc
->lpDDSPrimary
,
1620 &(pwc
->rectSurface
), pwc
->lpDDSOffScreen
, &(pwc
->rectOffScreen
), 0, NULL
);
1622 if( ddrval
== DD_OK
)
1626 if( ddrval
== DDERR_SURFACELOST
)
1628 if(!DDRestoreAll(pwc
))
1633 if( ddrval
!= DDERR_WASSTILLDRAWING
)
1639 while (pwc
->lpDDSOffScreen
->lpVtbl
->Lock(pwc
->lpDDSOffScreen
,
1640 NULL
, &(pwc
->ddsd
), 0, NULL
) == DDERR_WASSTILLDRAWING
)
1644 dwErr
= GetLastError();
1646 bRet
= BitBlt(pwc
->hDC
, 0, 0, pwc
->width
, pwc
->height
,
1647 pwc
->dib
.hDC
, 0, 0, SRCCOPY
);
1656 // The following code is added by Li Wei to enable stereo display
1658 #if !defined(NO_STEREO)
1660 void WMesaShowStereo(GLuint list
)
1663 GLbitfield mask
= GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
;
1666 // Must use double Buffer
1667 if( ! Current
-> db_flag
)
1671 glGetIntegerv(GL_MATRIX_MODE
,&matrix_mode
);
1673 // glPushMatrix(); //****
1674 WMesaViewport(Current
->gl_ctx
,0,Current
->height
/2,Current
->width
,Current
->height
/2);
1675 // Current->gl_ctx->NewState = 0;
1677 // glViewport(0,0,Current->width,Current->height/2);
1678 if(matrix_mode
!=GL_MODELVIEW
)
1679 glMatrixMode(GL_MODELVIEW
);
1681 glGetFloatv(GL_MODELVIEW_MATRIX
,cm
);
1683 gluLookAt(viewDistance
/2,0.0,0.0 ,
1684 viewDistance
/2,0.0,-1.0,
1686 // glTranslatef(viewDistance/2.0,0.,0.);
1687 glMultMatrixf( cm
);
1689 Current
->ScreenMem
= Current
->pbPixels
= Current
->addrOffScreen
;
1694 glGetFloatv(GL_MODELVIEW_MATRIX
,cm
);
1696 gluLookAt(-viewDistance
/2,0.0,0.0 ,
1697 -viewDistance
/2,0.0,-1.0,
1699 // glTranslatef(-viewDistance/2.0,0.,0.);
1702 Current
->ScreenMem
= Current
->pbPixels
= Current
->addrOffScreen
+ Current
->pitch
;
1704 if(matrix_mode
!=GL_MODELVIEW
)
1705 glMatrixMode(matrix_mode
);
1710 WMesaViewport(Current
->gl_ctx
,0,0,Current
->width
,Current
->height
);
1711 // Current->gl_ctx->NewState = 0;
1716 void toggleStereoMode()
1718 if(!Current
->db_flag
)
1722 if(stereoBuffer
==GL_FALSE
)
1723 #if !defined(NO_PARALLEL)
1727 Current
->ScanWidth
= Current
->pitch
*2;
1732 #if !defined(NO_PARALLEL)
1735 Current
->ScanWidth
= Current
->pitch
;
1736 Current
->pbPixels
= Current
->addrOffScreen
;
1740 /* if in stereo mode, the following function is called */
1741 void glShowStereo(GLuint list
)
1743 WMesaShowStereo(list
);
1746 #endif // End if NO_STEREO not defined
1748 #if !defined(NO_PARALLEL)
1750 void toggleParallelMode(void)
1753 parallelFlag
= GL_TRUE
;
1754 if(parallelMachine
==GL_FALSE
){
1755 PRCreateRenderBuffer( Current
->rgb_flag
? GL_RGBA
:GL_COLOR_INDEX
,
1756 Current
->cColorBits
/8,
1757 Current
->width
,Current
->height
,
1759 Current
->rgb_flag
? Current
->pbPixels
: Current
->ScreenMem
);
1760 parallelMachine
= GL_TRUE
;
1764 parallelFlag
= GL_FALSE
;
1765 if(parallelMachine
==GL_TRUE
){
1766 PRDestroyRenderBuffer();
1767 parallelMachine
=GL_FALSE
;
1768 ReadyForNextFrame
= GL_TRUE
;
1771 /***********************************************
1772 // Seems something wrong!!!!
1773 ************************************************/
1775 WMesaMakeCurrent(Current
);
1776 #if !defined(NO_STEREO)
1777 stereo_flag
= GL_FALSE
;
1782 void PRShowRenderResult(void)
1785 if(!glImageRendered())
1794 #endif //End if NO_PARALLEL not defined
1798 BYTE
DITHER_RGB_2_8BIT( int red
, int green
, int blue
, int pixel
, int scanline
)
1800 char unsigned redtemp
, greentemp
, bluetemp
, paletteindex
;
1802 //*** now, look up each value in the halftone matrix
1803 //*** using an 8x8 ordered dither.
1804 redtemp
= aDividedBy51
[red
]
1805 + (aModulo51
[red
] > aHalftone8x8
[(pixel
%8)*8
1807 greentemp
= aDividedBy51
[(char unsigned)green
]
1808 + (aModulo51
[green
] > aHalftone8x8
[
1809 (pixel
%8)*8 + scanline
%8]);
1810 bluetemp
= aDividedBy51
[(char unsigned)blue
]
1811 + (aModulo51
[blue
] > aHalftone8x8
[
1812 (pixel
%8)*8 +scanline
%8]);
1814 //*** recombine the halftoned rgb values into a palette index
1816 redtemp
+ aTimes6
[greentemp
] + aTimes36
[bluetemp
];
1818 //*** and translate through the wing halftone palette
1819 //*** translation vector to give the correct value.
1820 return aWinGHalftoneTranslation
[paletteindex
];
1827 * restore all lost objects
1829 HRESULT
DDRestoreAll( WMesaContext wc
)
1833 ddrval
= wc
->lpDDSPrimary
->lpVtbl
->Restore(wc
->lpDDSPrimary
);
1834 if( ddrval
== DD_OK
)
1836 ddrval
= wc
->lpDDSOffScreen
->lpVtbl
->Restore(wc
->lpDDSOffScreen
);
1844 * This function is called if the initialization function fails
1846 BOOL
initFail( HWND hwnd
, WMesaContext wc
)
1849 MessageBox( hwnd
, "DirectDraw Init FAILED", "", MB_OK
);
1855 static void DDDeleteOffScreen(WMesaContext wc
)
1857 if( wc
->lpDDSOffScreen
!= NULL
)
1859 wc
->lpDDSOffScreen
->lpVtbl
->Unlock(wc
->lpDDSOffScreen
,NULL
);
1860 wc
->lpDDSOffScreen
->lpVtbl
->Release(wc
->lpDDSOffScreen
);
1861 wc
->lpDDSOffScreen
= NULL
;
1866 static void DDFreePrimarySurface(WMesaContext wc
)
1868 if( wc
->lpDDSPrimary
!= NULL
)
1870 if(wc
->db_flag
== GL_FALSE
)
1871 wc
->lpDDSPrimary
->lpVtbl
->ReleaseDC(wc
->lpDDSPrimary
, wc
->hDC
);
1872 wc
->lpDDSPrimary
->lpVtbl
->Release(wc
->lpDDSPrimary
);
1873 wc
->lpDDSPrimary
= NULL
;
1877 static BOOL
DDCreatePrimarySurface(WMesaContext wc
)
1881 wc
->ddsd
.dwSize
= sizeof( wc
->ddsd
);
1882 wc
->ddsd
.dwFlags
= DDSD_CAPS
;
1883 wc
->ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
1885 ddrval
= wc
->lpDD
->lpVtbl
->CreateSurface( wc
->lpDD
,&(wc
->ddsd
), &(wc
->lpDDSPrimary
), NULL
);
1886 if( ddrval
!= DD_OK
)
1888 return initFail(wc
->hwnd
, wc
);
1890 if(wc
->db_flag
== GL_FALSE
)
1891 wc
->lpDDSPrimary
->lpVtbl
->GetDC(wc
->lpDDSPrimary
, wc
->hDC
);
1895 static BOOL
DDCreateOffScreen(WMesaContext wc
)
1899 if(wc
->lpDD
== NULL
)
1901 GetClientRect( wc
->hwnd
, &(wc
->rectOffScreen
) );
1902 wc
->ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
;
1903 wc
->ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
1904 wc
->ddsd
.dwHeight
= wc
->rectOffScreen
.bottom
- wc
->rectOffScreen
.top
;
1905 wc
->ddsd
.dwWidth
= wc
->rectOffScreen
.right
- wc
->rectOffScreen
.left
;
1907 ddrval
= wc
->lpDD
->lpVtbl
->CreateSurface( wc
->lpDD
, &(wc
->ddsd
), &(wc
->lpDDSOffScreen
), NULL
);
1908 if( ddrval
!= DD_OK
)
1913 while (wc
->lpDDSOffScreen
->lpVtbl
->Lock(wc
->lpDDSOffScreen
,NULL
, &(wc
->ddsd
), 0, NULL
) == DDERR_WASSTILLDRAWING
)
1915 // while ((ddrval = wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), DDLOCK_SURFACEMEMORYPTR , NULL)) != DD_OK)
1917 if(wc
->ddsd
.lpSurface
==NULL
)
1918 return initFail(wc
->hwnd
, wc
);
1920 wc
->ScreenMem
= wc
->pbPixels
= wc
->addrOffScreen
= (PBYTE
)(wc
->ddsd
.lpSurface
);
1921 wc
->ScanWidth
= wc
->pitch
= wc
->ddsd
.lPitch
;
1923 wc
->ScanWidth
= wc
->ddsd
.lPitch
*2;
1925 GetClientRect( wc
->hwnd
, &(wc
->rectSurface
) );
1927 ClientToScreen( wc
->hwnd
, &pt
);
1928 OffsetRect(&(wc
->rectSurface
), pt
.x
, pt
.y
);
1929 wmSetPixelFormat(wc
, wc
->hDC
);
1934 * doInit - do work required for every instance of the application:
1935 * create the window, initialize data
1937 static BOOL
DDInit( WMesaContext wc
, HWND hwnd
)
1942 LPDIRECTDRAW lpDD
; // DirectDraw object
1943 LPDIRECTDRAW2 lpDD2
;
1946 wc
->fullScreen
= displayOptions
.fullScreen
;
1947 wc
->gMode
= displayOptions
.mode
;
1949 stereo_flag
= displayOptions
.stereo
;
1950 if(wc
->db_flag
!= GL_TRUE
)
1951 stereo_flag
= GL_FALSE
;
1953 * create the main DirectDraw object
1955 ddrval
= DirectDrawCreate( NULL
, &(wc
->lpDD
), NULL
);
1956 if( ddrval
!= DD_OK
)
1958 return initFail(hwnd
,wc
);
1961 // Get exclusive mode if requested
1964 ddrval
= wc
->lpDD
->lpVtbl
->SetCooperativeLevel( wc
->lpDD
, hwnd
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1968 ddrval
= wc
->lpDD
->lpVtbl
->SetCooperativeLevel( wc
->lpDD
, hwnd
, DDSCL_NORMAL
);
1970 if( ddrval
!= DD_OK
)
1972 return initFail(hwnd
, wc
);
1976 /* ddrval = wc->lpDD->lpVtbl->QueryInterface(wc->lpDD, IID_IDirectDraw2,
1977 (LPVOID *)((wc->lpDD2)));
1981 return initFail(hwnd
, wc
);
1984 //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
1985 // wc->lpDD2->lpVtbl->GetMonitorFrequency(wc->lpDD, &dwFrequency);
1988 case 1: ddrval
= wc
->lpDD
->lpVtbl
->SetDisplayMode( wc
->lpDD
, 640, 480, displayOptions
.bpp
); break;
1989 case 2: ddrval
= wc
->lpDD
->lpVtbl
->SetDisplayMode( wc
->lpDD
, 800, 600, displayOptions
.bpp
); break;
1990 case 3: ddrval
= wc
->lpDD
->lpVtbl
->SetDisplayMode( wc
->lpDD
, 1024, 768, displayOptions
.bpp
); break;
1991 case 4: ddrval
= wc
->lpDD
->lpVtbl
->SetDisplayMode( wc
->lpDD
, 1152, 864, displayOptions
.bpp
); break;
1992 case 5: ddrval
= wc
->lpDD
->lpVtbl
->SetDisplayMode( wc
->lpDD
, 1280, 1024, displayOptions
.bpp
); break;
1995 if( ddrval
!= DD_OK
)
1997 printf("Can't modify display mode, current mode used\n");
1998 // return initFail(hwnd , wc);
2000 //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
2002 case DDERR_INVALIDOBJECT
:
2004 case DDERR_INVALIDPARAMS
:
2006 case DDERR_UNSUPPORTEDMODE
:
2010 if(DDCreatePrimarySurface(wc
) == GL_FALSE
)
2011 return initFail(hwnd
, wc
);
2014 return DDCreateOffScreen(wc
);
2017 static void DDFree( WMesaContext wc
)
2019 if( wc
->lpDD
!= NULL
)
2021 DDFreePrimarySurface(wc
);
2022 DDDeleteOffScreen(wc
);
2023 wc
->lpDD
->lpVtbl
->Release(wc
->lpDD
);
2026 // Clean up the screen on exit
2027 RedrawWindow( NULL
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ERASE
|
2033 void WMesaMove(void)
2035 WMesaContext wc
= Current
;
2037 if (Current
!= NULL
){
2038 GetClientRect( wc
->hwnd
, &(wc
->rectSurface
) );
2040 ClientToScreen( wc
->hwnd
, &pt
);
2041 OffsetRect(&(wc
->rectSurface
), pt
.x
, pt
.y
);
2046 * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
2049 #define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
2052 /**********************************************************************/
2053 /*** Triangle rendering ***/
2054 /**********************************************************************/
2059 * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
2061 static void smooth_8A8B8G8R_z_triangle( GLcontext
*ctx
,
2062 GLuint v0
, GLuint v1
, GLuint v2
,
2065 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2067 #define INTERP_RGB 1
2068 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2069 #define PIXEL_TYPE GLuint
2070 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2071 #define BYTES_PER_ROW (wmesa->ScanWidth)
2072 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2074 GLint i, len = RIGHT-LEFT; \
2075 for (i=0;i<len;i++) { \
2076 GLdepth z = FixedToDepth(ffz); \
2077 if (z < zRow[i]) { \
2078 pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
2079 FixedToInt(ffb) ); \
2082 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2086 #include "tritemp.h"
2091 * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
2093 static void smooth_8R8G8B_z_triangle( GLcontext
*ctx
,
2094 GLuint v0
, GLuint v1
, GLuint v2
,
2097 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2099 #define INTERP_RGB 1
2100 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2101 #define PIXEL_TYPE GLuint
2102 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2103 #define BYTES_PER_ROW (wmesa->ScanWidth)
2104 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2106 GLint i, len = RIGHT-LEFT; \
2107 for (i=0;i<len;i++) { \
2108 GLdepth z = FixedToDepth(ffz); \
2109 if (z < zRow[i]) { \
2110 pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
2111 FixedToInt(ffb) ); \
2114 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2118 #include "tritemp.h"
2124 * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
2126 static void smooth_5R6G5B_z_triangle( GLcontext
*ctx
,
2127 GLuint v0
, GLuint v1
, GLuint v2
,
2130 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2132 #define INTERP_RGB 1
2133 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
2134 #define PIXEL_TYPE GLushort
2135 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2136 #define BYTES_PER_ROW (wmesa->ScanWidth)
2137 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2139 GLint i, len = RIGHT-LEFT; \
2140 for (i=0;i<len;i++) { \
2141 GLdepth z = FixedToDepth(ffz); \
2142 if (z < zRow[i]) { \
2143 pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
2144 FixedToInt(ffb) ); \
2147 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2151 #include "tritemp.h"
2155 * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
2157 static void flat_8A8B8G8R_z_triangle( GLcontext
*ctx
, GLuint v0
,
2158 GLuint v1
, GLuint v2
, GLuint pv
)
2160 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2162 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2163 #define PIXEL_TYPE GLuint
2164 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2165 #define BYTES_PER_ROW (wmesa->ScanWidth)
2166 #define SETUP_CODE \
2167 unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
2168 VB->Color[pv][1], VB->Color[pv][2] );
2169 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2171 GLint i, len = RIGHT-LEFT; \
2172 for (i=0;i<len;i++) { \
2173 GLdepth z = FixedToDepth(ffz); \
2174 if (z < zRow[i]) { \
2181 #include "tritemp.h"
2186 * XImage, flat, depth-buffered, PF_8R8G8B triangle.
2188 static void flat_8R8G8B_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2189 GLuint v2
, GLuint pv
)
2191 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2193 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2194 #define PIXEL_TYPE GLuint
2195 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2196 #define BYTES_PER_ROW (wmesa->ScanWidth)
2197 #define SETUP_CODE \
2198 unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
2199 VB->Color[pv][1], VB->Color[pv][2] );
2200 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2202 GLint i, len = RIGHT-LEFT; \
2203 for (i=0;i<len;i++) { \
2204 GLdepth z = FixedToDepth(ffz); \
2205 if (z < zRow[i]) { \
2212 #include "tritemp.h"
2217 * XImage, flat, depth-buffered, PF_5R6G5B triangle.
2219 static void flat_5R6G5B_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2220 GLuint v2
, GLuint pv
)
2222 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2224 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
2225 #define PIXEL_TYPE GLushort
2226 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2227 #define BYTES_PER_ROW (wmesa->ScanWidth)
2228 #define SETUP_CODE \
2229 unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
2230 VB->Color[pv][1], VB->Color[pv][2] );
2231 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2233 GLint i, len = RIGHT-LEFT; \
2234 for (i=0;i<len;i++) { \
2235 GLdepth z = FixedToDepth(ffz); \
2236 if (z < zRow[i]) { \
2243 #include "tritemp.h"
2248 * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
2250 static void smooth_8A8B8G8R_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2251 GLuint v2
, GLuint pv
)
2253 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2254 #define INTERP_RGB 1
2255 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2256 #define PIXEL_TYPE GLuint
2257 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2258 #define BYTES_PER_ROW (wmesa->ScanWidth)
2259 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2262 PIXEL_TYPE *pixel = pRow; \
2263 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2264 *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
2265 FixedToInt(ffb) ); \
2266 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2269 #include "tritemp.h"
2274 * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
2276 static void smooth_8R8G8B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2277 GLuint v2
, GLuint pv
)
2279 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2280 #define INTERP_RGB 1
2281 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2282 #define PIXEL_TYPE GLuint
2283 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2284 #define BYTES_PER_ROW (wmesa->ScanWidth)
2285 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2288 PIXEL_TYPE *pixel = pRow; \
2289 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2290 *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
2291 FixedToInt(ffb) ); \
2292 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2295 #include "tritemp.h"
2300 * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
2302 static void smooth_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2303 GLuint v2
, GLuint pv
)
2305 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2306 #define INTERP_RGB 1
2307 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
2308 #define PIXEL_TYPE GLushort
2309 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2310 #define BYTES_PER_ROW (wmesa->ScanWidth)
2311 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2314 PIXEL_TYPE *pixel = pRow; \
2315 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2316 *pixel = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
2317 FixedToInt(ffb) ); \
2318 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2321 #include "tritemp.h"
2327 * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
2329 static void flat_8A8B8G8R_triangle( GLcontext
*ctx
, GLuint v0
,
2330 GLuint v1
, GLuint v2
, GLuint pv
)
2332 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2333 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2334 #define PIXEL_TYPE GLuint
2335 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2336 #define BYTES_PER_ROW (wmesa->ScanWidth)
2337 #define SETUP_CODE \
2338 unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
2339 VB->Color[pv][1], VB->Color[pv][2] );
2340 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2343 PIXEL_TYPE *pixel = pRow; \
2344 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2348 #include "tritemp.h"
2353 * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
2355 static void flat_8R8G8B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2356 GLuint v2
, GLuint pv
)
2358 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2359 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
2360 #define PIXEL_TYPE GLuint
2361 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2362 #define BYTES_PER_ROW (wmesa->ScanWidth)
2363 #define SETUP_CODE \
2364 unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
2365 VB->Color[pv][1], VB->Color[pv][2] );
2366 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2369 PIXEL_TYPE *pixel = pRow; \
2370 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2374 #include "tritemp.h"
2379 * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
2381 static void flat_5R6G5B_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2382 GLuint v2
, GLuint pv
)
2384 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2385 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
2386 #define PIXEL_TYPE GLushort
2387 //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
2388 #define BYTES_PER_ROW (wmesa->ScanWidth)
2389 #define SETUP_CODE \
2390 unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
2391 VB->Color[pv][1], VB->Color[pv][2] );
2392 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2395 PIXEL_TYPE *pixel = pRow; \
2396 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2400 #include "tritemp.h"
2405 * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
2408 static void smooth_ci_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2409 GLuint v2
, GLuint pv
)
2411 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2413 #define INTERP_INDEX 1
2414 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2415 #define PIXEL_TYPE GLubyte
2416 #define BYTES_PER_ROW (wmesa->ScanWidth)
2417 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2419 GLint i, len = RIGHT-LEFT; \
2420 for (i=0;i<len;i++) { \
2421 GLdepth z = FixedToDepth(ffz); \
2422 if (z < zRow[i]) { \
2423 pRow[i] = FixedToInt(ffi); \
2431 #include "tritemp.h"
2436 * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
2439 static void flat_ci_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2440 GLuint v2
, GLuint pv
)
2442 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2444 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2445 #define PIXEL_TYPE GLubyte
2446 #define BYTES_PER_ROW (wmesa->ScanWidth)
2447 #define SETUP_CODE \
2448 GLuint index = VB->Index[pv]; \
2449 if (!VB->MonoColor) { \
2450 /* set the color index */ \
2451 (*ctx->Driver.Index)( ctx, index ); \
2453 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2455 GLint i, len = RIGHT-LEFT; \
2456 for (i=0;i<len;i++) { \
2457 GLdepth z = FixedToDepth(ffz); \
2458 if (z < zRow[i]) { \
2465 #include "tritemp.h"
2471 * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
2474 static void smooth_ci_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2475 GLuint v2
, GLuint pv
)
2477 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2479 #define INTERP_INDEX 1
2480 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2481 #define PIXEL_TYPE GLubyte
2482 #define BYTES_PER_ROW (wmesa->ScanWidth)
2483 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2486 PIXEL_TYPE *pixel = pRow; \
2487 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2488 *pixel = FixedToInt(ffi); \
2492 #include "tritemp.h"
2497 * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
2499 static void flat_ci_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2500 GLuint v2
, GLuint pv
)
2502 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2504 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2505 #define PIXEL_TYPE GLubyte
2506 #define BYTES_PER_ROW (wmesa->ScanWidth)
2507 #define SETUP_CODE \
2508 GLuint index = VB->Index[pv]; \
2509 if (!VB->MonoColor) { \
2510 /* set the color index */ \
2511 (*ctx->Driver.Index)( ctx, index ); \
2513 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2516 PIXEL_TYPE *pixel = pRow; \
2517 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2521 #include "tritemp.h"
2525 * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
2527 static void smooth_DITHER8_z_triangle( GLcontext
*ctx
,
2528 GLuint v0
, GLuint v1
, GLuint v2
,
2531 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2532 DITHER_RGB_TO_8BIT_SETUP
2534 #define INTERP_RGB 1
2535 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2536 #define PIXEL_TYPE GLubyte
2537 #define BYTES_PER_ROW (wmesa->ScanWidth)
2538 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2540 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
2541 for (i=0;i<len;i++,xx++) { \
2542 GLdepth z = FixedToDepth(ffz); \
2543 if (z < zRow[i]) { \
2544 DITHER_RGB_TO_8BIT( FixedToInt(ffr), FixedToInt(ffg), \
2545 FixedToInt(ffb), xx, yy); \
2546 pRow[i] = pixelDithered; \
2549 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2553 #include "tritemp.h"
2557 * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
2559 static void flat_DITHER8_z_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2560 GLuint v2
, GLuint pv
)
2562 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2563 DITHER_RGB_TO_8BIT_SETUP
2565 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2566 #define PIXEL_TYPE GLubyte
2567 #define BYTES_PER_ROW (wmesa->ScanWidth)
2569 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2571 GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
2572 for (i=0;i<len;i++,xx++) { \
2573 GLdepth z = FixedToDepth(ffz); \
2574 if (z < zRow[i]) { \
2575 DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
2576 VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
2577 pRow[i] = pixelDithered; \
2583 #include "tritemp.h"
2587 * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
2589 static void smooth_DITHER8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2590 GLuint v2
, GLuint pv
)
2592 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2593 DITHER_RGB_TO_8BIT_SETUP
2594 #define INTERP_RGB 1
2595 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2596 #define PIXEL_TYPE GLubyte
2597 #define BYTES_PER_ROW (wmesa->ScanWidth)
2598 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2600 GLint xx, yy = FLIP(Y); \
2601 PIXEL_TYPE *pixel = pRow; \
2602 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2603 DITHER_RGB_TO_8BIT( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2], xx, yy);\
2604 *pixel = pixelDithered; \
2605 ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
2608 #include "tritemp.h"
2612 * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
2615 static void flat_DITHER8_triangle( GLcontext
*ctx
, GLuint v0
, GLuint v1
,
2616 GLuint v2
, GLuint pv
)
2618 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2619 DITHER_RGB_TO_8BIT_SETUP
2620 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
2621 #define PIXEL_TYPE GLubyte
2622 #define BYTES_PER_ROW (wmesa->ScanWidth)
2624 #define INNER_LOOP( LEFT, RIGHT, Y ) \
2626 GLint xx, yy = FLIP(Y); \
2627 PIXEL_TYPE *pixel = pRow; \
2628 for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
2629 DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
2630 VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
2631 *pixel = pixelDithered; \
2634 #include "tritemp.h"
2640 static triangle_func
choose_triangle_function( GLcontext
*ctx
)
2642 WMesaContext wmesa
= (WMesaContext
) ctx
->DriverCtx
;
2643 int depth
= wmesa
->cColorBits
;
2645 if (ctx
->Polygon
.SmoothFlag
) return NULL
;
2646 if (ctx
->Texture
.Enabled
) return NULL
;
2647 if (!wmesa
->db_flag
) return NULL
;
2648 /*if (wmesa->xm_buffer->buffer==XIMAGE)*/ {
2649 if ( ctx
->Light
.ShadeModel
==GL_SMOOTH
2650 && ctx
->_RasterMask
==DEPTH_BIT
2651 && ctx
->Depth
.Func
==GL_LESS
2652 && ctx
->Depth
.Mask
==GL_TRUE
2653 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
2654 switch (wmesa
->pixelformat
) {
2656 return smooth_8A8B8G8R_z_triangle
;
2658 return smooth_8R8G8B_z_triangle
;
2660 return smooth_5R6G5B_z_triangle
;
2662 return smooth_DITHER8_z_triangle
;
2664 return smooth_ci_z_triangle
;
2669 if ( ctx
->Light
.ShadeModel
==GL_FLAT
2670 && ctx
->_RasterMask
==DEPTH_BIT
2671 && ctx
->Depth
.Func
==GL_LESS
2672 && ctx
->Depth
.Mask
==GL_TRUE
2673 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
2674 switch (wmesa
->pixelformat
) {
2676 return flat_8A8B8G8R_z_triangle
;
2678 return flat_8R8G8B_z_triangle
;
2680 return flat_5R6G5B_z_triangle
;
2682 return flat_DITHER8_z_triangle
;
2684 return flat_ci_z_triangle
;
2689 if ( ctx
->_RasterMask
==0 /* no depth test */
2690 && ctx
->Light
.ShadeModel
==GL_SMOOTH
2691 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
2692 switch (wmesa
->pixelformat
) {
2694 return smooth_8A8B8G8R_triangle
;
2696 return smooth_8R8G8B_triangle
;
2698 return smooth_5R6G5B_triangle
;
2700 return smooth_DITHER8_triangle
;
2702 return smooth_ci_triangle
;
2708 if ( ctx
->_RasterMask
==0 /* no depth test */
2709 && ctx
->Light
.ShadeModel
==GL_FLAT
2710 && ctx
->Polygon
.StippleFlag
==GL_FALSE
) {
2711 switch (wmesa
->pixelformat
) {
2713 return flat_8A8B8G8R_triangle
;
2715 return flat_8R8G8B_triangle
;
2717 return flat_5R6G5B_triangle
;
2719 return flat_DITHER8_triangle
;
2721 return flat_ci_triangle
;
2732 * Define a new viewport and reallocate auxillary buffers if the size of
2733 * the window (color buffer) has changed.
2735 void WMesaViewport( GLcontext
*ctx
,
2736 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2739 ctx
->Viewport
.X
= x
;
2740 ctx
->Viewport
.Width
= width
;
2741 ctx
->Viewport
.Y
= y
;
2742 ctx
->Viewport
.Height
= height
;
2744 /* compute scale and bias values */
2745 ctx
->Viewport
.Sx
= (GLfloat
) width
/ 2.0F
;
2746 ctx
->Viewport
.Tx
= ctx
->Viewport
.Sx
+ x
;
2747 ctx
->Viewport
.Sy
= (GLfloat
) height
/ 2.0F
;
2748 ctx
->Viewport
.Ty
= ctx
->Viewport
.Sy
+ y
;