【发布时间】:2013-10-17 21:21:23
【问题描述】:
我正在尝试使用 SlimDX 创建 DirectX9 应用程序。
如果我使用.PresentationInterval = PresentInterval.Default,它会以~我的显示器的刷新率呈现,并且看起来不错。
如果我使用.PresentationInterval = PresentInterval.Immediate,我会得到大约 6,000 FPS,但会出现严重的闪烁 - 大概是因为在立即演示发生时设备正在更新,因此它可能正确绘制也可能不正确。
谁能告诉我如何使用后台缓冲区,以便立即不闪烁并且在我完成绘图时交换缓冲区?
显然,我实际上并不想要 6K FPS,但我确实想要控制帧速率上限,并且对缓冲有更好的了解。
设备初始化
PresentParameters = New PresentParameters()
With PresentParameters
.BackBufferFormat = Format.X8R8G8B8
.BackBufferCount = 2
.Multisample = MultisampleType.None
.SwapEffect = SwapEffect.Discard
.EnableAutoDepthStencil = True
.AutoDepthStencilFormat = Format.D24S8
.PresentFlags = PresentFlags.DiscardDepthStencil
.PresentationInterval = PresentInterval.Default '' or PresentInterval.Immediate
Select Case Settings.Display.Mode
Case WindowMode.FullScreen
.BackBufferWidth = Settings.Display.Width
.BackBufferHeight = Settings.Display.Height
.Windowed = False
Case WindowMode.Windowed Or WindowMode.WindowedNoBorder
.BackBufferWidth = Settings.Display.Width
.BackBufferHeight = Settings.Display.Height
.Windowed = True
End Select
.DeviceWindowHandle = Handle
End With
Direct3D = New Direct3D()
Device = New Device(Direct3D,
Settings.Display.Adapter,
DeviceType.Hardware,
Handle,
CreateFlags.HardwareVertexProcessing,
PresentParameters)
最小渲染示例...
Context9.Device.BeginScene()
Context9.Device.Clear(Direct3D9.ClearFlags.Target Or Direct3D9.ClearFlags.ZBuffer,
Color.Black,
1.0F,
0)
Game.Render(Context9)
Using Sprite As New Sprite(Context9.Device)
Sprite.Begin(SpriteFlags.AlphaBlend)
Dim Mtx = Matrix.Translation(125, 200, 0)
Dim Scaling = Matrix.Scaling(0.5, 0.5, 1)
Matrix.Multiply(Mtx, Scaling, Mtx)
Sprite.Transform = Mtx
Dim Fade As Single = CSng(Math.Min(1, Math.Sin(FrameI / 30) * 0.5 + 0.5))
Sprite.Draw(TestTex,
Nothing,
Nothing,
Nothing,
New Color4(Fade, Fade, Fade))
Sprite.End()
End Using
Context9.Device.EndScene()
Context9.Device.Present()
窗口创建/主循环
Private Sub Run()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Window = New RenderForm("Test")
InitializeDevice()
''Add lots of key handlers, etc here
LoadResources()
Clock.Start()
MessagePump.Run(Window, AddressOf MessageLoop)
Cleanup()
Window.Dispose()
End Sub
Sub MessageLoop()
Update()
If Not IsResizing Then
Render()
End If
End Sub
(我省略了显示 FPS / 其他一些位的代码,因为它只是噪音,但如果需要可以提供)
【问题讨论】:
-
如果你不使用vsync,无论你使用多少个backbuffer,总会有一些闪烁。
-
@Vertexwahn 如果图像发生剧烈/快速变化,我会同意并期待锯齿状/等,但这会使图像淡入淡出 - 在最糟糕的情况下,我预计会有一半图像比其他图像稍微不透明 - 但在这种情况下可能不可见。就目前而言,它像闪光灯一样闪烁
标签: .net directx slimdx doublebuffered