changeset 2525:4cc81f981afb

Everything except game can use d3d11
author a.parshin
date Fri, 10 Oct 2014 18:28:04 +0300
parents c7264ab7132f
children b1c516bf1102
files Engine/Graphics/IRender.h Engine/Graphics/Render.cpp Engine/Graphics/Render.h Engine/Graphics/RenderD3D11.cpp Engine/Graphics/RenderD3D11.h GUI/GUIProgressBar.cpp GUI/GUIWindow.cpp GUI/UI/UIPartyCreation.cpp GUI/UI/UISaveLoad.cpp
diffstat 9 files changed, 95 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Engine/Graphics/IRender.h	Fri Oct 10 17:42:05 2014 +0300
+++ b/Engine/Graphics/IRender.h	Fri Oct 10 18:28:04 2014 +0300
@@ -86,7 +86,7 @@
     virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) = 0;
     virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) = 0;
 
-    virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8) = 0;
+    virtual void DrawTextAlpha(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency) = 0;
     virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor) = 0;
 
     virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) = 0;
--- a/Engine/Graphics/Render.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/Engine/Graphics/Render.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -6853,7 +6853,7 @@
 }
 
 //----- (004A6AB1) --------------------------------------------------------
-void Render::DrawTextPalette( int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8 )
+void Render::DrawTextAlpha( int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency )
     {
   int v8; // edi@2
   unsigned int v9; // esi@2
@@ -6920,9 +6920,9 @@
       v11 = (unsigned char *)v25;
     }
 
-    if ( a8 )
-    {
-      v28 = 0x7FF; // 16bit pRenderer->uTargetGMask | pRenderer->uTargetBMask;
+    if ( present_time_transparency )
+    {
+      v28 = 0x7FF; // transparent color 16bit pRenderer->uTargetGMask | pRenderer->uTargetBMask;
       for (uint dy = 0; dy < v9; ++dy)
       {
         for (int dx = 0; dx < v8; ++dx)
--- a/Engine/Graphics/Render.h	Fri Oct 10 17:42:05 2014 +0300
+++ b/Engine/Graphics/Render.h	Fri Oct 10 18:28:04 2014 +0300
@@ -270,7 +270,7 @@
   virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask);
   virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height);
 
-  virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8);
+  virtual void DrawTextAlpha(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency);
   virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor);
 
   virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16);
--- a/Engine/Graphics/RenderD3D11.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/Engine/Graphics/RenderD3D11.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -34,7 +34,6 @@
 void RenderD3D11::CreateZBuffer() {__debugbreak();}
 void RenderD3D11::Release() {__debugbreak();}
 void RenderD3D11::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) {__debugbreak();}
-void RenderD3D11::ClearZBuffer(int a2, int a3) {__debugbreak();}
 void RenderD3D11::SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();}
 bool RenderD3D11::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags) {__debugbreak(); return 0;}
 void RenderD3D11::GetTargetPixelFormat(DDPIXELFORMAT *pOut) {__debugbreak();}
@@ -70,7 +69,6 @@
 void RenderD3D11::DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();}
 void RenderD3D11::DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) {__debugbreak();}
 void RenderD3D11::GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) {__debugbreak();}
-void RenderD3D11::DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8) {__debugbreak();}
 void RenderD3D11::FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) {__debugbreak();}
 void RenderD3D11::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7) {__debugbreak();}
 void RenderD3D11::DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();}
@@ -85,7 +83,6 @@
 void RenderD3D11::ChangeBetweenWinFullscreenModes() {__debugbreak();}
 bool RenderD3D11::AreRenderSurfacesOk() {return true;}
 void RenderD3D11::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) {__debugbreak();}
-void RenderD3D11::PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) {__debugbreak();}
 void RenderD3D11::SavePCXScreenshot() {__debugbreak();}
 int RenderD3D11::_46À6ÀÑ_GetActorsInViewport(int pDepth) {__debugbreak(); return 0;}
 void RenderD3D11::BeginLightmaps() {__debugbreak();}
@@ -107,6 +104,7 @@
 
 
 
+void RenderD3D11::PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) {}
 
 void RenderD3D11::SetUIClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
 {
@@ -145,6 +143,10 @@
   d3dc->ClearRenderTargetView(primary_srv, clear_color);
 }
 
+void RenderD3D11::ClearZBuffer(int, int)
+{
+  d3dc->ClearDepthStencilView(default_depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+}
 
 
 void RenderD3D11::DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4)
@@ -159,9 +161,10 @@
   DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), a4->uTextureWidth, a4->uTextureHeight, a4->d3d11_srv, ui_blend_alpha);
 }
 
-void RenderD3D11::DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4)
+void RenderD3D11::DrawTextureRGB(unsigned int uX, unsigned int uY, RGBTexture *a4)
 {
-  __debugbreak();
+  PrepareTexture(a4);
+  DrawTexture((float)uX / window->GetWidth(), (float)uY / window->GetHeight(), a4->uWidth, a4->uHeight, a4->d3d11_srv, ui_blend_solid);
 }
 
 void RenderD3D11::DrawTextureNew(float u, float v, Texture *tex)
