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/2000/XP/XBox (Win32)
33
* Description: GLDirect Direct3D 9.0 header file
35
****************************************************************************/
40
//---------------------------------------------------------------------------
42
//---------------------------------------------------------------------------
48
//#define WIN32_LEAN_AND_MEAN
49
//#include <windows.h>
53
// MS screwed up with the DX8.1 SDK - there's no compile-time
54
// method of compiling for 8.0 via the 8.1 SDK unless you
55
// "make sure you don't use any 8.1 interfaces".
56
// We CAN use 8.1 D3DX static functions, though - just not new 8.1 interfaces.
58
// D3D_SDK_VERSION is 120 for 8.0 (supported by Windows 95).
59
// D3D_SDK_VERSION is 220 for 8.1 (NOT supported by Windows 95).
61
//#define D3D_SDK_VERSION_DX9_SUPPORT_WIN95 120
62
//#define D3D_SDK_VERSION_DX91 220
64
// Typedef for obtaining function from d3d8.dll
65
typedef IDirect3D9* (WINAPI *FNDIRECT3DCREATE9) (UINT);
68
//---------------------------------------------------------------------------
70
//---------------------------------------------------------------------------
73
#define _GLD_TEST_HRESULT(h) \
77
gldLogError(GLDLOG_ERROR, #h, _hr); \
80
#define _GLD_DX9(func) _GLD_TEST_HRESULT(IDirect3D9_##func##)
81
#define _GLD_DX9_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice9_##func##)
82
#define _GLD_DX9_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer9_##func##)
83
#define _GLD_DX9_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture9_##func##)
85
#define _GLD_DX9(func) IDirect3D9_##func
86
#define _GLD_DX9_DEV(func) IDirect3DDevice9_##func
87
#define _GLD_DX9_VB(func) IDirect3DVertexBuffer9_##func
88
#define _GLD_DX9_TEX(func) IDirect3DTexture9_##func
91
#define SAFE_RELEASE(p) \
94
(p)->lpVtbl->Release(p); \
99
#define SAFE_RELEASE_VB9(p) \
102
IDirect3DVertexBuffer9_Release((p)); \
107
#define SAFE_RELEASE_SURFACE9(p) \
110
IDirect3DSurface9_Release((p)); \
119
GLD_SI_FLAT_EXTRAS = 2,
120
GLD_SI_SMOOTH_EXTRAS = 3,
125
GLD_PIPELINE_MESA = 0, // Mesa pipeline
126
GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline
127
GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader
130
//---------------------------------------------------------------------------
131
// Vertex definitions for Fixed-Function pipeline
132
//---------------------------------------------------------------------------
135
// NOTE: If the number of texture units is altered then most of
136
// the texture code will need to be revised.
139
#define GLD_MAX_TEXTURE_UNITS_DX9 2
142
// 2D vertex transformed by Mesa
144
#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \
149
FLOAT x, y; // 2D raster coords
150
FLOAT sz; // Screen Z (depth)
151
FLOAT rhw; // Reciprocal homogenous W
152
DWORD diffuse; // Diffuse colour
153
DWORD specular; // For separate-specular support
154
FLOAT t0_u, t0_v; // 1st set of texture coords
155
FLOAT t1_u, t1_v; // 2nd set of texture coords
160
// 3D vertex transformed by Direct3D
162
#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \
167
D3DXVECTOR3 Position; // XYZ Vector in object space
168
D3DCOLOR Diffuse; // Diffuse colour
169
D3DXVECTOR2 TexUnit0; // Texture unit 0
170
D3DXVECTOR2 TexUnit1; // Texture unit 1
173
//---------------------------------------------------------------------------
175
//---------------------------------------------------------------------------
179
DWORD hShader; // If NULL, shader is invalid and cannot be used
180
BOOL bHardware; // If TRUE then shader was created for hardware,
181
// otherwise shader was created for software.
184
//---------------------------------------------------------------------------
186
//---------------------------------------------------------------------------
188
// This keeps a count of how many times we choose each individual internal
189
// pathway. Useful for seeing if a certain pathway was ever used by an app, and
190
// how much each pathway is biased.
191
// Zero the members at context creation and dump stats at context deletion.
193
// Note: DWORD is probably too small
194
ULARGE_INTEGER qwMesa; // Mesa TnL pipeline
195
ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline
196
// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline
197
} GLD_pipeline_usage;
199
// GLDirect Primitive Buffer (points, lines, triangles and quads)
201
// Data for IDirect3DDevice9::CreateVertexBuffer()
202
DWORD dwStride; // Stride of vertex
203
DWORD dwUsage; // Usage flags
204
DWORD dwFVF; // Direct3D Flexible Vertex Format
205
DWORD dwPool; // Pool flags
207
IDirect3DVertexBuffer9 *pVB; // Holds points, lines, tris and quads.
209
// Point list is assumed to be at start of buffer
210
DWORD iFirstLine; // Index of start of line list
211
DWORD iFirstTriangle; // Index of start of triangle list
213
BYTE *pPoints; // Pointer to next free point
214
BYTE *pLines; // Pointer to next free line
215
BYTE *pTriangles; // Pointer to next free triangle
217
DWORD nPoints; // Number of points ready to render
218
DWORD nLines; // Number of lines ready to render
219
DWORD nTriangles; // Number of triangles ready to render
222
// GLDirect DX9 driver data
225
BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered)
226
BOOL bDepthStencil; // Depth buffer needed (stencil optional)
227
D3DFORMAT RenderFormat; // Format of back/front buffer
228
D3DFORMAT DepthFormat; // Format of depth/stencil
229
// float fFlipWindowY; // Value for flipping viewport Y coord
233
BOOL bHasHWTnL; // Device has Hardware Transform/Light?
234
IDirect3D9 *pD3D; // Base Direct3D9 interface
235
IDirect3DDevice9 *pDev; // Direct3D9 Device interface
236
GLD_pb_dx9 PB2d; // Vertices transformed by Mesa
237
GLD_pb_dx9 PB3d; // Vertices transformed by Direct3D
238
D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type
239
D3DXMATRIX matProjection; // Projection matrix for D3D TnL
240
D3DXMATRIX matModelView; // Model/View matrix for D3D TnL
241
int iSetupFunc; // Which setup functions to use
242
BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL
244
// Direct3D vars for two-sided lighting
245
// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting
246
// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders
249
// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline
250
GLD_pipeline_usage PipelineUsage;
252
BOOL bCanScissor; // Scissor test - new for DX9
255
#define GLD_GET_DX9_DRIVER(c) (GLD_driver_dx9*)(c)->glPriv
257
//---------------------------------------------------------------------------
258
// Function prototypes
259
//---------------------------------------------------------------------------
261
PROC gldGetProcAddress_DX9(LPCSTR a);
262
void gldEnableExtensions_DX9(GLcontext *ctx);
263
void gldInstallPipeline_DX9(GLcontext *ctx);
264
void gldSetupDriverPointers_DX9(GLcontext *ctx);
265
//void gldResizeBuffers_DX9(GLcontext *ctx);
266
void gldResizeBuffers_DX9(GLframebuffer *fb);
271
void gldCopyTexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border);
272
void gldCopyTexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
273
void gldCopyTexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width );
274
void gldCopyTexSubImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height );
275
void gldCopyTexSubImage3D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
277
void gld_NEW_TEXTURE_DX9(GLcontext *ctx);
278
void gld_DrawPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels);
279
void gld_ReadPixels_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest);
280
void gld_CopyPixels_DX9(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type);
281
void gld_Bitmap_DX9(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap);
282
const struct gl_texture_format* gld_ChooseTextureFormat_DX9(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType);
283
void gld_TexImage2D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *tObj, struct gl_texture_image *texImage);
284
void gld_TexImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage );
285
void gld_TexSubImage2D_DX9( GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage );
286
void gld_TexSubImage1D_DX9(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, struct gl_texture_object *texObj, struct gl_texture_image *texImage);
287
void gld_DeleteTexture_DX9(GLcontext *ctx, struct gl_texture_object *tObj);
288
void gld_ResetLineStipple_DX9(GLcontext *ctx);
290
// 2D primitive functions
292
void gld_Points2D_DX9(GLcontext *ctx, GLuint first, GLuint last);
294
void gld_Line2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
295
void gld_Line2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
297
void gld_Triangle2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
298
void gld_Triangle2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
299
void gld_Triangle2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
300
void gld_Triangle2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
302
void gld_Quad2DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
303
void gld_Quad2DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
304
void gld_Quad2DFlatExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
305
void gld_Quad2DSmoothExtras_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
307
// 3D primitive functions
309
void gld_Points3D_DX9(GLcontext *ctx, GLuint first, GLuint last);
310
void gld_Line3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
311
void gld_Triangle3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
312
void gld_Quad3DFlat_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
313
void gld_Line3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
314
void gld_Triangle3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
315
void gld_Quad3DSmooth_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
317
// Primitive functions for Two-sided-lighting Vertex Shader
319
void gld_Points2DTwoside_DX9(GLcontext *ctx, GLuint first, GLuint last);
320
void gld_Line2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
321
void gld_Line2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1);
322
void gld_Triangle2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
323
void gld_Triangle2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
324
void gld_Quad2DFlatTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
325
void gld_Quad2DSmoothTwoside_DX9(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);