~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/windows/gldirect/mesasw/gld_wgl_mesasw.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
*
3
 
*                        Mesa 3-D graphics library
4
 
*                        Direct3D Driver Interface
5
 
*
6
 
*  ========================================================================
7
 
*
8
 
*   Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
9
 
*
10
 
*   Permission is hereby granted, free of charge, to any person obtaining a
11
 
*   copy of this software and associated documentation files (the "Software"),
12
 
*   to deal in the Software without restriction, including without limitation
13
 
*   the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
 
*   and/or sell copies of the Software, and to permit persons to whom the
15
 
*   Software is furnished to do so, subject to the following conditions:
16
 
*
17
 
*   The above copyright notice and this permission notice shall be included
18
 
*   in all copies or substantial portions of the Software.
19
 
*
20
 
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
 
*   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 
*   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23
 
*   SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
 
*   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25
 
*   OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 
*   SOFTWARE.
27
 
*
28
 
*  ======================================================================
29
 
*
30
 
* Language:     ANSI C
31
 
* Environment:  Windows 9x/2000/XP/XBox (Win32)
32
 
*
33
 
* Description:  Mesa Software WGL (WindowsGL)
34
 
*
35
 
****************************************************************************/
36
 
 
37
 
#include <windows.h>
38
 
#define GL_GLEXT_PROTOTYPES
39
 
#include <GL/gl.h>
40
 
#include <GL/glext.h>
41
 
 
42
 
#include "glheader.h"
43
 
#include "colors.h"
44
 
#include "context.h"
45
 
#include "colormac.h"
46
 
#include "dd.h"
47
 
#include "depth.h"
48
 
#include "extensions.h"
49
 
#include "macros.h"
50
 
#include "matrix.h"
51
 
// #include "mem.h"
52
 
//#include "mmath.h"
53
 
#include "mtypes.h"
54
 
#include "texformat.h"
55
 
#include "texstore.h"
56
 
#include "teximage.h"
57
 
#include "array_cache/acache.h"
58
 
#include "swrast/swrast.h"
59
 
#include "swrast_setup/swrast_setup.h"
60
 
#include "swrast/s_context.h"
61
 
#include "swrast/s_depth.h"
62
 
#include "swrast/s_lines.h"
63
 
#include "swrast/s_triangle.h"
64
 
#include "swrast/s_trispan.h"
65
 
#include "tnl/tnl.h"
66
 
#include "tnl/t_context.h"
67
 
#include "tnl/t_pipeline.h"
68
 
 
69
 
#include "dglcontext.h"
70
 
#include "gld_driver.h"
71
 
 
72
 
//---------------------------------------------------------------------------
73
 
//---------------------------------------------------------------------------
74
 
 
75
 
DGL_pixelFormat pfTemplateMesaSW =
76
 
{
77
 
    {
78
 
        sizeof(PIXELFORMATDESCRIPTOR),  // Size of the data structure
79
 
                1,                                                      // Structure version - should be 1
80
 
                                                                        // Flags:
81
 
                PFD_DRAW_TO_WINDOW |            // The buffer can draw to a window or device surface.
82
 
                PFD_DRAW_TO_BITMAP |            // The buffer can draw to a bitmap. (DaveM)
83
 
                PFD_SUPPORT_GDI |                       // The buffer supports GDI drawing. (DaveM)
84
 
                PFD_SUPPORT_OPENGL |            // The buffer supports OpenGL drawing.
85
 
                PFD_DOUBLEBUFFER |                      // The buffer is double-buffered.
86
 
                0,                                                      // Placeholder for easy commenting of above flags
87
 
                PFD_TYPE_RGBA,                          // Pixel type RGBA.
88
 
                32,                                                     // Total colour bitplanes (excluding alpha bitplanes)
89
 
                8, 0,                                           // Red bits, shift
90
 
                8, 8,                                           // Green bits, shift
91
 
                8, 16,                                          // Blue bits, shift
92
 
                8, 24,                                          // Alpha bits, shift (destination alpha)
93
 
                64,                                                     // Accumulator bits (total)
94
 
                16, 16, 16, 16,                         // Accumulator bits: Red, Green, Blue, Alpha
95
 
                16,                                                     // Depth bits
96
 
                8,                                                      // Stencil bits
97
 
                0,                                                      // Number of auxiliary buffers
98
 
                0,                                                      // Layer type
99
 
                0,                                                      // Specifies the number of overlay and underlay planes.
100
 
                0,                                                      // Layer mask
101
 
                0,                                                      // Specifies the transparent color or index of an underlay plane.
102
 
                0                                                       // Damage mask
103
 
        },
104
 
        0,      // Unused
105
 
};
106
 
 
107
 
//---------------------------------------------------------------------------
108
 
// Extensions
109
 
//---------------------------------------------------------------------------
110
 
 
111
 
typedef struct {
112
 
        PROC proc;
113
 
        char *name;
114
 
}  GLD_extension;
115
 
 
116
 
