WhirlyGlobe
1.1
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 "GlobeView.h" 00034 00035 namespace WhirlyGlobe 00036 { 00037 00040 class AddTextureReq : public ChangeRequest 00041 { 00042 public: 00045 AddTextureReq(Texture *tex) : tex(tex) { } 00047 ~AddTextureReq() { if (tex) delete tex; tex = NULL; } 00048 00050 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00051 00052 protected: 00053 Texture *tex; 00054 }; 00055 00057 class RemTextureReq : public ChangeRequest 00058 { 00059 public: 00061 RemTextureReq(SimpleIdentity texId) : texture(texId) { } 00062 00064 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00065 00066 protected: 00067 SimpleIdentity texture; 00068 }; 00069 00071 class AddDrawableReq : public ChangeRequest 00072 { 00073 public: 00075 AddDrawableReq(Drawable *drawable) : drawable(drawable) { } 00077 ~AddDrawableReq() { if (drawable) delete drawable; drawable = NULL; } 00078 00080 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00081 00082 protected: 00083 Drawable *drawable; 00084 }; 00085 00087 class RemDrawableReq : public ChangeRequest 00088 { 00089 public: 00091 RemDrawableReq(SimpleIdentity drawId) : drawable(drawId) { } 00092 00094 void execute(GlobeScene *scene,WhirlyGlobeView *view); 00095 00096 protected: 00097 SimpleIdentity drawable; 00098 }; 00099 00107 class GlobeScene 00108 { 00109 friend class ChangeRequest; 00110 public: 00113 GlobeScene(unsigned int numX,unsigned int numY); 00114 ~GlobeScene(); 00115 00117 void getCullableSize(unsigned int &numX,unsigned int &numY) { numX = this->numX; numY = this->numY; } 00118 00120 const Cullable * getCullable(unsigned int x,unsigned int y) { return &cullables[y*numX+x]; } 00121 00123 const Cullable *getCullables() { return cullables; } 00124 00127 void addChangeRequest(ChangeRequest *newChange); 00130 void addChangeRequests(const std::vector<ChangeRequest *> &newchanges); 00131 00134 GLuint getGLTexture(SimpleIdentity texIdent); 00135 00138 // Note: Should give this a time limit 00139 void processChanges(WhirlyGlobeView *view); 00140 00141 public: 00143 void overlapping(GeoMbr geoMbr,std::vector<Cullable *> &cullables); 00144 00146 // Note: This could be optimized 00147 void removeFromCullables(Drawable *drawable); 00148 00150 Drawable *getDrawable(SimpleIdentity drawId); 00151 00153 Texture *getTexture(SimpleIdentity texId); 00154 00156 unsigned int numX,numY; 00157 00159 Cullable *cullables; 00160 00161 typedef std::set<Drawable *,IdentifiableSorter> DrawableSet; 00163 DrawableSet drawables; 00164 00165 typedef std::set<Texture *,IdentifiableSorter> TextureSet; 00167 TextureSet textures; 00168 00169 pthread_mutex_t changeRequestLock; 00172 std::vector<ChangeRequest *> changeRequests; 00173 }; 00174 00175 }