@@ -184,6 +187,14 @@
   srv->Release();
 }
 
+void RenderD3D11::DrawTextAlpha(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency)
+{
+  auto srv = PrepareFontTexture(font_pixels, a5, uFontHeight, pPalette);
+  {
+    DrawTexture((float)x / window->GetWidth(), (float)y / window->GetHeight(), a5, uFontHeight, srv, ui_blend_alpha);
+  }
+  srv->Release();
+}
 
 void RenderD3D11::DrawTexture(float u, float v, int texture_width, int texture_height, ID3D11ShaderResourceView *srv, ID3D11BlendState *blend)
 {
@@ -193,7 +204,7 @@
       clipping = true;
 
   float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-  d3dc->OMSetRenderTargets(1, &primary_srv, depth_srv);
+  d3dc->OMSetRenderTargets(1, &primary_srv, default_depth_srv);
   d3dc->OMSetBlendState(blend, blendFactor, 0xFFFFFFFF);
   d3dc->OMSetDepthStencilState(ui_depthstencil, 1);
 
@@ -408,10 +419,10 @@
   depth_srv_desc.Format = DXGI_FORMAT_D32_FLOAT;
   depth_srv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
   //depth_srv_desc.Texture2D.MipSlice = 0;
-  ErrorD3D(d3dd->CreateDepthStencilView(depth_surface, &depth_srv_desc, &depth_srv));
+  ErrorD3D(d3dd->CreateDepthStencilView(depth_surface, &depth_srv_desc, &default_depth_srv));
 
-  d3dc->OMSetRenderTargets(1, &primary_srv, depth_srv);
-  d3dc->ClearDepthStencilView(depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+  d3dc->OMSetRenderTargets(1, &primary_srv, default_depth_srv);
+  d3dc->ClearDepthStencilView(default_depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
 
 
 
@@ -975,6 +986,64 @@
   return srv;
 }
 
+
+ID3D11ShaderResourceView *RenderD3D11::PrepareFontTexture(unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned short *pFontPalette)
+{
+  D3D11_TEXTURE2D_DESC desc;
+  desc.Width = uCharWidth;
+  desc.Height = uCharHeight;
+  desc.ArraySize = 1;
+  desc.MipLevels = 1;
+  desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+  desc.SampleDesc.Count = 1;
+  desc.SampleDesc.Quality = 0;
+  desc.Usage = D3D11_USAGE_DEFAULT;
+  desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+  desc.CPUAccessFlags = 0;
+  desc.MiscFlags = 0;
+    
+  ID3D11Texture2D *vram_texture = nullptr;
+  ErrorD3D(d3dd->CreateTexture2D(&desc, nullptr, &vram_texture));
+
+  D3D11_TEXTURE2D_DESC ram_desc;
+  memcpy(&ram_desc, &desc, sizeof(ram_desc));
+  ram_desc.Usage = D3D11_USAGE_STAGING;
+  ram_desc.BindFlags = 0;
+  ram_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+    
+  ID3D11Texture2D *ram_texture = nullptr;
+  ErrorD3D(d3dd->CreateTexture2D(&ram_desc, nullptr, &ram_texture));
+
+  D3D11_MAPPED_SUBRESOURCE map;
+  ErrorD3D(d3dc->Map(ram_texture, 0, D3D11_MAP_WRITE, 0, &map));
+  for (unsigned int y = 0; y < desc.Height; ++y)
+    for (unsigned int x = 0; x < desc.Width; ++x)
+    {
+      auto index = pFontPixels[y * desc.Width + x];
+      auto src = pFontPalette[index];
+      auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x;
+
+      if (index)
+      {
+        extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16);
+        *dst = 0xFF000000 | Color32_SwapRedBlue(src);
+      }
+      else
+        *dst = 0x00000000;
+    }
+
+  d3dc->Unmap(ram_texture, 0);
+  d3dc->CopyResource(vram_texture, ram_texture);
+  ram_texture->Release();
+    
+  ID3D11ShaderResourceView *srv = nullptr;
+  ErrorD3D(d3dd->CreateShaderResourceView(vram_texture, nullptr, &srv));
+  vram_texture->Release();
+
+  return srv;
+}
+
+
 void d3d11_release(ID3D11ShaderResourceView *srv)
 {
   srv->Release();
@@ -1058,4 +1127,5 @@
     delete [] pHWLTexture->pPixels;
     delete pHWLTexture;
     return true;
-}
\ No newline at end of file
+}
+
--- a/Engine/Graphics/RenderD3D11.h	Fri Oct 10 17:42:05 2014 +0300
+++ b/Engine/Graphics/RenderD3D11.h	Fri Oct 10 18:28:04 2014 +0300
@@ -96,7 +96,7 @@
   virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask);
   virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height);
 
-  virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8);
+  virtual void DrawTextAlpha(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency);
   virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor);
 
   virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16);