static GLD_extension GLD_extList[] = {
117
 
#ifdef GL_EXT_polygon_offset
118
 
    {   (PROC)glPolygonOffsetEXT,               "glPolygonOffsetEXT"            },
119
 
#endif
120
 
    {   (PROC)glBlendEquationEXT,               "glBlendEquationEXT"            },
121
 
    {   (PROC)glBlendColorEXT,                  "glBlendColorExt"                       },
122
 
    {   (PROC)glVertexPointerEXT,               "glVertexPointerEXT"            },
123
 
    {   (PROC)glNormalPointerEXT,               "glNormalPointerEXT"            },
124
 
    {   (PROC)glColorPointerEXT,                "glColorPointerEXT"                     },
125
 
    {   (PROC)glIndexPointerEXT,                "glIndexPointerEXT"                     },
126
 
    {   (PROC)glTexCoordPointerEXT,             "glTexCoordPointer"                     },
127
 
    {   (PROC)glEdgeFlagPointerEXT,             "glEdgeFlagPointerEXT"          },
128
 
    {   (PROC)glGetPointervEXT,                 "glGetPointervEXT"                      },
129
 
    {   (PROC)glArrayElementEXT,                "glArrayElementEXT"                     },
130
 
    {   (PROC)glDrawArraysEXT,                  "glDrawArrayEXT"                        },
131
 
    {   (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT"      },
132
 
    {   (PROC)glBindTextureEXT,                 "glBindTextureEXT"                      },
133
 
    {   (PROC)glDeleteTexturesEXT,              "glDeleteTexturesEXT"           },
134
 
    {   (PROC)glGenTexturesEXT,                 "glGenTexturesEXT"                      },
135
 
    {   (PROC)glIsTextureEXT,                   "glIsTextureEXT"                        },
136
 
    {   (PROC)glPrioritizeTexturesEXT,  "glPrioritizeTexturesEXT"       },
137
 
    {   (PROC)glCopyTexSubImage3DEXT,   "glCopyTexSubImage3DEXT"        },
138
 
    {   (PROC)glTexImage3DEXT,                  "glTexImage3DEXT"                       },
139
 
    {   (PROC)glTexSubImage3DEXT,               "glTexSubImage3DEXT"            },
140
 
    {   (PROC)glPointParameterfEXT,             "glPointParameterfEXT"          },
141
 
    {   (PROC)glPointParameterfvEXT,    "glPointParameterfvEXT"         },
142
 
    {   (PROC)glLockArraysEXT,                  "glLockArraysEXT"                       },
143
 
    {   (PROC)glUnlockArraysEXT,                "glUnlockArraysEXT"                     },
144
 
        {       NULL,                                                   "\0"                                            }
145
 
};
146
 
 
147
 
//---------------------------------------------------------------------------
148
 
// WMesa Internal Functions
149
 
//---------------------------------------------------------------------------
150
 
 
151
 
#define PAGE_FILE       0xffffffff
152
 
 
153
 
#define REDBITS         0x03
154
 
#define REDSHIFT        0x00
155
 
#define GREENBITS       0x03
156
 
#define GREENSHIFT      0x03
157
 
#define BLUEBITS        0x02
158
 
#define BLUESHIFT       0x06
159
 
 
160
 
typedef struct _dibSection {
161
 
        HDC     hDC;
162
 
        HANDLE  hFileMap;
163
 
        BOOL    fFlushed;
164
 
        LPVOID  base;
165
 
} WMDIBSECTION, *PWMDIBSECTION;
166
 
 
167
 
typedef struct wmesa_context {
168
 
        HWND                            Window;
169
 
        HDC                             hDC;
170
 
        HPALETTE                        hPalette;
171
 
        HPALETTE                        hOldPalette;
172
 
        HPEN                            hPen;
173
 
        HPEN                            hOldPen;
174
 
        HCURSOR                         hOldCursor;
175
 
        COLORREF                        crColor;
176
 
        // 3D projection stuff
177
 
        RECT                            drawRect;
178
 
        UINT                            uiDIBoffset;
179
 
        // OpenGL stuff
180
 
        HPALETTE                        hGLPalette;
181
 
        GLuint                          width;
182
 
        GLuint                          height;
183
 
        GLuint                          ScanWidth;
184
 
        GLboolean                       db_flag;        //* double buffered?
185
 
        GLboolean                       rgb_flag;       //* RGB mode?
186
 
        GLboolean                       dither_flag;    //* use dither when 256 color mode for RGB?
187
 
        GLuint                          depth;          //* bits per pixel (1, 8, 24, etc)
188
 
        ULONG                           pixel;  // current color index or RGBA pixel value
189
 
        ULONG                           clearpixel; //* pixel for clearing the color buffers
190
 
        PBYTE                           ScreenMem; // WinG memory
191
 
        BITMAPINFO                      *IndexFormat;
192
 
        HPALETTE                        hPal; // Current Palette
193
 
        HPALETTE                        hPalHalfTone;
194
 
        
195
 
        
196
 
        WMDIBSECTION            dib;
197
 
        BITMAPINFO                      bmi;
198
 
        HBITMAP                         hbmDIB;
199
 
        HBITMAP                         hOldBitmap;
200
 
        HBITMAP                         Old_Compat_BM;
201
 
        HBITMAP                         Compat_BM;                        // Bitmap for double buffering
202
 
        PBYTE                           pbPixels;
203
 
        int                             nColors;
204
 
        BYTE                            cColorBits;
205
 
        int                             pixelformat;
206
 
        
207
 
        RECT                                    rectOffScreen;
208
 
        RECT                                    rectSurface;
209
 
//      HWND                                    hwnd;
210
 
        DWORD                                   pitch;
211
 
        PBYTE                                   addrOffScreen;
212
 
 
213
 
        // We always double-buffer, for performance reasons, but
214
 
        // we need to know which of SwapBuffers() or glFlush() to
215
 
        // handle. If we're emulating, then we update on Flush(),
216
 
        // otherwise we update on SwapBufers(). KeithH
217
 
        BOOL                            bEmulateSingleBuffer;
218
 
} WMesaContext, *PWMC;
219
 
 
220
 
#define GLD_GET_WMESA_DRIVER(c) (WMesaContext*)(c)->glPriv
221
 
 
222
 
// TODO:
223
 
GLint stereo_flag = 0 ;
224
 
 
225
 
/* If we are double-buffering, we want to get the DC for the
226
 
 * off-screen DIB, otherwise the DC for the window.
227
 
 */
228
 
#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
229
 
#define DD_RELEASEDC
230
 
 
231
 
#define FLIP(Y)  (Current->height-(Y)-1)
232
 
 
233
 
struct DISPLAY_OPTIONS {
234
 
        int  stereo;
235
 
        int  fullScreen;
236
 
        int      mode;
237
 
        int      bpp;
238
 
};
239
 
 
240
 
struct DISPLAY_OPTIONS displayOptions;
241
 
 
242
 
//---------------------------------------------------------------------------
243
 
 
244
 
static unsigned char threeto8[8] = {
245
 
  0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
246
 
};
247
 
 
248
 
static unsigned char twoto8[4] = {
249
 
  0, 0x55, 0xaa, 0xff
250
 
};
251
 
 
252
 
static unsigned char oneto8[2] = {
253
 
  0, 255
254
 
};
255
 
 
256
 
//---------------------------------------------------------------------------
257
 
 
258
 
BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline)
259
 
{
260
 
  char unsigned redtemp, greentemp, bluetemp, paletteindex;
261
 
  
262
 
  //*** now, look up each value in the halftone matrix
263
 
  //*** using an 8x8 ordered dither.
264
 
  redtemp = aDividedBy51[red]
265
 
    + (aModulo51[red] > aHalftone8x8[(pixel%8)*8
266
 
                                    + scanline%8]);
267
 
  greentemp = aDividedBy51[(char unsigned)green]
268
 
    + (aModulo51[green] > aHalftone8x8[
269
 
      (pixel%8)*8 + scanline%8]);
270
 
  bluetemp = aDividedBy51[(char unsigned)blue]
271
 
    + (aModulo51[blue] > aHalftone8x8[
272
 
      (pixel%8)*8 +scanline%8]);
273
 
  
274
 
  //*** recombine the halftoned rgb values into a palette index
275
 
  paletteindex =
276
 
    redtemp + aTimes6[greentemp] + aTimes36[bluetemp];
277
 
  
278
 
  //*** and translate through the wing halftone palette
279
 
  //*** translation vector to give the correct value.
280
 
  return aWinGHalftoneTranslation[paletteindex];
281
 
}
282
 
 
283
 
//---------------------------------------------------------------------------
284
 
 
285
 
static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift)
286
 
{
287
 
  unsigned char val;
288
 
  
289
 
  val = i >> shift;
290
 
  switch (nbits) {
291
 
    
292
 
  case 1:
293
 
    val &= 0x1;
294
 
    return oneto8[val];
295
 
    
296
 
  case 2:
297
 
    val &= 0x3;
298
 
    return twoto8[val];
299
 
    
300
 
  case 3:
301
 
    val &= 0x7;
302
 
    return threeto8[val];
303
 
    
304
 
  default:
305
 
    return 0;
306
 
  }
307
 
}
308
 
 
309
 
//---------------------------------------------------------------------------
310
 
 
311
 
 
312
 
void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
313
 
{
314
 
        WMesaContext *Current = pwc;
315
 
 
316
 
        // Test for invalid scanline parameter. KeithH
317
 
        if ((iScanLine < 0) || (iScanLine >= pwc->height))
318
 
                return;
319
 
 
320
 
  if (Current->db_flag) {
321
 
    LPBYTE  lpb = pwc->pbPixels;
322
 
    UINT    nBypp = pwc->cColorBits >> 3;
323
 
    UINT    nOffset = iPixel % nBypp;
324
 
    
325
 
    lpb += pwc->ScanWidth * iScanLine;
326
 
    lpb += iPixel * nBypp;
327
 
    
328
 
    if(nBypp == 1){
329
 
      if(pwc->dither_flag)
330
 
        *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
331
 
      else
332
 
        *lpb = BGR8(r,g,b);
333
 
    }
334
 
    else if(nBypp == 2)
335
 
      *((LPWORD)lpb) = BGR16(r,g,b);
336
 
    else if (nBypp == 3)
337
 
      *((LPDWORD)lpb) = BGR24(r,g,b);
338
 
    else if (nBypp == 4)
339
 
      *((LPDWORD)lpb) = BGR32(r,g,b);
340
 
  }
341
 
  else{
342
 
    SetPixel(Current->hDC, iPixel, iScanLine, RGB(r,g,b));
343
 
  }
344
 
}
345
 
 
346
 
//---------------------------------------------------------------------------
347
 
 
348
 
void  wmCreateDIBSection(
349
 
  HDC   hDC,
350
 
  PWMC pwc,    // handle of device context
351
 
  CONST BITMAPINFO *pbmi,  // bitmap size, format, and color data
352
 
  UINT iUsage  // color data type indicator: RGB values or palette indices
353
 
  )
354
 
{
355
 
  DWORD   dwSize = 0;
356
 
  DWORD   dwScanWidth;
357
 
  UINT    nBypp = pwc->cColorBits / 8;
358
 
  HDC     hic;
359
 
  
360
 
  dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3);
361
 
  
362
 
  pwc->ScanWidth =pwc->pitch = dwScanWidth;
363
 
  
364
 
  if (stereo_flag)
365
 
    pwc->ScanWidth = 2* pwc->pitch;
366
 
  
367
 
  dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height);
368
 
  
369
 
  pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE,
370
 
                                        NULL,
371
 
                                        PAGE_READWRITE | SEC_COMMIT,
372
 
                                        0,
373
 
                                        dwSize,
374
 
                                        NULL);
375
 
  
376
 
  if (!pwc->dib.hFileMap)
377
 
    return;
378
 
  
379
 
  pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap,
380
 
                                FILE_MAP_ALL_ACCESS,
381
 
                                0,
382
 
                                0,
383
 
                                0);
384
 
  
385
 
  if(!pwc->dib.base){
386
 
    CloseHandle(pwc->dib.hFileMap);
387
 
    return;
388
 
  }
389
 
  
390
 
 
391
 
  CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO));
392
 
  
393
 
  hic = CreateIC("display", NULL, NULL, NULL);
394
 
  pwc->dib.hDC = CreateCompatibleDC(hic);
395
 
  
396
 
 
397
 
  pwc->hbmDIB = CreateDIBSection(hic,
398
 
                                 &(pwc->bmi),
399
 
                                 (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS),
400
 
                                 &(pwc->pbPixels),
401
 
                                 pwc->dib.hFileMap,
402
 
                                 0);
403
 
  pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels;
404
 
  pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB);
