diff Engine/Graphics/Render.cpp @ 2574:dd36326a9994

More texture refactoring GetLeather -> DrawTextureCustomHeight
author a.parshin
date Mon, 07 Mar 2016 03:48:40 +0200
parents 0c67be4ec900
children a76d408c5132
line wrap: on
line diff
--- a/Engine/Graphics/Render.cpp	Sat Mar 05 16:25:53 2016 +0200
+++ b/Engine/Graphics/Render.cpp	Mon Mar 07 03:48:40 2016 +0200
@@ -306,7 +306,7 @@
       pTilePolygon->flags = 0;
       pTilePolygon->field_32 = 0;
       pTilePolygon->uTileBitmapID = pOutdoor->DoGetTileTexture(x, z);
-      pTilePolygon->pTexture = (Texture *)&pBitmaps_LOD->pHardwareTextures[pTilePolygon->uTileBitmapID];
+      pTilePolygon->pTexture = (Texture_MM7 *)&pBitmaps_LOD->pHardwareTextures[pTilePolygon->uTileBitmapID];
       if (pTilePolygon->uTileBitmapID == 0xFFFF)
         continue;
 
@@ -5146,7 +5146,7 @@
 }
 
 //----- (004A2FC0) --------------------------------------------------------
-void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *pFace, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8)
+void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *pFace, IDirect3DTexture2 *pHwTex, Texture_MM7 *pTex, int uPackedID, unsigned int uColor, int a8)
 {
   if (!uNumD3DSceneBegins || uNumVertices < 3)
     return;
@@ -6370,13 +6370,15 @@
          0xF800 & (r << (6 + 5 + 5 - 8));
 }
 
-void Render::DrawTextureNew(float u, float v, Texture *a4)
+void Render::DrawTextureNew(float u, float v, Texture_MM7 *a4)
 {
   __debugbreak();
 }
 
 
