How should VertexBuffers be used with Multiple Monitors in DirectX 9
- by Joshua C
I am currently using DirectX 9 on a machine with two GPUs and three monitors. I am currently trying to draw a triangle on each monitor using vertexbuffers; A directx helloworld with multiple monitors if you will. I am familiar with some DirectX coding, but new to multiple monitor DirectX coding. I may be going about this the wrong way, so please do correct me if I'm doing something wrong. I have created a Direct3D Device for each enumerated adapter sharing the same Form handle. This allows me to successfully use all three monitors in full-screen mode.
For Each Adapter In Direct3D.Adapters
Dim PresentParameters As New PresentParameters
'Setup PresentParameters
PresentParameters.Windowed = False
PresentParameters.DeviceWindowHandle = MainForm.Handle
Dim Device as New Device(Direct3D, Adapter.Adapter, DeviceType.Hardware, PresentParameters.DeviceWindowHandle, CreateFlags.HardwareVertexProcessing, PresentParameters)
Device.SetRenderState(RenderState.Lighting, False)
Devices.Add(Device)
Next
I can also draw text to each device successfully using a different Font for each Device.
When I render a triangle using a different VertexBuffer for each Device, only two monitors display the triangle. One of the two monitors on the same GPU, and the monitor on it's own GPU display properly.
VertexBuffer = New VertexBuffer(Device, 4 * Marshal.SizeOf(GetType(ColoredVertex)), Usage.WriteOnly, VertexFormat.None, Pool.Managed)
Dim Verts = VertexBuffer.Lock(0, 0, LockFlags.None)
Verts.WriteRange({
New ColoredVertex(-.5, -.5, 1, ForeColor),
New ColoredVertex(0, .5, 1, ForeColor),
New ColoredVertex(.5, -.5, 1, ForeColor)
})
VertexBuffer.Unlock()
VertexDeclaration = New VertexDeclaration(Device, {
New VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
New VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
})
Render Code:
Device.SetStreamSource(0, VertexBuffer, 0, Marshal.SizeOf(GetType(ColoredVertex)))
Device.VertexDeclaration = VertexDeclaration
Device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1)
I have to assume the fact that they share the same physical card comes into play. Should I use multiple buffers on the same card, and if so, how? Or what is the way I should access the VertexBuffer across Devices?
Another thought I had was the non working monitor acts like there are no lights. Is turning off lighting on each device on the same card causing issues somehow?