d3d11.Device

The Device class represents the actual physical (or software) device which will be used.

Methods

class Device
Device(Window window[, drivertype, adapterindex=0, rtformat, dsformat, multisampling=(1, 0)]) → Device
Parameters:
  • window – The Window used by the Device. Can be None if no on-screen rendering will be required.
  • drivertype – One of the Device driver type-values. Default is DRIVER_TYPE_HARDWARE.
  • adapterindex – The index of the adapter (usually a GPU) which will be used. You can use d3d11.enumAdapters() to enumerate all available adapters.
  • rtformatFormat for the default render target texture. Default is DXGI_FORMAT_R8G8B8A8_UNORM.
  • dsformat – Format for the default depth stencil texture. Default is DXGI_FORMAT_D24_UNORM_S8_UINT.
  • multisampling – Count and quality of samples when multisampling. (1, 0) means no multisampling.

The constructor creates a new device.

checkMultisampleQualityLevels(format, count) → int
Parameters:
  • format – A Format value.
  • count – Required multisampling sample count.

Checks support for multisampling, returns the supported quality level.

createBlendState(dict values) → DeviceState
Parameters:
  • values – A dictionary with

Creates a new DeviceState with a blend state. Use setState() to set the returned object.

#Creates a default state.
defaultBlendState = device.createBlendState({})

#Create two state that disable and enable alpha blending from the first render target.
disableAlphaBlendState = device.createBlendState({"BlendEnable[0]" : False})
enableAlphaBlendState = device.createBlendState({"BlendEnable[0]" : True})

#Create a depth stencil state.
depthStencilState = device.createDepthStencilState({"StencilEnable" : True,
    "BackFace.StencilFailOp" : STENCIL_OP_KEEP})
createDepthStencilState(dict values) → DeviceState

Creates a new DeviceState with a depth stencil state. See createBlendState().

createRasterizerState(dict values) → DeviceState

Creates a new DeviceState with a rasterizer state. See createBlendState().

createSamplerState(dict values) → DeviceState

Creates a new DeviceState with a sampler state. See createBlendState().

dispatch(int xcount, int ycount, int zcount) → None
Parameters:
  • xcount – The number of thread groups dispatched in x-direction.
  • ycount – The number of thread groups dispatched in y-direction.
  • zcount – The number of thread groups dispatched in z-direction.

Execute a command list from a thread group, used with compute shaders.

draw(int vertexcount, int startlocation) → None
Parameters:
  • vertexcount – Number of vertices to draw.
  • startlocation – The index of the first vertex to be drawn.

Draws vertices.

drawAuto() → None

Draw geometry of an unknown size.

MSDN - DrawAuto()

drawInstanced(int vertexcount, int instancecount, int startvertex, int startinstance) → None
Parameters:
  • vertexcount – How many vertices per instance.
  • instancecount – How many instances to draw.
  • startvertex – Index of the first vertex.
  • startinstance – A value added to each index before reading per-instance data from a vertex buffer.

Draws instanced vertices.

drawIndexed(int indexcount, int startindex, int basevertex) → None
Parameters:
  • indexcount – Number of indices to draw.
  • startindex – The index of the first index to be used.
  • basevertex – The index of the first vertex to be drawn.

Draws indexed vertices.

drawIndexedInstanced(int indexcount, int instancecount, int startindex, int startvertex, int startinstance) → None
Parameters:
  • indexcount – Number of indices read from the index buffer for each instance.
  • instancecount – Number of instances to draw.
  • startindex – The location of the first index read from the index buffer.
  • startvertex – A value added to each index before reading a vertex from the vertex buffer.
  • startinstance – A value added to each index before reading per-instance data from a vertex buffer.

Draws indexed and instanced vertices.

flush() → None

Flushes all pending operations. There is usually no need to call this.

getDefaultDS() → Texture

Note

Internal data, call the release() method of the returned object as soon as possible.

Returns the default depth stencil Texture or None.

getDefaultDSView() → View

Note

Internal data, call the release() method of the returned object as soon as possible.

Returns the default depth stencil View or None.

getDefaultRT() → Texture

Note

Internal data, call the release() method of the returned object as soon as possible.

Returns the default render target Texture or None.

getDefaultRTView() → View

Note

Internal data, call the release() method of the returned object as soon as possible.

Returns the default render target View or None.

getFeatureLevel() → int

Returns the feature level of the device. You can use d3d11x.featureLevel() to get more representable value.

getDisplayModes(format=0) → list

Returns all valid display modes (width, height, format) for the device. If format is 0 current backbuffer format is used.

getScissorRects() → list

Returns scissor rects as named tuples.

getScreenDesc() → ScreenInfo<int width, int height, int format, bool windowed>

A convenience method which returns swap chain information as a named tuple.

getState() → DeviceState

Returns depth stencil state, blend state and rasterizer state as a DeviceState.

getViewports() → list

Returns viewports as named tuples.

setFullscreenState(bool fullscreen, int width, int height) → None

Changes the Device into a fullscreen mode or out of it. Make sure that you are in windowed mode when your application exits (or you release the device). If width and height are both zero and the device is going into a fullscreen mode the main monitor’s resolution will be used.

setIndexBuffer(Buffer indexbuffer) → None
Parameters:
  • indexbuffer – The Buffer to be bound.

Binds the given index buffer to the device.

setInputLayout(layout) → None
Parameters:

Binds an input layout object to the device.

setPrimitiveTopology(int topology) → None
Parameters:

Set the primitve topology.

setRenderTargets(list rendertargetviews, View depthstencilview) → None
Parameters:
  • rendertargetviews – A list of View-objects where each references a Texture created for render target usage.
  • depthstencilview – A View which references a Texture created for depth stencil usage. Can be None.

Binds given views to the device.

setRenderTargetsDefault(clear=True) → None
Parameters:
  • clear – If True the render target and depth stencil will be cleared to default values before setting them.

A convenience method which clears and sets the default render target and depth stencil. These are managed by DirectPython. This is functionally similar to:

rt = device.getDefaultRTView() #Render target
rt.clearRenderTarget()
ds = device.getDefaultDSView() #Depth stencil
ds.clearDepthStencil()
device.setRenderTargets([rt], ds)
#Must be released.
ds.release()
rt.release()
setScissorRects(list rects) → None

Sets scissor rects. A scissor rect in a tuple of 4 int elements: (x, y, width, height).

setState(state) → None
Parameters:

Applies the state object.

setStreamOutputTargets(buffers) → None
Parameters:
  • buffers – A list of Buffer-objects to be bound.

Binds buffers to stream output.

MSDN - SOSetTargets()

setVertexBuffers(list buffers) → None
Parameters:
  • buffers – A list of Buffer-objects to be bound.

Binds buffers to the device.

setViewports(list viewports) → None

Sets viewports. A viewport is a tuple of 6 float elements: (x, y, width, height, minDepth, maxDepth).

present(int verticalsync) → None
Parameters:
  • verticalsync – How many syncs to wait before presenting. Use 0 to present immediately.

Presents the backbuffer to the window.

reset() → None

Resets some device settings, for example when the window size has changed. There is usually no reason to call this method directly unless you are using some third party windowing toolkit (wxWindows etc.).

restoreDepthStencilState() → None

A convenience method which restores the default depth stencil state.

restoreBlendState() → None

A convenience method which restores the default blend state.

restoreRasterizerState() → None

A convenience method which restores the default rasterizer state.

restoreSamplerState() → None

A convenience method which restores the default sampler state. There is usually no reason to call this.

Table Of Contents

Get DirectPython 11 at SourceForge.net. Fast, secure and Free Open Source software downloads