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 8.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_DX8_SUPPORT_WIN95 120
63
// Typedef for obtaining function from d3d8.dll
64
typedef IDirect3D8* (WINAPI *FNDIRECT3DCREATE8) (UINT);
67
//---------------------------------------------------------------------------
69
//---------------------------------------------------------------------------
72
#define _GLD_TEST_HRESULT(h) \
76
gldLogError(GLDLOG_ERROR, #h, _hr); \
79
#define _GLD_DX8(func) _GLD_TEST_HRESULT(IDirect3D8_##func##)
80
#define _GLD_DX8_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice8_##func##)
81
#define _GLD_DX8_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer8_##func##)
82
#define _GLD_DX8_TEX(func) _GLD_TEST_HRESULT(IDirect3DTexture8_##func##)
84
#define _GLD_DX8(func) IDirect3D8_##func
85
#define _GLD_DX8_DEV(func) IDirect3DDevice8_##func
86
#define _GLD_DX8_VB(func) IDirect3DVertexBuffer8_##func
87
#define _GLD_DX8_TEX(func) IDirect3DTexture8_##func
90
#define SAFE_RELEASE(p) \
93
(p)->lpVtbl->Release(p); \
98
#define SAFE_RELEASE_VB8(p) \
101
IDirect3DVertexBuffer8_Release((p)); \
106
#define SAFE_RELEASE_SURFACE8(p) \
109
IDirect3DSurface8_Release((p)); \
118
GLD_SI_FLAT_EXTRAS = 2,
119
GLD_SI_SMOOTH_EXTRAS = 3,
124
GLD_PIPELINE_MESA = 0, // Mesa pipeline
125
GLD_PIPELINE_D3D_FVF = 1, // Direct3D Fixed-function pipeline
126
GLD_PIPELINE_D3D_VS_TWOSIDE = 2 // Direct3D two-sided-lighting vertex shader
129
//---------------------------------------------------------------------------
130
// Vertex definitions for Fixed-Function pipeline
131
//---------------------------------------------------------------------------
134
// NOTE: If the number of texture units is altered then most of
135
// the texture code will need to be revised.
138
#define GLD_MAX_TEXTURE_UNITS_DX8 2
141
// 2D vertex transformed by Mesa
143
#define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \
148
FLOAT x, y; // 2D raster coords
149
FLOAT sz; // Screen Z (depth)
150
FLOAT rhw; // Reciprocal homogenous W
151
DWORD diffuse; // Diffuse colour
152
DWORD specular; // For separate-specular support
153
FLOAT t0_u, t0_v; // 1st set of texture coords
154
FLOAT t1_u, t1_v; // 2nd set of texture coords
159
// 3D vertex transformed by Direct3D
161
#define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \
166
D3DXVECTOR3 Position; // XYZ Vector in object space
167
D3DCOLOR Diffuse; // Diffuse colour
168
D3DXVECTOR2 TexUnit0; // Texture unit 0
169
D3DXVECTOR2 TexUnit1; // Texture unit 1
172
//---------------------------------------------------------------------------
174
//---------------------------------------------------------------------------
178
DWORD hShader; // If NULL, shader is invalid and cannot be used
179
BOOL bHardware; // If TRUE then shader was created for hardware,
180
// otherwise shader was created for software.
183
//---------------------------------------------------------------------------
185
//---------------------------------------------------------------------------
187
// This keeps a count of how many times we choose each individual internal
188
// pathway. Useful for seeing if a certain pathway was ever used by an app, and
189
// how much each pathway is biased.
190
// Zero the members at context creation and dump stats at context deletion.
192
// Note: DWORD is probably too small
193
ULARGE_INTEGER qwMesa; // Mesa TnL pipeline
194
ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline
195
// ULARGE_INTEGER dwD3D2SVS; // Direct3D Two-Sided Vertex Shader pipeline
196
} GLD_pipeline_usage;
198
// GLDirect Primitive Buffer (points, lines, triangles and quads)
200
// Data for IDirect3DDevice8::CreateVertexBuffer()
201
DWORD dwStride; // Stride of vertex
202
DWORD dwUsage; // Usage flags
203
DWORD dwFVF; // Direct3D Flexible Vertex Format
204
DWORD dwPool; // Pool flags
206
IDirect3DVertexBuffer8 *pVB; // Holds points, lines, tris and quads.
208
// Point list is assumed to be at start of buffer
209
DWORD iFirstLine; // Index of start of line list
210
DWORD iFirstTriangle; // Index of start of triangle list
212
BYTE *pPoints; // Pointer to next free point
213
BYTE *pLines; // Pointer to next free line
214
BYTE *pTriangles; // Pointer to next free triangle
216
DWORD nPoints; // Number of points ready to render
217
DWORD nLines; // Number of lines ready to render
218
DWORD nTriangles; // Number of triangles ready to render
221
// GLDirect DX8 driver data
224
BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered)
225
BOOL bDepthStencil; // Depth buffer needed (stencil optional)
226
D3DFORMAT RenderFormat; // Format of back/front buffer
227
D3DFORMAT DepthFormat; // Format of depth/stencil
228
// float fFlipWindowY; // Value for flipping viewport Y coord
232
BOOL bHasHWTnL; // Device has Hardware Transform/Light?
233
IDirect3D8 *pD3D; // Base Direct3D8 interface
234
IDirect3DDevice8 *pDev; // Direct3D8 Device interface
235
GLD_pb_dx8 PB2d; // Vertices transformed by Mesa
236
GLD_pb_dx8 PB3d; // Vertices transformed by Direct3D
237
D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type
238
D3DXMATRIX matProjection; // Projection matrix for D3D TnL
239
D3DXMATRIX matModelView; // Model/View matrix for D3D TnL
240
int iSetupFunc; // Which setup functions to use
241
BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL
243
// Direct3D vars for two-sided lighting
244
// GLD_vertexShader VStwosidelight; // Vertex Shader for two-sided lighting
245
// D3DXMATRIX matWorldViewProj;// World/View/Projection matrix for shaders
248
// GLD_tnl_pipeline TnLPipeline; // Index of current internal pipeline
249
GLD_pipeline_usage PipelineUsage;
252
#define GLD_GET_DX8_DRIVER(c) (GLD_driver_dx8*)(c)->glPriv
254
//---------------------------------------------------------------------------
255
// Function prototypes
256
//---------------------------------------------------------------------------
258
PROC gldGetProcAddress_DX8(LPCSTR a);
259
void gldEnableExtensions_DX8(GLcontext *ctx);
260
void gldInstallPipeline_DX8(GLcontext *ctx);
261
void gldSetupDriverPointers_DX8(GLcontext *ctx);
262
//void gldResizeBuffers_DX8(GLcontext *ctx);
263
void gldResizeBuffers_DX8(GLframebuffer *fb);
268
void gldCopyTexImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border);
269
void gldCopyTexImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
270
void gldCopyTexSubImage1D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width );
271
void gldCopyTexSubImage2D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height );
272
void gldCopyTexSubImage3D_DX8(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
274
void gld_NEW_TEXTURE_DX8(GLcontext *ctx);
275
void gld_DrawPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels);
276
void gld_ReadPixels_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest);
277
void gld_CopyPixels_DX8(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type);
278
void gld_Bitmap_DX8(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap);
279
const struct gl_texture_format* gld_ChooseTextureFormat_DX8(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType);
280
void gld_TexImage2D_DX8(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);
281
void gld_TexImage1D_DX8(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 );
282
void gld_TexSubImage2D_DX8( 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 );
283
void gld_TexSubImage1D_DX8(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);
284
void gld_DeleteTexture_DX8(GLcontext *ctx, struct gl_texture_object *tObj);
285
void gld_ResetLineStipple_DX8(GLcontext *ctx);
287
// 2D primitive functions
289
void gld_Points2D_DX8(GLcontext *ctx, GLuint first, GLuint last);
291
void gld_Line2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
292
void gld_Line2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
294
void gld_Triangle2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
295
void gld_Triangle2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
296
void gld_Triangle2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
297
void gld_Triangle2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
299
void gld_Quad2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
300
void gld_Quad2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
301
void gld_Quad2DFlatExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
302
void gld_Quad2DSmoothExtras_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
304
// 3D primitive functions
306
void gld_Points3D_DX8(GLcontext *ctx, GLuint first, GLuint last);
307
void gld_Line3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
308
void gld_Triangle3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
309
void gld_Quad3DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
310
void gld_Line3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
311
void gld_Triangle3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
312
void gld_Quad3DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
314
// Primitive functions for Two-sided-lighting Vertex Shader
316
void gld_Points2DTwoside_DX8(GLcontext *ctx, GLuint first, GLuint last);
317
void gld_Line2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
318
void gld_Line2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
319
void gld_Triangle2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
320
void gld_Triangle2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
321
void gld_Quad2DFlatTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
322
void gld_Quad2DSmoothTwoside_DX8(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);