-void Render::DrawTextureNew(float u, float v, Image *bmp)
+
+
+void Render::DrawTextureCustomHeight(float u, float v, class Image *img, int custom_height)
 {
     unsigned __int16 *v6; // esi@3
     unsigned int v8; // eax@5
@@ -6385,60 +6387,65 @@
     unsigned int v15; // eax@14
     int v19; // [sp+10h] [bp-8h]@3
 
-    if (!bmp)
+    if (!img)
         return;
 
     unsigned int uOutX = 640 * u;
     unsigned int uOutY = 480 * v;
 
-    int width = bmp->GetWidth();
-    int height = bmp->GetHeight();
-    v6 = (unsigned __int16 *)bmp->GetPixels(IMAGE_FORMAT_R5G6B5);
-
-        //v5 = &this->pTargetSurface[uOutX + uOutY * this->uTargetSurfacePitch];
-        v19 = width;
-        if (this->bClip)
-        {
-            if ((signed int)uOutX < (signed int)this->uClipX)
-            {
-                v8 = this->uClipX - uOutX;
-                unsigned int v9 = uOutX - this->uClipX;
-                v8 *= 2;
-                width += v9;
-                v6 = (unsigned __int16 *)((char *)v6 + v8);
-                //v5 = (unsigned __int16 *)((char *)v5 + v8);
-            }
-            if ((signed int)uOutY < (signed int)this->uClipY)
-            {
-                v11 = this->uClipY - uOutY;
-                v6 += v19 * v11;
-                height += uOutY - this->uClipY;
-                //v5 += this->uTargetSurfacePitch * v11;
-            }
-            v12 = max(this->uClipX, uOutX);
-            if ((signed int)(width + v12) >(signed int)this->uClipZ)
-            {
-                width = this->uClipZ - max(this->uClipX, uOutX);
-            }
-            v15 = max(this->uClipY, uOutY);
-            if ((signed int)(v15 + height) > (signed int)this->uClipW)
-            {
-                height = this->uClipW - max(this->uClipY, uOutY);
-            }
+    int width = img->GetWidth();
+    int height = min(img->GetHeight(), custom_height);
+    v6 = (unsigned __int16 *)img->GetPixels(IMAGE_FORMAT_R5G6B5);
+
+    //v5 = &this->pTargetSurface[uOutX + uOutY * this->uTargetSurfacePitch];
+    v19 = width;
+    if (this->bClip)
+    {
+        if ((signed int)uOutX < (signed int)this->uClipX)
+        {
+            v8 = this->uClipX - uOutX;
+            unsigned int v9 = uOutX - this->uClipX;
+            v8 *= 2;
+            width += v9;
+            v6 = (unsigned __int16 *)((char *)v6 + v8);
+            //v5 = (unsigned __int16 *)((char *)v5 + v8);
+        }
+        if ((signed int)uOutY < (signed int)this->uClipY)
+        {
+            v11 = this->uClipY - uOutY;
+            v6 += v19 * v11;
+            height += uOutY - this->uClipY;
+            //v5 += this->uTargetSurfacePitch * v11;
         }
-
-        for (int y = 0; y < height; y++)
-        {
-            for (int x = 0; x < width; x++)
-            {
-                WritePixel16(uOutX + x, uOutY + y, *v6);
-                //*v5 = *v6;
-                //++v5;
-                ++v6;
-            }
-            v6 += v19 - width;
-            //v5 += this->uTargetSurfacePitch - v4;
+        v12 = max(this->uClipX, uOutX);
+        if ((signed int)(width + v12) >(signed int)this->uClipZ)
+        {
+            width = this->uClipZ - max(this->uClipX, uOutX);
+        }
+        v15 = max(this->uClipY, uOutY);
+        if ((signed int)(v15 + height) > (signed int)this->uClipW)
+        {
+            height = this->uClipW - max(this->uClipY, uOutY);
         }
+    }
+
+    for (int y = 0; y < height; y++)
+    {
+        for (int x = 0; x < width; x++)
+        {
+            WritePixel16(uOutX + x, uOutY + y, *v6);
+            //*v5 = *v6;
+            //++v5;
+            ++v6;
+        }
+        v6 += v19 - width;
+        //v5 += this->uTargetSurfacePitch - v4;
+    }
+}
+
+void Render::DrawTextureNew(float u, float v, Image *bmp)
+{
+    DrawTextureCustomHeight(u, v, bmp, bmp->GetHeight());
 }
 
 
@@ -6515,7 +6522,7 @@
 }
 
 //----- (004A6E7E) --------------------------------------------------------
-void Render::DrawTranslucent(unsigned int a2, unsigned int a3, Texture *a4)
+void Render::DrawTranslucent(unsigned int a2, unsigned int a3, Texture_MM7 *a4)
 {
   int v5; // edx@4
   unsigned int v6; // edi@4
@@ -6790,16 +6797,17 @@
     }
 }
 
+/*
 //----- (004A6A68) --------------------------------------------------------
-void Render::GetLeather(unsigned int a2, unsigned int a3, Texture *a4, __int16 height)
-{
-  Texture tex; // [sp+Ch] [bp-48h]@1
-
-  memcpy(&tex, a4, sizeof(tex));
-  tex.uTextureHeight = a4->uTextureHeight - height;
+void Render::DrawTextureCustomHeight(unsigned int x, unsigned int y, Texture_MM7 *texture, __int16 height)
+{
+  Texture_MM7 tex; // [sp+Ch] [bp-48h]@1
+
+  memcpy(&tex, texture, sizeof(tex));
+  tex.uTextureHeight = texture->uTextureHeight - height;
   if ( (signed __int16)tex.uTextureHeight > 0 )
-      DrawTextureTransparentColorKey(a2, a3, &tex);
-}
+      DrawTextureTransparentColorKey(x, y, &tex);
+}*/
 
 //----- (004A6AB1) --------------------------------------------------------
 void Render::DrawTextAlpha( int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, bool present_time_transparency )
@@ -6963,124 +6971,20 @@
 }
 
 //----- (004A68EF) --------------------------------------------------------
