![]() |
WhirlyGlobe
1.2
A 3D interactive globe toolkit for iOS
|
00001 /* 00002 * GlobeScene.h 00003 * WhirlyGlobeLib 00004 * 00005 * Created by Steve Gifford on 1/3/11. 00006 * Copyright 2011 mousebird consulting 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 */ 00020 00021 00022 #import <OpenGLES/ES1/gl.h> 00023 #import <OpenGLES/ES1/glext.h> 00024 #import <OpenGLES/ES2/gl.h> 00025 #import <OpenGLES/ES2/glext.h> 00026 00027 #import <vector> 00028 #import <set> 00029 #import "WhirlyVector.h" 00030 #import "Texture.h" 00031 #import "Cullable.h" 00032 #import "Drawable.h" 00033 #import "Generator.h" 00034 #import "GlobeView.h" 00035 00036 namespace WhirlyGlobe 00037 { 00038 00039 class SubTexture; 00040 00043 class AddTextureReq : public ChangeRequest 00044 { 00045 public: 00048 AddTextureReq(Texture *tex) : tex(tex) { } 00050 ~AddTextureReq() { if (tex) delete tex; tex = NULL; } 00051 00053 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00054 00055 protected: 00056 Texture *tex; 00057 }; 00058 00060 class RemTextureReq : public ChangeRequest 00061 { 00062 public: 00064 RemTextureReq(SimpleIdentity texId) : texture(texId) { } 00065 00067 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00068 00069 protected: 00070 SimpleIdentity texture; 00071 }; 00072 00074 class AddDrawableReq : public ChangeRequest 00075 { 00076 public: 00078 AddDrawableReq(Drawable *drawable) : drawable(drawable) { } 00080 ~AddDrawableReq() { if (drawable) delete drawable; drawable = NULL; } 00081 00083 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00084 00085 protected: 00086 Drawable *drawable; 00087 }; 00088 00090 class RemDrawableReq : public ChangeRequest 00091 { 00092 public: 00094 RemDrawableReq(SimpleIdentity drawId) : drawable(drawId) { } 00095 00097 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00098 00099 protected: 00100 SimpleIdentity drawable; 00101 }; 00102 00104 class AddGeneratorReq : public ChangeRequest 00105 { 00106 public: 00108 AddGeneratorReq(Generator *generator) : generator(generator) { } 00109 00111 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00112 00113 protected: 00114 Generator *generator; 00115 }; 00116 00118 class RemGeneratorReq : public ChangeRequest 00119 { 00120 public: 00122 RemGeneratorReq(SimpleIdentity genId) : genId(genId) { } 00123 00125 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00126 00127 protected: 00128 SimpleIdentity genId; 00129 }; 00130 00132 typedef std::set<Generator *,IdentifiableSorter> GeneratorSet; 00133 00141 class GlobeScene 00142 { 00143 friend class ChangeRequest; 00144 public: 00147 GlobeScene(unsigned int numX,unsigned int numY); 00148 ~GlobeScene(); 00149 00151 void getCullableSize(unsigned int &numX,unsigned int &numY) { numX = this->numX; numY = this->numY; } 00152 00154 const Cullable * getCullable(unsigned int x,unsigned int y) { return &cullables[y*numX+x]; } 00155 00157 const Cullable *getCullables() { return cullables; } 00158 00160 const GeneratorSet *getGenerators() { return &generators; } 00161 00164 void addChangeRequest(ChangeRequest *newChange); 00167 void addChangeRequests(const std::vector<ChangeRequest *> &newchanges); 00168 00171 GLuint getGLTexture(SimpleIdentity texIdent); 00172 00175 // Note: Should give this a time limit 00176 void processChanges(WhirlyGlobeView *view); 00177 00182 void addSubTexture(const SubTexture &); 00183 void addSubTextures(const std::vector<SubTexture> &); 00184 00187 SubTexture getSubTexture(SimpleIdentity subTexId); 00188 00189 public: 00191 void overlapping(GeoMbr geoMbr,std::vector<Cullable *> &cullables); 00192 00194 // Note: This could be optimized 00195 void removeFromCullables(Drawable *drawable); 00196 00198 Generator *getGenerator(SimpleIdentity genId); 00199 00201 Drawable *getDrawable(SimpleIdentity drawId); 00202 00204 Texture *getTexture(SimpleIdentity texId); 00205 00207 GeneratorSet generators; 00208 00210 unsigned int numX,numY; 00211 00213 Cullable *cullables; 00214 00215 typedef std::set<Drawable *,IdentifiableSorter> DrawableSet; 00217 DrawableSet drawables; 00218 00219 typedef std::set<Texture *,IdentifiableSorter> TextureSet; 00221 TextureSet textures; 00222 00223 pthread_mutex_t changeRequestLock; 00226 std::vector<ChangeRequest *> changeRequests; 00227 00228 typedef std::set<SubTexture> SubTextureSet; 00230 SubTextureSet subTextureMap; 00231 }; 00232 00233 }