00001 #ifndef RENDERER_H
00002 #define RENDERER_H
00003
00004 #include <GL/freeglut.h>
00005
00006 #include <string>
00007 #include <vector>
00008
00009
00010 #include "../utils/FlowData.h"
00011 #include "../utils/StreamlineGrid.h"
00012 #include "../utils/vec3.h"
00013
00014 #include <semaphore.h>
00015
00019 class Renderer
00020 {
00021 public:
00025 struct TFPoint
00026 {
00027 unsigned int pos;
00028 unsigned char r;
00029 unsigned char g;
00030 unsigned char b;
00031 unsigned char a;
00032 };
00033
00037 struct TransferFunction
00038 {
00039 GLuint texID;
00040 unsigned int width;
00041 std::vector<TFPoint> points;
00042 int* histo;
00043 int* maxHist;
00044
00045 unsigned char* data;
00046
00047 TransferFunction()
00048 {
00049 this->width = 0;
00050 this->texID = 0;
00051 this->data = 0;
00052
00053 }
00054 };
00055
00057 Renderer();
00058 ~Renderer();
00059
00060 void setStreamlines(bool);
00061 void setArrows(bool);
00062
00063 void setArrowSize(float);
00064
00065 void setDTest(float);
00066 void setDSep(int);
00067 void setStepSize(float);
00068
00069 void setDataset(int);
00070 void setChannel(int);
00071
00073 void setTransferFunction(TransferFunction&);
00074
00076 void initGL();
00078 void resizeGL(int, int);
00080 void paintGL();
00081
00083 void animate();
00084
00085 int * getHisto() { return this->histo; };
00086 int * getMaxHist() { return this->maxHist; };
00087
00088 private:
00089 static Renderer* instance;
00090
00092 double loopFactor;
00093 clock_t timestamp;
00094
00095 FlowData* dataset;
00096
00097 int* histo;
00098
00099 int* maxHist;
00100
00102 GLuint width;
00104 GLuint height;
00105
00106 int channelIndex;
00107
00108 int timeStepIndex;
00109
00110 int xCountArrows;
00111 int yCountArrows;
00112
00113 float xArrowDist;
00114 float yArrowDist;
00115
00116 float arrowSize;
00117
00119 GLuint transferTexture;
00120
00122 GLint transferTextureLocation;
00123
00124 GLuint arrowTexture;
00125 GLint arrowTextureLocation;
00126
00127 GLint arrowPlottingProgram;
00128 GLint arrowPlottingChannelTexturesLocations[2];
00129
00130 GLint colorCodingProgram;
00131 GLint colorCodingChannelTextureLocation;
00132
00133 vector<GLuint*> timeStepTextures;
00134 vector<vector<float*> > timeStepData;
00135
00136 float newStepSize;
00137 int newDSep;
00138
00139 float stepSize;
00140 int dSep;
00141 StreamlineGrid* streamlineGrid;
00142
00143 bool doArrows;
00144 bool doStreamlines;
00145
00146 void loadArrowTexture();
00147 void preprocessFlowData();
00148
00149 void renderChannel();
00150 void renderArrows();
00151 void renderStreamlines();
00152
00154 void checkGLFeatures();
00155
00156 static bool create2DTexture(GLuint*, int, int, void*);
00157
00159 static GLuint createProgram(const std::string&, const std::string&);
00161 static GLint queryUniformLoc(GLint, const GLchar*);
00163 static bool readShaderSource(const std::string&, std::string&);
00164
00165 sem_t mutex;
00166
00167 static void* generateTimestepTextures(void*);
00168 };
00169
00170 #endif