405
 
  
406
 
  DeleteDC(hic);
407
 
  
408
 
  return;
409
 
  
410
 
}
411
 
 
412
 
//---------------------------------------------------------------------------
413
 
 
414
 
void wmCreatePalette( PWMC pwdc )
415
 
{
416
 
  /* Create a compressed and re-expanded 3:3:2 palette */
417
 
  int            i;
418
 
  LOGPALETTE     *pPal;
419
 
  BYTE           rb, rs, gb, gs, bb, bs;
420
 
  
421
 
  pwdc->nColors = 0x100;
422
 
  
423
 
  pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + 
424
 
                             pwdc->nColors * sizeof(PALETTEENTRY));
425
 
  memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) );
426
 
  
427
 
  pPal->palVersion = 0x300;
428
 
  
429
 
  rb = REDBITS;
430
 
  rs = REDSHIFT;
431
 
  gb = GREENBITS;
432
 
  gs = GREENSHIFT;
433
 
  bb = BLUEBITS;
434
 
  bs = BLUESHIFT;
435
 
  
436
 
  if (pwdc->db_flag) {
437
 
    
438
 
    /* Need to make two palettes: one for the screen DC and one for the DIB. */
439
 
    pPal->palNumEntries = pwdc->nColors;
440
 
    for (i = 0; i < pwdc->nColors; i++) {
441
 
      pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
442
 
      pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
443
 
      pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
444
 
      pPal->palPalEntry[i].peFlags = 0;
445
 
    }
446
 
    pwdc->hGLPalette = CreatePalette( pPal );
447
 
    pwdc->hPalette = CreatePalette( pPal );
448
 
  }
449
 
  
450
 
  else {
451
 
    pPal->palNumEntries = pwdc->nColors;
452
 
    for (i = 0; i < pwdc->nColors; i++) {
453
 
      pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
454
 
      pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
455
 
      pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
456
 
      pPal->palPalEntry[i].peFlags = 0;
457
 
    }
458
 
    pwdc->hGLPalette = CreatePalette( pPal );
459
 
  }
460
 
  
461
 
  free(pPal);
462
 
  
463
 
}
464
 
 
465
 
//---------------------------------------------------------------------------
466
 
 
467
 
/* This function sets the color table of a DIB section
468
 
 * to match that of the destination DC
469
 
 */
470
 
BOOL wmSetDibColors(PWMC pwc)
471
 
{
472
 
  RGBQUAD         *pColTab, *pRGB;
473
 
  PALETTEENTRY    *pPal, *pPE;
474
 
  int             i, nColors;
475
 
  BOOL            bRet=TRUE;
476
 
  DWORD           dwErr=0;
477
 
  
478
 
  /* Build a color table in the DIB that maps to the
479
 
   *  selected palette in the DC.
480
 
   */
481
 
  nColors = 1 << pwc->cColorBits;
482
 
  pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY));
483
 
  memset( pPal, 0, nColors * sizeof(PALETTEENTRY) );
484
 
  GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal );
485
 
  pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD));
486
 
  for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) {
487
 
    pRGB->rgbRed = pPE->peRed;
488
 
    pRGB->rgbGreen = pPE->peGreen;
489
 
    pRGB->rgbBlue = pPE->peBlue;
490
 
  }
491
 
  if(pwc->db_flag)
492
 
    bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab );
493
 
  
494
 
  if(!bRet)
495
 
    dwErr = GetLastError();
496
 
  
497
 
  free( pColTab );
498
 
  free( pPal );
499
 
  
500
 
  return bRet;
501
 
}
502
 
 
503
 
//---------------------------------------------------------------------------
504
 
 
505
 
static void wmSetPixelFormat( PWMC wc, HDC hDC)
506
 
{
507
 
  if(wc->rgb_flag)
508
 
    wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
509
 
  else
510
 
    wc->cColorBits = 8;
511
 
  switch(wc->cColorBits){
512
 
  case 8:
513
 
    if(wc->dither_flag != GL_TRUE)
514
 
      wc->pixelformat = PF_INDEX8;
515
 
    else
516
 
      wc->pixelformat = PF_DITHER8;
517
 
    break;
518
 
  case 16:
519
 
    wc->pixelformat = PF_5R6G5B;
520
 
    break;
521
 
  case 32:
522
 
    wc->pixelformat = PF_8R8G8B;
523
 
    break;
524
 
  default:
525
 
    wc->pixelformat = PF_BADFORMAT;
526
 
  }
527
 
}
528
 
 
529
 
//---------------------------------------------------------------------------
530
 
 
531
 
/*
532
 
 * This function creates the DIB section that is used for combined
533
 
 * GL and GDI calls
534
 
 */
535
 
BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize)
536
 
{
537
 
  HDC hdc = pwc->hDC;
538
 
  LPBITMAPINFO pbmi = &(pwc->bmi);
539
 
  int     iUsage;
540
 
  
541
 
  pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
542
 
  pbmi->bmiHeader.biWidth = lxSize;
543
 
  pbmi->bmiHeader.biHeight= -lySize;
544
 
  pbmi->bmiHeader.biPlanes = 1;
545
 
  if(pwc->rgb_flag)
546
 
    pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL);
547
 
  else
548
 
    pbmi->bmiHeader.biBitCount = 8;
549
 
  pbmi->bmiHeader.biCompression = BI_RGB;
550
 
  pbmi->bmiHeader.biSizeImage = 0;
551
 
  pbmi->bmiHeader.biXPelsPerMeter = 0;
552
 
  pbmi->bmiHeader.biYPelsPerMeter = 0;
553
 
  pbmi->bmiHeader.biClrUsed = 0;
554
 
  pbmi->bmiHeader.biClrImportant = 0;
555
 
  
556
 
  iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS;
557
 
 
558
 
  pwc->cColorBits = pbmi->bmiHeader.biBitCount;
559
 
  pwc->ScanWidth = pwc->pitch = lxSize;
560
 
  pwc->width = lxSize;
561
 
  pwc->height = lySize;
562
 
  
563
 
  wmCreateDIBSection(hdc, pwc, pbmi, iUsage);
564
 
  
565
 
  if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) {
566
 
    wmCreatePalette( pwc );
567
 
    wmSetDibColors( pwc );
568
 
  }
569
 
  wmSetPixelFormat(pwc, pwc->hDC);
570
 
  return TRUE;
571
 
}
572
 
 
573
 
//---------------------------------------------------------------------------
574
 
 
575
 
/*
576
 
 * Free up the dib section that was created
577
 
 */
578
 
BOOL wmDeleteBackingStore(PWMC pwc)
579
 
{
580
 
  SelectObject(pwc->dib.hDC, pwc->hOldBitmap);
581
 
  DeleteDC(pwc->dib.hDC);
582
 
  DeleteObject(pwc->hbmDIB);
583
 
  UnmapViewOfFile(pwc->dib.base);
584
 
  CloseHandle(pwc->dib.hFileMap);
585
 
  return TRUE;
586
 
}
587
 
 
588
 
//---------------------------------------------------------------------------
589
 
 
590
 
/*
591
 
 * Blit memory DC to screen DC
592
 
 */
593
 
BOOL wmFlush(PWMC pwc, HDC hDC)
594
 
{
595
 
  BOOL    bRet = 0;
596
 
  DWORD   dwErr = 0;
597
 
  
598
 
// Now using bEmulateSingleBuffer in the calling function. KeithH
599
 
 
600
 
//  if(pwc->db_flag){
601
 
    bRet = BitBlt(hDC, 0, 0, pwc->width, pwc->height,
602
 
                  pwc->dib.hDC, 0, 0, SRCCOPY);
603
 
//  }
604
 
  
605
 
  return bRet;
606
 
  
607
 
}
608
 
 
609
 
//---------------------------------------------------------------------------
610
 
// Support Functions
611
 
//---------------------------------------------------------------------------
612
 
 
613
 
static void flush(GLcontext* ctx)
614
 
{
615
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
616
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
617
 
/*
618
 
  if((Current->rgb_flag &&!(Current->db_flag))
619
 
     ||(!Current->rgb_flag))
620
 
    {
621
 
      wmFlush(Current, Current->hDC);
622
 
    }
623
 
*/
624
 
        // Only flush if we're not in double-buffer mode. KeithH
625
 
        // The demo fractal.c calls glutSwapBuffers() then glFlush()!
626
 
        if (Current->bEmulateSingleBuffer) {
627
 
                wmFlush(Current, Current->hDC);
628
 
        }
629
 
}
630
 
 
631
 
 
632
 
//---------------------------------------------------------------------------
633
 
 
634
 
 
635
 
/*
636
 
 * Set the color index used to clear the color buffer.
637
 
 */
638
 
static void clear_index(GLcontext* ctx, GLuint index)
639
 
{
640
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
641
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
642
 
  Current->clearpixel = index;
643
 
}
644
 
 
645
 
 
646
 
 
647
 
