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.

146 lines
5.1 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: haltex.c
  6. * Content: Direct3D HAL texture handling
  7. *@@BEGIN_MSINTERNAL
  8. *
  9. * $Id: haltex.c,v 1.1 1995/11/21 15:12:43 sjl Exp $
  10. *
  11. * History:
  12. * Date By Reason
  13. * ==== == ======
  14. * 07/11/95 stevela Initial rev.
  15. *@@END_MSINTERNAL
  16. *
  17. ***************************************************************************/
  18. #include "pch.cpp"
  19. #pragma hdrstop
  20. /*
  21. * Texture functionality is not emulated.
  22. */
  23. HRESULT D3DHAL_TextureCreate(LPDIRECT3DDEVICEI lpDevI,
  24. LPD3DTEXTUREHANDLE lphTex,
  25. LPDIRECTDRAWSURFACE lpDDS)
  26. {
  27. D3DHAL_TEXTURECREATEDATA data;
  28. HRESULT ret;
  29. if (!lpDevI->lpD3DHALCallbacks->TextureCreate) {
  30. D3D_ERR("TextureCreate called, but no texture support.");
  31. return (D3DERR_TEXTURE_NO_SUPPORT);
  32. }
  33. memset(&data, 0, sizeof(D3DHAL_TEXTURECREATEDATA));
  34. data.dwhContext = lpDevI->dwhContext;
  35. data.lpDDS = lpDDS;
  36. D3D_INFO(6, "TextureCreate, creating texture dwhContext = %08lx, lpDDS = %08lx",
  37. data.dwhContext, data.lpDDS);
  38. CALL_HALONLY(ret, lpDevI, TextureCreate, &data);
  39. if (ret != DDHAL_DRIVER_HANDLED || data.ddrval != DD_OK) {
  40. D3D_ERR("HAL failed to handle TextureCreate");
  41. return (D3DERR_TEXTURE_CREATE_FAILED);
  42. }
  43. *lphTex = data.dwHandle;
  44. D3D_INFO(6, "TextureCreate, created texture hTex = %08lx", data.dwHandle);
  45. return (D3D_OK);
  46. }
  47. HRESULT D3DHAL_TextureDestroy(LPD3DI_TEXTUREBLOCK lpBlock)
  48. {
  49. LPDIRECT3DDEVICEI lpDevI=lpBlock->lpDevI;
  50. D3DTEXTUREHANDLE hTex=lpBlock->hTex;
  51. DDASSERT(!IS_DX7HAL_DEVICE(lpDevI));
  52. if (!(lpDevI->lpD3DHALCallbacks->TextureDestroy))
  53. {
  54. D3D_ERR("TextureDestroy called, but no texture support.");
  55. return (D3DERR_TEXTURE_NO_SUPPORT);
  56. }
  57. // The following code ensures that before we ask the driver to unmap
  58. // the texture, we set the stages to NULL if the texture is still present
  59. // in any stage. This is probably not necessary, but we are just trying
  60. // to be extra cautious here. The CAVEAT here is that it is possible that
  61. // D3DHAL_TextureDestroy() is being called from DestroyDevice() and hence
  62. // IT COULD BE REALLY BAD TO BATCH additional commands to the device at
  63. // this stage. (snene - 3/2/98)
  64. BOOL bNeedFlush = FALSE;
  65. if (IS_DP2HAL_DEVICE(lpDevI)) {
  66. int dwStage;
  67. CDirect3DDeviceIDP2 *dp2dev = static_cast<CDirect3DDeviceIDP2 *>(lpDevI);
  68. // Find out the first stage with hTex and NULL out all the stages after
  69. for (dwStage=0;dwStage<(int)lpDevI->dwMaxTextureBlendStages; dwStage++)
  70. {
  71. if (hTex == lpDevI->tsstates[dwStage][D3DTSS_TEXTUREMAP])
  72. {
  73. // We need to do this backwards because we cannot have a texture bound to
  74. // stage i + 1 when there is no texture bound to stage i.
  75. for(int iCurStage=lpDevI->dwMaxTextureBlendStages-1; iCurStage>=dwStage; iCurStage--)
  76. {
  77. if (lpDevI->tsstates[iCurStage][D3DTSS_TEXTUREMAP] != 0)
  78. {
  79. dp2dev->SetTSSI(iCurStage, (D3DTEXTURESTAGESTATETYPE)D3DTSS_TEXTUREMAP, 0);
  80. bNeedFlush = TRUE;
  81. }
  82. }
  83. break;
  84. }
  85. }
  86. }
  87. if (lpDevI->rstates[D3DRENDERSTATE_TEXTUREHANDLE] == hTex)
  88. {
  89. lpDevI->rstates[D3DRENDERSTATE_TEXTUREHANDLE] = 0;
  90. lpDevI->SetRenderStateI(D3DRENDERSTATE_TEXTUREHANDLE, 0);
  91. bNeedFlush = TRUE;
  92. }
  93. // Make sure that we send down the command immediately to guarantee
  94. // that the driver gets it before we call it with Destroy
  95. if(bNeedFlush)
  96. {
  97. if(lpDevI->FlushStates())
  98. {
  99. D3D_ERR("Error trying to render batched commands in D3DHAL_TextureDestroy");
  100. }
  101. }
  102. else // Now we decide whether to flush due to a referenced texture in the batch or not
  103. {
  104. if(lpDevI->m_qwBatch <= ((LPDDRAWI_DDRAWSURFACE_INT)(lpBlock->lpD3DTextureI->lpDDS))->lpLcl->lpSurfMore->qwBatch.QuadPart)
  105. {
  106. if(lpDevI->FlushStates())
  107. {
  108. D3D_ERR("Error trying to render batched commands in D3DHAL_TextureDestroy");
  109. }
  110. }
  111. }
  112. D3DHAL_TEXTUREDESTROYDATA data;
  113. HRESULT ret;
  114. memset(&data, 0, sizeof(D3DHAL_TEXTUREDESTROYDATA));
  115. data.dwhContext = lpDevI->dwhContext;
  116. data.dwHandle = hTex;
  117. D3D_INFO(6, "TextureDestroy, destroying texture dwhContext = %08lx, hTex = %08lx",
  118. data.dwhContext, hTex);
  119. CALL_HALONLY(ret, lpDevI, TextureDestroy, &data);
  120. if (ret != DDHAL_DRIVER_HANDLED || data.ddrval != DD_OK) {
  121. D3D_ERR("HAL failed to handle TextureDestroy");
  122. return (D3DERR_TEXTURE_DESTROY_FAILED);
  123. }
  124. D3D_INFO(6, "TextureDestroy, destroyed texture hTex = %08lx", hTex);
  125. lpBlock->hTex=0;
  126. return (D3D_OK);
  127. }