-void Render::DrawTransparentGreenShade(signed int a2, signed int a3, Texture *pTexture)
-{
-  DrawMasked(a2, a3, pTexture, 0x07E0);
+void Render::DrawTransparentGreenShade(float u, float v, Image *pTexture)
+{
+  DrawMasked(u, v, pTexture, 0x07E0);
 }
 
 
 //----- (004A6776) --------------------------------------------------------
-void Render::DrawTransparentRedShade(unsigned int a2, unsigned int a3, Texture *a4)
-{
-  DrawMasked(a2, a3, a4, 0xF800);
-  /*Texture *v4; // edi@2
-  unsigned int v5; // ebx@4
-  unsigned __int16 *v6; // eax@4
-  unsigned int v7; // edx@5
-  unsigned int v8; // edx@6
-  unsigned int v9; // edx@7
-  unsigned int v10; // edx@8
-  unsigned int v11; // edx@9
-  unsigned int v12; // esi@12
-  unsigned int v13; // esi@15
-  unsigned int v14; // edx@17
-  unsigned int v15; // esi@18
-  unsigned __int8 *v16; // ebx@22
-  char v17; // zf@28
-  int v18; // [sp+10h] [bp-10h]@4
-  unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
-  int v20; // [sp+1Ch] [bp-4h]@4
-  int a2a; // [sp+28h] [bp+8h]@24
-  unsigned int a3a; // [sp+2Ch] [bp+Ch]@22
-  unsigned int a4a; // [sp+30h] [bp+10h]@11
-
-  if ( this->uNumSceneBegins )
-  {
-    v4 = a4;
-    if ( a4 )
-    {
-      if ( a4->pPalette16 )
-      {
-        v5 = a4->uTextureHeight;
-        v6 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
-        v19 = a4->pLevelOfDetail0_prolly_alpha_mask;
-        v20 = a4->uTextureWidth;
-        v18 = a4->uTextureWidth;
-        if ( this->bClip )
-        {
-          v7 = this->uClipX;
-          if ( (signed int)a2 < (signed int)v7 )
-          {
-            v8 = v7 - a2;
-            v19 += v8;
-            v20 += a2 - this->uClipX;
-            v6 += v8;
-          }
-          v9 = this->uClipY;
-          v5 = a4->uTextureHeight;
-          if ( (signed int)a3 < (signed int)v9 )
-          {
-            v10 = v9 - a3;
-            v19 += v18 * v10;
-            v5 = a3 - this->uClipY + a4->uTextureHeight;
-            v4 = a4;
-            v6 += this->uTargetSurfacePitch * v10;
-          }
-          v11 = this->uClipX;
-          if ( (signed int)v11 < (signed int)a2 )
-            v11 = a2;
-          a4a = this->uClipZ;
-          if ( (signed int)(v11 + v20) > (signed int)a4a )
-          {
-            v12 = this->uClipX;
-            if ( (signed int)v12 < (signed int)a2 )
-              v12 = a2;
-            v20 = a4a - v12;
-          }
-          v13 = this->uClipY;
-          if ( (signed int)v13 < (signed int)a3 )
-            v13 = a3;
-          v14 = this->uClipW;
-          if ( (signed int)(v5 + v13) > (signed int)v14 )
-          {
-            v15 = this->uClipY;
-            if ( (signed int)v15 < (signed int)a3 )
-              v15 = a3;
-            v5 = v14 - v15;
-          }
-        }
-        if ( (signed int)v5 > 0 )
-        {
-          a3a = v5;
-          v16 = v19;
-          do
-          {
-            if ( v20 > 0 )
-            {
-              a2a = v20;
-              do
-              {
-                if ( *v16 )
-                  *v6 = this->uTargetRMask & v4->pPalette16[*v16];
-                ++v6;
-                ++v16;
-                --a2a;
-              }
-              while ( a2a );
-            }
-            v16 += v18 - v20;
-            v17 = a3a-- == 1;
-            v6 += this->uTargetSurfacePitch - v20;
-          }
-          while ( !v17 );
-        }
-      }
-    }
-  }*/
+void Render::DrawTransparentRedShade(float u, float v, Image *a4)
+{
+  DrawMasked(u, v, a4, 0xF800);
 }
 
 //----- (004A68EF) --------------------------------------------------------
-void Render::DrawMasked(signed int a2, signed int a3, Texture *pTexture, unsigned __int16 mask)
+void Render::DrawMasked(float u, float v, Image *pTexture, unsigned __int16 mask)
 {
   unsigned int v5; // ebx@4
   int v10; // edx@8
@@ -7088,37 +6992,42 @@
   signed int v12; // esi@12
   signed int v13; // esi@15
   signed int v15; // esi@18
-  unsigned __int8 *v16; // ebx@22
+  //unsigned __int8 *v16; // ebx@22
   int v18; // [sp+10h] [bp-10h]@4
-  unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
+  //unsigned __int8 *v19; // [sp+18h] [bp-8h]@4
   int v20; // [sp+1Ch] [bp-4h]@4
 
   if (!uNumSceneBegins || !pTexture)
     return;
 
-  if ( pTexture->pPalette16 )
-  {
-    v5 = pTexture->uTextureHeight;
+  //if ( pTexture->pPalette16 )
+  {
+    v5 = pTexture->GetHeight();
     //v6 = &this->pTargetSurface[a2 + a3 * this->uTargetSurfacePitch];
-    v19 = pTexture->paletted_pixels;
-    v20 = pTexture->uTextureWidth;
-    v18 = pTexture->uTextureWidth;
+    //v19 = pTexture->paletted_pixels;
+    auto pixels = (unsigned __int32 *)pTexture->GetPixels(IMAGE_FORMAT_A8R8G8B8);
+
+    v18 = v20 = pTexture->GetWidth();
+
+    int a2 = u * window->GetWidth();
+    int a3 = v * window->GetHeight();
+
     int clipped_out_x = a2;
     int clipped_out_y = a3;
     if ( this->bClip )
     {
       if ( a2 < this->uClipX )
       {
-        v19 += this->uClipX - a2;
+          pixels += this->uClipX - a2;
         v20 += a2 - this->uClipX;
         clipped_out_x = uClipX;
       }
-      v5 = pTexture->uTextureHeight;
+      v5 = pTexture->GetHeight();
       if ( a3 < this->uClipY )
       {
         v10 = this->uClipY - a3;
-        v19 += v18 * v10;
-        v5 = a3 - this->uClipY + pTexture->uTextureHeight;
+        pixels += v18 * v10;
+        v5 = a3 - this->uClipY + pTexture->GetHeight();
         clipped_out_y = uClipY;
       }
       v11 = this->uClipX;
@@ -7143,7 +7052,7 @@
       }
     }
         
-    v16 = v19;
+    /*v16 = v19;
     for (uint y = 0; y < v5; ++y)
     {
       for (int x = 0; x < v20; ++x)
@@ -7153,39 +7062,28 @@
         ++v16;
       }
       v16 += v18 - v20;
-    }
-
-        /*if ( (signed int)v5 > 0 )
-        {
-          v22 = v5;
-          v16 = v19;
-          do
-          {
-            if ( v20 > 0 )
-            {
-              v21 = v20;
-              do
-              {
-                if ( *v16 )
-                  *v6 = this->uTargetGMask & v4->pPalette16[*v16];
-                ++v6;
-                ++v16;
-                --v21;
-              }
-              while ( v21 );
-            }
-            v16 += v18 - v20;
-            v17 = v22-- == 1;
-            v6 += this->uTargetSurfacePitch - v20;
-          }
-          while ( !v17 );
-        }*/
+    }*/
+
+    for (uint y = 0; y < v5; ++y)
+    {
+        for (int x = 0; x < v20; ++x)
+        {
+            if (*pixels & 0xFF000000)
+                WritePixel16(
+                    clipped_out_x + x,
+                    clipped_out_y + y,
+                    Color16((*pixels >> 16) & 0xFF, (*pixels >> 8) & 0xFF, *pixels & 0xFF) & mask
+                );
+            ++pixels;
+        }
+        pixels += v18 - v20;
+    }
   }
 }
 
 
 //----- (004A65CC) --------------------------------------------------------
-void Render::_4A65CC(unsigned int x, unsigned int y, Texture *a4, Texture *a5, int a6, int a7, int a8)
+void Render::_4A65CC(unsigned int x, unsigned int y, Texture_MM7 *a4, Texture_MM7 *a5, int a6, int a7, int a8)
 {
   unsigned int uHeight; // edi@6
   unsigned int v14; // edx@11
@@ -7291,7 +7189,8 @@
 }
 
 //----- (004A63E6) --------------------------------------------------------
-void Render::DrawAura(unsigned int a2, unsigned int a3, Texture *a4, Texture *a5, int a6, int a7, int a8)
+void Render::BlendTextures(unsigned int a2, unsigned int a3, Image *a4, Texture_MM7 *a5, int t, int start_opacity, int end_opacity)
+                         //unsigned int a2, unsigned int a3, Image *a4, Texture_MM7 *a5, int a6, int a7, int a8)
 {
   unsigned int v14; // edx@11
   unsigned int v16; // edx@14
@@ -7304,7 +7203,7 @@
   int v27; // [sp+24h] [bp+Ch]@23
   unsigned __int8 *v28; // [sp+28h] [bp+10h]@6
 
-  if ( this->uNumSceneBegins )
+  /*if ( this->uNumSceneBegins )
   {
     if ( a4 )
     {
@@ -7387,7 +7286,7 @@
         }
       }
     }
-  }
+  }*/
 }
 
 
@@ -7460,10 +7359,16 @@
     {
         for (int x = 0; x < uWidth; ++x)
         {
-            //if (*v19)
             if (*pixels & 0xFF000000)
-                //WritePixel16(clipped_out_x + x, clipped_out_y + y, pTexture->pPalette16[*v19]);
-                WritePixel16(clipped_out_x + x, clipped_out_y + y, Color16((*pixels >> 16) & 0xFF, (*pixels >> 8) & 0xFF, *pixels & 0xFF));
+                WritePixel16(
+                    clipped_out_x + x,
+                    clipped_out_y + y,
+                    Color16(
+                        (*pixels >> 16) & 0xFF,
+                        (*pixels >> 8) & 0xFF,
+                        *pixels & 0xFF
+                    )
+                );
             ++pixels;
         }
         pixels  += img->GetWidth() - uWidth;
@@ -7473,7 +7378,7 @@
 
 
 //----- (004A6274) --------------------------------------------------------
-void Render::DrawTextureIndexedAlpha(unsigned int uX, unsigned int uY, Texture *pTexture)
+void Render::DrawTextureIndexedAlpha(unsigned int uX, unsigned int uY, Texture_MM7 *pTexture)
 {
   int uHeight; // ebx@4
   unsigned int v11; // edx@9
@@ -7545,37 +7450,13 @@
           }
           v19 += pTexture->uTextureWidth - uWidth;
         }
-        /*if ( (signed int)uHeight > 0 )
-        {
-          uYa = uHeight;
-          v16 = v19;
-          do
-          {
-            if ( uWidth > 0 )
-            {
-              uXa = uWidth;
-              do
-              {
-                if ( *v16 )
-                  *v6 = pCurrentTexture->pPalette16[*v16];
-                ++v6;
-                ++v16;
-              }
-              while ( uXa-- !=1 );
-            }
-            v16 += v18 - uWidth;
-            uFlag = uYa-- == 1;
-            v6 += this->uTargetSurfacePitch - uWidth;
-          }
-          while ( !uFlag );
-        }*/
       }
     }
   }
 }
 
 //----- (004A612A) --------------------------------------------------------
