00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #import <vector>
00027
00028 #import <QuartzCore/QuartzCore.h>
00029
00030 #import <OpenGLES/EAGL.h>
00031 #import <OpenGLES/EAGLDrawable.h>
00032
00033 #import "sgTouches.h"
00034 #import "sgAccelerometer.h"
00035 #import "sgDebug.h"
00036 #import "sgColor.h"
00037 #import "sgQuaternion.h"
00038 #import "sgVector3.h"
00039 #import "sgMatrix4x4.h"
00040 #import "sgObject.h"
00041 #import "sgRessourceManager.h"
00042 #import "sgVertex.h"
00043 #import "sgCamera.h"
00044 #import "sgMaterial.h"
00045 #import "sgLight.h"
00046 #import "sgPanel.h"
00047
00048 struct sgOptimizedMesh
00049 {
00050 sgMesh *mesh;
00051 sgMaterial *material;
00052 sgObject *object;
00053
00054 sgOptimizedMesh *next;
00055 sgOptimizedMesh *prev;
00056 };
00057
00061 class sgRenderer
00062 {
00063 public:
00068 sgRenderer();
00069
00074 ~sgRenderer();
00075
00080 virtual BOOL init();
00081
00086 virtual void render();
00087
00093 virtual BOOL resizeFromLayer(CAEAGLLayer* layer);
00094
00100 void setOrientation(unsigned int ori);
00101
00106 sgObject *first_solid;
00107
00112 sgCamera *first_cam;
00113
00118 sgLight *first_light;
00119
00124 sgPanel *first_panel;
00125
00130 GLint backingWidth;
00131
00136 GLint backingHeight;
00137
00142 sgFColorA clearcolor;
00143
00148 static unsigned int oglversion;
00149
00154 BOOL optimize;
00155
00156 protected:
00157 void updateOrientation();
00158
00159 void culling();
00160 void sorting();
00161 void optimizing();
00162
00163 EAGLContext *context;
00164
00165 GLuint defaultFramebuffer;
00166 GLuint colorRenderbuffer;
00167 GLuint depthRenderbuffer;
00168
00169 float quadpos[12];
00170 float quaduv[8];
00171 sgMaterial *lastmat;
00172
00173 sgOptimizedMesh *first_optimized;
00174
00175 std::vector<sgMesh*> meshes;
00176 std::vector<sgMaterial*> materials;
00177
00178 unsigned int orientation;
00179 sgMatrix4x4 matglobal2d;
00180 sgMatrix4x4 matglobal3d;
00181 };