d3d11/context/
output_merger.rs1use std::mem::transmute;
2
3use crate::{
4 blend_state::BlendState, cast_optional_resource_refs, rtv::RenderTargetView,
5 util::OptionalParam, DepthStencilState, DepthStencilView,
6};
7
8use super::DeviceContext;
9
10#[cfg_attr(feature = "profiling", profiling::all_functions)]
11impl DeviceContext {
12 pub fn output_merger_set_render_targets(
13 &self,
14 render_target_views: &[Option<&RenderTargetView>],
15 depth_stencil_view: Option<&DepthStencilView>,
16 ) {
17 unsafe {
18 let raw_rtvs = cast_optional_resource_refs!(8, render_target_views);
19 self.0.OMSetRenderTargets(
20 Some(transmute(raw_rtvs.as_slice())),
21 depth_stencil_view.map(|d| &d.0),
22 );
23 }
24 }
25
26 pub fn output_merger_get_render_targets(
27 &self,
28 ) -> ([Option<RenderTargetView>; 8], Option<DepthStencilView>) {
29 let mut rtvs = [const { None }; 8];
30 let mut dsv = None;
31 unsafe {
32 self.0.OMGetRenderTargets(Some(&mut rtvs), Some(&mut dsv));
33 }
34 (
35 rtvs.map(|r| r.map(RenderTargetView)),
36 dsv.map(DepthStencilView),
37 )
38 }
39
40 pub fn output_merger_set_blend_state(
41 &self,
42 blend_state: impl OptionalParam<Output = BlendState>,
43 blend_factor: Option<&[f32; 4]>,
44 sample_mask: u32,
45 ) {
46 unsafe {
47 self.0.OMSetBlendState(
48 blend_state.as_option().map(|bs| &bs.0),
49 blend_factor,
50 sample_mask,
51 );
52 }
53 }
54
55 pub fn output_merger_set_depth_stencil_state(
56 &self,
57 depth_stencil_state: impl OptionalParam<Output = DepthStencilState>,
58 stencil_ref: u32,
59 ) {
60 unsafe {
61 self.0.OMSetDepthStencilState(
62 depth_stencil_state.as_option().map(|dss| &dss.0),
63 stencil_ref,
64 );
65 }
66 }
67}