-void Render::DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, Texture *pTexture, int zVal)
+void Render::ZDrawTextureAlpha(float u, float v, Image *img, int zVal)
 {
   unsigned int v6; // edx@3
   int v7; // ebx@3
@@ -7589,33 +7470,34 @@
   int v19; // [sp+Ch] [bp-Ch]@3
   int v20; // [sp+10h] [bp-8h]@3
   int uOutXa; // [sp+20h] [bp+8h]@21
-  unsigned __int8 *uOutYa; // [sp+24h] [bp+Ch]@3
+  //unsigned __int8 *uOutYa; // [sp+24h] [bp+Ch]@3
   int *pZBuffer; // [sp+28h] [bp+10h]@3
 
-  if ( this->uNumSceneBegins )
-  {
-    if ( pTexture )
-    {
+  if (!this->uNumSceneBegins || !img)
+      return;
+
+  int uOutX = u * this->window->GetWidth();
+  int uOutY = v * this->window->GetHeight();
+
       v6 = uOutY;
-      v7 = pTexture->uTextureHeight;
+      v7 = img->GetHeight();
       pZBuffer = &this->pActiveZBuffer[uOutX + window->GetWidth() * uOutY];
-      uOutYa = pTexture->paletted_pixels;
-      v8 = pTexture->uTextureWidth;
-      v20 = pTexture->uTextureWidth;
-      v19 = pTexture->uTextureWidth;
+      //uOutYa = pTexture->paletted_pixels;
+      v8 = v20 = v19 = img->GetWidth();
+      auto pixels = (unsigned __int32 *)img->GetPixels(IMAGE_FORMAT_A8R8G8B8);
       if ( this->bClip )
       {
         if ( uOutX < this->uClipX )
         {
           v10 = this->uClipX - uOutX;
-          uOutYa += v10;
+          pixels += v10;
           v8 += uOutX - this->uClipX;
           v20 = v8;
           pZBuffer += v10;
         }
         if ( (signed int)v6 < (signed int)this->uClipY )
         {
-          uOutYa += v19 * (this->uClipY - v6);
+            pixels += v19 * (this->uClipY - v6);
           v7 += v6 - this->uClipY;
           pZBuffer += window->GetWidth() * (this->uClipY - v6);
           v8 = v20;
@@ -7641,6 +7523,9 @@
           v7 = this->uClipW - v6;
         }
       }
+
+
+
       if ( v7 > 0 )
       {
         uOutXa = v7;
@@ -7651,28 +7536,27 @@
             v18 = v8;
             do
             {
-              if ( *uOutYa )
+              if ( *pixels & 0xFF000000)
                 *pZBuffer = zVal;
               ++pZBuffer;
-              ++uOutYa;
+              ++pixels;
               --v18;
             }
             while ( v18 );
           }
           pZBuffer += window->GetWidth() - v8;
-          uOutYa += v19 - v8;
+          pixels += v19 - v8;
           --uOutXa;
         }
         while ( uOutXa );
       }
-    }
-  }
+
 }
 
 //----- (004A601E) --------------------------------------------------------
