Line data Source code
1 0 : /* 2 : 3 : OOMesh.h 4 : 5 : Standard OODrawable for static meshes from DAT files. OOMeshes are immutable 6 : (and can therefore be shared). Avoid the temptation to add externally-visible 7 : mutator methods as it will break such sharing. (Sharing will be implemented 8 : when ship types are turned into objects instead of dictionaries; this is 9 : currently slated for post-1.70. -- Ahruman) 10 : 11 : Hmm. On further consideration, sharing will be problematic because of material 12 : bindings. Two possible solutions: separate mesh data into shared object with 13 : each mesh instance having its own set of materials but shared data, or 14 : retarget bindings each frame. -- Ahruman 15 : 16 : 17 : Oolite 18 : Copyright (C) 2004-2013 Giles C Williams and contributors 19 : 20 : This program is free software; you can redistribute it and/or 21 : modify it under the terms of the GNU General Public License 22 : as published by the Free Software Foundation; either version 2 23 : of the License, or (at your option) any later version. 24 : 25 : This program is distributed in the hope that it will be useful, 26 : but WITHOUT ANY WARRANTY; without even the implied warranty of 27 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 : GNU General Public License for more details. 29 : 30 : You should have received a copy of the GNU General Public License 31 : along with this program; if not, write to the Free Software 32 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 33 : MA 02110-1301, USA. 34 : 35 : */ 36 : 37 : #import "OODrawable.h" 38 : #import "OOOpenGL.h" 39 : #import "OOWeakReference.h" 40 : #import "OOOpenGLExtensionManager.h" 41 : 42 : @class OOMaterial, Octree; 43 : 44 : 45 0 : #define OOMESH_PROFILE 0 46 : #if OOMESH_PROFILE 47 : @class OOProfilingStopwatch; 48 : #endif 49 : 50 : 51 0 : enum 52 : { 53 : kOOMeshMaxMaterials = 8 54 : }; 55 : 56 : 57 0 : typedef uint16_t OOMeshSmoothGroup; 58 0 : typedef uint8_t OOMeshMaterialIndex, OOMeshMaterialCount; 59 0 : typedef uint32_t OOMeshVertexCount; 60 0 : typedef uint32_t OOMeshFaceCount; 61 0 : typedef uint8_t OOMeshFaceVertexCount; 62 : 63 : 64 0 : typedef struct 65 : { 66 0 : OOMeshSmoothGroup smoothGroup; 67 0 : OOMeshMaterialIndex materialIndex; 68 0 : GLuint vertex[3]; 69 : 70 0 : Vector normal; 71 0 : Vector tangent; 72 0 : GLfloat s[3]; 73 0 : GLfloat t[3]; 74 : } OOMeshFace; 75 : 76 : 77 0 : typedef struct 78 : { 79 0 : GLint *indexArray; 80 0 : GLfloat *textureUVArray; 81 0 : Vector *vertexArray; 82 0 : Vector *normalArray; 83 0 : Vector *tangentArray; 84 : 85 0 : GLuint count; 86 : } OOMeshDisplayLists; 87 : 88 : 89 0 : @interface OOMesh: OODrawable <NSCopying> 90 : { 91 : @private 92 : uint8_t _normalMode: 2, 93 0 : brokenInRender: 1, 94 0 : listsReady: 1; 95 0 : 96 : OOMeshMaterialCount materialCount; 97 0 : OOMeshVertexCount vertexCount; 98 0 : OOMeshFaceCount faceCount; 99 0 : 100 : NSString *baseFile; 101 0 : NSString *baseFileOctreeCacheRef; 102 0 : BOOL _cacheWriteable; 103 0 : 104 : Vector *_vertices; 105 0 : Vector *_normals; 106 0 : Vector *_tangents; 107 0 : OOMeshFace *_faces; 108 0 : 109 : // Redundancy! Needs fixing. 110 : OOMeshDisplayLists _displayLists; 111 0 : 112 : NSRange triangle_range[kOOMeshMaxMaterials]; 113 0 : NSString *materialKeys[kOOMeshMaxMaterials]; 114 0 : OOMaterial *materials[kOOMeshMaxMaterials]; 115 0 : GLuint displayList0; 116 0 : 117 : GLfloat collisionRadius; 118 0 : GLfloat maxDrawDistance; 119 0 : BoundingBox boundingBox; 120 0 : 121 : Octree *octree; 122 0 : 123 : NSMutableDictionary *_retainedObjects; 124 0 : 125 : NSDictionary *_materialDict; 126 0 : NSDictionary *_shadersDict; 127 0 : NSString *_cacheKey; 128 0 : NSDictionary *_shaderMacros; 129 0 : id _shaderBindingTarget; 130 0 : 131 : Vector _lastPosition; 132 0 : OOMatrix _lastRotMatrix; 133 0 : BoundingBox _lastBoundingBox; 134 0 : 135 : #if OO_MULTITEXTURE 136 : NSUInteger _textureUnitCount; 137 : #endif 138 : 139 : #if OOMESH_PROFILE 140 : OOProfilingStopwatch *_stopwatch; 141 : double _stopwatchLastTime; 142 : #endif 143 : } 144 : 145 : + (instancetype) meshWithName:(NSString *)name 146 0 : cacheKey:(NSString *)cacheKey 147 : materialDictionary:(NSDictionary *)materialDict 148 : shadersDictionary:(NSDictionary *)shadersDict 149 : smooth:(BOOL)smooth 150 : shaderMacros:(NSDictionary *)macros 151 : shaderBindingTarget:(id<OOWeakReferenceSupport>)object; 152 : 153 : + (instancetype) meshWithName:(NSString *)name 154 0 : cacheKey:(NSString *)cacheKey 155 : materialDictionary:(NSDictionary *)materialDict 156 : shadersDictionary:(NSDictionary *)shadersDict 157 : smooth:(BOOL)smooth 158 : shaderMacros:(NSDictionary *)macros 159 : shaderBindingTarget:(id<OOWeakReferenceSupport>)object 160 : scaleFactor:(float)factor 161 : cacheWriteable:(BOOL)cacheWriteable; 162 : 163 : 164 : + (OOMaterial *) placeholderMaterial; 165 0 : 166 : - (NSString *) modelName; 167 0 : 168 : - (void) rebindMaterials; 169 0 : 170 : - (NSDictionary *) materials; 171 0 : - (NSDictionary *) shaders; 172 0 : 173 : - (size_t) vertexCount; 174 0 : - (size_t) faceCount; 175 0 : 176 : - (Octree *) octree; 177 0 : 178 : // This needs a better name. 179 : - (BoundingBox) findBoundingBoxRelativeToPosition:(Vector)opv 180 0 : basis:(Vector)ri :(Vector)rj :(Vector)rk 181 : selfPosition:(Vector)position 182 : selfBasis:(Vector)si :(Vector)sj :(Vector)sk; 183 : - (BoundingBox) findSubentityBoundingBoxWithPosition:(Vector)position rotMatrix:(OOMatrix)rotMatrix; 184 0 : 185 : - (OOMesh *) meshRescaledBy:(GLfloat)scaleFactor; 186 0 : 187 : @end 188 : 189 : 190 : #import "OOCacheManager.h" 191 : @interface OOCacheManager (Octree) 192 : 193 : + (Octree *)octreeForModel:(NSString *)inKey; 194 0 : + (void)setOctree:(Octree *)inOctree forModel:(NSString *)inKey; 195 0 : 196 : @end