//---------------------------------------------------------------------------
648
 
 
649
 
/*
650
 
 * Set the color used to clear the color buffer.
651
 
 */
652
 
//static void clear_color( GLcontext* ctx, const GLchan color[4] )
653
 
// Changed for Mesa 5.x. KeithH
654
 
static void clear_color(
655
 
        GLcontext* ctx,
656
 
        const GLfloat color[4])
657
 
{
658
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
659
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
660
 
        GLubyte col[4];
661
 
        CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
662
 
        CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
663
 
        CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
664
 
        Current->clearpixel = RGB(col[0], col[1], col[2]);
665
 
}
666
 
 
667
 
 
668
 
//---------------------------------------------------------------------------
669
 
 
670
 
 
671
 
/*
672
 
 * Clear the specified region of the color buffer using the clear color
673
 
 * or index as specified by one of the two functions above.
674
 
 *
675
 
 * This procedure clears either the front and/or the back COLOR buffers.
676
 
 * Only the "left" buffer is cleared since we are not stereo.
677
 
 * Clearing of the other non-color buffers is left to the swrast.
678
 
 * We also only clear the color buffers if the color masks are all 1's.
679
 
 * Otherwise, we let swrast do it.
680
 
 */
681
 
 
682
 
static clear(GLcontext* ctx, GLbitfield mask,
683
 
             GLboolean all, GLint x, GLint y, GLint width, GLint height)
684
 
{
685
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
686
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
687
 
  DWORD   dwColor;
688
 
  WORD    wColor;
689
 
  BYTE    bColor;
690
 
  LPDWORD lpdw = (LPDWORD)Current->pbPixels;
691
 
  LPWORD  lpw = (LPWORD)Current->pbPixels;
692
 
  LPBYTE  lpb = Current->pbPixels;
693
 
  int     lines;
694
 
  const   GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask;
695
 
  
696
 
  if (all){
697
 
    x=y=0;
698
 
    width=Current->width;
699
 
    height=Current->height;
700
 
  }
701
 
  
702
 
  
703
 
  /* sanity check - can't have right(stereo) buffers */
704
 
  assert((mask & (DD_FRONT_RIGHT_BIT | DD_BACK_RIGHT_BIT)) == 0);
705
 
  
706
 
  /* clear alpha */
707
 
  if ((mask & (DD_FRONT_LEFT_BIT | DD_BACK_RIGHT_BIT)) &&
708
 
      ctx->DrawBuffer->UseSoftwareAlphaBuffers &&
709
 
      ctx->Color.ColorMask[ACOMP]) {
710
 
      _swrast_clear_alpha_buffers( ctx );
711
 
  }
712
 
  
713
 
  if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
714
 
      if (mask & DD_BACK_LEFT_BIT) {
715
 
          /* Double-buffering - clear back buffer */
716
 
          UINT    nBypp = Current->cColorBits / 8;
717
 
          int     i = 0;
718
 
          int     iSize = 0;
719
 
          
720
 
          assert(Current->db_flag==GL_TRUE); /* we'd better be double buffer */
721
 
          if(nBypp ==1 ){
722
 
              iSize = Current->width/4;
723
 
              bColor  = BGR8(GetRValue(Current->clearpixel),
724
 
                             GetGValue(Current->clearpixel),
725
 
                             GetBValue(Current->clearpixel));
726
 
              wColor  = MAKEWORD(bColor,bColor);
727
 
              dwColor = MAKELONG(wColor, wColor);
728
 
          }
729
 
          if(nBypp == 2){
730
 
              iSize = Current->width / 2;
731
 
              wColor = BGR16(GetRValue(Current->clearpixel),
732
 
                             GetGValue(Current->clearpixel),
733
 
                             GetBValue(Current->clearpixel));
734
 
              dwColor = MAKELONG(wColor, wColor);
735
 
          }
736
 
          else if(nBypp == 4){
737
 
              iSize = Current->width;
738
 
              dwColor = BGR32(GetRValue(Current->clearpixel),
739
 
                              GetGValue(Current->clearpixel),
740
 
                              GetBValue(Current->clearpixel));
741
 
          }
742
 
          
743
 
          /* clear a line */
744
 
          while(i < iSize){
745
 
              *lpdw = dwColor;
746
 
              lpdw++;
747
 
              i++;
748
 
          }
749
 
          
750
 
          /* This is the 24bit case */
751
 
          if (nBypp == 3) {
752
 
              iSize = Current->width *3/4;
753
 
              dwColor = BGR24(GetRValue(Current->clearpixel),
754
 
                              GetGValue(Current->clearpixel),
755
 
                              GetBValue(Current->clearpixel));
756
 
              while(i < iSize){
757
 
                  *lpdw = dwColor;
758
 
                  lpb += nBypp;
759
 
                  lpdw = (LPDWORD)lpb;
760
 
                  i++;
761
 
              }
762
 
          }
763
 
          
764
 
          i = 0;
765
 
          if (stereo_flag)
766
 
              lines = height /2;
767
 
          else
768
 
              lines = height;
769
 
          /* copy cleared line to other lines in buffer */
770
 
          do {
771
 
              memcpy(lpb, Current->pbPixels, iSize*4);
772
 
              lpb += Current->ScanWidth;
773
 
              i++;
774
 
          }
775
 
          while (i<lines-1);
776
 
          mask &= ~DD_BACK_LEFT_BIT;
777
 
      } /* double-buffer */
778
 
      
779
 
      if (mask & DD_FRONT_LEFT_BIT) {
780
 
          /* single-buffer */
781
 
          HDC DC=DD_GETDC;
782
 
          HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
783
 
          HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
784
 
          HPEN Old_Pen=SelectObject(DC,Pen);
785
 
          HBRUSH Old_Brush=SelectObject(DC,Brush);
786
 
          Rectangle(DC,x,y,x+width,y+height);
787
 
          SelectObject(DC,Old_Pen);
788
 
          SelectObject(DC,Old_Brush);
789
 
          DeleteObject(Pen);
790
 
          DeleteObject(Brush);
791
 
          DD_RELEASEDC;
792
 
          mask &= ~DD_FRONT_LEFT_BIT;
793
 
      } /* single-buffer */
794
 
  } /* if masks are all 1's */
795
 
    
796
 
  /* Call swrast if there is anything left to clear (like DEPTH) */
797
 
  if (mask)
798
 
      _swrast_Clear( ctx, mask, all, x, y, width, height );
799
 
}
800
 
  
801
 
 
802
 
//---------------------------------------------------------------------------
803
 
 
804
 
 
805
 
static void enable( GLcontext* ctx, GLenum pname, GLboolean enable )
806
 
{
807
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
808
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
809
 
 
810
 
        if (!Current)
811
 
                return;
812
 
        
813
 
        if (pname == GL_DITHER) {
814
 
                if(enable == GL_FALSE){
815
 
                        Current->dither_flag = GL_FALSE;
816
 
                        if(Current->cColorBits == 8)
817
 
                                Current->pixelformat = PF_INDEX8;
818
 
                }
819
 
                else{
820
 
                        if (Current->rgb_flag && Current->cColorBits == 8){
821
 
                                Current->pixelformat = PF_DITHER8;
822
 
                                Current->dither_flag = GL_TRUE;
823
 
                        }
824
 
                        else
825
 
                                Current->dither_flag = GL_FALSE;
826
 
                }
827
 
        }
828
 
}
829
 
 
830
 
//---------------------------------------------------------------------------
831
 
 
832
 
static GLboolean set_draw_buffer( GLcontext* ctx, GLenum mode )
833
 
{
834
 
  /* TODO: this could be better */
835
 
  if (mode==GL_FRONT_LEFT || mode==GL_BACK_LEFT) {
836
 
    return GL_TRUE;
837
 
  }
838
 
  else {
839
 
    return GL_FALSE;
840
 
  }
841
 
}
842
 
 
843
 
//---------------------------------------------------------------------------
844
 
 
845
 
 
846
 
static void set_read_buffer(GLcontext *ctx, GLframebuffer *colorBuffer,
847
 
                            GLenum buffer )
848
 
{
849
 
  /* XXX todo */
850
 
  return;
851
 
}
852
 
 
853
 
 
854
 
//---------------------------------------------------------------------------
855
 
 
856
 
 
857
 
/* Return characteristics of the output buffer. */
858
 
//static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height )
859
 
// Altered for Mesa 5.x. KeithH
860
 
static void buffer_size(
861
 
        GLframebuffer *buffer,
862
 
        GLuint *width,
863
 
        GLuint *height)
864
 
