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::DynBlock<
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::DynBlock<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
325extern_conformance!(
326    unsafe impl NSCoding for SCNProgram {}
327);
328
329extern_conformance!(
330    unsafe impl NSCopying for SCNProgram {}
331);
332
333unsafe impl CopyingHelper for SCNProgram {
334    type Result = Self;
335}
336
337extern_conformance!(
338    unsafe impl NSObjectProtocol for SCNProgram {}
339);
340
341extern_conformance!(
342    unsafe impl NSSecureCoding for SCNProgram {}
343);
344
345impl SCNProgram {
346    extern_methods!(
347        /// Creates and initialize a program instance.
348        #[unsafe(method(program))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn program() -> Retained<Self>;
351
352        /// Determines the receiver's vertex shader.
353        #[unsafe(method(vertexShader))]
354        #[unsafe(method_family = none)]
355        pub unsafe fn vertexShader(&self) -> Option<Retained<NSString>>;
356
357        /// Setter for [`vertexShader`][Self::vertexShader].
358        #[unsafe(method(setVertexShader:))]
359        #[unsafe(method_family = none)]
360        pub unsafe fn setVertexShader(&self, vertex_shader: Option<&NSString>);
361
362        /// Determines the receiver's fragment shader.
363        #[unsafe(method(fragmentShader))]
364        #[unsafe(method_family = none)]
365        pub unsafe fn fragmentShader(&self) -> Option<Retained<NSString>>;
366
367        /// Setter for [`fragmentShader`][Self::fragmentShader].
368        #[unsafe(method(setFragmentShader:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn setFragmentShader(&self, fragment_shader: Option<&NSString>);
371
372        /// Determines the receiver's tessellation control shader. Tessellation shaders require OpenGL Core Profile.
373        #[unsafe(method(tessellationControlShader))]
374        #[unsafe(method_family = none)]
375        pub unsafe fn tessellationControlShader(&self) -> Option<Retained<NSString>>;
376
377        /// Setter for [`tessellationControlShader`][Self::tessellationControlShader].
378        #[unsafe(method(setTessellationControlShader:))]
379        #[unsafe(method_family = none)]
380        pub unsafe fn setTessellationControlShader(
381            &self,
382            tessellation_control_shader: Option<&NSString>,
383        );
384
385        /// Determines the receiver's tessellation evaluation shader. Tessellation shaders require OpenGL Core Profile.
386        #[unsafe(method(tessellationEvaluationShader))]
387        #[unsafe(method_family = none)]
388        pub unsafe fn tessellationEvaluationShader(&self) -> Option<Retained<NSString>>;
389
390        /// Setter for [`tessellationEvaluationShader`][Self::tessellationEvaluationShader].
391        #[unsafe(method(setTessellationEvaluationShader:))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn setTessellationEvaluationShader(
394            &self,
395            tessellation_evaluation_shader: Option<&NSString>,
396        );
397
398        /// Determines the receiver's geometry shader. Geometry shaders require OpenGL Core Profile.
399        #[unsafe(method(geometryShader))]
400        #[unsafe(method_family = none)]
401        pub unsafe fn geometryShader(&self) -> Option<Retained<NSString>>;
402
403        /// Setter for [`geometryShader`][Self::geometryShader].
404        #[unsafe(method(setGeometryShader:))]
405        #[unsafe(method_family = none)]
406        pub unsafe fn setGeometryShader(&self, geometry_shader: Option<&NSString>);
407
408        /// Determines the receiver's vertex function name.
409        ///
410        /// The name of the vertex function (for Metal programs).
411        #[unsafe(method(vertexFunctionName))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn vertexFunctionName(&self) -> Option<Retained<NSString>>;
414
415        /// Setter for [`vertexFunctionName`][Self::vertexFunctionName].
416        #[unsafe(method(setVertexFunctionName:))]
417        #[unsafe(method_family = none)]
418        pub unsafe fn setVertexFunctionName(&self, vertex_function_name: Option<&NSString>);
419
420        /// Determines the receiver's fragment function name.
421        ///
422        /// The name of the fragment function (for Metal programs).
423        #[unsafe(method(fragmentFunctionName))]
424        #[unsafe(method_family = none)]
425        pub unsafe fn fragmentFunctionName(&self) -> Option<Retained<NSString>>;
426
427        /// Setter for [`fragmentFunctionName`][Self::fragmentFunctionName].
428        #[unsafe(method(setFragmentFunctionName:))]
429        #[unsafe(method_family = none)]
430        pub unsafe fn setFragmentFunctionName(&self, fragment_function_name: Option<&NSString>);
431
432        #[cfg(all(feature = "SCNNode", feature = "SCNRenderer", feature = "block2"))]
433        /// Sets the block to call at render time to bind the buffer of the specified symbol of the receiver's program.
434        ///
435        /// Parameter `name`: The name of the buffer to bind.
436        ///
437        /// 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.
438        ///
439        /// Parameter `block`: The block that binds the buffer.
440        ///
441        /// This method can only be used with Metal based programs.
442        #[unsafe(method(handleBindingOfBufferNamed:frequency:usingBlock:))]
443        #[unsafe(method_family = none)]
444        pub unsafe fn handleBindingOfBufferNamed_frequency_usingBlock(
445            &self,
446            name: &NSString,
447            frequency: SCNBufferFrequency,
448            block: SCNBufferBindingBlock,
449        );
450
451        /// Determines the receiver's fragment are opaque or not. Defaults to YES.
452        #[unsafe(method(isOpaque))]
453        #[unsafe(method_family = none)]
454        pub unsafe fn isOpaque(&self) -> bool;
455
456        /// Setter for [`isOpaque`][Self::isOpaque].
457        #[unsafe(method(setOpaque:))]
458        #[unsafe(method_family = none)]
459        pub unsafe fn setOpaque(&self, opaque: bool);
460
461        /// Associates a SceneKit semantic to a symbol.
462        ///
463        /// Parameter `semantic`: The SceneKit semantic to associate to the specified symbol.
464        ///
465        /// Parameter `symbol`: A symbol from the program source code.
466        ///
467        /// Parameter `options`: An optional dictionary. See the 'Semantic options' above.
468        ///
469        /// Associates semantics handled by the SceneKit runtime to a symbol from the program. Supported semantics are listed in SCNGeometry.h and SCNNode.h.
470        #[unsafe(method(setSemantic:forSymbol:options:))]
471        #[unsafe(method_family = none)]
472        pub unsafe fn setSemantic_forSymbol_options(
473            &self,
474            semantic: Option<&NSString>,
475            symbol: &NSString,
476            options: Option<&NSDictionary<NSString, AnyObject>>,
477        );
478
479        /// Retrieves the SceneKit semantic associated to a symbol from the program source code.
480        ///
481        /// Parameter `symbol`: A symbol from the program source code.
482        #[unsafe(method(semanticForSymbol:))]
483        #[unsafe(method_family = none)]
484        pub unsafe fn semanticForSymbol(&self, symbol: &NSString) -> Option<Retained<NSString>>;
485
486        /// Determines the receiver's delegate
487        #[unsafe(method(delegate))]
488        #[unsafe(method_family = none)]
489        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn SCNProgramDelegate>>>;
490
491        /// Setter for [`delegate`][Self::delegate].
492        #[unsafe(method(setDelegate:))]
493        #[unsafe(method_family = none)]
494        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn SCNProgramDelegate>>);
495
496        #[cfg(feature = "objc2-metal")]
497        #[cfg(not(target_os = "watchos"))]
498        /// Specifies the Metal library to use to locate the function names specified above.
499        ///
500        /// If set to nil the default library is used. Defaults to nil.
501        #[unsafe(method(library))]
502        #[unsafe(method_family = none)]
503        pub unsafe fn library(&self) -> Option<Retained<ProtocolObject<dyn MTLLibrary>>>;
504
505        #[cfg(feature = "objc2-metal")]
506        #[cfg(not(target_os = "watchos"))]
507        /// Setter for [`library`][Self::library].
508        #[unsafe(method(setLibrary:))]
509        #[unsafe(method_family = none)]
510        pub unsafe fn setLibrary(&self, library: Option<&ProtocolObject<dyn MTLLibrary>>);
511    );
512}
513
514/// Methods declared on superclass `NSObject`.
515impl SCNProgram {
516    extern_methods!(
517        #[unsafe(method(init))]
518        #[unsafe(method_family = init)]
519        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
520
521        #[unsafe(method(new))]
522        #[unsafe(method_family = new)]
523        pub unsafe fn new() -> Retained<Self>;
524    );
525}
526
527extern_protocol!(
528    /// The SCNProgramDelegate protocol declares the methods that an instance of SCNProgram invokes to delegate the binding of parameters.
529    ///
530    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnprogramdelegate?language=objc)
531    pub unsafe trait SCNProgramDelegate: NSObjectProtocol {
532        #[cfg(feature = "SCNRenderer")]
533        /// Invoked on the delegate to let it bind program values and/or also bind associated graphics resources (such as textures).
534        ///
535        /// Parameter `program`: The program to bind values for.
536        ///
537        /// Parameter `symbol`: The name of the symbol to bind a value for.
538        ///
539        /// Parameter `location`: The location of the symbol within the program object to be modified.
540        ///
541        /// Parameter `programID`: The program object.
542        ///
543        /// Parameter `renderer`: The renderer that is currently rendering the scene.
544        #[deprecated = "Use -[SCNShadable handleBindingOfSymbol:usingBlock:] instead"]
545        #[optional]
546        #[unsafe(method(program:bindValueForSymbol:atLocation:programID:renderer:))]
547        #[unsafe(method_family = none)]
548        unsafe fn program_bindValueForSymbol_atLocation_programID_renderer(
549            &self,
550            program: &SCNProgram,
551            symbol: &NSString,
552            location: c_uint,
553            program_id: c_uint,
554            renderer: &SCNRenderer,
555        ) -> bool;
556
557        #[cfg(feature = "SCNRenderer")]
558        /// Invoked on the delegate to let it unbind program values and/or also unbind associated graphic resources (such as textures).
559        ///
560        /// Parameter `program`: The program to unbind values for.
561        ///
562        /// Parameter `symbol`: The name of the symbol to unbind a value for.
563        ///
564        /// Parameter `location`: The location of the symbol within the program object to be modified.
565        ///
566        /// Parameter `programID`: The program object.
567        ///
568        /// Parameter `renderer`: The renderer that is currently rendering the scene.
569        #[deprecated = "Use -[SCNShadable handleUnbindingOfSymbol:usingBlock:] instead"]
570        #[optional]
571        #[unsafe(method(program:unbindValueForSymbol:atLocation:programID:renderer:))]
572        #[unsafe(method_family = none)]
573        unsafe fn program_unbindValueForSymbol_atLocation_programID_renderer(
574            &self,
575            program: &SCNProgram,
576            symbol: &NSString,
577            location: c_uint,
578            program_id: c_uint,
579            renderer: &SCNRenderer,
580        );
581
582        /// Invoked on the delegate whenever a compilation error occurs.
583        ///
584        /// Error domain is SCNErrorDomain.
585        ///
586        /// Parameter `program`: The program that generated a compilation error.
587        ///
588        /// Parameter `error`: The compilation error.
589        #[optional]
590        #[unsafe(method(program:handleError:))]
591        #[unsafe(method_family = none)]
592        unsafe fn program_handleError(&self, program: &SCNProgram, error: &NSError);
593
594        /// The delegate should implement this mehod and return NO if the fragments generated by the program are not opaque.
595        ///
596        /// Parameter `program`: The queried program.
597        ///
598        /// This is deprecated. Use SCNProgram's opaque property instead.
599        #[deprecated = "Use SCNProgram.opaque instead"]
600        #[optional]
601        #[unsafe(method(programIsOpaque:))]
602        #[unsafe(method_family = none)]
603        unsafe fn programIsOpaque(&self, program: &SCNProgram) -> bool;
604    }
605);
606
607extern "C" {
608    /// This is the entry point to operate on the geometry vertices, for example deforming them.
609    ///
610    /// It operates entirely in the vertex shader stage. It's input is the geometry structure:
611    ///
612    /// Structures available from the SCNShaderModifierEntryPointGeometry entry point:
613    ///
614    /// | struct SCNShaderGeometry {
615    /// |    float4 position;
616    /// |    float3 normal;
617    /// |    float4 tangent;
618    /// |    float4 color;
619    /// |    float2 texcoords[kSCNTexcoordCount];
620    /// | } _geometry;
621    /// |
622    /// | Access: ReadWrite
623    /// | Stages: Vertex shader only
624    ///
625    /// kSCNTexcoordCount is a constant integer set to the number of texture coordinates used.
626    ///
627    /// All the geometric fields (position, normal and tangent) are in model space. You can use one of the provided automatic uniforms
628    /// 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).
629    /// 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.
630    ///
631    /// Example: Simple sinusoidal deformation
632    ///
633    /// GLSL
634    /// | uniform float Amplitude = 0.1;
635    /// |
636    /// | _geometry.position.xyz += _geometry.normal * (Amplitude * _geometry.position.y * _geometry.position.x) * sin(u_time);
637    ///
638    /// Metal Shading Language
639    /// | #pragma arguments
640    /// | float Amplitude;
641    /// |
642    /// | _geometry.position.xyz += _geometry.normal * (Amplitude * _geometry.position.y * _geometry.position.x) * sin(scn_frame.time);
643    ///
644    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointgeometry?language=objc)
645    pub static SCNShaderModifierEntryPointGeometry: &'static SCNShaderModifierEntryPoint;
646}
647
648extern "C" {
649    /// This is the entry point to alter the surface representation of the material, before the lighting has taken place.
650    ///
651    /// Structures available from the SCNShaderModifierEntryPointSurface entry point:
652    ///
653    /// | struct SCNShaderSurface {
654    /// |    float3 view;                       // Direction from the point on the surface toward the camera (V)
655    /// |    float3 position;                   // Position of the fragment
656    /// |    float3 normal;                     // Normal of the fragment (N)
657    /// |    float3 geometryNormal;             // Geometric normal of the fragment (normal map is ignored)
658    /// |    float3 tangent;                    // Tangent of the fragment
659    /// |    float3 bitangent;                  // Bitangent of the fragment
660    /// |    float4 ambient;                    // Ambient property of the fragment
661    /// |    float2 ambientTexcoord;            // Ambient texture coordinates
662    /// |    float4 diffuse;                    // Diffuse property of the fragment. Alpha contains the opacity.
663    /// |    float2 diffuseTexcoord;            // Diffuse texture coordinates
664    /// |    float4 specular;                   // Specular property of the fragment
665    /// |    float2 specularTexcoord;           // Specular texture coordinates
666    /// |    float4 emission;                   // Emission property of the fragment
667    /// |    float2 emissionTexcoord;           // Emission texture coordinates
668    /// |    float4 multiply;                   // Multiply property of the fragment
669    /// |    float2 multiplyTexcoord;           // Multiply texture coordinates
670    /// |    float4 transparent;                // Transparent property of the fragment
671    /// |    float2 transparentTexcoord;        // Transparent texture coordinates
672    /// |    float4 reflective;                 // Reflective property of the fragment
673    /// |    float  metalness;                  // Metalness property of the fragment
674    /// |    float2 metalnessTexcoord;          // Metalness texture coordinates
675    /// |    float  roughness;                  // Roughness property of the fragment
676    /// |    float2 roughnessTexcoord;          // Roughness texture coordinates
677    /// |    float  clearCoat;                  // Clear Coat property of the fragment.           Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
678    /// |    float2 clearCoatTexcoord;          // Clear Coat texture coordinates.                Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
679    /// |    float  clearCoatRoughness;         // Clear Coat Roughness property of the fragment. Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
680    /// |    float2 clearCoatRoughnessTexcoord; // Clear Coat Roughness texture coordinates.      Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
681    /// |    float3 clearCoatNormal;            // Clear Coat Normal property of the fragment.    Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
682    /// |    float2 clearCoatNormalTexcoord;    // Clear Coat Normnal texture coordinates.        Available since macOS 10.15, iOS 13, tvOS 13 and watchOS 6.
683    /// |    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.
684    /// |    float2 selfIlluminationTexcoord;   // Self Illumination texture coordinates.         Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `emissionTexcoord` in previous versions.
685    /// |    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.
686    /// |    float2 ambientOcclusionTexcoord;   // Ambient Occlusion texture coordinates.         Available since macOS 10.13, iOS 11, tvOS 11 and watchOS 4. Available as `multiplyTexcoord` in previous versions.
687    /// |    float  shininess;                  // Shininess property of the fragment
688    /// |    float  fresnel;                    // Fresnel property of the fragment
689    /// | } _surface;
690    /// |
691    /// | Access: ReadWrite
692    /// | Stages: Fragment shader only
693    ///
694    /// All geometric fields are in view space.
695    /// 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.
696    /// In this case the naming pattern is u_
697    /// <property
698    /// >Texture. For example u_diffuseTexture or u_reflectiveTexture. Note that you have to be sure that the material do have a texture
699    /// set for this property, otherwise you'll trigger a shader compilation error.
700    ///
701    /// Example: Procedural black and white stripes
702    ///
703    /// GLSL
704    /// | uniform float Scale = 12.0;
705    /// | uniform float Width = 0.25;
706    /// | uniform float Blend = 0.3;
707    /// |
708    /// | vec2 position = fract(_surface.diffuseTexcoord * Scale);
709    /// | float f1 = clamp(position.y / Blend, 0.0, 1.0);
710    /// | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0);
711    /// | f1 = f1 * (1.0 - f2);
712    /// | f1 = f1 * f1 * 2.0 * (3. * 2. * f1);
713    /// | _surface.diffuse = mix(vec4(1.0), vec4(0.0), f1);
714    ///
715    /// Metal Shading Language
716    /// | #pragma arguments
717    /// | float Scale;
718    /// | float Width;
719    /// | float Blend;
720    /// |
721    /// | float2 position = fract(_surface.diffuseTexcoord * Scale);
722    /// | float f1 = clamp(position.y / Blend, 0.0, 1.0);
723    /// | float f2 = clamp((position.y - Width) / Blend, 0.0, 1.0);
724    /// | f1 = f1 * (1.0 - f2);
725    /// | f1 = f1 * f1 * 2.0 * (3. * 2. * f1);
726    /// | _surface.diffuse = mix(float4(1.0), float4(0.0), f1);
727    ///
728    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointsurface?language=objc)
729    pub static SCNShaderModifierEntryPointSurface: &'static SCNShaderModifierEntryPoint;
730}
731
732extern "C" {
733    /// This is the entry point to provide custom lighting equation. The fragment will be called for each active light
734    /// 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.
735    ///
736    /// Structures available from the SCNShaderModifierEntryPointLightingModel entry point:
737    ///
738    /// | All the structures available from the SCNShaderModifierEntryPointSurface entry point
739    /// |
740    /// | Access: ReadOnly
741    /// | Stages: Vertex shader and fragment shader
742    ///
743    /// | struct SCNShaderLightingContribution {
744    /// |    float3 ambient;
745    /// |    float3 diffuse;
746    /// |    float3 specular;
747    /// | } _lightingContribution;
748    /// |
749    /// | Access: ReadWrite
750    /// | Stages: Vertex shader and fragment shader
751    ///
752    /// | struct SCNShaderLight {
753    /// |    float4 intensity;
754    /// |    float3 direction; // Direction from the point on the surface toward the light (L)
755    /// | } _light;
756    /// |
757    /// | Access: ReadOnly
758    /// | Stages: Vertex shader and fragment shader
759    ///
760    /// Example: Wrap diffuse lighting
761    ///
762    /// GLSL
763    /// | uniform float WrapFactor = 0.5;
764    /// |
765    /// | float dotProduct = (WrapFactor + max(0.0, dot(_surface.normal,_light.direction))) / (1 + WrapFactor);
766    /// | _lightingContribution.diffuse += (dotProduct * _light.intensity.rgb);
767    /// | vec3 halfVector = normalize(_light.direction + _surface.view);
768    /// | dotProduct = max(0.0, pow(max(0.0, dot(_surface.normal, halfVector)), _surface.shininess));
769    /// | _lightingContribution.specular += (dotProduct * _light.intensity.rgb);
770    ///
771    /// Metal Shading Language
772    /// | #pragma arguments
773    /// | float WrapFactor;
774    /// |
775    /// | float dotProduct = (WrapFactor + max(0.0, dot(_surface.normal,_light.direction))) / (1 + WrapFactor);
776    /// | _lightingContribution.diffuse += (dotProduct * _light.intensity.rgb);
777    /// | float3 halfVector = normalize(_light.direction + _surface.view);
778    /// | dotProduct = max(0.0, pow(max(0.0, dot(_surface.normal, halfVector)), _surface.shininess));
779    /// | _lightingContribution.specular += (dotProduct * _light.intensity.rgb);
780    ///
781    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointlightingmodel?language=objc)
782    pub static SCNShaderModifierEntryPointLightingModel: &'static SCNShaderModifierEntryPoint;
783}
784
785extern "C" {
786    /// This is the last entry point in the fragment shader, where you can alter the final color returned by the shader.
787    ///
788    /// You can alter the final color by reading and writing to the output color via the output structure below.
789    ///
790    /// Structures available from the SCNShaderModifierEntryPointFragment entry point:
791    ///
792    /// | All the structures available from the SCNShaderModifierEntryPointSurface entry point
793    /// |
794    /// | Access: ReadOnly
795    /// | Stages: Fragment shader only
796    ///
797    /// | struct SCNFramebuffer {
798    /// |    float4 color; // Contents of the destination framebuffer corresponding to the fragment being processed
799    /// | } _framebuffer;  // Available since macOS 13, iOS 16, tvOS 16 and watchOS 9.
800    /// |
801    /// | Access: ReadOnly
802    /// | Stages: Fragment shader only
803    ///
804    /// | struct SCNShaderOutput {
805    /// |    float4 color;
806    /// | } _output;
807    /// |
808    /// | Access: ReadWrite
809    /// | Stages: Fragment shader only
810    ///
811    /// Example: Inverse final color
812    ///
813    /// GLSL
814    /// | _output.color.rgb = vec3(1.0) - _output.color.rgb;
815    ///
816    /// Metal Shading Language
817    /// | _output.color.rgb = 1.0 - _output.color.rgb;
818    ///
819    /// See also [Apple's documentation](https://developer.apple.com/documentation/scenekit/scnshadermodifierentrypointfragment?language=objc)
820    pub static SCNShaderModifierEntryPointFragment: &'static SCNShaderModifierEntryPoint;
821}