comparison Render.cpp @ 2153:d28d3c006077

Some Render decoupling.
author Nomad
date Thu, 09 Jan 2014 02:34:20 +0200
parents d44b7775fc06
children 9bd7522cdbbb
comparison
equal deleted inserted replaced
2152:d44b7775fc06 2153:d28d3c006077
1 #ifdef _MSC_VER 1 #include "Render.h"
2 #define _CRT_SECURE_NO_WARNINGS
3 #endif
4
5 #include "Outdoor_stuff.h" 2 #include "Outdoor_stuff.h"
6 #include "VideoPlayer.h" 3 #include "VideoPlayer.h"
7 #include "Sprites.h" 4 #include "Sprites.h"
8 #include "Mouse.h" 5 #include "Mouse.h"
9 #include "GammaControl.h" 6 #include "GammaControl.h"
10 #include "stru6.h" 7 #include "stru6.h"
11 #include "GUIWindow.h" 8 #include "GUIWindow.h"
12 #include "DecalBuilder.h" 9 #include "DecalBuilder.h"
13 #include "ParticleEngine.h" 10 #include "ParticleEngine.h"
14 #include "Render.h"
15 #include "Outdoor.h" 11 #include "Outdoor.h"
16 #include "Party.h" 12 #include "Party.h"
17 #include "LOD.h" 13 #include "LOD.h"
18 #include "Viewport.h" 14 #include "Viewport.h"
19 #include "OurMath.h" 15 #include "OurMath.h"
47 RenderVertexSoft array_507D30[50]; 43 RenderVertexSoft array_507D30[50];
48 RenderVertexSoft array_50AC10[50]; 44 RenderVertexSoft array_50AC10[50];
49 RenderVertexSoft array_73D150[20]; 45 RenderVertexSoft array_73D150[20];
50 46
51 RenderVertexD3D3 d3d_vertex_buffer[50]; 47 RenderVertexD3D3 d3d_vertex_buffer[50];
52
53 void SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1);
54 48
55 /* 384 */ 49 /* 384 */
56 #pragma pack(push, 1) 50 #pragma pack(push, 1)
57 struct PCXHeader_1 51 struct PCXHeader_1
58 { 52 {
404 398
405 assert(v6 < 1000); // many random crashes here 399 assert(v6 < 1000); // many random crashes here
406 400
407 // for all shore tiles - draw a tile water under them since they're half-empty 401 // for all shore tiles - draw a tile water under them since they're half-empty
408 if (!_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX 402 if (!_strnicmp(pBitmaps_LOD->pTextures[pTilePolygon->uTileBitmapID].pName, "wtrdr", 5)) // all shore tile filenames are wtrdrXXX
409 pTilePolygon->DrawBorderTiles(); 403 DrawBorderTiles(pTilePolygon);
410 404
411 pRenderer->DrawTerrainPolygon(pTilePolygon->uNumVertices, pTilePolygon, pBitmaps_LOD->pHardwareTextures[v6], transparent, true); 405 pRenderer->DrawTerrainPolygon(pTilePolygon->uNumVertices, pTilePolygon, pBitmaps_LOD->pHardwareTextures[v6], transparent, true);
412 } 406 }
413 //else //здесь уже пограничные тайлы воды 407 //else //здесь уже пограничные тайлы воды
414 //pTile->DrawBorderTiles(); 408 //pTile->DrawBorderTiles();
418 --pODMRenderParams->field_44; 412 --pODMRenderParams->field_44;
419 } 413 }
420 } 414 }
421 } 415 }
422 416
417
418 //----- (004811A3) --------------------------------------------------------
419 void Render::DrawBorderTiles(struct Polygon *poly)
420 {
421 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, false);
422 DrawTerrainPolygon(poly->uNumVertices, poly,
423 pBitmaps_LOD->pHardwareTextures[pHDWaterBitmapIDs[hd_water_current_frame]], false, true);
424
425 pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, true);
426 //DrawTerrainPolygon(poly->uNumVertices, poly, pBitmaps_LOD->pHardwareTextures[poly->uTileBitmapID], true, true);
427 }
423 428
424 429
425 //----- (0047BACF) -------------------------------------------------------- 430 //----- (0047BACF) --------------------------------------------------------
426 void Render::TransformBillboardsAndSetPalettesODM() 431 void Render::TransformBillboardsAndSetPalettesODM()
427 { 432 {
2154 v1->bClip = 1; 2159 v1->bClip = 1;
2155 //v1->bColorKeySupported = 0; 2160 //v1->bColorKeySupported = 0;
2156 v1->bRequiredTextureStagesAvailable = 0; 2161 v1->bRequiredTextureStagesAvailable = 0;
2157 v1->bTinting = 1; 2162 v1->bTinting = 1;
2158 LOBYTE(v1->field_103668) = 0; 2163 LOBYTE(v1->field_103668) = 0;
2159 v1->field_1036B8 = 0;
2160 v1->_gpu_memory_used = 0;
2161 uNumBillboardsToDraw = 0; 2164 uNumBillboardsToDraw = 0;
2162 bFogEnabled = false; 2165 bFogEnabled = false;
2163 2166
2164 hd_water_tile_id = -1; 2167 hd_water_tile_id = -1;
2165 hd_water_current_frame = 0; 2168 hd_water_current_frame = 0;
6391 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-7Ch]@4 6394 DDSURFACEDESC2 Dst; // [sp+Ch] [bp-7Ch]@4
6392 6395
6393 sprite_texture = pD3DSprites.LoadTexture(pSprite->pName, pSprite->uPaletteID); 6396 sprite_texture = pD3DSprites.LoadTexture(pSprite->pName, pSprite->uPaletteID);
6394 if ( sprite_texture ) 6397 if ( sprite_texture )
6395 { 6398 {
6396 _gpu_memory_used += 2 * sprite_texture->uWidth * sprite_texture->uHeight;
6397 pSprite->uAreaX = sprite_texture->uAreaX; 6399 pSprite->uAreaX = sprite_texture->uAreaX;
6398 pSprite->uAreaY = sprite_texture->uAreaY; 6400 pSprite->uAreaY = sprite_texture->uAreaY;
6399 pSprite->uBufferWidth = sprite_texture->uBufferWidth; 6401 pSprite->uBufferWidth = sprite_texture->uBufferWidth;
6400 pSprite->uBufferHeight = sprite_texture->uBufferHeight; 6402 pSprite->uBufferHeight = sprite_texture->uBufferHeight;
6401 pSprite->uAreaWidth = sprite_texture->uAreaWidth; 6403 pSprite->uAreaWidth = sprite_texture->uAreaWidth;
8654 8656
8655 return true; 8657 return true;
8656 } 8658 }
8657 8659
8658 //----- (004A1C1E) -------------------------------------------------------- 8660 //----- (004A1C1E) --------------------------------------------------------
8659 void DoRenderBillboards_D3D() 8661 void Render::DoRenderBillboards_D3D()
8660 { 8662 {
8661 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); 8663 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
8662 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); 8664 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
8663 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); 8665 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
8664 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); 8666 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
8665 8667
8666 /*if (pRenderer->uNumBillboardsToDraw) 8668 /*if (pRenderer->uNumBillboardsToDraw)
8667 { 8669 {
8668 auto p = &pRenderer->pBillboardRenderListD3D[0]; 8670 auto p = &pRenderer->pBillboardRenderListD3D[0];
8669 for (int i = 0; i < p->uNumVertices; ++i) 8671 for (int i = 0; i < p->uNumVertices; ++i)
8692 p->pQuads, p->uNumVertices, 8694 p->pQuads, p->uNumVertices,
8693 D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS)); 8695 D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS));
8694 8696
8695 }*/ 8697 }*/
8696 8698
8697 for (int i = pRenderer->uNumBillboardsToDraw - 1; i >= 0; --i) 8699 for (int i = uNumBillboardsToDraw - 1; i >= 0; --i)
8698 { 8700 {
8699 if((int)pRenderer->pBillboardRenderListD3D[i].pTexture == 0xcdcdcdcd) 8701 if (pBillboardRenderListD3D[i].uOpacity != RenderBillboardD3D::NoBlend)
8700 __debugbreak();//Ritor1: error 8702 SetBillboardBlendOptions(pBillboardRenderListD3D[i].uOpacity);
8701 if (pRenderer->pBillboardRenderListD3D[i].uOpacity != RenderBillboardD3D::NoBlend)
8702 SetBillboardBlendOptions(pRenderer->pBillboardRenderListD3D[i].uOpacity);
8703 8703
8704 8704
8705 pRenderer->pRenderD3D->pDevice->SetTexture(0, pRenderer->pBillboardRenderListD3D[i].pTexture); 8705 pRenderD3D->pDevice->SetTexture(0, pBillboardRenderListD3D[i].pTexture);
8706 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 8706 ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
8707 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, 8707 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
8708 pRenderer->pBillboardRenderListD3D[i].pQuads, pRenderer->pBillboardRenderListD3D[i].uNumVertices, 8708 pBillboardRenderListD3D[i].pQuads, pBillboardRenderListD3D[i].uNumVertices,
8709 D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS)); 8709 D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS));
8710 } 8710 }
8711 8711
8712 if (pRenderer->bFogEnabled) 8712 if (bFogEnabled)
8713 { 8713 {
8714 pRenderer->bFogEnabled = false; 8714 bFogEnabled = false;
8715 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); 8715 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
8716 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF)); 8716 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
8717 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); 8717 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
8718 } 8718 }
8719 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW)); 8719 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
8720 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); 8720 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
8721 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); 8721 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
8722 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 8722 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
8723 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); 8723 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
8724 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); 8724 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
8725 } 8725 }
8726 8726
8727 //----- (004A1DA8) -------------------------------------------------------- 8727 //----- (004A1DA8) --------------------------------------------------------
8728 void SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1) 8728 void Render::SetBillboardBlendOptions(RenderBillboardD3D::OpacityType a1)
8729 { 8729 {
8730 switch (a1) 8730 switch (a1)
8731 { 8731 {
8732 case RenderBillboardD3D::Transparent: 8732 case RenderBillboardD3D::Transparent:
8733 { 8733 {
8734 if (pRenderer->bFogEnabled) 8734 if (bFogEnabled)
8735 { 8735 {
8736 pRenderer->bFogEnabled = false; 8736 bFogEnabled = false;
8737 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); 8737 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE));
8738 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF)); 8738 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, GetLevelFogColor() & 0xFFFFFF));
8739 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0)); 8739 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0));
8740 } 8740 }
8741 8741
8742 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA)); 8742 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA));
8743 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA)); 8743 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA));
8744 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE)); 8744 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
8745 } 8745 }
8746 break; 8746 break;
8747 8747
8748 case RenderBillboardD3D::Opaque_1: 8748 case RenderBillboardD3D::Opaque_1:
8749 case RenderBillboardD3D::Opaque_2: 8749 case RenderBillboardD3D::Opaque_2:
8750 case RenderBillboardD3D::Opaque_3: 8750 case RenderBillboardD3D::Opaque_3:
8751 { 8751 {
8752 if (pRenderer->bUsingSpecular) 8752 if (bUsingSpecular)
8753 { 8753 {
8754 if (!pRenderer->bFogEnabled) 8754 if (!bFogEnabled)
8755 { 8755 {
8756 pRenderer->bFogEnabled = true; 8756 bFogEnabled = true;
8757 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); 8757 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE));
8758 } 8758 }
8759 } 8759 }
8760 8760
8761 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); 8761 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
8762 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); 8762 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
8763 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); 8763 ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
8764 } 8764 }
8765 break; 8765 break;
8766 8766
8767 default: 8767 default:
8768 Log::Warning(L"SetBillboardBlendOptions: invalid opacity type (%u)", a1); 8768 Log::Warning(L"SetBillboardBlendOptions: invalid opacity type (%u)", a1);