{
865
 
        // For some reason the context is not passed into this function.
866
 
        // Therefore we have to explicitly retrieve it.
867
 
        GET_CURRENT_CONTEXT(ctx);
868
 
 
869
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
870
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
871
 
        int New_Size;
872
 
        RECT CR;
873
 
        
874
 
        GetClientRect(Current->Window,&CR);
875
 
        
876
 
        *width=CR.right;
877
 
        *height=CR.bottom;
878
 
        
879
 
        New_Size=((*width)!=Current->width) || ((*height)!=Current->height);
880
 
        
881
 
        if (New_Size){
882
 
                Current->width=*width;
883
 
                Current->height=*height;
884
 
                Current->ScanWidth=Current->width;
885
 
                if ((Current->ScanWidth%sizeof(long))!=0)
886
 
                        Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
887
 
                
888
 
                if (Current->db_flag){
889
 
                        if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){
890
 
                                wmDeleteBackingStore(Current);
891
 
                                wmCreateBackingStore(Current, Current->width, Current->height);
892
 
                        }
893
 
                }
894
 
                
895
 
        }
896
 
}
897
 
 
898
 
 
899
 
 
900
 
/**********************************************************************/
901
 
/*****           Accelerated point, line, polygon rendering       *****/
902
 
/**********************************************************************/
903
 
 
904
 
/* Accelerated routines are not implemented in 4.0. See OSMesa for ideas. */
905
 
 
906
 
static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last )
907
 
{
908
 
}
909
 
 
910
 
//---------------------------------------------------------------------------
911
 
 
912
 
/* Return pointer to accelerated points function */
913
 
extern tnl_points_func choose_points_function( GLcontext* ctx )
914
 
{
915
 
  return NULL;
916
 
}
917
 
 
918
 
//---------------------------------------------------------------------------
919
 
 
920
 
static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, 
921
 
                                GLuint v1, GLuint pv )
922
 
{
923
 
}
924
 
 
925
 
//---------------------------------------------------------------------------
926
 
 
927
 
static tnl_line_func choose_line_function( GLcontext* ctx )
928
 
{
929
 
}
930
 
 
931
 
 
932
 
/**********************************************************************/
933
 
/*****                 Span-based pixel drawing                   *****/
934
 
/**********************************************************************/
935
 
 
936
 
 
937
 
/* Write a horizontal span of 32-bit color-index pixels with a boolean mask. */
938
 
static void write_ci32_span( const GLcontext* ctx,
939
 
                             GLuint n, GLint x, GLint y,
940
 
                             const GLuint index[],
941
 
                             const GLubyte mask[] )
942
 
{
943
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
944
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
945
 
  GLuint i;
946
 
  PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
947
 
  assert(Current->rgb_flag==GL_FALSE);
948
 
  for (i=0; i<n; i++)
949
 
    if (mask[i])
950
 
      Mem[i]=index[i];
951
 
}
952
 
 
953
 
 
954
 
//---------------------------------------------------------------------------
955
 
 
956
 
/* Write a horizontal span of 8-bit color-index pixels with a boolean mask. */
957
 
static void write_ci8_span( const GLcontext* ctx,
958
 
                            GLuint n, GLint x, GLint y,
959
 
                            const GLubyte index[],
960
 
                            const GLubyte mask[] )
961
 
{
962
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
963
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
964
 
  GLuint i;
965
 
  PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
966
 
  assert(Current->rgb_flag==GL_FALSE);
967
 
  for (i=0; i<n; i++)
968
 
    if (mask[i])
969
 
      Mem[i]=index[i];
970
 
}
971
 
 
972
 
 
973
 
//---------------------------------------------------------------------------
974
 
 
975
 
 
976
 
/*
977
 
 * Write a horizontal span of pixels with a boolean mask.  The current
978
 
 * color index is used for all pixels.
979
 
 */
980
 
static void write_mono_ci_span(const GLcontext* ctx,
981
 
                               GLuint n,GLint x,GLint y,
982
 
                               GLuint colorIndex, const GLubyte mask[])
983
 
{
984
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
985
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
986
 
  GLuint i;
987
 
  BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
988
 
  assert(Current->rgb_flag==GL_FALSE);
989
 
  for (i=0; i<n; i++)
990
 
    if (mask[i])
991
 
      Mem[i]=colorIndex;
992
 
}
993
 
 
994
 
//---------------------------------------------------------------------------
995
 
 
996
 
/*
997
 
 * To improve the performance of this routine, frob the data into an actual
998
 
 * scanline and call bitblt on the complete scan line instead of SetPixel.
999
 
 */
1000
 
 
1001
 
/* Write a horizontal span of RGBA color pixels with a boolean mask. */
1002
 
static void write_rgba_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
1003
 
                             const GLubyte rgba[][4], const GLubyte mask[] )
1004
 
