Mercurial > might-and-magic-trilogy
diff Render.cpp @ 68:fdacbc653945
BLV render: first image
author | Nomad |
---|---|
date | Sat, 27 Oct 2012 19:23:06 +0200 |
parents | 5159d2e6f559 |
children | 75994455e457 |
line wrap: on
line diff
--- a/Render.cpp Fri Oct 26 03:43:05 2012 +0200 +++ b/Render.cpp Sat Oct 27 19:23:06 2012 +0200 @@ -4129,61 +4129,42 @@ //----- (0049E4FC) -------------------------------------------------------- void RenderD3D::ClearTarget(unsigned int bClearColor, unsigned int uClearColor, unsigned int bClearDepth, float z_clear) { - unsigned int flags; // esi@1 - IDirect3DViewport3 *v6; // eax@6 - D3DRECT v7; // [sp+Ch] [bp-10h]@6 - - flags = 0; - if ( bClearColor ) - flags = 1; // D3DRMCLEAR_TARGET - if ( bClearDepth ) - flags |= 2u; // D3DRMCLEAR_ZBUFFER - if ( flags ) - { - v6 = this->pViewport; - v7.x1 = 0; - v7.y1 = 0; - v7.x2 = 640; - v7.y2 = 480; // BUG - v6->Clear2( - 1, - &v7, - flags, - uClearColor, - LODWORD(z_clear), - 0); - } + uint uClearFlags = 0; + + if (bClearColor) + uClearFlags |= D3DCLEAR_TARGET; + if (bClearDepth) + uClearFlags |= D3DCLEAR_ZBUFFER; + + D3DRECT rects[] = {{0, 0, 640, 480}}; + if (uClearFlags) + pViewport->Clear2(1, rects, uClearFlags, uClearColor, z_clear, 0); } //----- (0049E54D) -------------------------------------------------------- void RenderD3D::Present(bool bForceBlit) { - RenderD3D *v2; // esi@1 - char bFullscreen; // zf@1 - struct tagRECT Rect; // [sp+8h] [bp-28h]@4 RECT v5; // [sp+18h] [bp-18h]@1 struct tagPOINT Point; // [sp+28h] [bp-8h]@4 - v2 = this; v5.left = 0; v5.top = 0; - bFullscreen = this->bWindowed == 0; v5.bottom = 480; v5.right = 640; - if ( !bFullscreen || bForceBlit ) - { - GetClientRect(this->hWindow, &Rect); + + if (bWindowed || bForceBlit) + { + RECT rc; + GetClientRect(hWindow, &rc); Point.y = 0; Point.x = 0; - ClientToScreen(v2->hWindow, &Point); - OffsetRect(&Rect, Point.x, Point.y); - v2->pFrontBuffer->Blt(&Rect, v2->pBackBuffer, &v5, DDBLT_WAIT, 0); + ClientToScreen(hWindow, &Point); + OffsetRect(&rc, Point.x, Point.y); + pFrontBuffer->Blt(&rc, pBackBuffer, &v5, DDBLT_WAIT, 0); } else - { - this->pFrontBuffer->Flip(0, 1u); - } + pFrontBuffer->Flip(0, 1); } @@ -4692,20 +4673,13 @@ //----- (0049ECC4) -------------------------------------------------------- void Render::ClearBlack() { - Render *v1; // eax@1 - RenderD3D *v2; // ecx@1 - - v1 = this; - v2 = this->pRenderD3D; - if ( v2 ) - { - if ( v1->field_40110 ) - pRenderD3D->ClearTarget(1u, 0, 0, 0.0); + if (pRenderD3D) + { + if (field_40110) + pRenderD3D->ClearTarget(true, 0, false, 0.0); } else - { - memset(pRenderer->pTargetSurface, 0, 4 * (v1->field_10 * v1->field_14 >> 1)); - } + memset(pRenderer->pTargetSurface, 0, 4 * (field_10 * field_14 / 2)); } @@ -4718,7 +4692,8 @@ RECT x; // [sp+68h] [bp-10h]@3 memset(&v3, 0, sizeof(DDBLTFX)); - if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) + if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || + pVersion->pVersionInfo.dwMajorVersion >= 5) { x.left = uWindowX; x.right = uWindowX + uWindowHeight; @@ -5435,20 +5410,13 @@ //----- (0049FBCD) -------------------------------------------------------- void Render::ClearTarget(unsigned int uColor) { - Render *v2; // eax@1 - RenderD3D *v3; // ecx@1 - - v2 = this; - v3 = this->pRenderD3D; - if ( v3 ) - { - if ( v2->field_40110 ) - pRenderD3D->ClearTarget(1u, uColor, 0, 0.0); + if (pRenderD3D) + { + if (field_40110) + pRenderD3D->ClearTarget(true, uColor, false, 0.0); } else - { - memset32(v2->pTargetSurface, uColor, v2->field_10 * v2->field_14 >> 1); - } + memset32(pTargetSurface, uColor, field_10 * field_14 / 2); } @@ -5479,7 +5447,7 @@ { if (pAsyncMouse) pAsyncMouse->_46BAEC(); - pRenderD3D->Present(0); + pRenderD3D->Present(false); if (pAsyncMouse) pAsyncMouse->_46BB0A(); } @@ -7113,12 +7081,12 @@ { if (pRenderD3D) { - pRenderD3D->ClearTarget(1u, 0, 1u, 1.0); + pRenderD3D->ClearTarget(true, 0x00F08020, true, 1.0); pRenderer->uNumBillboardsToDraw = 0; pRenderD3D->pDevice->BeginScene(); - if ( !pRenderD3D->DoesRaiseExceptions() ) - { - MessageBoxW(nullptr, L"Error executing scratch 3D operations", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\screen16_3d.cpp:360", 0); + if (!pRenderD3D->DoesRaiseExceptions()) + { + MessageBoxW(nullptr, L"Error executing scratch 3D operations", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\screen16_3d.cpp:360", 0); } if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor ) uFogColor = GetLevelFogColor(); @@ -7323,7 +7291,7 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, a5)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 16)); @@ -7383,7 +7351,7 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, 0)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 16)); @@ -7414,7 +7382,7 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3u)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 16)); @@ -7441,7 +7409,7 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 5u)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 16)); @@ -7525,7 +7493,7 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, a4)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 24)); @@ -7581,7 +7549,7 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, a2, 28)); @@ -7592,81 +7560,66 @@ //----- (004A2FC0) -------------------------------------------------------- -void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *a3, IDirect3DTexture2 *pHwTex, Texture *pTex, int a6, int a7, int a8) -{ - Render *v8; // edi@1 - unsigned int v9; // esi@3 - HRESULT v10; // eax@8 - HRESULT v11; // eax@8 +void Render::DrawIndoorPolygon(unsigned int uNumVertices, BLVFace *pFace, IDirect3DTexture2 *pHwTex, Texture *pTex, int uPackedID, unsigned int uColor, int a8) +{ + //Render *v8; // edi@1 + //unsigned int v9; // esi@3 char *v12; // ecx@9 char *v13; // eax@9 double v14; // st6@10 int v15; // edx@10 Texture *v16; // edx@10 double v17; // st6@10 - char v18; // zf@10 + //char v18; // zf@10 Texture *v19; // edx@10 - HRESULT v20; // eax@11 - HRESULT v21; // eax@11 - HRESULT v22; // eax@11 Texture *v23; // edx@16 char *v24; // ecx@16 char *v25; // eax@16 double v26; // st6@17 int v27; // esi@17 double v28; // st6@17 - HRESULT v29; // eax@18 - HRESULT v30; // eax@18 - HRESULT v31; // eax@18 - HRESULT v32; // eax@18 unsigned int v33; // ecx@18 char *v34; // eax@19 - HRESULT v35; // eax@21 - HRESULT v36; // eax@21 - HRESULT v37; // eax@21 - HRESULT v38; // eax@21 - HRESULT v39; // eax@21 - HRESULT v40; // eax@21 - HRESULT v41; // eax@21 - HRESULT v42; // eax@21 - HRESULT v43; // eax@21 - HRESULT v44; // eax@21 - Texture *v45; // edx@23 - char *v46; // ecx@23 - char *v47; // eax@23 - double v48; // st6@24 - int v49; // esi@24 - double v50; // st6@24 - HRESULT v51; // eax@25 - HRESULT v52; // eax@25 + //Texture *v45; // edx@23 + //char *v46; // ecx@23 + //char *v47; // eax@23 + //double v48; // st6@24 + //int v49; // esi@24 + //double v50; // st6@24 const char *v53; // [sp-Ch] [bp-20h]@21 - int v54; // [sp-8h] [bp-1Ch]@21 - unsigned int v55; // [sp-4h] [bp-18h]@21 + //int v54; // [sp-8h] [bp-1Ch]@21 + //unsigned int v55; // [sp-4h] [bp-18h]@21 const char *v56; // [sp+0h] [bp-14h]@0 int v57; // [sp+4h] [bp-10h]@0 unsigned int v58; // [sp+8h] [bp-Ch]@0 - LightmapBuilder *v59; // [sp+Ch] [bp-8h]@3 - int a3a; // [sp+10h] [bp-4h]@4 - - v8 = this; - if ( this->uNumD3DSceneBegins && (signed int)uNumVertices >= 3 ) - { - v59 = pGame->pLightmapBuilder; - v9 = v59->std__vector_000004_size; - if ( v9 ) - a3a = -1; - else - a3a = a7; - pGame->_44EDE4(a3, &a3a); - if ( byte_4D864C && pGame->uFlags & 1 ) - { + //LightmapBuilder *v59; // [sp+Ch] [bp-8h]@3 + //int a3a; // [sp+10h] [bp-4h]@4 + + //v8 = this; + if (!uNumD3DSceneBegins || uNumVertices < 3) + return; + + //auto a3 = pFace; + //auto a6 = uPackedID; + //v59 = pGame->pLightmapBuilder; + //v9 = v59->std__vector_000004_size; + + auto uCorrectedColor = uColor; + if (pGame->pLightmapBuilder->std__vector_000004_size) + uCorrectedColor = 0xFFFFFFFF; + pGame->AlterGamma(pFace, &uCorrectedColor); + + if (byte_4D864C && pGame->uFlags & 1) + { + __debugbreak(); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false)); ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1)); if ( (signed int)uNumVertices > 0 ) { v12 = (char *)&array_507D30[0].vWorldViewPosition; v13 = (char *)&arary_77E5C8[0].pos.y; - a7 = uNumVertices; + auto a7 = uNumVertices; + uint v18; do { v14 = *(float *)v12 * 0.061758894; @@ -7674,7 +7627,7 @@ *((int *)v13 + 4) = 0; *((int *)v13 - 1) = v15; *(int *)v13 = *((int *)v12 + 4); - *((int *)v13 + 3) = a3a; + *((int *)v13 + 3) = uCorrectedColor; v16 = pTex; v13 += 32; *((float *)v13 - 7) = 1.0 - 1.0 / v14; @@ -7694,63 +7647,47 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 28)); - v59->_45D74F_MessWithLight(-1, 0); - } - else - { - if ( !v9 || byte_4D864C && pGame->uFlags & 2 ) - { - if ( (signed int)uNumVertices > 0 ) - { - v45 = pTex; - v46 = (char *)&array_507D30[0].vWorldViewPosition; - v47 = (char *)&arary_77E5C8[0].pos.y; - pTex = (Texture *)uNumVertices; - do - { - v48 = *(float *)v46 * 0.061758894; - v49 = *((int *)v46 + 3); - *((int *)v47 + 4) = 0; - *((int *)v47 - 1) = v49; - *(int *)v47 = *((int *)v46 + 4); - *((int *)v47 + 3) = a3a; - v47 += 32; - *((float *)v47 - 7) = 1.0 - 1.0 / v48; - v50 = 1.0 / *(float *)v46; - v46 += 48; - v18 = pTex == (Texture *)1; - pTex = (Texture *)((char *)pTex - 1); - *((float *)v47 - 6) = v50; - a7 = v45->uTextureWidth; - *((float *)v47 - 3) = *((float *)v46 - 6) / (double)a7; - a7 = v45->uTextureHeight; - *((float *)v47 - 2) = *((float *)v46 - 5) / (double)a7; - } - while ( !v18 ); - } - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1)); - ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex)); - v55 = 0; - v54 = 1490; - ErrD3D(pRenderD3D->pDevice->DrawPrimitive( - D3DPT_TRIANGLEFAN, - 452, + pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0); + } + else + { + if (!pGame->pLightmapBuilder->std__vector_000004_size || + byte_4D864C && pGame->uFlags & 2) + { + for (uint i = 0; i < uNumVertices; ++i) + { + arary_77E5C8[i].pos.x = array_507D30[i].vWorldViewProjX; + arary_77E5C8[i].pos.y = array_507D30[i].vWorldViewProjY; + arary_77E5C8[i].pos.z = 1.0 - 1.0 / (array_507D30[i].vWorldViewPosition.x * 0.061758894); + arary_77E5C8[i].rhw = 1.0 / array_507D30[i].vWorldViewPosition.x; + arary_77E5C8[i].diffuse = uCorrectedColor; + arary_77E5C8[i].specular = 0; + arary_77E5C8[i].texcoord.x = array_507D30[i].u / (double)pTex->uTextureWidth; + arary_77E5C8[i].texcoord.y = array_507D30[i].v / (double)pTex->uTextureHeight; + } + + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, 1)); + ErrD3D(pRenderD3D->pDevice->SetTexture(0, pHwTex)); + ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 28)); - } - else - { + } + else + { + __debugbreak(); if ( (signed int)uNumVertices > 0 ) { v23 = pTex; v24 = (char *)&array_507D30[0].vWorldViewPosition; v25 = (char *)&arary_77E5C8[0].pos.y; pTex = (Texture *)uNumVertices; + uint v18; do { v26 = *(float *)v24 * 0.061758894; @@ -7758,7 +7695,7 @@ *((int *)v25 + 4) = 0; *((int *)v25 - 1) = v27; *(int *)v25 = *((int *)v24 + 4); - *((int *)v25 + 3) = a7; + *((int *)v25 + 3) = uColor; v25 += 32; *((float *)v25 - 7) = 1.0 - 1.0 / v26; v28 = 1.0 / *(float *)v24; @@ -7766,10 +7703,10 @@ v18 = pTex == (Texture *)1; pTex = (Texture *)((char *)pTex - 1); *((float *)v25 - 6) = v28; - a3 = (BLVFace *)v23->uTextureWidth; - *((float *)v25 - 3) = *((float *)v24 - 6) / (double)(signed int)a3; - a3 = (BLVFace *)v23->uTextureHeight; - *((float *)v25 - 2) = *((float *)v24 - 5) / (double)(signed int)a3; + //a3 = (BLVFace *)v23->uTextureWidth; + *((float *)v25 - 3) = *((float *)v24 - 6) / (double)(signed int)v23->uTextureWidth; + //a3 = (BLVFace *)v23->uTextureHeight; + *((float *)v25 - 2) = *((float *)v24 - 5) / (double)(signed int)v23->uTextureHeight; } while ( !v18 ); } @@ -7778,19 +7715,19 @@ ErrD3D(pRenderD3D->pDevice->SetTexture(0, nullptr)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 28)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1)); - v59->_45D74F_MessWithLight(-1, 0); + pGame->pLightmapBuilder->_45D74F_MessWithLight(-1, 0); v33 = uNumVertices; if ( (signed int)uNumVertices > 0 ) { v34 = (char *)&arary_77E5C8[0].diffuse; do { - *(int *)v34 = a3a; + *(int *)v34 = uCorrectedColor; v34 += 32; --v33; } @@ -7804,14 +7741,13 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 3)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, arary_77E5C8, uNumVertices, 28)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, 2)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, 1)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, false)); - } } } } @@ -8614,7 +8550,7 @@ ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, a9)); ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, v29, 4, 24)); @@ -9092,7 +9028,7 @@ ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 8u)); ErrD3D(pRenderD3D->pDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, - 452, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, v36, 4, 28));