summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/d3d/D3DRaster.cpp
blob: b87b3abd6d37d52e8c710184e406d3daa33d9552 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*===========================================================================*/
/*                                                                           */
/* Mesa-3.0 DirectX 6 Driver                                                 */
/*                                                                           */
/* By Leigh McRae                                                            */
/*                                                                           */
/* http://www.altsoftware.com/                                               */
/*                                                                           */
/* Copyright (c) 1999-1998  alt.software inc.  All Rights Reserved           */
/*===========================================================================*/
#include "D3DHAL.h"
/*===========================================================================*/
/*  This function clears the context bound to the supplied shared context.   */
/* The function takes the D3D flags D3DCLEAR_TARGET, D3DCLEAR_STENCIL and    */
/* D3DCLEAR_ZBUFFER.  Set bAll to TRUE for a full clear else supply the coord*/
/* of the rect to be cleared relative to the window.  The color is always a  */
/* 32bit value (RGBA).  Fill in the z-value and stencil if needed.           */
/*                                                                           */
/*  TODO: this can be redone to be called by Mesa directly.                  */
/*===========================================================================*/
/* RETURN:                                                                   */
/*===========================================================================*/
extern "C" void ClearHAL( PMESAD3DSHARED pShared, DWORD dwFlags, BOOL bAll, int x, int y, int cx, int cy, DWORD dwColor, float zv, DWORD dwStencil )
{
  PMESAD3DHAL	pHAL = (PMESAD3DHAL)pShared;
  D3DRECT		d3dRect;

#ifdef D3D_DEBUG
  HRESULT		rc;

  DPF(( DBG_FUNC, "CleaHAL();" ));

  /* Make sure we have enough info. */
  if ( (pHAL == NULL) || (pHAL->lpViewport == NULL) )
    return;
#endif

  if ( bAll )
  {
    /* I assume my viewport is valid. */
    d3dRect.lX1 = pShared->rectV.left;
    d3dRect.lY1 = pShared->rectV.top;
    d3dRect.lX2 = pShared->rectV.right;
    d3dRect.lY2 = pShared->rectV.bottom;
  }
  else
  {
    d3dRect.lX1 = pShared->rectV.left + x;
    d3dRect.lY1 = pShared->rectV.top  + y;
    d3dRect.lX2 = d3dRect.lX1 + cx;
    d3dRect.lY2 = d3dRect.lY1 + cy;
  }

#ifdef D3D_DEBUG
  rc = pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil );
  if ( FAILED(rc) )
  {
    RIP( pHAL, "Clear2 ->", ErrorStringD3D(rc) );
  }
#else
  pHAL->lpViewport->Clear2( 1, &d3dRect, dwFlags, dwColor, zv, dwStencil );