{
1005
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1006
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1007
 
  PWMC    pwc = Current;
1008
 
  
1009
 
  if (pwc->rgb_flag==GL_TRUE)
1010
 
    {
1011
 
      GLuint i;
1012
 
      HDC DC=DD_GETDC;
1013
 
      y=FLIP(y);
1014
 
      if (mask) {
1015
 
        for (i=0; i<n; i++)
1016
 
          if (mask[i])
1017
 
            wmSetPixel(pwc, y, x + i, 
1018
 
                       rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1019
 
      }
1020
 
      else {
1021
 
        for (i=0; i<n; i++)
1022
 
          wmSetPixel(pwc, y, x + i, 
1023
 
                     rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1024
 
      }
1025
 
      DD_RELEASEDC;
1026
 
    }
1027
 
  else
1028
 
    {
1029
 
      GLuint i;
1030
 
      BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
1031
 
      y = FLIP(y);
1032
 
      if (mask) {
1033
 
        for (i=0; i<n; i++)
1034
 
          if (mask[i])
1035
 
            Mem[i] = GetNearestPaletteIndex(Current->hPal, 
1036
 
                                            RGB(rgba[i][RCOMP], 
1037
 
                                                rgba[i][GCOMP], 
1038
 
                                                rgba[i][BCOMP]));
1039
 
      }
1040
 
      else {
1041
 
        for (i=0; i<n; i++)
1042
 
          Mem[i] = GetNearestPaletteIndex(Current->hPal,
1043
 
                                          RGB(rgba[i][RCOMP], 
1044
 
                                              rgba[i][GCOMP], 
1045
 
                                              rgba[i][BCOMP]));
1046
 
      }
1047
 
    }
1048
 
}
1049
 
 
1050
 
//---------------------------------------------------------------------------
1051
 
 
1052
 
/* Write a horizontal span of RGB color pixels with a boolean mask. */
1053
 
static void write_rgb_span( const GLcontext* ctx,
1054
 
                            GLuint n, GLint x, GLint y,
1055
 
                            const GLubyte rgb[][3], const GLubyte mask[] )
1056
 
{
1057
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1058
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1059
 
  PWMC    pwc = Current;
1060
 
  
1061
 
  if (pwc->rgb_flag==GL_TRUE)
1062
 
    {
1063
 
      GLuint i;
1064
 
      HDC DC=DD_GETDC;
1065
 
      y=FLIP(y);
1066
 
      if (mask) {
1067
 
        for (i=0; i<n; i++)
1068
 
          if (mask[i])
1069
 
            wmSetPixel(pwc, y, x + i, 
1070
 
                       rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1071
 
      }
1072
 
      else {
1073
 
        for (i=0; i<n; i++)
1074
 
          wmSetPixel(pwc, y, x + i, 
1075
 
                     rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1076
 
      }
1077
 
      DD_RELEASEDC;
1078
 
    }
1079
 
  else
1080
 
    {
1081
 
      GLuint i;
1082
 
      BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
1083
 
      y = FLIP(y);
1084
 
      if (mask) {
1085
 
        for (i=0; i<n; i++)
1086
 
          if (mask[i])
1087
 
            Mem[i] = GetNearestPaletteIndex(Current->hPal,
1088
 
                                            RGB(rgb[i][RCOMP], 
1089
 
                                                rgb[i][GCOMP], 
1090
 
                                                rgb[i][BCOMP]));
1091
 
      }
1092
 
      else {
1093
 
        for (i=0; i<n; i++)
1094
 
          Mem[i] = GetNearestPaletteIndex(Current->hPal,
1095
 
                                          RGB(rgb[i][RCOMP], 
1096
 
                                              rgb[i][GCOMP], 
1097
 
                                              rgb[i][BCOMP]));
1098
 
      }
1099
 
    }
1100
 
}
1101
 
 
1102
 
//---------------------------------------------------------------------------
1103
 
 
1104
 
/*
1105
 
 * Write a horizontal span of pixels with a boolean mask.  The current color
1106
 
 * is used for all pixels.
1107
 
 */
1108
 
static void write_mono_rgba_span( const GLcontext* ctx,
1109
 
                                  GLuint n, GLint x, GLint y,
1110
 
                                  const GLchan color[4], const GLubyte mask[])
1111
 
{
1112
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1113
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1114
 
  ULONG pixel =  RGB( color[RCOMP], color[GCOMP], color[BCOMP] );
1115
 
  GLuint i;
1116
 
  HDC DC=DD_GETDC;
1117
 
  PWMC pwc = Current;
1118
 
  assert(Current->rgb_flag==GL_TRUE);
1119
 
  y=FLIP(y);
1120
 
  if(Current->rgb_flag==GL_TRUE){
1121
 
    for (i=0; i<n; i++)
1122
 
      if (mask[i])
1123
 
        wmSetPixel(pwc,y,x+i,color[RCOMP], color[GCOMP], color[BCOMP]);
1124
 
  }
1125
 
  else {
1126
 
    for (i=0; i<n; i++)
1127
 
      if (mask[i])
1128
 
        SetPixel(DC, y, x+i, pixel);
1129
 
  }
1130
 
  DD_RELEASEDC;
1131
 
}
1132
 
 
1133
 
 
1134
 
 
1135
 
/**********************************************************************/
1136
 
/*****                   Array-based pixel drawing                *****/
1137
 
/**********************************************************************/
1138
 
 
1139
 
 
1140
 
/* Write an array of 32-bit index pixels with a boolean mask. */
1141
 
static void write_ci32_pixels( const GLcontext* ctx,
1142
 
                               GLuint n, const GLint x[], const GLint y[],
1143
 
                               const GLuint index[], const GLubyte mask[] )
1144
 
{
1145
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1146
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1147
 
  GLuint i;
1148
 
  assert(Current->rgb_flag==GL_FALSE);
1149
 
  for (i=0; i<n; i++) {
1150
 
    if (mask[i]) {
1151
 
      BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
1152
 
      *Mem = index[i];
1153
 
    }
1154
 
  }
1155
 
}
1156
 
 
1157
 
 
1158
 
//---------------------------------------------------------------------------
1159
 
 
1160
 
 
1161
 
/*
1162
 
 * Write an array of pixels with a boolean mask.  The current color
1163
 
 * index is used for all pixels.
1164
 
 */
1165
 
static void write_mono_ci_pixels( const GLcontext* ctx,
1166
 
                                  GLuint n,
1167
 
                                  const GLint x[], const GLint y[],
1168
 
                                  GLuint colorIndex, const GLubyte mask[] )
1169
 
{
1170
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1171
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1172
 
  GLuint i;
1173
 
  assert(Current->rgb_flag==GL_FALSE);
1174
 
  for (i=0; i<n; i++) {
1175
 
    if (mask[i]) {
1176
 
      BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
1177
 
      *Mem = colorIndex;
1178
 
    }
1179
 
  }
1180
 
}
1181
 
 
1182
 
 
1183
 
//---------------------------------------------------------------------------
1184
 
 
1185
 
 
1186
 
/* Write an array of RGBA pixels with a boolean mask. */
1187
 
static void write_rgba_pixels( const GLcontext* ctx,
1188
 
                               GLuint n, const GLint x[], const GLint y[],
1189
 
                               const GLubyte rgba[][4], const GLubyte mask[] )
1190
 
{
1191
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1192
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1193
 
  GLuint i;
1194
 
  PWMC    pwc = Current;
1195
 
  HDC DC=DD_GETDC;
1196
 
  assert(Current->rgb_flag==GL_TRUE);
1197
 
  for (i=0; i<n; i++)
1198
 
    if (mask[i])
1199
 
      wmSetPixel(pwc, FLIP(y[i]), x[i],
1200
 
                 rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1201
 
  DD_RELEASEDC;
1202
 
}
1203
 
 
1204
 
 
1205
 
//---------------------------------------------------------------------------
1206
 
 
1207
 
 
1208
 
/*
1209
 
 * Write an array of pixels with a boolean mask.  The current color
1210
 
 * is used for all pixels.
1211
 
 */
1212
 
static void write_mono_rgba_pixels( const GLcontext* ctx,
1213
 
                                    GLuint n,
1214
 
                                    const GLint x[], const GLint y[],
1215
 
                                    const GLchan color[4],
1216
 
                                    const GLubyte mask[] )
1217
 
{
1218
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1219
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1220
 
  GLuint i;
1221
 
  PWMC    pwc = Current;
1222
 
  HDC DC=DD_GETDC;
1223
 
  assert(Current->rgb_flag==GL_TRUE);
1224
 
  for (i=0; i<n; i++)
1225
 
    if (mask[i])
1226
 
      wmSetPixel(pwc, FLIP(y[i]),x[i],color[RCOMP],
1227
 
                 color[GCOMP], color[BCOMP]);
1228
 
  DD_RELEASEDC;
1229
 
}
1230
 
 
1231
 
/**********************************************************************/
1232
 
/*****            Read spans/arrays of pixels                     *****/
1233
 
/**********************************************************************/
1234
 
 
1235
 
/* Read a horizontal span of color-index pixels. */
1236
 
static void read_ci32_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
1237
 
                            GLuint index[])
1238
 
{
1239
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1240
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1241
 
  GLuint i;
1242
 
  BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
1243
 
  assert(Current->rgb_flag==GL_FALSE);
1244
 
  for (i=0; i<n; i++)
1245
 
    index[i]=Mem[i];
1246
 
}
1247
 
 
1248
 
//---------------------------------------------------------------------------
1249
 
 
1250
 
/* Read an array of color index pixels. */
1251
 
static void read_ci32_pixels( const GLcontext* ctx,
1252
 
                              GLuint n, const GLint x[], const GLint y[],
1253
 
                              GLuint indx[], const GLubyte mask[] )
1254
 
{
1255
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1256
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1257
 
  GLuint i;
1258
 
  assert(Current->rgb_flag==GL_FALSE);
1259
 
  for (i=0; i<n; i++) {
1260
 
    if (mask[i]) {
1261
 
      indx[i]=*(Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]);
1262
 
    }
1263
 
  }
1264
 
}
1265
 
 
1266
 
//---------------------------------------------------------------------------
1267
 
 
1268
 
/* Read a horizontal span of color pixels. */
1269
 
static void read_rgba_span( const GLcontext* ctx,
1270
 
                            GLuint n, GLint x, GLint y,
1271
 
                            GLubyte rgba[][4] )
1272
 
{
1273
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1274
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1275
 
  UINT i;
1276
 
  COLORREF Color;
1277
 
  HDC DC=DD_GETDC;
1278
 
  assert(Current->rgb_flag==GL_TRUE);
1279
 
  y = Current->height - y - 1;
1280
 
  for (i=0; i<n; i++) {
1281
 
    Color=GetPixel(DC,x+i,y);
1282
 
    rgba[i][RCOMP] = GetRValue(Color);
1283
 
    rgba[i][GCOMP] = GetGValue(Color);
1284
 
    rgba[i][BCOMP] = GetBValue(Color);
1285
 
    rgba[i][ACOMP] = 255;
1286
 
  }
1287
 
  DD_RELEASEDC;
1288
 
}
1289
 
 
1290
 
//---------------------------------------------------------------------------
1291
 
 
1292
 
/* Read an array of color pixels. */
1293
 
static void read_rgba_pixels( const GLcontext* ctx,
1294
 
                              GLuint n, const GLint x[], const GLint y[],
1295
 
                              GLubyte rgba[][4], const GLubyte mask[] )
1296
 
{
1297
 
        GLD_context *gldCtx = GLD_GET_CONTEXT(ctx);
1298
 
        WMesaContext *Current = GLD_GET_WMESA_DRIVER(gldCtx);
1299
 
  GLuint i;
1300
 
  COLORREF Color;
1301
 
  HDC DC=DD_GETDC;
1302
 
  assert(Current->rgb_flag==GL_TRUE);
1303
 
  for (i=0; i<n; i++) {
1304
 
    if (mask[i]) {
1305
 
      GLint y2 = Current->height - y[i] - 1;
1306
 
      Color=GetPixel(DC,x[i],y2);
1307
 
      rgba[i][RCOMP] = GetRValue(Color);
1308
 
      rgba[i][GCOMP] = GetGValue(Color);
1309
 
      rgba[i][BCOMP] = GetBValue(Color);
1310
 
      rgba[i][ACOMP] = 255;
1311
 
    }
1312
 
  }
1313
 
  DD_RELEASEDC;
1314
 
}
1315
 
 
1316
 
//---------------------------------------------------------------------------
1317
 
 
1318
 
static void wmesa_update_state(
1319
 
        GLcontext *ctx,
1320
 
        GLuint new_state)
1321
 
{
1322
 
    _swrast_InvalidateState( ctx, new_state );
1323
 
        _swsetup_InvalidateState( ctx, new_state );
1324
 
        _ac_InvalidateState( ctx, new_state );
1325
 
        _tnl_InvalidateState( ctx, new_state );
1326
 
}
1327
 
 
1328
 
//---------------------------------------------------------------------------
1329
 
 
1330
 
static void wmesa_viewport(
1331
 
        GLcontext *ctx,
1332
 
        GLint x,
1333
 
        GLint y,
1334
 
        GLsizei w,
1335
 
        GLsizei h)
1336
 
{
1337
 
//      ctx->Driver.ResizeBuffersMESA(ctx);
1338
 
}
1339
 
 
1340
 
//---------------------------------------------------------------------------
1341
 
 
1342
 
static void wmesa_update_state_first_time(
1343
 
        GLcontext *ctx,
1344
 
        GLuint new_state)
1345
 
{
1346
 
        struct swrast_device_driver     *swdd = _swrast_GetDeviceDriverReference( ctx );
1347
 
        TNLcontext                                      *tnl = TNL_CONTEXT(ctx);
1348
 
        
1349
 
        /*
1350
 
        * XXX these function pointers could be initialized just once during
1351
 
        * context creation since they don't depend on any state changes.
1352
 
        * kws - This is true - this function gets called a lot and it
1353
 
        * would be good to minimize setting all this when not needed.
1354
 
        */
1355
 
        // Good idea, so I'll do it. KeithH. :-)
1356
 
 
1357
 
        ctx->Driver.GetString                           = _gldGetStringGeneric;
1358
 
        ctx->Driver.UpdateState                         = wmesa_update_state;
1359
 
        ctx->Driver.DrawBuffer                          = set_draw_buffer;
1360
 
        ctx->Driver.ResizeBuffers                       = _swrast_alloc_buffers;
1361
 
        ctx->Driver.GetBufferSize                       = buffer_size;
1362
 
 
1363
 
        ctx->Driver.Viewport                            = wmesa_viewport;
1364
 
        
1365
 
        ctx->Driver.Accum                                       = _swrast_Accum;
1366
 
        ctx->Driver.Bitmap                                      = _swrast_Bitmap;
1367
 
        ctx->Driver.Clear                                       = clear;
1368
 
        
1369
 
        ctx->Driver.Flush                                       = flush;
1370
 
        ctx->Driver.ClearIndex                          = clear_index;
1371
 
        ctx->Driver.ClearColor                          = clear_color;
1372
 
        ctx->Driver.Enable                                      = enable;
1373
 
        
1374
 
        ctx->Driver.CopyPixels                          = _swrast_CopyPixels;
1375
 
        ctx->Driver.DrawPixels                          = _swrast_DrawPixels;
1376
 
        ctx->Driver.ReadPixels                          = _swrast_ReadPixels;
1377
 
        
1378
 
        ctx->Driver.ChooseTextureFormat         = _mesa_choose_tex_format;
1379
 
        ctx->Driver.TexImage1D                          = _mesa_store_teximage1d;
1380
 
        ctx->Driver.TexImage2D                          = _mesa_store_teximage2d;
1381
 
        ctx->Driver.TexImage3D                          = _mesa_store_teximage3d;
1382
 
        ctx->Driver.TexSubImage1D                       = _mesa_store_texsubimage1d;
1383
 
        ctx->Driver.TexSubImage2D                       = _mesa_store_texsubimage2d;
1384
 
        ctx->Driver.TexSubImage3D                       = _mesa_store_texsubimage3d;
1385
 
        ctx->Driver.TestProxyTexImage           = _mesa_test_proxy_teximage;
1386
 
        
1387
 
        ctx->Driver.CopyTexImage1D                      = _swrast_copy_teximage1d;
1388
 
        ctx->Driver.CopyTexImage2D                      = _swrast_copy_teximage2d;
1389
 
        ctx->Driver.CopyTexSubImage1D           = _swrast_copy_texsubimage1d;
1390
 
        ctx->Driver.CopyTexSubImage2D           = _swrast_copy_texsubimage2d;
1391
 
        ctx->Driver.CopyTexSubImage3D           = _swrast_copy_texsubimage3d;
1392
 
        ctx->Driver.CopyColorTable                      = _swrast_CopyColorTable;
1393
 
        ctx->Driver.CopyColorSubTable           = _swrast_CopyColorSubTable;
1394
 
        ctx->Driver.CopyConvolutionFilter1D     = _swrast_CopyConvolutionFilter1D;
1395
 
        ctx->Driver.CopyConvolutionFilter2D     = _swrast_CopyConvolutionFilter2D;
1396
 
        
1397
 
        // Does not apply for Mesa 5.x
1398
 
        //ctx->Driver.BaseCompressedTexFormat   = _mesa_base_compressed_texformat;
1399
 
        //ctx->Driver.CompressedTextureSize     = _mesa_compressed_texture_size;
1400
 
        //ctx->Driver.GetCompressedTexImage     = _mesa_get_compressed_teximage;
1401
 
        
1402
 
        swdd->SetBuffer                                 = set_read_buffer;
1403
 
        
1404
 
        
1405
 
        /* Pixel/span writing functions: */
1406
 
        swdd->WriteRGBASpan        = write_rgba_span;
1407
 
        swdd->WriteRGBSpan         = write_rgb_span;
1408
 
        swdd->WriteMonoRGBASpan    = write_mono_rgba_span;
1409
 
        swdd->WriteRGBAPixels      = write_rgba_pixels;
1410
 
        swdd->WriteMonoRGBAPixels  = write_mono_rgba_pixels;
1411
 
        swdd->WriteCI32Span        = write_ci32_span;
1412
 
        swdd->WriteCI8Span         = write_ci8_span;
1413
 
        swdd->WriteMonoCISpan      = write_mono_ci_span;
1414
 
        swdd->WriteCI32Pixels      = write_ci32_pixels;
1415
 
        swdd->WriteMonoCIPixels    = write_mono_ci_pixels;
1416
 
        
1417
 
        swdd->ReadCI32Span        = read_ci32_span;
1418
 
        swdd->ReadRGBASpan        = read_rgba_span;
1419
 
        swdd->ReadCI32Pixels      = read_ci32_pixels;
1420
 
        swdd->ReadRGBAPixels      = read_rgba_pixels;
1421
 
        
1422
 
        
1423
 
        tnl->Driver.RunPipeline = _tnl_run_pipeline;
1424
 
        
1425
 
        wmesa_update_state(ctx, new_state);
1426
 
}
1427
 
 
1428
 
//---------------------------------------------------------------------------
1429
 
// Driver interface functions
1430
 
//---------------------------------------------------------------------------
1431
 
 
1432
 
BOOL gldCreateDrawable_MesaSW(
1433
 
        DGL_ctx *pCtx,
1434
 
        BOOL bPersistantInterface,
1435
 
        BOOL bPersistantBuffers)
1436
 
{
1437
 
        WMesaContext *c;
1438
 
        GLboolean true_color_flag;
1439
 
        GLboolean rgb_flag = GL_TRUE;
1440
 
        GLboolean db_flag = GL_TRUE;
1441
 
 
1442
 
        if (pCtx == NULL)
1443
 
                return FALSE;
1444
 
 
1445
 
        c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context));
1446
 
        if (!c)
1447
 
                return FALSE;
1448
 
 
1449
 
        pCtx->glPriv = c;
1450
 
 
1451
 
        c->hDC          = pCtx->hDC;
1452
 
        c->Window       = pCtx->hWnd;
1453
 
 
1454
 
        true_color_flag = GetDeviceCaps(pCtx->hDC, BITSPIXEL) > 8;
1455
 
        
1456
 
        
1457
 
#ifdef DITHER
1458
 
        if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){
1459
 
                c->dither_flag = GL_TRUE;
1460
 
                c->hPalHalfTone = WinGCreateHalftonePalette();
1461
 
        }
1462
 
        else
1463
 
                c->dither_flag = GL_FALSE;
1464
 
#else
1465
 
        c->dither_flag = GL_FALSE;
1466
 
#endif
1467
 
        
1468
 
        
1469
 
        if (rgb_flag==GL_FALSE)
1470
 
    {
1471
 
                c->rgb_flag = GL_FALSE;
1472
 
#if 0
1473
 
                /* Old WinG stuff???? */
1474
 
                c->db_flag = db_flag =GL_TRUE; /* WinG requires double buffering */
1475
 
                printf("Single buffer is not supported in color index mode, ",
1476
 
                        "setting to double buffer.\n");
1477
 
#endif
1478
 
    }
1479
 
        else
1480
 
    {
1481
 
                c->rgb_flag = GL_TRUE;
1482
 
    }
1483
 
 
1484
 
//      db_flag = pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER ? GL_TRUE : GL_FALSE;
1485
 
        db_flag = GL_TRUE; // Force double-buffer
1486
 
        if (db_flag) {
1487
 
                c->db_flag = 1;
1488
 
                /* Double buffered */
1489
 
                {
1490
 
                        wmCreateBackingStore(c, pCtx->dwWidth, pCtx->dwHeight);
1491
 
                        
1492
 
                }
1493
 
    } else {
1494
 
                /* Single Buffered */
1495
 
                if (c->rgb_flag)
1496
 
                        c->db_flag = 0;
1497
 
    }   
1498
 
 
1499
 
        c->bEmulateSingleBuffer = (pCtx->lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER)
1500
 
                ? FALSE : TRUE;
1501
 
 
1502
 
        return TRUE;
1503
 
}
1504
 
 
1505
 
