1 /****************************************************************************
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
6 * ========================================================================
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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
28 * ======================================================================
31 * Environment: Windows 9x (Win32)
33 * Description: OpenGL context handling.
35 ****************************************************************************/
37 #ifndef __DGLCONTEXT_H
38 #define __DGLCONTEXT_H
40 // Disable compiler complaints about DLL linkage
41 #pragma warning (disable:4273)
43 // Macros to control compilation
47 #define WIN32_LEAN_AND_MEAN
52 #include "dglmacros.h"
53 #include "dglglobals.h"
57 #include "context.h" // Mesa context
62 #include "dglmacros.h"
63 #include "dglglobals.h"
67 #include "d3dvertex.h"
71 #include "context.h" // Mesa context
72 #include "vb.h" // Mesa vertex buffer
73 #endif // _USE_GLD3_WGL
75 /*---------------------- Macros and type definitions ----------------------*/
77 // TODO: Use a list instead of this constant!
78 #define DGL_MAX_CONTEXTS 32
80 // Structure for describing an OpenGL context
84 DGL_pixelFormat
*lpPF
;
86 // Pointer to private driver data (this also contains the drawable).
90 GLcontext
*glCtx
; // The core Mesa context
91 GLvisual
*glVis
; // Describes the color buffer
92 GLframebuffer
*glBuffer
; // Ancillary buffers
96 GLubyte ClearColor
[4];
97 GLubyte CurrentColor
[4];
99 BOOL EmulateSingle
; // Emulate single-buffering
103 // Shared driver vars:
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
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
123 LONG lpfnWndProc
; // window message handler function
127 #define GLD_context DGL_ctx
128 #define GLD_GET_CONTEXT(c) (GLD_context*)(c)->DriverCtx
130 #else // _USE_GLD3_WGL
133 BOOL bHasBeenCurrent
;
134 DGL_pixelFormat
*lpPF
;
136 // Mesa context vars:
138 GLcontext
*glCtx
; // The core Mesa context
139 GLvisual
*glVis
; // Describes the color buffer
140 GLframebuffer
*glBuffer
; // Ancillary buffers
144 GLubyte ClearColor
[4];
145 GLubyte CurrentColor
[4];
147 BOOL EmulateSingle
; // Emulate single-buffering
150 int iZBufferPF
; // Index of Zbuffer pixel format
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.
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];
164 // Device driver vars:
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?
172 // DirectX COM interfaces, postfixed with the interface number
176 IDirect3DDevice3
*lpDev3
;
177 IDirect3DViewport3
*lpViewport3
;
178 IDirectDrawSurface4
*lpFront4
;
179 IDirectDrawSurface4
*lpBack4
;
180 IDirectDrawSurface4
*lpDepth4
;
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
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
];
191 DDCAPS ddCaps
; // DirectDraw caps
192 D3DDEVICEDESC D3DDevDesc
; // Direct3D Device description
194 DDPIXELFORMAT ddpfRender
; // Pixel format of the render buffer
195 DDPIXELFORMAT ddpfDepth
; // Pixel format of the depth buffer
197 BOOL bStencil
; // TRUE is this context has stencil
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
203 D3DVIEWPORT2 d3dViewport
; // D3D Viewport object
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
214 // DGL_vertex LineCache[DGL_MAX_LINE_VERTS];
215 // DGL_vertex TriCache[DGL_MAX_TRI_VERTS];
216 // DWORD dwNextLineVert;
217 // DWORD dwNextTriVert;
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
230 LONG lpfnWndProc
; // window message handler function
232 // Shared texture palette
233 IDirectDrawPalette
*lpGlobalPalette
;
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
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
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)
251 DWORD dwMaxTextureSize
; // Max texture size:
255 #endif // _USE_GLD3_WGL
257 /*------------------------- Function Prototypes ---------------------------*/
264 LRESULT CALLBACK
dglKeyProc(int code
,WPARAM wParam
,LPARAM lParam
);
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
);