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