//---------------------------------------------------------------------------
1506
 
 
1507
 
BOOL gldResizeDrawable_MesaSW(
1508
 
        DGL_ctx *ctx,
1509
 
        BOOL bDefaultDriver,
1510
 
        BOOL bPersistantInterface,
1511
 
        BOOL bPersistantBuffers)
1512
 
{
1513
 
        WMesaContext *c;
1514
 
 
1515
 
        if (ctx == NULL)
1516
 
                return FALSE;
1517
 
 
1518
 
        c = ctx->glPriv;
1519
 
        if (c == NULL)
1520
 
                return FALSE;
1521
 
 
1522
 
        c->hDC = ctx->hDC;
1523
 
        c->Window = ctx->hWnd;
1524
 
//      c->width = ctx->dwWidth;
1525
 
//      c->height = ctx->dwHeight;
1526
 
 
1527
 
        if (c->db_flag) {
1528
 
                wmDeleteBackingStore(c);
1529
 
                wmCreateBackingStore(c, ctx->dwWidth, ctx->dwHeight);
1530
 
        }
1531
 
 
1532
 
        return TRUE;
1533
 
}
1534
 
 
1535
 
//---------------------------------------------------------------------------
1536
 
 
1537
 
BOOL gldDestroyDrawable_MesaSW(
1538
 
        DGL_ctx *ctx)
