[go: up one dir, main page]

gfx_core/
dummy.rs

1// Copyright 2015 The Gfx-rs Developers.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Dummy backend implementation to test the code for compile errors
16//! outside of the graphics development environment.
17
18use {Capabilities, Device, SubmissionResult, Resources, IndexType, VertexCount};
19use {state, target, handle, mapping, pso, shade, texture};
20use command::{self, AccessInfo};
21
22/// Dummy device which does minimal work, just to allow testing
23/// gfx-rs apps for compilation.
24pub struct DummyDevice {
25    capabilities: Capabilities,
26}
27
28/// Dummy resources phantom type
29#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
30pub enum DummyResources {}
31
32impl Resources for DummyResources {
33    type Buffer               = ();
34    type Shader               = ();
35    type Program              = ();
36    type PipelineStateObject  = ();
37    type Texture              = ();
38    type ShaderResourceView   = ();
39    type UnorderedAccessView  = ();
40    type RenderTargetView     = ();
41    type DepthStencilView     = ();
42    type Sampler              = ();
43    type Fence                = DummyFence;
44    type Mapping              = DummyMapping;
45}
46
47/// Dummy fence that does nothing.
48#[derive(Clone, Debug, Eq, Hash, PartialEq)]
49pub struct DummyFence;
50
51/// Dummy mapping which will crash on use.
52#[derive(Clone, Debug, Eq, Hash, PartialEq)]
53pub struct DummyMapping;
54
55impl mapping::Gate<DummyResources> for DummyMapping {
56    unsafe fn set<T>(&self, _index: usize, _val: T) { unimplemented!() }
57    unsafe fn slice<'a, 'b, T>(&'a self, _len: usize) -> &'b [T] { unimplemented!() }
58    unsafe fn mut_slice<'a, 'b, T>(&'a self, _len: usize) -> &'b mut [T] { unimplemented!() }
59}
60
61impl DummyDevice {
62    /// Create a new dummy device
63    pub fn new() -> DummyDevice {
64        let caps = Capabilities {
65            max_vertex_count: 0,
66            max_index_count: 0,
67            max_texture_size: 0,
68            max_patch_size: 0,
69            instance_base_supported: false,
70            instance_call_supported: false,
71            instance_rate_supported: false,
72            vertex_base_supported: false,
73            srgb_color_supported: false,
74            constant_buffer_supported: false,
75            unordered_access_view_supported: false,
76            separate_blending_slots_supported: false,
77            copy_buffer_supported: false,
78        };
79        DummyDevice {
80            capabilities: caps,
81        }
82    }
83}
84
85/// Dummy command buffer, which ignores all the calls.
86pub struct DummyCommandBuffer;
87impl command::Buffer<DummyResources> for DummyCommandBuffer {
88    fn reset(&mut self) {}
89    fn bind_pipeline_state(&mut self, _: ()) {}
90    fn bind_vertex_buffers(&mut self, _: pso::VertexBufferSet<DummyResources>) {}
91    fn bind_constant_buffers(&mut self, _: &[pso::ConstantBufferParam<DummyResources>]) {}
92    fn bind_global_constant(&mut self, _: shade::Location, _: shade::UniformValue) {}
93    fn bind_resource_views(&mut self, _: &[pso::ResourceViewParam<DummyResources>]) {}
94    fn bind_unordered_views(&mut self, _: &[pso::UnorderedViewParam<DummyResources>]) {}
95    fn bind_samplers(&mut self, _: &[pso::SamplerParam<DummyResources>]) {}
96    fn bind_pixel_targets(&mut self, _: pso::PixelTargetSet<DummyResources>) {}
97    fn bind_index(&mut self, _: (), _: IndexType) {}
98    fn set_scissor(&mut self, _: target::Rect) {}
99    fn set_ref_values(&mut self, _: state::RefValues) {}
100    fn copy_buffer(&mut self, _: (), _: (),
101                   _: usize, _: usize,
102                   _: usize) {}
103    fn copy_buffer_to_texture(&mut self, _: (), _: usize, _: texture::TextureCopyRegion<()>) {}
104    fn copy_texture_to_buffer(&mut self, _: texture::TextureCopyRegion<()>, _: (), _: usize) {}
105    fn copy_texture_to_texture(&mut self,
106                               _: texture::TextureCopyRegion<()>,
107                               _: texture::TextureCopyRegion<()>) {}
108    fn update_buffer(&mut self, _: (), _: &[u8], _: usize) {}
109    fn update_texture(&mut self, _: texture::TextureCopyRegion<()>, _: &[u8]) {}
110    fn generate_mipmap(&mut self, _: ()) {}
111    fn clear_color(&mut self, _: (), _: command::ClearColor) {}
112    fn clear_depth_stencil(&mut self, _: (), _: Option<target::Depth>,
113                           _: Option<target::Stencil>) {}
114    fn call_draw(&mut self, _: VertexCount, _: VertexCount, _: Option<command::InstanceParams>) {}
115    fn call_draw_indexed(&mut self, _: VertexCount, _: VertexCount,
116                         _: VertexCount, _: Option<command::InstanceParams>) {}
117}
118
119impl Device for DummyDevice {
120    type Resources = DummyResources;
121    type CommandBuffer = DummyCommandBuffer;
122
123    fn get_capabilities(&self) -> &Capabilities {
124        &self.capabilities
125    }
126    fn pin_submitted_resources(&mut self, _: &handle::Manager<DummyResources>) {}
127    fn submit(&mut self,
128              _: &mut DummyCommandBuffer,
129              _: &AccessInfo<Self::Resources>)
130              -> SubmissionResult<()> {
131        unimplemented!()
132    }
133
134    fn fenced_submit(&mut self,
135                     _: &mut Self::CommandBuffer,
136                     _: &AccessInfo<Self::Resources>,
137                     _after: Option<handle::Fence<Self::Resources>>)
138                     -> SubmissionResult<handle::Fence<Self::Resources>> {
139        unimplemented!()
140    }
141
142    fn wait_fence(&mut self, _: &handle::Fence<Self::Resources>) {
143        unimplemented!()
144    }
145
146    fn cleanup(&mut self) {}
147}