00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _BSP_H
00025 #define _BSP_H
00026
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030
00031
00032 #include <vector>
00033 #include <string>
00034 #include "GLee.h"
00035 #include "q3types.h"
00036 #include "q3entities.h"
00037 #include "texture.h"
00038 #include "bitset.h"
00039 #include "world.h"
00040 #include "errors.h"
00041 #include "patch.h"
00042 #include "shader.h"
00043 #include "collision.h"
00044
00045
00046
00047 namespace ngn {
00048 class Skybox;
00049 class Camera;
00050 namespace core {
00051
00052
00053
00054
00055 class Bsp : public World
00056 {
00057
00058 public:
00059 Bsp();
00060 virtual ~Bsp();
00061
00062 virtual bool load( const char* filename );
00063
00064 virtual void render( const Camera& cam );
00065
00066 void clear();
00067
00068 void setGammaFactor( float gamma );
00069
00070 float getGammaFactor() const;
00071
00072 const Vector3df& getEntryPoint( unsigned int index ) const;
00073
00074 const Vector3df& getRandomEntryPoint() const;
00075
00076 protected:
00077
00078 bool addTextureExtension( char* filename );
00079
00080 void createTextures( tBSPTexture *pTex );
00081
00082 void createLightmap( unsigned int &texture, unsigned char* pImageBits, int width, int height);
00083
00084 void setGamma( float gamma );
00085
00086 float getGamma() const;
00087
00088 void enableVertexArray() const;
00089
00090 void disableVertexArray() const;
00091
00092 void renderTree( int node, bool frustumcheck, const Camera& cam );
00093
00094 void renderLeaf( int leaf, bool frustumcheck, const Camera& cam )const;
00095
00096 void renderFace( int faceindex );
00097
00098 void renderPatch( int index ) const;
00099
00100 void renderSkybox( const Camera& cam ) const;
00101
00102 int isClusterVisible( int current, int test );
00103
00104 int findLeaf( const Vector3df& pos );
00105
00106 void createPatches();
00107
00108
00109 void loadVertices();
00110
00111 void loadFaces();
00112
00113 void loadTextures();
00114
00115 void loadLightmaps();
00116
00117 void loadNodes();
00118
00119 void loadLeafs();
00120
00121 void loadLeafFaces();
00122
00123 void loadPlanes();
00124
00125 void loadVisData();
00126
00127 void loadEntities();
00128
00129 void loadModels();
00130
00131 void loadMeshVertices();
00132
00133 void loadLights();
00134
00135 void loadSkybox();
00136
00137 void loadBrushes();
00138
00139 void loadBrushSides();
00140
00141 void loadLeafBrushes();
00142
00143 void loadIndices();
00144
00145
00146 private:
00147
00148
00149 void adjustGamma( unsigned char *pImage, int size, float factor );
00150
00151 int m_nVerts;
00152 int m_nFaces;
00153 int m_nTextures;
00154 int m_nLightmaps;
00155 int m_nNodes;
00156 int m_nLeafs;
00157 int m_nLeafFaces;
00158 int m_nPlanes;
00159 int m_nModels;
00160 int m_nMeshVertices;
00161 int m_nPatchFaces;
00162 int m_nLights;
00163 int m_nBrushes;
00164 int m_nBrushSides;
00165 int m_nLeafBrushes;
00166 int m_nIndices;
00167
00168 tBSPLump m_lumps[ kMaxLumps ];
00169
00170 tBSPVertex *m_pVerts;
00171 tBSPFace *m_pFaces;
00172 tBSPTexture *m_pTextures;
00173 tBSPNode *m_pNodes;
00174 tBSPLeaf *m_pLeafs;
00175 tBSPPlane *m_pPlanes;
00176 int *m_pLeafFaces;
00177 tBSPVisData m_clusters;
00178 char *m_entities;
00179 tBSPModel *m_pModels;
00180 int *m_pMeshVertices;
00181 bsp::tBSPPatchFace *m_pPatchFaces;
00182 tBSPLights *m_pLights;
00183 tBSPBrush *m_pBrushes;
00184 tBSPBrushSide *m_pBrushSides;
00185 int *m_pLeafBrushes;
00186 int *m_pIndices;
00187
00188
00189
00190 GLuint m_texArray[ MAX_TEXTURES ];
00191 GLuint m_lightmapArray[ MAX_TEXTURES ];
00192 Texture *m_pTex;
00193 Bitset m_bitset;
00194 FILE *m_file;
00195 float m_gamma;
00196 std::vector<bsp::entry_point> m_entry_points;
00197 Skybox *m_skybox;
00198 std::string m_map_file;
00199 gl::ShaderProgram *m_shader;
00200
00201 friend class bsp::BSPCollision;
00202
00203 };
00204
00205
00206
00207 }
00208 }
00209 #endif