draw: corrections to allow for different cliptest cases
[mesa.git] / src / mesa / drivers / windows / gldirect / dx7 / gld_dx7.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/2000/XP/XBox (Win32)
32 *
33 * Description: GLDirect Direct3D 7.0a header file
34 *
35 ****************************************************************************/
36
37 #ifndef _GLD_DX7_H
38 #define _GLD_DX7_H
39
40 //---------------------------------------------------------------------------
41 // Windows includes
42 //---------------------------------------------------------------------------
43
44 #define DIRECTDRAW_VERSION 0x0700
45 #define DIRECT3D_VERSION 0x0700
46 #include <d3d.h>
47 #include <d3dx.h>
48
49 // Typedef for obtaining function from d3d7.dll
50 //typedef IDirect3D7* (WINAPI *FNDIRECT3DCREATE7) (UINT);
51
52
53 //---------------------------------------------------------------------------
54 // Defines
55 //---------------------------------------------------------------------------
56
57 #ifdef _DEBUG
58 // Debug build tests the return value of D3D calls
59 #define _GLD_TEST_HRESULT(h) \
60 { \
61 HRESULT _hr = (h); \
62 if (FAILED(_hr)) { \
63 gldLogError(GLDLOG_ERROR, #h, _hr); \
64 } \
65 }
66 #define _GLD_DX7(func) _GLD_TEST_HRESULT(IDirect3D7_##func##)
67 #define _GLD_DX7_DEV(func) _GLD_TEST_HRESULT(IDirect3DDevice7_##func##)
68 #define _GLD_DX7_VB(func) _GLD_TEST_HRESULT(IDirect3DVertexBuffer7_##func##)
69 #define _GLD_DX7_TEX(func) _GLD_TEST_HRESULT(IDirectDrawSurface7_##func##)
70 #else
71 #define _GLD_DX7(func) IDirect3D7_##func
72 #define _GLD_DX7_DEV(func) IDirect3DDevice7_##func
73 #define _GLD_DX7_VB(func) IDirect3DVertexBuffer7_##func
74 #define _GLD_DX7_TEX(func) IDirectDrawSurface7_##func
75 #endif
76
77 #define SAFE_RELEASE(p) \
78 { \
79 if (p) { \
80 (p)->lpVtbl->Release(p); \
81 (p) = NULL; \
82 } \
83 }
84
85 #define SAFE_RELEASE_VB7(p) \
86 { \
87 if (p) { \
88 IDirect3DVertexBuffer7_Release((p)); \
89 (p) = NULL; \
90 } \
91 }
92
93 #define SAFE_RELEASE_SURFACE7(p) \
94 { \
95 if (p) { \
96 IDirectDrawSurface7_Release((p)); \
97 (p) = NULL; \
98 } \
99 }
100
101 // Emulate some DX8 defines
102 #define D3DCOLOR_ARGB(a,r,g,b) ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
103 #define D3DCOLOR_RGBA(r,g,b,a) D3DCOLOR_ARGB(a,r,g,b)
104 #define D3DCOLOR_COLORVALUE(r,g,b,a) D3DCOLOR_RGBA((DWORD)((r)*255.f),(DWORD)((g)*255.f),(DWORD)((b)*255.f),(DWORD)((a)*255.f))
105
106
107 // Setup index.
108 enum {
109 GLD_SI_FLAT = 0,
110 GLD_SI_SMOOTH = 1,
111 GLD_SI_FLAT_EXTRAS = 2,
112 GLD_SI_SMOOTH_EXTRAS = 3,
113 };
114
115 //---------------------------------------------------------------------------
116 // Vertex definitions for Fixed-Function pipeline
117 //---------------------------------------------------------------------------
118
119 //
120 // NOTE: If the number of texture units is altered then most of
121 // the texture code will need to be revised.
122 //
123
124 #define GLD_MAX_TEXTURE_UNITS_DX7 2
125
126 //
127 // 2D vertex transformed by Mesa
128 //
129 #define GLD_FVF_2D_VERTEX ( D3DFVF_XYZRHW | \
130 D3DFVF_DIFFUSE | \
131 D3DFVF_SPECULAR | \
132 D3DFVF_TEX2)
133 typedef struct {
134 FLOAT x, y; // 2D raster coords
135 FLOAT sz; // Screen Z (depth)
136 FLOAT rhw; // Reciprocal homogenous W
137 DWORD diffuse; // Diffuse colour
138 DWORD specular; // For separate-specular support
139 FLOAT t0_u, t0_v; // 1st set of texture coords
140 FLOAT t1_u, t1_v; // 2nd set of texture coords
141 } GLD_2D_VERTEX;
142
143
144 //
145 // 3D vertex transformed by Direct3D
146 //
147 #define GLD_FVF_3D_VERTEX ( D3DFVF_XYZ | \
148 D3DFVF_DIFFUSE | \
149 D3DFVF_TEX2)
150
151 typedef struct {
152 D3DXVECTOR3 Position; // XYZ Vector in object space
153 D3DCOLOR Diffuse; // Diffuse colour
154 D3DXVECTOR2 TexUnit0; // Texture unit 0
155 D3DXVECTOR2 TexUnit1; // Texture unit 1
156 } GLD_3D_VERTEX;
157
158 //---------------------------------------------------------------------------
159 // Structs
160 //---------------------------------------------------------------------------
161
162 // This keeps a count of how many times we choose each individual internal
163 // pathway. Useful for seeing if a certain pathway was ever used by an app, and
164 // how much each pathway is biased.
165 // Zero the members at context creation and dump stats at context deletion.
166 typedef struct {
167 // Note: DWORD is probably too small
168 ULARGE_INTEGER qwMesa; // Mesa TnL pipeline
169 ULARGE_INTEGER qwD3DFVF; // Direct3D Fixed-Function pipeline
170 } GLD_pipeline_usage;
171
172 // GLDirect Primitive Buffer (points, lines, triangles and quads)
173 typedef struct {
174 // Data for IDirect3D7::CreateVertexBuffer()
175 DWORD dwStride; // Stride of vertex
176 DWORD dwCreateFlags; // Create flags
177 DWORD dwFVF; // Direct3D Flexible Vertex Format
178
179 IDirect3DVertexBuffer7 *pVB; // Holds points, lines, tris and quads.
180
181 // Point list is assumed to be at start of buffer
182 DWORD iFirstLine; // Index of start of line list
183 DWORD iFirstTriangle; // Index of start of triangle list
184
185 BYTE *pPoints; // Pointer to next free point
186 BYTE *pLines; // Pointer to next free line
187 BYTE *pTriangles; // Pointer to next free triangle
188
189 DWORD nPoints; // Number of points ready to render
190 DWORD nLines; // Number of lines ready to render
191 DWORD nTriangles; // Number of triangles ready to render
192 } GLD_pb_dx7;
193
194 // GLDirect DX7 driver data
195 typedef struct {
196 // GLDirect vars
197 BOOL bDoublebuffer; // Doublebuffer (otherwise single-buffered)
198 BOOL bDepthStencil; // Depth buffer needed (stencil optional)
199 D3DX_SURFACEFORMAT RenderFormat; // Format of back/front buffer
200 D3DX_SURFACEFORMAT DepthFormat; // Format of depth/stencil
201
202 // Direct3D vars
203 DDCAPS ddCaps;
204 D3DDEVICEDESC7 d3dCaps;
205 BOOL bHasHWTnL; // Device has Hardware Transform/Light?
206 ID3DXContext *pD3DXContext; // Base D3DX context
207 IDirectDraw7 *pDD; // DirectDraw7 interface
208 IDirect3D7 *pD3D; // Base Direct3D7 interface
209 IDirect3DDevice7 *pDev; // Direct3D7 Device interface
210 GLD_pb_dx7 PB2d; // Vertices transformed by Mesa
211 GLD_pb_dx7 PB3d; // Vertices transformed by Direct3D
212 D3DPRIMITIVETYPE d3dpt; // Current Direct3D primitive type
213 D3DMATRIX matProjection; // Projection matrix for D3D TnL
214 D3DMATRIX matModelView; // Model/View matrix for D3D TnL
215 int iSetupFunc; // Which setup functions to use
216 BOOL bUseMesaTnL; // Whether to use Mesa or D3D for TnL
217
218 GLD_pipeline_usage PipelineUsage;
219 } GLD_driver_dx7;
220
221 #define GLD_GET_DX7_DRIVER(c) (GLD_driver_dx7*)(c)->glPriv
222
223 //---------------------------------------------------------------------------
224 // Function prototypes
225 //---------------------------------------------------------------------------
226
227 PROC gldGetProcAddress_DX7(LPCSTR a);
228 void gldEnableExtensions_DX7(GLcontext *ctx);
229 void gldInstallPipeline_DX7(GLcontext *ctx);
230 void gldSetupDriverPointers_DX7(GLcontext *ctx);
231 void gldResizeBuffers_DX7(GLframebuffer *fb);
232
233
234 // Texture functions
235
236 void gldCopyTexImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border);
237 void gldCopyTexImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
238 void gldCopyTexSubImage1D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width );
239 void gldCopyTexSubImage2D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height );
240 void gldCopyTexSubImage3D_DX7(GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
241
242 void gld_NEW_TEXTURE_DX7(GLcontext *ctx);
243 void gld_DrawPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels);
244 void gld_ReadPixels_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const struct gl_pixelstore_attrib *unpack, GLvoid *dest);
245 void gld_CopyPixels_DX7(GLcontext *ctx, GLint srcx, GLint srcy, GLsizei width, GLsizei height, GLint dstx, GLint dsty, GLenum type);
246 void gld_Bitmap_DX7(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap);
247 const struct gl_texture_format* gld_ChooseTextureFormat_DX7(GLcontext *ctx, GLint internalFormat, GLenum srcFormat, GLenum srcType);
248 void gld_TexImage2D_DX7(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);
249 void gld_TexImage1D_DX7(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 );
250 void gld_TexSubImage2D_DX7( 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 );
251 void gld_TexSubImage1D_DX7(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);
252 void gld_DeleteTexture_DX7(GLcontext *ctx, struct gl_texture_object *tObj);
253 void gld_ResetLineStipple_DX7(GLcontext *ctx);
254
255 // 2D primitive functions
256
257 void gld_Points2D_DX7(GLcontext *ctx, GLuint first, GLuint last);
258
259 void gld_Line2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
260 void gld_Line2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
261
262 void gld_Triangle2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
263 void gld_Triangle2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
264 void gld_Triangle2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
265 void gld_Triangle2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
266
267 void gld_Quad2DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
268 void gld_Quad2DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
269 void gld_Quad2DFlatExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
270 void gld_Quad2DSmoothExtras_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
271
272 // 3D primitive functions
273
274 void gld_Points3D_DX7(GLcontext *ctx, GLuint first, GLuint last);
275 void gld_Line3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
276 void gld_Triangle3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
277 void gld_Quad3DFlat_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
278 void gld_Line3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
279 void gld_Triangle3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
280 void gld_Quad3DSmooth_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
281
282 // Primitive functions for Two-sided-lighting Vertex Shader
283
284 void gld_Points2DTwoside_DX7(GLcontext *ctx, GLuint first, GLuint last);
285 void gld_Line2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
286 void gld_Line2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1);
287 void gld_Triangle2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
288 void gld_Triangle2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2);
289 void gld_Quad2DFlatTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
290 void gld_Quad2DSmoothTwoside_DX7(GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
291
292 #endif