Oolite
Loading...
Searching...
No Matches
OOShaderUniform.h
Go to the documentation of this file.
1/*
2
3OOShaderUniform.h
4
5Manages a uniform variable for OOShaderMaterial.
6
7
8Copyright (C) 2007-2013 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30#import "OOShaderMaterial.h"
31
32#if OO_SHADERS
33
34#import "OOMaths.h"
35
36@class OOColor;
37
38@interface OOShaderUniform : NSObject {
39@private
40 NSString* name;
41 GLint location;
42 uint8_t isBinding : 1,
43 // flags that apply only to bindings:
44 isActiveBinding : 1,
45 convertClamp : 1,
46 convertNormalize : 1,
47 convertToMatrix : 1,
48 bindToSuper : 1;
49 uint8_t type;
50 union {
51 GLint constInt;
52 GLfloat constFloat;
53 GLfloat constVector[4];
54 OOMatrix constMatrix;
55 struct
56 {
57 OOWeakReference* object;
58 SEL selector;
59 IMP method;
60 } binding;
61 } value;
62}
63
64- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram intValue:(GLint)constValue;
65- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram floatValue:(GLfloat)constValue;
66- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram vectorValue:(GLfloat[4])constValue;
67- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram colorValue:(OOColor*)constValue; // Converted to vector
68- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram quaternionValue:(Quaternion)constValue asMatrix:(BOOL)asMatrix; // Converted to vector (in xyzw order, not wxyz!) or rotation matrix.
69- (id)initWithName:(NSString*)uniformName shaderProgram:(OOShaderProgram*)shaderProgram matrixValue:(OOMatrix)constValue;
70
71/* "Convert" has different meanings for different types.
72 For float and int types, it clamps to the range [0, 1].
73 For vector types, it normalizes.
74 For quaternions, it converts to rotation matrix (instead of vec4).
75*/
76- (id)initWithName:(NSString*)uniformName
77 shaderProgram:(OOShaderProgram*)shaderProgram
78 boundToObject:(id<OOWeakReferenceSupport>)target
79 property:(SEL)selector
80 convertOptions:(OOUniformConvertOptions)options;
81
82- (void)apply;
83
84- (void)setBindingTarget:(id<OOWeakReferenceSupport>)target;
85
86@end
87
88#endif // OO_SHADERS
struct OOMatrix OOMatrix