raster.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. #include "pch.h"
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. //
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. class D3DRasterizerImpl : public D3DRasterizer {
  8. private:
  9. TRef<DDDevice> m_pdddevice;
  10. TRef<D3DDevice> m_pd3ddevice;
  11. TRef<IDirect3DDeviceX> m_pd3dd;
  12. TRef<IDirect3DViewportX> m_pd3dview;
  13. PrivateSurface* m_psurface;
  14. DDSurface* m_pddsurface;
  15. DWORD m_dwDrawPrimitiveFlags;
  16. Rect m_rectGuard;
  17. Rect m_rectClip;
  18. #ifdef _DEBUG
  19. bool m_bSurfaceLost;
  20. void InitializeD3DCall()
  21. {
  22. m_bSurfaceLost = false;
  23. }
  24. void D3DError(HRESULT hr, const char* pszCall, const char* pszFile, int line, const char* pszModule)
  25. {
  26. if (m_bSurfaceLost) {
  27. // ignore all errors if the surface is lost
  28. } else {
  29. if (
  30. hr == DDERR_SURFACELOST
  31. || hr == D3DERR_SCENE_BEGIN_FAILED
  32. ) {
  33. m_bSurfaceLost = true;
  34. } else {
  35. DDError(hr, pszCall, pszFile, line, pszModule);
  36. }
  37. }
  38. }
  39. #define D3DCall(hr) D3DError(hr, #hr, __FILE__, __LINE__, __MODULE__)
  40. #else
  41. void InitializeD3DCall() {}
  42. void D3DCall(HRESULT hr) {}
  43. #endif
  44. public:
  45. //////////////////////////////////////////////////////////////////////////////
  46. //
  47. // Constructor
  48. //
  49. //////////////////////////////////////////////////////////////////////////////
  50. D3DRasterizerImpl(PrivateSurface* psurface) :
  51. m_psurface(psurface),
  52. m_dwDrawPrimitiveFlags(
  53. D3DDP_DONOTUPDATEEXTENTS
  54. | D3DDP_DONOTCLIP
  55. )
  56. {
  57. CastTo(m_pddsurface, psurface->GetVideoSurface());
  58. InitializeD3DCall();
  59. //
  60. // Tell the device about this rasterizer
  61. //
  62. m_pdddevice = m_pddsurface->GetDDDevice();
  63. m_pdddevice->AddRasterizer(this);
  64. //
  65. // Create a D3D device
  66. //
  67. m_pd3ddevice = m_pdddevice->CreateD3DDevice(m_pddsurface);
  68. if (m_pd3ddevice == NULL) {
  69. return;
  70. }
  71. m_pd3dd = m_pd3ddevice->GetD3DDeviceX();
  72. D3DDeviceDescription d3dddSW;
  73. D3DDeviceDescription d3dddHW;
  74. D3DCall(m_pd3dd->GetCaps(&d3dddHW, &d3dddSW));
  75. #ifndef DREAMCAST
  76. m_rectGuard =
  77. Rect(
  78. d3dddHW.dvGuardBandLeft,
  79. d3dddHW.dvGuardBandTop,
  80. d3dddHW.dvGuardBandRight,
  81. d3dddHW.dvGuardBandBottom
  82. );
  83. #endif
  84. //
  85. // Create the D3D viewport
  86. //
  87. D3DCall(m_pdddevice->GetD3D()->CreateViewport(&m_pd3dview, NULL));
  88. D3DCall(m_pd3dd->AddViewport(m_pd3dview));
  89. UpdateViewport();
  90. //
  91. // default rendering states
  92. //
  93. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL));
  94. }
  95. bool IsValid()
  96. {
  97. return m_pd3ddevice != NULL;
  98. }
  99. //////////////////////////////////////////////////////////////////////////////
  100. //
  101. // Destructor
  102. //
  103. //////////////////////////////////////////////////////////////////////////////
  104. ~D3DRasterizerImpl()
  105. {
  106. m_pdddevice->RemoveRasterizer(this);
  107. }
  108. //////////////////////////////////////////////////////////////////////////////
  109. //
  110. // Termination
  111. //
  112. //////////////////////////////////////////////////////////////////////////////
  113. void Terminate()
  114. {
  115. m_pd3dview = NULL;
  116. m_pd3dd = NULL;
  117. }
  118. TRef<IDirect3DDeviceX> GetD3DDeviceX()
  119. {
  120. return m_pd3dd;
  121. }
  122. TRef<IDirect3DX> GetD3D()
  123. {
  124. return m_pdddevice->GetD3D();
  125. }
  126. TRef<IDirect3DViewportX> GetViewport()
  127. {
  128. return m_pd3dview;
  129. }
  130. //////////////////////////////////////////////////////////////////////////////
  131. //
  132. // Change Render target
  133. //
  134. //////////////////////////////////////////////////////////////////////////////
  135. /* , make this work
  136. void SetSurface(ISurfaceImpl* psurface)
  137. {
  138. ZAssert(!m_bRendering);
  139. m_psurface = psurface;
  140. D3DCall(m_pd3dd->SetRenderTarget(m_psurface->GetDDS(), 0));
  141. }
  142. */
  143. //////////////////////////////////////////////////////////////////////////////
  144. //
  145. // Scene
  146. //
  147. //////////////////////////////////////////////////////////////////////////////
  148. void BeginScene()
  149. {
  150. m_pddsurface->BeginScene();
  151. m_pdddevice->BeginScene();
  152. D3DCall(m_pd3dd->BeginScene());
  153. }
  154. void EndScene()
  155. {
  156. m_pddsurface->EndScene();
  157. //
  158. // 11/16/99 not checking return codes here since the Permedia 2
  159. // driver on Win2K returns error every once in a while
  160. //
  161. m_pd3dd->EndScene();
  162. m_pdddevice->EndScene();
  163. }
  164. //////////////////////////////////////////////////////////////////////////////
  165. //
  166. // Viewport
  167. //
  168. //////////////////////////////////////////////////////////////////////////////
  169. void UpdateViewport()
  170. {
  171. const WinPoint& size = m_psurface->GetSize();
  172. float aspect = (float)size.X() / (float)size.Y();
  173. D3DVIEWPORT2 view;
  174. view.dwSize = sizeof(D3DVIEWPORT2);
  175. view.dwX = 0;
  176. view.dwY = 0;
  177. view.dwWidth = (int)size.X();
  178. view.dwHeight = (int)size.Y();
  179. view.dvClipX = -1;
  180. view.dvClipWidth = 2;
  181. view.dvClipY = aspect;
  182. view.dvClipHeight = 2 * aspect;
  183. view.dvMinZ = 0;
  184. view.dvMaxZ = 1;
  185. D3DCall(m_pd3dview->SetViewport2(&view));
  186. D3DCall(m_pd3dd->SetCurrentViewport(m_pd3dview));
  187. }
  188. void SetClipRect(const Rect& rectClip)
  189. {
  190. m_rectClip = rectClip;
  191. }
  192. void ClearZBuffer()
  193. {
  194. ZTrace(
  195. "Clearing ZBuffer ("
  196. + ZString(m_rectClip.XMin()) + ", "
  197. + ZString(m_rectClip.YMin()) + ", "
  198. + ZString(m_rectClip.XMax()) + ", "
  199. + ZString(m_rectClip.YMax()) + ")"
  200. );
  201. D3DRect rect(
  202. (int)m_rectClip.XMin(),
  203. (int)m_rectClip.YMin(),
  204. (int)m_rectClip.XMax(),
  205. (int)m_rectClip.YMax()
  206. );
  207. HRESULT hr = m_pd3dview->Clear(1, &rect, D3DCLEAR_ZBUFFER);
  208. //
  209. // This is actually a DDraw call so it's possible it can fail.
  210. //
  211. if (hr != DDERR_UNSUPPORTED) {
  212. D3DCall(hr);
  213. }
  214. }
  215. //////////////////////////////////////////////////////////////////////////////
  216. //
  217. // Attributes
  218. //
  219. //////////////////////////////////////////////////////////////////////////////
  220. bool HasZBuffer()
  221. {
  222. return m_pddsurface->HasZBuffer();
  223. }
  224. bool Has3DAcceleration()
  225. {
  226. return m_pdddevice->GetAllow3DAcceleration();
  227. }
  228. Point GetSurfaceSize()
  229. {
  230. return Point::Cast(m_pddsurface->GetSize());
  231. }
  232. //////////////////////////////////////////////////////////////////////////////
  233. //
  234. // State
  235. //
  236. //////////////////////////////////////////////////////////////////////////////
  237. void SetTexture(Surface* psurfaceTextureArg)
  238. {
  239. PrivateSurface* psurfaceTexture; CastTo(psurfaceTexture, psurfaceTextureArg);
  240. if (psurfaceTexture != NULL) {
  241. DDSurface* pddsurfaceTexture; CastTo(pddsurfaceTexture, psurfaceTexture->GetVideoSurface());
  242. D3DCall(m_pd3dd->SetTexture(
  243. 0,
  244. m_pdddevice->GetTextureX(m_pd3ddevice, pddsurfaceTexture)
  245. ));
  246. } else {
  247. D3DCall(m_pd3dd->SetTexture(0, NULL));
  248. }
  249. }
  250. void SetShadeMode(ShadeMode shadeMode)
  251. {
  252. switch (shadeMode) {
  253. case ShadeModeNone:
  254. case ShadeModeCopy:
  255. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_DECAL));
  256. break;
  257. case ShadeModeFlat:
  258. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT));
  259. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE));
  260. break;
  261. case ShadeModeGlobalColor:
  262. case ShadeModeGouraud:
  263. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD));
  264. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMAPBLEND, D3DTBLEND_MODULATE));
  265. break;
  266. default:
  267. ZError("Invalid ShadeMode");
  268. }
  269. }
  270. void SetBlendMode(BlendMode blendMode)
  271. {
  272. switch (blendMode) {
  273. case BlendModeSource:
  274. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false));
  275. break;
  276. case BlendModeAdd:
  277. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
  278. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
  279. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
  280. break;
  281. case BlendModeSourceAlpha:
  282. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, true));
  283. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
  284. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA));
  285. break;
  286. default:
  287. ZError("Invalid BlendMode");
  288. }
  289. }
  290. void SetWrapMode(WrapMode wrapMode)
  291. {
  292. switch (wrapMode) {
  293. case WrapModeNone:
  294. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPU, false));
  295. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPV, false));
  296. break;
  297. case WrapModeUCylinder:
  298. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPU, true));
  299. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPV, false));
  300. break;
  301. case WrapModeVCylinder:
  302. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPU, false));
  303. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPV, true));
  304. break;
  305. case WrapModeTorus:
  306. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPU, true));
  307. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_WRAPV, true));
  308. break;
  309. default:
  310. ZError("Invalid WrapMode");
  311. }
  312. }
  313. void SetCullMode(CullMode cullMode)
  314. {
  315. switch (cullMode) {
  316. case CullModeNone:
  317. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
  318. break;
  319. case CullModeCW:
  320. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
  321. break;
  322. case CullModeCCW:
  323. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW));
  324. break;
  325. case CullModeBoth:
  326. ZUnimplemented();
  327. break;
  328. default:
  329. ZError("Invalid CullMode");
  330. }
  331. }
  332. void SetZTest(bool bZTest)
  333. {
  334. D3DCall(m_pd3dd->SetRenderState(
  335. D3DRENDERSTATE_ZENABLE,
  336. HasZBuffer() && bZTest
  337. ));
  338. }
  339. void SetZWrite(bool bZWrite)
  340. {
  341. D3DCall(m_pd3dd->SetRenderState(
  342. D3DRENDERSTATE_ZWRITEENABLE,
  343. HasZBuffer() && bZWrite
  344. ));
  345. }
  346. void SetLinearFilter(bool bLinearFilter)
  347. {
  348. if (bLinearFilter && Has3DAcceleration()) {
  349. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_LINEAR));
  350. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_LINEAR));
  351. } else {
  352. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_NEAREST));
  353. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_NEAREST));
  354. }
  355. }
  356. void SetPerspectiveCorrection(bool bPerspectiveCorrection)
  357. {
  358. D3DCall(m_pd3dd->SetRenderState(
  359. D3DRENDERSTATE_TEXTUREPERSPECTIVE,
  360. bPerspectiveCorrection || Has3DAcceleration()
  361. ));
  362. }
  363. void SetDither(bool bDither)
  364. {
  365. D3DCall(m_pd3dd->SetRenderState(
  366. D3DRENDERSTATE_DITHERENABLE,
  367. false //bDither || Has3DAcceleration()
  368. ));
  369. }
  370. void SetColorKey(bool bColorKey)
  371. {
  372. D3DCall(m_pd3dd->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, bColorKey));
  373. }
  374. //////////////////////////////////////////////////////////////////////////////
  375. //
  376. // Debug
  377. //
  378. //////////////////////////////////////////////////////////////////////////////
  379. void CheckVertices(const VertexScreen* pvertex, int vcount)
  380. {
  381. /*
  382. #ifdef _DEBUG
  383. {
  384. const float error = 0.5f;
  385. for (int index = 0; index < vcount; index++) {
  386. ZAssert(pvertex[index].x >= m_rectClip.XMin() - error);
  387. ZAssert(pvertex[index].x <= m_rectClip.XMax() + error);
  388. ZAssert(pvertex[index].y >= m_rectClip.YMin() - error);
  389. ZAssert(pvertex[index].y <= m_rectClip.YMax() + error);
  390. ZAssert(pvertex[index].z >= 0.0f - error);
  391. ZAssert(pvertex[index].z <= 1.0f + error);
  392. }
  393. }
  394. #endif
  395. */
  396. VertexScreen* pcheck = (VertexScreen*)pvertex;
  397. for (int index = 0; index < vcount; index++) {
  398. if (pcheck[index].x < m_rectClip.XMin()) {
  399. pcheck[index].x = m_rectClip.XMin();
  400. } else if (pcheck[index].x > m_rectClip.XMax()) {
  401. pcheck[index].x = m_rectClip.XMax();
  402. }
  403. if (pcheck[index].y < m_rectClip.YMin()) {
  404. pcheck[index].y = m_rectClip.YMin();
  405. } else if (pcheck[index].y > m_rectClip.YMax()) {
  406. pcheck[index].y = m_rectClip.YMax();
  407. }
  408. if (pcheck[index].z < 0) {
  409. pcheck[index].z = 0;
  410. } else if (pcheck[index].z > 1) {
  411. pcheck[index].z = 1;
  412. }
  413. }
  414. }
  415. void CheckIndices(const MeshIndex* pindex, int icount, int vcount)
  416. {
  417. #ifdef _DEBUG
  418. for (int index = 0; index < icount; index++) {
  419. ZAssert(pindex[index] >= 0 && pindex[index] < vcount);
  420. }
  421. #endif
  422. }
  423. //////////////////////////////////////////////////////////////////////////////
  424. //
  425. // Rendering
  426. //
  427. //////////////////////////////////////////////////////////////////////////////
  428. void DrawTrianglesD3D(const D3DLVertex* pvertex, int vcount, const MeshIndex* pindex, int icount)
  429. {
  430. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  431. D3DPT_TRIANGLELIST,
  432. D3DFVF_LVERTEX,
  433. (void*)pvertex,
  434. vcount,
  435. (MeshIndex*)pindex,
  436. icount,
  437. m_dwDrawPrimitiveFlags
  438. ));
  439. }
  440. void DrawLinesD3D(const D3DLVertex* pvertex, int vcount, const MeshIndex* pindex, int icount)
  441. {
  442. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  443. D3DPT_LINELIST,
  444. D3DFVF_LVERTEX,
  445. (void*)pvertex,
  446. vcount,
  447. (MeshIndex*)pindex,
  448. icount,
  449. m_dwDrawPrimitiveFlags
  450. ));
  451. }
  452. void DrawPointsD3D(const D3DLVertex* pvertex, int vcount)
  453. {
  454. D3DCall(m_pd3dd->DrawPrimitive(
  455. D3DPT_POINTLIST,
  456. D3DFVF_LVERTEX,
  457. (void*)pvertex,
  458. vcount,
  459. m_dwDrawPrimitiveFlags
  460. ));
  461. }
  462. void DrawTrianglesD3D(const D3DVertex* pvertex, int vcount, const MeshIndex* pindex, int icount)
  463. {
  464. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  465. D3DPT_TRIANGLELIST,
  466. D3DFVF_VERTEX,
  467. (void*)pvertex,
  468. vcount,
  469. (MeshIndex*)pindex,
  470. icount,
  471. m_dwDrawPrimitiveFlags
  472. ));
  473. }
  474. void DrawLinesD3D(const D3DVertex* pvertex, int vcount, const MeshIndex* pindex, int icount)
  475. {
  476. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  477. D3DPT_LINELIST,
  478. D3DFVF_VERTEX,
  479. (void*)pvertex,
  480. vcount,
  481. (MeshIndex*)pindex,
  482. icount,
  483. m_dwDrawPrimitiveFlags
  484. ));
  485. }
  486. void DrawPointsD3D(const D3DVertex* pvertex, int vcount)
  487. {
  488. D3DCall(m_pd3dd->DrawPrimitive(
  489. D3DPT_POINTLIST,
  490. D3DFVF_VERTEX,
  491. (void*)pvertex,
  492. vcount,
  493. m_dwDrawPrimitiveFlags
  494. ));
  495. }
  496. void DrawTriangles(const VertexScreen* pvertex, int vcount, const MeshIndex* pindex, int icount)
  497. {
  498. CheckVertices(pvertex, vcount);
  499. CheckIndices(pindex, icount, vcount);
  500. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  501. D3DPT_TRIANGLELIST,
  502. D3DFVF_TLVERTEX,
  503. (void*)pvertex,
  504. vcount,
  505. (MeshIndex*)pindex,
  506. icount,
  507. m_dwDrawPrimitiveFlags
  508. ));
  509. }
  510. void DrawLines(const VertexScreen* pvertex, int vcount, const MeshIndex* pindex, int icount)
  511. {
  512. CheckVertices(pvertex, vcount);
  513. CheckIndices(pindex, icount, vcount);
  514. D3DCall(m_pd3dd->DrawIndexedPrimitive(
  515. D3DPT_LINELIST,
  516. D3DFVF_TLVERTEX,
  517. (void*)pvertex,
  518. vcount,
  519. (MeshIndex*)pindex,
  520. icount,
  521. m_dwDrawPrimitiveFlags
  522. ));
  523. }
  524. void DrawPoints(const VertexScreen* pvertex, int vcount)
  525. {
  526. if (true) {
  527. PixelFormat* ppf = m_psurface->GetPixelFormat();
  528. int pitch = m_psurface->GetPitch();
  529. BYTE* pdata = m_psurface->GetWritablePointer();
  530. ZAssert(ppf->PixelBytes() == 2 );
  531. ZAssert(ppf->RedSize() == 0x1f);
  532. ZAssert(ppf->BlueSize() == 0x1f);
  533. if (ppf->GreenSize() == 0x1f) {
  534. // 555
  535. for (int index = 0; index < vcount; index++) {
  536. BYTE* ppixel =
  537. pdata
  538. + FloorInt(pvertex[index].x) * 2
  539. + FloorInt(pvertex[index].y) * pitch;
  540. DWORD color = pvertex[index].color;
  541. WORD
  542. pixel =
  543. (WORD)(
  544. ((color >> 9) & 0x7c00)
  545. | ((color >> 6) & 0x03e0)
  546. | ((color >> 3) & 0x001f)
  547. );
  548. *(WORD*)(ppixel) = pixel;
  549. }
  550. } else {
  551. // 565
  552. ZAssert(ppf->GreenSize() == 0x3f);
  553. for (int index = 0; index < vcount; index++) {
  554. BYTE* ppixel =
  555. pdata
  556. + FloorInt(pvertex[index].x) * 2
  557. + FloorInt(pvertex[index].y) * pitch;
  558. DWORD color = pvertex[index].color;
  559. WORD pixel =
  560. (WORD)(
  561. ((color >> 8) & 0xf800)
  562. | ((color >> 5) & 0x07e0)
  563. | ((color >> 3) & 0x001f)
  564. );
  565. *(WORD*)(ppixel) = pixel;
  566. }
  567. }
  568. m_psurface->ReleasePointer();
  569. } else {
  570. CheckVertices(pvertex, vcount);
  571. D3DCall(m_pd3dd->DrawPrimitive(
  572. D3DPT_POINTLIST,
  573. D3DFVF_TLVERTEX,
  574. (void*)pvertex,
  575. vcount,
  576. m_dwDrawPrimitiveFlags
  577. ));
  578. }
  579. }
  580. };
  581. TRef<D3DRasterizer> CreateD3DRasterizer(PrivateSurface* psurface)
  582. {
  583. TRef<D3DRasterizer> prasterizer = new D3DRasterizerImpl(psurface);
  584. return prasterizer->IsValid() ? prasterizer : NULL;
  585. }