From 4f6cbd58bb31b6aa240f01c357208c11fbcf649d Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 19 Mar 2022 12:40:57 +0300 Subject: [PATCH 1/2] remove unused CreateTextureFromFileInMemory --- src/libs/common/include/dx9render.h | 2 -- src/libs/renderer/src/s_device.cpp | 15 --------------- src/libs/renderer/src/s_device.h | 2 -- 3 files changed, 19 deletions(-) diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 52fe5eda2..36972208e 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -298,8 +298,6 @@ class VDX9RENDER : public SERVICE virtual void SetLoadTextureEnable(bool bEnable = true) = 0; virtual IDirect3DBaseTexture9 *GetBaseTexture(int32_t iTexture) = 0; - virtual IDirect3DBaseTexture9 *CreateTextureFromFileInMemory(const char *pFile, uint32_t dwSize) = 0; - virtual bool PushRenderTarget() = 0; virtual bool PopRenderTarget() = 0; virtual bool SetRenderTarget(IDirect3DCubeTexture9 *pCubeTex, uint32_t dwFaceType, uint32_t dwLevel, diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 66a16450a..9c825a97e 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -4470,21 +4470,6 @@ void DX9RENDER::SetLoadTextureEnable(bool bEnable) bLoadTextureEnabled = bEnable; } -IDirect3DBaseTexture9 *DX9RENDER::CreateTextureFromFileInMemory(const char *pFile, uint32_t dwSize) -{ - if (!pFile || !dwSize) - return nullptr; - - IDirect3DTexture9 *pTexture = nullptr; - auto *pTga = (TGA_H *)pFile; - const D3DFORMAT d3dFormat = (pTga->bpp == 16) ? D3DFMT_DXT1 : D3DFMT_DXT3; - D3DXCreateTextureFromFileInMemoryEx(static_cast(GetD3DDevice()), pFile, dwSize, D3DX_DEFAULT, - D3DX_DEFAULT, 1, 0, d3dFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, - nullptr, nullptr, &pTexture); - - return pTexture; -} - IDirect3DVolumeTexture9 *DX9RENDER::CreateVolumeTexture(uint32_t Width, uint32_t Height, uint32_t Depth, uint32_t Levels, uint32_t Usage, D3DFORMAT Format, D3DPOOL Pool) { diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index 3ce9e7ed4..7e9599d63 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -409,8 +409,6 @@ class DX9RENDER : public VDX9RENDER const char *pTechniqueName = "DXVector") override; IDirect3DBaseTexture9 *GetBaseTexture(int32_t iTexture) override; - IDirect3DBaseTexture9 *CreateTextureFromFileInMemory(const char *pFile, uint32_t dwSize) override; - bool PushRenderTarget() override; bool PopRenderTarget() override; bool SetRenderTarget(IDirect3DCubeTexture9 *pCubeTex, uint32_t dwFaceType, uint32_t dwLevel, From 58fcb2924b2ee5c66715e960b516f9879edd4c91 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 19 Mar 2022 13:13:35 +0300 Subject: [PATCH 2/2] remove unused screenshot.cpp bVideoCapture will never become true and functions in screenshot.cpp can be called if bVideoCapture == true --- src/libs/renderer/src/s_device.cpp | 29 ----------- src/libs/renderer/src/s_device.h | 15 ------ src/libs/renderer/src/screenshot.cpp | 76 ---------------------------- 3 files changed, 120 deletions(-) delete mode 100644 src/libs/renderer/src/screenshot.cpp diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 9c825a97e..dd756e75b 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -463,10 +463,6 @@ DX9RENDER::DX9RENDER() progressFramesCountX = 8; progressFramesCountY = 8; - bVideoCapture = false; - bPreparedCapture = false; - iCaptureFrameIndex = 0; - vViewRelationPos = CVECTOR(0.f, 0.f, 0.f); vWordRelationPos = -vViewRelationPos; bUseLargeBackBuffer = false; @@ -610,14 +606,6 @@ bool DX9RENDER::Init() if (progressFramesCountY > 64) progressFramesCountY = 64; - // videocapture section - fFixedFPS = ini->GetFloat("VideoCapture", "FPS", 25); - if (fFixedFPS == 0.0f) - fFixedFPS = 25.0f; - const int32_t iCapBuffers = ini->GetInt("VideoCapture", "Buffers", 0); - for (int32_t i = 0; i < iCapBuffers; i++) - aCaptureBuffers.push_back(new char[sizeof(uint32_t) * screen_size.x * screen_size.y]); - CreateSphere(); auto *pScriptRender = static_cast(core.GetScriptVariable("Render")); ATTRIBUTES *pARender = pScriptRender->GetAClass(); @@ -638,8 +626,6 @@ bool DX9RENDER::Init() return false; } - dwCaptureBuffersReady = 0; - uint16_t *pI = &qi[0]; // setup ibuffer for (int32_t y = 0; y < 31; y++) @@ -699,18 +685,6 @@ DX9RENDER::~DX9RENDER() STORM_DELETE(DX9sphereVertex); ReleaseDevice(); - - if (bPreparedCapture) - { - STORM_DELETE(lpbi); - ReleaseDC(static_cast(core.GetAppHWND()), hDesktopDC); - DeleteDC(hCaptureDC); - DeleteObject(hCaptureBitmap); - } - for (const auto &buffer : aCaptureBuffers) - delete buffer; - - // aCaptureBuffers.DelAllWithPointers(); } bool DX9RENDER::InitDevice(bool windowed, HWND _hwnd, int32_t width, int32_t height) @@ -1293,9 +1267,6 @@ bool DX9RENDER::DX9EndScene() if (bMakeShoot) MakeScreenShot(); - if (bVideoCapture) - MakeCapture(); - const HRESULT hRes = d3d9->Present(nullptr, nullptr, nullptr, nullptr); if (hRes == D3DERR_DEVICELOST) diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index 7e9599d63..d0f1bdc52 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -483,17 +483,6 @@ class DX9RENDER : public VDX9RENDER bool MakeAvi; IDirect3DSurface9 *ImageBuffer; - // VideoCapture section - HDC hDesktopDC, hCaptureDC; - HBITMAP hCaptureBitmap; - LPBITMAPINFO lpbi; - int32_t iCaptureFrameIndex; - bool bPreparedCapture; - bool bVideoCapture; - float fFixedFPS; - std::vector aCaptureBuffers; - uint32_t dwCaptureBuffersReady; - //-------- post process struct QuadVertex @@ -596,8 +585,4 @@ class DX9RENDER : public VDX9RENDER bool TextureLoad(int32_t texid); bool TextureLoadUsingD3DX(const char *path, int32_t texid); - - bool MakeCapture(); - void SaveCaptureBuffers(); - void PrepareCapture(); }; diff --git a/src/libs/renderer/src/screenshot.cpp b/src/libs/renderer/src/screenshot.cpp deleted file mode 100644 index 2a7506aaf..000000000 --- a/src/libs/renderer/src/screenshot.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include "core.h" -#include "s_device.h" -#include "tga.h" - -void DX9RENDER::PrepareCapture() -{ - hDesktopDC = GetDC(static_cast(core.GetAppHWND())); - hCaptureDC = CreateCompatibleDC(hDesktopDC); - hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, screen_size.x, screen_size.y); - - auto *const OldBmp = static_cast(SelectObject(hCaptureDC, hCaptureBitmap)); - lpbi = (LPBITMAPINFO)(new char[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]); - PZERO(lpbi, sizeof(BITMAPINFO)); - lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - SelectObject(hCaptureDC, OldBmp); - GetDIBits(hCaptureDC, hCaptureBitmap, 0, screen_size.y, nullptr, lpbi, DIB_RGB_COLORS); - - bPreparedCapture = true; -} - -void DX9RENDER::SaveCaptureBuffers() -{ - uint32_t Written; - char cFileName[256]; - - int32_t fi; - for (fi = iCaptureFrameIndex; fi < iCaptureFrameIndex + 10000; fi++) - { - sprintf_s(cFileName, "k3cap_%04d.tga", fi); - if (!fio->_FileOrDirectoryExists(cFileName)) - break; - } - - for (uint32_t i = 0; i < dwCaptureBuffersReady; i++) - { - TGA_H TgaHead = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32}; - TgaHead.width = static_cast(screen_size.x); - TgaHead.height = static_cast(screen_size.y); - sprintf_s(cFileName, "k3cap_%04d.tga", fi + i); - auto fileS = fio->_CreateFile(cFileName, std::ios::binary | std::ios::out); - fio->_WriteFile(fileS, &TgaHead, sizeof(TGA_H)); - fio->_WriteFile(fileS, aCaptureBuffers[i], screen_size.x * screen_size.y * sizeof(uint32_t)); - fio->_CloseFile(fileS); - } - - iCaptureFrameIndex = fi + dwCaptureBuffersReady + 1; - - _flushall(); - dwCaptureBuffersReady = 0; -} - -bool DX9RENDER::MakeCapture() -{ - if (aCaptureBuffers.empty()) - return false; - - if (!bPreparedCapture) - PrepareCapture(); - - if (dwCaptureBuffersReady >= aCaptureBuffers.size()) - { - Beep(1000, 150); - SaveCaptureBuffers(); - Beep(5000, 150); - } - - auto *const OldBmp = static_cast(SelectObject(hCaptureDC, hCaptureBitmap)); - BitBlt(hCaptureDC, 0, 0, screen_size.x, screen_size.y, hDesktopDC, 0, 0, SRCCOPY); - SelectObject(hCaptureDC, OldBmp); - GetDIBits(hCaptureDC, hCaptureBitmap, 0, screen_size.y, aCaptureBuffers[dwCaptureBuffersReady], lpbi, - DIB_RGB_COLORS); - dwCaptureBuffersReady++; - return true; -}