-void Render::ZBuffer_Fill_2(signed int a2, signed int a3, Texture *pTexture, int a5)
-{
-  signed int v5; // edx@3
+void Render::ZBuffer_Fill_2(signed int a2, signed int a3, Image *pTexture, int a5)
+{
+/*  signed int v5; // edx@3
   int v6; // ebx@3
   int v7; // esi@3
   void *v8; // esi@3
@@ -7739,13 +7623,13 @@
       }
       while ( v6 );
     }
-  }
+  }*/
 }
 
 
 
 //----- (004A5EB2) --------------------------------------------------------
-void Render::DrawTextureTransparentColorKey(signed int x, signed int y, Texture *tex)
+void Render::DrawTextureTransparentColorKey(signed int x, signed int y, Texture_MM7 *tex)
 {
   int v5; // ebx@4
   unsigned int v8; // edx@6
@@ -8306,7 +8190,7 @@
 void Render::DrawBuildingsD3D()
 {
   int v9; // ecx@8
-  Texture *pFaceTexture; // eax@10
+  Texture_MM7 *pFaceTexture; // eax@10
   unsigned int v16; // edi@22
   int v27; // eax@57
 //  int vertex_id; // eax@58
@@ -8548,7 +8432,7 @@
 	//pSkyPolygon.uTileBitmapID = pOutdoor->New_SKY_NIGHT_ID;
   //else
 	pSkyPolygon.uTileBitmapID = pOutdoor->sSky_TextureID;//179(original 166)
-  pSkyPolygon.pTexture = (Texture *)(pSkyPolygon.uTileBitmapID != -1 ? (int)&pBitmaps_LOD->pTextures[pSkyPolygon.uTileBitmapID] : 0);
+  pSkyPolygon.pTexture = (Texture_MM7 *)(pSkyPolygon.uTileBitmapID != -1 ? (int)&pBitmaps_LOD->pTextures[pSkyPolygon.uTileBitmapID] : 0);
   if ( pSkyPolygon.pTexture )
   {
     pSkyPolygon.dimming_level = 0;