1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/// Compile directx shader at compile time and returns byte code. it uses [`D3DCompile2`](https://docs.microsoft.com/en-us/windows/win32/api/d3dcompiler/nf-d3dcompiler-d3dcompile2).
/// any unexplained parameters are analogous to that function.
///
/// ## Syntax
///
/// ```
/// compile_shader!{
/// src: "some shader source code" // [required] either src or src_file is required
/// src_file: "path/to/shader/source/code" // [required] either src or src_file is required
/// entry_point: "main_func_name" // [required] name of entry point function
/// target: "shader_profile" // [required] shader used to compile the shader.
/// src_name: "path/to/shader/source/file" // [optional] required for #include if any.
/// // This is auto generated when src_file is used.
/// defines: { // [optional] used to define shader macros before compiling
/// ("DEFINE_1","32"),
/// },
/// flags1: 0, // [optional] flags1
/// flags2: 0, // [optional] flags2
/// secondary_data_flags: 0 // [optional] secondary_data_flags
/// secondary_data: "" // [optional] secondary_data
/// }
///
/// ```
///
/// ## Example usage
///
/// ```
/// let data = compile_shader!{
/// src: "
/// int main() {
/// return 1;
/// }
/// ",
/// entry_point: "main"
/// target: "ps_5_0"
/// };
/// ```
/// Compile DirectX shader at compile time and generates a function. The function takes an
/// `ID3D11Device4` instance to produce respective shader.
///
/// ## Syntax:
///
/// ```
/// // ps for pixel shader syntax for compile_shader! check
/// // name of func to create vs for vertex shader compile_shader docs for this syntax
/// // |_________________ | ____________________|
/// // \ | /
/// generate_shader!(fn_name ps {...})
/// ```
///
/// ## Example Usage:
///
/// ```rust
///
/// use dx11_screencap::generate_shader;
///
///
/// // this directly translates to
/// // fn sample_pixel_shader(device: ID3D11Device4)->PixelShader { ... }
/// generate_shader!(sample_pixel_shader ps {
/// src: "
/// int main() {
/// return 1;
/// }
/// ",
/// entry_point: "main"
/// target: "ps_5_0"
/// });
///
/// fn main(){
/// // somehow acquire directx device
/// let sample_shader = sample_pixel_shader(device);
/// }
///
/// ```
///