1 /*===========================================================================*/
3 /* Mesa-3.0 DirectX 6 Driver */
7 /* http://www.altsoftware.com/ */
9 /* Copyright (c) 1999-1998 alt.software inc. All Rights Reserved */
10 /*===========================================================================*/
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. */
19 /* TODO: this can be redone to be called by Mesa directly. */
20 /*===========================================================================*/
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
)
25 PMESAD3DHAL pHAL
= (PMESAD3DHAL
)pShared
;
31 DPF(( DBG_FUNC
, "CleaHAL();" ));
33 /* Make sure we have enough info. */
34 if ( (pHAL
== NULL
) || (pHAL
->lpViewport
== NULL
) )
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
;
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
;
55 rc
= pHAL
->lpViewport
->Clear2( 1, &d3dRect
, dwFlags
, dwColor
, zv
, dwStencil
);
58 RIP( pHAL
, "Clear2 ->", ErrorStringD3D(rc
) );
61 pHAL
->lpViewport
->Clear2( 1, &d3dRect
, dwFlags
, dwColor
, zv
, dwStencil
);
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. */
69 /* TODO: I'm not sure if I want to bother to check for errors on this call. */
70 /* The overhead kills me... */
71 /*===========================================================================*/
73 /*===========================================================================*/
74 extern "C" void DrawPrimitiveHAL( PMESAD3DSHARED pShared
, D3DPRIMITIVETYPE dptPrimitiveType
, D3DTLVERTEX
*pVertices
, DWORD dwCount
)
76 PMESAD3DHAL pHAL
= (PMESAD3DHAL
)pShared
;
81 DPF(( DBG_FUNC
, "DrawPrimitveHAL();" ));
83 /* Make sure we have enough info. */
84 if ( (pHAL
== NULL
) || (pHAL
->lpD3DDevice
== NULL
) )
87 DPF(( DBG_PRIM_INFO
, "DP( %d )", dwCount
));
89 rc
= pHAL
->lpD3DDevice
->DrawPrimitive( dptPrimitiveType
,
93 (D3DDP_DONOTCLIP
| D3DDP_DONOTLIGHT
) );
96 RIP( pHAL
, "DrawPrimitive ->", ErrorStringD3D(rc
) );
99 pHAL
->lpD3DDevice
->DrawPrimitive( dptPrimitiveType
,
103 (D3DDP_DONOTCLIP
| D3DDP_DONOTLIGHT
) );
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 /*===========================================================================*/
116 /*===========================================================================*/
117 extern "C" void SwapBuffersHAL( PMESAD3DSHARED pShared
)
119 PMESAD3DHAL pHAL
= (PMESAD3DHAL
)pShared
;
124 DPF(( DBG_FUNC
, "SwapBuffersHAL();" ));
125 DPF(( DBG_ALL_PROFILE
, "=================SWAP===================" ));
127 /* Make sure we have enough info. */
128 if ( (pHAL
== NULL
) || (pHAL
->lpD3DDevice
== NULL
) )
131 /* Make sure we have enough info. */
132 if ( pHAL
->lpDDSPrimary
!= NULL
)
134 rc
= pHAL
->lpD3DDevice
->EndScene();
137 RIP( pHAL
, "EndScene ->", ErrorStringD3D(rc
) );
140 if ( pShared
->bFlipable
)
142 DPF(( DBG_CNTX_PROFILE
, "Swap->FLIP" ));
143 rc
= pHAL
->lpDDSPrimary
->Flip( NULL
, DDFLIP_WAIT
);
147 DPF(( DBG_CNTX_PROFILE
, "Swap->Blt" ));
148 rc
= pHAL
->lpDDSPrimary
->Blt( &pShared
->rectW
, pHAL
->lpDDSRender
, NULL
, DDBLT_WAIT
, NULL
);
152 RIP( pHAL
, "Blt (RENDER/PRIMARY) ->", ErrorStringD3D(rc
) );
155 rc
= pHAL
->lpD3DDevice
->BeginScene();
158 RIP( pHAL
, "BeginScene ->", ErrorStringD3D(rc
) );
162 pHAL
->lpD3DDevice
->EndScene();
164 if ( pShared
->bFlipable
)
165 pHAL
->lpDDSPrimary
->Flip( NULL
, DDFLIP_WAIT
);
167 pHAL
->lpDDSPrimary
->Blt( &pShared
->rectW
, pHAL
->lpDDSRender
, NULL
, DDBLT_WAIT
, NULL
);
169 pHAL
->lpD3DDevice
->BeginScene();
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. */
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 /*===========================================================================*/
182 /*===========================================================================*/
183 extern "C" void SetStateHAL( PMESAD3DSHARED pShared
, DWORD dwType
, DWORD dwState
)
185 PMESAD3DHAL pHAL
= (PMESAD3DHAL
)pShared
;
190 DPF(( DBG_FUNC
, "SetStateHAL();" ));
192 /* Make sure we have enough info. */
193 if ( (pHAL
== NULL
) || (pHAL
->lpD3DDevice
== NULL
) )
196 rc
= pHAL
->lpD3DDevice
->SetRenderState( (D3DRENDERSTATETYPE
)dwType
, dwState
);
199 RIP( pHAL
, "SetRenderState ->", ErrorStringD3D(rc
) );
203 pHAL
->lpD3DDevice
->SetRenderState( (D3DRENDERSTATETYPE
)dwType
, dwState
);