Mercurial > mm7
diff Render.cpp @ 2154:9bd7522cdbbb
Render decoupling.
Unsorted variables cleaning.
author | Nomad |
---|---|
date | Thu, 09 Jan 2014 14:36:48 +0200 |
parents | d28d3c006077 |
children | 0a1438c16c2b |
line wrap: on
line diff
--- a/Render.cpp Thu Jan 09 02:34:20 2014 +0200 +++ b/Render.cpp Thu Jan 09 14:36:48 2014 +0200 @@ -80,7 +80,7 @@ signed int __stdcall RenderD3D__DeviceEnumerator(GUID *lpGUID, const char *lpDevDesc, const char *lpDriverName, RenderD3D__DevInfo *pOut); // idb //----- (0049E79F) -------------------------------------------------------- -bool CheckTextureStages() +bool Render::CheckTextureStages() { bool v0; // edi@1 IDirectDrawSurface4 *pSurface2; // [sp+Ch] [bp-14h]@1 @@ -90,30 +90,30 @@ IDirect3DTexture2 *pTexture1; // [sp+1Ch] [bp-4h]@1 v0 = false; - pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface1, &pTexture1, true, false, 32u); - pRenderer->pRenderD3D->CreateTexture(64u, 64u, &pSurface2, &pTexture2, true, false, 32u); - - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture1)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 1u)); - - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture2)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 7u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, 1u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MINFILTER, 2u)); - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MIPFILTER, 1u)); - - if ( !pRenderer->pRenderD3D->pDevice->ValidateDevice(&v4) && v4 == 1 ) + pRenderD3D->CreateTexture(64u, 64u, &pSurface1, &pTexture1, true, false, 32u); + pRenderD3D->CreateTexture(64u, 64u, &pSurface2, &pTexture2, true, false, 32u); + + ErrD3D(pRenderD3D->pDevice->SetTexture(0, pTexture1)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 1)); + + ErrD3D(pRenderD3D->pDevice->SetTexture(0, pTexture2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 7)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, 1)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MINFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_MIPFILTER, 1)); + + if ( !pRenderD3D->pDevice->ValidateDevice(&v4) && v4 == 1 ) v0 = true; - ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1u)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, 1u)); pTexture1->Release(); pTexture2->Release(); pSurface1->Release(); @@ -200,28 +200,9 @@ } //----- (004A16A5) -------------------------------------------------------- -bool AreRenderSurfacesOk() -{ - char v0; // zf@4 - bool result; // eax@8 - - if (!pRenderer) - return true; - - { - if ( !pRenderer->pBackBuffer4 ) - goto LABEL_9; - v0 = pRenderer->pFrontBuffer4 == 0; - } - - if ( !v0 ) - { - LOBYTE(result) = 1; - return result; - } -LABEL_9: - LOBYTE(result) = 0; - return result; +bool Render::AreRenderSurfacesOk() +{ + return pFrontBuffer4 && pBackBuffer4; } @@ -614,8 +595,8 @@ LOBYTE(v46) = v46 | 0x80; if ( a6 ) { - //LOBYTE(v11) = byte_4E94D3; - pMobileLightsStack->AddLight(x, y, z, object->uSectorID, a6, 0xFFu, 0xFFu, 0xFFu, byte_4E94D3); + //LOBYTE(v11) = _4E94D3_light_type; + pMobileLightsStack->AddLight(x, y, z, object->uSectorID, a6, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type); } v12 = (x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16; if (pGame->pIndoorCameraD3D->sRotationX) @@ -1113,7 +1094,7 @@ v14, v15, v16, - byte_4E94D0); + _4E94D0_light_type); } v17 = (decor->vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16; if (pGame->pIndoorCameraD3D->sRotationX) @@ -1716,20 +1697,20 @@ } else { - if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 0x10) ) + if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_SRCALPHA) ) v1 = 2; - if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 2) ) + if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_ONE) ) v1 |= 4u; - if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & 1) ) + if ( !(halCaps.dpcTriCaps.dwSrcBlendCaps & D3DPBLENDCAPS_ZERO) ) v1 |= 8u; - if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 0x20) ) + if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) ) v1 |= 0x10u; - if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 2) ) + if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_ONE) ) v1 |= 0x20u; - if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & 4) ) + if ( !(halCaps.dpcTriCaps.dwDestBlendCaps & D3DPBLENDCAPS_SRCCOLOR) ) v1 |= 0x40u; - if ( halCaps.dpcTriCaps.dwTextureCaps & 0x20 ) - LOBYTE(v1) = v1 | 0x80; + if ( halCaps.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY ) + v1 |= 0x80; result = v1; } return result; @@ -2119,7 +2100,7 @@ this->pDirectDraw4 = 0; this->pFrontBuffer4 = 0; this->pBackBuffer4 = 0; - this->pColorKeySurface4 = 0; + //this->pColorKeySurface4 = 0; //this->pDirectDraw2 = 0; //this->pFrontBuffer2 = 0; //this->pBackBuffer2 = 0; @@ -2127,25 +2108,25 @@ //RenderHWLContainer::RenderHWLContainer(&this->pD3DBitmaps); //RenderHWLContainer::RenderHWLContainer(&v1->pD3DSprites); v1->bWindowMode = 1; - v1->field_40054 = 0; - v1->field_10 = 640; - v1->field_14 = 480; - v1->field_40030 = 0; - v1->field_4002C = 0; + //v1->field_40054 = 0; + //v1->field_10 = 640; + //v1->field_14 = 480; + //v1->field_40030 = 0; + //v1->field_4002C = 0; v1->pActiveZBuffer = 0; v1->pDefaultZBuffer = 0; v1->raster_clip_y = 0; v1->raster_clip_x = 0; v1->raster_clip_z = 639; v1->raster_clip_w = 479; - v1->field_4003C = (int)&unk_4EED80; - v1->field_40040 = dword_4EED78; + //v1->field_4003C = 0x004EED80; + //v1->field_40040 = dword_4EED78; v1->uClipZ = 640; - v1->field_40044 = 2; - v1->field_40048 = 6; + //v1->field_40044 = 2; + //v1->field_40048 = 6; v1->pFrontBuffer4 = 0; v1->pBackBuffer4 = 0; - v1->pColorKeySurface4 = 0; + //v1->pColorKeySurface4 = 0; v1->pDirectDraw4 = 0; v1->pRenderD3D = 0; v1->uNumSceneBegins = 0; @@ -2160,7 +2141,7 @@ //v1->bColorKeySupported = 0; v1->bRequiredTextureStagesAvailable = 0; v1->bTinting = 1; - LOBYTE(v1->field_103668) = 0; + //LOBYTE(v1->field_103668) = 0; uNumBillboardsToDraw = 0; bFogEnabled = false; @@ -2195,13 +2176,13 @@ //----- (0049ECC4) -------------------------------------------------------- void Render::ClearBlack() { - if (pRenderD3D) + //if (pRenderD3D) { if (using_software_screen_buffer) pRenderD3D->ClearTarget(true, 0, false, 0.0); } - else - memset(pRenderer->pTargetSurface, 0, 4 * (field_10 * field_14 / 2)); + //else + //memset(pRenderer->pTargetSurface, 0, 4 * (field_10 * field_14 / 2)); } //----- (0049ED18) -------------------------------------------------------- @@ -2267,9 +2248,9 @@ File = fopen(Filename, "wb"); if ( File ) { - pitch = this->field_10; - if ( this->field_10 & 1 ) - pitch = this->field_10 + 1; + pitch = this->GetRenderWidth(); + if ( pitch & 1 ) + pitch = pitch + 1; if ( this->pRenderD3D ) { memset(&Dst, 0, 0x7C); @@ -2285,9 +2266,9 @@ surface = pRenderer->pTargetSurface; v5 = pRenderer->uTargetSurfacePitch; } - header1.right = this->field_10 - 1; + header1.right = GetRenderWidth() - 1; header1.left = 0; - header1.bottom = this->field_14 - 1; + header1.bottom = this->GetRenderHeight() - 1; header1.up = 0; header2.pitch = pitch; memset(color_map, 0, sizeof(color_map)); @@ -2318,20 +2299,20 @@ fwrite(&header2.pitch, 2, 1, pOutFile); fwrite(&header2.palette_info, 2, 1, pOutFile); fwrite(v15, 0x3Au, 1, pOutFile); - lineRGB = (char *)malloc(3 * this->field_10 + 6); - if ( this->field_14 > 0 ) + lineRGB = (char *)malloc(3 * GetRenderWidth() + 6); + if ( this->GetRenderHeight() > 0 ) { image_width = 3 * pitch; //v24 = 2 * v5; v8 = (unsigned short *)surface; - for ( int y = 0; y < this->field_14; y++ ) + for ( int y = 0; y < this->GetRenderHeight(); y++ ) { line_picture_data = v8; - if ( this->field_10 > 0 ) + if ( GetRenderWidth() > 0 ) { lineG = (char *)lineRGB + pitch; lineB = (char *)lineRGB + 2 * pitch; - for ( uint x = 0; x < this->field_10; x++ ) + for ( uint x = 0; x < this->GetRenderWidth(); x++ ) { int p = *line_picture_data; //0x2818 int for_rad = (pRenderer->uTargetGBits + pRenderer->uTargetBBits );//16 = 8 + 8 @@ -2435,14 +2416,16 @@ if ( !this->pRenderD3D || this->using_software_screen_buffer ) { - ++dword_4EFA84; + static int _4EFA84_num_winners_certificates = 0; + ++_4EFA84_num_winners_certificates; + File = fopen(a1, "wb"); if ( File ) { - v25 = this->field_10; - pitch = this->field_10; - if ( this->field_10 & 1 ) - pitch = this->field_10 + 1; + v25 = this->GetRenderWidth(); + pitch = v25; + if ( pitch & 1 ) + pitch = pitch + 1; if ( this->pRenderD3D ) { memset(&Dst, 0, 0x7C); @@ -2458,9 +2441,9 @@ surface = pRenderer->pTargetSurface; v6 = pRenderer->uTargetSurfacePitch; } - v33 = this->field_10 - 1; + v33 = this->GetRenderWidth() - 1; v31 = 0; - v34 = (short)this->field_14 - 1; + v34 = (short)this->GetRenderHeight() - 1; v32 = 0; v39 = pitch; memset(&color_map, 0, sizeof(color_map)); @@ -2492,11 +2475,11 @@ fwrite(&v40, 2, 1, File); fwrite(&v16, 0x3A, 1, File); lineRGB = (char *)malloc(3 * (v25 + 2)); - if ( (signed int)this->field_14 > 0 ) + if ( (signed int)this->GetRenderHeight() > 0 ) { image_width = 3 * pitch; v9 = (unsigned short *)surface; - for ( uint j = 0; j < this->field_14; j++) + for ( uint j = 0; j < this->GetRenderHeight(); j++) { a1 = (const char *)v9; if ( v25 > 0 ) @@ -2543,7 +2526,6 @@ } } } -// 4EFA84: using guessed type int dword_4EFA84; //----- (0049F5A2) -------------------------------------------------------- void Render::PackPCXpicture( unsigned short* picture_data, int wight, int heidth, void *data_buff, int max_buff_size,unsigned int* packed_size ) @@ -2812,13 +2794,13 @@ //----- (0049FBCD) -------------------------------------------------------- void Render::ClearTarget(unsigned int uColor) { - if (pRenderD3D) + //if (pRenderD3D) { if (using_software_screen_buffer) pRenderD3D->ClearTarget(true, uColor, false, 0.0); } - else - memset32(pTargetSurface, uColor, field_10 * field_14 / 2); + //else + //memset32(pTargetSurface, uColor, field_10 * field_14 / 2); } //----- (0049FC23) -------------------------------------------------------- @@ -2877,7 +2859,7 @@ } //----- (0049FD3A) -------------------------------------------------------- -void Render::_49FD3A() +void Render::_49FD3A_fullscreen() { Render *v2; // esi@1 IDirectDrawSurface4 *v3; // eax@6 @@ -2942,7 +2924,7 @@ pRenderD3D->Present(0); pRenderD3D->ClearTarget(true, 0, false, 1.0); } - v1->pColorKeySurface4 = 0; + //v1->pColorKeySurface4 = 0; v1->pBackBuffer4 = 0; v1->pFrontBuffer4 = 0; v1->pDirectDraw4 = 0; @@ -3106,8 +3088,8 @@ if ( !pRenderer->uNumSceneBegins ) { - if ( pRenderer->using_software_screen_buffer ) - { + //if ( pRenderer->using_software_screen_buffer ) + //{ memset(&Dst, 0, 0x7Cu); Dst.dwSize = 124; if ( pRenderer->LockSurface_DDraw4(pRenderer->pBackBuffer4, &Dst, DDLOCK_WAIT) ) @@ -3238,18 +3220,10 @@ } }*/ } - } - } -} - - - - -//----- (0049FFD7) -------------------------------------------------------- -void Render::CreateSomeTexture() -{ - pRenderD3D->CreateTexture(64, 64, &pSurface, &pTexture, true, false, 32); -} + //} + } +} + //----- (0049FFFB) -------------------------------------------------------- bool Render::InitializeFullscreen() @@ -3286,7 +3260,7 @@ //v2 = this; this->using_software_screen_buffer = 0; - this->pColorKeySurface4 = 0; + //this->pColorKeySurface4 = 0; this->pBackBuffer4 = 0; this->pFrontBuffer4 = 0; this->pDirectDraw4 = 0; @@ -3314,14 +3288,12 @@ if ( v7[v6].bIsDeviceCompatible ) { v8 = pRenderD3D->CreateDevice(v6, /*0*/true, window); - uAcquiredDirect3DDevice = uDesiredDirect3DDevice; } else { if ( v7[1].bIsDeviceCompatible ) { v8 = pRenderD3D->CreateDevice(1, /*0*/true, window); - uAcquiredDirect3DDevice = 1; } else { @@ -3329,7 +3301,6 @@ Error("There aren't any D3D devices to create."); v8 = pRenderD3D->CreateDevice(0, /*0*/true, window); - uAcquiredDirect3DDevice = 1; } } if ( !v8 ) @@ -3360,7 +3331,7 @@ pRenderD3D->Release(); delete pRenderD3D; } - pColorKeySurface4 = 0; + //pColorKeySurface4 = 0; pRenderD3D = 0; pBackBuffer4 = 0; pFrontBuffer4 = 0; @@ -3380,7 +3351,7 @@ pDirectDraw4 = 0; Error("Direct3D renderer: The device doesn't support non-square textures."); } - LOBYTE(field_10365C) = ~(unsigned __int8)(v10 >> 6) & 1; + //LOBYTE(field_10365C) = ~(unsigned __int8)(v10 >> 6) & 1; bRequiredTextureStagesAvailable = CheckTextureStages(); memset(&halCaps, 0, 0xFCu); halCaps.dwSize = 252; @@ -3398,24 +3369,23 @@ uMaxDeviceTextureDim = v14; if ( (unsigned int)v13 < 4 ) uMinDeviceTextureDim = 4; - CreateSomeTexture(); v15 = 1; ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, true)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true)); - ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u)); + ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, false)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, false)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, false)); - ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1u)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2u)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2u)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 3u)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2u)); + ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, 1)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, 3)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, 2)); ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2)); ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0)); - ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u)); + ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4)); //} ddpfPrimarySuface.dwSize = 32; GetTargetPixelFormat(&ddpfPrimarySuface); @@ -3509,7 +3479,7 @@ pViewport->SetFOV(flt_6BE3A0 * 65536.0f); using_software_screen_buffer = 0; Release(); - pColorKeySurface4 = 0; + //pColorKeySurface4 = 0; pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; @@ -3544,7 +3514,6 @@ uDesiredDirect3DDevice != 1 ) { v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, true, window); - uAcquiredDirect3DDevice = uDesiredDirect3DDevice; } else { @@ -3552,13 +3521,12 @@ Error("There aren't any D3D devices to init."); v7 = pRenderD3D->CreateDevice(0, true, window); - uAcquiredDirect3DDevice = 0; } if ( !v7 ) Error("D3Drend->Init failed."); //v8 = pRenderD3D; - pColorKeySurface4 = 0; + //pColorKeySurface4 = 0; pBackBuffer4 = pRenderD3D->pBackBuffer; pFrontBuffer4 = pRenderD3D->pFrontBuffer; pDirectDraw4 = pRenderD3D->pHost; @@ -3583,14 +3551,14 @@ pRenderD3D->Release(); delete pRenderD3D; } - pColorKeySurface4 = 0; + //pColorKeySurface4 = 0; pRenderD3D = 0; pBackBuffer4 = 0; pFrontBuffer4 = 0; pDirectDraw4 = 0; Error("Direct3D renderer: The device doesn't support the necessary alpha blending modes."); } - if ( (v9 & 0x80u) != 0 ) + if (v9 & 0x80) { if (pRenderD3D) { @@ -3603,7 +3571,7 @@ pDirectDraw4 = 0; Error("Direct3D renderer: The device doesn't support non-square textures."); } - LOBYTE(field_10365C) = ~(unsigned __int8)(v9 >> 6) & 1; + //LOBYTE(field_10365C) = ~(unsigned __int8)(v9 >> 6) & 1; bRequiredTextureStagesAvailable = CheckTextureStages(); memset(&halCaps, 0, 0xFCu); halCaps.dwSize = 252; @@ -3619,7 +3587,6 @@ if ( (unsigned int)halCaps.dwMaxTextureWidth < halCaps.dwMaxTextureHeight ) v13 = halCaps.dwMaxTextureHeight; uMaxDeviceTextureDim = v13; - CreateSomeTexture(); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, 1u)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, 1u)); ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, 2u)); @@ -3715,6 +3682,26 @@ goto LABEL_45; } + +//----- (0044F2B2) -------------------------------------------------------- +bool Render::IsGammaSupported() +{ + bool result; // eax@3 + HRESULT v1; // eax@4 + + //if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) + { + DDCAPS halCaps; // [sp+0h] [bp-180h]@4 + memset(&halCaps, 0, sizeof(DDCAPS)); + halCaps.dwSize = sizeof(DDCAPS); + + ErrD3D(pDirectDraw4->GetCaps(&halCaps, 0)); + return (halCaps.dwCaps2 >> 17) & 1; + } + /*else + return false;*/ +} + //----- (004A0BEE) -------------------------------------------------------- void Render::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) { @@ -4194,7 +4181,7 @@ void Render::CreateDirectDrawPrimarySurface() { Render *v1; // esi@1 - int v2; // ebx@3 + //int v2; // ebx@3 IDirectDraw2 *v3; // eax@3 HRESULT v4; // eax@3 IDirectDrawSurface *pFrontBuffer; // eax@3 @@ -4216,8 +4203,8 @@ //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || //pVersion->pVersionInfo.dwMajorVersion != 4 ) { - v2 = 0; - this->field_4004C = 1; + //v2 = 0; + //this->field_4004C = 1; memset(&ddsd2, 0, 0x7Cu); v7 = v1->pDirectDraw4; ddsd2.dwBackBufferCount = 1; @@ -4258,8 +4245,8 @@ v17.dwCaps = 4; ErrD3D(pFrontBuffer->GetAttachedSurface((DDSCAPS *)&v17, ppBackBuffer));// hr = this->pFrontBuffer->GetAttachedSurface(&ddsCaps2, ppBackBuffer); //CheckHRESULT(&thisa, v11, (const char *)v10, v9, (unsigned int)ppBackBuffer); - v1->field_40030 = v2; - v1->field_18_locked_pitch = v2; + //v1->field_40030 = v2; + //v1->field_18_locked_pitch = v2; } //----- (004A14F4) -------------------------------------------------------- @@ -4518,7 +4505,7 @@ { if (!uNumD3DSceneBegins++) { - if (pRenderD3D) + //if (pRenderD3D) { pRenderD3D->ClearTarget(true, 0x00F08020, true, 1.0); pRenderer->uNumBillboardsToDraw = 0; @@ -4542,14 +4529,14 @@ bUsingSpecular = 0; } } - else + /*else { LockRenderSurface((void **)&pTargetSurface, &uTargetSurfacePitch); if (pTargetSurface) field_18_locked_pitch = uTargetSurfacePitch; else --uNumD3DSceneBegins; - } + }*/ } } @@ -6469,10 +6456,10 @@ if ( !this->pTargetSurface ) { LockRenderSurface((void **)&this->pTargetSurface, &this->uTargetSurfacePitch); - if ( this->pTargetSurface ) + /*if ( this->pTargetSurface ) { this->field_18_locked_pitch = this->uTargetSurfacePitch; - } + }*/ --this->uNumSceneBegins; } } @@ -6502,7 +6489,7 @@ { this->pTargetSurface = 0; this->uTargetSurfacePitch = 0; - this->field_18_locked_pitch = 0; + //this->field_18_locked_pitch = 0; UnlockBackBuffer(); } } @@ -8351,7 +8338,7 @@ ModalWindow(pGlobalTXT_LocalizationStrings[62], UIMSG_0);// "Might and Magic VII requires your desktop to be in 16bit (32k or 65k) Color mode in order to operate in a window." return; }*/ - if ( pRenderer->bWindowMode || !pRenderer->pRenderD3D || pRenderer->pRenderD3D->pAvailableDevices->bIsDeviceCompatible ) + if ( pRenderer->bWindowMode || pRenderer->pRenderD3D->pAvailableDevices->bIsDeviceCompatible ) { if ( pEventTimer->bPaused ) dword_6BE364_game_settings_1 |= GAME_SETTINGS_0800; @@ -9239,4 +9226,172 @@ return true; } return false; -} \ No newline at end of file +} + + +//----- (0045E03A) -------------------------------------------------------- +unsigned short *Render::MakeScreenshot(signed int width, signed int height) +{ + unsigned __int16 *v3; // ebx@1 + int v4; // edx@7 + unsigned __int8 v5; // cf@9 + unsigned int v6; // ecx@9 + unsigned __int16 *v7; // edi@9 + int j; // ecx@9 + unsigned int screen_x; // qax@18 + HRESULT v14; // eax@21 + int v15; // edi@29 + signed __int64 v16; // qax@30 + signed int v17; // edx@34 + unsigned __int16 *v18; // edi@36 + int k; // ecx@36 + DDSURFACEDESC2 Dst; // [sp+4h] [bp-A0h]@6 + unsigned __int16 *pPixels; // [sp+80h] [bp-24h]@1 + float interval_x; // [sp+84h] [bp-20h]@1 + unsigned __int16 *_this; // [sp+88h] [bp-1Ch]@21 + float interval_y; // [sp+8Ch] [bp-18h]@1 + unsigned int screen_y; // [sp+90h] [bp-14h]@17 + int v28; // [sp+98h] [bp-Ch]@16 + int v29; // [sp+9Ch] [bp-8h]@15 + + interval_x = game_viewport_width / (double)width; + interval_y = game_viewport_height / (double)height; + + pPixels = (unsigned __int16 *)malloc(2 * height * width); + memset(pPixels, 0 , 2 * height * width); + + v3 = pPixels; + + BeginSceneD3D(); + + if (uCurrentlyLoadedLevelType == LEVEL_Indoor) + pIndoor->Draw(); + else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) + pOutdoor->Draw(); + + DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene(); + memset(&Dst, 0, 0x7C); + Dst.dwSize = sizeof(Dst); + + if ( LockSurface_DDraw4(pBackBuffer4, &Dst, DDLOCK_WAIT) ) + { + for (uint y = 0; y < height; ++y) + { + for (uint x = 0; x < width; ++x) + { + //*v3 = pRenderer->ReadPixel16((int)(x* interval_x + 8.0), (int)(y * interval_y + 8.0));//screen_data[screen_y + (int)(x* interval_x + 8.0)]; + + if (Dst.ddpfPixelFormat.dwRGBBitCount == 32) + { + auto p = (unsigned __int32 *)Dst.lpSurface + (int)(x * interval_x + 8.0) + y/* (int)(y * interval_y + 8.0)*/ * Dst.lPitch; + *v3 = Color16((*p >> 16) & 255, (*p >> 8) & 255, *p & 255); + } + else if (Dst.ddpfPixelFormat.dwRGBBitCount == 16) + { + auto p = (unsigned __int16 *)Dst.lpSurface + (int)(x * interval_x + 8.0) + y * Dst.lPitch; + *v3 = *p; + } + else __debugbreak(); + ++v3; + } + } + ErrD3D(pBackBuffer4->Unlock(0)); + } + else + { + __debugbreak(); // unrefactored - black screenshot + v4 = height; + if ( height > 0 ) + { + do + { + if ( width > 0 ) + { + v5 = width & 1; + v6 = (unsigned int)width >> 1; + memset(v3, 0, 4 * ((unsigned int)width >> 1)); + v7 = &v3[2 * v6]; + for ( j = v5; j; --j ) + { + *v7 = 0; + ++v7; + } + v3 += width; + } + --v4; + } + while ( v4 ); + } + } + + + /*if (!pRenderer->pRenderD3D) + { + pRenderer->BeginScene(); + if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) + { + pIndoor->Draw(); + } + else + { + if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor ) + pOutdoor->Draw(); + } + _this = pRenderer->pTargetSurface; + v26 = pRenderer->uTargetSurfacePitch; + if ( pRenderer->pTargetSurface ) + { + if ( height > 0 ) + { + for ( v29 = 0; v29 < height; ++v29 ) + { + if ( width > 0 ) + { + v15 = v26 * (unsigned __int64)(signed __int64)((double)v29 * v25 + 8.0); + for ( v28 = 0; v28 < width; v28++ ) + { + *v3 = _this[v15 + (int)(signed __int64)((double)v28 * v23 + 8.0)]; + ++v3; + } + } + } + } + } + else + { + if ( height > 0 ) + { + for ( v17 = height; v17; --v17 ) + { + if ( width > 0 ) + { + memset(v3, 0, 4 * ((unsigned int)width >> 1)); + v18 = &v3[2 * ((unsigned int)width >> 1)]; + for ( k = width & 1; k; --k ) + { + *v18 = 0; + ++v18; + } + v3 += width; + } + } + } + } + pRenderer->EndScene(); + }*/ + return pPixels; +} +//----- (0045E26C) -------------------------------------------------------- +void Render::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) +{ + auto pixels = pRenderer->MakeScreenshot(width, height); + pRenderer->SavePCXImage(pFilename, pixels, width, height); + free(pixels); +} + +void Render::PackScreenshot(unsigned int width, unsigned int height, void *data, unsigned int data_size, unsigned int *out_screenshot_size) +{ + auto pixels = pRenderer->MakeScreenshot(150, 112); + pRenderer->PackPCXpicture(pixels, 150, 112, data, 1000000, out_screenshot_size); + free(pixels); +}