00001 #ifndef _OGL_PARTS_H
00002 #define _OGL_PARTS_H
00003
00004 #ifdef WIN32
00005 #include <windows.h>
00006 #endif
00007
00008 #if defined(__APPLE__) || defined(MACOSX)
00009 #include <GLUT/glut.h>
00010 #else
00011 #include <GL/glut.h>
00012 #endif
00013
00014 #ifdef GLEXT
00015 #include "GLEXTHandler.h"
00016 #endif
00017
00018
00019 #include <vector>
00020 #include <string>
00021 using namespace std;
00022
00024 enum TextureType
00025 {
00026 TTGRAYSCALE = 0,
00027 TTRGB,
00028 TTRGBA,
00029 TTRGBA16,
00030 TTRGBA32,
00031 TTUNDEFINED
00032 };
00033
00035
00043 class Shader
00044 {
00045 public:
00046 Shader();
00047 ~Shader();
00048
00050
00054 bool LoadShader( const char * sShaderName );
00055
00057
00060 bool LoadShaderFrag( const char * sShaderCode );
00061
00063
00066 bool LoadShaderVert( const char * sShaderCode );
00067
00069
00072 bool LoadShaderGeom( const char * sShaderCode );
00073
00075
00077 bool LinkShaders();
00078
00080
00084 bool ActivateShader( vector< string > &vsAllSamplerLocs, vector< string > &vsUniformFloats, vector < float > & vfUniformFloats );
00085
00087 bool ActivateShader( vector< string > &vsAllSamplerLocs);
00088
00090 bool ActivateShader() { vector<string> st; return ActivateShader( st ); }
00091
00093 bool ActivateShader( const string & s ) { vector<string> st; st.push_back( s ); return ActivateShader( st ); }
00094
00096 bool DeactivateShader();
00097
00099 void CheckForNewer( const char * sShaderName );
00100
00102 GLhandleARB GetProgramID() { return iProgramID; }
00103 private:
00105
00106
00107 void GetTimeCodes( unsigned long * iOut, const char * sShaderName );
00108
00110 unsigned long iTimeCode[3];
00111
00113 GLhandleARB iProgramID;
00114
00116 GLhandleARB geometryShader;
00117
00119 GLhandleARB vertexShader;
00120
00122 GLhandleARB fragmentShader;
00123
00125 GLuint vertexProgram;
00127 GLuint fragmentProgram;
00129 bool bIsGLSLAsm;
00130 };
00131
00133
00141 class Texture
00142 {
00143 public:
00144 Texture() { iTexture = (GLuint)-1; }
00145 ~Texture();
00146
00149 bool MakeDynamicTexture( int iWidth, int iHeight, TextureType tt );
00150
00152 bool LoadTextureFile( const char * sFileName );
00153
00155 bool LoadTexture( char * sRawData, int iWidth, int iHeight, TextureType tt );
00156
00158 bool ActivateTexture( int iPlace = 0 );
00159
00161 bool DeactivateTexture( int iPlace = 0 );
00162
00164 unsigned int GetTexHandle() { return iTexture; }
00165
00167
00168 bool StripFromScreen( int x, int y, int width, int height );
00169
00171 inline int GetWidth( ) { return mWidth; }
00172
00174 inline int GetHeight( ) { return mHeight; }
00175
00178 void ChangeFilter( bool bNearest );
00179 private:
00180 GLuint iTexture;
00181 TextureType mtt;
00182 int mWidth, mHeight;
00183 };
00184
00186
00194 class RFBuffer
00195 {
00196 public:
00197 RFBuffer();
00198 ~RFBuffer();
00199
00201 bool Setup( bool bUseDepthBuffer = true );
00202
00204 bool ConfigureAndStart( int iWidth, int iHeight, int iTextures, Texture * TexturesToAttach, bool bClear = false );
00205
00208 bool End( int iRegVPX, int iRegVPY );
00209
00211 int GetWidth() { return mWidth; }
00212
00214 int GetHeight() { return mHeight; }
00215
00217 TextureType GetTT() { return mtt; }
00218 private:
00219 bool m_bUseDepthBuffer;
00220 int mWidth, mHeight;
00221 TextureType mtt;
00222
00223 GLuint iRenderbuffer;
00224 GLuint iOutputBuffer;
00225 };
00226
00227 class VertexData;
00228 class IndexData;
00229
00231
00236 class VertexData
00237 {
00238 public:
00239 VertexData() { iVertexData = 0; }
00240 ~VertexData();
00241
00243 void Init( float * Verts, int iNumVerts, int iStride = 3 );
00244
00246 void UpdateData( float * Verts, int iNumVerts, int iStride = 3 );
00247
00249 void StripFromFrameBuffer( int iWidth, int iHeight, TextureType tt );
00250 private:
00251 int mStride;
00252 GLuint iVertexData;
00253 friend void DrawGeometry( VertexData ** vd, string * vsVertexNames, int iNumVertexDatas, IndexData * id, Shader * sShader );
00254 friend void DrawGeometrySolid( VertexData ** vd, string * vsVertexNames,
00255 int iNumVertexDatas, IndexData * id, Shader * sShader, int facecount );
00256 };
00257
00259
00261 class IndexData
00262 {
00263 public:
00264 IndexData() { mIndexData = (GLuint*)-1; }
00265 ~IndexData();
00266
00268
00270 void Init( int * Indices, int iNumIndices );
00271 private:
00272 GLuint mIndexCount;
00273 GLuint * mIndexData;
00274 friend void DrawGeometry( VertexData ** vd, string * vsVertexNames,
00275 int iNumVertexDatas, IndexData * id, Shader * sShader );
00276 friend void DrawGeometrySolid( VertexData ** vd, string * vsVertexNames,
00277 int iNumVertexDatas, IndexData * id, Shader * sShader, int facecount );
00278 };
00279
00281 void DrawSquare();
00282
00284 void DrawGeometry( VertexData ** vd, string * vsVertexNames, int iNumVertexDatas, IndexData * id, Shader * sShader );
00285
00286
00288 void DrawGeometrySolid( VertexData ** vd, string * vsVertexNames, int iNumVertexDatas, IndexData * id, Shader * sShader, int facecount );
00289
00291
00294 void SetupForDataRun();
00296 void PopFromDataRun();
00297
00299 void StripDataFromBuffer( int ix, int iy, int iwidth, int iheight, TextureType tt, char * buffer );
00300
00301
00304 int OpenPPM( const char * sPPMName, unsigned char ** buffer, int * width, int * height );
00305
00306 #endif
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328