@@ -169,6 +169,7 @@
     void PrepareTexture(struct RGBTexture *p);
     void PrepareTextureIndexed(struct Texture *p);
     ID3D11ShaderResourceView *PrepareFontTexture(unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned short *pFontPalette, unsigned short uFaceColor, unsigned short uShadowColor);
+    ID3D11ShaderResourceView *PrepareFontTexture(unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned short *pFontPalette);
 
     OSWindow *window;
 
@@ -176,7 +177,7 @@
     ID3D11Device            *d3dd;
     ID3D11DeviceContext     *d3dc;
     ID3D11RenderTargetView  *primary_srv;
-    ID3D11DepthStencilView  *depth_srv;
+    ID3D11DepthStencilView  *default_depth_srv;
     ID3D11RasterizerState   *default_rasterizer;
     ID3D11DepthStencilState *default_depthstencil;
     ID3D11BlendState        *default_blend;
--- a/GUI/GUIProgressBar.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/GUI/GUIProgressBar.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -177,7 +177,7 @@
   }
 
   pRenderer->DrawTextureRGB(0, 0, &pLoadingBg);
-  pRenderer->SetRasterClipRect(0, 0, 639, 479);
+  //pRenderer->SetRasterClipRect(0, 0, 639, 479);
   pRenderer->SetUIClipRect(172, 459, 15 * (signed int)(signed __int64)((double)(300 * uProgressCurrent) / (double)uProgressMax) / 15 + 172, 471);
   pRenderer->DrawTextureIndexedAlpha(172, 459, &pLoadingProgress);
   pRenderer->ResetUIClipRect();
--- a/GUI/GUIWindow.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/GUI/GUIWindow.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -1203,7 +1203,7 @@
                   pRenderer->DrawText(v12, v13, (unsigned __int8 *)v17, v16, LOBYTE(v10->uFontHeight),
                     v10->pFontPalettes[0], uFontColor, uFontShadowColor);
                 else
-                  pRenderer->DrawTextPalette(v12, v13, (unsigned char*)v17, v16, LOBYTE(v10->uFontHeight),
+                  pRenderer->DrawTextAlpha(v12, v13, (unsigned char*)v17, v16, LOBYTE(v10->uFontHeight),
                     v10->pFontPalettes[0], a7);
                 LOBYTE(v11) = v30;
                 v12 += v28;
@@ -1353,7 +1353,7 @@
           if ( uColor )
               pRenderer->DrawText(v13, v14,  v21, v20, pFont->uFontHeight, pFont->pFontPalettes[0], uColor, 0);
           else
-              pRenderer->DrawTextPalette(v13, v14, v21, v20, pFont->uFontHeight, pFont->pFontPalettes[0], 0);
+              pRenderer->DrawTextAlpha(v13, v14, v21, v20, pFont->uFontHeight, pFont->pFontPalettes[0], false);
           v13 += v20;
           if ( i < (signed int)pNumLen )
               v13 += pFont->pMetrics[v15].uRightSpacing;
--- a/GUI/UI/UIPartyCreation.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/GUI/UI/UIPartyCreation.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -106,7 +106,7 @@
 
   //move sky
   pRenderer->BeginScene();
-  pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
+  pRenderer->DrawTextureNew(0, 0, &pTexture_PCX);
   uPlayerCreationUI_SkySliderPos = (GetTickCount() % 12800) / 20;
   pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos, 2, pTexture_MAKESKY);
   pRenderer->DrawTextureIndexed(uPlayerCreationUI_SkySliderPos - window->GetWidth(), 2, pTexture_MAKESKY);
@@ -427,7 +427,7 @@
   pTexture_buttplus  = pIcons_LOD->LoadTexturePtr("buttplus", TEXTURE_16BIT_PALETTE);
   pTexture_pressrigh = pIcons_LOD->LoadTexturePtr("presrigh", TEXTURE_16BIT_PALETTE);
   pTexture_presleft  = pIcons_LOD->LoadTexturePtr("presleft", TEXTURE_16BIT_PALETTE);
-  uControlParam = 1;
+  uControlParam = 0;
   do
   {
     sprintf(pTmpBuf.data(), "arrowl%d", uControlParam);
--- a/GUI/UI/UISaveLoad.cpp	Fri Oct 10 17:42:05 2014 +0300
+++ b/GUI/UI/UISaveLoad.cpp	Fri Oct 10 18:28:04 2014 +0300
@@ -185,7 +185,7 @@
     pRenderer->DrawTextureIndexed(351, 302, pIcons_LOD->GetTexture(uTextureID_x_u));
   }
   else
-    pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
+    pRenderer->DrawTextureNew(0, 0, &pTexture_PCX);
   pGUIWindow_CurrentMenu = GUIWindow::Create(saveload_dlg_xs[uDialogueType], saveload_dlg_ys[uDialogueType], saveload_dlg_zs[uDialogueType],
       saveload_dlg_ws[uDialogueType], WINDOW_MainMenu_Load, 0, 0);
   pGUIWindow_CurrentMenu->DrawText(pFontSmallnum, 25, 199, 0, pGlobalTXT_LocalizationStrings[505], 0, 0, 0);// "Reading..."