1539
 
{
1540
 
        WMesaContext *c;
1541
 
 
1542
 
        if (ctx == NULL)
1543
 
                return FALSE;
1544
 
 
1545
 
        c = ctx->glPriv;
1546
 
        if (c == NULL)
1547
 
                return FALSE;
1548
 
 
1549
 
        if (c->hPalHalfTone != NULL)
1550
 
                DeleteObject(c->hPalHalfTone);
1551
 
    
1552
 
        if (c->db_flag)
1553
 
                wmDeleteBackingStore(c);
1554
 
 
1555
 
        free(c);
1556
 
 
1557
 
        ctx->glPriv = NULL;
1558
 
 
1559
 
        return TRUE;
1560
 
}
1561
 
 
1562
 
//---------------------------------------------------------------------------
1563
 
 
1564
 
BOOL gldCreatePrivateGlobals_MesaSW(void)
1565
 
{
1566
 
        // Mesa Software driver needs no private globals
1567
 
        return TRUE;
1568
 
}
1569
 
 
1570
 
//---------------------------------------------------------------------------
1571
 
 
1572
 
BOOL gldDestroyPrivateGlobals_MesaSW(void)
1573
 
{
1574
 
        // Mesa Software driver needs no private globals
1575
 
        return TRUE;
1576
 
}
1577
 
 
1578
 
//---------------------------------------------------------------------------
1579
 
 
1580
 
BOOL gldBuildPixelformatList_MesaSW(void)
1581
 
{
1582
 
        // Release any existing pixelformat list
1583
 
        if (glb.lpPF) {
1584
 
                free(glb.lpPF);
1585
 
        }
1586
 
 
1587
 
        glb.nPixelFormatCount   = 0;
1588
 
        glb.lpPF                                = NULL;
1589
 
 
1590
 
        glb.lpPF = (DGL_pixelFormat *)calloc(2, sizeof(DGL_pixelFormat));
1591
 
        if (glb.lpPF == NULL)
1592
 
                return FALSE;
1593
 
        // Single-buffered
1594
 
        memcpy(&glb.lpPF[0], &pfTemplateMesaSW, sizeof(DGL_pixelFormat));
1595
 
        glb.lpPF[0].pfd.dwFlags &= ~PFD_DOUBLEBUFFER; // Remove doublebuffer flag
1596
 
        // Double-buffered
1597
 
        memcpy(&glb.lpPF[1], &pfTemplateMesaSW, sizeof(DGL_pixelFormat));
1598
 
        glb.nPixelFormatCount = 2;
1599
 
 
1600
 
        // Mark list as 'current'
1601
 
        glb.bPixelformatsDirty = FALSE;
1602
 
 
1603
 
        return TRUE;
1604
 
}
1605
 
 
1606
 
//---------------------------------------------------------------------------
1607
 
 
1608
 
BOOL gldInitialiseMesa_MesaSW(
1609
 
        DGL_ctx *gld)
1610
 
{
1611
 
        GLcontext *ctx;
1612
 
 
1613
 
        if (gld == NULL)
1614
 
                return FALSE;
1615
 
 
1616
 
        ctx = gld->glCtx;
1617
 
 
1618
 
        // Set max texture size to 256
1619
 
        ctx->Const.MaxTextureLevels = 8;
1620
 
 
1621
 
        // Multitexture enable/disable
1622
 
        ctx->Const.MaxTextureUnits = (glb.bMultitexture) ? MAX_TEXTURE_UNITS : 1;
1623
 
 
1624
 
        /* Initialize the software rasterizer and helper modules.*/
1625
 
 
1626
 
        // Added this to force max texture diminsion to 256. KeithH
1627
 
        ctx->Const.MaxTextureLevels = 8;
1628
 
 
1629
 
        _mesa_enable_sw_extensions(ctx);
1630
 
        _mesa_enable_imaging_extensions(ctx);
1631
 
        _mesa_enable_1_3_extensions(ctx);
1632
 
        
1633
 
//      _swrast_CreateContext( ctx );
1634
 
//      _ac_CreateContext( ctx );
1635
 
//      _tnl_CreateContext( ctx );
1636
 
//      _swsetup_CreateContext( ctx );
1637
 
        
1638
 
        _swsetup_Wakeup( ctx );
1639
 
        
1640
 
        wmesa_update_state_first_time(ctx, ~0);
1641
 
 
1642
 
        return TRUE;
1643
 
}
1644
 
 
1645
 
//---------------------------------------------------------------------------
1646
 
 
1647
 
BOOL gldSwapBuffers_MesaSW(
1648
 
        DGL_ctx *ctx,
1649
 
        HDC hDC,
1650
 
        HWND hWnd)
1651
 
{
1652
 
        WMesaContext *c;
1653
 
 
1654
 
        if (ctx == NULL)
1655
 
                return FALSE;
1656
 
 
1657
 
        c = ctx->glPriv;
1658
 
        if (c == NULL)
1659
 
                return FALSE;
1660
 
        
1661
 
        /* If we're swapping the buffer associated with the current context
1662
 
        * we have to flush any pending rendering commands first.
1663
 
        */
1664
 
 
1665
 
        // Altered to respect bEmulateSingleBuffer. KeithH
1666
 
//      if (c->db_flag)
1667
 
        if (!c->bEmulateSingleBuffer)
1668
 
                wmFlush(c, hDC);
1669
 
 
1670
 
        return TRUE;
1671
 
}
1672
 
 
1673
 
//---------------------------------------------------------------------------
1674
 
 
1675
 
PROC gldGetProcAddress_MesaSW(
1676
 
        LPCSTR a)
1677
 
{
1678
 
        int             i;
1679
 
        PROC    proc = NULL;
1680
 
 
1681
 
        for (i=0; GLD_extList[i].proc; i++) {
1682
 
                if (!strcmp(a, GLD_extList[i].name)) {
1683
 
                        proc = GLD_extList[i].proc;
1684
 
                        break;
1685
 
                }
1686
 
        }
1687
 
 
1688
 
        gldLogPrintf(GLDLOG_INFO, "GetProcAddress: %s (%s)", a, proc ? "OK" : "Failed");
1689
 
 
1690
 
        return proc;
1691
 
}
1692
 
 
1693
 
//---------------------------------------------------------------------------
1694
 
 
1695
 
BOOL gldGetDisplayMode_MesaSW(
1696
 
        DGL_ctx *ctx,
1697
 
        GLD_displayMode *glddm)
1698
 
{
1699
 
        HDC hdcDesktop;
1700
 
 
1701
 
        if (glddm == NULL)
1702
 
                return FALSE;
1703
 
 
1704
 
        //
1705
 
        // A bit hacky... KeithH
1706
 
        //
1707
 
 
1708
 
        hdcDesktop = GetDC(NULL);
1709
 
        glddm->Width    = GetDeviceCaps(hdcDesktop, HORZRES);
1710
 
        glddm->Height   = GetDeviceCaps(hdcDesktop, VERTRES);
1711
 
        glddm->BPP              = GetDeviceCaps(hdcDesktop, BITSPIXEL);
1712
 
        glddm->Refresh  = 0;
1713
 
        ReleaseDC(0, hdcDesktop);
1714
 
 
1715
 
        return TRUE;
1716
 
}
1717
 
 
1718
 
//---------------------------------------------------------------------------
1719