Path: blob/master/RSDKv5/RSDK/Graphics/DX11/DX11RenderDevice.hpp
1168 views
const auto _wapiShowCursor = ShowCursor;1const auto _wapiGetCursorPos = GetCursorPos;23class RenderDevice : public RenderDeviceBase4{5public:6struct WindowInfo {7union {8struct {9UINT width;10UINT height;11DXGI_RATIONAL refresh_rate;12};13DXGI_MODE_DESC internal;14} * displays;15D3D11_VIEWPORT viewport;16};17static WindowInfo displayInfo;1819static bool Init();20static void CopyFrameBuffer();21static void FlipScreen();22static void Release(bool32 isRefresh);2324static void RefreshWindow();25static void GetWindowSize(int32 *width, int32 *height);2627static void SetupImageTexture(int32 width, int32 height, uint8 *imagePixels);28static void SetupVideoTexture_YUV420(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,29int32 strideV);30static void SetupVideoTexture_YUV422(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,31int32 strideV);32static void SetupVideoTexture_YUV444(int32 width, int32 height, uint8 *yPlane, uint8 *uPlane, uint8 *vPlane, int32 strideY, int32 strideU,33int32 strideV);3435static bool ProcessEvents();3637static void InitFPSCap();38static bool CheckFPSCap();39static void UpdateFPSCap();4041static bool InitShaders();42static void LoadShader(const char *fileName, bool32 linear);4344inline static void ShowCursor(bool32 shown)45{46if (shown) {47while (_wapiShowCursor(true) < 0)48;49}50else {51while (_wapiShowCursor(false) >= 0)52;53}54}5556inline static bool GetCursorPos(Vector2 *pos)57{58POINT cursorPos{};59_wapiGetCursorPos(&cursorPos);60ScreenToClient(windowHandle, &cursorPos);61pos->x = cursorPos.x;62pos->y = cursorPos.y;63return true;64}6566inline static void SetWindowTitle()67{68#if _UNICODE69// shoddy workaround to get the title into wide chars in UNICODE mode70std::string str = gameVerInfo.gameTitle;71std::wstring temp = std::wstring(str.begin(), str.end());72LPCWSTR gameTitle = temp.c_str();73#else74std::string str = gameVerInfo.gameTitle;75LPCSTR gameTitle = str.c_str();76#endif7778SetWindowText(windowHandle, gameTitle);79}8081static HWND windowHandle;82static ID3D11Texture2D *imageTexture;8384static ID3D11DeviceContext *dx11Context;85static ID3D11Device *dx11Device;8687static UINT dxAdapter;88static int32 adapterCount;8990// WinMain args91static HINSTANCE hInstance;92static HINSTANCE hPrevInstance;93static INT nShowCmd;9495private:96static bool SetupRendering();97static void InitVertexBuffer();98static bool InitGraphicsAPI();99static bool LoadBackupShader();100101static void GetDisplays();102103inline static std::vector<IDXGIAdapter *> GetAdapterList()104{105std::vector<IDXGIAdapter *> adapterList;106107IDXGIFactory *dxgiFactory = nullptr;108HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&dxgiFactory);109if (FAILED(hr))110return adapterList;111112IDXGIAdapter *pAdapter;113for (UINT i = 0; dxgiFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++i) adapterList.push_back(pAdapter);114dxgiFactory->Release();115116return adapterList;117}118119static void ProcessEvent(MSG msg);120static LRESULT CALLBACK WindowEventCallback(HWND hRecipient, UINT message, WPARAM wParam, LPARAM lParam);121122static bool useFrequency;123124static LARGE_INTEGER performanceCount, frequency, initialFrequency, curFrequency;125126static HDEVNOTIFY deviceNotif;127static PAINTSTRUCT Paint;128129static ID3D11Buffer *dx11VertexBuffer;130static ID3D11Texture2D *screenTextures[SCREEN_COUNT];131static ID3D11ShaderResourceView *screenTextureViews[SCREEN_COUNT];132static ID3D11ShaderResourceView *imageTextureView;133static D3D11_VIEWPORT dx11ViewPort;134135static IDXGISwapChain *swapChain;136static ID3D11RenderTargetView *renderView;137138static ID3D11RasterizerState *rasterState;139static ID3D11SamplerState *samplerPoint;140static ID3D11SamplerState *samplerLinear;141142static ID3D11Buffer *psConstBuffer;143144static D3D_DRIVER_TYPE driverType;145static D3D_FEATURE_LEVEL featureLevel;146147static RECT monitorDisplayRect;148static LUID deviceIdentifier;149};150151struct ShaderEntry : public ShaderEntryBase {152ID3D11VertexShader *vertexShaderObject;153ID3D11PixelShader *pixelShaderObject;154155ID3D11InputLayout *vertexDeclare;156};157158159