objc2_scene_kit/generated/
SCNShadable.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7#[cfg(feature = "objc2-metal")]
8#[cfg(not(target_os = "watchos"))]
9use objc2_metal::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypoint?language=objc)
14// NS_TYPED_ENUM
15pub type SCNShaderModifierEntryPoint = NSString;
16
17/// The frequency at which the custom program input should be updated.
18///
19/// When the frequency is set to SCNBufferFrequencyPerFrame, the binding block is invoked once per frame.
20/// When the frequency is set to SCNBufferFrequencyPerNode, the binding block is invoked once per SCNNode.
21/// When the frequency is set to SCNBufferFrequencyPerShadable, the binding block is invoked once per SCNMaterial or SCNGeometry (depending on the object that owns the SCNProgram).
22///
23/// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnbufferfrequency?language=objc)
24// NS_ENUM
25#[repr(transparent)]
26#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
27pub struct SCNBufferFrequency(pub NSInteger);
28impl SCNBufferFrequency {
29    #[doc(alias = "SCNBufferFrequencyPerFrame")]
30    pub const PerFrame: Self = Self(0);
31    #[doc(alias = "SCNBufferFrequencyPerNode")]
32    pub const PerNode: Self = Self(1);
33    #[doc(alias = "SCNBufferFrequencyPerShadable")]
34    pub const PerShadable: Self = Self(2);
35}
36
37unsafe impl Encode for SCNBufferFrequency {
38    const ENCODING: Encoding = NSInteger::ENCODING;
39}
40
41unsafe impl RefEncode for SCNBufferFrequency {
42    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
43}
44
45extern_protocol!(
46    /// [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnbufferstream?language=objc)
47    pub unsafe trait SCNBufferStream: NSObjectProtocol {
48        #[unsafe(method(writeBytes:length:))]
49        #[unsafe(method_family = none)]
50        unsafe fn writeBytes_length(&self, bytes: NonNull<c_void>, length: NSUInteger);
51    }
52);
53
54/// Signature for the block to execute to bind or unbind a buffer.
55///
56/// Parameter `buffer`: The buffer to fill.
57///
58/// Parameter `node`: The rendered node.
59///
60/// Parameter `shadable`: The rendered shadable (geometry or material).
61///
62/// Parameter `renderer`: The renderer that is currently rendering the scene.
63///
64/// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnbufferbindingblock?language=objc)
65#[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
66pub type SCNBufferBindingBlock = *mut block2::Block<
67    dyn Fn(
68        NonNull<ProtocolObject<dyn SCNBufferStream>>,
69        NonNull<SCNNode>,
70        NonNull<ProtocolObject<dyn SCNShadable>>,
71        NonNull<SCNRenderer>,
72    ),
73>;
74
75/// Signature for the block to execute to bind or unbind a uniform of an OpenGL or OpenGLES based program.
76///
77/// Parameter `programID`: The id of the program object to bind/unbind values for.
78///
79/// Parameter `location`: The location of the symbol within the program object to bind/unbind values for.
80///
81/// Parameter `renderedNode`: The node currently being rendered.
82///
83/// Parameter `renderer`: The renderer that is currently rendering the scene.
84///
85/// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnbindingblock?language=objc)
86#[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
87pub type SCNBindingBlock =
88    *mut block2::Block<dyn Fn(c_uint, c_uint, *mut SCNNode, NonNull<SCNRenderer>)>;
89
90extern_protocol!(
91    /// The SCNShadable protocol defines an object that is rendered with shaders.
92    ///
93    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadable?language=objc)
94    pub unsafe trait SCNShadable: NSObjectProtocol {
95        /// Specifies a custom program used to render the receiver.
96        ///
97        /// When a program is set, it overrides all the rendering parameters such as material settings and shaderModifiers.
98        #[optional]
99        #[unsafe(method(program))]
100        #[unsafe(method_family = none)]
101        unsafe fn program(&self) -> Option<Retained<SCNProgram>>;
102
103        /// Setter for [`program`][Self::program].
104        #[optional]
105        #[unsafe(method(setProgram:))]
106        #[unsafe(method_family = none)]
107        unsafe fn setProgram(&self, program: Option<&SCNProgram>);
108
109        #[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
110        /// Sets the block to call at render time to bind the value for the specified symbol of the receiver's SCNProgram. This method has no effect for symbols declared in shader modifiers.
111        ///
112        /// Parameter `symbol`: The name of the symbol to bind a value for.
113        ///
114        /// Parameter `block`: The block to call to bind the specified symbol.
115        ///
116        /// This method can only be used with OpenGL and OpenGLES based programs.
117        #[optional]
118        #[unsafe(method(handleBindingOfSymbol:usingBlock:))]
119        #[unsafe(method_family = none)]
120        unsafe fn handleBindingOfSymbol_usingBlock(
121            &self,
122            symbol: &NSString,
123            block: SCNBindingBlock,
124        );
125
126        #[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
127        /// Sets the block to call at render time to unbind the value for the specified symbol of the receiver's SCNProgram. This method has no effect for symbols declared in shader modifiers.
128        ///
129        /// Parameter `symbol`: The name of the symbol to unbind.
130        ///
131        /// Parameter `block`: The block to call to unbind the specified symbol.
132        ///
133        /// This method can only be used with OpenGL and OpenGLES based programs.
134        #[optional]
135        #[unsafe(method(handleUnbindingOfSymbol:usingBlock:))]
136        #[unsafe(method_family = none)]
137        unsafe fn handleUnbindingOfSymbol_usingBlock(
138            &self,
139            symbol: &NSString,
140            block: SCNBindingBlock,
141        );
142
143        /// Dictionary of shader modifiers snippets, targeting entry points. The valid keys are the entry points described in the "Shader Modifier Entry Point" constants. The values are the code snippets formatted as described below.
144        ///
145        /// Shader modifiers allow you to inject shader code in the standard shaders of SceneKit. This injection is allowed in few controlled entry points, allowing specific kind of tasks in specific context. Each modifier can operate on specific structures along with access to global uniforms, that could be the standard SceneKit uniforms or its own declared uniforms.
146        ///
147        /// Shader modifiers can be used to tweak SceneKit rendering by adding custom code at the following entry points:
148        /// 1. vertex   (SCNShaderModifierEntryPointGeometry)
149        /// 2. surface  (SCNShaderModifierEntryPointSurface)
150        /// 3. lighting (SCNShaderModifierEntryPointLightingModel)
151        /// 4. fragment (SCNShaderModifierEntryPointFragment)
152        /// See below for a detailed explanation of these entry points and the context they provide.
153        ///
154        /// Shader modifiers can be written in either GLSL or the Metal Shading Language. Metal shaders won't run on iOS 8 and macOS 10.10 or earlier.
155        ///
156        /// The structure of a shader modifier is:
157        ///
158        /// GLSL
159        /// | uniform float myGrayAmount = 3.0; // Custom GLSL uniforms declarations are of the form `[uniform type uniformName [= defaultValue]]`
160        /// |
161        /// | // Optional global function definitions (for Metal: references to uniforms in global functions are not supported).
162        /// | float mySin(float t) {
163        /// |    return sin(t);
164        /// | }
165        /// |
166        /// | [#pragma transparent | opaque]
167        /// | [#pragma body]
168        /// |
169        /// | // the shader modifier code snippet itself
170        /// | vec3 myColor = myGrayAmount;
171        /// | _output.color.rgb += myColor;
172        ///
173        /// Metal Shading Language
174        /// | #pragma arguments
175        /// | float myGrayAmount; // Custom Metal uniforms declarations require a #pragma and are of the form `[type name]`
176        /// |
177        /// | #pragma declaration
178        /// | // Optional global function definitions (for Metal: references to uniforms in global functions are not supported).
179        /// | float mySin(float t) {
180        /// |    return sin(t);
181        /// | }
182        /// |
183        /// | [#pragma transparent | opaque]
184        /// | [#pragma body]
185        /// |
186        /// | // the shader modifier code snippet itself
187        /// | float3 myColor = myGrayAmount;
188        /// | _output.color.rgb += myColor;
189        ///
190        /// The `#pragma body` directive
191        /// Is only needed if you declared functions that must not be included in the shader code itself.
192        ///
193        /// The `#pragma transparent` directive
194        /// Forces the rendering to be blended using the following equation:
195        /// _output.color.rgb + (1 - _output.color.a) * dst.rgb;
196        /// where `dst` represents the current fragment color. The rgb components must be premultiplied.
197        ///
198        /// The `#pragma opaque` directive
199        /// Forces the rendering to be opaque. It then ignores the alpha component of the fragment.
200        ///
201        /// When using Metal, you can also transfer varying values from the vertex shader (geometry shader modifier) to the fragment shader (surface and/or fragment shader modifier):
202        /// 1. Start by declaring the varying values in at least one of the shader modifiers:
203        ///
204        /// Metal Shading Language
205        /// | #pragma varyings
206        /// | half3 myVec;
207        ///
208        /// 2. Then write the varying values from the vertex shader (geometry shader modifier):
209        ///
210        /// Metal Shading Language
211        /// | #pragma body
212        /// | out.myVec = _geometry.normal.xyz * 0.5h + 0.5h;
213        ///
214        /// 3. Finally read the varying values from the fragment shader (surface and/or fragment shader modifier):
215        ///
216        /// Metal Shading Language
217        /// | _output.color.rgb = saturate(in.myVec);
218        ///
219        /// SceneKit declares the following built-in uniforms:
220        ///
221        /// GLSL                                        | Metal Shading Language                                |
222        /// --------------------------------------------┼-------------------------------------------------------┤
223        /// float u_time                                | float    scn_frame.time                               | The current time, in seconds
224        /// vec2  u_inverseResolution                   | float2   scn_frame.inverseResolution                  | 1.0 / screen size
225        /// --------------------------------------------┼-------------------------------------------------------┤
226        /// mat4  u_viewTransform                       | float4x4 scn_frame.viewTransform                      | See SCNViewTransform
227        /// mat4  u_inverseViewTransform                | float4x4 scn_frame.inverseViewTransform               |
228        /// mat4  u_projectionTransform                 | float4x4 scn_frame.projectionTransform                | See SCNProjectionTransform
229        /// mat4  u_inverseProjectionTransform          | float4x4 scn_frame.inverseProjectionTransform         |
230        /// --------------------------------------------┼-------------------------------------------------------┤
231        /// mat4  u_normalTransform                     | float4x4 scn_node.normalTransform                     | See SCNNormalTransform
232        /// mat4  u_modelTransform                      | float4x4 scn_node.modelTransform                      | See SCNModelTransform
233        /// mat4  u_inverseModelTransform               | float4x4 scn_node.inverseModelTransform               |
234        /// mat4  u_modelViewTransform                  | float4x4 scn_node.modelViewTransform                  | See SCNModelViewTransform
235        /// mat4  u_inverseModelViewTransform           | float4x4 scn_node.inverseModelViewTransform           |
236        /// mat4  u_modelViewProjectionTransform        | float4x4 scn_node.modelViewProjectionTransform        | See SCNModelViewProjectionTransform
237        /// mat4  u_inverseModelViewProjectionTransform | float4x4 scn_node.inverseModelViewProjectionTransform |
238        /// --------------------------------------------┼-------------------------------------------------------┤
239        /// mat2x3 u_boundingBox;                       | float2x3 scn_node.boundingBox                         | The bounding box of the current geometry, in model space, u_boundingBox[0].xyz and u_boundingBox[1].xyz being respectively the minimum and maximum corner of the box.
240        /// mat2x3 u_worldBoundingBox;                  | float2x3 scn_node.worldBoundingBox                    | The bounding box of the current geometry, in world space.
241        ///
242        /// When writing shaders using the Metal Shading Language a complete description of the type of the scn_frame variable (SCNSceneBuffer) can be found in the
243        /// <SceneKit
244        /// /scn_metal> header file.
245        /// The type of the scn_node variable is generated at compile time and there's no corresponding header file in the framework.
246        ///
247        /// In addition to these built-in uniforms, it is possible to use custom uniforms:
248        ///
249        /// The SCNGeometry and SCNMaterial classes are key-value coding compliant classes, which means that you can set values for arbitrary keys. Even if the key `myAmplitude` is not a declared property of the class, you can still set a value for it.
250        /// Declaring a `myAmplitude` uniform in the shader modifier makes SceneKit observe the reveiver's `myAmplitude` key. Any change to that key will make SceneKit bind the uniform with the new value.
251        ///
252        /// The following GLSL and Metal Shading Language types (and their Objective-C counterparts) can be used to declare (and bind) custom uniforms:
253        ///
254        /// GLSL        | Metal Shading Language | Objective-C                           |
255        /// ------------┼------------------------┼---------------------------------------┤
256        /// int         | int                    | NSNumber, NSInteger, int              |
257        /// float       | float                  | NSNumber, CGFloat, float, double      |
258        /// vec2        | float2                 | CGPoint                               |
259        /// vec3        | float3                 | SCNVector3                            |
260        /// vec4        | float4                 | SCNVector4                            |
261        /// mat4, mat44 | float4x4               | SCNMatrix4                            |
262        /// sampler2D   | texture2d              | SCNMaterialProperty                   |
263        /// samplerCube | texturecube            | SCNMaterialProperty (with a cube map) |
264        /// -           | device const T*        | MTLBuffer                             | Feature introduced in macOS 10.13, iOS 11.0 and tvOS 11.0
265        /// -           | struct {...}           | NSData                                | The entire struct can be set using NSData but it is also possible to set individual members using the member's name as a key and a value compatible with the member's type
266        ///
267        /// Common scalar types wrapped into a NSValue are also supported.
268        ///
269        /// The following prefixes are reserved by SceneKit and should not be used in custom names:
270        /// 1. u_
271        /// 2. a_
272        /// 3. v_
273        ///
274        /// Custom uniforms can be animated using explicit animations.
275        #[optional]
276        #[unsafe(method(shaderModifiers))]
277        #[unsafe(method_family = none)]
278        unsafe fn shaderModifiers(
279            &self,
280        ) -> Option<Retained<NSDictionary<SCNShaderModifierEntryPoint, NSString>>>;
281
282        /// Setter for [`shaderModifiers`][Self::shaderModifiers].
283        #[optional]
284        #[unsafe(method(setShaderModifiers:))]
285        #[unsafe(method_family = none)]
286        unsafe fn setShaderModifiers(
287            &self,
288            shader_modifiers: Option<&NSDictionary<SCNShaderModifierEntryPoint, NSString>>,
289        );
290
291        /// The minimum language version required to interpret the shadable source code (wrapped MTLLanguageVersion). Defaults to nil.
292        ///
293        /// By default SceneKit does not use the most recent language version in order to reduce compilation times. If set to nil the shadable source code is assumed to compile with any language version greater than or equal to Metal 2.0.
294        #[optional]
295        #[unsafe(method(minimumLanguageVersion))]
296        #[unsafe(method_family = none)]
297        unsafe fn minimumLanguageVersion(&self) -> Option<Retained<NSNumber>>;
298
299        /// Setter for [`minimumLanguageVersion`][Self::minimumLanguageVersion].
300        #[optional]
301        #[unsafe(method(setMinimumLanguageVersion:))]
302        #[unsafe(method_family = none)]
303        unsafe fn setMinimumLanguageVersion(&self, minimum_language_version: Option<&NSNumber>);
304    }
305);
306
307extern "C" {
308    /// Semantic options
309    ///
310    /// Valid keys for the option parameter of setSemantic:forSymbol:options:
311    ///
312    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnprogrammappingchannelkey?language=objc)
313    pub static SCNProgramMappingChannelKey: &'static NSString;
314}
315
316extern_class!(
317    /// A SCNProgram lets you specify custom shaders to use when rendering materials.
318    ///
319    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnprogram?language=objc)
320    #[unsafe(super(NSObject))]
321    #[derive(Debug, PartialEq, Eq, Hash)]
322    pub struct SCNProgram;
323);
324
325unsafe impl NSCoding for SCNProgram {}
326
327unsafe impl NSCopying for SCNProgram {}
328
329unsafe impl CopyingHelper for SCNProgram {
330    type Result = Self;
331}
332
333unsafe impl NSObjectProtocol for SCNProgram {}
334
335unsafe impl NSSecureCoding for SCNProgram {}
336
337impl SCNProgram {
338    extern_methods!(
339        /// Creates and initialize a program instance.
340        #[unsafe(method(program))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn program() -> Retained<Self>;
343
344        /// Determines the receiver's vertex shader.
345        #[unsafe(method(vertexShader))]
346        #[unsafe(method_family = none)]
347        pub unsafe fn vertexShader(&self) -> Option<Retained<NSString>>;
348
349        /// Setter for [`vertexShader`][Self::vertexShader].
350        #[unsafe(method(setVertexShader:))]
351        #[unsafe(method_family = none)]
352        pub unsafe fn setVertexShader(&self, vertex_shader: Option<&NSString>);
353
354        /// Determines the receiver's fragment shader.
355        #[unsafe(method(fragmentShader))]
356        #[unsafe(method_family = none)]
357        pub unsafe fn fragmentShader(&self) -> Option<Retained<NSString>>;
358
359        /// Setter for [`fragmentShader`][Self::fragmentShader].
360        #[unsafe(method(setFragmentShader:))]
361        #[unsafe(method_family = none)]
362        pub unsafe fn setFragmentShader(&self, fragment_shader: Option<&NSString>);
363
364        /// Determines the receiver's tessellation control shader. Tessellation shaders require OpenGL Core Profile.
365        #[unsafe(method(tessellationControlShader))]
366        #[unsafe(method_family = none)]
367        pub unsafe fn tessellationControlShader(&self) -> Option<Retained<NSString>>;
368
369        /// Setter for [`tessellationControlShader`][Self::tessellationControlShader].
370        #[unsafe(method(setTessellationControlShader:))]
371        #[unsafe(method_family = none)]
372        pub unsafe fn setTessellationControlShader(
373            &self,
374            tessellation_control_shader: Option<&NSString>,
375        );
376
377        /// Determines the receiver's tessellation evaluation shader. Tessellation shaders require OpenGL Core Profile.
378        #[unsafe(method(tessellationEvaluationShader))]
379        #[unsafe(method_family = none)]
380        pub unsafe fn tessellationEvaluationShader(&self) -> Option<Retained<NSString>>;
381
382        /// Setter for [`tessellationEvaluationShader`][Self::tessellationEvaluationShader].
383        #[unsafe(method(setTessellationEvaluationShader:))]
384        #[unsafe(method_family = none)]
385        pub unsafe fn setTessellationEvaluationShader(
386            &self,
387            tessellation_evaluation_shader: Option<&NSString>,
388        );
389
390        /// Determines the receiver's geometry shader. Geometry shaders require OpenGL Core Profile.
391        #[unsafe(method(geometryShader))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn geometryShader(&self) -> Option<Retained<NSString>>;
394
395        /// Setter for [`geometryShader`][Self::geometryShader].
396        #[unsafe(method(setGeometryShader:))]
397        #[unsafe(method_family = none)]
398        pub unsafe fn setGeometryShader(&self, geometry_shader: Option<&NSString>);
399
400        /// Determines the receiver's vertex function name.
401        ///
402        /// The name of the vertex function (for Metal programs).
403        #[unsafe(method(vertexFunctionName))]
404        #[unsafe(method_family = none)]
405        pub unsafe fn vertexFunctionName(&self) -> Option<Retained<NSString>>;
406
407        /// Setter for [`vertexFunctionName`][Self::vertexFunctionName].
408        #[unsafe(method(setVertexFunctionName:))]
409        #[unsafe(method_family = none)]
410        pub unsafe fn setVertexFunctionName(&self, vertex_function_name: Option<&NSString>);
411
412        /// Determines the receiver's fragment function name.
413        ///
414        /// The name of the fragment function (for Metal programs).
415        #[unsafe(method(fragmentFunctionName))]
416        #[unsafe(method_family = none)]
417        pub unsafe fn fragmentFunctionName(&self) -> Option<Retained<NSString>>;
418
419        /// Setter for [`fragmentFunctionName`][Self::fragmentFunctionName].
420        #[unsafe(method(setFragmentFunctionName:))]
421        #[unsafe(method_family = none)]
422        pub unsafe fn setFragmentFunctionName(&self, fragment_function_name: Option<&NSString>);
423
424        #[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
425        /// Sets the block to call at render time to bind the buffer of the specified symbol of the receiver's program.
426        ///
427        /// Parameter `name`: The name of the buffer to bind.
428        ///
429        /// Parameter `frequency`: The frequency at which the block has to be invoked. Can be per frame, per node or per geometry or material. See SCNBufferBindingBlock above.
430        ///
431        /// Parameter `block`: The block that binds the buffer.
432        ///
433        /// This method can only be used with Metal based programs.
434        #[unsafe(method(handleBindingOfBufferNamed:frequency:usingBlock:))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn handleBindingOfBufferNamed_frequency_usingBlock(
437            &self,
438            name: &NSString,
439            frequency: SCNBufferFrequency,
440            block: SCNBufferBindingBlock,
441        );
442
443        /// Determines the receiver's fragment are opaque or not. Defaults to YES.
444        #[unsafe(method(isOpaque))]
445        #[unsafe(method_family = none)]
446        pub unsafe fn isOpaque(&self) -> bool;
447
448        /// Setter for [`isOpaque`][Self::isOpaque].
449        #[unsafe(method(setOpaque:))]
450        #[unsafe(method_family = none)]
451        pub unsafe fn setOpaque(&self, opaque: bool);
452
453        /// Associates a SceneKit semantic to a symbol.
454        ///
455        /// Parameter `semantic`: The SceneKit semantic to associate to the specified symbol.
456        ///
457        /// Parameter `symbol`: A symbol from the program source code.
458        ///
459        /// Parameter `options`: An optional dictionary. See the 'Semantic options' above.
460        ///
461        /// Associates semantics handled by the SceneKit runtime to a symbol from the program. Supported semantics are listed in SCNGeometry.h and SCNNode.h.
462        #[unsafe(method(setSemantic:forSymbol:options:))]
463        #[unsafe(method_family = none)]
464        pub unsafe fn setSemantic_forSymbol_options(
465            &self,
466            semantic: Option<&NSString>,
467            symbol: &NSString,
468            options: Option<&NSDictionary<NSString, AnyObject>>,
469        );
470
471        /// Retrieves the SceneKit semantic associated to a symbol from the program source code.
472        ///
473        /// Parameter `symbol`: A symbol from the program source code.
474        #[unsafe(method(semanticForSymbol:))]
475        #[unsafe(method_family = none)]
476        pub unsafe fn semanticForSymbol(&self, symbol: &NSString) -> Option<Retained<NSString>>;
477
478        /// Determines the receiver's delegate
479        #[unsafe(method(delegate))]
480        #[unsafe(method_family = none)]
481        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn SCNProgramDelegate>>>;
482
483        /// Setter for [`delegate`][Self::delegate].
484        #[unsafe(method(setDelegate:))]
485        #[unsafe(method_family = none)]
486        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn SCNProgramDelegate>>);
487
488        #[cfg(feature = "objc2-metal")]
489        #[cfg(not(target_os = "watchos"))]
490        /// Specifies the Metal library to use to locate the function names specified above.
491        ///
492        /// If set to nil the default library is used. Defaults to nil.
493        #[unsafe(method(library))]
494        #[unsafe(method_family = none)]
495        pub unsafe fn library(&self) -> Option<Retained<ProtocolObject<dyn MTLLibrary>>>;
496
497        #[cfg(feature = "objc2-metal")]
498        #[cfg(not(target_os = "watchos"))]
499        /// Setter for [`library`][Self::library].
500        #[unsafe(method(setLibrary:))]
501        #[unsafe(method_family = none)]
502        pub unsafe fn setLibrary(&self, library: Option<&ProtocolObject<dyn MTLLibrary>>);
503    );
504}
505
506/// Methods declared on superclass `NSObject`.
507impl SCNProgram {
508    extern_methods!(
509        #[unsafe(method(init))]
510        #[unsafe(method_family = init)]
511        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
512
513        #[unsafe(method(new))]
514        #[unsafe(method_family = new)]
515        pub unsafe fn new() -> Retained<Self>;
516    );
517}
518
519extern_protocol!(
520    /// The SCNProgramDelegate protocol declares the methods that an instance of SCNProgram invokes to delegate the binding of parameters.
521    ///
522    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnprogramdelegate?language=objc)
523    pub unsafe trait SCNProgramDelegate: NSObjectProtocol {
524        #[cfg(feature = "SCNRenderer")]
525        /// Invoked on the delegate to let it bind program values and/or also bind associated graphics resources (such as textures).
526        ///
527        /// Parameter `program`: The program to bind values for.
528        ///
529        /// Parameter `symbol`: The name of the symbol to bind a value for.
530        ///
531        /// Parameter `location`: The location of the symbol within the program object to be modified.
532        ///
533        /// Parameter `programID`: The program object.
534        ///
535        /// Parameter `renderer`: The renderer that is currently rendering the scene.
536        #[deprecated = "Use -[SCNShadable handleBindingOfSymbol:usingBlock:] instead"]
537        #[optional]
538        #[unsafe(method(program:bindValueForSymbol:atLocation:programID:renderer:))]
539        #[unsafe(method_family = none)]
540        unsafe fn program_bindValueForSymbol_atLocation_programID_renderer(
541            &self,
542            program: &SCNProgram,
543            symbol: &NSString,
544            location: c_uint,
545            program_id: c_uint,
546            renderer: &SCNRenderer,
547        ) -> bool;
548
549        #[cfg(feature = "SCNRenderer")]
550        /// Invoked on the delegate to let it unbind program values and/or also unbind associated graphic resources (such as textures).
551        ///
552        /// Parameter `program`: The program to unbind values for.
553        ///
554        /// Parameter `symbol`: The name of the symbol to unbind a value for.
555        ///
556        /// Parameter `location`: The location of the symbol within the program object to be modified.
557        ///
558        /// Parameter `programID`: The program object.
559        ///
560        /// Parameter `renderer`: The renderer that is currently rendering the scene.
561        #[deprecated = "Use -[SCNShadable handleUnbindingOfSymbol:usingBlock:] instead"]
562        #[optional]
563        #[unsafe(method(program:unbindValueForSymbol:atLocation:programID:renderer:))]
564        #[unsafe(method_family = none)]
565        unsafe fn program_unbindValueForSymbol_atLocation_programID_renderer(
566            &self,
567            program: &SCNProgram,
568            symbol: &NSString,
569            location: c_uint,
570            program_id: c_uint,
571            renderer: &SCNRenderer,
572        );
573
574        /// Invoked on the delegate whenever a compilation error occurs.
575        ///
576        /// Error domain is SCNErrorDomain.
577        ///
578        /// Parameter `program`: The program that generated a compilation error.
579        ///
580        /// Parameter `error`: The compilation error.
581        #[optional]
582        #[unsafe(method(program:handleError:))]
583        #[unsafe(method_family = none)]
584        unsafe fn program_handleError(&self, program: &SCNProgram, error: &NSError);
585
586        /// The delegate should implement this mehod and return NO if the fragments generated by the program are not opaque.
587        ///
588        /// Parameter `program`: The queried program.
589        ///
590        /// This is deprecated. Use SCNProgram's opaque property instead.
591        #[deprecated = "Use SCNProgram.opaque instead"]
592        #[optional]
593        #[unsafe(method(programIsOpaque:))]
594        #[unsafe(method_family = none)]
595        unsafe fn programIsOpaque(&self, program: &SCNProgram) -> bool;
596    }
597);
598
599extern "C" {
600    /// This is the entry point to operate on the geometry vertices, for example deforming them.
601    ///
602    /// It operates entirely in the vertex shader stage. It's input is the geometry structure:
603    ///
604    /// Structures available from the SCNShaderModifierEntryPointGeometry entry point:
605    ///
606    /// | struct SCNShaderGeometry {
607    /// |    float4 position;
608    /// |    float3 normal;
609    /// |    float4 tangent;
610    /// |    float4 color;
611    /// |    float2 texcoords[kSCNTexcoordCount];
612    /// | } _geometry;
613    /// |
614    /// | Access: ReadWrite
615    /// | Stages: Vertex shader only
616    ///
617    /// kSCNTexcoordCount is a constant integer set to the number of texture coordinates used.
618    ///
619    /// All the geometric fields (position, normal and tangent) are in model space. You can use one of the provided automatic uniforms
620    /// such as u_modelTransform or u_modelViewTransform if you want to operate in another space (but the results must stay in the model space, otherwise remaining computations won't be correct).
621    /// The texture coordinates are the raw values found in the mesh, they have not been transformed yet by their optional contentsTransform. The contentsTransform if any is applied after the geometry shader modifier.
622    ///
623    /// Example: Simple sinusoidal deformation
624    ///
625    /// GLSL
626    /// | uniform float Amplitude = 0.1;
627    /// |
628    /// | _geometry.position.xyz += _geometry.normal * (Amplitude * _geometry.position.y * _geometry.position.x) * sin(u_time);
629    ///
630    /// Metal Shading Language
631    /// | #pragma arguments
632    /// | float Amplitude;
633    /// |
634    /// | _geometry.position.xyz += _geometry.normal * (Amplitude * _geometry.position.y * _geometry.position.x) * sin(scn_frame.time);
635    ///
636    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointgeometry?language=objc)
637    pub static SCNShaderModifierEntryPointGeometry: &'static SCNShaderModifierEntryPoint;
638}
639
640extern "C" {
641    /// This is the entry point to alter the surface representation of the material, before the lighting has taken place.
642    ///
643    /// Structures available from the SCNShaderModifierEntryPointSurface entry point:
644    ///
645    /// | struct SCNShaderSurface {
646    /// |    float3 view;                       // Direction from the point on the surface toward the camera (V)
647    /// |    float3 position;                   // Position of the fragment
648    /// |    float3 normal;                     // Normal of the fragment (N)
649    /// |    float3 geometryNormal;             // Geometric normal of the fragment (normal map is ignored)
650    /// |    float3 tangent;                    // Tangent of the fragment
651    /// |    float3 bitangent;                  // Bitangent of the fragment
652    /// |    float4 ambient;                    // Ambient property of the fragment
653    /// |    float2 ambientTexcoord;            // Ambient texture coordinates
654    /// |    float4 diffuse;                    // Diffuse property of the fragment. Alpha contains the opacity.
655    /// |    float2 diffuseTexcoord;            // Diffuse texture coordinates
656    /// |    float4 specular;                   // Specular property of the fragment
657    /// |    float2 specularTexcoord;           // Specular texture coordinates
658    /// |    float4 emission;                   // Emission property of the fragment
659    /// |    float2 emissionTexcoord;           // Emission texture coordinates
660    /// |    float4 multiply;                   // Multiply property of the fragment
661    /// |    float2 multiplyTexcoord;           // Multiply texture coordinates
662    /// |    float4 transparent;                // Transparent property of the fragment
663    /// |    float2 transparentTexcoord;        // Transparent texture coordinates
664    /// |    float4 reflective;                 // Reflective property of the fragment
665    /// |    float  metalness;                  // Metalness property of the fragment
666    /// |    float2 metalnessTexcoord;          // Metalness texture coordinates
667    /// |    float  roughness;                  // Roughness property of the fragment
668    /// |    float2 roughnessTexcoord;          // Roughness texture coordinates
669    /// |    float  clearCoat;                  // Clear Coat property of the fragment.           Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
670    /// |    float2 clearCoatTexcoord;          // Clear Coat texture coordinates.                Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
671    /// |    float  clearCoatRoughness;         // Clear Coat Roughness property of the fragment. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
672    /// |    float2 clearCoatRoughnessTexcoord; // Clear Coat Roughness texture coordinates.      Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
673    /// |    float3 clearCoatNormal;            // Clear Coat Normal property of the fragment.    Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
674    /// |    float2 clearCoatNormalTexcoord;    // Clear Coat Normnal texture coordinates.        Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
675    /// |    float4 selfIllumination;           // Self Illumination property of the fragment.    Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `emission` in previous versions.
676    /// |    float2 selfIlluminationTexcoord;   // Self Illumination texture coordinates.         Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `emissionTexcoord` in previous versions.
677    /// |    float  ambientOcclusion;           // Ambient Occlusion property of the fragment.    Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `multiply` in previous versions.
678    /// |    float2 ambientOcclusionTexcoord;   // Ambient Occlusion texture coordinates.         Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `multiplyTexcoord` in previous versions.
679    /// |    float  shininess;                  // Shininess property of the fragment
680    /// |    float  fresnel;                    // Fresnel property of the fragment
681    /// | } _surface;
682    /// |
683    /// | Access: ReadWrite
684    /// | Stages: Fragment shader only
685    ///
686    /// All geometric fields are in view space.
687    /// All the other properties will be colors (texture have already been sampled at this stage) or floats. You can however do an extra sampling of standard textures if you want.
688    /// In this case the naming pattern is u_
689    /// <property
690    /// >Texture. For example u_diffuseTexture or u_reflectiveTexture. Note that you have to be sure that the material do have a texture
691    /// set for this property, otherwise you'll trigger a shader compilation error.
692    ///
693    /// Example: Procedural black and white stripes
694    ///
695    /// GLSL
696    /// | uniform float Scale = 12.0;
697    /// | uniform float Width = 0.25;
698    /// | uniform float Blend = 0.3;
699    /// |
700    /// | vec2 position = fract(_surface.diffuseTexcoord * Scale);
701    /// | float f1 = clamp(position.y / Blend, 0.0, 1.0);
702    /// | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0);
703    /// | f1 = f1 * (1.0 - f2);
704    /// | f1 = f1 * f1 * 2.0 * (3. * 2. * f1);
705    /// | _surface.diffuse = mix(vec4(1.0), vec4(0.0), f1);
706    ///
707    /// Metal Shading Language
708    /// | #pragma arguments
709    /// | float Scale;
710    /// | float Width;
711    /// | float Blend;
712    /// |
713    /// | float2 position = fract(_surface.diffuseTexcoord * Scale);
714    /// | float f1 = clamp(position.y / Blend, 0.0, 1.0);
715    /// | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0);
716    /// | f1 = f1 * (1.0 - f2);
717    /// | f1 = f1 * f1 * 2.0 * (3. * 2. * f1);
718    /// | _surface.diffuse = mix(float4(1.0), float4(0.0), f1);
719    ///
720    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointsurface?language=objc)
721    pub static SCNShaderModifierEntryPointSurface: &'static SCNShaderModifierEntryPoint;
722}
723
724extern "C" {
725    /// This is the entry point to provide custom lighting equation. The fragment will be called for each active light
726    /// of the scene and will need to accumulate lighting contribution for the vertex or the fragment in the _lightingContribution structure, using the light structure given.
727    ///
728    /// Structures available from the SCNShaderModifierEntryPointLightingModel entry point:
729    ///
730    /// | All the structures available from the SCNShaderModifierEntryPointSurface entry point
731    /// |
732    /// | Access: ReadOnly
733    /// | Stages: Vertex shader and fragment shader
734    ///
735    /// | struct SCNShaderLightingContribution {
736    /// |    float3 ambient;
737    /// |    float3 diffuse;
738    /// |    float3 specular;
739    /// | } _lightingContribution;
740    /// |
741    /// | Access: ReadWrite
742    /// | Stages: Vertex shader and fragment shader
743    ///
744    /// | struct SCNShaderLight {
745    /// |    float4 intensity;
746    /// |    float3 direction; // Direction from the point on the surface toward the light (L)
747    /// | } _light;
748    /// |
749    /// | Access: ReadOnly
750    /// | Stages: Vertex shader and fragment shader
751    ///
752    /// Example: Wrap diffuse lighting
753    ///
754    /// GLSL
755    /// | uniform float WrapFactor = 0.5;
756    /// |
757    /// | float dotProduct = (WrapFactor + max(0.0, dot(_surface.normal,_light.direction))) / (1 + WrapFactor);
758    /// | _lightingContribution.diffuse += (dotProduct * _light.intensity.rgb);
759    /// | vec3 halfVector = normalize(_light.direction + _surface.view);
760    /// | dotProduct = max(0.0, pow(max(0.0, dot(_surface.normal, halfVector)), _surface.shininess));
761    /// | _lightingContribution.specular += (dotProduct * _light.intensity.rgb);
762    ///
763    /// Metal Shading Language
764    /// | #pragma arguments
765    /// | float WrapFactor;
766    /// |
767    /// | float dotProduct = (WrapFactor + max(0.0, dot(_surface.normal,_light.direction))) / (1 + WrapFactor);
768    /// | _lightingContribution.diffuse += (dotProduct * _light.intensity.rgb);
769    /// | float3 halfVector = normalize(_light.direction + _surface.view);
770    /// | dotProduct = max(0.0, pow(max(0.0, dot(_surface.normal, halfVector)), _surface.shininess));
771    /// | _lightingContribution.specular += (dotProduct * _light.intensity.rgb);
772    ///
773    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointlightingmodel?language=objc)
774    pub static SCNShaderModifierEntryPointLightingModel: &'static SCNShaderModifierEntryPoint;
775}
776
777extern "C" {
778    /// This is the last entry point in the fragment shader, where you can alter the final color returned by the shader.
779    ///
780    /// You can alter the final color by reading and writing to the output color via the output structure below.
781    ///
782    /// Structures available from the SCNShaderModifierEntryPointFragment entry point:
783    ///
784    /// | All the structures available from the SCNShaderModifierEntryPointSurface entry point
785    /// |
786    /// | Access: ReadOnly
787    /// | Stages: Fragment shader only
788    ///
789    /// | struct SCNFramebuffer {
790    /// |    float4 color; // Contents of the destination framebuffer corresponding to the fragment being processed
791    /// | } _framebuffer;  // Available since macOS 13, iOS 16, tvOS 16 and watchOS 9.
792    /// |
793    /// | Access: ReadOnly
794    /// | Stages: Fragment shader only
795    ///
796    /// | struct SCNShaderOutput {
797    /// |    float4 color;
798    /// | } _output;
799    /// |
800    /// | Access: ReadWrite
801    /// | Stages: Fragment shader only
802    ///
803    /// Example: Inverse final color
804    ///
805    /// GLSL
806    /// | _output.color.rgb = vec3(1.0) - _output.color.rgb;
807    ///
808    /// Metal Shading Language
809    /// | _output.color.rgb = 1.0 - _output.color.rgb;
810    ///
811    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointfragment?language=objc)
812    pub static SCNShaderModifierEntryPointFragment: &'static SCNShaderModifierEntryPoint;
813}