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