dora_ssr/dora/effect.rs
1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10 fn effect_type() -> i32;
11 fn effect_add(slf: i64, pass: i64);
12 fn effect_get(slf: i64, index: i64) -> i64;
13 fn effect_clear(slf: i64);
14 fn effect_new(vert_shader: i64, frag_shader: i64) -> i64;
15}
16use crate::dora::IObject;
17/// A struct for managing multiple render pass objects.
18/// Effect objects allow you to combine multiple passes to create more complex shader effects.
19pub struct Effect { raw: i64 }
20crate::dora_object!(Effect);
21impl IEffect for Effect { }
22pub trait IEffect: IObject {
23 /// Adds a Pass object to this Effect.
24 ///
25 /// # Arguments
26 ///
27 /// * `pass` - The Pass object to add.
28 fn add(&mut self, pass: &crate::dora::Pass) {
29 unsafe { effect_add(self.raw(), pass.raw()); }
30 }
31 /// Retrieves a Pass object from this Effect by index.
32 ///
33 /// # Arguments
34 ///
35 /// * `index` - The index of the Pass object to retrieve.
36 ///
37 /// # Returns
38 ///
39 /// * `Pass` - The Pass object at the given index.
40 fn get(&self, index: i64) -> Option<crate::dora::Pass> {
41 unsafe { return crate::dora::Pass::from(effect_get(self.raw(), index)); }
42 }
43 /// Removes all Pass objects from this Effect.
44 fn clear(&mut self) {
45 unsafe { effect_clear(self.raw()); }
46 }
47}
48impl Effect {
49 pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
50 (unsafe { effect_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
51 match raw {
52 0 => None,
53 _ => Some(Box::new(Effect { raw: raw }))
54 }
55 })
56 }
57 /// A method that allows you to create a new Effect object.
58 ///
59 /// # Arguments
60 ///
61 /// * `vert_shader` - The vertex shader file string.
62 /// * `frag_shader` - The fragment shader file string. A shader file string must be one of the formats:
63 /// * "builtin:" + theBuiltinShaderName
64 /// * "Shader/compiled_shader_file.bin"
65 ///
66 /// # Returns
67 ///
68 /// * `Effect` - A new Effect object.
69 pub fn new(vert_shader: &str, frag_shader: &str) -> Effect {
70 unsafe { return Effect { raw: effect_new(crate::dora::from_string(vert_shader), crate::dora::from_string(frag_shader)) }; }
71 }
72}