Convert crlf->lf line endings.
[mesa.git] / src / mesa / drivers / d3d / D3DRaster.cpp
1 /*===========================================================================*/
2 /* */
3 /* Mesa-3.0 DirectX 6 Driver */
4 /* */
5 /* By Leigh McRae */
6 /* */
7 /* http://www.altsoftware.com/ */
8 /* */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
11 #include "D3DHAL.h"
12 /*===========================================================================*/
13 /* This function clears the context bound to the supplied shared context. */
14 /* The function takes the D3D flags D3DCLEAR_TARGET, D3DCLEAR_STENCIL and */
15 /* D3DCLEAR_ZBUFFER. Set bAll to TRUE for a full clear else supply the coord*/
16 /* of the rect to be cleared relative to the window. The color is always a */
17 /* 32bit value (RGBA). Fill in the z-value and stencil if needed. */
18 /* */
19 /* TODO: this can be redone to be called by Mesa directly. */
20 /*===========================================================================*/
21 /* RETURN: */
22 /*===========================================================================*/
23 extern "C" void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil )
24 {
25 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
26 D3DRECT d3dRect;
27
28 #ifdef D3D_DEBUG
29 HRESULT rc;
30
31 DPF(( DBG_FUNC, "CleaHAL();" ));
32
33 /* Make sure we have enough info. */
34 if ( (pHAL == NULL) || (pHAL->lpViewport == NULL) )
35 return;
36 #endif
37
38 if ( bAll )
39 {
40 /* I assume my viewport is valid. */
41 d3dRect.lX1 = pShared->rectV.left;
42 d3dRect.lY1 = pShared->rectV.top;
43 d3dRect.lX2 = pShared->rectV.right;
44 d3dRect.lY2 = pShared->rectV.bottom;
45 }
46 else
47 {
48 d3dRect.lX1 = pShared->rectV.left + x;
49 d3dRect.lY1 = pShared->rectV.top + y;
50 d3dRect.lX2 = d3dRect.lX1 + cx;
51 d3dRect.lY2 = d3dRect.lY1 + cy;
52 }
53
54 #ifdef D3D_DEBUG
55 rc = pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil );
56 if ( FAILED(rc) )
57 {
58 RIP( pHAL, "Clear2 ->", ErrorStringD3D(rc) );
59 }
60 #else
61 pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil );
62 #endif
63 }
64 /*===========================================================================*/
65 /* Well this is the guts of it all. Here we rasterize the primitives that */
66 /* are in their final form. OpenGL has done all the lighting, transfomations*/
67 /* and clipping at this point. */
68 /* */
69 /* TODO: I'm not sure if I want to bother to check for errors on this call. */
70 /* The overhead kills me... */
71 /*===========================================================================*/
72 /* RETURN: */
73 /*===========================================================================*/
74 extern "C" void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount )
75 {
76 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
77
78 #ifdef D3D_DEBUG
79 HRESULT rc;
80
81 DPF(( DBG_FUNC, "DrawPrimitveHAL();" ));
82
83 /* Make sure we have enough info. */
84 if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
85 return;
86
87 DPF(( DBG_PRIM_INFO, "DP( %d )", dwCount ));
88
89 rc = pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType,
90 D3DFVF_TLVERTEX,
91 (LPVOID)pVertices,
92 dwCount,
93 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
94 if ( FAILED(rc) )
95 {
96 RIP( pHAL, "DrawPrimitive ->", ErrorStringD3D(rc) );
97 }
98 #else
99 pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType,
100 D3DFVF_TLVERTEX,
101 (LPVOID)pVertices,
102 dwCount,
103 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
104 #endif
105 }
106 /*===========================================================================*/
107 /* This call will handle the swapping of the buffers. Now I didn't bother */
108 /* to support single buffered so this will be used for glFlush() as its all */
109 /* the same. So first we do an EndScene as we are always considered to be in*/
110 /* a BeginScene because when we leave we do a BeginScene. Now note that when*/
111 /* the context is created in the first place we do a BeginScene also just to */
112 /* get things going. The call will use either Flip/blt based on the type of */
113 /* surface was created for rendering. */
114 /*===========================================================================*/
115 /* RETURN: */
116 /*===========================================================================*/
117 extern "C" void SwapBuffersHAL( PMESAD3DSHARED pShared )
118 {
119 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
120
121 #ifdef D3D_DEBUG
122 HRESULT rc;
123
124 DPF(( DBG_FUNC, "SwapBuffersHAL();" ));
125 DPF(( DBG_ALL_PROFILE, "=================SWAP===================" ));
126
127 /* Make sure we have enough info. */
128 if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
129 return;
130
131 /* Make sure we have enough info. */
132 if ( pHAL->lpDDSPrimary != NULL )
133 {
134 rc = pHAL->lpD3DDevice->EndScene();
135 if ( FAILED(rc) )
136 {
137 RIP( pHAL, "EndScene ->", ErrorStringD3D(rc) );
138 }
139
140 if ( pShared->bFlipable )
141 {
142 DPF(( DBG_CNTX_PROFILE, "Swap->FLIP" ));
143 rc = pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
144 }
145 else
146 {
147 DPF(( DBG_CNTX_PROFILE, "Swap->Blt" ));
148 rc = pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL );
149 }
150 if ( FAILED(rc) )
151 {
152 RIP( pHAL, "Blt (RENDER/PRIMARY) ->", ErrorStringD3D(rc) );
153 }
154
155 rc = pHAL->lpD3DDevice->BeginScene();
156 if ( FAILED(rc) )
157 {
158 RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) );
159 }
160 }
161 #else
162 pHAL->lpD3DDevice->EndScene();
163
164 if ( pShared->bFlipable )
165 pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
166 else
167 pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL );
168
169 pHAL->lpD3DDevice->BeginScene();
170
171 #endif
172 }
173 /*===========================================================================*/
174 /* This function is a very thin wrapper for the D3D call 'SetRenderState'. */
175 /* Using this function requires all the types to be defined by including the */
176 /* D3D header file. */
177 /* */
178 /* TODO: would be much better to get ride of all these calls per VBRender. */
179 /* I feel I should get this call into SetRenderStates() the RenderVB. */
180 /*===========================================================================*/
181 /* RETURN: */
182 /*===========================================================================*/
183 extern "C" void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState )
184 {
185 PMESAD3DHAL pHAL = (PMESAD3DHAL)pShared;
186
187 #ifdef D3D_DEBUG
188 HRESULT rc;
189
190 DPF(( DBG_FUNC, "SetStateHAL();" ));
191
192 /* Make sure we have enough info. */
193 if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
194 return;
195
196 rc = pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState );
197 if ( FAILED(rc) )
198 {
199 RIP( pHAL, "SetRenderState ->", ErrorStringD3D(rc) );
200 }
201
202 #else
203 pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState );
204 #endif
205 }
206
207
208
209
210
211
212
213