summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/windows
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/drivers/windows')
-rw-r--r--src/mesa/drivers/windows/colors.h499
-rw-r--r--src/mesa/drivers/windows/mesa_extend.c211
-rw-r--r--src/mesa/drivers/windows/mesa_extend.h43
-rw-r--r--src/mesa/drivers/windows/stereo.h47
-rw-r--r--src/mesa/drivers/windows/wgl.c518
-rw-r--r--src/mesa/drivers/windows/wing32.def12
-rw-r--r--src/mesa/drivers/windows/wmesa.c3021
-rw-r--r--src/mesa/drivers/windows/wmesaBackup.c2879
-rw-r--r--src/mesa/drivers/windows/wmesaOld.c2737
-rw-r--r--src/mesa/drivers/windows/wmesa_stereo.c1872
-rw-r--r--src/mesa/drivers/windows/wmesadef.h154
11 files changed, 11993 insertions, 0 deletions
diff --git a/src/mesa/drivers/windows/colors.h b/src/mesa/drivers/windows/colors.h
new file mode 100644
index 00000000000..40ead3040fe
--- /dev/null
+++ b/src/mesa/drivers/windows/colors.h
@@ -0,0 +1,499 @@
+/* File name : colors.h
+ * Version : 2.3
+ *
+ * Header file for display driver for Mesa 2.3 under
+ * Windows95 and WindowsNT
+ * This file defines macros and global variables needed
+ * for converting color format
+ *
+ * Copyright (C) 1996- Li Wei
+ * Address : Institute of Artificial Intelligence
+ * : & Robotics
+ * : Xi'an Jiaotong University
+ * Email : [email protected]
+ * Web page : http://sun.aiar.xjtu.edu.cn
+ *
+ * This file and its associations are partially based on the
+ * Windows NT driver for Mesa, written by Mark Leaming
+ */
+
+/* $Log: ddcolors.h 1997/6/14 by Li Wei([email protected])
+ * Macros for pixel format defined
+ */
+
+/*
+ * $Log: colors.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.2 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 1.1 1999/01/03 03:08:12 brianp
+ * Initial revision
+ *
+ * Revision 2.0.2 1997/4/30 15:58:00 CST by Li Wei([email protected])
+ * Add LUTs need for dithering
+ */
+
+/*
+ * $Log: colors.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.2 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 1.1 1999/01/03 03:08:12 brianp
+ * Initial revision
+ *
+ * Revision 2.0.1 1997/4/29 15:52:00 CST by Li Wei([email protected])
+ * Add BGR8 Macro
+ */
+
+/*
+ * $Log: colors.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.2 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 1.1 1999/01/03 03:08:12 brianp
+ * Initial revision
+ *
+ * Revision 2.0 1996/11/15 10:55:00 CST by Li Wei([email protected])
+ * Initial revision
+ */
+/* Values for wmesa->pixelformat: */
+
+#define PF_8A8B8G8R 3 /* 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R */
+#define PF_8R8G8B 4 /* 32-bit TrueColor: 8-R, 8-G, 8-B */
+#define PF_5R6G5B 5 /* 16-bit TrueColor: 5-R, 6-G, 5-B bits */
+#define PF_DITHER8 6 /* Dithered RGB using a lookup table */
+#define PF_LOOKUP 7 /* Undithered RGB using a lookup table */
+#define PF_GRAYSCALE 10 /* Grayscale or StaticGray */
+#define PF_BADFORMAT 11
+#define PF_INDEX8 12
+
+char ColorMap16[] = {
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
+0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
+0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
+0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,
+0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
+0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
+0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
+0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
+0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,
+0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,
+0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
+0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
+0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,0x0D,
+0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,
+0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
+0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
+0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
+0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
+0x13,0x13,0x13,0x13,0x13,0x13,0x13,0x13,
+0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
+0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
+0x16,0x16,0x16,0x16,0x16,0x16,0x16,0x16,
+0x17,0x17,0x17,0x17,0x17,0x17,0x17,0x17,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,
+0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,0x1A,
+0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,0x1B,
+0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,
+0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,0x1D,
+0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,
+0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F};
+
+#define BGR8(r,g,b) (unsigned)(((BYTE)(b & 0xc0 | (g & 0xe0)>>2 | (r & 0xe0)>>5)))
+#ifdef DDRAW
+#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(g&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[r])) << 11)))
+#else
+#define BGR16(r,g,b) ((WORD)(((BYTE)(ColorMap16[b]) | ((BYTE)(ColorMap16[g]) << 5)) | (((WORD)(BYTE)(ColorMap16[r])) << 10)))
+#endif
+#define BGR24(r,g,b) (unsigned long)(((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16))) << 8)
+#define BGR32(r,g,b) (unsigned long)((DWORD)(((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
+
+
+
+/*
+ * If pixelformat==PF_8A8B8G8R:
+ */
+#define PACK_8A8B8G8R( R, G, B, A ) \
+ ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
+
+
+/*
+ * If pixelformat==PF_8R8G8B:
+ */
+#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
+
+
+/*
+ * If pixelformat==PF_5R6G5B:
+ */
+
+
+#ifdef DDRAW
+#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(G&0xfc) << 3)) | (((WORD)(BYTE)(ColorMap16[R])) << 11)))
+#else
+#define PACK_5R6G5B( R, G, B) ((WORD)(((BYTE)(ColorMap16[B]) | ((BYTE)(ColorMap16[G]) << 5)) | (((WORD)(BYTE)(ColorMap16[R])) << 10)))
+#endif
+/*----------------------------------------------------------------------------
+
+Division lookup tables. These tables compute 0-255 divided by 51 and
+modulo 51. These tables could approximate gamma correction.
+
+*/
+
+char unsigned const aDividedBy51Rounded[256] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+};
+
+char unsigned const aDividedBy51[256] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
+};
+
+char unsigned const aModulo51[256] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
+ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
+ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6,
+ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
+ 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0, 1, 2, 3,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 0,
+};
+
+/*----------------------------------------------------------------------------
+
+Multiplication LUTs. These compute 0-5 times 6 and 36.
+
+*/
+
+char unsigned const aTimes6[6] =
+{
+ 0, 6, 12, 18, 24, 30
+};
+
+char unsigned const aTimes36[6] =
+{
+ 0, 36, 72, 108, 144, 180
+};
+
+
+/*----------------------------------------------------------------------------
+
+Dither matrices for 8 bit to 2.6 bit halftones.
+
+*/
+
+char unsigned const aHalftone16x16[256] =
+{
+ 0, 44, 9, 41, 3, 46, 12, 43, 1, 44, 10, 41, 3, 46, 12, 43,
+ 34, 16, 25, 19, 37, 18, 28, 21, 35, 16, 26, 19, 37, 18, 28, 21,
+ 38, 6, 47, 3, 40, 9, 50, 6, 38, 7, 47, 4, 40, 9, 49, 6,
+ 22, 28, 13, 31, 25, 31, 15, 34, 22, 29, 13, 32, 24, 31, 15, 34,
+ 2, 46, 12, 43, 1, 45, 10, 42, 2, 45, 11, 42, 1, 45, 11, 42,
+ 37, 18, 27, 21, 35, 17, 26, 20, 36, 17, 27, 20, 36, 17, 26, 20,
+ 40, 8, 49, 5, 38, 7, 48, 4, 39, 8, 48, 5, 39, 7, 48, 4,
+ 24, 30, 15, 33, 23, 29, 13, 32, 23, 30, 14, 33, 23, 29, 14, 32,
+ 2, 46, 12, 43, 0, 44, 10, 41, 3, 47, 12, 44, 0, 44, 10, 41,
+ 37, 18, 27, 21, 35, 16, 25, 19, 37, 19, 28, 22, 35, 16, 25, 19,
+ 40, 9, 49, 5, 38, 7, 47, 4, 40, 9, 50, 6, 38, 6, 47, 3,
+ 24, 30, 15, 34, 22, 29, 13, 32, 25, 31, 15, 34, 22, 28, 13, 31,
+ 1, 45, 11, 42, 2, 46, 11, 42, 1, 45, 10, 41, 2, 46, 11, 43,
+ 36, 17, 26, 20, 36, 17, 27, 21, 35, 16, 26, 20, 36, 18, 27, 21,
+ 39, 8, 48, 4, 39, 8, 49, 5, 38, 7, 48, 4, 39, 8, 49, 5,
+ 23, 29, 14, 33, 24, 30, 14, 33, 23, 29, 13, 32, 24, 30, 14, 33,
+};
+
+char unsigned const aHalftone8x8[64] =
+{
+ 0, 38, 9, 47, 2, 40, 11, 50,
+ 25, 12, 35, 22, 27, 15, 37, 24,
+ 6, 44, 3, 41, 8, 47, 5, 43,
+ 31, 19, 28, 15, 34, 21, 31, 18,
+ 1, 39, 11, 49, 0, 39, 10, 48,
+ 27, 14, 36, 23, 26, 13, 35, 23,
+ 7, 46, 4, 43, 7, 45, 3, 42,
+ 33, 20, 30, 17, 32, 19, 29, 16,
+};
+
+char unsigned const aHalftone4x4_1[16] =
+{
+ 0, 25, 6, 31,
+ 38, 12, 44, 19,
+ 9, 35, 3, 28,
+ 47, 22, 41, 15
+};
+
+char unsigned const aHalftone4x4_2[16] =
+{
+ 41, 3, 9, 28,
+ 35, 15, 22, 47,
+ 6, 25, 38, 0,
+ 19, 44, 31, 12
+};
+
+/***************************************************************************
+ aWinGHalftoneTranslation
+
+ Translates a 2.6 bit-per-pixel halftoned representation into the
+ slightly rearranged WinG Halftone Palette.
+*/
+
+char unsigned const aWinGHalftoneTranslation[216] =
+{
+ 0,
+ 29,
+ 30,
+ 31,
+ 32,
+ 249,
+ 33,
+ 34,
+ 35,
+ 36,
+ 37,
+ 38,
+ 39,
+ 40,
+ 41,
+ 42,
+ 43,
+ 44,
+ 45,
+ 46,
+ 47,
+ 48,
+ 49,
+ 50,
+ 51,
+ 52,
+ 53,
+ 54,
+ 55,
+ 56,
+ 250,
+ 250,
+ 57,
+ 58,
+ 59,
+ 251,
+ 60,
+ 61,
+ 62,
+ 63,
+ 64,
+ 65,
+ 66,
+ 67,
+ 68,
+ 69,
+ 70,
+ 71,
+ 72,
+ 73,
+ 74,
+ 75,
+ 76,
+ 77,
+ 78,
+ 79,
+ 80,
+ 81,
+ 82,
+ 83,
+ 84,
+ 85,
+ 86,
+ 87,
+ 88,
+ 89,
+ 250,
+ 90,
+ 91,
+ 92,
+ 93,
+ 94,
+ 95,
+ 96,
+ 97,
+ 98,
+ 99,
+ 100,
+ 101,
+ 102,
+ 103,
+ 104,
+ 105,
+ 106,
+ 107,
+ 108,
+ 109,
+ 110,
+ 111,
+ 227,
+ 112,
+ 113,
+ 114,
+ 115,
+ 116,
+ 117,
+ 118,
+ 119,
+ 151,
+ 120,
+ 121,
+ 122,
+ 123,
+ 124,
+ 228,
+ 125,
+ 126,
+ 229,
+ 133,
+ 162,
+ 135,
+ 131,
+ 132,
+ 137,
+ 166,
+ 134,
+ 140,
+ 130,
+ 136,
+ 143,
+ 138,
+ 139,
+ 174,
+ 141,
+ 142,
+ 177,
+ 129,
+ 144,
+ 145,
+ 146,
+ 147,
+ 148,
+ 149,
+ 150,
+ 157,
+ 152,
+ 153,
+ 154,
+ 155,
+ 156,
+ 192,
+ 158,
+ 159,
+ 160,
+ 161,
+ 196,
+ 163,
+ 164,
+ 165,
+ 127,
+ 199,
+ 167,
+ 168,
+ 169,
+ 170,
+ 171,
+ 172,
+ 173,
+ 207,
+ 175,
+ 176,
+ 210,
+ 178,
+ 179,
+ 180,
+ 181,
+ 182,
+ 183,
+ 184,
+ 185,
+ 186,
+ 187,
+ 188,
+ 189,
+ 190,
+ 191,
+ 224,
+ 193,
+ 194,
+ 195,
+ 252,
+ 252,
+ 197,
+ 198,
+ 128,
+ 253,
+ 252,
+ 200,
+ 201,
+ 202,
+ 203,
+ 204,
+ 205,
+ 206,
+ 230,
+ 208,
+ 209,
+ 231,
+ 211,
+ 212,
+ 213,
+ 214,
+ 215,
+ 216,
+ 217,
+ 218,
+ 219,
+ 220,
+ 221,
+ 222,
+ 254,
+ 223,
+ 232,
+ 225,
+ 226,
+ 255,
+}; \ No newline at end of file
diff --git a/src/mesa/drivers/windows/mesa_extend.c b/src/mesa/drivers/windows/mesa_extend.c
new file mode 100644
index 00000000000..933e3badd3c
--- /dev/null
+++ b/src/mesa/drivers/windows/mesa_extend.c
@@ -0,0 +1,211 @@
+/* File: mesa_extend.c for wmesa-2.3
+ Written by Li Wei ([email protected])
+*/
+
+/*******************************************************************
+ Users can use the following keys to control the view
+
+ The following four key combinations can shift the view correspondingly,
+ function in both stereo and normal mode.
+ Ctrl+left arrow
+ Ctrl+right arrow
+ Ctrl+up arrow
+ Ctrl+down arrow
+
+ F (captital letter) shift the camera far from objects
+ N (captital letter) shift the camera near from objects
+ S (captital letter) toggle between normal and stereo mode
+ I (captital letter) increase the distance between two views
+ D (captital letter) decrease the distance between two views
+
+ if the Key function defined by user maps any key appearing above, it will be
+ masked by the program. Hence, user should either modify his own code or
+ modify function defaultKeyProc at the end of this file
+*******************************************************************/
+
+/* Log 6/14, 1997
+ * revision 1.01
+ * struct DisplayOptions defined for tk_ddmesa.c to read the initial file
+ */
+
+#include "mesa_extend.h"
+#include "gltk.h"
+#include <stdio.h>
+#ifndef NO_STEREO
+ #include "stereo.h"
+#endif
+#ifndef NO_PARALLEL
+// #include "parallel.h"
+#endif
+
+GLenum (*userKeyProc) (int, GLenum) = NULL;
+
+GLfloat viewDistance = 1.0;
+GLfloat deltaView = 0.1;
+GLfloat deltaShift = 0.1;
+
+GLuint viewShift = SHIFT_NONE;
+GLuint viewTag = 0 ;
+
+GLenum imageRendered = GL_FALSE;
+
+GLenum glImageRendered()
+{
+ return imageRendered;
+}
+
+//Code added by Li Wei to enable stereo display
+GLenum defaultKeyProc(int key, GLenum mask )
+{
+ GLenum flag = GL_FALSE ;
+ if(mask & TK_CONTROL){
+ flag = GL_TRUE ;
+ switch(key){
+ case TK_LEFT:
+ viewShift = SHIFT_LEFT;
+ break;
+ case TK_RIGHT:
+ viewShift = SHIFT_RIGHT;
+ break;
+ case TK_UP:
+ viewShift = SHIFT_UP;
+ break;
+ case TK_DOWN:
+ viewShift = SHIFT_DOWN;
+ break;
+ default:
+ flag = GL_FALSE ;
+ }
+ }
+ if(flag == GL_FALSE){
+ flag = GL_TRUE ;
+ switch(key){
+ case TK_F:
+ viewShift = SHIFT_FAR;
+ break;
+ case TK_N:
+ viewShift = SHIFT_NEAR;
+ break;
+
+#if !defined(NO_STEREO)
+ case TK_D:
+ viewDistance-= deltaView;
+ break;
+ case TK_I:
+ viewDistance+= deltaView;
+ break;
+ case TK_S:
+ toggleStereoMode();
+ break;
+#endif
+
+#if !defined(NO_PARALLEL)
+ case TK_P:
+ if(machineType == MASTER)
+ toggleParallelMode();
+ break;
+#endif
+ default:
+ flag = GL_FALSE;
+ }
+ }
+
+ if(userKeyProc)
+ flag=flag||(*userKeyProc)(key, mask);
+
+#if !defined(NO_PARALLEL)
+ if(parallelFlag&&key!=TK_P&&machineType == MASTER){
+ PRKeyDown(key,mask);
+ }
+#endif
+
+ return flag;
+}
+
+/* The following function implemented key board control of the display,
+ availabe even in normal mode so long the driver is linked into exe file.
+*/
+void shiftView()
+{
+ GLfloat cm[16];
+ if(viewShift != SHIFT_NONE){
+/* glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glMatrixMode(GL_MODELVIEW);
+*/
+ GLint matrix_mode;
+ glGetIntegerv(GL_MATRIX_MODE,&matrix_mode);
+/* if(matrix_mode!=GL_PROJECTION)
+ glMatrixMode(GL_PROJECTION);
+ glGetFloatv(GL_PROJECTION_MATRIX,cm);
+ glLoadIdentity();
+ switch(viewShift){
+ case SHIFT_LEFT:
+ glTranslatef(-deltaShift,0,0);
+ break;
+ case SHIFT_RIGHT:
+ glTranslatef(deltaShift,0,0);
+ break;
+ case SHIFT_UP:
+ glTranslatef(0,deltaShift,0);
+ break;
+ case SHIFT_DOWN:
+ glTranslatef(0,-deltaShift,0);
+ break;
+ case SHIFT_FAR:
+ glTranslatef(0,0,-deltaShift);
+ break;
+ case SHIFT_NEAR:
+ glTranslatef(0,0,deltaShift);
+ break;
+ }
+
+ viewShift = SHIFT_NONE;
+ glMultMatrixf( cm );
+ if(matrix_mode!=GL_PROJECTION)
+ glMatrixMode(matrix_mode);
+
+ }
+*/
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(GL_MODELVIEW);
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ switch(viewShift){
+ case SHIFT_LEFT:
+ glTranslatef(-deltaShift,0,0);
+ break;
+ case SHIFT_RIGHT:
+ glTranslatef(deltaShift,0,0);
+ break;
+ case SHIFT_UP:
+ glTranslatef(0,deltaShift,0);
+ break;
+ case SHIFT_DOWN:
+ glTranslatef(0,-deltaShift,0);
+ break;
+ case SHIFT_FAR:
+ glTranslatef(0,0,-deltaShift);
+ break;
+ case SHIFT_NEAR:
+ glTranslatef(0,0,deltaShift);
+ break;
+ }
+
+ viewShift = SHIFT_NONE;
+ glMultMatrixf( cm );
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(matrix_mode);
+
+ }
+}
+
+
+void getDisplayOptions( void)
+{
+ displayOptions.stereo = GetPrivateProfileInt("DISPLAY", "STEREO",1,"ddmesa.ini" );
+ displayOptions.fullScreen = GetPrivateProfileInt("DISPLAY", "FULLSCREEN",0,"ddmesa.ini" );
+ displayOptions.mode = GetPrivateProfileInt("DISPLAY", "MODE",1, "ddmesa.ini");
+ displayOptions.bpp = GetPrivateProfileInt("DISPLAY", "BPP", 32, "ddmesa.ini");
+
+}
+//end modification
diff --git a/src/mesa/drivers/windows/mesa_extend.h b/src/mesa/drivers/windows/mesa_extend.h
new file mode 100644
index 00000000000..66a8a77d65e
--- /dev/null
+++ b/src/mesa/drivers/windows/mesa_extend.h
@@ -0,0 +1,43 @@
+/* mesa_extend.h
+ * for wmesa-2.3
+ * Written by Li Wei ([email protected])
+ */
+
+/* Log 6/14, 1997
+ * revision 1.01
+ * struct DisplayOptions defined for tk_ddmesa.c to read the initial file
+ */
+
+#include <GL/gl.h>
+#include <stdlib.h>
+#include <windows.h>
+#include <winbase.h>
+
+typedef enum SHIFT{ SHIFT_NONE, SHIFT_LEFT,SHIFT_RIGHT,SHIFT_UP,SHIFT_DOWN,SHIFT_FAR,SHIFT_NEAR};
+
+extern GLfloat deltaView ;
+
+extern GLuint viewShift;
+
+extern GLenum glImageRendered();
+
+extern GLenum imageRendered ;
+
+extern GLfloat deltaView ;
+
+extern GLfloat deltaShift;
+
+void shiftView( void );
+
+struct DISPLAY_OPTIONS {
+ int stereo;
+ int fullScreen;
+ int mode;
+ int bpp;
+};
+
+extern struct DISPLAY_OPTIONS displayOptions;
+extern void getDisplayOptions( void);
+
+GLenum defaultKeyProc(int, GLenum);
+extern GLenum (*userKeyProc) (int, GLenum);
diff --git a/src/mesa/drivers/windows/stereo.h b/src/mesa/drivers/windows/stereo.h
new file mode 100644
index 00000000000..544af542351
--- /dev/null
+++ b/src/mesa/drivers/windows/stereo.h
@@ -0,0 +1,47 @@
+/* File name stereov.h
+ header file for stereo display driver
+***************************************************************
+* WMesa *
+* version 2.3 *
+* *
+* By *
+* Li Wei *
+* Institute of Artificial Intelligence & Robotics *
+* Xi'an Jiaotong University *
+* Email: [email protected] *
+* Web page: http://sun.aiar.xjtu.edu.cn *
+* *
+* July 7th, 1997 *
+***************************************************************
+
+*/
+#if defined( __WIN32__) || defined (WIN32)
+ #include <windows.h>
+#endif
+
+typedef enum VIEW_INDICATOR { FIRST, SECOND};
+
+#define MAXIMUM_DISPLAY_LIST 99
+
+extern GLenum stereoBuffer;
+
+extern GLint displayList;
+
+extern GLint stereo_flag ;
+
+extern GLfloat viewDistance;
+
+extern GLuint viewTag;
+
+extern GLuint displayListBase;
+
+extern GLuint numOfLists;
+
+extern GLenum stereoCompile;
+
+extern GLenum stereoShowing;
+
+extern void glShowStereo(GLuint list);
+
+extern void toggleStereoMode();
+
diff --git a/src/mesa/drivers/windows/wgl.c b/src/mesa/drivers/windows/wgl.c
new file mode 100644
index 00000000000..d5f577dd814
--- /dev/null
+++ b/src/mesa/drivers/windows/wgl.c
@@ -0,0 +1,518 @@
+/* $Id: wgl.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */
+
+/*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Library General Public
+* License as published by the Free Software Foundation; either
+* version 2 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Library General Public License for more details.
+*
+* You should have received a copy of the GNU Library General Public
+* License along with this library; if not, write to the Free
+* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*
+*/
+
+/*
+* File name : wgl.c
+* WGL stuff. Added by Oleg Letsinsky, [email protected]
+* Some things originated from the 3Dfx WGL functions
+*/
+
+#ifdef WIN32
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <windows.h>
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#include <stdio.h>
+#include <tchar.h>
+#include "wmesadef.h"
+#include "GL/wmesa.h"
+#include "types.h"
+
+#define MAX_MESA_ATTRS 20
+
+struct __extensions__
+{
+ PROC proc;
+ char *name;
+};
+
+struct __pixelformat__
+{
+ PIXELFORMATDESCRIPTOR pfd;
+ GLboolean doubleBuffered;
+};
+
+struct __extensions__ ext[] = {
+
+#ifdef GL_EXT_polygon_offset
+ { (PROC)glPolygonOffsetEXT, "glPolygonOffsetEXT" },
+#endif
+ { (PROC)glBlendEquationEXT, "glBlendEquationEXT" },
+ { (PROC)glBlendColorEXT, "glBlendColorExt" },
+ { (PROC)glVertexPointerEXT, "glVertexPointerEXT" },
+ { (PROC)glNormalPointerEXT, "glNormalPointerEXT" },
+ { (PROC)glColorPointerEXT, "glColorPointerEXT" },
+ { (PROC)glIndexPointerEXT, "glIndexPointerEXT" },
+ { (PROC)glTexCoordPointerEXT, "glTexCoordPointer" },
+ { (PROC)glEdgeFlagPointerEXT, "glEdgeFlagPointerEXT" },
+ { (PROC)glGetPointervEXT, "glGetPointervEXT" },
+ { (PROC)glArrayElementEXT, "glArrayElementEXT" },
+ { (PROC)glDrawArraysEXT, "glDrawArrayEXT" },
+ { (PROC)glAreTexturesResidentEXT, "glAreTexturesResidentEXT" },
+ { (PROC)glBindTextureEXT, "glBindTextureEXT" },
+ { (PROC)glDeleteTexturesEXT, "glDeleteTexturesEXT" },
+ { (PROC)glGenTexturesEXT, "glGenTexturesEXT" },
+ { (PROC)glIsTextureEXT, "glIsTextureEXT" },
+ { (PROC)glPrioritizeTexturesEXT, "glPrioritizeTexturesEXT" },
+ { (PROC)glCopyTexSubImage3DEXT, "glCopyTexSubImage3DEXT" },
+ { (PROC)glTexImage3DEXT, "glTexImage3DEXT" },
+ { (PROC)glTexSubImage3DEXT, "glTexSubImage3DEXT" },
+ { (PROC)glColorTableEXT, "glColorTableEXT" },
+ { (PROC)glColorSubTableEXT, "glColorSubTableEXT" },
+ { (PROC)glGetColorTableEXT, "glGetColorTableEXT" },
+ { (PROC)glGetColorTableParameterfvEXT, "glGetColorTableParameterfvEXT" },
+ { (PROC)glGetColorTableParameterivEXT, "glGetColorTableParameterivEXT" },
+ { (PROC)glPointParameterfEXT, "glPointParameterfEXT" },
+ { (PROC)glPointParameterfvEXT, "glPointParameterfvEXT" },
+ { (PROC)glBlendFuncSeparateINGR, "glBlendFuncSeparateINGR" },
+ { (PROC)glLockArraysEXT, "glLockArraysEXT" },
+ { (PROC)glUnlockArraysEXT, "glUnlockArraysEXT" }
+};
+
+int qt_ext = sizeof(ext) / sizeof(ext[0]);
+
+struct __pixelformat__ pix[] =
+{
+ { { sizeof(PIXELFORMATDESCRIPTOR), 1,
+ PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT|PFD_DOUBLEBUFFER|PFD_SWAP_COPY,
+ PFD_TYPE_RGBA,
+ 24, 8, 0, 8, 8, 8, 16, 8, 24,
+ 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
+ GL_TRUE
+ },
+ { { sizeof(PIXELFORMATDESCRIPTOR), 1,
+ PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_FORMAT,
+ PFD_TYPE_RGBA,
+ 24, 8, 0, 8, 8, 8, 16, 8, 24,
+ 0, 0, 0, 0, 0, 16, 8, 0, 0, 0, 0, 0, 0 },
+ GL_FALSE
+ },
+};
+
+int qt_pix = sizeof(pix) / sizeof(pix[0]);
+
+typedef struct {
+ WMesaContext ctx;
+ HDC hdc;
+} MesaWglCtx;
+
+#define MESAWGL_CTX_MAX_COUNT 20
+
+static MesaWglCtx wgl_ctx[MESAWGL_CTX_MAX_COUNT];
+
+static unsigned ctx_count = 0;
+static unsigned ctx_current = -1;
+static unsigned curPFD = 0;
+
+GLAPI BOOL GLWINAPI wglCopyContext(HGLRC hglrcSrc,HGLRC hglrcDst,UINT mask)
+{
+ return(FALSE);
+}
+
+GLAPI HGLRC GLWINAPI wglCreateContext(HDC hdc)
+{
+ HWND hWnd;
+ int i = 0;
+ if(!(hWnd = WindowFromDC(hdc)))
+ {
+ SetLastError(0);
+ return(NULL);
+ }
+ if (!ctx_count)
+ {
+ for(i=0;i<MESAWGL_CTX_MAX_COUNT;i++)
+ {
+ wgl_ctx[i].ctx = NULL;
+ wgl_ctx[i].hdc = NULL;
+ }
+ }
+ for( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
+ {
+ if ( wgl_ctx[i].ctx == NULL )
+ {
+ wgl_ctx[i].ctx = WMesaCreateContext( hWnd, NULL, GL_TRUE,
+ pix[curPFD-1].doubleBuffered );
+ if (wgl_ctx[i].ctx == NULL)
+ break;
+ wgl_ctx[i].hdc = hdc;
+ ctx_count++;
+ return ((HGLRC)wgl_ctx[i].ctx);
+ }
+ }
+ SetLastError(0);
+ return(NULL);
+}
+
+GLAPI BOOL GLWINAPI wglDeleteContext(HGLRC hglrc)
+{
+ int i;
+ for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
+ {
+ if ( wgl_ctx[i].ctx == (PWMC) hglrc )
+ {
+ WMesaMakeCurrent((PWMC) hglrc);
+ WMesaDestroyContext();
+ wgl_ctx[i].ctx = NULL;
+ wgl_ctx[i].hdc = NULL;
+ ctx_count--;
+ return(TRUE);
+ }
+ }
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI HGLRC GLWINAPI wglCreateLayerContext(HDC hdc,int iLayerPlane)
+{
+ SetLastError(0);
+ return(NULL);
+}
+
+GLAPI HGLRC GLWINAPI wglGetCurrentContext(VOID)
+{
+ if (ctx_current < 0)
+ return 0;
+ else
+ return (HGLRC) wgl_ctx[ctx_current].ctx;
+}
+
+GLAPI HDC GLWINAPI wglGetCurrentDC(VOID)
+{
+ if (ctx_current < 0)
+ return 0;
+ else
+ return wgl_ctx[ctx_current].hdc;
+}
+
+GLAPI BOOL GLWINAPI wglMakeCurrent(HDC hdc,HGLRC hglrc)
+{
+ int i;
+
+ /* new code suggested by Andy Sy */
+ if (!hdc || !hglrc) {
+ WMesaMakeCurrent(NULL);
+ ctx_current = -1;
+ return TRUE;
+ }
+
+ for ( i = 0; i < MESAWGL_CTX_MAX_COUNT; i++ )
+ {
+ if ( wgl_ctx[i].ctx == (PWMC) hglrc )
+ {
+ wgl_ctx[i].hdc = hdc;
+ WMesaMakeCurrent( (WMesaContext) hglrc );
+ ctx_current = i;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+GLAPI BOOL GLWINAPI wglShareLists(HGLRC hglrc1,HGLRC hglrc2)
+{
+ return(TRUE);
+}
+
+
+static FIXED FixedFromDouble(double d)
+{
+ long l = (long) (d * 65536L);
+ return *(FIXED *)&l;
+}
+
+
+GLAPI BOOL GLWINAPI wglUseFontBitmapsA(HDC hdc, DWORD first,
+ DWORD count, DWORD listBase)
+{
+ int i;
+ GLuint font_list;
+ DWORD size;
+ GLYPHMETRICS gm;
+ HANDLE hBits;
+ LPSTR lpBits;
+ MAT2 mat;
+
+ if (first<0)
+ return FALSE;
+ if (count<0)
+ return FALSE;
+ if (listBase<0)
+ return FALSE;
+
+ font_list = glGenLists( count );
+ if(font_list == 0)
+ return FALSE;
+
+ mat.eM11 = FixedFromDouble(1);
+ mat.eM12 = FixedFromDouble(0);
+ mat.eM21 = FixedFromDouble(0);
+ mat.eM22 = FixedFromDouble(1);
+
+ memset(&gm,0,sizeof(gm));
+
+ for (i = 0; i < count; i++)
+ {
+ glNewList( font_list+i, GL_COMPILE );
+
+ /* allocate space for the bitmap/outline */
+ size = GetGlyphOutline(hdc, first + i, GGO_BITMAP, &gm, 0, NULL, &mat);
+ if (size == GDI_ERROR)
+ {
+ DWORD err;
+ err = GetLastError();
+ return(FALSE);
+ }
+
+ hBits = GlobalAlloc(GHND, size);
+ lpBits = GlobalLock(hBits);
+
+ GetGlyphOutline(hdc, /* handle to device context */
+ first + i, /* character to query */
+ GGO_BITMAP, /* format of data to return */
+ &gm, /* pointer to structure for metrics */
+ size, /* size of buffer for data */
+ lpBits, /* pointer to buffer for data */
+ &mat /* pointer to transformation */
+ /* matrix structure */
+ );
+
+ if (*lpBits == GDI_ERROR)
+ {
+ DWORD err;
+ err = GetLastError();
+
+ GlobalUnlock(hBits);
+ GlobalFree(hBits);
+
+ return(FALSE);
+ }
+
+ glBitmap(gm.gmBlackBoxX,gm.gmBlackBoxY,
+ gm.gmptGlyphOrigin.x,
+ gm.gmptGlyphOrigin.y,
+ gm.gmCellIncX,gm.gmCellIncY,
+ (const GLubyte * )lpBits);
+
+ GlobalUnlock(hBits);
+ GlobalFree(hBits);
+
+ glEndList( );
+ }
+
+ return TRUE;
+}
+
+GLAPI BOOL GLWINAPI wglUseFontBitmapsW(HDC hdc,DWORD first,DWORD count,DWORD listBase)
+{
+ return FALSE;
+}
+
+GLAPI BOOL GLWINAPI wglUseFontOutlinesA(HDC hdc,DWORD first,DWORD count,
+ DWORD listBase,FLOAT deviation,
+ FLOAT extrusion,int format,
+ LPGLYPHMETRICSFLOAT lpgmf)
+{
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI BOOL GLWINAPI wglUseFontOutlinesW(HDC hdc,DWORD first,DWORD count,
+ DWORD listBase,FLOAT deviation,
+ FLOAT extrusion,int format,
+ LPGLYPHMETRICSFLOAT lpgmf)
+{
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI BOOL GLWINAPI wglDescribeLayerPlane(HDC hdc,int iPixelFormat,
+ int iLayerPlane,UINT nBytes,
+ LPLAYERPLANEDESCRIPTOR plpd)
+{
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI int GLWINAPI wglSetLayerPaletteEntries(HDC hdc,int iLayerPlane,
+ int iStart,int cEntries,
+ CONST COLORREF *pcr)
+{
+ SetLastError(0);
+ return(0);
+}
+
+GLAPI int GLWINAPI wglGetLayerPaletteEntries(HDC hdc,int iLayerPlane,
+ int iStart,int cEntries,
+ COLORREF *pcr)
+{
+ SetLastError(0);
+ return(0);
+}
+
+GLAPI BOOL GLWINAPI wglRealizeLayerPalette(HDC hdc,int iLayerPlane,BOOL bRealize)
+{
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI BOOL GLWINAPI wglSwapLayerBuffers(HDC hdc,UINT fuPlanes)
+{
+ if( !hdc )
+ {
+ WMesaSwapBuffers();
+ return(TRUE);
+ }
+ SetLastError(0);
+ return(FALSE);
+}
+
+GLAPI int GLWINAPI wglChoosePixelFormat(HDC hdc,
+ CONST PIXELFORMATDESCRIPTOR *ppfd)
+{
+ int i,best = -1,bestdelta = 0x7FFFFFFF,delta,qt_valid_pix;
+
+ qt_valid_pix = qt_pix;
+ if(ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR) || ppfd->nVersion != 1)
+ {
+ SetLastError(0);
+ return(0);
+ }
+ for(i = 0;i < qt_valid_pix;i++)
+ {
+ delta = 0;
+ if(
+ (ppfd->dwFlags & PFD_DRAW_TO_WINDOW) &&
+ !(pix[i].pfd.dwFlags & PFD_DRAW_TO_WINDOW))
+ continue;
+ if(
+ (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) &&
+ !(pix[i].pfd.dwFlags & PFD_DRAW_TO_BITMAP))
+ continue;
+ if(
+ (ppfd->dwFlags & PFD_SUPPORT_GDI) &&
+ !(pix[i].pfd.dwFlags & PFD_SUPPORT_GDI))
+ continue;
+ if(
+ (ppfd->dwFlags & PFD_SUPPORT_OPENGL) &&
+ !(pix[i].pfd.dwFlags & PFD_SUPPORT_OPENGL))
+ continue;
+ if(
+ !(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) &&
+ ((ppfd->dwFlags & PFD_DOUBLEBUFFER) != (pix[i].pfd.dwFlags & PFD_DOUBLEBUFFER)))
+ continue;
+ if(
+ !(ppfd->dwFlags & PFD_STEREO_DONTCARE) &&
+ ((ppfd->dwFlags & PFD_STEREO) != (pix[i].pfd.dwFlags & PFD_STEREO)))
+ continue;
+ if(ppfd->iPixelType != pix[i].pfd.iPixelType)
+ delta++;
+ if(delta < bestdelta)
+ {
+ best = i + 1;
+ bestdelta = delta;
+ if(bestdelta == 0)
+ break;
+ }
+ }
+ if(best == -1)
+ {
+ SetLastError(0);
+ return(0);
+ }
+ return(best);
+}
+
+GLAPI int GLWINAPI wglDescribePixelFormat(HDC hdc,int iPixelFormat,UINT nBytes,
+ LPPIXELFORMATDESCRIPTOR ppfd)
+{
+ int qt_valid_pix;
+
+ qt_valid_pix = qt_pix;
+ if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || nBytes != sizeof(PIXELFORMATDESCRIPTOR))
+ {
+ SetLastError(0);
+ return(0);
+ }
+ *ppfd = pix[iPixelFormat - 1].pfd;
+ return(qt_valid_pix);
+}
+
+/*
+* GetProcAddress - return the address of an appropriate extension
+*/
+GLAPI PROC GLWINAPI wglGetProcAddress(LPCSTR lpszProc)
+{
+ int i;
+ for(i = 0;i < qt_ext;i++)
+ if(!strcmp(lpszProc,ext[i].name))
+ return(ext[i].proc);
+
+ SetLastError(0);
+ return(NULL);
+}
+
+GLAPI int GLWINAPI wglGetPixelFormat(HDC hdc)
+{
+ if(curPFD == 0)
+ {
+ SetLastError(0);
+ return(0);
+ }
+ return(curPFD);
+}
+
+GLAPI BOOL GLWINAPI wglSetPixelFormat(HDC hdc,int iPixelFormat,
+ PIXELFORMATDESCRIPTOR *ppfd)
+{
+ int qt_valid_pix;
+
+ qt_valid_pix = qt_pix;
+ if(iPixelFormat < 1 || iPixelFormat > qt_valid_pix || ppfd->nSize != sizeof(PIXELFORMATDESCRIPTOR))
+ {
+ SetLastError(0);
+ return(FALSE);
+ }
+ curPFD = iPixelFormat;
+ return(TRUE);
+}
+
+GLAPI BOOL GLWINAPI wglSwapBuffers(HDC hdc)
+{
+ if (ctx_current < 0)
+ return FALSE;
+
+ if(wgl_ctx[ctx_current].ctx == NULL) {
+ SetLastError(0);
+ return(FALSE);
+ }
+ WMesaSwapBuffers();
+ return(TRUE);
+}
+
+#endif /* WIN32 */
diff --git a/src/mesa/drivers/windows/wing32.def b/src/mesa/drivers/windows/wing32.def
new file mode 100644
index 00000000000..ac8fc1dfb60
--- /dev/null
+++ b/src/mesa/drivers/windows/wing32.def
@@ -0,0 +1,12 @@
+EXPORTS
+ WinGBitBlt@32
+ WinGCreateBitmap@12
+ WinGCreateDC@0
+ WinGCreateHalftoneBrush@12
+ WinGCreateHalftonePalette@0
+ WinGGetDIBColorTable@16
+ WinGGetDIBPointer@8
+ WinGRecommendDIBFormat@4
+ WinGSetDIBColorTable@16
+ WinGStretchBlt@40
+
diff --git a/src/mesa/drivers/windows/wmesa.c b/src/mesa/drivers/windows/wmesa.c
new file mode 100644
index 00000000000..d2c0a56b26f
--- /dev/null
+++ b/src/mesa/drivers/windows/wmesa.c
@@ -0,0 +1,3021 @@
+/* $Id: wmesa.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */
+
+/*
+* File name : wmesa.c
+* Version : 2.3
+*
+* Display driver for Mesa 2.3 under
+* Windows95 and WindowsNT
+*
+* Copyright (C) 1996- Li Wei
+* Address : Institute of Artificial Intelligence
+* : & Robotics
+* : Xi'an Jiaotong University
+* Web page : http://sun.aiar.xjtu.edu.cn
+*
+* This file and its associations are partially borrowed from the
+* Windows NT driver for Mesa 1.8 , written by Mark Leaming
+*/
+
+
+/*
+ * $Log: wmesa.c,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 3.10 1999/06/15 01:35:06 brianp
+ * small change to wmSetPixel() from [email protected]
+ *
+ * Revision 3.9 1999/05/11 19:06:01 brianp
+ * fixed a few VB->Index bugs ([email protected])
+ *
+ * Revision 3.8 1999/05/08 15:15:23 brianp
+ * various updates from [email protected]
+ *
+ * Revision 3.7 1999/04/01 01:27:34 brianp
+ * always flip Y coord in read_rgba_span()
+ *
+ * Revision 3.6 1999/03/28 21:17:27 brianp
+ * updated SetBuffer driver function
+ *
+ * Revision 3.5 1999/03/16 01:36:42 brianp
+ * patched dither() to check if Current is NULL, per [email protected]
+ *
+ * Revision 3.4 1999/02/25 14:12:33 keithw
+ * Merged in kw3 patch
+ *
+ * Revision 3.3 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 3.2 1998/08/29 00:26:01
+ * updated for Mesa 3.0 to accomodate EGCS-Mingw32 build
+ *
+ * Revision 3.1 1998/06/11 01:42:08 brianp
+ * updated for Mesa 3.0 device driver interface (but not tested)
+ *
+ * Revision 3.0 1998/06/11 01:18:25 brianp
+ * initial revision
+ *
+ */
+
+
+#define WMESA_STEREO_C
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/wmesa.h>
+#include "mesa_extend.h"
+#include "colors.h"
+#include "macros.h"
+#include "context.h"
+#include "dd.h"
+#include "xform.h"
+#include "vb.h"
+#include "matrix.h"
+#include "depth.h"
+#include "wmesadef.h"
+
+#pragma warning ( disable : 4133 4761 )
+
+#ifdef PROFILE
+// #include "profile.h"
+#endif
+
+#ifdef DITHER
+#include <wing.h>
+#endif
+
+#ifdef __CYGWIN32__
+#include "macros.h"
+#include <string.h>
+#define CopyMemory memcpy
+#endif
+
+#if !defined(NO_STEREO)
+
+#include "gl\glu.h"
+#include "stereo.h"
+
+#endif
+#if !defined(NO_PARALLEL)
+// #include "parallel.h"
+#endif
+
+struct DISPLAY_OPTIONS displayOptions;
+
+GLenum stereoCompile = GL_FALSE ;
+GLenum stereoShowing = GL_FALSE ;
+GLenum stereoBuffer = GL_FALSE;
+#if !defined(NO_STEREO)
+GLint displayList = MAXIMUM_DISPLAY_LIST ;
+#endif
+GLint stereo_flag = 0 ;
+
+/* end of added code*/
+
+static PWMC Current = NULL;
+WMesaContext WC = NULL;
+
+#ifdef NDEBUG
+#define assert(ignore) ((void) 0)
+#else
+void Mesa_Assert(void *Cond,void *File,unsigned Line)
+{
+ char Msg[512];
+ sprintf(Msg,"%s %s %d",Cond,File,Line);
+ MessageBox(NULL,Msg,"Assertion failed.",MB_OK);
+ exit(1);
+}
+#define assert(e) if (!e) Mesa_Assert(#e,__FILE__,__LINE__);
+#endif
+
+//#define DD_GETDC (Current->hDC )
+#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
+//#define DD_GETDC ((Current->db_flag) ? Current->hDCPrimary : Current->hDCBack )
+#define DD_RELEASEDC
+
+//#define BEGINGDICALL if(Current->rgb_flag)wmFlushBits(Current);
+#define BEGINGDICALL
+//#define ENDGDICALL if(Current->rgb_flag)wmGetBits(Current);
+#define ENDGDICALL
+
+//#define FLIP(Y) (Current->dither_flag? Y : Current->height-(Y)-1)
+//#define FLIP(Y) (Current->height-(Y)-1)
+//#define FLIP(Y) Y
+/*
+ * XXX Why only flip Y coord if single buffered???
+ */
+#define FLIP(Y) (Current->db_flag? Y: Current->height-(Y)-1)
+#define STARTPROFILE
+#define ENDPROFILE(PARA)
+
+#define DITHER_RGB_TO_8BIT_SETUP \
+GLubyte pixelDithered;
+
+#define DITHER_RGB_TO_8BIT(red, green, blue, pixel, scanline) \
+{ \
+ char unsigned redtemp, greentemp, bluetemp, paletteindex; \
+ redtemp = aDividedBy51[red] \
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 \
+ + scanline%8]); \
+ greentemp = aDividedBy51[(char unsigned)green] \
+ + (aModulo51[green] > aHalftone8x8[ \
+ (pixel%8)*8 + scanline%8]); \
+ bluetemp = aDividedBy51[(char unsigned)blue] \
+ + (aModulo51[blue] > aHalftone8x8[ \
+ (pixel%8)*8 +scanline%8]); \
+ paletteindex = redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; \
+ pixelDithered = aWinGHalftoneTranslation[paletteindex]; \
+}
+
+
+#ifdef DDRAW
+static BOOL DDInit( WMesaContext wc, HWND hwnd);
+static void DDFree( WMesaContext wc);
+static HRESULT DDRestoreAll( WMesaContext wc );
+static void DDDeleteOffScreen(WMesaContext wc);
+static BOOL DDCreateOffScreen(WMesaContext wc);
+#endif
+
+static void FlushToFile(PWMC pwc, PSTR szFile);
+
+BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize);
+BOOL wmDeleteBackingStore(PWMC pwc);
+void wmCreatePalette( PWMC pwdc );
+BOOL wmSetDibColors(PWMC pwc);
+void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b);
+
+void wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ );
+
+
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height );
+
+
+static triangle_func choose_triangle_function( GLcontext *ctx );
+
+
+static void wmSetPixelFormat( PWMC wc, HDC hDC)
+{
+ if(wc->rgb_flag)
+ wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
+ else
+ wc->cColorBits = 8;
+ switch(wc->cColorBits){
+ case 8:
+ if(wc->dither_flag != GL_TRUE)
+ wc->pixelformat = PF_INDEX8;
+ else
+ wc->pixelformat = PF_DITHER8;
+ break;
+ case 16:
+ wc->pixelformat = PF_5R6G5B;
+ break;
+ case 32:
+ wc->pixelformat = PF_8R8G8B;
+ break;
+ default:
+ wc->pixelformat = PF_BADFORMAT;
+ }
+}
+
+//
+// This function sets the color table of a DIB section
+// to match that of the destination DC
+//
+BOOL /*WINAPI*/ wmSetDibColors(PWMC pwc)
+{
+ RGBQUAD *pColTab, *pRGB;
+ PALETTEENTRY *pPal, *pPE;
+ int i, nColors;
+ BOOL bRet=TRUE;
+ DWORD dwErr=0;
+
+ /* Build a color table in the DIB that maps to the
+ selected palette in the DC.
+ */
+ nColors = 1 << pwc->cColorBits;
+ pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, nColors * sizeof(PALETTEENTRY) );
+ GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal );
+ pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD));
+ for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) {
+ pRGB->rgbRed = pPE->peRed;
+ pRGB->rgbGreen = pPE->peGreen;
+ pRGB->rgbBlue = pPE->peBlue;
+ }
+ if(pwc->db_flag)
+ bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab );
+
+ if(!bRet)
+ dwErr = GetLastError();
+
+ free( pColTab );
+ free( pPal );
+
+ return(bRet);
+}
+
+
+//
+// Free up the dib section that was created
+//
+BOOL wmDeleteBackingStore(PWMC pwc)
+{
+ SelectObject(pwc->dib.hDC, pwc->hOldBitmap);
+ DeleteDC(pwc->dib.hDC);
+ DeleteObject(pwc->hbmDIB);
+ UnmapViewOfFile(pwc->dib.base);
+ CloseHandle(pwc->dib.hFileMap);
+ return TRUE;
+}
+
+
+//
+// This function creates the DIB section that is used for combined
+// GL and GDI calls
+//
+BOOL /*WINAPI*/ wmCreateBackingStore(PWMC pwc, long lxSize, long lySize)
+{
+ HDC hdc = pwc->hDC;
+ LPBITMAPINFO pbmi = &(pwc->bmi);
+ int iUsage;
+
+ pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->bmiHeader.biWidth = lxSize;
+ pbmi->bmiHeader.biHeight= -lySize;
+ pbmi->bmiHeader.biPlanes = 1;
+ if(pwc->rgb_flag)
+ pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL);
+ else
+ pbmi->bmiHeader.biBitCount = 8;
+ pbmi->bmiHeader.biCompression = BI_RGB;
+ pbmi->bmiHeader.biSizeImage = 0;
+ pbmi->bmiHeader.biXPelsPerMeter = 0;
+ pbmi->bmiHeader.biYPelsPerMeter = 0;
+ pbmi->bmiHeader.biClrUsed = 0;
+ pbmi->bmiHeader.biClrImportant = 0;
+
+ iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS;
+
+ pwc->cColorBits = pbmi->bmiHeader.biBitCount;
+ pwc->ScanWidth = pwc->pitch = lxSize;
+
+ wmCreateDIBSection(hdc, pwc, pbmi, iUsage);
+
+ if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) {
+ wmCreatePalette( pwc );
+ wmSetDibColors( pwc );
+ }
+ wmSetPixelFormat(pwc, pwc->hDC);
+ return(TRUE);
+
+}
+
+
+//
+// This function copies one scan line in a DIB section to another
+//
+BOOL WINAPI wmSetDIBits(PWMC pwc, UINT uiScanWidth, UINT uiNumScans, UINT nBypp, UINT uiNewWidth, LPBYTE pBits)
+{
+ UINT uiScans = 0;
+ LPBYTE pDest = pwc->pbPixels;
+ DWORD dwNextScan = uiScanWidth;
+ DWORD dwNewScan = uiNewWidth;
+ DWORD dwScanWidth = (uiScanWidth * nBypp);
+
+ //
+ // We need to round up to the nearest DWORD
+ // and multiply by the number of bytes per
+ // pixel
+ //
+ dwNextScan = (((dwNextScan * nBypp)+ 3) & ~3);
+ dwNewScan = (((dwNewScan * nBypp)+ 3) & ~3);
+
+ for(uiScans = 0; uiScans < uiNumScans; uiScans++){
+ CopyMemory(pDest, pBits, dwScanWidth);
+ pBits += dwNextScan;
+ pDest += dwNewScan;
+ }
+
+ return(TRUE);
+
+}
+
+
+BOOL wmFlush(PWMC pwc);
+
+/*
+* Useful macros:
+Modified from file osmesa.c
+*/
+
+
+#define PIXELADDR(X,Y) ((GLubyte *)Current->pbPixels + (Current->height-Y-1)* Current->ScanWidth + (X)*nBypp)
+#define PIXELADDR1( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X))
+#define PIXELADDR2( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*2)
+#define PIXELADDR4( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*4)
+
+
+BYTE DITHER_RGB_2_8BIT( int r, int g, int b, int x, int y);
+
+/* Finish all pending operations and synchronize. */
+static void finish(GLcontext* ctx)
+{
+ /* No op */
+}
+
+
+//
+// We cache all gl draw routines until a flush is made
+//
+static void flush(GLcontext* ctx)
+{
+ STARTPROFILE
+ if((Current->rgb_flag /*&& !(Current->dib.fFlushed)*/&&!(Current->db_flag))
+ ||(!Current->rgb_flag))
+ {
+ wmFlush(Current);
+ }
+ ENDPROFILE(flush)
+
+}
+
+
+
+/*
+* Set the color index used to clear the color buffer.
+*/
+static void clear_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->clearpixel = index;
+ ENDPROFILE(clear_index)
+}
+
+
+
+/*
+* Set the color used to clear the color buffer.
+*/
+static void clear_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->clearpixel=RGB(r, g, b );
+ ENDPROFILE(clear_color)
+}
+
+
+
+/*
+* Clear the specified region of the color buffer using the clear color
+* or index as specified by one of the two functions above.
+*/
+//static void clear(GLcontext* ctx,
+// GLboolean all,GLint x, GLint y, GLint width, GLint height )
+// TODO: I modified this function to match the prototype in dd.h. ([email protected])
+// dd.h does not explain what the return type is so I could not set this to the proper
+// value.
+static GLbitfield clear(GLcontext* ctx, GLbitfield mask,
+ GLboolean all, GLint x, GLint y, GLint width, GLint height)
+{
+ DWORD dwColor;
+ WORD wColor;
+ BYTE bColor;
+ LPDWORD lpdw = (LPDWORD)Current->pbPixels;
+ LPWORD lpw = (LPWORD)Current->pbPixels;
+ LPBYTE lpb = Current->pbPixels;
+ int lines;
+
+ STARTPROFILE
+
+ if (all){
+ x=y=0;
+ width=Current->width;
+ height=Current->height;
+ }
+ if(Current->db_flag==GL_TRUE){
+ UINT nBypp = Current->cColorBits / 8;
+ int i = 0;
+ int iSize = 0;
+
+ if(nBypp ==1 ){
+ /* Need rectification */
+ iSize = Current->width/4;
+ bColor = BGR8(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ wColor = MAKEWORD(bColor,bColor);
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ if(nBypp == 2){
+ iSize = Current->width / 2;
+ wColor = BGR16(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ else if(nBypp == 4){
+ iSize = Current->width;
+ dwColor = BGR32(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ }
+
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpdw++;
+ i++;
+ }
+
+ //
+ // This is the 24bit case
+ //
+ if (nBypp == 3) {
+ iSize = Current->width *3/4;
+ dwColor = BGR24(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpb += nBypp;
+ lpdw = (LPDWORD)lpb;
+ i++;
+ }
+ }
+
+ i = 0;
+ if (stereo_flag)
+ lines = height /2;
+ else
+ lines = height;
+ do {
+ memcpy(lpb, Current->pbPixels, iSize*4);
+ lpb += Current->ScanWidth;
+ i++;
+ }
+ while (i<lines-1);
+ }
+ else { // For single buffer
+ HDC DC=DD_GETDC;
+ HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
+ HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
+ HPEN Old_Pen=SelectObject(DC,Pen);
+ HBRUSH Old_Brush=SelectObject(DC,Brush);
+ Rectangle(DC,x,y,x+width,y+height);
+ SelectObject(DC,Old_Pen);
+ SelectObject(DC,Old_Brush);
+ DeleteObject(Pen);
+ DeleteObject(Brush);
+ DD_RELEASEDC;
+ }
+
+
+
+ ENDPROFILE(clear)
+
+ return mask; // TODO: I doubt this is correct. dd.h doesn't explain what this should
+ // be...
+}
+
+
+
+/* Set the current color index. */
+static void set_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->pixel=index;
+ ENDPROFILE(set_index)
+}
+
+
+
+/* Set the current RGBA color. */
+static void set_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->pixel = RGB( r, g, b );
+ ENDPROFILE(set_color)
+}
+
+
+
+/* Set the index mode bitplane mask. */
+static GLboolean index_mask(GLcontext* ctx, GLuint mask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/* Set the RGBA drawing mask. */
+static GLboolean color_mask( GLcontext* ctx,
+ GLboolean rmask, GLboolean gmask,
+ GLboolean bmask, GLboolean amask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/*
+* Set the pixel logic operation. Return GL_TRUE if the device driver
+* can perform the operation, otherwise return GL_FALSE. If GL_FALSE
+* is returned, the logic op will be done in software by Mesa.
+*/
+GLboolean logicop( GLcontext* ctx, GLenum op )
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+static void dither( GLcontext* ctx, GLboolean enable )
+{
+ if (!Current)
+ return;
+
+ if(enable == GL_FALSE){
+ Current->dither_flag = GL_FALSE;
+ if(Current->cColorBits == 8)
+ Current->pixelformat = PF_INDEX8;
+ }
+ else{
+ if (Current->rgb_flag && Current->cColorBits == 8){
+ Current->pixelformat = PF_DITHER8;
+ Current->dither_flag = GL_TRUE;
+ }
+ else
+ Current->dither_flag = GL_FALSE;
+ }
+}
+
+
+
+static GLboolean set_buffer( GLcontext* ctx, GLenum mode )
+{
+ STARTPROFILE
+ /* TODO: this could be better */
+ if (mode==GL_FRONT_LEFT || mode==GL_BACK_LEFT) {
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+ ENDPROFILE(set_buffer)
+}
+
+
+
+/* Return characteristics of the output buffer. */
+static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height )
+{
+ int New_Size;
+ RECT CR;
+
+ STARTPROFILE
+ GetClientRect(Current->Window,&CR);
+
+ *width=CR.right;
+ *height=CR.bottom;
+
+ New_Size=((*width)!=Current->width) || ((*height)!=Current->height);
+
+ if (New_Size){
+ Current->width=*width;
+ Current->height=*height;
+ Current->ScanWidth=Current->width;
+ if ((Current->ScanWidth%sizeof(long))!=0)
+ Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
+
+ if (Current->db_flag){
+#ifdef DDRAW
+ DDDeleteOffScreen(Current);
+ DDCreateOffScreen(Current);
+#else
+ if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){
+ wmDeleteBackingStore(Current);
+ wmCreateBackingStore(Current, Current->width, Current->height);
+ }
+#endif
+ }
+
+ // Resize OsmesaBuffer if in Parallel mode
+#if !defined(NO_PARALLEL)
+ if(parallelFlag)
+ PRSizeRenderBuffer(Current->width, Current->height,Current->ScanWidth,
+ Current->rgb_flag == GL_TRUE ? Current->pbPixels: Current->ScreenMem);
+#endif
+ }
+ ENDPROFILE(buffer_size)
+}
+
+
+
+/**********************************************************************/
+/***** Accelerated point, line, polygon rendering *****/
+/**********************************************************************/
+
+
+static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last )
+{
+ GLuint i;
+ // HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ STARTPROFILE
+
+ if (0 /*Current->gl_ctx->VB->MonoColor*/) {
+ /* all drawn with current color */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ x = (GLint) Current->gl_ctx->VB->Win.data[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win.data[i][1] );
+ wmSetPixel(pwc, y,x,GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ }
+ }
+ else {
+ /* draw points of different colors */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ unsigned long pixel=RGB(Current->gl_ctx->VB->ColorPtr->data[i][0]*255.0,
+ Current->gl_ctx->VB->ColorPtr->data[i][1]*255.0,
+ Current->gl_ctx->VB->ColorPtr->data[i][2]*255.0);
+ x = (GLint) Current->gl_ctx->VB->Win.data[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win.data[i][1] );
+ wmSetPixel(pwc, y,x,Current->gl_ctx->VB->ColorPtr->data[i][0]*255.0,
+ Current->gl_ctx->VB->ColorPtr->data[i][1]*255.0,
+ Current->gl_ctx->VB->ColorPtr->data[i][2]*255.0);
+ }
+ }
+ }
+ // DD_RELEASEDC;
+ ENDPROFILE(fast_rgb_points)
+}
+
+
+
+/* Return pointer to accerated points function */
+extern points_func choose_points_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && ctx->Visual->RGBAflag) {
+ ENDPROFILE(choose_points_function)
+ return fast_rgb_points;
+ }
+ else {
+ ENDPROFILE(choose_points_function)
+ return NULL;
+ }
+}
+
+
+
+/* Draw a line using the color specified by Current->gl_ctx->VB->ColorPtr->data[pv] */
+static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, GLuint v1, GLuint pv )
+{
+ STARTPROFILE
+ int x0, y0, x1, y1;
+ unsigned long pixel;
+ HDC DC=DD_GETDC;
+ HPEN Pen;
+ HPEN Old_Pen;
+
+ if (0 /*Current->gl_ctx->VB->MonoColor*/) {
+ pixel = Current->pixel; /* use current color */
+ }
+ else {
+ pixel = RGB(Current->gl_ctx->VB->ColorPtr->data[pv][0]*255.0, Current->gl_ctx->VB->ColorPtr->data[pv][1]*255.0, Current->gl_ctx->VB->ColorPtr->data[pv][2]*255.0);
+ }
+
+ x0 = (int) Current->gl_ctx->VB->Win.data[v0][0];
+ y0 = FLIP( (int) Current->gl_ctx->VB->Win.data[v0][1] );
+ x1 = (int) Current->gl_ctx->VB->Win.data[v1][0];
+ y1 = FLIP( (int) Current->gl_ctx->VB->Win.data[v1][1] );
+
+
+ BEGINGDICALL
+
+ Pen=CreatePen(PS_SOLID,1,pixel);
+ Old_Pen=SelectObject(DC,Pen);
+ MoveToEx(DC,x0,y0,NULL);
+ LineTo(DC,x1,y1);
+ SelectObject(DC,Old_Pen);
+ DeleteObject(Pen);
+ DD_RELEASEDC;
+
+ ENDGDICALL
+
+ ENDPROFILE(fast_flat_rgb_line)
+}
+
+
+
+/* Return pointer to accerated line function */
+static line_func choose_line_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Line.Width==1.0 && !ctx->Line.SmoothFlag && !ctx->Line.StippleFlag
+ && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && Current->rgb_flag) {
+ ENDPROFILE(choose_line_function)
+ return fast_flat_rgb_line;
+ }
+ else {
+ ENDPROFILE(choose_line_function)
+ return NULL;
+ }
+}
+
+
+/**********************************************************************/
+/***** Span-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write a horizontal span of 32-bit color-index pixels with a boolean mask. */
+static void write_ci32_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLuint index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_ci32_span)
+}
+
+
+/* Write a horizontal span of 8-bit color-index pixels with a boolean mask. */
+static void write_ci8_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_ci8_span)
+}
+
+
+
+/*
+* Write a horizontal span of pixels with a boolean mask. The current
+* color index is used for all pixels.
+*/
+static void write_mono_ci_span(const GLcontext* ctx,
+ GLuint n,GLint x,GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=Current->pixel;
+ ENDPROFILE(write_mono_ci_span)
+}
+
+/*
+ * To improve the performance of this routine, frob the data into an actual
+ * scanline and call bitblt on the complete scan line instead of SetPixel.
+ */
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
+ }
+ DD_RELEASEDC;
+ }
+ else
+ {
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ y = FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ }
+ ENDPROFILE(write_rgba_span)
+
+}
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3], const GLubyte mask[] )
+{
+ STARTPROFILE
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
+ }
+ DD_RELEASEDC;
+ }
+ else
+ {
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ y = FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
+ }
+ }
+ ENDPROFILE(write_rgb_span)
+
+}
+
+/*
+* Write a horizontal span of pixels with a boolean mask. The current color
+* is used for all pixels.
+*/
+static void write_mono_rgba_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+ if(Current->rgb_flag==GL_TRUE){
+ for (i=0; i<n; i++)
+ if (mask[i])
+ // Trying
+ wmSetPixel(pwc,y,x+i,GetRValue(Current->pixel), GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ else {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(DC, y, x+i, Current->pixel);
+ }
+ DD_RELEASEDC;
+ ENDPROFILE(write_mono_rgba_span)
+}
+
+
+
+/**********************************************************************/
+/***** Array-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write an array of 32-bit index pixels with a boolean mask. */
+static void write_ci32_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = index[i];
+ }
+ }
+ ENDPROFILE(write_ci32_pixels)
+}
+
+
+
+/*
+* Write an array of pixels with a boolean mask. The current color
+* index is used for all pixels.
+*/
+static void write_mono_ci_pixels( const GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = Current->pixel;
+ }
+ }
+ ENDPROFILE(write_mono_ci_pixels)
+}
+
+
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]);
+ DD_RELEASEDC;
+ ENDPROFILE(write_rgba_pixels)
+}
+
+
+
+/*
+* Write an array of pixels with a boolean mask. The current color
+* is used for all pixels.
+*/
+static void write_mono_rgba_pixels( const GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ DD_RELEASEDC;
+ ENDPROFILE(write_mono_rgba_pixels)
+}
+
+
+
+/**********************************************************************/
+/***** Read spans/arrays of pixels *****/
+/**********************************************************************/
+
+
+/* Read a horizontal span of color-index pixels. */
+static void read_ci32_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
+ GLuint index[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ index[i]=Mem[i];
+ ENDPROFILE(read_ci32_span)
+}
+
+
+
+
+/* Read an array of color index pixels. */
+static void read_ci32_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint indx[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ indx[i]=*(Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]);
+ }
+ }
+ ENDPROFILE(read_ci32_pixels)
+}
+
+
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ STARTPROFILE
+ UINT i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ /* y=FLIP(y);*/
+ y = Current->height - y - 1;
+ for (i=0; i<n; i++) {
+ Color=GetPixel(DC,x+i,y);
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+ DD_RELEASEDC;
+// Brian P. Has mentioned to comment this out.
+// memset(alpha,0,n*sizeof(GLubyte));
+ ENDPROFILE(read_rgba_span)
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ Color=GetPixel(DC,x[i],FLIP(y[i]));
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+ }
+ DD_RELEASEDC;
+// Brian P. has mentioned to comment this out.
+// memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_rgba_pixels)
+}
+
+
+
+/**********************************************************************/
+/**********************************************************************/
+
+
+static const char *renderer_string(void)
+{
+ return "Windows";
+}
+
+
+
+void setup_DD_pointers( GLcontext* ctx )
+{
+ ctx->Driver.RendererString = renderer_string;
+ ctx->Driver.UpdateState = setup_DD_pointers;
+ ctx->Driver.GetBufferSize = buffer_size;
+ ctx->Driver.Finish = finish;
+ ctx->Driver.Flush = flush;
+
+ ctx->Driver.ClearIndex = clear_index;
+ ctx->Driver.ClearColor = clear_color;
+ ctx->Driver.Clear = clear;
+
+ ctx->Driver.Index = set_index;
+ ctx->Driver.Color = set_color;
+ ctx->Driver.IndexMask = index_mask;
+ ctx->Driver.ColorMask = color_mask;
+
+ ctx->Driver.LogicOp = logicop;
+ ctx->Driver.Dither = dither;
+
+ ctx->Driver.SetBuffer = set_buffer;
+ ctx->Driver.GetBufferSize = buffer_size;
+
+ ctx->Driver.PointsFunc = choose_points_function(ctx);
+ ctx->Driver.LineFunc = choose_line_function(ctx);
+ ctx->Driver.TriangleFunc = choose_triangle_function( ctx );
+
+ /* Pixel/span writing functions: */
+ ctx->Driver.WriteRGBASpan = write_rgba_span;
+ ctx->Driver.WriteRGBSpan = write_rgb_span;
+ ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span;
+ ctx->Driver.WriteRGBAPixels = write_rgba_pixels;
+ ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels;
+ ctx->Driver.WriteCI32Span = write_ci32_span;
+ ctx->Driver.WriteCI8Span = write_ci8_span;
+ ctx->Driver.WriteMonoCISpan = write_mono_ci_span;
+ ctx->Driver.WriteCI32Pixels = write_ci32_pixels;
+ ctx->Driver.WriteMonoCIPixels = write_mono_ci_pixels;
+
+ ctx->Driver.ReadCI32Span = read_ci32_span;
+ ctx->Driver.ReadRGBASpan = read_rgba_span;
+ ctx->Driver.ReadCI32Pixels = read_ci32_pixels;
+ ctx->Driver.ReadRGBAPixels = read_rgba_pixels;
+}
+
+
+/**********************************************************************/
+/***** WMesa API Functions *****/
+/**********************************************************************/
+
+
+
+#define PAL_SIZE 256
+static void GetPalette(HPALETTE Pal,RGBQUAD *aRGB)
+{
+ STARTPROFILE
+ int i;
+ HDC hdc;
+ struct
+ {
+ WORD Version;
+ WORD NumberOfEntries;
+ PALETTEENTRY aEntries[PAL_SIZE];
+ } Palette =
+ {
+ 0x300,
+ PAL_SIZE
+ };
+ hdc=GetDC(NULL);
+ if (Pal!=NULL)
+ GetPaletteEntries(Pal,0,PAL_SIZE,Palette.aEntries);
+ else
+ GetSystemPaletteEntries(hdc,0,PAL_SIZE,Palette.aEntries);
+ if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
+ {
+ for(i = 0; i <PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ Palette.aEntries[255].peRed = 255;
+ Palette.aEntries[255].peGreen = 255;
+ Palette.aEntries[255].peBlue = 255;
+ Palette.aEntries[255].peFlags = 0;
+ Palette.aEntries[0].peRed = 0;
+ Palette.aEntries[0].peGreen = 0;
+ Palette.aEntries[0].peBlue = 0;
+ Palette.aEntries[0].peFlags = 0;
+ }
+ else
+ {
+ int nStaticColors;
+ int nUsableColors;
+ nStaticColors = GetDeviceCaps(hdc, NUMCOLORS)/2;
+ for (i=0; i<nStaticColors; i++)
+ Palette.aEntries[i].peFlags = 0;
+ nUsableColors = PAL_SIZE-nStaticColors;
+ for (; i<nUsableColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (; i<PAL_SIZE-nStaticColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (i=PAL_SIZE-nStaticColors; i<PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = 0;
+ }
+ ReleaseDC(NULL,hdc);
+ for (i=0; i<PAL_SIZE; i++)
+ {
+ aRGB[i].rgbRed=Palette.aEntries[i].peRed;
+ aRGB[i].rgbGreen=Palette.aEntries[i].peGreen;
+ aRGB[i].rgbBlue=Palette.aEntries[i].peBlue;
+ aRGB[i].rgbReserved=Palette.aEntries[i].peFlags;
+ }
+ ENDPROFILE(GetPalette)
+}
+
+
+WMesaContext WMesaCreateContext( HWND hWnd, HPALETTE* Pal,
+ GLboolean rgb_flag,
+ GLboolean db_flag )
+{
+ RECT CR;
+ WMesaContext c;
+ GLboolean true_color_flag;
+ c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context));
+ if (!c)
+ return NULL;
+
+ c->Window=hWnd;
+ c->hDC = GetDC(hWnd);
+ true_color_flag = GetDeviceCaps(c->hDC, BITSPIXEL) > 8;
+#ifdef DDRAW
+ if(true_color_flag) c->rgb_flag = rgb_flag = GL_TRUE;
+#endif
+
+
+#ifdef DITHER
+ if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){
+ c->dither_flag = GL_TRUE;
+ c->hPalHalfTone = WinGCreateHalftonePalette();
+ }
+ else
+ c->dither_flag = GL_FALSE;
+#else
+ c->dither_flag = GL_FALSE;
+#endif
+
+
+ if (rgb_flag==GL_FALSE)
+ {
+ c->rgb_flag = GL_FALSE;
+ // c->pixel = 1;
+ c->db_flag = db_flag =GL_TRUE; // WinG requires double buffering
+ printf("Single buffer is not supported in color index mode, setting to double buffer.\n");
+ }
+ else
+ {
+ c->rgb_flag = GL_TRUE;
+ // c->pixel = 0;
+ }
+ GetClientRect(c->Window,&CR);
+ c->width=CR.right;
+ c->height=CR.bottom;
+ if (db_flag)
+ {
+ c->db_flag = 1;
+ /* Double buffered */
+#ifndef DDRAW
+ // if (c->rgb_flag==GL_TRUE && c->dither_flag != GL_TRUE )
+ {
+ wmCreateBackingStore(c, c->width, c->height);
+
+ }
+#endif
+ }
+ else
+ {
+ /* Single Buffered */
+ if (c->rgb_flag)
+ c->db_flag = 0;
+ }
+#ifdef DDRAW
+ if (DDInit(c,hWnd) == GL_FALSE) {
+ free( (void *) c );
+ exit(1);
+ }
+#endif
+
+
+ c->gl_visual = gl_create_visual(rgb_flag,
+ GL_FALSE, /* software alpha */
+ db_flag, /* db_flag */
+ GL_FALSE, /* stereo */
+ 16, /* depth_bits */
+ 8, /* stencil_bits */
+ 8, /* accum_bits */
+ 0, /* index bits */
+ 8,8,8,8 ); /* r, g, b, a bits */
+
+ if (!c->gl_visual) {
+ return NULL;
+ }
+
+ /* allocate a new Mesa context */
+ c->gl_ctx = gl_create_context( c->gl_visual, NULL, c, GL_TRUE);
+
+ if (!c->gl_ctx) {
+ gl_destroy_visual( c->gl_visual );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_buffer = gl_create_framebuffer( c->gl_visual );
+ if (!c->gl_buffer) {
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_context( c->gl_ctx );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_ctx->Driver.UpdateState = setup_DD_pointers;
+
+ // setup_DD_pointers(c->gl_ctx);
+
+ return c;
+}
+
+void WMesaDestroyContext( void )
+{
+ WMesaContext c = Current;
+ ReleaseDC(c->Window,c->hDC);
+ WC = c;
+ if(c->hPalHalfTone != NULL)
+ DeleteObject(c->hPalHalfTone);
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_framebuffer( c->gl_buffer );
+ gl_destroy_context( c->gl_ctx );
+
+ if (c->db_flag)
+#ifdef DDRAW
+ DDFree(c);
+#else
+ wmDeleteBackingStore(c);
+#endif
+ free( (void *) c );
+ //Following code is added to enable parallel render
+ // Parallel render only work in double buffer mode
+#if !defined(NO_PARALLEL)
+ if(parallelMachine)
+ PRDestroyRenderBuffer();
+#endif
+ // End modification
+}
+
+
+
+void /*APIENTRY*/ WMesaMakeCurrent( WMesaContext c )
+{
+ if(!c){
+ Current = c;
+ return;
+ }
+
+ //
+ // A little optimization
+ // If it already is current,
+ // don't set it again
+ //
+ if(Current == c)
+ return;
+
+ //gl_set_context( c->gl_ctx );
+ gl_make_current(c->gl_ctx, c->gl_buffer);
+ setup_DD_pointers(c->gl_ctx);
+ Current = c;
+ if (Current->gl_ctx->Viewport.Width==0) {
+ /* initialize viewport to window size */
+ gl_Viewport( Current->gl_ctx,
+ 0, 0, Current->width, Current->height );
+ }
+ if ((c->cColorBits <= 8 ) && (c->rgb_flag == GL_TRUE)){
+ WMesaPaletteChange(c->hPalHalfTone);
+ }
+}
+
+
+
+void /*APIENTRY*/ WMesaSwapBuffers( void )
+{
+ HDC DC = Current->hDC;
+ if (Current->db_flag)
+ wmFlush(Current);
+}
+
+
+
+void /*APIENTRY*/ WMesaPaletteChange(HPALETTE Pal)
+{
+ int vRet;
+ LPPALETTEENTRY pPal;
+ if (Current && (Current->rgb_flag==GL_FALSE || Current->dither_flag == GL_TRUE))
+ {
+ pPal = (PALETTEENTRY *)malloc( 256 * sizeof(PALETTEENTRY));
+ Current->hPal=Pal;
+ // GetPaletteEntries( Pal, 0, 256, pPal );
+ GetPalette( Pal, pPal );
+#ifdef DDRAW
+ Current->lpDD->lpVtbl->CreatePalette(Current->lpDD,DDPCAPS_8BIT,
+ pPal, &(Current->lpDDPal), NULL);
+ if (Current->lpDDPal)
+ Current->lpDDSPrimary->lpVtbl->SetPalette(Current->lpDDSPrimary,Current->lpDDPal);
+#else
+ vRet = SetDIBColorTable(Current->dib.hDC,0,256,pPal);
+#endif
+ free( pPal );
+ }
+
+}
+
+
+
+
+static unsigned char threeto8[8] = {
+ 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
+};
+
+static unsigned char twoto8[4] = {
+ 0, 0x55, 0xaa, 0xff
+};
+
+static unsigned char oneto8[2] = {
+ 0, 255
+};
+
+static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift)
+{
+ unsigned char val;
+
+ val = i >> shift;
+ switch (nbits) {
+
+ case 1:
+ val &= 0x1;
+ return oneto8[val];
+
+ case 2:
+ val &= 0x3;
+ return twoto8[val];
+
+ case 3:
+ val &= 0x7;
+ return threeto8[val];
+
+ default:
+ return 0;
+ }
+}
+
+void /*WINAPI*/ wmCreatePalette( PWMC pwdc )
+{
+ /* Create a compressed and re-expanded 3:3:2 palette */
+ int i;
+ LOGPALETTE *pPal;
+ BYTE rb, rs, gb, gs, bb, bs;
+
+ pwdc->nColors = 0x100;
+
+ pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) );
+
+ pPal->palVersion = 0x300;
+
+ rb = REDBITS;
+ rs = REDSHIFT;
+ gb = GREENBITS;
+ gs = GREENSHIFT;
+ bb = BLUEBITS;
+ bs = BLUESHIFT;
+
+ if (pwdc->db_flag) {
+
+ /* Need to make two palettes: one for the screen DC and one for the DIB. */
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ pwdc->hPalette = CreatePalette( pPal );
+ }
+
+ else {
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ }
+
+ free(pPal);
+
+}
+
+void /*WINAPI*/ wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
+{
+ if (Current->db_flag) {
+ LPBYTE lpb = pwc->pbPixels;
+ LPDWORD lpdw;
+ LPWORD lpw;
+ UINT nBypp = pwc->cColorBits >> 3;
+ UINT nOffset = iPixel % nBypp;
+
+ // Move the pixel buffer pointer to the scanline that we
+ // want to access
+
+ // pwc->dib.fFlushed = FALSE;
+
+ lpb += pwc->ScanWidth * iScanLine;
+ // Now move to the desired pixel
+ lpb += iPixel * nBypp;
+ lpb = PIXELADDR(iPixel, iScanLine);
+ lpdw = (LPDWORD)lpb;
+ lpw = (LPWORD)lpb;
+
+ if(nBypp == 1){
+ if(pwc->dither_flag)
+ *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
+ else
+ *lpb = BGR8(r,g,b);
+ }
+ else if(nBypp == 2)
+ *lpw = BGR16(r,g,b);
+ else if (nBypp == 3){
+ *lpdw = BGR24(r,g,b);
+ }
+ else if (nBypp == 4)
+ *lpdw = BGR32(r,g,b);
+ }
+ else{
+ SetPixel(Current->hDC, iPixel, iScanLine, RGB(r,g,b));
+ DD_RELEASEDC;
+ }
+}
+
+void /*WINAPI*/ wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ )
+{
+ DWORD dwSize = 0;
+ DWORD dwScanWidth;
+ UINT nBypp = pwc->cColorBits / 8;
+ HDC hic;
+
+ dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3);
+
+ pwc->ScanWidth =pwc->pitch = dwScanWidth;
+
+ if (stereo_flag)
+ pwc->ScanWidth = 2* pwc->pitch;
+
+ dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height);
+
+ pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE,
+ NULL,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0,
+ dwSize,
+ NULL);
+
+ if (!pwc->dib.hFileMap)
+ return;
+
+ pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap,
+ FILE_MAP_ALL_ACCESS,
+ 0,
+ 0,
+ 0);
+
+ if(!pwc->dib.base){
+ CloseHandle(pwc->dib.hFileMap);
+ return;
+ }
+
+ // pwc->pbPixels = pwc->addrOffScreen = ((LPBYTE)pwc->dib.base) + sizeof(BITMAPINFO);
+
+ // pwc->dib.hDC = CreateCompatibleDC(hDC);
+
+ CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO));
+
+ hic = CreateIC("display", NULL, NULL, NULL);
+ pwc->dib.hDC = CreateCompatibleDC(hic);
+
+
+ /* pwc->hbmDIB = CreateDIBitmap(hic,
+ &(pwc->bmi.bmiHeader),
+ CBM_INIT,
+ pwc->pbPixels,
+ &(pwc->bmi),
+ DIB_RGB_COLORS);
+ */
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS),
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ /*
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ DIB_RGB_COLORS,
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ */
+ pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels;
+ pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB);
+
+ DeleteDC(hic);
+
+ return;
+
+}
+
+//
+// Blit memory DC to screen DC
+//
+BOOL /*WINAPI*/ wmFlush(PWMC pwc)
+{
+ BOOL bRet = 0;
+ DWORD dwErr = 0;
+#ifdef DDRAW
+ HRESULT ddrval;
+#endif
+
+ // Now search through the torus frames and mark used colors
+ if(pwc->db_flag){
+#ifdef DDRAW
+ if (pwc->lpDDSOffScreen == NULL)
+ if(DDCreateOffScreen(pwc) == GL_FALSE)
+ return;
+
+ pwc->lpDDSOffScreen->lpVtbl->Unlock(pwc->lpDDSOffScreen, NULL);
+
+ while( 1 )
+ {
+ ddrval = pwc->lpDDSPrimary->lpVtbl->Blt( pwc->lpDDSPrimary,
+ &(pwc->rectSurface), pwc->lpDDSOffScreen, &(pwc->rectOffScreen), 0, NULL );
+
+ if( ddrval == DD_OK )
+ {
+ break;
+ }
+ if( ddrval == DDERR_SURFACELOST )
+ {
+ if(!DDRestoreAll(pwc))
+ {
+ break;
+ }
+ }
+ if( ddrval != DDERR_WASSTILLDRAWING )
+ {
+ break;
+ }
+ }
+
+ while (pwc->lpDDSOffScreen->lpVtbl->Lock(pwc->lpDDSOffScreen,
+ NULL, &(pwc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+
+ if(ddrval != DD_OK)
+ dwErr = GetLastError();
+#else
+ bRet = BitBlt(pwc->hDC, 0, 0, pwc->width, pwc->height,
+ pwc->dib.hDC, 0, 0, SRCCOPY);
+#endif
+ }
+
+ return(TRUE);
+
+}
+
+
+// The following code is added by Li Wei to enable stereo display
+
+#if !defined(NO_STEREO)
+
+void WMesaShowStereo(GLuint list)
+{
+
+ GLbitfield mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
+ GLfloat cm[16];
+ GLint matrix_mode;
+ // Must use double Buffer
+ if( ! Current-> db_flag )
+ return;
+
+
+ glGetIntegerv(GL_MATRIX_MODE,&matrix_mode);
+
+ // glPushMatrix(); //****
+ WMesaViewport(Current->gl_ctx,0,Current->height/2,Current->width,Current->height/2);
+ // Current->gl_ctx->NewState = 0;
+
+ // glViewport(0,0,Current->width,Current->height/2);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(GL_MODELVIEW);
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(viewDistance/2,0.0,0.0 ,
+ viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ // glTranslatef(viewDistance/2.0,0.,0.);
+ glMultMatrixf( cm );
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen;
+ //glPushMatrix();
+ glCallList( list );
+ //glPopMatrix();
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(-viewDistance/2,0.0,0.0 ,
+ -viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ // glTranslatef(-viewDistance/2.0,0.,0.);
+ glMultMatrixf(cm);
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen + Current->pitch;
+ glCallList(list);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(matrix_mode);
+
+ // glPopMatrix();
+ glFlush();
+
+ WMesaViewport(Current->gl_ctx,0,0,Current->width,Current->height);
+ // Current->gl_ctx->NewState = 0;
+ WMesaSwapBuffers();
+
+}
+
+void toggleStereoMode()
+{
+ if(!Current->db_flag)
+ return;
+ if(!stereo_flag){
+ stereo_flag = 1;
+ if(stereoBuffer==GL_FALSE)
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ {
+ Current->ScanWidth = Current->pitch*2;
+ }
+ }
+ else {
+ stereo_flag = 0;
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ Current->ScanWidth = Current->pitch;
+ Current->pbPixels = Current->addrOffScreen;
+ }
+}
+
+/* if in stereo mode, the following function is called */
+void glShowStereo(GLuint list)
+{
+ WMesaShowStereo(list);
+}
+
+#endif // End if NO_STEREO not defined
+
+#if !defined(NO_PARALLEL)
+
+void toggleParallelMode(void)
+{
+ if(!parallelFlag){
+ parallelFlag = GL_TRUE;
+ if(parallelMachine==GL_FALSE){
+ PRCreateRenderBuffer( Current->rgb_flag? GL_RGBA :GL_COLOR_INDEX,
+ Current->cColorBits/8,
+ Current->width ,Current->height,
+ Current->ScanWidth,
+ Current->rgb_flag? Current->pbPixels: Current->ScreenMem);
+ parallelMachine = GL_TRUE;
+ }
+ }
+ else {
+ parallelFlag = GL_FALSE;
+ if(parallelMachine==GL_TRUE){
+ PRDestroyRenderBuffer();
+ parallelMachine=GL_FALSE;
+ ReadyForNextFrame = GL_TRUE;
+ }
+
+ /***********************************************
+ // Seems something wrong!!!!
+ ************************************************/
+
+ WMesaMakeCurrent(Current);
+#if !defined(NO_STEREO)
+ stereo_flag = GL_FALSE ;
+#endif
+ }
+}
+
+void PRShowRenderResult(void)
+{
+ int flag = 0;
+ if(!glImageRendered())
+ return;
+
+ if (parallelFlag)
+ {
+ WMesaSwapBuffers();
+ }
+
+}
+#endif //End if NO_PARALLEL not defined
+
+//end modification
+
+BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline)
+{
+ char unsigned redtemp, greentemp, bluetemp, paletteindex;
+
+ //*** now, look up each value in the halftone matrix
+ //*** using an 8x8 ordered dither.
+ redtemp = aDividedBy51[red]
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8
+ + scanline%8]);
+ greentemp = aDividedBy51[(char unsigned)green]
+ + (aModulo51[green] > aHalftone8x8[
+ (pixel%8)*8 + scanline%8]);
+ bluetemp = aDividedBy51[(char unsigned)blue]
+ + (aModulo51[blue] > aHalftone8x8[
+ (pixel%8)*8 +scanline%8]);
+
+ //*** recombine the halftoned rgb values into a palette index
+ paletteindex =
+ redtemp + aTimes6[greentemp] + aTimes36[bluetemp];
+
+ //*** and translate through the wing halftone palette
+ //*** translation vector to give the correct value.
+ return aWinGHalftoneTranslation[paletteindex];
+}
+
+#ifdef DDRAW
+/*
+* restoreAll
+*
+* restore all lost objects
+*/
+HRESULT DDRestoreAll( WMesaContext wc )
+{
+ HRESULT ddrval;
+
+ ddrval = wc->lpDDSPrimary->lpVtbl->Restore(wc->lpDDSPrimary);
+ if( ddrval == DD_OK )
+ {
+ ddrval = wc->lpDDSOffScreen->lpVtbl->Restore(wc->lpDDSOffScreen);
+ }
+ return ddrval;
+
+} /* restoreAll */
+
+
+ /*
+ * This function is called if the initialization function fails
+*/
+BOOL initFail( HWND hwnd, WMesaContext wc )
+{
+ DDFree(wc);
+ MessageBox( hwnd, "DirectDraw Init FAILED", "", MB_OK );
+ return FALSE;
+
+} /* initFail */
+
+
+static void DDDeleteOffScreen(WMesaContext wc)
+{
+ if( wc->lpDDSOffScreen != NULL )
+ {
+ wc->lpDDSOffScreen->lpVtbl->Unlock(wc->lpDDSOffScreen,NULL);
+ wc->lpDDSOffScreen->lpVtbl->Release(wc->lpDDSOffScreen);
+ wc->lpDDSOffScreen = NULL;
+ }
+
+}
+
+static void DDFreePrimarySurface(WMesaContext wc)
+{
+ if( wc->lpDDSPrimary != NULL )
+ {
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->ReleaseDC(wc->lpDDSPrimary, wc->hDC);
+ wc->lpDDSPrimary->lpVtbl->Release(wc->lpDDSPrimary);
+ wc->lpDDSPrimary = NULL;
+ }
+}
+
+static BOOL DDCreatePrimarySurface(WMesaContext wc)
+{
+ HRESULT ddrval;
+ DDSCAPS ddscaps;
+ wc->ddsd.dwSize = sizeof( wc->ddsd );
+ wc->ddsd.dwFlags = DDSD_CAPS;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD,&(wc->ddsd), &(wc->lpDDSPrimary), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(wc->hwnd , wc);
+ }
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->GetDC(wc->lpDDSPrimary, wc->hDC);
+ return TRUE;
+}
+
+static BOOL DDCreateOffScreen(WMesaContext wc)
+{
+ POINT pt;
+ HRESULT ddrval;
+ if(wc->lpDD == NULL)
+ return FALSE;
+ GetClientRect( wc->hwnd, &(wc->rectOffScreen) );
+ wc->ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
+ wc->ddsd.dwHeight = wc->rectOffScreen.bottom - wc->rectOffScreen.top;
+ wc->ddsd.dwWidth = wc->rectOffScreen.right - wc->rectOffScreen.left;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD, &(wc->ddsd), &(wc->lpDDSOffScreen), NULL );
+ if( ddrval != DD_OK )
+ {
+ return FALSE;
+ }
+
+ while (wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+ // while ((ddrval = wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), DDLOCK_SURFACEMEMORYPTR , NULL)) != DD_OK)
+ ;
+ if(wc->ddsd.lpSurface==NULL)
+ return initFail(wc->hwnd, wc);
+
+ wc->ScreenMem = wc->pbPixels = wc->addrOffScreen = (PBYTE)(wc->ddsd.lpSurface);
+ wc->ScanWidth = wc->pitch = wc->ddsd.lPitch;
+ if (stereo_flag)
+ wc->ScanWidth = wc->ddsd.lPitch*2;
+
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ wmSetPixelFormat(wc, wc->hDC);
+ return TRUE;
+}
+
+/*
+* doInit - do work required for every instance of the application:
+* create the window, initialize data
+*/
+static BOOL DDInit( WMesaContext wc, HWND hwnd)
+{
+ HRESULT ddrval;
+ DWORD dwFrequency;
+
+ LPDIRECTDRAW lpDD; // DirectDraw object
+ LPDIRECTDRAW2 lpDD2;
+
+
+ wc->fullScreen = displayOptions.fullScreen;
+ wc->gMode = displayOptions.mode;
+ wc->hwnd = hwnd;
+ stereo_flag = displayOptions.stereo;
+ if(wc->db_flag!= GL_TRUE)
+ stereo_flag = GL_FALSE;
+ /*
+ * create the main DirectDraw object
+ */
+ ddrval = DirectDrawCreate( NULL, &(wc->lpDD), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd,wc);
+ }
+
+ // Get exclusive mode if requested
+ if(wc->fullScreen)
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
+ }
+ else
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_NORMAL );
+ }
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd , wc);
+ }
+
+
+ /* ddrval = wc->lpDD->lpVtbl->QueryInterface(wc->lpDD, IID_IDirectDraw2,
+ (LPVOID *)((wc->lpDD2)));
+
+ */
+ if(ddrval != DD_OK)
+ return initFail(hwnd , wc);
+
+
+ //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+ // wc->lpDD2->lpVtbl->GetMonitorFrequency(wc->lpDD, &dwFrequency);
+ switch( wc->gMode )
+ {
+ case 1: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 640, 480, displayOptions.bpp); break;
+ case 2: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 800, 600, displayOptions.bpp); break;
+ case 3: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1024, 768, displayOptions.bpp); break;
+ case 4: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1152, 864, displayOptions.bpp); break;
+ case 5: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1280, 1024, displayOptions.bpp); break;
+ }
+
+ if( ddrval != DD_OK )
+ {
+ printf("Can't modify display mode, current mode used\n");
+ // return initFail(hwnd , wc);
+ }
+ //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+ switch(ddrval){
+ case DDERR_INVALIDOBJECT:
+ break;
+ case DDERR_INVALIDPARAMS:
+ break;
+ case DDERR_UNSUPPORTEDMODE:
+ ;
+ }
+
+ if(DDCreatePrimarySurface(wc) == GL_FALSE)
+ return initFail(hwnd, wc);
+
+ if(wc->db_flag)
+ return DDCreateOffScreen(wc);
+} /* DDInit */
+
+static void DDFree( WMesaContext wc)
+{
+ if( wc->lpDD != NULL )
+ {
+ DDFreePrimarySurface(wc);
+ DDDeleteOffScreen(wc);
+ wc->lpDD->lpVtbl->Release(wc->lpDD);
+ wc->lpDD = NULL;
+ }
+ // Clean up the screen on exit
+ RedrawWindow( NULL, NULL, NULL, RDW_INVALIDATE | RDW_ERASE |
+ RDW_ALLCHILDREN );
+
+}
+#endif
+
+void WMesaMove(void)
+{
+ WMesaContext wc = Current;
+ POINT pt;
+ if (Current != NULL){
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ }
+}
+
+
+
+/*
+* Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
+* shortcut.
+*/
+#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
+
+
+/**********************************************************************/
+/*** Triangle rendering ***/
+/**********************************************************************/
+
+/*
+ * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, smooth, depth-buffered, PF_8R8G8B triangle.
+*/
+static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+
+/*
+* XImage, smooth, depth-buffered, PF_5R6G5B triangle.
+*/
+static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+/*
+* XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, PF_8R8G8B triangle.
+*/
+static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, PF_5R6G5B triangle.
+*/
+static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
+*/
+static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
+*/
+static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
+*/
+static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
+*/
+static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void smooth_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = FixedToInt(ffi); \
+ zRow[i] = z; \
+ } \
+ ffi += fdidx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void flat_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->IndexPtr->data[pv]; \
+ (*ctx->Driver.Index)( ctx, index );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = index; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+
+/*
+* XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void smooth_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = FixedToInt(ffi); \
+ ffi += fdidx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+static void flat_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->IndexPtr->data[pv]; \
+ (*ctx->Driver.Index)( ctx, index );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = index; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+/*
+* XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
+*/
+static void smooth_DITHER8_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb), xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+/*
+* XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
+*/
+static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+/*
+* XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
+*/
+static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], xx, yy);\
+ *pixel = pixelDithered; \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+/*
+* XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
+*/
+
+static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->ColorPtr->data[pv][0], \
+ VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2], xx, yy); \
+ *pixel = pixelDithered; \
+ } \
+ }
+#ifdef __MINGW32__
+ #include "tritemp.h"
+#else
+
+ #ifdef WIN32
+ #include "..\tritemp.h"
+ #else
+ #include "tritemp.h"
+ #endif
+#endif
+}
+
+
+
+
+static triangle_func choose_triangle_function( GLcontext *ctx )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ int depth = wmesa->cColorBits;
+
+ if (ctx->Polygon.SmoothFlag) return NULL;
+ if (ctx->Texture.Enabled) return NULL;
+ if (!wmesa->db_flag) return NULL;
+ /*if (wmesa->xm_buffer->buffer==XIMAGE)*/ {
+ if ( ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return smooth_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->Light.ShadeModel==GL_FLAT
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return flat_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_triangle;
+ case PF_INDEX8:
+ return smooth_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_FLAT
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_triangle;
+ case PF_INDEX8:
+ return flat_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ return NULL;
+ }
+}
+
+/*
+* Define a new viewport and reallocate auxillary buffers if the size of
+* the window (color buffer) has changed.
+*/
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ /* Save viewport */
+ ctx->Viewport.X = x;
+ ctx->Viewport.Width = width;
+ ctx->Viewport.Y = y;
+ ctx->Viewport.Height = height;
+
+ /* compute scale and bias values */
+/* Pre-Keith 3.1 changes
+ ctx->Viewport.Map.m[Sx] = (GLfloat) width / 2.0F;
+ ctx->Viewport.Map.m[Tx] = ctx->Viewport.Sx + x;
+ ctx->Viewport.Map.m[Sy] = (GLfloat) height / 2.0F;
+ ctx->Viewport.Map.m[Ty] = ctx->Viewport.Sy + y;
+*/
+ ctx->Viewport.WindowMap.m[MAT_SX] = (GLfloat) width / 2.0F;
+ ctx->Viewport.WindowMap.m[MAT_TX] = ctx->Viewport.WindowMap.m[MAT_SX] + x;
+ ctx->Viewport.WindowMap.m[MAT_SY] = (GLfloat) height / 2.0F;
+ ctx->Viewport.WindowMap.m[MAT_TY] = ctx->Viewport.WindowMap.m[MAT_SY] + y;
+}
diff --git a/src/mesa/drivers/windows/wmesaBackup.c b/src/mesa/drivers/windows/wmesaBackup.c
new file mode 100644
index 00000000000..57269fbadb0
--- /dev/null
+++ b/src/mesa/drivers/windows/wmesaBackup.c
@@ -0,0 +1,2879 @@
+/* $Id: wmesaBackup.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */
+
+/*
+* File name : wmesa.c
+* Version : 2.3
+*
+* Display driver for Mesa 2.3 under
+* Windows95 and WindowsNT
+*
+* Copyright (C) 1996- Li Wei
+* Address : Institute of Artificial Intelligence
+* : & Robotics
+* : Xi'an Jiaotong University
+* Web page : http://sun.aiar.xjtu.edu.cn
+*
+* This file and its associations are partially borrowed from the
+* Windows NT driver for Mesa 1.8 , written by Mark Leaming
+*/
+
+
+/*
+ * $Log: wmesaBackup.c,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.1 1999/01/03 03:08:57 brianp
+ * Initial revision
+ *
+ * Revision 3.1 1998/06/11 01:42:08 brianp
+ * updated for Mesa 3.0 device driver interface (but not tested)
+ *
+ * Revision 3.0 1998/06/11 01:18:25 brianp
+ * initial revision
+ *
+ */
+
+
+#define WMESA_STEREO_C
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/wmesa.h>
+#include "mesa_extend.h"
+#include "colors.h"
+#include "macros.h"
+#include "context.h"
+#include "dd.h"
+#include "xform.h"
+#include "vb.h"
+#include "matrix.h"
+#include "depth.h"
+#include "wmesadef.h"
+
+#pragma warning ( disable : 4133 4761 )
+
+#ifdef PROFILE
+// #include "profile.h"
+#endif
+
+#ifdef DITHER
+#include <wing.h>
+#endif
+
+#ifdef __CYGWIN32__
+#include "macros.h"
+#include <string.h>
+#define CopyMemory memcpy
+#endif
+
+#if !defined(NO_STEREO)
+
+#include "gl\glu.h"
+#include "stereo.h"
+
+#endif
+#if !defined(NO_PARALLEL)
+// #include "parallel.h"
+#endif
+
+struct DISPLAY_OPTIONS displayOptions;
+
+GLenum stereoCompile = GL_FALSE ;
+GLenum stereoShowing = GL_FALSE ;
+GLenum stereoBuffer = GL_FALSE;
+#if !defined(NO_STEREO)
+GLint displayList = MAXIMUM_DISPLAY_LIST ;
+#endif
+GLint stereo_flag = 0 ;
+
+/* end of added code*/
+
+static PWMC Current = NULL;
+WMesaContext WC = NULL;
+
+#ifdef NDEBUG
+#define assert(ignore) ((void) 0)
+#else
+void Mesa_Assert(void *Cond,void *File,unsigned Line)
+{
+ char Msg[512];
+ sprintf(Msg,"%s %s %d",Cond,File,Line);
+ MessageBox(NULL,Msg,"Assertion failed.",MB_OK);
+ exit(1);
+}
+#define assert(e) if (!e) Mesa_Assert(#e,__FILE__,__LINE__);
+#endif
+
+//#define DD_GETDC (Current->hDC )
+#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
+//#define DD_GETDC ((Current->db_flag) ? Current->hDCPrimary : Current->hDCBack )
+#define DD_RELEASEDC
+
+//#define BEGINGDICALL if(Current->rgb_flag)wmFlushBits(Current);
+#define BEGINGDICALL
+//#define ENDGDICALL if(Current->rgb_flag)wmGetBits(Current);
+#define ENDGDICALL
+
+//#define FLIP(Y) (Current->dither_flag? Y : Current->height-(Y)-1)
+//#define FLIP(Y) (Current->height-(Y)-1)
+//#define FLIP(Y) Y
+#define FLIP(Y) (Current->db_flag? Y: Current->height-(Y)-1)
+#define STARTPROFILE
+#define ENDPROFILE(PARA)
+
+#define DITHER_RGB_TO_8BIT_SETUP \
+GLubyte pixelDithered;
+
+#define DITHER_RGB_TO_8BIT(red, green, blue, pixel, scanline) \
+{ \
+ char unsigned redtemp, greentemp, bluetemp, paletteindex; \
+ redtemp = aDividedBy51[red] \
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 \
+ + scanline%8]); \
+ greentemp = aDividedBy51[(char unsigned)green] \
+ + (aModulo51[green] > aHalftone8x8[ \
+ (pixel%8)*8 + scanline%8]); \
+ bluetemp = aDividedBy51[(char unsigned)blue] \
+ + (aModulo51[blue] > aHalftone8x8[ \
+ (pixel%8)*8 +scanline%8]); \
+ paletteindex = redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; \
+ pixelDithered = aWinGHalftoneTranslation[paletteindex]; \
+}
+
+
+#ifdef DDRAW
+static BOOL DDInit( WMesaContext wc, HWND hwnd);
+static void DDFree( WMesaContext wc);
+static HRESULT DDRestoreAll( WMesaContext wc );
+static void DDDeleteOffScreen(WMesaContext wc);
+static BOOL DDCreateOffScreen(WMesaContext wc);
+#endif
+
+static void FlushToFile(PWMC pwc, PSTR szFile);
+
+BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize);
+BOOL wmDeleteBackingStore(PWMC pwc);
+void wmCreatePalette( PWMC pwdc );
+BOOL wmSetDibColors(PWMC pwc);
+void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b);
+
+void wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ );
+
+
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height );
+
+
+static triangle_func choose_triangle_function( GLcontext *ctx );
+
+
+static void wmSetPixelFormat( PWMC wc, HDC hDC)
+{
+ if(wc->rgb_flag)
+ wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
+ else
+ wc->cColorBits = 8;
+ switch(wc->cColorBits){
+ case 8:
+ if(wc->dither_flag != GL_TRUE)
+ wc->pixelformat = PF_INDEX8;
+ else
+ wc->pixelformat = PF_DITHER8;
+ break;
+ case 16:
+ wc->pixelformat = PF_5R6G5B;
+ break;
+ case 32:
+ wc->pixelformat = PF_8R8G8B;
+ break;
+ default:
+ wc->pixelformat = PF_BADFORMAT;
+ }
+}
+
+//
+// This function sets the color table of a DIB section
+// to match that of the destination DC
+//
+BOOL /*WINAPI*/ wmSetDibColors(PWMC pwc)
+{
+ RGBQUAD *pColTab, *pRGB;
+ PALETTEENTRY *pPal, *pPE;
+ int i, nColors;
+ BOOL bRet=TRUE;
+ DWORD dwErr=0;
+
+ /* Build a color table in the DIB that maps to the
+ selected palette in the DC.
+ */
+ nColors = 1 << pwc->cColorBits;
+ pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, nColors * sizeof(PALETTEENTRY) );
+ GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal );
+ pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD));
+ for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) {
+ pRGB->rgbRed = pPE->peRed;
+ pRGB->rgbGreen = pPE->peGreen;
+ pRGB->rgbBlue = pPE->peBlue;
+ }
+ if(pwc->db_flag)
+ bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab );
+
+ if(!bRet)
+ dwErr = GetLastError();
+
+ free( pColTab );
+ free( pPal );
+
+ return(bRet);
+}
+
+
+//
+// Free up the dib section that was created
+//
+BOOL wmDeleteBackingStore(PWMC pwc)
+{
+ SelectObject(pwc->dib.hDC, pwc->hOldBitmap);
+ DeleteDC(pwc->dib.hDC);
+ DeleteObject(pwc->hbmDIB);
+ UnmapViewOfFile(pwc->dib.base);
+ CloseHandle(pwc->dib.hFileMap);
+ return TRUE;
+}
+
+
+//
+// This function creates the DIB section that is used for combined
+// GL and GDI calls
+//
+BOOL /*WINAPI*/ wmCreateBackingStore(PWMC pwc, long lxSize, long lySize)
+{
+ HDC hdc = pwc->hDC;
+ LPBITMAPINFO pbmi = &(pwc->bmi);
+ int iUsage;
+
+ pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->bmiHeader.biWidth = lxSize;
+ pbmi->bmiHeader.biHeight= -lySize;
+ pbmi->bmiHeader.biPlanes = 1;
+ if(pwc->rgb_flag)
+ pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL);
+ else
+ pbmi->bmiHeader.biBitCount = 8;
+ pbmi->bmiHeader.biCompression = BI_RGB;
+ pbmi->bmiHeader.biSizeImage = 0;
+ pbmi->bmiHeader.biXPelsPerMeter = 0;
+ pbmi->bmiHeader.biYPelsPerMeter = 0;
+ pbmi->bmiHeader.biClrUsed = 0;
+ pbmi->bmiHeader.biClrImportant = 0;
+
+ iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS;
+
+ pwc->cColorBits = pbmi->bmiHeader.biBitCount;
+ pwc->ScanWidth = pwc->pitch = lxSize;
+
+ wmCreateDIBSection(hdc, pwc, pbmi, iUsage);
+
+ if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) {
+ wmCreatePalette( pwc );
+ wmSetDibColors( pwc );
+ }
+ wmSetPixelFormat(pwc, pwc->hDC);
+ return(TRUE);
+
+}
+
+
+//
+// This function copies one scan line in a DIB section to another
+//
+BOOL GLWINAPI wmSetDIBits(PWMC pwc, UINT uiScanWidth, UINT uiNumScans, UINT nBypp, UINT uiNewWidth, LPBYTE pBits)
+{
+ UINT uiScans = 0;
+ LPBYTE pDest = pwc->pbPixels;
+ DWORD dwNextScan = uiScanWidth;
+ DWORD dwNewScan = uiNewWidth;
+ DWORD dwScanWidth = (uiScanWidth * nBypp);
+
+ //
+ // We need to round up to the nearest DWORD
+ // and multiply by the number of bytes per
+ // pixel
+ //
+ dwNextScan = (((dwNextScan * nBypp)+ 3) & ~3);
+ dwNewScan = (((dwNewScan * nBypp)+ 3) & ~3);
+
+ for(uiScans = 0; uiScans < uiNumScans; uiScans++){
+ CopyMemory(pDest, pBits, dwScanWidth);
+ pBits += dwNextScan;
+ pDest += dwNewScan;
+ }
+
+ return(TRUE);
+
+}
+
+
+BOOL wmFlush(PWMC pwc);
+
+/*
+* Useful macros:
+Modified from file osmesa.c
+*/
+
+
+#define PIXELADDR(X,Y) ((GLubyte *)Current->pbPixels + (Current->height-Y-1)* Current->ScanWidth + (X)*nBypp)
+#define PIXELADDR1( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X))
+#define PIXELADDR2( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*2)
+#define PIXELADDR4( X, Y ) \
+((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*4)
+
+
+BYTE DITHER_RGB_2_8BIT( int r, int g, int b, int x, int y);
+
+/* Finish all pending operations and synchronize. */
+static void finish(GLcontext* ctx)
+{
+ /* No op */
+}
+
+
+//
+// We cache all gl draw routines until a flush is made
+//
+static void flush(GLcontext* ctx)
+{
+ STARTPROFILE
+ if((Current->rgb_flag /*&& !(Current->dib.fFlushed)*/&&!(Current->db_flag))
+ ||(!Current->rgb_flag))
+ {
+ wmFlush(Current);
+ }
+ ENDPROFILE(flush)
+
+}
+
+
+
+/*
+* Set the color index used to clear the color buffer.
+*/
+static void clear_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->clearpixel = index;
+ ENDPROFILE(clear_index)
+}
+
+
+
+/*
+* Set the color used to clear the color buffer.
+*/
+static void clear_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->clearpixel=RGB(r, g, b );
+ ENDPROFILE(clear_color)
+}
+
+
+
+/*
+* Clear the specified region of the color buffer using the clear color
+* or index as specified by one of the two functions above.
+*/
+//static void clear(GLcontext* ctx,
+// GLboolean all,GLint x, GLint y, GLint width, GLint height )
+// TODO: I modified this function to match the prototype in dd.h. ([email protected])
+// dd.h does not explain what the return type is so I could not set this to the proper
+// value.
+static GLbitfield clear(GLcontext* ctx, GLbitfield mask,
+ GLboolean all, GLint x, GLint y, GLint width, GLint height)
+{
+ DWORD dwColor;
+ WORD wColor;
+ BYTE bColor;
+ LPDWORD lpdw = (LPDWORD)Current->pbPixels;
+ LPWORD lpw = (LPWORD)Current->pbPixels;
+ LPBYTE lpb = Current->pbPixels;
+ int lines;
+
+ STARTPROFILE
+
+ if (all){
+ x=y=0;
+ width=Current->width;
+ height=Current->height;
+ }
+ if(Current->db_flag==GL_TRUE){
+ UINT nBypp = Current->cColorBits / 8;
+ int i = 0;
+ int iSize = 0;
+
+ if(nBypp ==1 ){
+ /* Need rectification */
+ iSize = Current->width/4;
+ bColor = BGR8(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ wColor = MAKEWORD(bColor,bColor);
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ if(nBypp == 2){
+ iSize = Current->width / 2;
+ wColor = BGR16(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ else if(nBypp == 4){
+ iSize = Current->width;
+ dwColor = BGR32(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ }
+
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpdw++;
+ i++;
+ }
+
+ //
+ // This is the 24bit case
+ //
+ if (nBypp == 3) {
+ iSize = Current->width *3/4;
+ dwColor = BGR24(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpb += nBypp;
+ lpdw = (LPDWORD)lpb;
+ i++;
+ }
+ }
+
+ i = 0;
+ if (stereo_flag)
+ lines = height /2;
+ else
+ lines = height;
+ do {
+ memcpy(lpb, Current->pbPixels, iSize*4);
+ lpb += Current->ScanWidth;
+ i++;
+ }
+ while (i<lines-1);
+ }
+ else { // For single buffer
+ HDC DC=DD_GETDC;
+ HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
+ HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
+ HPEN Old_Pen=SelectObject(DC,Pen);
+ HBRUSH Old_Brush=SelectObject(DC,Brush);
+ Rectangle(DC,x,y,x+width,y+height);
+ SelectObject(DC,Old_Pen);
+ SelectObject(DC,Old_Brush);
+ DeleteObject(Pen);
+ DeleteObject(Brush);
+ DD_RELEASEDC;
+ }
+
+
+
+ ENDPROFILE(clear)
+
+ return mask; // TODO: I doubt this is correct. dd.h doesn't explain what this should
+ // be...
+}
+
+
+
+/* Set the current color index. */
+static void set_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->pixel=index;
+ ENDPROFILE(set_index)
+}
+
+
+
+/* Set the current RGBA color. */
+static void set_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->pixel = RGB( r, g, b );
+ ENDPROFILE(set_color)
+}
+
+
+
+/* Set the index mode bitplane mask. */
+static GLboolean index_mask(GLcontext* ctx, GLuint mask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/* Set the RGBA drawing mask. */
+static GLboolean color_mask( GLcontext* ctx,
+ GLboolean rmask, GLboolean gmask,
+ GLboolean bmask, GLboolean amask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/*
+* Set the pixel logic operation. Return GL_TRUE if the device driver
+* can perform the operation, otherwise return GL_FALSE. If GL_FALSE
+* is returned, the logic op will be done in software by Mesa.
+*/
+GLboolean logicop( GLcontext* ctx, GLenum op )
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+static void dither( GLcontext* ctx, GLboolean enable )
+{
+ if(enable == GL_FALSE){
+ Current->dither_flag = GL_FALSE;
+ if(Current->cColorBits == 8)
+ Current->pixelformat = PF_INDEX8;
+ }
+ else{
+ if (Current->rgb_flag && Current->cColorBits == 8){
+ Current->pixelformat = PF_DITHER8;
+ Current->dither_flag = GL_TRUE;
+ }
+ else
+ Current->dither_flag = GL_FALSE;
+ }
+}
+
+
+
+static GLboolean set_buffer( GLcontext* ctx, GLenum mode )
+{
+ STARTPROFILE
+ /* TODO: this could be better */
+ if (mode==GL_FRONT || mode==GL_BACK) {
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+ ENDPROFILE(set_buffer)
+}
+
+
+
+/* Return characteristics of the output buffer. */
+static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height )
+{
+ int New_Size;
+ RECT CR;
+
+ STARTPROFILE
+ GetClientRect(Current->Window,&CR);
+
+ *width=CR.right;
+ *height=CR.bottom;
+
+ New_Size=((*width)!=Current->width) || ((*height)!=Current->height);
+
+ if (New_Size){
+ Current->width=*width;
+ Current->height=*height;
+ Current->ScanWidth=Current->width;
+ if ((Current->ScanWidth%sizeof(long))!=0)
+ Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
+
+ if (Current->db_flag){
+#ifdef DDRAW
+ DDDeleteOffScreen(Current);
+ DDCreateOffScreen(Current);
+#else
+ if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){
+ wmDeleteBackingStore(Current);
+ wmCreateBackingStore(Current, Current->width, Current->height);
+ }
+#endif
+ }
+
+ // Resize OsmesaBuffer if in Parallel mode
+#if !defined(NO_PARALLEL)
+ if(parallelFlag)
+ PRSizeRenderBuffer(Current->width, Current->height,Current->ScanWidth,
+ Current->rgb_flag == GL_TRUE ? Current->pbPixels: Current->ScreenMem);
+#endif
+ }
+ ENDPROFILE(buffer_size)
+}
+
+
+
+/**********************************************************************/
+/***** Accelerated point, line, polygon rendering *****/
+/**********************************************************************/
+
+
+static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last )
+{
+ GLuint i;
+ // HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ STARTPROFILE
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ /* all drawn with current color */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ }
+ }
+ else {
+ /* draw points of different colors */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ unsigned long pixel=RGB(Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ }
+ }
+ }
+ // DD_RELEASEDC;
+ ENDPROFILE(fast_rgb_points)
+}
+
+
+
+/* Return pointer to accerated points function */
+extern points_func choose_points_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && ctx->Visual->RGBAflag) {
+ ENDPROFILE(choose_points_function)
+ return fast_rgb_points;
+ }
+ else {
+ ENDPROFILE(choose_points_function)
+ return NULL;
+ }
+}
+
+
+
+/* Draw a line using the color specified by Current->gl_ctx->VB->Color[pv] */
+static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, GLuint v1, GLuint pv )
+{
+ STARTPROFILE
+ int x0, y0, x1, y1;
+ unsigned long pixel;
+ HDC DC=DD_GETDC;
+ HPEN Pen;
+ HPEN Old_Pen;
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ pixel = Current->pixel; /* use current color */
+ }
+ else {
+ 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);
+ }
+
+ x0 = (int) Current->gl_ctx->VB->Win[v0][0];
+ y0 = FLIP( (int) Current->gl_ctx->VB->Win[v0][1] );
+ x1 = (int) Current->gl_ctx->VB->Win[v1][0];
+ y1 = FLIP( (int) Current->gl_ctx->VB->Win[v1][1] );
+
+
+ BEGINGDICALL
+
+ Pen=CreatePen(PS_SOLID,1,pixel);
+ Old_Pen=SelectObject(DC,Pen);
+ MoveToEx(DC,x0,y0,NULL);
+ LineTo(DC,x1,y1);
+ SelectObject(DC,Old_Pen);
+ DeleteObject(Pen);
+ DD_RELEASEDC;
+
+ ENDGDICALL
+
+ ENDPROFILE(fast_flat_rgb_line)
+}
+
+
+
+/* Return pointer to accerated line function */
+static line_func choose_line_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Line.Width==1.0 && !ctx->Line.SmoothFlag && !ctx->Line.StippleFlag
+ && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && Current->rgb_flag) {
+ ENDPROFILE(choose_line_function)
+ return fast_flat_rgb_line;
+ }
+ else {
+ ENDPROFILE(choose_line_function)
+ return NULL;
+ }
+}
+
+
+/**********************************************************************/
+/***** Span-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write a horizontal span of 32-bit color-index pixels with a boolean mask. */
+static void write_ci32_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLuint index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_ci32_span)
+}
+
+
+/* Write a horizontal span of 8-bit color-index pixels with a boolean mask. */
+static void write_ci8_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_ci8_span)
+}
+
+
+
+/*
+* Write a horizontal span of pixels with a boolean mask. The current
+* color index is used for all pixels.
+*/
+static void write_mono_ci_span(const GLcontext* ctx,
+ GLuint n,GLint x,GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=Current->pixel;
+ ENDPROFILE(write_mono_ci_span)
+}
+
+/*
+ * To improve the performance of this routine, frob the data into an actual
+ * scanline and call bitblt on the complete scan line instead of SetPixel.
+ */
+
+/* Write a horizontal span of RGBA color pixels with a boolean mask. */
+static void write_rgba_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
+ }
+ DD_RELEASEDC;
+ }
+ else
+ {
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ y = FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
+ }
+ }
+ ENDPROFILE(write_rgba_span)
+
+}
+
+/* Write a horizontal span of RGB color pixels with a boolean mask. */
+static void write_rgb_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3], const GLubyte mask[] )
+{
+ STARTPROFILE
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
+ }
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
+ }
+ DD_RELEASEDC;
+ }
+ else
+ {
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ y = FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i] = GetNearestPaletteIndex(Current->hPal,RGB(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
+ }
+ }
+ ENDPROFILE(write_rgb_span)
+
+}
+
+/*
+* Write a horizontal span of pixels with a boolean mask. The current color
+* is used for all pixels.
+*/
+static void write_mono_rgba_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+ if(Current->rgb_flag==GL_TRUE){
+ for (i=0; i<n; i++)
+ if (mask[i])
+ // Trying
+ wmSetPixel(pwc,y,x+i,GetRValue(Current->pixel), GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ else {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(DC, y, x+i, Current->pixel);
+ }
+ DD_RELEASEDC;
+ ENDPROFILE(write_mono_rgba_span)
+}
+
+
+
+/**********************************************************************/
+/***** Array-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write an array of 32-bit index pixels with a boolean mask. */
+static void write_ci32_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = index[i];
+ }
+ }
+ ENDPROFILE(write_ci32_pixels)
+}
+
+
+
+/*
+* Write an array of pixels with a boolean mask. The current color
+* index is used for all pixels.
+*/
+static void write_mono_ci_pixels( const GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = Current->pixel;
+ }
+ }
+ ENDPROFILE(write_mono_ci_pixels)
+}
+
+
+
+/* Write an array of RGBA pixels with a boolean mask. */
+static void write_rgba_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]);
+ DD_RELEASEDC;
+ ENDPROFILE(write_rgba_pixels)
+}
+
+
+
+/*
+* Write an array of pixels with a boolean mask. The current color
+* is used for all pixels.
+*/
+static void write_mono_rgba_pixels( const GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ DD_RELEASEDC;
+ ENDPROFILE(write_mono_rgba_pixels)
+}
+
+
+
+/**********************************************************************/
+/***** Read spans/arrays of pixels *****/
+/**********************************************************************/
+
+
+/* Read a horizontal span of color-index pixels. */
+static void read_ci32_span( const GLcontext* ctx, GLuint n, GLint x, GLint y,
+ GLuint index[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ index[i]=Mem[i];
+ ENDPROFILE(read_ci32_span)
+}
+
+
+
+
+/* Read an array of color index pixels. */
+static void read_ci32_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint indx[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ indx[i]=*(Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]);
+ }
+ }
+ ENDPROFILE(read_ci32_pixels)
+}
+
+
+
+/* Read a horizontal span of color pixels. */
+static void read_rgba_span( const GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4] )
+{
+ STARTPROFILE
+ UINT i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+ for (i=0; i<n; i++) {
+ Color=GetPixel(DC,x+i,y);
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+ DD_RELEASEDC;
+// Brian P. Has mentioned to comment this out.
+// memset(alpha,0,n*sizeof(GLubyte));
+ ENDPROFILE(read_rgba_span)
+}
+
+
+/* Read an array of color pixels. */
+static void read_rgba_pixels( const GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ Color=GetPixel(DC,x[i],FLIP(y[i]));
+ rgba[i][RCOMP] = GetRValue(Color);
+ rgba[i][GCOMP] = GetGValue(Color);
+ rgba[i][BCOMP] = GetBValue(Color);
+ rgba[i][ACOMP] = 255;
+ }
+ }
+ DD_RELEASEDC;
+// Brian P. has mentioned to comment this out.
+// memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_rgba_pixels)
+}
+
+
+
+/**********************************************************************/
+/**********************************************************************/
+
+
+static const char *renderer_string(void)
+{
+ return "Windows";
+}
+
+
+
+void setup_DD_pointers( GLcontext* ctx )
+{
+ ctx->Driver.RendererString = renderer_string;
+ ctx->Driver.UpdateState = setup_DD_pointers;
+ ctx->Driver.GetBufferSize = buffer_size;
+ ctx->Driver.Finish = finish;
+ ctx->Driver.Flush = flush;
+
+ ctx->Driver.ClearIndex = clear_index;
+ ctx->Driver.ClearColor = clear_color;
+ ctx->Driver.Clear = clear;
+
+ ctx->Driver.Index = set_index;
+ ctx->Driver.Color = set_color;
+ ctx->Driver.IndexMask = index_mask;
+ ctx->Driver.ColorMask = color_mask;
+
+ ctx->Driver.LogicOp = logicop;
+ ctx->Driver.Dither = dither;
+
+ ctx->Driver.SetBuffer = set_buffer;
+ ctx->Driver.GetBufferSize = buffer_size;
+
+ ctx->Driver.PointsFunc = choose_points_function(ctx);
+ ctx->Driver.LineFunc = choose_line_function(ctx);
+ ctx->Driver.TriangleFunc = choose_triangle_function( ctx );
+
+ /* Pixel/span writing functions: */
+ ctx->Driver.WriteRGBASpan = write_rgba_span;
+ ctx->Driver.WriteRGBSpan = write_rgb_span;
+ ctx->Driver.WriteMonoRGBASpan = write_mono_rgba_span;
+ ctx->Driver.WriteRGBAPixels = write_rgba_pixels;
+ ctx->Driver.WriteMonoRGBAPixels = write_mono_rgba_pixels;
+ ctx->Driver.WriteCI32Span = write_ci32_span;
+ ctx->Driver.WriteCI8Span = write_ci8_span;
+ ctx->Driver.WriteMonoCISpan = write_mono_ci_span;
+ ctx->Driver.WriteCI32Pixels = write_ci32_pixels;
+ ctx->Driver.WriteMonoCIPixels = write_mono_ci_pixels;
+
+ ctx->Driver.ReadCI32Span = read_ci32_span;
+ ctx->Driver.ReadRGBASpan = read_rgba_span;
+ ctx->Driver.ReadCI32Pixels = read_ci32_pixels;
+ ctx->Driver.ReadRGBAPixels = read_rgba_pixels;
+}
+
+
+/**********************************************************************/
+/***** WMesa API Functions *****/
+/**********************************************************************/
+
+
+
+#define PAL_SIZE 256
+static void GetPalette(HPALETTE Pal,RGBQUAD *aRGB)
+{
+ STARTPROFILE
+ int i;
+ HDC hdc;
+ struct
+ {
+ WORD Version;
+ WORD NumberOfEntries;
+ PALETTEENTRY aEntries[PAL_SIZE];
+ } Palette =
+ {
+ 0x300,
+ PAL_SIZE
+ };
+ hdc=GetDC(NULL);
+ if (Pal!=NULL)
+ GetPaletteEntries(Pal,0,PAL_SIZE,Palette.aEntries);
+ else
+ GetSystemPaletteEntries(hdc,0,PAL_SIZE,Palette.aEntries);
+ if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
+ {
+ for(i = 0; i <PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ Palette.aEntries[255].peRed = 255;
+ Palette.aEntries[255].peGreen = 255;
+ Palette.aEntries[255].peBlue = 255;
+ Palette.aEntries[255].peFlags = 0;
+ Palette.aEntries[0].peRed = 0;
+ Palette.aEntries[0].peGreen = 0;
+ Palette.aEntries[0].peBlue = 0;
+ Palette.aEntries[0].peFlags = 0;
+ }
+ else
+ {
+ int nStaticColors;
+ int nUsableColors;
+ nStaticColors = GetDeviceCaps(hdc, NUMCOLORS)/2;
+ for (i=0; i<nStaticColors; i++)
+ Palette.aEntries[i].peFlags = 0;
+ nUsableColors = PAL_SIZE-nStaticColors;
+ for (; i<nUsableColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (; i<PAL_SIZE-nStaticColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (i=PAL_SIZE-nStaticColors; i<PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = 0;
+ }
+ ReleaseDC(NULL,hdc);
+ for (i=0; i<PAL_SIZE; i++)
+ {
+ aRGB[i].rgbRed=Palette.aEntries[i].peRed;
+ aRGB[i].rgbGreen=Palette.aEntries[i].peGreen;
+ aRGB[i].rgbBlue=Palette.aEntries[i].peBlue;
+ aRGB[i].rgbReserved=Palette.aEntries[i].peFlags;
+ }
+ ENDPROFILE(GetPalette)
+}
+
+
+WMesaContext WMesaCreateContext( HWND hWnd,
+ HPALETTE* Pal,
+ GLboolean rgb_flag,
+ GLboolean db_flag )
+{
+ RECT CR;
+ WMesaContext c;
+ GLboolean true_color_flag;
+ c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context));
+ if (!c)
+ return NULL;
+
+ c->Window=hWnd;
+ c->hDC = GetDC(hWnd);
+ true_color_flag = GetDeviceCaps(c->hDC, BITSPIXEL) > 8;
+#ifdef DDRAW
+ if(true_color_flag) c->rgb_flag = rgb_flag = GL_TRUE;
+#endif
+
+
+#ifdef DITHER
+ if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){
+ c->dither_flag = GL_TRUE;
+ c->hPalHalfTone = WinGCreateHalftonePalette();
+ }
+ else
+ c->dither_flag = GL_FALSE;
+#else
+ c->dither_flag = GL_FALSE;
+#endif
+
+
+ if (rgb_flag==GL_FALSE)
+ {
+ c->rgb_flag = GL_FALSE;
+ // c->pixel = 1;
+ c->db_flag = db_flag =GL_TRUE; // WinG requires double buffering
+ printf("Single buffer is not supported in color index mode, setting to double buffer.\n");
+ }
+ else
+ {
+ c->rgb_flag = GL_TRUE;
+ // c->pixel = 0;
+ }
+ GetClientRect(c->Window,&CR);
+ c->width=CR.right;
+ c->height=CR.bottom;
+ if (db_flag)
+ {
+ c->db_flag = 1;
+ /* Double buffered */
+#ifndef DDRAW
+ // if (c->rgb_flag==GL_TRUE && c->dither_flag != GL_TRUE )
+ {
+ wmCreateBackingStore(c, c->width, c->height);
+
+ }
+#endif
+ }
+ else
+ {
+ /* Single Buffered */
+ if (c->rgb_flag)
+ c->db_flag = 0;
+ }
+#ifdef DDRAW
+ if (DDInit(c,hWnd) == GL_FALSE) {
+ free( (void *) c );
+ exit(1);
+ }
+#endif
+
+
+ c->gl_visual = gl_create_visual(rgb_flag,
+ GL_FALSE, /* software alpha */
+ db_flag, /* db_flag */
+ GL_FALSE, /* stereo */
+ 16, /* depth_bits */
+ 8, /* stencil_bits */
+ 8, /* accum_bits */
+ 0, /* index bits */
+ 8,8,8,8 ); /* r, g, b, a bits */
+
+ if (!c->gl_visual) {
+ return NULL;
+ }
+
+ /* allocate a new Mesa context */
+ c->gl_ctx = gl_create_context( c->gl_visual, NULL, c, GL_TRUE);
+
+ if (!c->gl_ctx) {
+ gl_destroy_visual( c->gl_visual );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_buffer = gl_create_framebuffer( c->gl_visual );
+ if (!c->gl_buffer) {
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_context( c->gl_ctx );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_ctx->Driver.UpdateState = setup_DD_pointers;
+
+ // setup_DD_pointers(c->gl_ctx);
+
+ return c;
+}
+
+void WMesaDestroyContext( void )
+{
+ WMesaContext c = Current;
+ ReleaseDC(c->Window,c->hDC);
+ WC = c;
+ if(c->hPalHalfTone != NULL)
+ DeleteObject(c->hPalHalfTone);
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_framebuffer( c->gl_buffer );
+ gl_destroy_context( c->gl_ctx );
+
+ if (c->db_flag)
+#ifdef DDRAW
+ DDFree(c);
+#else
+ wmDeleteBackingStore(c);
+#endif
+ free( (void *) c );
+ //Following code is added to enable parallel render
+ // Parallel render only work in double buffer mode
+#if !defined(NO_PARALLEL)
+ if(parallelMachine)
+ PRDestroyRenderBuffer();
+#endif
+ // End modification
+}
+
+void WMesaMakeCurrent( WMesaContext c )
+{
+ if(!c){
+ Current = c;
+ return;
+ }
+
+ //
+ // A little optimization
+ // If it already is current,
+ // don't set it again
+ //
+ if(Current == c)
+ return;
+
+ //gl_set_context( c->gl_ctx );
+ gl_make_current(c->gl_ctx, c->gl_buffer);
+ setup_DD_pointers(c->gl_ctx);
+ Current = c;
+ if (Current->gl_ctx->Viewport.Width==0) {
+ /* initialize viewport to window size */
+ gl_Viewport( Current->gl_ctx,
+ 0, 0, Current->width, Current->height );
+ }
+ if ((c->cColorBits <= 8 ) && (c->rgb_flag == GL_TRUE)){
+ WMesaPaletteChange(c->hPalHalfTone);
+ }
+}
+
+void WMesaSwapBuffers( void )
+{
+ HDC DC = Current->hDC;
+ if (Current->db_flag)
+ wmFlush(Current);
+}
+
+void WMesaPaletteChange(HPALETTE Pal)
+{
+ int vRet;
+ LPPALETTEENTRY pPal;
+ if (Current && (Current->rgb_flag==GL_FALSE || Current->dither_flag == GL_TRUE))
+ {
+ pPal = (PALETTEENTRY *)malloc( 256 * sizeof(PALETTEENTRY));
+ Current->hPal=Pal;
+ // GetPaletteEntries( Pal, 0, 256, pPal );
+ GetPalette( Pal, pPal );
+#ifdef DDRAW
+ Current->lpDD->lpVtbl->CreatePalette(Current->lpDD,DDPCAPS_8BIT,
+ pPal, &(Current->lpDDPal), NULL);
+ if (Current->lpDDPal)
+ Current->lpDDSPrimary->lpVtbl->SetPalette(Current->lpDDSPrimary,Current->lpDDPal);
+#else
+ vRet = SetDIBColorTable(Current->dib.hDC,0,256,pPal);
+#endif
+ free( pPal );
+ }
+
+}
+
+static unsigned char threeto8[8] = {
+ 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
+};
+
+static unsigned char twoto8[4] = {
+ 0, 0x55, 0xaa, 0xff
+};
+
+static unsigned char oneto8[2] = {
+ 0, 255
+};
+
+static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift)
+{
+ unsigned char val;
+
+ val = i >> shift;
+ switch (nbits) {
+
+ case 1:
+ val &= 0x1;
+ return oneto8[val];
+
+ case 2:
+ val &= 0x3;
+ return twoto8[val];
+
+ case 3:
+ val &= 0x7;
+ return threeto8[val];
+
+ default:
+ return 0;
+ }
+}
+
+void wmCreatePalette( PWMC pwdc )
+{
+ /* Create a compressed and re-expanded 3:3:2 palette */
+ int i;
+ LOGPALETTE *pPal;
+ BYTE rb, rs, gb, gs, bb, bs;
+
+ pwdc->nColors = 0x100;
+
+ pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) );
+
+ pPal->palVersion = 0x300;
+
+ rb = REDBITS;
+ rs = REDSHIFT;
+ gb = GREENBITS;
+ gs = GREENSHIFT;
+ bb = BLUEBITS;
+ bs = BLUESHIFT;
+
+ if (pwdc->db_flag) {
+
+ /* Need to make two palettes: one for the screen DC and one for the DIB. */
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ pwdc->hPalette = CreatePalette( pPal );
+ }
+
+ else {
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ }
+
+ free(pPal);
+
+}
+
+void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
+{
+ if(Current->db_flag){
+ LPBYTE lpb = pwc->pbPixels;
+ LPDWORD lpdw;
+ LPWORD lpw;
+ UINT nBypp = pwc->cColorBits / 8;
+ UINT nOffset = iPixel % nBypp;
+
+ // Move the pixel buffer pointer to the scanline that we
+ // want to access
+
+ // pwc->dib.fFlushed = FALSE;
+
+ lpb += pwc->ScanWidth * iScanLine;
+ // Now move to the desired pixel
+ lpb += iPixel * nBypp;
+ lpb = PIXELADDR(iPixel, iScanLine);
+ lpdw = (LPDWORD)lpb;
+ lpw = (LPWORD)lpb;
+
+ if(nBypp == 1){
+ if(pwc->dither_flag)
+ *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
+ else
+ *lpb = BGR8(r,g,b);
+ }
+ else if(nBypp == 2)
+ *lpw = BGR16(r,g,b);
+ else if (nBypp == 3){
+ *lpdw = BGR24(r,g,b);
+ }
+ else if (nBypp == 4)
+ *lpdw = BGR32(r,g,b);
+ }
+ else{
+ HDC DC = DD_GETDC;
+ SetPixel(DC, iPixel, iScanLine, RGB(r,g,b));
+ DD_RELEASEDC;
+ }
+}
+
+void wmCreateDIBSection( HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ )
+{
+ DWORD dwSize = 0;
+ DWORD dwScanWidth;
+ UINT nBypp = pwc->cColorBits / 8;
+ HDC hic;
+
+ dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3);
+
+ pwc->ScanWidth =pwc->pitch = dwScanWidth;
+
+ if (stereo_flag)
+ pwc->ScanWidth = 2* pwc->pitch;
+
+ dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height);
+
+ pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE,
+ NULL,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0,
+ dwSize,
+ NULL);
+
+ if (!pwc->dib.hFileMap)
+ return;
+
+ pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap,
+ FILE_MAP_ALL_ACCESS,
+ 0,
+ 0,
+ 0);
+
+ if(!pwc->dib.base){
+ CloseHandle(pwc->dib.hFileMap);
+ return;
+ }
+
+ // pwc->pbPixels = pwc->addrOffScreen = ((LPBYTE)pwc->dib.base) + sizeof(BITMAPINFO);
+
+ // pwc->dib.hDC = CreateCompatibleDC(hDC);
+
+ CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO));
+
+ hic = CreateIC("display", NULL, NULL, NULL);
+ pwc->dib.hDC = CreateCompatibleDC(hic);
+
+
+ /* pwc->hbmDIB = CreateDIBitmap(hic,
+ &(pwc->bmi.bmiHeader),
+ CBM_INIT,
+ pwc->pbPixels,
+ &(pwc->bmi),
+ DIB_RGB_COLORS);
+ */
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS),
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ /*
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ DIB_RGB_COLORS,
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ */
+ pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels;
+ pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB);
+
+ DeleteDC(hic);
+
+ return;
+
+}
+
+//
+// Blit memory DC to screen DC
+//
+BOOL wmFlush(PWMC pwc)
+{
+ BOOL bRet = 0;
+ DWORD dwErr = 0;
+#ifdef DDRAW
+ HRESULT ddrval;
+#endif
+
+ // Now search through the torus frames and mark used colors
+ if(pwc->db_flag){
+#ifdef DDRAW
+ if (pwc->lpDDSOffScreen == NULL)
+ if(DDCreateOffScreen(pwc) == GL_FALSE)
+ return;
+
+ pwc->lpDDSOffScreen->lpVtbl->Unlock(pwc->lpDDSOffScreen, NULL);
+
+ while( 1 )
+ {
+ ddrval = pwc->lpDDSPrimary->lpVtbl->Blt( pwc->lpDDSPrimary,
+ &(pwc->rectSurface), pwc->lpDDSOffScreen, &(pwc->rectOffScreen), 0, NULL );
+
+ if( ddrval == DD_OK )
+ {
+ break;
+ }
+ if( ddrval == DDERR_SURFACELOST )
+ {
+ if(!DDRestoreAll(pwc))
+ {
+ break;
+ }
+ }
+ if( ddrval != DDERR_WASSTILLDRAWING )
+ {
+ break;
+ }
+ }
+
+ while (pwc->lpDDSOffScreen->lpVtbl->Lock(pwc->lpDDSOffScreen,
+ NULL, &(pwc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+
+ if(ddrval != DD_OK)
+ dwErr = GetLastError();
+#else
+ bRet = BitBlt(pwc->hDC, 0, 0, pwc->width, pwc->height,
+ pwc->dib.hDC, 0, 0, SRCCOPY);
+#endif
+ }
+
+ return(TRUE);
+
+}
+
+// The following code is added by Li Wei to enable stereo display
+
+#if !defined(NO_STEREO)
+
+void WMesaShowStereo(GLuint list)
+{
+
+ GLbitfield mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
+ GLfloat cm[16];
+ GLint matrix_mode;
+ // Must use double Buffer
+ if( ! Current-> db_flag )
+ return;
+
+
+ glGetIntegerv(GL_MATRIX_MODE,&matrix_mode);
+
+ // glPushMatrix(); //****
+ WMesaViewport(Current->gl_ctx,0,Current->height/2,Current->width,Current->height/2);
+ // Current->gl_ctx->NewState = 0;
+
+ // glViewport(0,0,Current->width,Current->height/2);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(GL_MODELVIEW);
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(viewDistance/2,0.0,0.0 ,
+ viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ // glTranslatef(viewDistance/2.0,0.,0.);
+ glMultMatrixf( cm );
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen;
+ //glPushMatrix();
+ glCallList( list );
+ //glPopMatrix();
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(-viewDistance/2,0.0,0.0 ,
+ -viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ // glTranslatef(-viewDistance/2.0,0.,0.);
+ glMultMatrixf(cm);
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen + Current->pitch;
+ glCallList(list);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(matrix_mode);
+
+ // glPopMatrix();
+ glFlush();
+
+ WMesaViewport(Current->gl_ctx,0,0,Current->width,Current->height);
+ // Current->gl_ctx->NewState = 0;
+ WMesaSwapBuffers();
+
+}
+
+void toggleStereoMode()
+{
+ if(!Current->db_flag)
+ return;
+ if(!stereo_flag){
+ stereo_flag = 1;
+ if(stereoBuffer==GL_FALSE)
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ {
+ Current->ScanWidth = Current->pitch*2;
+ }
+ }
+ else {
+ stereo_flag = 0;
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ Current->ScanWidth = Current->pitch;
+ Current->pbPixels = Current->addrOffScreen;
+ }
+}
+
+/* if in stereo mode, the following function is called */
+void glShowStereo(GLuint list)
+{
+ WMesaShowStereo(list);
+}
+
+#endif // End if NO_STEREO not defined
+
+#if !defined(NO_PARALLEL)
+
+void toggleParallelMode(void)
+{
+ if(!parallelFlag){
+ parallelFlag = GL_TRUE;
+ if(parallelMachine==GL_FALSE){
+ PRCreateRenderBuffer( Current->rgb_flag? GL_RGBA :GL_COLOR_INDEX,
+ Current->cColorBits/8,
+ Current->width ,Current->height,
+ Current->ScanWidth,
+ Current->rgb_flag? Current->pbPixels: Current->ScreenMem);
+ parallelMachine = GL_TRUE;
+ }
+ }
+ else {
+ parallelFlag = GL_FALSE;
+ if(parallelMachine==GL_TRUE){
+ PRDestroyRenderBuffer();
+ parallelMachine=GL_FALSE;
+ ReadyForNextFrame = GL_TRUE;
+ }
+
+ /***********************************************
+ // Seems something wrong!!!!
+ ************************************************/
+
+ WMesaMakeCurrent(Current);
+#if !defined(NO_STEREO)
+ stereo_flag = GL_FALSE ;
+#endif
+ }
+}
+
+void PRShowRenderResult(void)
+{
+ int flag = 0;
+ if(!glImageRendered())
+ return;
+
+ if (parallelFlag)
+ {
+ WMesaSwapBuffers();
+ }
+
+}
+#endif //End if NO_PARALLEL not defined
+
+//end modification
+
+BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline)
+{
+ char unsigned redtemp, greentemp, bluetemp, paletteindex;
+
+ //*** now, look up each value in the halftone matrix
+ //*** using an 8x8 ordered dither.
+ redtemp = aDividedBy51[red]
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8
+ + scanline%8]);
+ greentemp = aDividedBy51[(char unsigned)green]
+ + (aModulo51[green] > aHalftone8x8[
+ (pixel%8)*8 + scanline%8]);
+ bluetemp = aDividedBy51[(char unsigned)blue]
+ + (aModulo51[blue] > aHalftone8x8[
+ (pixel%8)*8 +scanline%8]);
+
+ //*** recombine the halftoned rgb values into a palette index
+ paletteindex =
+ redtemp + aTimes6[greentemp] + aTimes36[bluetemp];
+
+ //*** and translate through the wing halftone palette
+ //*** translation vector to give the correct value.
+ return aWinGHalftoneTranslation[paletteindex];
+}
+
+#ifdef DDRAW
+/*
+* restoreAll
+*
+* restore all lost objects
+*/
+static HRESULT DDRestoreAll( WMesaContext wc )
+{
+ HRESULT ddrval;
+
+ ddrval = wc->lpDDSPrimary->lpVtbl->Restore(wc->lpDDSPrimary);
+ if( ddrval == DD_OK )
+ {
+ ddrval = wc->lpDDSOffScreen->lpVtbl->Restore(wc->lpDDSOffScreen);
+ }
+ return ddrval;
+
+} /* restoreAll */
+
+
+ /*
+ * This function is called if the initialization function fails
+*/
+static BOOL initFail( HWND hwnd, WMesaContext wc )
+{
+ DDFree(wc);
+ MessageBox( hwnd, "DirectDraw Init FAILED", "", MB_OK );
+ return FALSE;
+
+} /* initFail */
+
+
+static void DDDeleteOffScreen(WMesaContext wc)
+{
+ if( wc->lpDDSOffScreen != NULL )
+ {
+ wc->lpDDSOffScreen->lpVtbl->Unlock(wc->lpDDSOffScreen,NULL);
+ wc->lpDDSOffScreen->lpVtbl->Release(wc->lpDDSOffScreen);
+ wc->lpDDSOffScreen = NULL;
+ }
+
+}
+
+static void DDFreePrimarySurface(WMesaContext wc)
+{
+ if( wc->lpDDSPrimary != NULL )
+ {
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->ReleaseDC(wc->lpDDSPrimary, wc->hDC);
+ wc->lpDDSPrimary->lpVtbl->Release(wc->lpDDSPrimary);
+ wc->lpDDSPrimary = NULL;
+ }
+}
+
+static BOOL DDCreatePrimarySurface(WMesaContext wc)
+{
+ HRESULT ddrval;
+ DDSCAPS ddscaps;
+ wc->ddsd.dwSize = sizeof( wc->ddsd );
+ wc->ddsd.dwFlags = DDSD_CAPS;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD,&(wc->ddsd), &(wc->lpDDSPrimary), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(wc->hwnd , wc);
+ }
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->GetDC(wc->lpDDSPrimary, wc->hDC);
+ return TRUE;
+}
+
+static BOOL DDCreateOffScreen(WMesaContext wc)
+{
+ POINT pt;
+ HRESULT ddrval;
+ if(wc->lpDD == NULL)
+ return FALSE;
+ GetClientRect( wc->hwnd, &(wc->rectOffScreen) );
+ wc->ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
+ wc->ddsd.dwHeight = wc->rectOffScreen.bottom - wc->rectOffScreen.top;
+ wc->ddsd.dwWidth = wc->rectOffScreen.right - wc->rectOffScreen.left;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD, &(wc->ddsd), &(wc->lpDDSOffScreen), NULL );
+ if( ddrval != DD_OK )
+ {
+ return FALSE;
+ }
+
+ while (wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+ // while ((ddrval = wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), DDLOCK_SURFACEMEMORYPTR , NULL)) != DD_OK)
+ ;
+ if(wc->ddsd.lpSurface==NULL)
+ return initFail(wc->hwnd, wc);
+
+ wc->ScreenMem = wc->pbPixels = wc->addrOffScreen = (PBYTE)(wc->ddsd.lpSurface);
+ wc->ScanWidth = wc->pitch = wc->ddsd.lPitch;
+ if (stereo_flag)
+ wc->ScanWidth = wc->ddsd.lPitch*2;
+
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ wmSetPixelFormat(wc, wc->hDC);
+ return TRUE;
+}
+
+/*
+* doInit - do work required for every instance of the application:
+* create the window, initialize data
+*/
+static BOOL DDInit( WMesaContext wc, HWND hwnd)
+{
+ HRESULT ddrval;
+ DWORD dwFrequency;
+
+ LPDIRECTDRAW lpDD; // DirectDraw object
+ LPDIRECTDRAW2 lpDD2;
+
+
+ wc->fullScreen = displayOptions.fullScreen;
+ wc->gMode = displayOptions.mode;
+ wc->hwnd = hwnd;
+ stereo_flag = displayOptions.stereo;
+ if(wc->db_flag!= GL_TRUE)
+ stereo_flag = GL_FALSE;
+ /*
+ * create the main DirectDraw object
+ */
+ ddrval = DirectDrawCreate( NULL, &(wc->lpDD), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd,wc);
+ }
+
+ // Get exclusive mode if requested
+ if(wc->fullScreen)
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
+ }
+ else
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_NORMAL );
+ }
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd , wc);
+ }
+
+
+ /* ddrval = wc->lpDD->lpVtbl->QueryInterface(wc->lpDD, IID_IDirectDraw2,
+ (LPVOID *)((wc->lpDD2)));
+
+ */
+ if(ddrval != DD_OK)
+ return initFail(hwnd , wc);
+
+
+ //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+ // wc->lpDD2->lpVtbl->GetMonitorFrequency(wc->lpDD, &dwFrequency);
+ switch( wc->gMode )
+ {
+ case 1: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 640, 480, displayOptions.bpp); break;
+ case 2: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 800, 600, displayOptions.bpp); break;
+ case 3: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1024, 768, displayOptions.bpp); break;
+ case 4: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1152, 864, displayOptions.bpp); break;
+ case 5: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1280, 1024, displayOptions.bpp); break;
+ }
+
+ if( ddrval != DD_OK )
+ {
+ printf("Can't modify display mode, current mode used\n");
+ // return initFail(hwnd , wc);
+ }
+ //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+ switch(ddrval){
+ case DDERR_INVALIDOBJECT:
+ break;
+ case DDERR_INVALIDPARAMS:
+ break;
+ case DDERR_UNSUPPORTEDMODE:
+ ;
+ }
+
+ if(DDCreatePrimarySurface(wc) == GL_FALSE)
+ return initFail(hwnd, wc);
+
+ if(wc->db_flag)
+ return DDCreateOffScreen(wc);
+} /* DDInit */
+
+static void DDFree( WMesaContext wc)
+{
+ if( wc->lpDD != NULL )
+ {
+ DDFreePrimarySurface(wc);
+ DDDeleteOffScreen(wc);
+ wc->lpDD->lpVtbl->Release(wc->lpDD);
+ wc->lpDD = NULL;
+ }
+ // Clean up the screen on exit
+ RedrawWindow( NULL, NULL, NULL, RDW_INVALIDATE | RDW_ERASE |
+ RDW_ALLCHILDREN );
+
+}
+#endif
+
+void WMesaMove(void)
+{
+ WMesaContext wc = Current;
+ POINT pt;
+ if (Current != NULL){
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ }
+}
+
+
+
+/*
+* Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
+* shortcut.
+*/
+#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
+
+
+/**********************************************************************/
+/*** Triangle rendering ***/
+/**********************************************************************/
+
+/*
+ * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, smooth, depth-buffered, PF_8R8G8B triangle.
+*/
+static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+
+/*
+* XImage, smooth, depth-buffered, PF_5R6G5B triangle.
+*/
+static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+/*
+* XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, PF_8R8G8B triangle.
+*/
+static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, PF_5R6G5B triangle.
+*/
+static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
+*/
+static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
+*/
+static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
+*/
+static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
+*/
+static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
+*/
+static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+ //#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void smooth_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = FixedToInt(ffi); \
+ zRow[i] = z; \
+ } \
+ ffi += fdidx; \
+ ffz += fdzdx; \
+ } \
+ }
+
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void flat_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->Index[pv]; \
+ if (!VB->MonoColor) { \
+ /* set the color index */ \
+ (*ctx->Driver.Index)( ctx, index ); \
+ }
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = index; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+
+/*
+* XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+
+static void smooth_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = FixedToInt(ffi); \
+ ffi += fdidx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+/*
+* XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+*/
+static void flat_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->Index[pv]; \
+ if (!VB->MonoColor) { \
+ /* set the color index */ \
+ (*ctx->Driver.Index)( ctx, index ); \
+ }
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = index; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+/*
+* XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
+*/
+static void smooth_DITHER8_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb), xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+/*
+* XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
+*/
+static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+/*
+* XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
+*/
+static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2], xx, yy);\
+ *pixel = pixelDithered; \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+/*
+* XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
+*/
+
+static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+ { \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
+ *pixel = pixelDithered; \
+ } \
+ }
+#ifdef WIN32
+ #include "..\tritemp.h"
+#else
+ #include "tritemp.h"
+#endif
+}
+
+
+
+
+static triangle_func choose_triangle_function( GLcontext *ctx )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ int depth = wmesa->cColorBits;
+
+ if (ctx->Polygon.SmoothFlag) return NULL;
+ if (ctx->Texture.Enabled) return NULL;
+ if (!wmesa->db_flag) return NULL;
+ /*if (wmesa->xm_buffer->buffer==XIMAGE)*/ {
+ if ( ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return smooth_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->Light.ShadeModel==GL_FLAT
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return flat_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_triangle;
+ case PF_INDEX8:
+ return smooth_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_FLAT
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_triangle;
+ case PF_INDEX8:
+ return flat_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ return NULL;
+ }
+}
+
+/*
+* Define a new viewport and reallocate auxillary buffers if the size of
+* the window (color buffer) has changed.
+*/
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ /* Save viewport */
+ ctx->Viewport.X = x;
+ ctx->Viewport.Width = width;
+ ctx->Viewport.Y = y;
+ ctx->Viewport.Height = height;
+
+ /* compute scale and bias values */
+ ctx->Viewport.Sx = (GLfloat) width / 2.0F;
+ ctx->Viewport.Tx = ctx->Viewport.Sx + x;
+ ctx->Viewport.Sy = (GLfloat) height / 2.0F;
+ ctx->Viewport.Ty = ctx->Viewport.Sy + y;
+}
diff --git a/src/mesa/drivers/windows/wmesaOld.c b/src/mesa/drivers/windows/wmesaOld.c
new file mode 100644
index 00000000000..afaeecebcf4
--- /dev/null
+++ b/src/mesa/drivers/windows/wmesaOld.c
@@ -0,0 +1,2737 @@
+/*
+ * File name : wmesa.c
+ * Version : 2.3
+ *
+ * Display driver for Mesa 2.3 under
+ * Windows95 and WindowsNT
+ *
+ * Copyright (C) 1996- Li Wei
+ * Address : Institute of Artificial Intelligence
+ * : & Robotics
+ * : Xi'an Jiaotong University
+ * Email : [email protected]
+ * Web page : http://sun.aiar.xjtu.edu.cn
+ *
+ * This file and its associations are partially borrowed from the
+ * Windows NT driver for Mesa 1.8 , written by Mark Leaming
+ */
+
+
+/*
+ * $Log: wmesaOld.c,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.2 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 1.0 1997/06/14 17:51:00 CST by Li Wei([email protected])
+ * New display driver for Mesa 2.x using Microsoft Direct Draw
+ * Initial vision
+ */
+
+
+#define WMESA_STEREO_C
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <GL/wmesa.h>
+#include "wmesadef.h"
+#include "context.h"
+#include "dd.h"
+#include "xform.h"
+#include "vb.h"
+#include "matrix.h"
+#include "depth.h"
+
+#ifdef PROFILE
+// #include "profile.h"
+#endif
+
+#ifdef DITHER
+ #include <wing.h>
+#endif
+
+#ifdef __CYGWIN32__
+#include "macros.h"
+#include <string.h>
+#define CopyMemory memcpy
+#endif
+#include "mesa_extend.h"
+#include "colors.h"
+
+#if !defined(NO_STEREO)
+
+ #include "gl\glu.h"
+ #include "stereo.h"
+
+#endif
+#if !defined(NO_PARALLEL)
+// #include "parallel.h"
+#endif
+
+struct DISPLAY_OPTIONS displayOptions;
+
+GLenum stereoCompile = GL_FALSE ;
+GLenum stereoShowing = GL_FALSE ;
+GLenum stereoBuffer = GL_FALSE;
+#if !defined(NO_STEREO)
+GLint displayList = MAXIMUM_DISPLAY_LIST ;
+#endif
+GLint stereo_flag = 0 ;
+
+/* end of added code*/
+
+static PWMC Current = NULL;
+WMesaContext WC = NULL;
+
+#ifdef NDEBUG
+ #define assert(ignore) ((void) 0)
+#else
+ void Mesa_Assert(void *Cond,void *File,unsigned Line)
+ {
+ char Msg[512];
+ sprintf(Msg,"%s %s %d",Cond,File,Line);
+ MessageBox(NULL,Msg,"Assertion failed.",MB_OK);
+ exit(1);
+ }
+ #define assert(e) if (!e) Mesa_Assert(#e,__FILE__,__LINE__);
+#endif
+
+//#define DD_GETDC (Current->hDC )
+#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
+//#define DD_GETDC ((Current->db_flag) ? Current->hDCPrimary : Current->hDCBack )
+#define DD_RELEASEDC
+
+//#define BEGINGDICALL if(Current->rgb_flag)wmFlushBits(Current);
+#define BEGINGDICALL
+//#define ENDGDICALL if(Current->rgb_flag)wmGetBits(Current);
+#define ENDGDICALL
+
+//#define FLIP(Y) (Current->dither_flag? Y : Current->height-(Y)-1)
+//#define FLIP(Y) (Current->height-(Y)-1)
+//#define FLIP(Y) Y
+#define FLIP(Y) (Current->db_flag? Y: Current->height-(Y)-1)
+#define STARTPROFILE
+#define ENDPROFILE(PARA)
+
+#define DITHER_RGB_TO_8BIT_SETUP \
+ GLubyte pixelDithered;
+
+#define DITHER_RGB_TO_8BIT(red, green, blue, pixel, scanline) \
+{ \
+ char unsigned redtemp, greentemp, bluetemp, paletteindex; \
+ redtemp = aDividedBy51[red] \
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8 \
+ + scanline%8]); \
+ greentemp = aDividedBy51[(char unsigned)green] \
+ + (aModulo51[green] > aHalftone8x8[ \
+ (pixel%8)*8 + scanline%8]); \
+ bluetemp = aDividedBy51[(char unsigned)blue] \
+ + (aModulo51[blue] > aHalftone8x8[ \
+ (pixel%8)*8 +scanline%8]); \
+ paletteindex = redtemp + aTimes6[greentemp] + aTimes36[bluetemp]; \
+ pixelDithered = aWinGHalftoneTranslation[paletteindex]; \
+}
+
+
+#ifdef DDRAW
+ static BOOL DDInit( WMesaContext wc, HWND hwnd);
+ static void DDFree( WMesaContext wc);
+ static HRESULT DDRestoreAll( WMesaContext wc );
+ static void DDDeleteOffScreen(WMesaContext wc);
+ static BOOL DDCreateOffScreen(WMesaContext wc);
+#endif
+
+static void FlushToFile(PWMC pwc, PSTR szFile);
+
+BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize);
+BOOL wmDeleteBackingStore(PWMC pwc);
+void wmCreatePalette( PWMC pwdc );
+BOOL wmSetDibColors(PWMC pwc);
+void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b);
+
+void wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ );
+
+
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height );
+
+static triangle_func choose_triangle_function( GLcontext *ctx );
+
+static void wmSetPixelFormat( PWMC wc, HDC hDC)
+{
+ if(wc->rgb_flag)
+ wc->cColorBits = GetDeviceCaps(hDC, BITSPIXEL);
+ else
+ wc->cColorBits = 8;
+ switch(wc->cColorBits){
+ case 8:
+ if(wc->dither_flag != GL_TRUE)
+ wc->pixelformat = PF_INDEX8;
+ else
+ wc->pixelformat = PF_DITHER8;
+ break;
+ case 16:
+ wc->pixelformat = PF_5R6G5B;
+ break;
+ case 32:
+ wc->pixelformat = PF_8R8G8B;
+ break;
+ default:
+ wc->pixelformat = PF_BADFORMAT;
+ }
+}
+
+//
+// This function sets the color table of a DIB section
+// to match that of the destination DC
+//
+BOOL /*WINAPI*/ wmSetDibColors(PWMC pwc)
+{
+ RGBQUAD *pColTab, *pRGB;
+ PALETTEENTRY *pPal, *pPE;
+ int i, nColors;
+ BOOL bRet=TRUE;
+ DWORD dwErr=0;
+
+ /* Build a color table in the DIB that maps to the
+ selected palette in the DC.
+ */
+ nColors = 1 << pwc->cColorBits;
+ pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, nColors * sizeof(PALETTEENTRY) );
+ GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal );
+ pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD));
+ for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) {
+ pRGB->rgbRed = pPE->peRed;
+ pRGB->rgbGreen = pPE->peGreen;
+ pRGB->rgbBlue = pPE->peBlue;
+ }
+ if(pwc->db_flag)
+ bRet = SetDIBColorTable(pwc->dib.hDC, 0, nColors, pColTab );
+
+ if(!bRet)
+ dwErr = GetLastError();
+
+ free( pColTab );
+ free( pPal );
+
+ return(bRet);
+}
+
+
+//
+// Free up the dib section that was created
+//
+BOOL wmDeleteBackingStore(PWMC pwc)
+{
+ SelectObject(pwc->dib.hDC, pwc->hOldBitmap);
+ DeleteDC(pwc->dib.hDC);
+ DeleteObject(pwc->hbmDIB);
+ UnmapViewOfFile(pwc->dib.base);
+ CloseHandle(pwc->dib.hFileMap);
+ return TRUE;
+}
+
+
+//
+// This function creates the DIB section that is used for combined
+// GL and GDI calls
+//
+BOOL /*WINAPI*/ wmCreateBackingStore(PWMC pwc, long lxSize, long lySize)
+{
+ HDC hdc = pwc->hDC;
+ LPBITMAPINFO pbmi = &(pwc->bmi);
+ int iUsage;
+
+ pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->bmiHeader.biWidth = lxSize;
+ pbmi->bmiHeader.biHeight= -lySize;
+ pbmi->bmiHeader.biPlanes = 1;
+ if(pwc->rgb_flag)
+ pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL);
+ else
+ pbmi->bmiHeader.biBitCount = 8;
+ pbmi->bmiHeader.biCompression = BI_RGB;
+ pbmi->bmiHeader.biSizeImage = 0;
+ pbmi->bmiHeader.biXPelsPerMeter = 0;
+ pbmi->bmiHeader.biYPelsPerMeter = 0;
+ pbmi->bmiHeader.biClrUsed = 0;
+ pbmi->bmiHeader.biClrImportant = 0;
+
+ iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS;
+
+ pwc->cColorBits = pbmi->bmiHeader.biBitCount;
+ pwc->ScanWidth = pwc->pitch = lxSize;
+
+ wmCreateDIBSection(hdc, pwc, pbmi, iUsage);
+
+ if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) {
+ wmCreatePalette( pwc );
+ wmSetDibColors( pwc );
+ }
+ wmSetPixelFormat(pwc, pwc->hDC);
+ return(TRUE);
+
+}
+
+
+//
+// This function copies one scan line in a DIB section to another
+//
+BOOL GLWINAPI wmSetDIBits(PWMC pwc, UINT uiScanWidth, UINT uiNumScans, UINT nBypp, UINT uiNewWidth, LPBYTE pBits)
+{
+ UINT uiScans = 0;
+ LPBYTE pDest = pwc->pbPixels;
+ DWORD dwNextScan = uiScanWidth;
+ DWORD dwNewScan = uiNewWidth;
+ DWORD dwScanWidth = (uiScanWidth * nBypp);
+
+ //
+ // We need to round up to the nearest DWORD
+ // and multiply by the number of bytes per
+ // pixel
+ //
+ dwNextScan = (((dwNextScan * nBypp)+ 3) & ~3);
+ dwNewScan = (((dwNewScan * nBypp)+ 3) & ~3);
+
+ for(uiScans = 0; uiScans < uiNumScans; uiScans++){
+ CopyMemory(pDest, pBits, dwScanWidth);
+ pBits += dwNextScan;
+ pDest += dwNewScan;
+ }
+
+ return(TRUE);
+
+}
+
+
+BOOL wmFlush(PWMC pwc);
+
+/*
+ * Useful macros:
+ Modified from file osmesa.c
+ */
+
+
+#define PIXELADDR(X,Y) ((GLubyte *)Current->pbPixels + (Current->height-Y-1)* Current->ScanWidth + (X)*nBypp)
+#define PIXELADDR1( X, Y ) \
+ ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X))
+#define PIXELADDR2( X, Y ) \
+ ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*2)
+#define PIXELADDR4( X, Y ) \
+ ((GLubyte *)wmesa->pbPixels + (wmesa->height-Y-1)* wmesa->ScanWidth + (X)*4)
+
+
+BYTE DITHER_RGB_2_8BIT( int r, int g, int b, int x, int y);
+
+/* Finish all pending operations and synchronize. */
+static void finish(GLcontext* ctx)
+{
+ /* No op */
+}
+
+
+//
+// We cache all gl draw routines until a flush is made
+//
+static void flush(GLcontext* ctx)
+{
+ STARTPROFILE
+ if((Current->rgb_flag /*&& !(Current->dib.fFlushed)*/&&!(Current->db_flag))
+ ||(!Current->rgb_flag))
+ {
+ wmFlush(Current);
+ }
+ ENDPROFILE(flush)
+
+}
+
+
+
+/*
+ * Set the color index used to clear the color buffer.
+ */
+static void clear_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->clearpixel = index;
+ ENDPROFILE(clear_index)
+}
+
+
+
+/*
+ * Set the color used to clear the color buffer.
+ */
+static void clear_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->clearpixel=RGB(r, g, b );
+ ENDPROFILE(clear_color)
+}
+
+
+
+/*
+ * Clear the specified region of the color buffer using the clear color
+ * or index as specified by one of the two functions above.
+ */
+static void clear(GLcontext* ctx,
+ GLboolean all,GLint x, GLint y, GLint width, GLint height )
+{
+ DWORD dwColor;
+ WORD wColor;
+ BYTE bColor;
+ LPDWORD lpdw = (LPDWORD)Current->pbPixels;
+ LPWORD lpw = (LPWORD)Current->pbPixels;
+ LPBYTE lpb = Current->pbPixels;
+ int lines;
+
+ STARTPROFILE
+
+ if (all){
+ x=y=0;
+ width=Current->width;
+ height=Current->height;
+ }
+ if(Current->db_flag==GL_TRUE){
+ UINT nBypp = Current->cColorBits / 8;
+ int i = 0;
+ int iSize;
+
+ if(nBypp ==1 ){
+ /* Need rectification */
+ iSize = Current->width/4;
+ bColor = BGR8(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ wColor = MAKEWORD(bColor,bColor);
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ if(nBypp == 2){
+ iSize = Current->width / 2;
+ wColor = BGR16(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ else if(nBypp == 4){
+ iSize = Current->width;
+ dwColor = BGR32(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ }
+
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpdw++;
+ i++;
+ }
+
+ //
+ // This is the 24bit case
+ //
+ if (nBypp == 3) {
+ iSize = Current->width *3/4;
+ dwColor = BGR24(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpb += nBypp;
+ lpdw = (LPDWORD)lpb;
+ i++;
+ }
+ }
+
+ i = 0;
+ if(stereo_flag) lines = height /2;
+ else lines = height;
+ do{
+ lpb += Current->ScanWidth;
+ memcpy(lpb, Current->pbPixels, iSize*4);
+ i++;
+ }
+ while(i<lines-1);
+ }
+ else{ // For single buffer
+ HDC DC=DD_GETDC;
+ HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
+ HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
+ HPEN Old_Pen=SelectObject(DC,Pen);
+ HBRUSH Old_Brush=SelectObject(DC,Brush);
+ Rectangle(DC,x,y,x+width,y+height);
+ SelectObject(DC,Old_Pen);
+ SelectObject(DC,Old_Brush);
+ DeleteObject(Pen);
+ DeleteObject(Brush);
+ DD_RELEASEDC;
+ }
+
+
+
+ ENDPROFILE(clear)
+}
+
+
+
+/* Set the current color index. */
+static void set_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->pixel=index;
+ ENDPROFILE(set_index)
+}
+
+
+
+/* Set the current RGBA color. */
+static void set_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->pixel = RGB( r, g, b );
+ ENDPROFILE(set_color)
+}
+
+
+
+/* Set the index mode bitplane mask. */
+static GLboolean index_mask(GLcontext* ctx, GLuint mask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/* Set the RGBA drawing mask. */
+static GLboolean color_mask( GLcontext* ctx,
+ GLboolean rmask, GLboolean gmask,
+ GLboolean bmask, GLboolean amask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/*
+ * Set the pixel logic operation. Return GL_TRUE if the device driver
+ * can perform the operation, otherwise return GL_FALSE. If GL_FALSE
+ * is returned, the logic op will be done in software by Mesa.
+ */
+GLboolean logicop( GLcontext* ctx, GLenum op )
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+static void dither( GLcontext* ctx, GLboolean enable )
+{
+ if(enable == GL_FALSE){
+ Current->dither_flag = GL_FALSE;
+ if(Current->cColorBits == 8)
+ Current->pixelformat = PF_INDEX8;
+ }
+ else{
+ if (Current->rgb_flag && Current->cColorBits == 8){
+ Current->pixelformat = PF_DITHER8;
+ Current->dither_flag = GL_TRUE;
+ }
+ else
+ Current->dither_flag = GL_FALSE;
+ }
+}
+
+
+
+static GLboolean set_buffer( GLcontext* ctx, GLenum mode )
+{
+ STARTPROFILE
+ /* TODO: this could be better */
+ if (mode==GL_FRONT || mode==GL_BACK) {
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+ ENDPROFILE(set_buffer)
+}
+
+
+
+/* Return characteristics of the output buffer. */
+static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height /*, GLuint *depth */)
+{
+
+ int New_Size;
+ RECT CR;
+
+ STARTPROFILE
+ GetClientRect(Current->Window,&CR);
+
+ *width=CR.right;
+ *height=CR.bottom;
+// *depth = Current->depth;
+
+ New_Size=((*width)!=Current->width) || ((*height)!=Current->height);
+
+ if (New_Size){
+ Current->width=*width;
+ Current->height=*height;
+ Current->ScanWidth=Current->width;
+ if ((Current->ScanWidth%sizeof(long))!=0)
+ Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
+
+ if (Current->db_flag){
+#ifdef DDRAW
+ DDDeleteOffScreen(Current);
+ DDCreateOffScreen(Current);
+#else
+ if (Current->rgb_flag==GL_TRUE && Current->dither_flag!=GL_TRUE){
+ wmDeleteBackingStore(Current);
+ wmCreateBackingStore(Current, Current->width, Current->height);
+ }
+#endif
+ }
+
+// Resize OsmesaBuffer if in Parallel mode
+#if !defined(NO_PARALLEL)
+ if(parallelFlag)
+ PRSizeRenderBuffer(Current->width, Current->height,Current->ScanWidth,
+ Current->rgb_flag == GL_TRUE ? Current->pbPixels: Current->ScreenMem);
+#endif
+ }
+ ENDPROFILE(buffer_size)
+}
+
+
+
+/**********************************************************************/
+/***** Accelerated point, line, polygon rendering *****/
+/**********************************************************************/
+
+
+static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last )
+{
+ GLuint i;
+ // HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ STARTPROFILE
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ /* all drawn with current color */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ }
+ }
+ else {
+ /* draw points of different colors */
+ for (i=first;i<=last;i++) {
+ if (!Current->gl_ctx->VB->ClipMask[i]) {
+ int x, y;
+ unsigned long pixel=RGB(Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ }
+ }
+ }
+// DD_RELEASEDC;
+ ENDPROFILE(fast_rgb_points)
+}
+
+
+
+/* Return pointer to accerated points function */
+extern points_func choose_points_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && ctx->Visual->RGBAflag) {
+ ENDPROFILE(choose_points_function)
+ return fast_rgb_points;
+ }
+ else {
+ ENDPROFILE(choose_points_function)
+ return NULL;
+ }
+}
+
+
+
+/* Draw a line using the color specified by Current->gl_ctx->VB->Color[pv] */
+static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, GLuint v1, GLuint pv )
+{
+ STARTPROFILE
+ int x0, y0, x1, y1;
+ unsigned long pixel;
+ HDC DC=DD_GETDC;
+ HPEN Pen;
+ HPEN Old_Pen;
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ pixel = Current->pixel; /* use current color */
+ }
+ else {
+ 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);
+ }
+
+ x0 = (int) Current->gl_ctx->VB->Win[v0][0];
+ y0 = FLIP( (int) Current->gl_ctx->VB->Win[v0][1] );
+ x1 = (int) Current->gl_ctx->VB->Win[v1][0];
+ y1 = FLIP( (int) Current->gl_ctx->VB->Win[v1][1] );
+
+
+ BEGINGDICALL
+
+ Pen=CreatePen(PS_SOLID,1,pixel);
+ Old_Pen=SelectObject(DC,Pen);
+ MoveToEx(DC,x0,y0,NULL);
+ LineTo(DC,x1,y1);
+ SelectObject(DC,Old_Pen);
+ DeleteObject(Pen);
+ DD_RELEASEDC;
+
+ ENDGDICALL
+
+ ENDPROFILE(fast_flat_rgb_line)
+}
+
+
+
+/* Return pointer to accerated line function */
+static line_func choose_line_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Line.Width==1.0 && !ctx->Line.SmoothFlag && !ctx->Line.StippleFlag
+ && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && Current->rgb_flag) {
+ ENDPROFILE(choose_line_function)
+ return fast_flat_rgb_line;
+ }
+ else {
+ ENDPROFILE(choose_line_function)
+ return NULL;
+ }
+}
+
+
+/**********************************************************************/
+/***** Span-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write a horizontal span of color-index pixels with a boolean mask. */
+static void write_index_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLuint index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PBYTE Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_index_span)
+}
+
+
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current
+ * color index is used for all pixels.
+ */
+static void write_monoindex_span(GLcontext* ctx,
+ GLuint n,GLint x,GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=Current->pixel;
+ ENDPROFILE(write_monoindex_span)
+}
+
+/*
+ To improve the performance of this routine, frob the data into an actual scanline
+ and call bitblt on the complete scan line instead of SetPixel.
+*/
+
+/* Write a horizontal span of color pixels with a boolean mask. */
+static void write_color_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte
+ red[], const GLubyte green[],
+ const GLubyte blue[], const GLubyte alpha[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i,red[i], green[i], blue[i]);
+ }
+
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, red[i], green[i], blue[i]);
+ }
+
+ DD_RELEASEDC;
+
+ }
+
+ else
+ {
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ y=FLIP(y);
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=GetNearestPaletteIndex(Current->hPal,RGB(red[i],green[i],blue[i]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i]=GetNearestPaletteIndex(Current->hPal,RGB(red[i],green[i],blue[i]));
+ }
+ }
+ ENDPROFILE(write_color_span)
+
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_monocolor_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+
+ if(Current->rgb_flag==GL_TRUE){
+ for (i=0; i<n; i++)
+ if (mask[i])
+// Trying
+ wmSetPixel(pwc,y,x+i,GetRValue(Current->pixel), GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ else {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(DC, y, x+i, Current->pixel);
+ }
+
+ DD_RELEASEDC;
+
+ ENDPROFILE(write_monocolor_span)
+}
+
+
+
+/**********************************************************************/
+/***** Array-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write an array of pixels with a boolean mask. */
+static void write_index_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = index[i];
+ }
+ }
+ ENDPROFILE(write_index_pixels)
+}
+
+
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * index is used for all pixels.
+ */
+static void write_monoindex_pixels( GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ BYTE *Mem=Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i];
+ *Mem = Current->pixel;
+ }
+ }
+ ENDPROFILE(write_monoindex_pixels)
+}
+
+
+
+/* Write an array of pixels with a boolean mask. */
+static void write_color_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte r[], const GLubyte g[],
+ const GLubyte b[], const GLubyte a[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],r[i],g[i],b[i]);
+ DD_RELEASEDC;
+ ENDPROFILE(write_color_pixels)
+}
+
+
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_monocolor_pixels( GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ DD_RELEASEDC;
+ ENDPROFILE(write_monocolor_pixels)
+}
+
+
+
+/**********************************************************************/
+/***** Read spans/arrays of pixels *****/
+/**********************************************************************/
+
+
+/* Read a horizontal span of color-index pixels. */
+static void read_index_span( GLcontext* ctx, GLuint n, GLint x, GLint y, GLuint index[])
+{
+ STARTPROFILE
+ GLuint i;
+ BYTE *Mem=Current->ScreenMem+FLIP(y)*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ index[i]=Mem[i];
+ ENDPROFILE(read_index_span)
+
+}
+
+
+
+
+/* Read an array of color index pixels. */
+static void read_index_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint indx[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ indx[i]=*(Current->ScreenMem+FLIP(y[i])*Current->ScanWidth+x[i]);
+ }
+ }
+ ENDPROFILE(read_index_pixels)
+}
+
+
+
+/* Read a horizontal span of color pixels. */
+static void read_color_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ GLubyte red[], GLubyte green[],
+ GLubyte blue[], GLubyte alpha[] )
+{
+ STARTPROFILE
+ UINT i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+ for (i=0; i<n; i++)
+ {
+ Color=GetPixel(DC,x+i,y);
+ red[i]=GetRValue(Color);
+ green[i]=GetGValue(Color);
+ blue[i]=GetBValue(Color);
+ alpha[i]=255;
+ }
+ DD_RELEASEDC;
+ memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_color_span)
+}
+
+
+/* Read an array of color pixels. */
+static void read_color_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte red[], GLubyte green[],
+ GLubyte blue[], GLubyte alpha[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ Color=GetPixel(DC,x[i],FLIP(y[i]));
+ red[i]=GetRValue(Color);
+ green[i]=GetGValue(Color);
+ blue[i]=GetBValue(Color);
+ alpha[i]=255;
+ }
+ }
+ DD_RELEASEDC;
+ memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_color_pixels)
+}
+
+
+
+/**********************************************************************/
+/**********************************************************************/
+
+
+
+void setup_DD_pointers( GLcontext* ctx )
+{
+ ctx->Driver.UpdateState = setup_DD_pointers;
+ ctx->Driver.GetBufferSize = buffer_size;
+ ctx->Driver.Finish = finish;
+ ctx->Driver.Flush = flush;
+
+ ctx->Driver.ClearIndex = clear_index;
+ ctx->Driver.ClearColor = clear_color;
+ ctx->Driver.Clear = clear;
+
+ ctx->Driver.Index = set_index;
+ ctx->Driver.Color = set_color;
+ ctx->Driver.IndexMask = index_mask;
+ ctx->Driver.ColorMask = color_mask;
+
+ ctx->Driver.LogicOp = logicop;
+ ctx->Driver.Dither = dither;
+
+ ctx->Driver.SetBuffer = set_buffer;
+ ctx->Driver.GetBufferSize = buffer_size;
+
+ ctx->Driver.PointsFunc = choose_points_function(ctx);
+ ctx->Driver.LineFunc = choose_line_function(ctx);
+ ctx->Driver.TriangleFunc = choose_triangle_function( ctx );
+
+ /* Pixel/span writing functions: */
+ ctx->Driver.WriteColorSpan = write_color_span;
+ ctx->Driver.WriteMonocolorSpan = write_monocolor_span;
+ ctx->Driver.WriteColorPixels = write_color_pixels;
+ ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
+ ctx->Driver.WriteIndexSpan = write_index_span;
+ ctx->Driver.WriteMonoindexSpan = write_monoindex_span;
+ ctx->Driver.WriteIndexPixels = write_index_pixels;
+ ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
+
+ /* Pixel/span reading functions: */
+ ctx->Driver.ReadIndexSpan = read_index_span;
+ ctx->Driver.ReadColorSpan = read_color_span;
+ ctx->Driver.ReadIndexPixels = read_index_pixels;
+ ctx->Driver.ReadColorPixels = read_color_pixels;
+}
+
+
+/**********************************************************************/
+/***** WMesa API Functions *****/
+/**********************************************************************/
+
+
+
+#define PAL_SIZE 256
+static void GetPalette(HPALETTE Pal,RGBQUAD *aRGB)
+{
+ STARTPROFILE
+ int i;
+ HDC hdc;
+ struct
+ {
+ WORD Version;
+ WORD NumberOfEntries;
+ PALETTEENTRY aEntries[PAL_SIZE];
+ } Palette =
+ {
+ 0x300,
+ PAL_SIZE
+ };
+ hdc=GetDC(NULL);
+ if (Pal!=NULL)
+ GetPaletteEntries(Pal,0,PAL_SIZE,Palette.aEntries);
+ else
+ GetSystemPaletteEntries(hdc,0,PAL_SIZE,Palette.aEntries);
+ if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
+ {
+ for(i = 0; i <PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ Palette.aEntries[255].peRed = 255;
+ Palette.aEntries[255].peGreen = 255;
+ Palette.aEntries[255].peBlue = 255;
+ Palette.aEntries[255].peFlags = 0;
+ Palette.aEntries[0].peRed = 0;
+ Palette.aEntries[0].peGreen = 0;
+ Palette.aEntries[0].peBlue = 0;
+ Palette.aEntries[0].peFlags = 0;
+ }
+ else
+ {
+ int nStaticColors;
+ int nUsableColors;
+ nStaticColors = GetDeviceCaps(hdc, NUMCOLORS)/2;
+ for (i=0; i<nStaticColors; i++)
+ Palette.aEntries[i].peFlags = 0;
+ nUsableColors = PAL_SIZE-nStaticColors;
+ for (; i<nUsableColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (; i<PAL_SIZE-nStaticColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (i=PAL_SIZE-nStaticColors; i<PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = 0;
+ }
+ ReleaseDC(NULL,hdc);
+ for (i=0; i<PAL_SIZE; i++)
+ {
+ aRGB[i].rgbRed=Palette.aEntries[i].peRed;
+ aRGB[i].rgbGreen=Palette.aEntries[i].peGreen;
+ aRGB[i].rgbBlue=Palette.aEntries[i].peBlue;
+ aRGB[i].rgbReserved=Palette.aEntries[i].peFlags;
+ }
+ ENDPROFILE(GetPalette)
+}
+
+
+WMesaContext WMesaCreateContext( HWND hWnd, HPALETTE* Pal,
+ GLboolean rgb_flag,
+ GLboolean db_flag )
+{
+ RECT CR;
+ WMesaContext c;
+ GLboolean true_color_flag;
+ c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context));
+ if (!c)
+ return NULL;
+
+ c->Window=hWnd;
+ c->hDC = GetDC(hWnd);
+ true_color_flag = GetDeviceCaps(c->hDC, BITSPIXEL) > 8;
+#ifdef DDRAW
+ if(true_color_flag) c->rgb_flag = rgb_flag = GL_TRUE;
+#endif
+
+
+#ifdef DITHER
+ if ((true_color_flag==GL_FALSE) && (rgb_flag == GL_TRUE)){
+ c->dither_flag = GL_TRUE;
+ c->hPalHalfTone = WinGCreateHalftonePalette();
+ }
+ else
+ c->dither_flag = GL_FALSE;
+#else
+ c->dither_flag = GL_FALSE;
+#endif
+
+
+ if (rgb_flag==GL_FALSE)
+ {
+ c->rgb_flag = GL_FALSE;
+// c->pixel = 1;
+ c->db_flag = db_flag =GL_TRUE; // WinG requires double buffering
+ printf("Single buffer is not supported in color index mode, setting to double buffer.\n");
+ }
+ else
+ {
+ c->rgb_flag = GL_TRUE;
+// c->pixel = 0;
+ }
+ GetClientRect(c->Window,&CR);
+ c->width=CR.right;
+ c->height=CR.bottom;
+ if (db_flag)
+ {
+ c->db_flag = 1;
+ /* Double buffered */
+#ifndef DDRAW
+// if (c->rgb_flag==GL_TRUE && c->dither_flag != GL_TRUE )
+ {
+ wmCreateBackingStore(c, c->width, c->height);
+
+ }
+#endif
+ }
+ else
+ {
+ /* Single Buffered */
+ if (c->rgb_flag)
+ c->db_flag = 0;
+ }
+#ifdef DDRAW
+ if (DDInit(c,hWnd) == GL_FALSE) {
+ free( (void *) c );
+ exit(1);
+ }
+#endif
+
+
+ c->gl_visual = gl_create_visual(rgb_flag,
+ GL_FALSE, /* software alpha */
+ db_flag, /* db_flag */
+ 16, /* depth_bits */
+ 8, /* stencil_bits */
+ 8, /* accum_bits */
+ 8,
+ 255.0, 255.0, 255.0, 255.0,
+ 8,8,8,8 );
+
+ if (!c->gl_visual) {
+ return NULL;
+ }
+
+ /* allocate a new Mesa context */
+ c->gl_ctx = gl_create_context( c->gl_visual, NULL,c);
+
+ if (!c->gl_ctx) {
+ gl_destroy_visual( c->gl_visual );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_buffer = gl_create_framebuffer( c->gl_visual );
+ if (!c->gl_buffer) {
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_context( c->gl_ctx );
+ free(c);
+ return NULL;
+ }
+// setup_DD_pointers(c->gl_ctx);
+
+ return c;
+}
+
+void WMesaDestroyContext( void )
+{
+ WMesaContext c = Current;
+ ReleaseDC(c->Window,c->hDC);
+ WC = c;
+ if(c->hPalHalfTone != NULL)
+ DeleteObject(c->hPalHalfTone);
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_framebuffer( c->gl_buffer );
+ gl_destroy_context( c->gl_ctx );
+
+ if (c->db_flag)
+#ifdef DDRAW
+ DDFree(c);
+#else
+ wmDeleteBackingStore(c);
+#endif
+ free( (void *) c );
+//Following code is added to enable parallel render
+// Parallel render only work in double buffer mode
+#if !defined(NO_PARALLEL)
+ if(parallelMachine)
+ PRDestroyRenderBuffer();
+#endif
+// End modification
+}
+
+
+
+void /*APIENTRY*/ WMesaMakeCurrent( WMesaContext c )
+{
+ if(!c){
+ Current = c;
+ return;
+ }
+
+ //
+ // A little optimization
+ // If it already is current,
+ // don't set it again
+ //
+ if(Current == c)
+ return;
+
+ //gl_set_context( c->gl_ctx );
+ gl_make_current(c->gl_ctx, c->gl_buffer);
+ Current = c;
+ setup_DD_pointers(c->gl_ctx);
+ if (Current->gl_ctx->Viewport.Width==0) {
+ /* initialize viewport to window size */
+ gl_Viewport( Current->gl_ctx,
+ 0, 0, Current->width, Current->height );
+ }
+ if ((c->cColorBits <= 8 ) && (c->rgb_flag == GL_TRUE)){
+ WMesaPaletteChange(c->hPalHalfTone);
+ }
+}
+
+
+
+void /*APIENTRY*/ WMesaSwapBuffers( void )
+{
+ HDC DC = Current->hDC;
+ if (Current->db_flag)
+ wmFlush(Current);
+}
+
+
+
+void /*APIENTRY*/ WMesaPaletteChange(HPALETTE Pal)
+{
+ int vRet;
+ LPPALETTEENTRY pPal;
+ if (Current && (Current->rgb_flag==GL_FALSE || Current->dither_flag == GL_TRUE))
+ {
+ pPal = (PALETTEENTRY *)malloc( 256 * sizeof(PALETTEENTRY));
+ Current->hPal=Pal;
+// GetPaletteEntries( Pal, 0, 256, pPal );
+ GetPalette( Pal, pPal );
+#ifdef DDRAW
+ Current->lpDD->lpVtbl->CreatePalette(Current->lpDD,DDPCAPS_8BIT,
+ pPal, &(Current->lpDDPal), NULL);
+ if (Current->lpDDPal)
+ Current->lpDDSPrimary->lpVtbl->SetPalette(Current->lpDDSPrimary,Current->lpDDPal);
+#else
+ vRet = SetDIBColorTable(Current->dib.hDC,0,256,pPal);
+#endif
+ free( pPal );
+ }
+
+}
+
+
+
+
+static unsigned char threeto8[8] = {
+ 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
+};
+
+static unsigned char twoto8[4] = {
+ 0, 0x55, 0xaa, 0xff
+};
+
+static unsigned char oneto8[2] = {
+ 0, 255
+};
+
+static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift)
+{
+ unsigned char val;
+
+ val = i >> shift;
+ switch (nbits) {
+
+ case 1:
+ val &= 0x1;
+ return oneto8[val];
+
+ case 2:
+ val &= 0x3;
+ return twoto8[val];
+
+ case 3:
+ val &= 0x7;
+ return threeto8[val];
+
+ default:
+ return 0;
+ }
+}
+
+void /*WINAPI*/ wmCreatePalette( PWMC pwdc )
+{
+ /* Create a compressed and re-expanded 3:3:2 palette */
+ int i;
+ LOGPALETTE *pPal;
+ BYTE rb, rs, gb, gs, bb, bs;
+
+ pwdc->nColors = 0x100;
+
+ pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) );
+
+ pPal->palVersion = 0x300;
+
+ rb = REDBITS;
+ rs = REDSHIFT;
+ gb = GREENBITS;
+ gs = GREENSHIFT;
+ bb = BLUEBITS;
+ bs = BLUESHIFT;
+
+ if (pwdc->db_flag) {
+
+ /* Need to make two palettes: one for the screen DC and one for the DIB. */
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ pwdc->hPalette = CreatePalette( pPal );
+ }
+
+ else {
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ }
+
+ free(pPal);
+
+}
+
+void /*WINAPI*/ wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
+{
+ if(Current->db_flag){
+ LPBYTE lpb = pwc->pbPixels;
+ LPDWORD lpdw;
+ LPWORD lpw;
+ UINT nBypp = pwc->cColorBits / 8;
+ UINT nOffset = iPixel % nBypp;
+
+ // Move the pixel buffer pointer to the scanline that we
+ // want to access
+
+// pwc->dib.fFlushed = FALSE;
+
+ lpb += pwc->ScanWidth * iScanLine;
+ // Now move to the desired pixel
+ lpb += iPixel * nBypp;
+ lpb = PIXELADDR(iPixel, iScanLine);
+ lpdw = (LPDWORD)lpb;
+ lpw = (LPWORD)lpb;
+
+ if(nBypp == 1){
+ if(pwc->dither_flag)
+ *lpb = DITHER_RGB_2_8BIT(r,g,b,iScanLine,iPixel);
+ else
+ *lpb = BGR8(r,g,b);
+ }
+ else if(nBypp == 2)
+ *lpw = BGR16(r,g,b);
+ else if (nBypp == 3){
+ *lpdw = BGR24(r,g,b);
+ }
+ else if (nBypp == 4)
+ *lpdw = BGR32(r,g,b);
+ }
+ else{
+ HDC DC = DD_GETDC;
+ SetPixel(DC, iPixel, iScanLine, RGB(r,g,b));
+ DD_RELEASEDC;
+ }
+}
+
+void /*WINAPI*/ wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+)
+{
+ DWORD dwSize = 0;
+ DWORD dwScanWidth;
+ UINT nBypp = pwc->cColorBits / 8;
+ HDC hic;
+
+ dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3);
+
+ pwc->ScanWidth =pwc->pitch = dwScanWidth;
+
+ if (stereo_flag)
+ pwc->ScanWidth = 2* pwc->pitch;
+
+ dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height);
+
+ pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE,
+ NULL,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0,
+ dwSize,
+ NULL);
+
+ if (!pwc->dib.hFileMap)
+ return;
+
+ pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap,
+ FILE_MAP_ALL_ACCESS,
+ 0,
+ 0,
+ 0);
+
+ if(!pwc->dib.base){
+ CloseHandle(pwc->dib.hFileMap);
+ return;
+ }
+
+// pwc->pbPixels = pwc->addrOffScreen = ((LPBYTE)pwc->dib.base) + sizeof(BITMAPINFO);
+
+// pwc->dib.hDC = CreateCompatibleDC(hDC);
+
+ CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO));
+
+ hic = CreateIC("display", NULL, NULL, NULL);
+ pwc->dib.hDC = CreateCompatibleDC(hic);
+
+
+/* pwc->hbmDIB = CreateDIBitmap(hic,
+ &(pwc->bmi.bmiHeader),
+ CBM_INIT,
+ pwc->pbPixels,
+ &(pwc->bmi),
+ DIB_RGB_COLORS);
+*/
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ (iUsage ? DIB_PAL_COLORS : DIB_RGB_COLORS),
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ /*
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi),
+ DIB_RGB_COLORS,
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ */
+ pwc->ScreenMem = pwc->addrOffScreen = pwc->pbPixels;
+ pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB);
+
+ DeleteDC(hic);
+
+ return;
+
+}
+
+//
+// Blit memory DC to screen DC
+//
+BOOL /*WINAPI*/ wmFlush(PWMC pwc)
+{
+ BOOL bRet = 0;
+ DWORD dwErr = 0;
+ HRESULT ddrval;
+
+ // Now search through the torus frames and mark used colors
+ if(pwc->db_flag){
+#ifdef DDRAW
+ if (pwc->lpDDSOffScreen == NULL)
+ if(DDCreateOffScreen(pwc) == GL_FALSE)
+ return;
+
+ pwc->lpDDSOffScreen->lpVtbl->Unlock(pwc->lpDDSOffScreen, NULL);
+
+ while( 1 )
+ {
+ ddrval = pwc->lpDDSPrimary->lpVtbl->Blt( pwc->lpDDSPrimary,
+ &(pwc->rectSurface), pwc->lpDDSOffScreen, &(pwc->rectOffScreen), 0, NULL );
+
+ if( ddrval == DD_OK )
+ {
+ break;
+ }
+ if( ddrval == DDERR_SURFACELOST )
+ {
+ if(!DDRestoreAll(pwc))
+ {
+ break;
+ }
+ }
+ if( ddrval != DDERR_WASSTILLDRAWING )
+ {
+ break;
+ }
+ }
+
+ while (pwc->lpDDSOffScreen->lpVtbl->Lock(pwc->lpDDSOffScreen,
+ NULL, &(pwc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+
+ if(ddrval != DD_OK)
+ dwErr = GetLastError();
+#else
+ bRet = BitBlt(pwc->hDC, 0, 0, pwc->width, pwc->height,
+ pwc->dib.hDC, 0, 0, SRCCOPY);
+#endif
+ }
+
+ return(TRUE);
+
+}
+
+
+// The following code is added by Li Wei to enable stereo display
+
+#if !defined(NO_STEREO)
+
+void WMesaShowStereo(GLuint list)
+{
+
+ GLbitfield mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
+ GLfloat cm[16];
+ GLint matrix_mode;
+ // Must use double Buffer
+ if( ! Current-> db_flag )
+ return;
+
+
+ glGetIntegerv(GL_MATRIX_MODE,&matrix_mode);
+
+// glPushMatrix(); //****
+ WMesaViewport(Current->gl_ctx,0,Current->height/2,Current->width,Current->height/2);
+// Current->gl_ctx->NewState = 0;
+
+ // glViewport(0,0,Current->width,Current->height/2);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(GL_MODELVIEW);
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(viewDistance/2,0.0,0.0 ,
+ viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+// glTranslatef(viewDistance/2.0,0.,0.);
+ glMultMatrixf( cm );
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen;
+ //glPushMatrix();
+ glCallList( list );
+ //glPopMatrix();
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glLoadIdentity();
+ gluLookAt(-viewDistance/2,0.0,0.0 ,
+ -viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+// glTranslatef(-viewDistance/2.0,0.,0.);
+ glMultMatrixf(cm);
+
+ Current->ScreenMem = Current->pbPixels = Current->addrOffScreen + Current->pitch;
+ glCallList(list);
+ if(matrix_mode!=GL_MODELVIEW)
+ glMatrixMode(matrix_mode);
+
+// glPopMatrix();
+ glFlush();
+
+ WMesaViewport(Current->gl_ctx,0,0,Current->width,Current->height);
+// Current->gl_ctx->NewState = 0;
+ WMesaSwapBuffers();
+
+}
+
+void toggleStereoMode()
+{
+ if(!Current->db_flag)
+ return;
+ if(!stereo_flag){
+ stereo_flag = 1;
+ if(stereoBuffer==GL_FALSE)
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ {
+ Current->ScanWidth = Current->pitch*2;
+ }
+ }
+ else {
+ stereo_flag = 0;
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ Current->ScanWidth = Current->pitch;
+ Current->pbPixels = Current->addrOffScreen;
+ }
+}
+
+/* if in stereo mode, the following function is called */
+void glShowStereo(GLuint list)
+{
+ WMesaShowStereo(list);
+}
+
+#endif // End if NO_STEREO not defined
+
+#if !defined(NO_PARALLEL)
+
+void toggleParallelMode(void)
+{
+ if(!parallelFlag){
+ parallelFlag = GL_TRUE;
+ if(parallelMachine==GL_FALSE){
+ PRCreateRenderBuffer( Current->rgb_flag? GL_RGBA :GL_COLOR_INDEX,
+ Current->cColorBits/8,
+ Current->width ,Current->height,
+ Current->ScanWidth,
+ Current->rgb_flag? Current->pbPixels: Current->ScreenMem);
+ parallelMachine = GL_TRUE;
+ }
+ }
+ else {
+ parallelFlag = GL_FALSE;
+ if(parallelMachine==GL_TRUE){
+ PRDestroyRenderBuffer();
+ parallelMachine=GL_FALSE;
+ ReadyForNextFrame = GL_TRUE;
+ }
+
+/***********************************************
+// Seems something wrong!!!!
+************************************************/
+
+ WMesaMakeCurrent(Current);
+#if !defined(NO_STEREO)
+ stereo_flag = GL_FALSE ;
+#endif
+ }
+}
+
+void PRShowRenderResult(void)
+{
+ int flag = 0;
+if(!glImageRendered())
+ return;
+
+ if (parallelFlag)
+ {
+ WMesaSwapBuffers();
+ }
+
+}
+#endif //End if NO_PARALLEL not defined
+
+//end modification
+
+BYTE DITHER_RGB_2_8BIT( int red, int green, int blue, int pixel, int scanline)
+{
+ char unsigned redtemp, greentemp, bluetemp, paletteindex;
+
+ //*** now, look up each value in the halftone matrix
+ //*** using an 8x8 ordered dither.
+ redtemp = aDividedBy51[red]
+ + (aModulo51[red] > aHalftone8x8[(pixel%8)*8
+ + scanline%8]);
+ greentemp = aDividedBy51[(char unsigned)green]
+ + (aModulo51[green] > aHalftone8x8[
+ (pixel%8)*8 + scanline%8]);
+ bluetemp = aDividedBy51[(char unsigned)blue]
+ + (aModulo51[blue] > aHalftone8x8[
+ (pixel%8)*8 +scanline%8]);
+
+ //*** recombine the halftoned rgb values into a palette index
+ paletteindex =
+ redtemp + aTimes6[greentemp] + aTimes36[bluetemp];
+
+ //*** and translate through the wing halftone palette
+ //*** translation vector to give the correct value.
+ return aWinGHalftoneTranslation[paletteindex];
+}
+
+#ifdef DDRAW
+/*
+ * restoreAll
+ *
+ * restore all lost objects
+ */
+HRESULT DDRestoreAll( WMesaContext wc )
+{
+ HRESULT ddrval;
+
+ ddrval = wc->lpDDSPrimary->lpVtbl->Restore(wc->lpDDSPrimary);
+ if( ddrval == DD_OK )
+ {
+ ddrval = wc->lpDDSOffScreen->lpVtbl->Restore(wc->lpDDSOffScreen);
+ }
+ return ddrval;
+
+} /* restoreAll */
+
+
+/*
+ * This function is called if the initialization function fails
+ */
+BOOL initFail( HWND hwnd, WMesaContext wc )
+{
+ DDFree(wc);
+ MessageBox( hwnd, "DirectDraw Init FAILED", "", MB_OK );
+ return FALSE;
+
+} /* initFail */
+
+
+static void DDDeleteOffScreen(WMesaContext wc)
+{
+ if( wc->lpDDSOffScreen != NULL )
+ {
+ wc->lpDDSOffScreen->lpVtbl->Unlock(wc->lpDDSOffScreen,NULL);
+ wc->lpDDSOffScreen->lpVtbl->Release(wc->lpDDSOffScreen);
+ wc->lpDDSOffScreen = NULL;
+ }
+
+}
+
+static void DDFreePrimarySurface(WMesaContext wc)
+{
+ if( wc->lpDDSPrimary != NULL )
+ {
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->ReleaseDC(wc->lpDDSPrimary, wc->hDC);
+ wc->lpDDSPrimary->lpVtbl->Release(wc->lpDDSPrimary);
+ wc->lpDDSPrimary = NULL;
+ }
+}
+
+static BOOL DDCreatePrimarySurface(WMesaContext wc)
+{
+ HRESULT ddrval;
+ DDSCAPS ddscaps;
+ wc->ddsd.dwSize = sizeof( wc->ddsd );
+ wc->ddsd.dwFlags = DDSD_CAPS;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD,&(wc->ddsd), &(wc->lpDDSPrimary), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(wc->hwnd , wc);
+ }
+ if(wc->db_flag == GL_FALSE)
+ wc->lpDDSPrimary->lpVtbl->GetDC(wc->lpDDSPrimary, wc->hDC);
+ return TRUE;
+}
+
+static BOOL DDCreateOffScreen(WMesaContext wc)
+{
+ POINT pt;
+ HRESULT ddrval;
+ if(wc->lpDD == NULL)
+ return FALSE;
+ GetClientRect( wc->hwnd, &(wc->rectOffScreen) );
+ wc->ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
+ wc->ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
+ wc->ddsd.dwHeight = wc->rectOffScreen.bottom - wc->rectOffScreen.top;
+ wc->ddsd.dwWidth = wc->rectOffScreen.right - wc->rectOffScreen.left;
+
+ ddrval = wc->lpDD->lpVtbl->CreateSurface( wc->lpDD, &(wc->ddsd), &(wc->lpDDSOffScreen), NULL );
+ if( ddrval != DD_OK )
+ {
+ return FALSE;
+ }
+
+ while (wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), 0, NULL) == DDERR_WASSTILLDRAWING)
+ ;
+// while ((ddrval = wc->lpDDSOffScreen->lpVtbl->Lock(wc->lpDDSOffScreen,NULL, &(wc->ddsd), DDLOCK_SURFACEMEMORYPTR , NULL)) != DD_OK)
+ ;
+ if(wc->ddsd.lpSurface==NULL)
+ return initFail(wc->hwnd, wc);
+
+ wc->ScreenMem = wc->pbPixels = wc->addrOffScreen = (PBYTE)(wc->ddsd.lpSurface);
+ wc->ScanWidth = wc->pitch = wc->ddsd.lPitch;
+ if (stereo_flag)
+ wc->ScanWidth = wc->ddsd.lPitch*2;
+
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ wmSetPixelFormat(wc, wc->hDC);
+ return TRUE;
+}
+
+/*
+ * doInit - do work required for every instance of the application:
+ * create the window, initialize data
+ */
+static BOOL DDInit( WMesaContext wc, HWND hwnd)
+{
+ HRESULT ddrval;
+ DWORD dwFrequency;
+
+ LPDIRECTDRAW lpDD; // DirectDraw object
+ LPDIRECTDRAW2 lpDD2;
+
+
+ wc->fullScreen = displayOptions.fullScreen;
+ wc->gMode = displayOptions.mode;
+ wc->hwnd = hwnd;
+ stereo_flag = displayOptions.stereo;
+ if(wc->db_flag!= GL_TRUE)
+ stereo_flag = GL_FALSE;
+ /*
+ * create the main DirectDraw object
+ */
+ ddrval = DirectDrawCreate( NULL, &(wc->lpDD), NULL );
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd,wc);
+ }
+
+ // Get exclusive mode if requested
+ if(wc->fullScreen)
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
+ }
+ else
+ {
+ ddrval = wc->lpDD->lpVtbl->SetCooperativeLevel( wc->lpDD, hwnd, DDSCL_NORMAL );
+ }
+ if( ddrval != DD_OK )
+ {
+ return initFail(hwnd , wc);
+ }
+
+
+/* ddrval = wc->lpDD->lpVtbl->QueryInterface(wc->lpDD, IID_IDirectDraw2,
+ (LPVOID *)((wc->lpDD2)));
+
+*/
+ if(ddrval != DD_OK)
+ return initFail(hwnd , wc);
+
+
+ //ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+ // wc->lpDD2->lpVtbl->GetMonitorFrequency(wc->lpDD, &dwFrequency);
+ switch( wc->gMode )
+ {
+ case 1: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 640, 480, displayOptions.bpp); break;
+ case 2: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 800, 600, displayOptions.bpp); break;
+ case 3: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1024, 768, displayOptions.bpp); break;
+ case 4: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1152, 864, displayOptions.bpp); break;
+ case 5: ddrval = wc->lpDD->lpVtbl->SetDisplayMode( wc->lpDD, 1280, 1024, displayOptions.bpp); break;
+ }
+
+ if( ddrval != DD_OK )
+ {
+ printf("Can't modify display mode, current mode used\n");
+// return initFail(hwnd , wc);
+ }
+//ddrval = wc->lpDD->lpVtbl->GetDisplayMode( wc->lpDD, &(wc->ddsd));
+switch(ddrval){
+case DDERR_INVALIDOBJECT:
+ break;
+case DDERR_INVALIDPARAMS:
+ break;
+case DDERR_UNSUPPORTEDMODE:
+ ;
+}
+
+ if(DDCreatePrimarySurface(wc) == GL_FALSE)
+ return initFail(hwnd, wc);
+
+ if(wc->db_flag)
+ return DDCreateOffScreen(wc);
+} /* DDInit */
+
+static void DDFree( WMesaContext wc)
+{
+ if( wc->lpDD != NULL )
+ {
+ DDFreePrimarySurface(wc);
+ DDDeleteOffScreen(wc);
+ wc->lpDD->lpVtbl->Release(wc->lpDD);
+ wc->lpDD = NULL;
+ }
+ // Clean up the screen on exit
+ RedrawWindow( NULL, NULL, NULL, RDW_INVALIDATE | RDW_ERASE |
+ RDW_ALLCHILDREN );
+
+}
+#endif
+
+void WMesaMove(void)
+{
+ WMesaContext wc = Current;
+ POINT pt;
+ if (Current != NULL){
+ GetClientRect( wc->hwnd, &(wc->rectSurface) );
+ pt.x = pt.y = 0;
+ ClientToScreen( wc->hwnd, &pt );
+ OffsetRect(&(wc->rectSurface), pt.x, pt.y);
+ }
+}
+
+/*
+ * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
+ * shortcut.
+ */
+#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
+
+
+/**********************************************************************/
+/*** Triangle rendering ***/
+/**********************************************************************/
+
+
+
+/*
+ * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
+ */
+static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+
+/*
+ * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
+ */
+static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+/*
+ * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, depth-buffered, PF_8R8G8B triangle.
+ */
+static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, depth-buffered, PF_5R6G5B triangle.
+ */
+static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = p; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8B8G8R( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
+ */
+static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_8R8G8B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
+ */
+static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = PACK_5R6G5B( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb) ); \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+
+/*
+ * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
+ */
+static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
+ GLuint v1, GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8B8G8R( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
+ */
+static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR4(X,Y)
+#define PIXEL_TYPE GLuint
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_8R8G8B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
+ */
+static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define PIXEL_ADDRESS(X,Y) PIXELADDR2(X,Y)
+#define PIXEL_TYPE GLushort
+//#define BYTES_PER_ROW (wmesa->xm_buffer->backimage->bytes_per_line)
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ unsigned long p = PACK_5R6G5B( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2] );
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = p; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
+ */
+
+static void smooth_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = FixedToInt(ffi); \
+ zRow[i] = z; \
+ } \
+ ffi += fdidx; \
+ ffz += fdzdx; \
+ } \
+}
+
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
+ */
+
+static void flat_ci_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->Index[pv]; \
+ if (!VB->MonoColor) { \
+ /* set the color index */ \
+ (*ctx->Driver.Index)( ctx, index ); \
+ }
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ for (i=0;i<len;i++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ pRow[i] = index; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+
+/*
+ * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+ */
+
+static void smooth_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define INTERP_INDEX 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = FixedToInt(ffi); \
+ ffi += fdidx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+/*
+ * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
+ */
+static void flat_ci_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define SETUP_CODE \
+ GLuint index = VB->Index[pv]; \
+ if (!VB->MonoColor) { \
+ /* set the color index */ \
+ (*ctx->Driver.Index)( ctx, index ); \
+ }
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx; \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ *pixel = index; \
+ } \
+}
+#include "tritemp.h"
+}
+
+/*
+ * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
+ */
+static void smooth_DITHER8_z_triangle( GLcontext *ctx,
+ GLuint v0, GLuint v1, GLuint v2,
+ GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb), xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+/*
+ * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
+ */
+static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_Z 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, xx = LEFT, yy = FLIP(Y), len = RIGHT-LEFT; \
+ for (i=0;i<len;i++,xx++) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
+ pRow[i] = pixelDithered; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+/*
+ * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
+ */
+static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define INTERP_RGB 1
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], VB->Color[pv][1], VB->Color[pv][2], xx, yy);\
+ *pixel = pixelDithered; \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; \
+ } \
+}
+#include "tritemp.h"
+}
+
+/*
+ * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
+ */
+
+static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ DITHER_RGB_TO_8BIT_SETUP
+#define PIXEL_ADDRESS(X,Y) PIXELADDR1(X,Y)
+#define PIXEL_TYPE GLubyte
+#define BYTES_PER_ROW (wmesa->ScanWidth)
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint xx, yy = FLIP(Y); \
+ PIXEL_TYPE *pixel = pRow; \
+ for (xx=LEFT;xx<RIGHT;xx++,pixel++) { \
+ DITHER_RGB_TO_8BIT( VB->Color[pv][0], \
+ VB->Color[pv][1], VB->Color[pv][2], xx, yy); \
+ *pixel = pixelDithered; \
+ } \
+}
+#include "tritemp.h"
+}
+
+
+
+
+static triangle_func choose_triangle_function( GLcontext *ctx )
+{
+ WMesaContext wmesa = (WMesaContext) ctx->DriverCtx;
+ int depth = wmesa->cColorBits;
+
+ if (ctx->Polygon.SmoothFlag) return NULL;
+ if (ctx->Texture.Enabled) return NULL;
+ if (!wmesa->db_flag) return NULL;
+ /*if (wmesa->xm_buffer->buffer==XIMAGE)*/ {
+ if ( ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return smooth_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->Light.ShadeModel==GL_FLAT
+ && ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_z_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_z_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_z_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_z_triangle;
+ case PF_INDEX8:
+ return flat_ci_z_triangle;
+ default:
+ return NULL;
+ }
+ }
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_SMOOTH
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return smooth_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return smooth_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return smooth_5R6G5B_triangle;
+ case PF_DITHER8:
+ return smooth_DITHER8_triangle;
+ case PF_INDEX8:
+ return smooth_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ if ( ctx->RasterMask==0 /* no depth test */
+ && ctx->Light.ShadeModel==GL_FLAT
+ && ctx->Polygon.StippleFlag==GL_FALSE) {
+ switch (wmesa->pixelformat) {
+ case PF_8A8B8G8R:
+ return flat_8A8B8G8R_triangle;
+ case PF_8R8G8B:
+ return flat_8R8G8B_triangle;
+ case PF_5R6G5B:
+ return flat_5R6G5B_triangle;
+ case PF_DITHER8:
+ return flat_DITHER8_triangle;
+ case PF_INDEX8:
+ return flat_ci_triangle;
+ default:
+ return NULL;
+ }
+ }
+
+ return NULL;
+ }
+}
+
+/*
+ * Define a new viewport and reallocate auxillary buffers if the size of
+ * the window (color buffer) has changed.
+ */
+void WMesaViewport( GLcontext *ctx,
+ GLint x, GLint y, GLsizei width, GLsizei height )
+{
+ /* Save viewport */
+ ctx->Viewport.X = x;
+ ctx->Viewport.Width = width;
+ ctx->Viewport.Y = y;
+ ctx->Viewport.Height = height;
+
+ /* compute scale and bias values */
+ ctx->Viewport.Sx = (GLfloat) width / 2.0F;
+ ctx->Viewport.Tx = ctx->Viewport.Sx + x;
+ ctx->Viewport.Sy = (GLfloat) height / 2.0F;
+ ctx->Viewport.Ty = ctx->Viewport.Sy + y;
+}
diff --git a/src/mesa/drivers/windows/wmesa_stereo.c b/src/mesa/drivers/windows/wmesa_stereo.c
new file mode 100644
index 00000000000..ea721a13b66
--- /dev/null
+++ b/src/mesa/drivers/windows/wmesa_stereo.c
@@ -0,0 +1,1872 @@
+/*
+ WMesa_stereo.c
+*/
+// Stereo display feature added by Li Wei
+// Updated 1996/10/06 11:16:15 CST
+// Paralell render feature added by Li Wei
+// http://sun.aiar.xjtu.edu.cn
+
+#define WMESA_STEREO_C
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wmesadef.h>
+
+#include <GL\wmesa.h>
+#include "context.h"
+#include "dd.h"
+#include "xform.h"
+#include "vb.h"
+#include "matrix.h"
+#include "depth.h"
+
+#ifdef PROFILE
+ #include "profile.h"
+#endif
+
+#include <wing.h>
+
+// Code added by Li Wei to enable stereo display and Paralell render
+
+
+/*#include "mesa_extend.h"*/
+
+#if !defined(NO_STEREO)
+
+ #include "gl\glu.h"
+ #include "stereo.h"
+
+ PBYTE Buffer_Stereo;
+
+ void WMesaCreateStereoBuffer(void);
+
+ void WMesaInterleave( GLenum aView);
+
+ void WMesaDestroyStereoBuffer(void);
+
+ void WMesaShowStereo(GLuint list);
+#endif
+#if !defined(NO_PARALLEL)
+ #include "parallel.h"
+#endif
+
+/* end of added code*/
+
+/* Bit's used for dest: */
+#define FRONT_PIXMAP 1
+#define BACK_PIXMAP 2
+#define BACK_XIMAGE 4
+
+static PWMC Current = NULL;
+WMesaContext WC = NULL;
+
+#ifdef NDEBUG
+ #define assert(ignore) ((void) 0)
+#else
+ void Mesa_Assert(void *Cond,void *File,unsigned Line)
+ {
+ char Msg[512];
+ sprintf(Msg,"%s %s %d",Cond,File,Line);
+ MessageBox(NULL,Msg,"Assertion failed.",MB_OK);
+ exit(1);
+ }
+ #define assert(e) if (!e) Mesa_Assert(#e,__FILE__,__LINE__);
+#endif
+
+#define DD_GETDC ((Current->db_flag) ? Current->dib.hDC : Current->hDC )
+#define DD_RELEASEDC
+
+//#define BEGINGDICALL if(Current->rgb_flag)wmFlushBits(Current);
+#define BEGINGDICALL
+//#define ENDGDICALL if(Current->rgb_flag)wmGetBits(Current);
+#define ENDGDICALL
+
+#define FLIP(Y) (Current->height-(Y)-1)
+
+#define STARTPROFILE
+#define ENDPROFILE(PARA)
+
+static void FlushToFile(PWMC pwc, PSTR szFile);
+
+BOOL wmCreateBackingStore(PWMC pwc, long lxSize, long lySize);
+
+BOOL wmDeleteBackingStore(PWMC pwc);
+
+void wmCreatePalette( PWMC pwdc );
+BOOL wmSetDibColors(PWMC pwc);
+void wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b);
+
+void wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+ );
+
+BOOL wmFlush(PWMC pwc);
+
+/*
+ * Useful macros:
+ Modified from file osmesa.c
+ */
+
+#define PIXELADDR(X,Y) ((GLbyte *)Current->pbPixels + (Current->height-Y)* Current->ScanWidth + (X)*nBypp)
+
+
+/* Finish all pending operations and synchronize. */
+static void finish(GLcontext* ctx)
+{
+ /* no op */
+}
+
+
+//
+// We cache all gl draw routines until a flush is made
+//
+static void flush(GLcontext* ctx)
+{
+ STARTPROFILE
+ if(Current->rgb_flag && !(Current->dib.fFlushed)&&!(Current->db_flag)){
+ wmFlush(Current);
+ }
+ ENDPROFILE(flush)
+
+}
+
+
+
+/*
+ * Set the color index used to clear the color buffer.
+ */
+static void clear_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->clearpixel = index;
+ ENDPROFILE(clear_index)
+}
+
+
+
+/*
+ * Set the color used to clear the color buffer.
+ */
+static void clear_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->clearpixel=RGB(r, g, b );
+ ENDPROFILE(clear_color)
+}
+
+
+
+/*
+ * Clear the specified region of the color buffer using the clear color
+ * or index as specified by one of the two functions above.
+ */
+static void clear(GLcontext* ctx,
+ GLboolean all,GLint x, GLint y, GLint width, GLint height )
+{
+ DWORD dwColor;
+ WORD wColor;
+ LPDWORD lpdw = (LPDWORD)Current->pbPixels;
+ LPWORD lpw = (LPWORD)Current->pbPixels;
+ LPBYTE lpb = Current->pbPixels;
+
+ STARTPROFILE
+
+ if (all){
+ x=y=0;
+ width=Current->width;
+ height=Current->height;
+ }
+ if (Current->rgb_flag==GL_TRUE){
+ if(Current->db_flag==GL_TRUE){
+ UINT nBypp = Current->cColorBits / 8;
+ int i = 0;
+ int iSize;
+
+ if(nBypp == 2){
+ iSize = (Current->width * Current->height) / nBypp;
+
+ wColor = BGR16(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ dwColor = MAKELONG(wColor, wColor);
+ }
+ else if(nBypp == 4){
+ iSize = (Current->width * Current->height);
+
+ dwColor = BGR32(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+ }
+ //
+ // This is the 24bit case
+ //
+ else {
+
+ iSize = (Current->width * Current->height) / nBypp;
+
+ dwColor = BGR24(GetRValue(Current->clearpixel),
+ GetGValue(Current->clearpixel),
+ GetBValue(Current->clearpixel));
+
+
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpb += nBypp;
+ lpdw = (LPDWORD)lpb;
+ i++;
+ }
+
+ // ENDPROFILE(clear)
+
+ return;
+ }
+
+ while(i < iSize){
+ *lpdw = dwColor;
+ lpdw++;
+ i++;
+ }
+ }
+ else{ // For single buffer
+ HDC DC=DD_GETDC;
+ HPEN Pen=CreatePen(PS_SOLID,1,Current->clearpixel);
+ HBRUSH Brush=CreateSolidBrush(Current->clearpixel);
+ HPEN Old_Pen=SelectObject(DC,Pen);
+ HBRUSH Old_Brush=SelectObject(DC,Brush);
+ Rectangle(DC,x,y,x+width,y+height);
+ SelectObject(DC,Old_Pen);
+ SelectObject(DC,Old_Brush);
+ DeleteObject(Pen);
+ DeleteObject(Brush);
+ DD_RELEASEDC;
+ }
+ }
+ else {
+ int i;
+ char *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ for (i=0; i<height; i++){
+ memset(Mem,Current->clearpixel,width);
+ Mem+=width;
+ }
+ }
+ ENDPROFILE(clear)
+}
+
+
+
+/* Set the current color index. */
+static void set_index(GLcontext* ctx, GLuint index)
+{
+ STARTPROFILE
+ Current->pixel=index;
+ ENDPROFILE(set_index)
+}
+
+
+
+/* Set the current RGBA color. */
+static void set_color( GLcontext* ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a )
+{
+ STARTPROFILE
+ Current->pixel = RGB( r, g, b );
+ ENDPROFILE(set_color)
+}
+
+
+
+/* Set the index mode bitplane mask. */
+static GLboolean index_mask(GLcontext* ctx, GLuint mask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/* Set the RGBA drawing mask. */
+static GLboolean color_mask( GLcontext* ctx,
+ GLboolean rmask, GLboolean gmask,
+ GLboolean bmask, GLboolean amask)
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+
+/*
+ * Set the pixel logic operation. Return GL_TRUE if the device driver
+ * can perform the operation, otherwise return GL_FALSE. If GL_FALSE
+ * is returned, the logic op will be done in software by Mesa.
+ */
+GLboolean logicop( GLcontext* ctx, GLenum op )
+{
+ /* can't implement */
+ return GL_FALSE;
+}
+
+
+static void dither( GLcontext* ctx, GLboolean enable )
+{
+ /* No op */
+}
+
+
+
+static GLboolean set_buffer( GLcontext* ctx, GLenum mode )
+{
+ STARTPROFILE
+ /* TODO: this could be better */
+ if (mode==GL_FRONT || mode==GL_BACK) {
+ return GL_TRUE;
+ }
+ else {
+ return GL_FALSE;
+ }
+ ENDPROFILE(set_buffer)
+}
+
+
+
+/* Return characteristics of the output buffer. */
+static void buffer_size( GLcontext* ctx, GLuint *width, GLuint *height /*, GLuint *depth */)
+{
+
+ int New_Size;
+ RECT CR;
+
+ STARTPROFILE
+ GetClientRect(Current->Window,&CR);
+
+ *width=CR.right;
+ *height=CR.bottom;
+// *depth = Current->depth;
+
+ New_Size=((*width)!=Current->width) || ((*height)!=Current->height);
+
+ if (New_Size){
+ Current->width=*width;
+ Current->height=*height;
+ Current->ScanWidth=Current->width;
+ if ((Current->ScanWidth%sizeof(long))!=0)
+ Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
+
+ if (Current->db_flag){
+ if (Current->rgb_flag==GL_TRUE){
+ wmDeleteBackingStore(Current);
+ wmCreateBackingStore(Current, Current->width, Current->height);
+ }
+ else{
+ Current->ScanWidth=Current->width;
+ if ((Current->ScanWidth%sizeof(long))!=0)
+ Current->ScanWidth+=(sizeof(long)-(Current->ScanWidth%sizeof(long)));
+
+ Current->IndexFormat->bmiHeader.biWidth=Current->width;
+
+ if (Current->IndexFormat->bmiHeader.biHeight<0)
+ Current->IndexFormat->bmiHeader.biHeight=-(Current->height);
+ else
+ Current->IndexFormat->bmiHeader.biHeight=Current->height;
+
+ Current->Compat_BM=WinGCreateBitmap(Current->dib.hDC,Current->IndexFormat,&((void *) Current->ScreenMem));
+
+ DeleteObject(SelectObject(Current->dib.hDC,Current->Compat_BM));
+ }
+//Code added by Li Wei to enable stereo display
+// Recreate stereo buffer when stereo_flag is TRUE while parallelFlag is FALSE
+#if !defined(NO_STEREO)
+ if(stereo_flag
+#if !defined(NO_PARALLEL)
+ &&!parallelFlag
+#endif
+ ) {
+ if(stereoBuffer == GL_TRUE)
+ WMesaDestroyStereoBuffer();
+ WMesaCreateStereoBuffer();
+ }
+#endif
+// Resize OsmesaBuffer if in Parallel mode
+#if !defined(NO_PARALLEL)
+ if(parallelFlag)
+ PRSizeRenderBuffer(Current->width, Current->height,Current->ScanWidth,
+ Current->rgb_flag == GL_TRUE ? Current->pbPixels: Current->ScreenMem);
+#endif
+//end modification
+
+ }
+ }
+
+ ENDPROFILE(buffer_size)
+}
+
+
+
+/**********************************************************************/
+/***** Accelerated point, line, polygon rendering *****/
+/**********************************************************************/
+
+
+static void fast_rgb_points( GLcontext* ctx, GLuint first, GLuint last )
+{
+ GLuint i;
+ // HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ STARTPROFILE
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ /* all drawn with current color */
+ for (i=first;i<=last;i++) {
+ if (Current->gl_ctx->VB->ClipMask[i]==0) {
+ int x, y;
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ }
+ }
+ else {
+ /* draw points of different colors */
+ for (i=first;i<=last;i++) {
+ if (Current->gl_ctx->VB->ClipMask[i]==0) {
+ int x, y;
+ unsigned long pixel=RGB(Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ x = (GLint) Current->gl_ctx->VB->Win[i][0];
+ y = FLIP( (GLint) Current->gl_ctx->VB->Win[i][1] );
+ wmSetPixel(pwc, y,x,Current->gl_ctx->VB->Color[i][0]*255.0,
+ Current->gl_ctx->VB->Color[i][1]*255.0,
+ Current->gl_ctx->VB->Color[i][2]*255.0);
+ }
+ }
+ }
+// DD_RELEASEDC;
+ ENDPROFILE(fast_rgb_points)
+}
+
+
+
+/* Return pointer to accerated points function */
+extern points_func choose_points_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Point.Size==1.0 && !ctx->Point.SmoothFlag && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && ctx->Visual->RGBAflag) {
+ ENDPROFILE(choose_points_function)
+ return fast_rgb_points;
+ }
+ else {
+ ENDPROFILE(choose_points_function)
+ return NULL;
+ }
+}
+
+
+
+/* Draw a line using the color specified by Current->gl_ctx->VB->Color[pv] */
+static void fast_flat_rgb_line( GLcontext* ctx, GLuint v0, GLuint v1, GLuint pv )
+{
+ STARTPROFILE
+ int x0, y0, x1, y1;
+ unsigned long pixel;
+ HDC DC=DD_GETDC;
+ HPEN Pen;
+ HPEN Old_Pen;
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ pixel = Current->pixel; /* use current color */
+ }
+ else {
+ 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);
+ }
+
+ x0 = (int) Current->gl_ctx->VB->Win[v0][0];
+ y0 = FLIP( (int) Current->gl_ctx->VB->Win[v0][1] );
+ x1 = (int) Current->gl_ctx->VB->Win[v1][0];
+ y1 = FLIP( (int) Current->gl_ctx->VB->Win[v1][1] );
+
+
+ BEGINGDICALL
+
+ Pen=CreatePen(PS_SOLID,1,pixel);
+ Old_Pen=SelectObject(DC,Pen);
+ MoveToEx(DC,x0,y0,NULL);
+ LineTo(DC,x1,y1);
+ SelectObject(DC,Old_Pen);
+ DeleteObject(Pen);
+ DD_RELEASEDC;
+
+ ENDGDICALL
+
+ ENDPROFILE(fast_flat_rgb_line)
+}
+
+
+
+/* Return pointer to accerated line function */
+static line_func choose_line_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (ctx->Line.Width==1.0 && !ctx->Line.SmoothFlag && !ctx->Line.StippleFlag
+ && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && Current->rgb_flag) {
+ ENDPROFILE(choose_line_function)
+ return fast_flat_rgb_line;
+ }
+ else {
+ ENDPROFILE(choose_line_function)
+ return NULL;
+ }
+}
+
+/**********************************************************************/
+/***** Optimized triangle rendering *****/
+/**********************************************************************/
+
+
+/*
+ * Smooth-shaded, z-less triangle, RGBA color.
+ */
+static void smooth_color_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+UINT nBypp = Current->cColorBits / 8;
+GLbyte* img;
+GLushort* img16;
+GLuint *img24 ,*img32;
+#define INTERP_Z 1
+#define INTERP_RGB 1
+#define INTERP_ALPHA 1
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ img = PIXELADDR(LEFT,Y); \
+ for (i=0;i<len;i++,img+=nBypp) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ img16 = img24 = img32 = img; \
+ if(nBypp == 2) \
+ *img16 = BGR16( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb)); \
+ if(nBypp == 3) \
+ *img24 = BGR24( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb)); \
+ if(nBypp == 4) \
+ *img32 = BGR32( FixedToInt(ffr), FixedToInt(ffg), \
+ FixedToInt(ffb)); \
+ zRow[i] = z; \
+ } \
+ ffr += fdrdx; ffg += fdgdx; ffb += fdbdx; ffa += fdadx;\
+ ffz += fdzdx; \
+ } \
+}
+
+ #include "tritemp.h"
+ }
+
+
+
+
+/*
+ * Flat-shaded, z-less triangle, RGBA color.
+ */
+static void flat_color_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
+ GLuint v2, GLuint pv )
+{
+GLbyte* img;
+GLushort* img16;
+GLuint *img24, *img32;
+UINT nBypp = Current->cColorBits / 8;
+GLubyte r, g, b ;
+GLushort pixel16 = BGR16(r,g,b);
+GLuint pixel24 = BGR24(r,g,b);
+GLuint pixel32 = BGR32(r,g,b);
+
+#define INTERP_Z 1
+#define SETUP_CODE \
+ r = VB->Color[pv][0]; \
+ g = VB->Color[pv][1]; \
+ b = VB->Color[pv][2];
+
+#define INNER_LOOP( LEFT, RIGHT, Y ) \
+{ \
+ GLint i, len = RIGHT-LEFT; \
+ img = PIXELADDR(LEFT,Y); \
+ for (i=0;i<len;i++,img+=nBypp) { \
+ GLdepth z = FixedToDepth(ffz); \
+ if (z < zRow[i]) { \
+ img16 = img24 = img32 = img; \
+ if(nBypp == 2) \
+ *img16 = pixel16; \
+ if(nBypp == 3) \
+ *img24 = pixel24; \
+ if(nBypp == 4) \
+ *img32 = pixel32; \
+ zRow[i] = z; \
+ } \
+ ffz += fdzdx; \
+ } \
+}
+
+#include "tritemp.h"
+}
+
+
+
+/*
+ * Return pointer to an accelerated triangle function if possible.
+ */
+static triangle_func choose_triangle_function( GLcontext *ctx )
+{
+ if (ctx->Polygon.SmoothFlag) return NULL;
+ if (ctx->Polygon.StippleFlag) return NULL;
+ if (ctx->Texture.Enabled) return NULL;
+
+ if (ctx->RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual->RGBAflag) {
+ if (ctx->Light.ShadeModel==GL_SMOOTH) {
+ return smooth_color_z_triangle;
+ }
+ else {
+ return flat_color_z_triangle;
+ }
+ }
+ return NULL;
+}
+
+
+/* Draw a convex polygon using color Current->gl_ctx->VB->Color[pv] */
+static void fast_flat_rgb_polygon( GLcontext* ctx, GLuint n, GLuint vlist[], GLuint pv )
+{
+ STARTPROFILE
+ POINT *Pts=(POINT *) malloc(n*sizeof(POINT));
+ HDC DC=DD_GETDC;
+ HPEN Pen;
+ HBRUSH Brush;
+ HPEN Old_Pen;
+ HBRUSH Old_Brush;
+ GLint pixel;
+ GLuint i;
+
+ if (Current->gl_ctx->VB->MonoColor) {
+ pixel = Current->pixel; /* use current color */
+ }
+ else {
+ 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);
+ }
+
+ Pen=CreatePen(PS_SOLID,1,pixel);
+ Brush=CreateSolidBrush(pixel);
+ Old_Pen=SelectObject(DC,Pen);
+ Old_Brush=SelectObject(DC,Brush);
+
+ for (i=0; i<n; i++) {
+ int j = vlist[i];
+ Pts[i].x = (int) Current->gl_ctx->VB->Win[j][0];
+ Pts[i].y = FLIP( (int) Current->gl_ctx->VB->Win[j][1] );
+ }
+
+ BEGINGDICALL
+
+ Polygon(DC,Pts,n);
+ SelectObject(DC,Old_Pen);
+ SelectObject(DC,Old_Brush);
+ DeleteObject(Pen);
+ DeleteObject(Brush);
+ DD_RELEASEDC;
+ free(Pts);
+
+ ENDGDICALL
+
+ ENDPROFILE(fast_flat_rgb_polygon)
+}
+
+
+
+/* Return pointer to accerated polygon function */
+static polygon_func choose_polygon_function( GLcontext* ctx )
+{
+ STARTPROFILE
+ if (!ctx->Polygon.SmoothFlag && !ctx->Polygon.StippleFlag
+ && ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0
+ && !ctx->Texture.Enabled && Current->rgb_flag==GL_TRUE) {
+ ENDPROFILE(choose_polygon_function)
+ return fast_flat_rgb_polygon;
+ }
+ else {
+ ENDPROFILE(choose_polygon_function)
+ return NULL;
+ }
+}
+
+
+
+/**********************************************************************/
+/***** Span-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write a horizontal span of color-index pixels with a boolean mask. */
+static void write_index_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLuint index[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ char *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=index[i];
+ ENDPROFILE(write_index_span)
+}
+
+
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current
+ * color index is used for all pixels.
+ */
+static void write_monoindex_span(GLcontext* ctx,
+ GLuint n,GLint x,GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ char *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=Current->pixel;
+ ENDPROFILE(write_monoindex_span)
+}
+
+/*
+ To improve the performance of this routine, frob the data into an actual scanline
+ and call bitblt on the complete scan line instead of SetPixel.
+*/
+
+/* Write a horizontal span of color pixels with a boolean mask. */
+static void write_color_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte
+ red[], const GLubyte green[],
+ const GLubyte blue[], const GLubyte alpha[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+
+ PWMC pwc = Current;
+
+ if (pwc->rgb_flag==GL_TRUE)
+ {
+ GLuint i;
+ HDC DC=DD_GETDC;
+ y=FLIP(y);
+
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, y, x + i,red[i], green[i], blue[i]);
+ }
+
+ else {
+ for (i=0; i<n; i++)
+ wmSetPixel(pwc, y, x + i, red[i], green[i], blue[i]);
+ }
+
+ DD_RELEASEDC;
+
+ }
+
+ else
+ {
+ GLuint i;
+ char *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ if (mask) {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ Mem[i]=GetNearestPaletteIndex(Current->hPal,RGB(red[i],green[i],blue[i]));
+ }
+ else {
+ for (i=0; i<n; i++)
+ Mem[i]=GetNearestPaletteIndex(Current->hPal,RGB(red[i],green[i],blue[i]));
+ }
+ }
+ ENDPROFILE(write_color_span)
+
+}
+
+/*
+ * Write a horizontal span of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_monocolor_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ const GLubyte mask[])
+{
+ STARTPROFILE
+ GLuint i;
+ HDC DC=DD_GETDC;
+ PWMC pwc = Current;
+
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+
+ if(Current->rgb_flag==GL_TRUE){
+ for (i=0; i<n; i++)
+ if (mask[i])
+// Trying
+ wmSetPixel(pwc,y,x+i,GetRValue(Current->pixel), GetGValue(Current->pixel), GetBValue(Current->pixel));
+ }
+ else {
+ for (i=0; i<n; i++)
+ if (mask[i])
+ SetPixel(DC, y, x+i, Current->pixel);
+ }
+
+ DD_RELEASEDC;
+
+ ENDPROFILE(write_monocolor_span)
+}
+
+
+
+/**********************************************************************/
+/***** Array-based pixel drawing *****/
+/**********************************************************************/
+
+
+/* Write an array of pixels with a boolean mask. */
+static void write_index_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ char *Mem=Current->ScreenMem+y[i]*Current->ScanWidth+x[i];
+ *Mem = index[i];
+ }
+ }
+ ENDPROFILE(write_index_pixels)
+}
+
+
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * index is used for all pixels.
+ */
+static void write_monoindex_pixels( GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ char *Mem=Current->ScreenMem+y[i]*Current->ScanWidth+x[i];
+ *Mem = Current->pixel;
+ }
+ }
+ ENDPROFILE(write_monoindex_pixels)
+}
+
+
+
+/* Write an array of pixels with a boolean mask. */
+static void write_color_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte r[], const GLubyte g[],
+ const GLubyte b[], const GLubyte a[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],r[i],g[i],b[i]);
+ DD_RELEASEDC;
+ ENDPROFILE(write_color_pixels)
+}
+
+
+
+/*
+ * Write an array of pixels with a boolean mask. The current color
+ * is used for all pixels.
+ */
+static void write_monocolor_pixels( GLcontext* ctx,
+ GLuint n,
+ const GLint x[], const GLint y[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ PWMC pwc = Current;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++)
+ if (mask[i])
+ wmSetPixel(pwc, FLIP(y[i]),x[i],GetRValue(Current->pixel),
+ GetGValue(Current->pixel), GetBValue(Current->pixel));
+ DD_RELEASEDC;
+ ENDPROFILE(write_monocolor_pixels)
+}
+
+
+
+/**********************************************************************/
+/***** Read spans/arrays of pixels *****/
+/**********************************************************************/
+
+
+/* Read a horizontal span of color-index pixels. */
+static void read_index_span( GLcontext* ctx, GLuint n, GLint x, GLint y, GLuint index[])
+{
+ STARTPROFILE
+ GLuint i;
+ char *Mem=Current->ScreenMem+y*Current->ScanWidth+x;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++)
+ index[i]=Mem[i];
+ ENDPROFILE(read_index_span)
+
+}
+
+
+
+
+/* Read an array of color index pixels. */
+static void read_index_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint indx[], const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ assert(Current->rgb_flag==GL_FALSE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ indx[i]=*(Current->ScreenMem+y[i]*Current->ScanWidth+x[i]);
+ }
+ }
+ ENDPROFILE(read_index_pixels)
+}
+
+
+
+/* Read a horizontal span of color pixels. */
+static void read_color_span( GLcontext* ctx,
+ GLuint n, GLint x, GLint y,
+ GLubyte red[], GLubyte green[],
+ GLubyte blue[], GLubyte alpha[] )
+{
+ STARTPROFILE
+ UINT i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ y=FLIP(y);
+ for (i=0; i<n; i++)
+ {
+ Color=GetPixel(DC,x+i,y);
+ red[i]=GetRValue(Color);
+ green[i]=GetGValue(Color);
+ blue[i]=GetBValue(Color);
+ alpha[i]=255;
+ }
+ DD_RELEASEDC;
+ memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_color_span)
+}
+
+
+/* Read an array of color pixels. */
+static void read_color_pixels( GLcontext* ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte red[], GLubyte green[],
+ GLubyte blue[], GLubyte alpha[],
+ const GLubyte mask[] )
+{
+ STARTPROFILE
+ GLuint i;
+ COLORREF Color;
+ HDC DC=DD_GETDC;
+ assert(Current->rgb_flag==GL_TRUE);
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ Color=GetPixel(DC,x[i],FLIP(y[i]));
+ red[i]=GetRValue(Color);
+ green[i]=GetGValue(Color);
+ blue[i]=GetBValue(Color);
+ alpha[i]=255;
+ }
+ }
+ DD_RELEASEDC;
+ memset(alpha,0,n*sizeof(GLint));
+ ENDPROFILE(read_color_pixels)
+}
+
+
+
+/**********************************************************************/
+/**********************************************************************/
+
+
+
+void setup_DD_pointers( GLcontext* ctx )
+{
+ ctx->Driver.Finish = finish;
+ ctx->Driver.Flush = flush;
+
+ ctx->Driver.ClearIndex = clear_index;
+ ctx->Driver.ClearColor = clear_color;
+ ctx->Driver.Clear = clear;
+
+ ctx->Driver.Index = set_index;
+ ctx->Driver.Color = set_color;
+ ctx->Driver.IndexMask = index_mask;
+ ctx->Driver.ColorMask = color_mask;
+
+ ctx->Driver.LogicOp = logicop;
+ ctx->Driver.Dither = dither;
+
+ ctx->Driver.SetBuffer = set_buffer;
+ ctx->Driver.GetBufferSize = buffer_size;
+
+ ctx->Driver.PointsFunc = choose_points_function(ctx);
+ ctx->Driver.LineFunc = choose_line_function(ctx);
+ ctx->Driver.TriangleFunc = choose_triangle_function( ctx );
+ // ctx->Driver.TriangleFunc = choose_polygon_function(ctx);
+
+ /* Pixel/span writing functions: */
+ ctx->Driver.WriteColorSpan = write_color_span;
+ ctx->Driver.WriteMonocolorSpan = write_monocolor_span;
+ ctx->Driver.WriteColorPixels = write_color_pixels;
+ ctx->Driver.WriteMonocolorPixels = write_monocolor_pixels;
+ ctx->Driver.WriteIndexSpan = write_index_span;
+ ctx->Driver.WriteMonoindexSpan = write_monoindex_span;
+ ctx->Driver.WriteIndexPixels = write_index_pixels;
+ ctx->Driver.WriteMonoindexPixels = write_monoindex_pixels;
+
+ /* Pixel/span reading functions: */
+ ctx->Driver.ReadIndexSpan = read_index_span;
+ ctx->Driver.ReadColorSpan = read_color_span;
+ ctx->Driver.ReadIndexPixels = read_index_pixels;
+ ctx->Driver.ReadColorPixels = read_color_pixels;
+}
+
+//
+// MesaGL32 is the DLL version of MesaGL for Win32
+//
+
+/**********************************************************************/
+/***** WMesa API Functions *****/
+/**********************************************************************/
+
+
+
+#define PAL_SIZE 256
+static void GetPalette(HPALETTE Pal,RGBQUAD *aRGB)
+{
+ STARTPROFILE
+ int i;
+ HDC hdc;
+ struct
+ {
+ WORD Version;
+ WORD NumberOfEntries;
+ PALETTEENTRY aEntries[PAL_SIZE];
+ } Palette =
+ {
+ 0x300,
+ PAL_SIZE
+ };
+ hdc=GetDC(NULL);
+ if (Pal!=NULL)
+ GetPaletteEntries(Pal,0,PAL_SIZE,Palette.aEntries);
+ else
+ GetSystemPaletteEntries(hdc,0,PAL_SIZE,Palette.aEntries);
+ if (GetSystemPaletteUse(hdc) == SYSPAL_NOSTATIC)
+ {
+ for(i = 0; i <PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ Palette.aEntries[255].peRed = 255;
+ Palette.aEntries[255].peGreen = 255;
+ Palette.aEntries[255].peBlue = 255;
+ Palette.aEntries[255].peFlags = 0;
+ Palette.aEntries[0].peRed = 0;
+ Palette.aEntries[0].peGreen = 0;
+ Palette.aEntries[0].peBlue = 0;
+ Palette.aEntries[0].peFlags = 0;
+ }
+ else
+ {
+ int nStaticColors;
+ int nUsableColors;
+ nStaticColors = GetDeviceCaps(hdc, NUMCOLORS)/2;
+ for (i=0; i<nStaticColors; i++)
+ Palette.aEntries[i].peFlags = 0;
+ nUsableColors = PAL_SIZE-nStaticColors;
+ for (; i<nUsableColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (; i<PAL_SIZE-nStaticColors; i++)
+ Palette.aEntries[i].peFlags = PC_RESERVED;
+ for (i=PAL_SIZE-nStaticColors; i<PAL_SIZE; i++)
+ Palette.aEntries[i].peFlags = 0;
+ }
+ ReleaseDC(NULL,hdc);
+ for (i=0; i<PAL_SIZE; i++)
+ {
+ aRGB[i].rgbRed=Palette.aEntries[i].peRed;
+ aRGB[i].rgbGreen=Palette.aEntries[i].peGreen;
+ aRGB[i].rgbBlue=Palette.aEntries[i].peBlue;
+ aRGB[i].rgbReserved=Palette.aEntries[i].peFlags;
+ }
+ ENDPROFILE(GetPalette)
+}
+
+
+WMesaContext /*APIENTRY*/ WMesaCreateContext( HWND hWnd, HPALETTE Pal,
+ /*HDC hDC,*/ GLboolean rgb_flag,
+ GLboolean db_flag )
+{
+ BITMAPINFO *Rec;
+ //HDC DC;
+ RECT CR;
+ WMesaContext c;
+
+ c = (struct wmesa_context * ) calloc(1,sizeof(struct wmesa_context));
+ if (!c)
+ return NULL;
+
+ c->Window=hWnd;
+ c->hDC = GetDC(hWnd);
+
+ if (rgb_flag==GL_FALSE)
+ {
+ c->rgb_flag = GL_FALSE;
+ c->pixel = 1;
+ db_flag=GL_TRUE; // WinG requires double buffering
+ //c->gl_ctx->BufferDepth = windepth;
+ }
+ else
+ {
+ c->rgb_flag = GL_TRUE;
+ c->pixel = 0;
+ }
+ GetClientRect(c->Window,&CR);
+ c->width=CR.right;
+ c->height=CR.bottom;
+ if (db_flag)
+ {
+ c->db_flag = 1;
+// c->hDC GetDC(c->Window);
+ /* Double buffered */
+ if (c->rgb_flag==GL_TRUE)
+ {
+ //DC = c->hDC = hDC;
+
+// DC = c->hDC = GetDC(c->Window);
+ wmCreateBackingStore(c, c->width, c->height);
+// ReleaseDC(c->Window,DC);
+ }
+ else
+ {
+ c->dib.hDC=WinGCreateDC();
+ Rec=(BITMAPINFO *) malloc(sizeof(BITMAPINFO)+(PAL_SIZE-1)*sizeof(RGBQUAD));
+ c->hPal=Pal;
+ GetPalette(Pal,Rec->bmiColors);
+ WinGRecommendDIBFormat(Rec);
+ Rec->bmiHeader.biWidth=c->width;
+ Rec->bmiHeader.biHeight*=c->height;
+ Rec->bmiHeader.biClrUsed=PAL_SIZE;
+ if (Rec->bmiHeader.biPlanes!=1 || Rec->bmiHeader.biBitCount!=8)
+ {
+ MessageBox(NULL,"Error.","This code presumes a 256 color, single plane, WinG Device.\n",MB_OK);
+ exit(1);
+ }
+ c->Compat_BM=WinGCreateBitmap(c->dib.hDC,Rec,&((void *) c->ScreenMem));
+ c->Old_Compat_BM=SelectObject(c->dib.hDC,c->Compat_BM);
+ WinGSetDIBColorTable(c->dib.hDC,0,PAL_SIZE,Rec->bmiColors);
+ c->IndexFormat=Rec;
+ c->ScanWidth=c->width;
+ c->cColorBits = 8;
+ if ((c->ScanWidth%sizeof(long))!=0)
+ c->ScanWidth+=(sizeof(long)-(c->ScanWidth%sizeof(long)));
+ }
+ }
+ else
+ {
+ /* Single Buffered */
+ c->db_flag = 0;
+
+// wmCreateBackingStore(c, c->width, c->height);
+ }
+
+
+
+ c->gl_visual = gl_create_visual(rgb_flag,
+ GL_FALSE, /* software alpha */
+ db_flag, /* db_flag */
+ 16, /* depth_bits */
+ 8, /* stencil_bits */
+ 8, /* accum_bits */
+ 8,
+ 255.0, 255.0, 255.0, 255.0 );
+
+ if (!c->gl_visual) {
+ return NULL;
+ }
+
+ /* allocate a new Mesa context */
+ c->gl_ctx = gl_create_context( c->gl_visual, NULL,c);
+
+ if (!c->gl_ctx) {
+ gl_destroy_visual( c->gl_visual );
+ free(c);
+ return NULL;
+ }
+
+ c->gl_buffer = gl_create_framebuffer( c->gl_visual );
+ if (!c->gl_buffer) {
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_context( c->gl_ctx );
+ free(c);
+ return NULL;
+ }
+// setup_DD_pointers(c->gl_ctx);
+
+ return c;
+}
+
+
+
+void /*APIENTRY*/ WMesaDestroyContext( void )
+{
+ WMesaContext c = Current;
+ ReleaseDC(c->Window,c->hDC);
+ WC = c;
+
+ gl_destroy_visual( c->gl_visual );
+ gl_destroy_framebuffer( c->gl_buffer );
+ gl_destroy_context( c->gl_ctx );
+
+ if (c->db_flag){
+ wmDeleteBackingStore(c);
+
+//Code added by Li Wei to enable parallel render
+#if !defined(NO_STEREO)
+ if(stereoBuffer==GL_TRUE){
+ WMesaDestroyStereoBuffer();
+ stereoBuffer=GL_FALSE;
+ }
+#endif
+// End modification
+ }
+ free( (void *) c );
+//Code added by Li Wei to enable parallel render
+// Parallel render only work in double buffer mode
+#if !defined(NO_PARALLEL)
+ if(parallelMachine)
+ PRDestroyRenderBuffer();
+#endif
+// End modification
+}
+
+
+
+void /*APIENTRY*/ WMesaMakeCurrent( WMesaContext c )
+{
+ if(!c){
+ Current = c;
+ return;
+ }
+
+ //
+ // A little optimization
+ // If it already is current,
+ // don't set it again
+ //
+ if(Current == c)
+ return;
+
+ //gl_set_context( c->gl_ctx );
+ gl_make_current(c->gl_ctx, c->gl_buffer);
+ Current = c;
+ setup_DD_pointers(c->gl_ctx);
+ if (Current->gl_ctx->Viewport.Width==0) {
+ /* initialize viewport to window size */
+ gl_Viewport( Current->gl_ctx,
+ 0, 0, Current->width, Current->height );
+ }
+}
+
+
+
+void /*APIENTRY*/ WMesaSwapBuffers( void )
+{
+ HDC DC = Current->hDC;
+ if (Current->db_flag)
+ {
+ if (Current->rgb_flag)
+ wmFlush(Current);
+ else
+ WinGBitBlt(DC,0,0,Current->width,Current->height,Current->dib.hDC,0,0);
+ }
+}
+
+
+
+void /*APIENTRY*/ WMesaPaletteChange(HPALETTE Pal)
+{
+ if (Current && Current->rgb_flag==GL_FALSE)
+ {
+ Current->hPal=Pal;
+ GetPalette(Pal,Current->IndexFormat->bmiColors);
+ WinGSetDIBColorTable(Current->dib.hDC,0,PAL_SIZE,Current->IndexFormat->bmiColors);
+ }
+}
+
+//
+// Free up the dib section that was created
+//
+BOOL wmDeleteBackingStore(PWMC pwc)
+{
+ SelectObject(pwc->dib.hDC, pwc->hOldBitmap);
+ DeleteDC(pwc->dib.hDC);
+ DeleteObject(pwc->hbmDIB);
+ UnmapViewOfFile(pwc->dib.base);
+ CloseHandle(pwc->dib.hFileMap);
+ return TRUE;
+}
+
+
+//
+// This function creates the DIB section that is used for combined
+// GL and GDI calls
+//
+BOOL /*WINAPI*/ wmCreateBackingStore(PWMC pwc, long lxSize, long lySize)
+{
+ HDC hdc = pwc->hDC;
+ LPBITMAPINFO pbmi = &(pwc->bmi);
+ int iUsage;
+
+ pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->bmiHeader.biWidth = lxSize;
+ pbmi->bmiHeader.biHeight= -lySize;
+ pbmi->bmiHeader.biPlanes = 1;
+ pbmi->bmiHeader.biBitCount = GetDeviceCaps(pwc->hDC, BITSPIXEL);
+ pbmi->bmiHeader.biCompression = BI_RGB;
+ pbmi->bmiHeader.biSizeImage = 0;
+ pbmi->bmiHeader.biXPelsPerMeter = 0;
+ pbmi->bmiHeader.biYPelsPerMeter = 0;
+ pbmi->bmiHeader.biClrUsed = 0;
+ pbmi->bmiHeader.biClrImportant = 0;
+
+ iUsage = (pbmi->bmiHeader.biBitCount <= 8) ? DIB_PAL_COLORS : DIB_RGB_COLORS;
+
+ pwc->cColorBits = pbmi->bmiHeader.biBitCount;
+ pwc->ScanWidth = lxSize;
+
+ wmCreateDIBSection(hdc, pwc, pbmi, iUsage);
+
+ if ((iUsage == DIB_PAL_COLORS) && !(pwc->hGLPalette)) {
+ wmCreatePalette( pwc );
+ wmSetDibColors( pwc );
+ }
+
+ return(TRUE);
+
+}
+
+
+//
+// This function copies one scan line in a DIB section to another
+//
+BOOL GLWINAPI wmSetDIBits(PWMC pwc, UINT uiScanWidth, UINT uiNumScans, UINT nBypp, UINT uiNewWidth, LPBYTE pBits)
+{
+ UINT uiScans = 0;
+ LPBYTE pDest = pwc->pbPixels;
+ DWORD dwNextScan = uiScanWidth;
+ DWORD dwNewScan = uiNewWidth;
+ DWORD dwScanWidth = (uiScanWidth * nBypp);
+
+ //
+ // We need to round up to the nearest DWORD
+ // and multiply by the number of bytes per
+ // pixel
+ //
+ dwNextScan = (((dwNextScan * nBypp)+ 3) & ~3);
+ dwNewScan = (((dwNewScan * nBypp)+ 3) & ~3);
+
+ for(uiScans = 0; uiScans < uiNumScans; uiScans++){
+ CopyMemory(pDest, pBits, dwScanWidth);
+ pBits += dwNextScan;
+ pDest += dwNewScan;
+ }
+
+ return(TRUE);
+
+}
+
+BOOL GLWINAPI wmSetPixelFormat( PWMC pwdc, HDC hDC, DWORD dwFlags )
+{
+ return(TRUE);
+}
+
+static unsigned char threeto8[8] = {
+ 0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
+};
+
+static unsigned char twoto8[4] = {
+ 0, 0x55, 0xaa, 0xff
+};
+
+static unsigned char oneto8[2] = {
+ 0, 255
+};
+
+static unsigned char componentFromIndex(UCHAR i, UINT nbits, UINT shift)
+{
+ unsigned char val;
+
+ val = i >> shift;
+ switch (nbits) {
+
+ case 1:
+ val &= 0x1;
+ return oneto8[val];
+
+ case 2:
+ val &= 0x3;
+ return twoto8[val];
+
+ case 3:
+ val &= 0x7;
+ return threeto8[val];
+
+ default:
+ return 0;
+ }
+}
+
+void /*WINAPI*/ wmCreatePalette( PWMC pwdc )
+{
+ /* Create a compressed and re-expanded 3:3:2 palette */
+ int i;
+ LOGPALETTE *pPal;
+ BYTE rb, rs, gb, gs, bb, bs;
+
+ pwdc->nColors = 0x100;
+
+ pPal = (PLOGPALETTE)malloc(sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, sizeof(LOGPALETTE) + pwdc->nColors * sizeof(PALETTEENTRY) );
+
+ pPal->palVersion = 0x300;
+
+ rb = REDBITS;
+ rs = REDSHIFT;
+ gb = GREENBITS;
+ gs = GREENSHIFT;
+ bb = BLUEBITS;
+ bs = BLUESHIFT;
+
+ if (pwdc->db_flag) {
+
+ /* Need to make two palettes: one for the screen DC and one for the DIB. */
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ pwdc->hPalette = CreatePalette( pPal );
+ }
+
+ else {
+ pPal->palNumEntries = pwdc->nColors;
+ for (i = 0; i < pwdc->nColors; i++) {
+ pPal->palPalEntry[i].peRed = componentFromIndex( i, rb, rs );
+ pPal->palPalEntry[i].peGreen = componentFromIndex( i, gb, gs );
+ pPal->palPalEntry[i].peBlue = componentFromIndex( i, bb, bs );
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ pwdc->hGLPalette = CreatePalette( pPal );
+ }
+
+ free(pPal);
+
+}
+
+//
+// This function sets the color table of a DIB section
+// to match that of the destination DC
+//
+BOOL /*WINAPI*/ wmSetDibColors(PWMC pwc)
+{
+ RGBQUAD *pColTab, *pRGB;
+ PALETTEENTRY *pPal, *pPE;
+ int i, nColors;
+ BOOL bRet=TRUE;
+ DWORD dwErr=0;
+
+ /* Build a color table in the DIB that maps to the
+ selected palette in the DC.
+ */
+ nColors = 1 << pwc->cColorBits;
+ pPal = (PALETTEENTRY *)malloc( nColors * sizeof(PALETTEENTRY));
+ memset( pPal, 0, nColors * sizeof(PALETTEENTRY) );
+ GetPaletteEntries( pwc->hGLPalette, 0, nColors, pPal );
+ pColTab = (RGBQUAD *)malloc( nColors * sizeof(RGBQUAD));
+ for (i = 0, pRGB = pColTab, pPE = pPal; i < nColors; i++, pRGB++, pPE++) {
+ pRGB->rgbRed = pPE->peRed;
+ pRGB->rgbGreen = pPE->peGreen;
+ pRGB->rgbBlue = pPE->peBlue;
+ }
+ if(pwc->db_flag)
+ bRet = SetDIBColorTable(pwc->hDC, 0, nColors, pColTab );
+
+ if(!bRet)
+ dwErr = GetLastError();
+
+ free( pColTab );
+ free( pPal );
+
+ return(bRet);
+}
+
+void /*WINAPI*/ wmSetPixel(PWMC pwc, int iScanLine, int iPixel, BYTE r, BYTE g, BYTE b)
+{
+ if(Current->db_flag){
+ LPBYTE lpb = pwc->pbPixels;
+ LPDWORD lpdw;
+ LPWORD lpw;
+ UINT nBypp = pwc->cColorBits / 8;
+ UINT nOffset = iPixel % nBypp;
+
+ // Move the pixel buffer pointer to the scanline that we
+ // want to access
+
+ pwc->dib.fFlushed = FALSE;
+
+ lpb += pwc->ScanWidth * iScanLine;
+ // Now move to the desired pixel
+ lpb += iPixel * nBypp;
+
+ lpdw = (LPDWORD)lpb;
+ lpw = (LPWORD)lpb;
+
+ if(nBypp == 2)
+ *lpw = BGR16(r,g,b);
+ else if (nBypp == 3){
+ *lpdw = BGR24(r,g,b);
+ }
+ else
+ *lpdw = BGR32(r,g,b);
+ }
+ else{
+ HDC DC = DD_GETDC;
+ SetPixel(DC, iPixel, iScanLine, RGB(r,g,b));
+ DD_RELEASEDC;
+ }
+}
+
+void /*WINAPI*/ wmCreateDIBSection(
+ HDC hDC,
+ PWMC pwc, // handle of device context
+ CONST BITMAPINFO *pbmi, // address of structure containing bitmap size, format, and color data
+ UINT iUsage // color data type indicator: RGB values or palette indices
+)
+{
+ DWORD dwSize = 0;
+ DWORD dwScanWidth;
+ UINT nBypp = pwc->cColorBits / 8;
+ HDC hic;
+
+ dwScanWidth = (((pwc->ScanWidth * nBypp)+ 3) & ~3);
+
+ pwc->ScanWidth = dwScanWidth;
+
+ dwSize = sizeof(BITMAPINFO) + (dwScanWidth * pwc->height);
+
+ pwc->dib.hFileMap = CreateFileMapping((HANDLE)PAGE_FILE,
+ NULL,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0,
+ dwSize,
+ NULL);
+
+ if (!pwc->dib.hFileMap)
+ return;
+
+ pwc->dib.base = MapViewOfFile(pwc->dib.hFileMap,
+ FILE_MAP_ALL_ACCESS,
+ 0,
+ 0,
+ 0);
+
+ if(!pwc->dib.base){
+ CloseHandle(pwc->dib.hFileMap);
+ return;
+ }
+
+ pwc->pbPixels = ((LPBYTE)pwc->dib.base) + sizeof(BITMAPINFO);
+
+ pwc->dib.hDC = CreateCompatibleDC(hDC);
+
+ CopyMemory(pwc->dib.base, pbmi, sizeof(BITMAPINFO));
+
+ hic = CreateIC("display", NULL, NULL, NULL);
+
+/* pwc->hbmDIB = CreateDIBitmap(hic,
+ &(pwc->bmi.bmiHeader),
+ CBM_INIT,
+ pwc->pbPixels,
+ &(pwc->bmi),
+ DIB_RGB_COLORS);
+*/
+ pwc->hbmDIB = CreateDIBSection(hic,
+ &(pwc->bmi.bmiHeader),
+ DIB_RGB_COLORS,
+ &(pwc->pbPixels),
+ pwc->dib.hFileMap,
+ 0);
+ pwc->hOldBitmap = SelectObject(pwc->dib.hDC, pwc->hbmDIB);
+
+ DeleteDC(hic);
+
+ return;
+
+}
+
+//
+// Blit memory DC to screen DC
+//
+BOOL /*WINAPI*/ wmFlush(PWMC pwc)
+{
+ BOOL bRet = 0;
+ DWORD dwErr = 0;
+
+
+// wmFlushBits(pwc);
+
+ bRet = BitBlt(pwc->hDC, 0, 0, pwc->width, pwc->height,
+ pwc->dib.hDC, 0, 0, SRCCOPY);
+
+ if(!bRet)
+ dwErr = GetLastError();
+
+ pwc->dib.fFlushed = TRUE;
+
+ return(TRUE);
+
+}
+
+
+// The following code is added by Li Wei to enable stereo display
+
+#if !defined(NO_STEREO)
+
+void WMesaCreateStereoBuffer()
+{
+ /* Must use double buffer and not in parallelMode */
+ if (! Current->db_flag
+#if !defined(NO_PARALLEL)
+ || parallelFlag
+#endif
+ )
+ return;
+
+ Buffer_Stereo = malloc( Current->ScanWidth * Current->height);
+ ZeroMemory(Buffer_Stereo,Current->ScanWidth * Current->height);
+ stereoBuffer = GL_TRUE ;
+}
+
+void WMesaDestroyStereoBuffer()
+{
+ /* Must use double buffer and not in parallelMode */
+ if (! Current->db_flag
+#if !defined(NO_PARALLEL)
+ || parallelFlag
+#endif
+ )
+ return;
+ if(stereoBuffer){
+ free(Buffer_Stereo);
+ stereoBuffer = GL_FALSE ;
+ }
+}
+
+void WMesaInterleave(GLenum aView)
+{
+ int offset;
+ unsigned line;
+ LPBYTE dest;
+ LPBYTE src;
+ if(aView == FIRST)
+ offset = 0;
+ else offset = 1;
+
+ dest = Buffer_Stereo + offset * Current->ScanWidth;
+ if(Current->rgb_flag )
+ src = Current->pbPixels + Current->ScanWidth*(Current->height/2);
+ else
+ src = Current->ScreenMem;
+
+ for(line = 0; line<Current->height/2; line ++){
+ CopyMemory(dest, src, Current->ScanWidth);
+ dest += 2*Current->ScanWidth;
+ src += Current->ScanWidth;
+ }
+ if(aView == SECOND)
+ if(Current->rgb_flag)
+ CopyMemory(Current->pbPixels, Buffer_Stereo, Current->ScanWidth*Current->height);
+ else
+ CopyMemory(Current->ScreenMem, Buffer_Stereo, Current->ScanWidth*Current->height);
+}
+
+void WMesaShowStereo(GLuint list)
+{
+
+ GLbitfield mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
+ GLfloat cm[16];
+ // Must use double Buffer
+ if( ! Current-> db_flag )
+ return;
+
+ glViewport(0,0,Current->width,Current->height/2);
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ gluLookAt(viewDistance/2,0.0,0.0 ,
+ viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ glMultMatrixf( cm );
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glCallList( list );
+ glPopMatrix();
+ glFlush();
+ WMesaInterleave( FIRST );
+
+ glGetFloatv(GL_MODELVIEW_MATRIX,cm);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ gluLookAt(-viewDistance/2,0.0,0.0 ,
+ -viewDistance/2,0.0,-1.0,
+ 0.0,1.0,0.0 );
+ glMultMatrixf(cm);
+ glMatrixMode(GL_MODELVIEW);
+ glCallList(list);
+ glFlush();
+ WMesaInterleave( SECOND );
+ glViewport(0,0,Current->width,Current->height);
+ WMesaSwapBuffers();
+
+}
+
+void toggleStereoMode()
+{
+ if(!Current->db_flag)
+ return;
+ if(!stereo_flag){
+ stereo_flag = 1;
+ if(stereoBuffer==GL_FALSE)
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ {
+ WMesaCreateStereoBuffer();
+ }
+ }
+ else {
+ stereo_flag = 0;
+ if(stereoBuffer==GL_TRUE)
+#if !defined(NO_PARALLEL)
+ if(!parallelFlag)
+#endif
+ if(stereoBuffer==GL_TRUE){
+ WMesaDestroyStereoBuffer();
+ }
+ }
+}
+
+/* if in stereo mode, the following function is called */
+void glShowStereo(GLuint list)
+{
+ WMesaShowStereo(list);
+}
+
+#endif // End if NO_STEREO not defined
+
+#if !defined(NO_PARALLEL)
+
+void toggleParallelMode(void)
+{
+ if(!parallelFlag){
+ parallelFlag = GL_TRUE;
+ if(parallelMachine==GL_FALSE){
+ PRCreateRenderBuffer( Current->rgb_flag? GL_RGBA :GL_COLOR_INDEX,
+ Current->cColorBits/8,
+ Current->width ,Current->height,
+ Current->ScanWidth,
+ Current->rgb_flag? Current->pbPixels: Current->ScreenMem);
+ parallelMachine = GL_TRUE;
+ }
+ }
+ else {
+ parallelFlag = GL_FALSE;
+ if(parallelMachine==GL_TRUE){
+ PRDestroyRenderBuffer();
+ parallelMachine=GL_FALSE;
+ ReadyForNextFrame = GL_TRUE;
+ }
+
+/***********************************************
+// Seems something wrong!!!!
+************************************************/
+
+ WMesaMakeCurrent(Current);
+#if !defined(NO_STEREO)
+ stereo_flag = GL_FALSE ;
+#endif
+ }
+}
+
+void PRShowRenderResult(void)
+{
+ int flag = 0;
+if(!glImageRendered())
+ return;
+
+ if (parallelFlag)
+ {
+ WMesaSwapBuffers();
+ }
+
+}
+#endif //End if NO_PARALLEL not defined
+
+//end modification
diff --git a/src/mesa/drivers/windows/wmesadef.h b/src/mesa/drivers/windows/wmesadef.h
new file mode 100644
index 00000000000..7cd4bb9a7d4
--- /dev/null
+++ b/src/mesa/drivers/windows/wmesadef.h
@@ -0,0 +1,154 @@
+/* File name : wmesadef.h
+ * Version : 2.3
+ *
+ * Header file for display driver for Mesa 2.3 under
+ * Windows95, WindowsNT and Win32
+ *
+ * Copyright (C) 1996- Li Wei
+ * Address : Institute of Artificial Intelligence
+ * : & Robotics
+ * : Xi'an Jiaotong University
+ * Email : [email protected]
+ * Web page : http://sun.aiar.xjtu.edu.cn
+ *
+ * This file and its associations are partially based on the
+ * Windows NT driver for Mesa, written by Mark Leaming
+ */
+
+/*
+ * $Log: wmesadef.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.3 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Initial version 1997/6/14 CST by Li Wei([email protected])
+ */
+
+/*
+ * $Log: wmesadef.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.3 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 2.1 1996/11/15 10:54:00 CST by Li Wei([email protected])
+ * a new element added to wmesa_context :
+ * dither_flag
+ */
+
+/*
+ * $Log: wmesadef.h,v $
+ * Revision 1.1 1999/08/19 00:55:42 jtg
+ * Initial revision
+ *
+ * Revision 1.3 1999/01/03 03:08:57 brianp
+ * Ted Jump's changes
+ *
+ * Revision 2.0 1996/11/15 10:54:00 CST by Li Wei([email protected])
+ * Initial revision
+ */
+
+
+
+#ifndef DDMESADEF_H
+#define DDMESADEF_H
+
+#include <windows.h>
+#include <GL\gl.h>
+#include "context.h"
+#ifdef DDRAW
+ #include <ddraw.h>
+#endif
+//#include "profile.h"
+
+#define REDBITS 0x03
+#define REDSHIFT 0x00
+#define GREENBITS 0x03
+#define GREENSHIFT 0x03
+#define BLUEBITS 0x02
+#define BLUESHIFT 0x06
+
+typedef struct _dibSection{
+ HDC hDC;
+ HANDLE hFileMap;
+ BOOL fFlushed;
+ LPVOID base;
+}WMDIBSECTION, *PWMDIBSECTION;
+
+
+typedef struct wmesa_context{
+ GLcontext *gl_ctx; /* The core GL/Mesa context */
+ GLvisual *gl_visual; /* Describes the buffers */
+ GLframebuffer *gl_buffer; /* Depth, stencil, accum, etc buffers */
+
+
+ HWND Window;
+ HDC hDC;
+ HPALETTE hPalette;
+ HPALETTE hOldPalette;
+ HPEN hPen;
+ HPEN hOldPen;
+ HCURSOR hOldCursor;
+ COLORREF crColor;
+ // 3D projection stuff
+ RECT drawRect;
+ UINT uiDIBoffset;
+ // OpenGL stuff
+ HPALETTE hGLPalette;
+ GLuint width;
+ GLuint height;
+ GLuint ScanWidth;
+ GLboolean db_flag; //* double buffered?
+ GLboolean rgb_flag; //* RGB mode?
+ GLboolean dither_flag; //* use dither when 256 color mode for RGB?
+ GLuint depth; //* bits per pixel (1, 8, 24, etc)
+ ULONG pixel; // current color index or RGBA pixel value
+ ULONG clearpixel; //* pixel for clearing the color buffers
+ PBYTE ScreenMem; // WinG memory
+ BITMAPINFO *IndexFormat;
+ HPALETTE hPal; // Current Palette
+ HPALETTE hPalHalfTone;
+
+
+ WMDIBSECTION dib;
+ BITMAPINFO bmi;
+ HBITMAP hbmDIB;
+ HBITMAP hOldBitmap;
+ HBITMAP Old_Compat_BM;
+ HBITMAP Compat_BM; // Bitmap for double buffering
+ PBYTE pbPixels;
+ int nColors;
+ BYTE cColorBits;
+ int pixelformat;
+
+#ifdef DDRAW
+ LPDIRECTDRAW lpDD; // DirectDraw object
+// LPDIRECTDRAW2 lpDD2; // DirectDraw object
+ LPDIRECTDRAWSURFACE lpDDSPrimary; // DirectDraw primary surface
+ LPDIRECTDRAWSURFACE lpDDSOffScreen; // DirectDraw off screen surface
+ LPDIRECTDRAWPALETTE lpDDPal; // DirectDraw palette
+ BOOL bActive; // is application active?
+ DDSURFACEDESC ddsd;
+ int fullScreen;
+ int gMode ;
+#endif
+ RECT rectOffScreen;
+ RECT rectSurface;
+ HWND hwnd;
+ DWORD pitch;
+ PBYTE addrOffScreen;
+//#ifdef PROFILE
+// MESAPROF profile;
+//#endif
+} *PWMC;
+
+
+#define PAGE_FILE 0xffffffff
+
+
+
+#endif