Videra.Platform.Windows 0.1.0-alpha.1

This is a prerelease version of Videra.Platform.Windows.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Videra.Platform.Windows --version 0.1.0-alpha.1
                    
NuGet\Install-Package Videra.Platform.Windows -Version 0.1.0-alpha.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Videra.Platform.Windows" Version="0.1.0-alpha.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Videra.Platform.Windows" Version="0.1.0-alpha.1" />
                    
Directory.Packages.props
<PackageReference Include="Videra.Platform.Windows" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Videra.Platform.Windows --version 0.1.0-alpha.1
                    
#r "nuget: Videra.Platform.Windows, 0.1.0-alpha.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Videra.Platform.Windows@0.1.0-alpha.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Videra.Platform.Windows&version=0.1.0-alpha.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Videra.Platform.Windows&version=0.1.0-alpha.1&prerelease
                    
Install as a Cake Tool

Videra.Platform.Windows - Direct3D 11 后端

Windows 平台的 Direct3D 11 图形后端实现。

模块架构

graph TB
    subgraph "D3D11 Backend"
        Backend[D3D11Backend<br/>后端实现]
        Factory[D3D11ResourceFactory<br/>资源工厂]
        Executor[D3D11CommandExecutor<br/>命令执行器]
        Buffer[D3D11Buffer<br/>缓冲区]
        Pipeline[D3D11Pipeline<br/>渲染管线]
    end

    subgraph "Silk.NET"
        D3D11[Silk.NET.Direct3D11]
        DXGI[Silk.NET.DXGI]
    end

    subgraph "Windows"
        HWND[窗口句柄]
        SwapChain[交换链]
        RTV[渲染目标视图]
        DSV[深度模板视图]
    end

    Backend --> Factory
    Backend --> Executor
    Factory --> Buffer
    Factory --> Pipeline
    Backend --> D3D11
    Backend --> DXGI
    D3D11 --> HWND
    HWND --> SwapChain
    SwapChain --> RTV
    Backend --> DSV

初始化流程

sequenceDiagram
    participant App as 应用程序
    participant Backend as D3D11Backend
    participant D3D11 as Direct3D 11
    participant DXGI as DXGI

    App->>Backend: Initialize(hwnd, w, h)
    Backend->>D3D11: GetApi()
    Backend->>DXGI: GetApi()
    Backend->>D3D11: CreateDevice()
    Backend->>DXGI: CreateSwapChain()
    Backend->>D3D11: CreateRenderTargetView()
    Backend->>D3D11: CreateDepthStencilView()
    Backend->>Backend: CreateResourceFactory()
    Backend->>Backend: CreateCommandExecutor()
    Backend-->>App: IsInitialized = true

渲染流程

sequenceDiagram
    participant Engine as VideraEngine
    participant Backend as D3D11Backend
    participant Context as DeviceContext
    participant SwapChain as SwapChain

    Engine->>Backend: BeginFrame()
    Backend->>Context: ClearRenderTargetView()
    Backend->>Context: ClearDepthStencilView()
    Backend->>Context: OMSetRenderTargets()

    loop 绘制对象
        Engine->>Backend: Draw()
        Backend->>Context: IASetVertexBuffers()
        Backend->>Context: IASetIndexBuffer()
        Backend->>Context: VSSetConstantBuffers()
        Backend->>Context: DrawIndexed()
    end

    Engine->>Backend: EndFrame()
    Backend->>SwapChain: Present()

核心类

D3D11Backend

实现 IGraphicsBackend 接口的 Direct3D 11 后端。

public class D3D11Backend : IGraphicsBackend
{
    public void Initialize(IntPtr windowHandle, int width, int height);
    public void Resize(int width, int height);
    public void BeginFrame();
    public void EndFrame();
    public void SetClearColor(Vector4 color);
    public IResourceFactory GetResourceFactory();
    public ICommandExecutor GetCommandExecutor();
}

D3D11ResourceFactory

创建 D3D11 GPU 资源。

internal class D3D11ResourceFactory : IResourceFactory
{
    public IBuffer CreateVertexBuffer(VertexPositionNormalColor[] vertices);
    public IBuffer CreateVertexBuffer(uint sizeInBytes);
    public IBuffer CreateIndexBuffer(uint[] indices);
    public IBuffer CreateIndexBuffer(uint sizeInBytes);
    public IBuffer CreateUniformBuffer(uint sizeInBytes);
    public IPipeline CreatePipeline(PipelineDescription description);
    public IPipeline CreatePipeline(uint vertexSize, bool hasNormals, bool hasColors);
}

深度缓冲配置

flowchart LR
    subgraph "深度测试"
        Near[近平面 0.0] --> Test{深度比较<br/>LessEqual}
        Test --> Far[远平面 1.0]
    end

    subgraph "格式"
        Format[D24_UNORM_S8_UINT]
    end
  • 深度格式: D24_UNORM_S8_UINT
  • 比较函数: LessEqual
  • 深度写入: 启用

文件结构

Videra.Platform.Windows/
├── D3D11Backend.cs           # 后端实现
├── D3D11Buffer.cs            # 缓冲区实现
├── D3D11CommandExecutor.cs   # 命令执行器
├── D3D11Pipeline.cs          # 渲染管线
└── D3D11ResourceFactory.cs   # 资源工厂

依赖

  • .NET 8.0
  • Silk.NET.Direct3D11
  • Silk.NET.DXGI
  • Videra.Core

原生验证

在 Windows 原生主机上,可通过仓库统一验证入口执行 D3D11 与真实 HWND 生命周期验证:

# Unix shell
./verify.sh --configuration Release

# PowerShell
pwsh -File ./verify.ps1 -Configuration Release

这一步会覆盖解决方案构建、测试以及 tests/Videra.Platform.Windows.Tests 中的真实 HWND-backed D3D11 验证路径。

系统要求

  • Windows 10 或更高版本
  • Direct3D 11 兼容显卡
  • 支持 Feature Level 11_0
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.7 53 4/18/2026
0.1.0-alpha.3 57 4/17/2026
0.1.0-alpha.1 57 4/16/2026