add SciTech's GLDirect driver for Windows.
[mesa.git] / src / mesa / drivers / windows / gldirect / dglcontext.h
1 /****************************************************************************
2 *
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
5 *
6 * ========================================================================
7 *
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 *
28 * ======================================================================
29 *
30 * Language: ANSI C
31 * Environment: Windows 9x (Win32)
32 *
33 * Description: OpenGL context handling.
34 *
35 ****************************************************************************/
36
37 #ifndef __DGLCONTEXT_H
38 #define __DGLCONTEXT_H
39
40 // Disable compiler complaints about DLL linkage
41 #pragma warning (disable:4273)
42
43 // Macros to control compilation
44 #ifndef STRICT
45 #define STRICT
46 #endif // STRICT
47 #define WIN32_LEAN_AND_MEAN
48 #include <windows.h>
49 #include <GL\gl.h>
50
51 #ifdef _USE_GLD3_WGL
52 #include "dglmacros.h"
53 #include "dglglobals.h"
54 #include "pixpack.h"
55 #include "ddlog.h"
56 #include "dglpf.h"
57 #include "context.h" // Mesa context
58 #else
59 #include <ddraw.h>
60 #include <d3d.h>
61
62 #include "dglmacros.h"
63 #include "dglglobals.h"
64 #include "pixpack.h"
65 #include "ddlog.h"
66 #include "dglpf.h"
67 #include "d3dvertex.h"
68
69 #include "DirectGL.h"
70
71 #include "context.h" // Mesa context
72 #include "vb.h" // Mesa vertex buffer
73 #endif // _USE_GLD3_WGL
74
75 /*---------------------- Macros and type definitions ----------------------*/
76
77 // TODO: Use a list instead of this constant!
78 #define DGL_MAX_CONTEXTS 32
79
80 // Structure for describing an OpenGL context
81 #ifdef _USE_GLD3_WGL
82 typedef struct {
83 BOOL bHasBeenCurrent;
84 DGL_pixelFormat *lpPF;
85
86 // Pointer to private driver data (this also contains the drawable).
87 void *glPriv;
88
89 // Mesa vars:
90 GLcontext *glCtx; // The core Mesa context
91 GLvisual *glVis; // Describes the color buffer
92 GLframebuffer *glBuffer; // Ancillary buffers
93
94 GLuint ClearIndex;
95 GLuint CurrentIndex;
96 GLubyte ClearColor[4];
97 GLubyte CurrentColor[4];
98
99 BOOL EmulateSingle; // Emulate single-buffering
100 BOOL bDoubleBuffer;
101 BOOL bDepthBuffer;
102
103 // Shared driver vars:
104 BOOL bAllocated;
105 BOOL bFullscreen; // Is this a fullscreen context?
106 BOOL bSceneStarted; // Has a lpDev->BeginScene been issued?
107 BOOL bCanRender; // Flag: states whether rendering is OK
108 BOOL bFrameStarted; // Has frame update started at all?
109 BOOL bStencil; // TRUE if this context has stencil
110 BOOL bGDIEraseBkgnd; // GDI Erase Background command
111
112 // Window information
113 HWND hWnd; // Window handle
114 HDC hDC; // Windows' Device Context of the window
115 DWORD dwWidth; // Window width
116 DWORD dwHeight; // Window height
117 DWORD dwBPP; // Window bits-per-pixel;
118 RECT rcScreenRect; // Screen rectangle
119 DWORD dwModeWidth; // Display mode width
120 DWORD dwModeHeight; // Display mode height
121 float dvClipX;
122 float dvClipY;
123 LONG lpfnWndProc; // window message handler function
124
125 } DGL_ctx;
126
127 #define GLD_context DGL_ctx
128 #define GLD_GET_CONTEXT(c) (GLD_context*)(c)->DriverCtx
129
130 #else // _USE_GLD3_WGL
131
132 typedef struct {
133 BOOL bHasBeenCurrent;
134 DGL_pixelFormat *lpPF;
135 //
136 // Mesa context vars:
137 //
138 GLcontext *glCtx; // The core Mesa context
139 GLvisual *glVis; // Describes the color buffer
140 GLframebuffer *glBuffer; // Ancillary buffers
141
142 GLuint ClearIndex;
143 GLuint CurrentIndex;
144 GLubyte ClearColor[4];
145 GLubyte CurrentColor[4];
146
147 BOOL EmulateSingle; // Emulate single-buffering
148 BOOL bDoubleBuffer;
149 BOOL bDepthBuffer;
150 int iZBufferPF; // Index of Zbuffer pixel format
151
152 // Vertex buffer: one-to-one correlation with Mesa's vertex buffer.
153 // This will be filled by our setup function (see d3dvsetup.c)
154 DGL_TLvertex gWin[VB_SIZE]; // Transformed and lit vertices
155 // DGL_Lvertex gObj[VB_SIZE]; // Lit vertices in object coordinates.
156
157 // Indices for DrawIndexedPrimitive.
158 // Clipped quads are drawn seperately, so use VB_SIZE.
159 // 6 indices are needed to make 2 triangles for each possible quad
160 // WORD wIndices[(VB_SIZE / 4) * 6];
161 WORD wIndices[32768];
162
163 //
164 // Device driver vars:
165 //
166 BOOL bAllocated;
167 BOOL bFullscreen; // Is this a fullscreen context?
168 BOOL bSceneStarted; // Has a lpDev->BeginScene been issued?
169 BOOL bCanRender; // Flag: states whether rendering is OK
170 BOOL bFrameStarted; // Has frame update started at all?
171
172 // DirectX COM interfaces, postfixed with the interface number
173 IDirectDraw *lpDD1;
174 IDirectDraw4 *lpDD4;
175 IDirect3D3 *lpD3D3;
176 IDirect3DDevice3 *lpDev3;
177 IDirect3DViewport3 *lpViewport3;
178 IDirectDrawSurface4 *lpFront4;
179 IDirectDrawSurface4 *lpBack4;
180 IDirectDrawSurface4 *lpDepth4;
181
182 // Vertex buffers
183 BOOL bD3DPipeline; // True if using D3D geometry pipeline
184 IDirect3DVertexBuffer *m_vbuf; // Unprocessed vertices
185 IDirect3DVertexBuffer *m_pvbuf; // Processed vertices ready to be rendered
186
187 D3DTEXTUREOP ColorOp[MAX_TEXTURE_UNITS]; // Used for re-enabling texturing
188 D3DTEXTUREOP AlphaOp[MAX_TEXTURE_UNITS]; // Used for re-enabling texturing
189 struct gl_texture_object *tObj[MAX_TEXTURE_UNITS];
190
191 DDCAPS ddCaps; // DirectDraw caps
192 D3DDEVICEDESC D3DDevDesc; // Direct3D Device description
193
194 DDPIXELFORMAT ddpfRender; // Pixel format of the render buffer
195 DDPIXELFORMAT ddpfDepth; // Pixel format of the depth buffer
196
197 BOOL bStencil; // TRUE is this context has stencil
198
199 PX_packFunc fnPackFunc; // Pixel packing function for SW
200 PX_unpackFunc fnUnpackFunc; // Pixel unpacking function for SW
201 PX_packSpanFunc fnPackSpanFunc; // Pixel span packer
202
203 D3DVIEWPORT2 d3dViewport; // D3D Viewport object
204
205 D3DCULL cullmode; // Direct3D cull mode
206 D3DCOLOR curcolor; // Current color
207 DWORD dwColorPF; // Current color, in format of target surface
208 D3DCOLOR d3dClearColor; // Clear color
209 D3DCOLOR ConstantColor; // For flat shading
210 DWORD dwClearColorPF; // Clear color, in format of target surface
211 BOOL bGDIEraseBkgnd; // GDI Erase Background command
212
213 // Primitive caches
214 // DGL_vertex LineCache[DGL_MAX_LINE_VERTS];
215 // DGL_vertex TriCache[DGL_MAX_TRI_VERTS];
216 // DWORD dwNextLineVert;
217 // DWORD dwNextTriVert;
218
219 // Window information
220 HWND hWnd; // Window handle
221 HDC hDC; // Windows' Device Context of the window
222 DWORD dwWidth; // Window width
223 DWORD dwHeight; // Window height
224 DWORD dwBPP; // Window bits-per-pixel;
225 RECT rcScreenRect; // Screen rectangle
226 DWORD dwModeWidth; // Display mode width
227 DWORD dwModeHeight; // Display mode height
228 float dvClipX;
229 float dvClipY;
230 LONG lpfnWndProc; // window message handler function
231
232 // Shared texture palette
233 IDirectDrawPalette *lpGlobalPalette;
234
235 // Usage counters.
236 // One of these counters will be incremented when we choose
237 // between hardware and software rendering functions.
238 // DWORD dwHWUsageCount; // Hardware usage count
239 // DWORD dwSWUsageCount; // Software usage count
240
241 // Texture state flags.
242 // BOOL m_texturing; // TRUE is texturing
243 // BOOL m_mtex; // TRUE if multitexture
244 // BOOL m_texHandleValid; // TRUE if tex state valid
245
246 // Renderstate caches to ensure no redundant state changes
247 DWORD dwRS[256]; // Renderstates
248 DWORD dwTSS[2][24]; // Texture-stage states
249 LPDIRECT3DTEXTURE2 lpTex[2]; // Texture (1 per stage)
250
251 DWORD dwMaxTextureSize; // Max texture size:
252 // clamped to 1024.
253
254 } DGL_ctx;
255 #endif // _USE_GLD3_WGL
256
257 /*------------------------- Function Prototypes ---------------------------*/
258
259 #ifdef __cplusplus
260 extern "C" {
261 #endif
262
263 HHOOK hKeyHook;
264 LRESULT CALLBACK dglKeyProc(int code,WPARAM wParam,LPARAM lParam);
265
266 void dglInitContextState();
267 void dglDeleteContextState();
268 BOOL dglIsValidContext(HGLRC a);
269 DGL_ctx* dglGetContextAddress(const HGLRC a);
270 HDC dglGetCurrentDC(void);
271 HGLRC dglGetCurrentContext(void);
272 HGLRC dglCreateContext(HDC a, const DGL_pixelFormat *lpPF);
273 BOOL dglMakeCurrent(HDC a, HGLRC b);
274 BOOL dglDeleteContext(HGLRC a);
275 BOOL dglSwapBuffers(HDC hDC);
276
277 #ifdef __cplusplus
278 }
279 #endif
280
281 #endif