Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.6 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // ramprov.cpp
  4. //
  5. // Implements software rasterizer HAL provider.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. extern HRESULT
  13. RastService(ULONG_PTR dwCtx,
  14. RastServiceType srvType, DWORD arg1, LPVOID arg2);
  15. extern HRESULT
  16. RastRampService(ULONG_PTR dwCtx,
  17. RastRampServiceType srvType, ULONG_PTR arg1, LPVOID arg2);
  18. extern D3DDEVICEDESC g_nullDevDesc;
  19. #define BUILD_RAMP 1
  20. #define devDesc rampDevDescDX5
  21. #include "getcaps.h"
  22. STDMETHODIMP
  23. RampRastHalProvider::GetCaps(THIS_
  24. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  25. LPD3DDEVICEDESC pHwDesc,
  26. LPD3DDEVICEDESC pHelDesc,
  27. DWORD dwVersion)
  28. {
  29. *pHwDesc = g_nullDevDesc;
  30. *pHelDesc = rampDevDescDX5;
  31. return D3D_OK;
  32. }
  33. //----------------------------------------------------------------------------
  34. //
  35. // RampRastHalProvider::GetInterface
  36. //
  37. // Returns driver interface data for opt rast.
  38. //
  39. //----------------------------------------------------------------------------
  40. static D3DHAL_GLOBALDRIVERDATA SwDriverData =
  41. {
  42. sizeof(D3DHAL_GLOBALDRIVERDATA),
  43. // The rest is filled in at runtime.
  44. };
  45. static D3DHAL_CALLBACKS RampRastCallbacks =
  46. {
  47. sizeof(D3DHAL_CALLBACKS),
  48. RastContextCreateRamp,
  49. RastContextDestroyRamp,
  50. NULL,
  51. NULL,
  52. NULL,
  53. NULL,
  54. RastRenderState,
  55. RastRenderPrimitive,
  56. NULL,
  57. RastTextureCreate,
  58. RastTextureDestroy,
  59. RastTextureSwap,
  60. RastTextureGetSurf,
  61. // All others NULL.
  62. };
  63. static D3DHAL_CALLBACKS2 RampRastCallbacks2 =
  64. {
  65. sizeof(D3DHAL_CALLBACKS2),
  66. D3DHAL2_CB32_SETRENDERTARGET |
  67. D3DHAL2_CB32_DRAWONEPRIMITIVE |
  68. D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE |
  69. D3DHAL2_CB32_DRAWPRIMITIVES,
  70. RastSetRenderTarget,
  71. NULL,
  72. RastDrawOnePrimitive,
  73. RastDrawOneIndexedPrimitive,
  74. RastDrawPrimitives
  75. };
  76. static D3DHAL_CALLBACKS3 RampRastCallbacks3 =
  77. {
  78. sizeof(D3DHAL_CALLBACKS3),
  79. D3DHAL3_CB32_DRAWPRIMITIVES2,
  80. NULL, // Clear2
  81. NULL, // lpvReserved
  82. NULL, // ValidateTextureStageState
  83. RastDrawPrimitives2, // DrawVB
  84. };
  85. //----------------------------------------------------------------------------
  86. //
  87. // TextureFormats
  88. //
  89. // Returns all the texture formats supported by our rasterizer.
  90. // Right now, it's called at device creation time to fill the driver gloabl
  91. // data.
  92. //
  93. //----------------------------------------------------------------------------
  94. #define NUM_RAMP_SUPPORTED_TEXTURE_FORMATS 2
  95. int
  96. RampTextureFormats(LPDDSURFACEDESC* lplpddsd)
  97. {
  98. static DDSURFACEDESC ddsd[NUM_RAMP_SUPPORTED_TEXTURE_FORMATS];
  99. int i = 0;
  100. /* pal8 */
  101. ddsd[i].dwSize = sizeof(ddsd[0]);
  102. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  103. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  104. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  105. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
  106. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  107. i++;
  108. /* pal4 */
  109. // although ramp supports the pal4 (and 16 bit texture formats, for copy)
  110. // texture format, it must not be enumerated for backwards compatibility
  111. //
  112. // ddsd[i].dwSize = sizeof(ddsd[0]);
  113. // ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  114. // ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  115. // ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  116. // ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
  117. // ddsd[i].ddpfPixelFormat.dwRGBBitCount = 4;
  118. //
  119. // i++;
  120. *lplpddsd = ddsd;
  121. return i;
  122. }
  123. // Note: because ramp ZBuffer Formats are different than the standard ones
  124. // used by the other rasterizers, it is impossible for DDHEL to properly validate
  125. // zbuffer creation for the case of ramp (because the ramp device may have not
  126. // been created at zbuffer creation time), so Direct3DCreateDevice has a special check
  127. // to invalidate the zformats (i.e. stencil) not accepted by ramp
  128. #define NUM_SUPPORTED_ZBUFFER_FORMATS 1
  129. int
  130. RampZBufferFormats(DDPIXELFORMAT** ppDDPF)
  131. {
  132. static DDPIXELFORMAT DDPF[NUM_SUPPORTED_ZBUFFER_FORMATS];
  133. int i = 0;
  134. /* 16 bit Z; no stencil */
  135. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  136. DDPF[i].dwFlags = DDPF_ZBUFFER;
  137. DDPF[i].dwZBufferBitDepth = 16;
  138. DDPF[i].dwStencilBitDepth = 0;
  139. DDPF[i].dwZBitMask = 0xffff;
  140. DDPF[i].dwStencilBitMask = 0x0000;
  141. i++;
  142. *ppDDPF = DDPF;
  143. return i;
  144. }
  145. STDMETHODIMP
  146. RampRastHalProvider::GetInterface(THIS_
  147. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  148. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  149. DWORD dwVersion)
  150. {
  151. memcpy(&SwDriverData.hwCaps, &rampDevDescDX5, sizeof(SwDriverData.hwCaps));
  152. SwDriverData.dwNumVertices = BASE_VERTEX_COUNT;
  153. SwDriverData.dwNumClipVertices = MAX_CLIP_VERTICES;
  154. SwDriverData.dwNumTextureFormats =
  155. RampTextureFormats(&SwDriverData.lpTextureFormats);
  156. pInterfaceData->pGlobalData = &SwDriverData;
  157. pInterfaceData->pExtCaps = NULL;
  158. pInterfaceData->pCallbacks = &RampRastCallbacks;
  159. pInterfaceData->pCallbacks2 = &RampRastCallbacks2;
  160. pInterfaceData->pCallbacks3 = &RampRastCallbacks3;
  161. pInterfaceData->pfnRampService = RastRampService;
  162. pInterfaceData->pfnRastService = RastService;
  163. return S_OK;
  164. }