~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/windows/gldirect/dx8/gld_dx8.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/2000/XP/XBox (Win32)
32
 
*
33
 
* Description:  GLDirect Direct3D 8.0 header file
34
 
*
35
 
****************************************************************************/
36
 
 
37
 
#ifndef _GLD_DX8_H
38
 
#define _GLD_DX8_H
39
 
 
40
 
//---------------------------------------------------------------------------
41
 
// Windows includes
42
 
//---------------------------------------------------------------------------
43
 
 
44
 
//#ifndef STRICT
45
 
//#define STRICT
46
 
//#endif
47
 
 
48
 
//#define WIN32_LEAN_AND_MEAN
49
 
//#include <windows.h>
50
 
#include <d3d8.h>
51
 
#include <d3dx8.h>
52
 
 
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.
57
 
//
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).
60
 
//
61
 
#define D3D_SDK_VERSION_DX8_SUPPORT_WIN95 120
62
 
 
63
 
// Typedef for obtaining function from d3d8.dll
64
 
typedef IDirect3D8* (WINAPI *FNDIRECT3DCREATE8) (UINT);
65
 
 
66
 
 
67
 
//---------------------------------------------------------------------------
68
 
// Defines
69
 
//---------------------------------------------------------------------------
70
 
 
71
 
#ifdef _DEBUG
72
 
#define _GLD_TEST_HRESULT(h)                                    \
73
 
{                                                                                               \
74
 
        HRESULT _hr = (h);                                                      \
75
 
        if (FAILED(_hr)) {                                                      \
76
 
                gldLogError(GLDLOG_ERROR, #h, _hr);             \
77
 
        }                                                                                       \
78
 
}
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##)
83
 
#else
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
88
 
#endif
89
 
 
90
 
#define SAFE_RELEASE(p)                 \
91
 
{                                                               \
92
 
        if (p) {                                        \
93
 
                (p)->lpVtbl->Release(p);        \
94
 
                (p) = NULL;                             \
95
 
        }                                                       \
96
 
}
97
 
 
98
 
#define SAFE_RELEASE_VB8(p)                                             \
99
 
{                                                                                               \
100
 
        if (p) {                                                                        \
101
 
                IDirect3DVertexBuffer8_Release((p));    \
102
 
                (p) = NULL;                                                             \
103
 
        }                                                                                       \
104
 
}
105
 
 
106
 
#define SAFE_RELEASE_SURFACE8(p)                \
107
 
{                                                                               \
108
 
        if (p) {                                                        \
109
 
                IDirect3DSurface8_Release((p)); \
110
 
                (p) = NULL;                                             \
111
 
        }                                                                       \
112
 
}
113
 
 
114
 
// Setup index.
115
 
enum {
116
 
        GLD_SI_FLAT                             = 0,
117
 
        GLD_SI_SMOOTH                   = 1,
118
 
        GLD_SI_FLAT_EXTRAS              = 2,
119
 
        GLD_SI_SMOOTH_EXTRAS    = 3,
120
 
};
121
 
/*
122
 
// Internal pipeline
123
 
typedef enum {
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
127
 
} GLD_tnl_pipeline;
128
 
*/
129
 
//---------------------------------------------------------------------------
130
 
// Vertex definitions for Fixed-Function pipeline
131
 
//---------------------------------------------------------------------------
132
 
 
133
 
//
134
 
// NOTE: If the number of texture units is altered then most of
135
 
//       the texture code will need to be revised.
136
 
//
137
 
 
138
 
#define GLD_MAX_TEXTURE_UNITS_DX8       2
139
 
 
140
 
//
141
 
// 2D vertex transformed by Mesa
142
 
//
143
 
#define GLD_FVF_2D_VERTEX (     D3DFVF_XYZRHW |         \
144
 
                                                        D3DFVF_DIFFUSE |        \
145
 
                                                        D3DFVF_SPECULAR |       \
146
 
                                                        D3DFVF_TEX2)
147
 
typedef struct {
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
155
 
} GLD_2D_VERTEX;
156
 
 
157
 
 
158
 
//
159
 
// 3D vertex transformed by Direct3D
160
 
//
161
 
#define GLD_FVF_3D_VERTEX (     D3DFVF_XYZ |                            \
162
 
                                                        D3DFVF_DIFFUSE |                        \
163
 
                                                        D3DFVF_TEX2)
164
 
 
165
 
typedef struct {
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
170
 
} GLD_3D_VERTEX;
171
 
 
172
 
//---------------------------------------------------------------------------
173
 
// Vertex Shaders
174
 
//---------------------------------------------------------------------------
175
 
/*
176
 
// DX8 Vertex Shader
177
 
typedef struct {
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.
181
 
} GLD_vertexShader;
182
 
*/
183
 
//---------------------------------------------------------------------------
184
 
// Structs
185
 
//---------------------------------------------------------------------------
186
 
 
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.
191
 
typedef struct {
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;
197
 
 
198
 
// GLDirect Primitive Buffer (points, lines, triangles and quads)
199
 
typedef struct {
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
205
 
 
206
 
        IDirect3DVertexBuffer8  *pVB;                   // Holds points, lines, tris and quads.
207
 
 
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
211
 
 
212
 
        BYTE                                    *pPoints;               // Pointer to next free point
213
 
        BYTE                                    *pLines;                // Pointer to next free line
214
 
        BYTE                                    *pTriangles;    // Pointer to next free triangle
215
 
 
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
219
 
} GLD_pb_dx8;
220
 
 
221
 
// GLDirect DX8 driver data
222
 
typedef struct {
223
 
        // GLDirect vars
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
229
 
 
230
 
        // Direct3D vars
231
 
        D3DCAPS8                                d3dCaps8;
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
242
 
 
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
246
 
 
247
 
 
248
 
//      GLD_tnl_pipeline                TnLPipeline;    // Index of current internal pipeline
249
 
        GLD_pipeline_usage              PipelineUsage;
250
 
} GLD_driver_dx8;
251
 
 
252
 
#define GLD_GET_DX8_DRIVER(c) (GLD_driver_dx8*)(c)->glPriv
253
 
 
254
 
//---------------------------------------------------------------------------
255
 
// Function prototypes
256
 
//---------------------------------------------------------------------------
257
 
 
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);
264
 
 
265
 
 
266
 
// Texture functions
267
 
 
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 );
273
 
 
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);
286
 
 
287
 
// 2D primitive functions
288
 
 
289
 
void    gld_Points2D_DX8(GLcontext *ctx, GLuint first, GLuint last);
290
 
 
291
 
void    gld_Line2DFlat_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
292
 
void    gld_Line2DSmooth_DX8(GLcontext *ctx, GLuint v0, GLuint v1);
293
 
 
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);
298
 
 
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);
303
 
 
304
 
// 3D primitive functions
305
 
 
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);
313
 
 
314
 
// Primitive functions for Two-sided-lighting Vertex Shader
315
 
 
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);
323
 
 
324
 
#endif