|
OpenTTD Source 20261112-master-gbcbec5e63f
|
The D3D11 video driver for windows. More...
Public Member Functions | |
| VideoDriver_Win32D3D11 () | |
| Constructor for the D3D11 video driver. | |
| std::optional< std::string_view > | Start (const StringList ¶m) override |
| Start this driver. | |
| void | Stop () override |
| Stop this driver. | |
| bool | ChangeResolution (int w, int h) override |
| Change the resolution of the window. | |
| bool | ToggleFullscreen (bool fullscreen) override |
| Change the full screen setting. | |
| bool | AfterBlitterChange () override |
| Callback invoked after the blitter was changed. | |
| bool | HasEfficient8Bpp () const override |
| Has this video driver an efficient code path for palette animated 8-bpp sprites? | |
| bool | UseSystemCursor () override |
| Get whether the mouse cursor is drawn by the video driver. | |
| std::string_view | GetName () const override |
| Get the name of this driver. | |
| std::string_view | GetInfoString () const override |
| Get some information about the selected driver/backend to be shown to the user. | |
| Public Member Functions inherited from VideoDriver_Win32Base | |
| VideoDriver_Win32Base (bool uses_hardware_acceleration=false, bool supports_animation_buffer=false) | |
| Create the video driver. | |
| void | MakeDirty (int left, int top, int width, int height) override |
| Mark a particular area dirty. | |
| void | MainLoop () override |
| Perform the actual drawing. | |
| void | ClaimMousePointer () override |
| Claim the exclusive rights for the mouse pointer. | |
| void | EditBoxLostFocus () override |
| An edit box lost the input focus. | |
| std::vector< int > | GetListOfMonitorRefreshRates () override |
| Get a list of refresh rates of each available monitor. | |
| Public Member Functions inherited from VideoDriver | |
| VideoDriver (bool uses_hardware_acceleration=false, bool supports_animation_buffer=false) | |
| Create the video driver. | |
| virtual void | ToggleVsync (bool vsync) |
| Change the vsync setting. | |
| virtual void | PopulateSystemSprites () |
| Populate all sprites in cache. | |
| virtual void | ClearSystemSprites () |
| Clear all cached sprites. | |
| virtual bool | HasGUI () const |
| Whether the driver has a graphical user interface with the end user. | |
| constexpr bool | SupportsAnimationBuffer () const |
| Does this video driver support a separate animation buffer in addition to the colour buffer? | |
| constexpr uint8_t * | GetAnimBuffer () const |
| Get a pointer to the animation buffer of the video back-end. | |
| constexpr int | GetAnimBufferPitch () const |
| Get the animation buffer pitch in uint8_t elements per row. | |
| virtual void | EditBoxGainedFocus () |
| An edit box gained the input focus. | |
| void | QueueOnMainThread (std::function< void()> &&func) |
| Queue a function to be called on the main thread with game state lock held and video buffer locked. | |
| void | GameLoopPause () |
| Pause the game-loop for a bit, releasing the game-state lock. | |
| virtual void | SetScreensaverInhibited (bool inhibited) |
| Prevents the system from going to sleep. | |
| Public Member Functions inherited from Driver | |
| virtual | ~Driver ()=default |
| Ensure the destructor of the sub classes are called as well. | |
Protected Member Functions | |
| bool | MinimiseRestoreWithToggleFullscreen () const override |
| Whether minimising and restoring fullscreen windows uses ToggleFullscreen. | |
| uint8_t | GetFullscreenBpp () override |
| Colour depth to use for fullscreen display modes. | |
| void | Paint () override |
| Paint the window. | |
| bool | AllocateBackingStore (int w, int h, bool force=false) override |
| (Re-)create the backing store. | |
| void * | GetVideoPointer () override |
| Get a pointer to the video buffer. | |
| void | ReleaseVideoPointer () override |
| Hand video buffer back to the painting backend. | |
| void | PaletteChanged (HWND) override |
| Palette of the window has changed. | |
| std::string_view | CreateSwapchain () |
| Creates a DXGI swap chain for the current window. | |
| void | DestroySwapchain () |
| Destroys the DXGI swap chain and releases all associated resources. | |
| Protected Member Functions inherited from VideoDriver_Win32Base | |
| Dimension | GetScreenSize () const override |
| Get the resolution of the main screen. | |
| void | InputLoop () override |
| Handle input logic, is CTRL pressed, should we fast-forward, etc. | |
| bool | LockVideoBuffer () override |
| Make sure the video buffer is ready for drawing. | |
| void | UnlockVideoBuffer () override |
| Unlock a previously locked video buffer. | |
| void | CheckPaletteAnim () override |
| Process any pending palette animation. | |
| bool | PollEvent () override |
| Process a single system event. | |
| std::optional< std::string_view > | Initialize () |
| bool | MakeWindow (bool full_screen, bool resize=true) |
| Instantiate a new window. | |
| void | ClientSizeChanged (int w, int h, bool force=false) |
| Indicate to the driver the client-size might have changed. | |
| Protected Member Functions inherited from VideoDriver | |
| void | UpdateAutoResolution () |
| Apply resolution auto-detection and clamp to sensible defaults. | |
| void | StartGameThread () |
| Start the loop for game-tick. | |
| void | StopGameThread () |
| Stop the loop for the game-tick. | |
| void | Tick () |
| Give the video-driver a tick. | |
| void | SleepTillNextTick () |
| Sleep till the next tick is about to happen. | |
| std::chrono::steady_clock::duration | GetGameInterval () |
| std::chrono::steady_clock::duration | GetDrawInterval () |
| void | DrainCommandQueue () |
| Execute all queued commands. | |
Protected Attributes | |
| ComPtr< IDXGISwapChain > | swap_chain |
| DXGI swap chain. | |
| ComPtr< ID3D11RenderTargetView > | rendertarget |
| D3D11 render target view for the back buffer. | |
| bool | dxgi_force_resize_buffer = false |
| Flag indicating whether to force resize the swap chain buffer. | |
| bool | dxgi_fullscreen = false |
| Flag indicating whether we're in fullscreen mode. | |
| UINT | dxgi_flags = 0 |
| DXGI swap chain flags. | |
| std::string | driver_info |
| Information string about selected driver. | |
| Protected Attributes inherited from VideoDriver_Win32Base | |
| HWND | main_wnd = nullptr |
| Handle to system window. | |
| bool | fullscreen = false |
| Whether to use (true) fullscreen mode. | |
| bool | has_focus = false |
| Does our window have system focus? | |
| Rect | dirty_rect |
| Region of the screen that needs redrawing. | |
| int | width = 0 |
| Width in pixels of our display surface. | |
| int | height = 0 |
| Height in pixels of our display surface. | |
| int | width_org = 0 |
| Original monitor resolution width, before we changed it. | |
| int | height_org = 0 |
| Original monitor resolution height, before we changed it. | |
| bool | buffer_locked = false |
| Video buffer was locked by the main thread. | |
| Palette | local_palette |
| Current palette to use for drawing. | |
| Protected Attributes inherited from VideoDriver | |
| const uint | ALLOWED_DRIFT = 5 |
| How many times videodriver can miss deadlines without it being overly compensated. | |
| std::chrono::steady_clock::time_point | next_game_tick |
| std::chrono::steady_clock::time_point | next_draw_tick |
| std::thread | game_thread |
| std::mutex | game_state_mutex |
| std::mutex | game_thread_wait_mutex |
| uint8_t * | anim_buffer = nullptr |
| The animation buffer if supported/used. | |
| int | anim_pitch = 0 |
| Pitch of the animation buffer if supported/used. | |
| const bool | uses_hardware_acceleration |
| Whether hardware acceleration is used or not. | |
| const bool | supports_animation_buffer |
| Whether this driver supports hardware accelerated animation. | |
| bool | fast_forward_key_pressed = false |
| The fast-forward key is being pressed. | |
| bool | fast_forward_via_key = false |
| The fast-forward was enabled by key press. | |
| bool | is_game_threaded = true |
| Whether the game is allowed to use threads; cleared in the driver implementation constructors if required. | |
Private Member Functions | |
| std::string_view | InitD3D () |
| Check for the needed D3D11 functionality and allocate all resources. | |
| std::string_view | Resize (int w, int h) |
| Resizes the D3D11 textures to the given width and height. | |
Private Attributes | |
| ComPtr< ID3D11Device > | device |
| D3D11 device. | |
| ComPtr< ID3D11DeviceContext > | device_ctx |
| D3D11 device context. | |
| ComPtr< ID3D11VertexShader > | vertex_shader |
| Vertex shader for sprite rendering. | |
| ComPtr< ID3D11PixelShader > | direct_shader |
| Pixel shader for direct rendering. | |
| ComPtr< ID3D11PixelShader > | palette_shader |
| Pixel shader for palette animation. | |
| ComPtr< ID3D11PixelShader > | rgb_mask_blend_shader |
| Pixel shader for RGB mask blending. | |
| ComPtr< ID3D11PixelShader > | sprite_blend_shader |
| Pixel shader for sprite blending. | |
| ComPtr< ID3D11Buffer > | constant_buffer |
| Constant buffer. | |
| ComPtr< ID3D11Texture2D > | vid_texture |
| Video texture for the back buffer. | |
| ComPtr< ID3D11Texture2D > | vid_texture_staging |
| Staging texture for video texture. | |
| ComPtr< ID3D11ShaderResourceView > | vid_texture_srv |
| Shader resource view for video texture. | |
| ComPtr< ID3D11Texture2D > | anim_texture |
| Animation texture for palette animation. | |
| ComPtr< ID3D11Texture2D > | anim_texture_staging |
| Staging texture for animation texture. | |
| ComPtr< ID3D11ShaderResourceView > | anim_texture_srv |
| Shader resource view for animation texture. | |
| ComPtr< ID3D11Texture1D > | pal_texture |
| Palette texture for palette animation. | |
| ComPtr< ID3D11ShaderResourceView > | pal_texture_srv |
| Shader resource view for palette texture. | |
| ComPtr< ID3D11SamplerState > | texture_sampler |
| Sampler state for texture sampling. | |
Additional Inherited Members | |
| Public Types inherited from Driver | |
| enum class | Type : uint8_t { Begin = 0 , Music = 0 , Sound , Video , End } |
| The type of driver. More... | |
| Static Public Member Functions inherited from VideoDriver | |
| static VideoDriver * | GetInstance () |
| Get the currently active instance of the video driver. | |
| static std::string | GetCaption () |
| Get the caption to use for the game's title bar. | |
| Static Protected Member Functions inherited from VideoDriver | |
| static void | GameThreadThunk (VideoDriver *drv) |
The D3D11 video driver for windows.
Definition at line 120 of file d3d11_v.cpp.
|
inline |
Constructor for the D3D11 video driver.
Definition at line 125 of file d3d11_v.cpp.
References driver_info, GetName(), and VideoDriver_Win32Base::VideoDriver_Win32Base().
|
overridevirtual |
Callback invoked after the blitter was changed.
Reimplemented from VideoDriver.
Definition at line 602 of file d3d11_v.cpp.
References VideoDriver_Win32Base::ClientSizeChanged(), BlitterFactory::GetCurrentBlitter(), VideoDriver_Win32Base::height, and VideoDriver_Win32Base::width.
|
overrideprotectedvirtual |
(Re-)create the backing store.
| w | The width of the window. |
| h | The height of the window. |
| force | Whether to force full reallocation, instead of not reallocating when size did not change. |
Implements VideoDriver_Win32Base.
Definition at line 609 of file d3d11_v.cpp.
References CreateSwapchain(), Critical, Debug, device, VideoDriver_Win32Base::dirty_rect, Driver, dxgi_flags, dxgi_force_resize_buffer, GetVideoPointer(), VideoDriver_Win32Base::height, ReleaseVideoPointer(), rendertarget, Resize(), swap_chain, and VideoDriver_Win32Base::width.
Referenced by Paint().
|
overridevirtual |
Change the resolution of the window.
| w | The new width. |
| h | The new height. |
Reimplemented from VideoDriver_Win32Base.
Definition at line 576 of file d3d11_v.cpp.
References _window_maximize, VideoDriver_Win32Base::main_wnd, and swap_chain.
|
protected |
Creates a DXGI swap chain for the current window.
Definition at line 492 of file d3d11_v.cpp.
References _video_vsync, device, dxgi_flags, dxgi_fullscreen, and VideoDriver_Win32Base::main_wnd.
Referenced by AllocateBackingStore().
|
protected |
Destroys the DXGI swap chain and releases all associated resources.
Definition at line 569 of file d3d11_v.cpp.
References dxgi_fullscreen, rendertarget, and swap_chain.
Referenced by Stop().
|
inlineoverrideprotectedvirtual |
Colour depth to use for fullscreen display modes.
Reimplemented from VideoDriver_Win32Base.
Definition at line 174 of file d3d11_v.cpp.
|
inlineoverridevirtual |
Get some information about the selected driver/backend to be shown to the user.
Reimplemented from VideoDriver.
Definition at line 154 of file d3d11_v.cpp.
References driver_info.
|
inlineoverridevirtual |
Get the name of this driver.
Implements Driver.
Definition at line 149 of file d3d11_v.cpp.
Referenced by Start(), and VideoDriver_Win32D3D11().
|
overrideprotectedvirtual |
Get a pointer to the video buffer.
Implements VideoDriver_Win32Base.
Definition at line 660 of file d3d11_v.cpp.
References VideoDriver::anim_buffer, VideoDriver::anim_pitch, anim_texture_staging, device_ctx, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), and vid_texture_staging.
Referenced by AllocateBackingStore().
|
inlineoverridevirtual |
Has this video driver an efficient code path for palette animated 8-bpp sprites?
Reimplemented from VideoDriver.
Definition at line 139 of file d3d11_v.cpp.
|
private |
Check for the needed D3D11 functionality and allocate all resources.
Definition at line 246 of file d3d11_v.cpp.
References _D3D11CreateDevice, _frag_shader_direct_hlsl, _frag_shader_palette_hlsl, _frag_shader_rgb_mask_blend_hlsl, _frag_shader_sprite_blend_hlsl, _vertex_shader_sprite_hlsl, constant_buffer, CreatePixelShader(), CreateVertexShader(), device, device_ctx, pal_texture, and texture_sampler.
Referenced by Start().
|
inlineoverrideprotectedvirtual |
Whether minimising and restoring fullscreen windows uses ToggleFullscreen.
Reimplemented from VideoDriver_Win32Base.
Definition at line 169 of file d3d11_v.cpp.
|
overrideprotectedvirtual |
Paint the window.
Reimplemented from VideoDriver.
Definition at line 718 of file d3d11_v.cpp.
References _video_vsync, AllocateBackingStore(), anim_texture_srv, Blitter::Blitter, constant_buffer, device_ctx, direct_shader, dxgi_flags, dxgi_force_resize_buffer, dxgi_fullscreen, BlitterFactory::GetCurrentBlitter(), VideoDriver_Win32Base::height, VideoDriver_Win32Base::local_palette, MarkWholeScreenDirty(), pal_texture, pal_texture_srv, palette_shader, Blitter::PaletteAnimate(), rendertarget, rgb_mask_blend_shader, swap_chain, texture_sampler, Blitter::UsePaletteAnimation(), vertex_shader, vid_texture_srv, Video, and VideoDriver_Win32Base::width.
|
inlineoverrideprotectedvirtual |
Palette of the window has changed.
| hWnd | The window handle of the changed window. |
Implements VideoDriver_Win32Base.
Definition at line 184 of file d3d11_v.cpp.
|
overrideprotectedvirtual |
Hand video buffer back to the painting backend.
Reimplemented from VideoDriver_Win32Base.
Definition at line 678 of file d3d11_v.cpp.
References VideoDriver::anim_buffer, VideoDriver::anim_pitch, anim_texture, anim_texture_staging, device_ctx, VideoDriver_Win32Base::dirty_rect, IsEmptyRect(), vid_texture, and vid_texture_staging.
Referenced by AllocateBackingStore(), and Start().
|
private |
Resizes the D3D11 textures to the given width and height.
| w | The new width. |
| h | The new height. |
Definition at line 338 of file d3d11_v.cpp.
References anim_texture, anim_texture_staging, device, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), vid_texture, and vid_texture_staging.
Referenced by AllocateBackingStore().
|
overridevirtual |
Start this driver.
| parm | Parameters passed to the driver. |
Implements Driver.
Definition at line 417 of file d3d11_v.cpp.
References _d3d11, _D3D11CreateDevice, _D3DCompile, _d3dcompiler, VideoDriver_Win32Base::ClientSizeChanged(), convert_from_fs(), device, driver_info, dxgi_fullscreen, BlitterFactory::GetCurrentBlitter(), GetDriverParamBool(), GetName(), VideoDriver_Win32Base::height, InitD3D(), VideoDriver::is_game_threaded, VideoDriver_Win32Base::MakeWindow(), MarkWholeScreenDirty(), ReleaseVideoPointer(), ToggleFullscreen(), and VideoDriver_Win32Base::width.
|
overridevirtual |
Stop this driver.
Reimplemented from VideoDriver_Win32Base.
Definition at line 479 of file d3d11_v.cpp.
References _D3D11CreateDevice, _D3DCompile, DestroySwapchain(), and VideoDriver_Win32Base::Stop().
|
overridevirtual |
Change the full screen setting.
| fullscreen | The new setting. |
Reimplemented from VideoDriver_Win32Base.
Definition at line 588 of file d3d11_v.cpp.
References dxgi_force_resize_buffer, dxgi_fullscreen, VideoDriver_Win32Base::fullscreen, InvalidateWindowClassesData(), and swap_chain.
Referenced by Start().
|
inlineoverridevirtual |
Get whether the mouse cursor is drawn by the video driver.
Reimplemented from VideoDriver.
Definition at line 144 of file d3d11_v.cpp.
|
private |
Animation texture for palette animation.
Definition at line 207 of file d3d11_v.cpp.
Referenced by ReleaseVideoPointer(), and Resize().
|
private |
Shader resource view for animation texture.
Definition at line 209 of file d3d11_v.cpp.
Referenced by Paint().
|
private |
Staging texture for animation texture.
Definition at line 208 of file d3d11_v.cpp.
Referenced by GetVideoPointer(), ReleaseVideoPointer(), and Resize().
|
private |
|
private |
D3D11 device.
Definition at line 192 of file d3d11_v.cpp.
Referenced by AllocateBackingStore(), CreateSwapchain(), InitD3D(), Resize(), and Start().
|
private |
D3D11 device context.
Definition at line 193 of file d3d11_v.cpp.
Referenced by GetVideoPointer(), InitD3D(), Paint(), and ReleaseVideoPointer().
|
private |
Pixel shader for direct rendering.
Definition at line 196 of file d3d11_v.cpp.
Referenced by Paint().
|
protected |
Information string about selected driver.
Definition at line 167 of file d3d11_v.cpp.
Referenced by GetInfoString(), Start(), and VideoDriver_Win32D3D11().
|
protected |
DXGI swap chain flags.
Definition at line 165 of file d3d11_v.cpp.
Referenced by AllocateBackingStore(), CreateSwapchain(), and Paint().
|
protected |
Flag indicating whether to force resize the swap chain buffer.
Definition at line 163 of file d3d11_v.cpp.
Referenced by AllocateBackingStore(), Paint(), and ToggleFullscreen().
|
protected |
Flag indicating whether we're in fullscreen mode.
Definition at line 164 of file d3d11_v.cpp.
Referenced by CreateSwapchain(), DestroySwapchain(), Paint(), Start(), and ToggleFullscreen().
|
private |
Palette texture for palette animation.
Definition at line 211 of file d3d11_v.cpp.
|
private |
Shader resource view for palette texture.
Definition at line 212 of file d3d11_v.cpp.
Referenced by Paint().
|
private |
Pixel shader for palette animation.
Definition at line 197 of file d3d11_v.cpp.
Referenced by Paint().
|
protected |
D3D11 render target view for the back buffer.
Definition at line 161 of file d3d11_v.cpp.
Referenced by AllocateBackingStore(), DestroySwapchain(), and Paint().
|
private |
Pixel shader for RGB mask blending.
Definition at line 198 of file d3d11_v.cpp.
Referenced by Paint().
|
private |
Pixel shader for sprite blending.
Definition at line 199 of file d3d11_v.cpp.
|
protected |
DXGI swap chain.
Definition at line 160 of file d3d11_v.cpp.
Referenced by AllocateBackingStore(), ChangeResolution(), DestroySwapchain(), Paint(), and ToggleFullscreen().
|
private |
Sampler state for texture sampling.
Definition at line 214 of file d3d11_v.cpp.
|
private |
Vertex shader for sprite rendering.
Definition at line 195 of file d3d11_v.cpp.
Referenced by Paint().
|
private |
Video texture for the back buffer.
Definition at line 203 of file d3d11_v.cpp.
Referenced by ReleaseVideoPointer(), and Resize().
|
private |
Shader resource view for video texture.
Definition at line 205 of file d3d11_v.cpp.
Referenced by Paint().
|
private |
Staging texture for video texture.
Definition at line 204 of file d3d11_v.cpp.
Referenced by GetVideoPointer(), ReleaseVideoPointer(), and Resize().