#endif
}
/*===========================================================================*/
/*  Well this is the guts of it all.  Here we rasterize the primitives that  */
/* are in their final form.  OpenGL has done all the lighting, transfomations*/
/* and clipping at this point.                                               */
/*                                                                           */
/* TODO:  I'm not sure if I want to bother to check for errors on this call. */
/*       The overhead kills me...                                            */
/*===========================================================================*/
/* RETURN:                                                                   */
/*===========================================================================*/
extern "C" void DrawPrimitiveHAL( PMESAD3DSHARED pShared, D3DPRIMITIVETYPE dptPrimitiveType, D3DTLVERTEX *pVertices, DWORD dwCount )
{
  PMESAD3DHAL	pHAL = (PMESAD3DHAL)pShared;

#ifdef D3D_DEBUG
  HRESULT		rc;      

  DPF(( DBG_FUNC, "DrawPrimitveHAL();" ));

  /* Make sure we have enough info. */
  if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
    return;

  DPF(( DBG_PRIM_INFO, "DP( %d )", dwCount ));

  rc = pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType,
								 D3DFVF_TLVERTEX,
								 (LPVOID)pVertices,
								 dwCount, 
								 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
  if ( FAILED(rc) )
  {
    RIP( pHAL, "DrawPrimitive ->", ErrorStringD3D(rc) );
  }
#else
  pHAL->lpD3DDevice->DrawPrimitive( dptPrimitiveType,
							 D3DFVF_TLVERTEX,
							 (LPVOID)pVertices,
							 dwCount, 
							 (D3DDP_DONOTCLIP | D3DDP_DONOTLIGHT) );
#endif
}
/*===========================================================================*/
/*  This call will handle the swapping of the buffers.  Now I didn't bother  */
/* to support single buffered so this will be used for glFlush() as its all  */
/* the same.  So first we do an EndScene as we are always considered to be in*/
/* a BeginScene because when we leave we do a BeginScene.  Now note that when*/
/* the context is created in the first place we do a BeginScene also just to */
/* get things going.  The call will use either Flip/blt based on the type of */
/* surface was created for rendering.                                        */
/*===========================================================================*/
/* RETURN:                                                                   */
/*===========================================================================*/
extern "C" void SwapBuffersHAL( PMESAD3DSHARED pShared )
{
  PMESAD3DHAL	pHAL = (PMESAD3DHAL)pShared;

#ifdef D3D_DEBUG
  HRESULT		rc;      

  DPF(( DBG_FUNC, "SwapBuffersHAL();" ));
  DPF(( DBG_ALL_PROFILE, "=================SWAP===================" ));

  /* Make sure we have enough info. */
  if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
    return;

  /* Make sure we have enough info. */
  if ( pHAL->lpDDSPrimary != NULL )
  {
    rc = pHAL->lpD3DDevice->EndScene();   
    if ( FAILED(rc) )
    {
	 RIP( pHAL, "EndScene ->", ErrorStringD3D(rc) );
    }
 
    if ( pShared->bFlipable )
    {
	 DPF(( DBG_CNTX_PROFILE, "Swap->FLIP" ));
	 rc = pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
    }
    else
    {
	 DPF(( DBG_CNTX_PROFILE, "Swap->Blt" ));
	 rc = pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL );
    }
    if ( FAILED(rc) )
    {
	 RIP( pHAL, "Blt (RENDER/PRIMARY) ->", ErrorStringD3D(rc) );
    }

    rc = pHAL->lpD3DDevice->BeginScene(); 
    if ( FAILED(rc) )
    {
	 RIP( pHAL, "BeginScene ->", ErrorStringD3D(rc) );
    }
  }
#else
  pHAL->lpD3DDevice->EndScene();   

  if ( pShared->bFlipable )
    pHAL->lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
  else
    pHAL->lpDDSPrimary->Blt( &pShared->rectW, pHAL->lpDDSRender, NULL, DDBLT_WAIT, NULL );

  pHAL->lpD3DDevice->BeginScene(); 

#endif
}
/*===========================================================================*/
/*  This function is a very thin wrapper for the D3D call 'SetRenderState'.  */
/* Using this function requires all the types to be defined by including the */
/* D3D header file.                                                          */
/*                                                                           */
/*  TODO:  would be much better to get ride of all these calls per VBRender. */
/*        I feel I should get this call into SetRenderStates() the RenderVB. */
/*===========================================================================*/
/* RETURN:                                                                   */
/*===========================================================================*/
extern "C" void SetStateHAL( PMESAD3DSHARED pShared, DWORD dwType, DWORD dwState )
{
  PMESAD3DHAL	pHAL = (PMESAD3DHAL)pShared;

#ifdef D3D_DEBUG   
  HRESULT		rc;

  DPF(( DBG_FUNC, "SetStateHAL();" ));

  /* Make sure we have enough info. */
  if ( (pHAL == NULL) || (pHAL->lpD3DDevice == NULL) )
    return;

  rc = pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState );
  if ( FAILED(rc) )
  {
    RIP( pHAL, "SetRenderState ->", ErrorStringD3D(rc) );
  }

#else
  pHAL->lpD3DDevice->SetRenderState( (D3DRENDERSTATETYPE)dwType, dwState );
#endif
}