OpenTTD Source 20261112-master-gbcbec5e63f
d3d11_v.cpp File Reference

Implementation of the Windows (Direct3D 11) video driver. More...

#include "../stdafx.h"
#include "../openttd.h"
#include "../error_func.h"
#include "../os/windows/win32.h"
#include "../blitter/factory.hpp"
#include "../core/geometry_func.hpp"
#include "../window_func.h"
#include "../framerate_type.h"
#include "../library_loader.h"
#include "../table/hlsl_shader.h"
#include "win32_v.h"
#include <windows.h>
#include <objbase.h>
#include <wrl/client.h>
#include <dxgi1_5.h>
#include <d3d11.h>
#include <d3dcompiler.h>
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  HlslConstantBuffer
 Structure for an HLSL constant buffer containing the sprite position, screen size, zoom level, and flags for RGB and crash mode. More...
class  VideoDriver_Win32D3D11
 The D3D11 video driver for windows. More...
class  FVideoDriver_Win32D3D11
 The factory for Windows' D3D11 video driver. More...

Functions

static std::string_view CompileShader (std::string_view source, std::string_view func, std::string_view profile, ComPtr< ID3DBlob > &code)
 Compiles an HLSL shader from source code.
static std::string_view CreateVertexShader (ID3D11Device *device, std::string_view source, ComPtr< ID3D11VertexShader > &shader)
 Creates a vertex shader from HLSL source code.
static std::string_view CreatePixelShader (ID3D11Device *device, std::string_view source, ComPtr< ID3D11PixelShader > &shader)
 Creates a pixel shader from HLSL source code.

Variables

bool _window_maximize
 Declared in win32_v.cpp.
static LibraryLoader _d3d11 ("d3d11.dll")
 LibraryLoader instance for the D3D11 DLL.
static std::unique_ptr< LibraryLoader > _d3dcompiler
 Pointer to a LibraryLoader instance for the D3DCompiler DLL.
static PFN_D3D11_CREATE_DEVICE _D3D11CreateDevice
 Pointer to the D3D11CreateDevice function.
static pD3DCompile _D3DCompile
 Pointer to the D3DCompile function.
static FVideoDriver_Win32D3D11 iFVideoDriver_Win32D3D11
 Factory instance for the D3D11 video driver.

Detailed Description

Implementation of the Windows (Direct3D 11) video driver.

Definition in file d3d11_v.cpp.

Function Documentation

◆ CompileShader()

std::string_view CompileShader ( std::string_view source,
std::string_view func,
std::string_view profile,
ComPtr< ID3DBlob > & code )
static

Compiles an HLSL shader from source code.

Parameters
sourceThe HLSL source code.
funcThe entry point function name.
profileThe shader profile (e.g., "vs_4_0" for vertex shader, "ps_4_0" for pixel shader).
codeA reference to a ComPtr that will hold the compiled shader object.
Returns
An error message if compilation fails, or an empty string if successful.

Definition at line 61 of file d3d11_v.cpp.

References _D3DCompile, Debug, Driver, and Error.

Referenced by CreatePixelShader(), and CreateVertexShader().

◆ CreatePixelShader()

std::string_view CreatePixelShader ( ID3D11Device * device,
std::string_view source,
ComPtr< ID3D11PixelShader > & shader )
static

Creates a pixel shader from HLSL source code.

Parameters
deviceThe D3D11 device.
sourceThe HLSL source code.
shaderA reference to a ComPtr that will hold the created pixel shader.
Returns
An error message if creation fails, or an empty string if successful.

Definition at line 106 of file d3d11_v.cpp.

References CompileShader().

Referenced by VideoDriver_Win32D3D11::InitD3D().

◆ CreateVertexShader()

std::string_view CreateVertexShader ( ID3D11Device * device,
std::string_view source,
ComPtr< ID3D11VertexShader > & shader )
static

Creates a vertex shader from HLSL source code.

Parameters
deviceThe D3D11 device.
sourceThe HLSL source code.
shaderA reference to a ComPtr that will hold the created vertex shader.
Returns
An error message if creation fails, or an empty string if successful.

Definition at line 85 of file d3d11_v.cpp.

References CompileShader().

Referenced by VideoDriver_Win32D3D11::InitD3D().

Variable Documentation

◆ _D3D11CreateDevice

PFN_D3D11_CREATE_DEVICE _D3D11CreateDevice
static

Pointer to the D3D11CreateDevice function.

Definition at line 49 of file d3d11_v.cpp.

Referenced by VideoDriver_Win32D3D11::InitD3D(), VideoDriver_Win32D3D11::Start(), and VideoDriver_Win32D3D11::Stop().

◆ _D3DCompile

pD3DCompile _D3DCompile
static

Pointer to the D3DCompile function.

Definition at line 50 of file d3d11_v.cpp.

Referenced by CompileShader(), VideoDriver_Win32D3D11::Start(), and VideoDriver_Win32D3D11::Stop().

◆ _d3dcompiler

std::unique_ptr<LibraryLoader> _d3dcompiler
static

Pointer to a LibraryLoader instance for the D3DCompiler DLL.

Definition at line 47 of file d3d11_v.cpp.

Referenced by VideoDriver_Win32D3D11::Start().

◆ _window_maximize

bool _window_maximize
extern

◆ iFVideoDriver_Win32D3D11

FVideoDriver_Win32D3D11 iFVideoDriver_Win32D3D11
static

Factory instance for the D3D11 video driver.

Definition at line 240 of file d3d11_v.cpp.