00001 #ifndef _FV_TXT_UTLS_H_
00002 #define _FV_TXT_UTLS_H_
00003
00004 #include "types.h"
00005 #include "fv_config.h"
00006 #include "fv_inc.h"
00007 #include "RenderParams.h"
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <assert.h>
00011 #include <string>
00012 #include <vector>
00013
00014 namespace FemViewer {
00015
00016 enum ePixelFormat {
00017 PF_UNKNOWN = 0,
00018 PF_R8,
00019 PF_RG8,
00020 PF_RGB8,
00021 PF_RGBA8,
00022
00023
00024 PF_RGBA8_SRGB,
00025 PF_BGRA8_SRGB,
00026
00027 PF_ALL
00028 };
00029
00030
00031 enum eShaderType
00032 {
00033 SH_VERTEX = 0x01,
00034 SH_GEOMETRY = 0x02,
00035 SH_FRAGMENT = 0x04,
00036 SH_TESELATOR = 0x08,
00037 SH_COMPUTE = 0x10,
00038 };
00039
00040
00041
00043 typedef struct {
00044 int _internal;
00045 int _format;
00046 int _type;
00047 unsigned int _size;
00048 int _components;
00049 bool _rt;
00050 int _sRGB;
00051 const char *_txt;
00052 bool _compressed;
00053 } pixel_descr_t, *pixel_descrptr_t;
00054
00055 extern const pixel_descr_t pixel_descriptors[];
00056
00057 inline const pixel_descr_t* getPixelFormatDescriptor(const int id) {
00058 assert(id > PF_UNKNOWN && id < PF_ALL);
00059 return (pixel_descriptors + id);
00060 }
00061
00062
00063 class GLCore
00064 {
00065 static GLboolean wasInit;
00066 std::string vendor;
00067 std::string renderer;
00068 std::string version;
00069 std::string glslVersion;
00070 std::vector <std::string> extensions;
00071 int redBits;
00072 int greenBits;
00073 int blueBits;
00074 int alphaBits;
00075 int depthBits;
00076 int stencilBits;
00077 int maxTextureSize;
00078 int maxLights;
00079 int maxAttribStacks;
00080 int maxModelViewStacks;
00081 int maxProjectionStacks;
00082 int maxClipPlanes;
00083 int maxTextureStacks;
00084 int maxUniformBufferSize;
00085
00086 GLuint compileList;
00087 GLsizei range;
00088
00089 explicit GLCore();
00090 public:
00091
00092 ~GLCore();
00093
00094 static GLboolean init(int argc,char *argv[]);
00095 static GLCore& instance();
00096
00097 GLuint createBuffer(const void* data,unsigned int dataSize, GLenum target, GLenum usage);
00098
00099 bool initGLLists(const GLsizei size);
00100 void renderGLList(const GLuint type);
00101 void deleteGLLists(const GLuint listID, const GLsizei size);
00102 void deleteBuffers(GLuint* buffer,const GLsizei size);
00103
00104 void startGLList(GLuint type);
00105 void endGLList();
00106
00107 bool getInfo(unsigned int param=0);
00108 void printSelf();
00109 bool isExtensionSupported(const std::string& ext);
00110
00111 template< typename TVertex >
00112 GLuint createGLText(const TVertex* buffer,
00113 const GLsizei stride,
00114 const GLuint num,
00115 const GLfloat color[3],
00116 const GLuint type,
00117 const GLboolean drawAll = GL_TRUE) {}
00118
00119 private:
00120 GLCore(const GLCore&);
00121 GLCore& operator=(const GLCore&);
00122
00123 void Check() const;
00124
00125 };
00126
00127 }
00128
00129 bool initGLEW(const bool bFlag = false);
00130 bool initGLLists(const GLsizei size);
00131 GLuint initShaders(const char *path_to_vertex_shader, const char *payh_to_fragment_shader);
00132 bool loadFile(const char* path,std::string& source);
00133 GLuint createBuffer(const void* data,unsigned int dataSize, GLenum target, GLenum usage);
00134
00135 GLuint createPixelBuffer(const int width,const int height,GLuint* pbId);
00136
00137
00138
00139 float getTextWidthOnScreen(const std::string& text, void* pCurrentFont);
00140 void drawText(const std::string& pText,
00141 float pXMin, float pYMin, float pXMax, float pYMax,
00142 int pFontSize, void* pCurrentFont, bool pAutoLineBreak, bool pFlagCentered);
00143
00144 void drawText3D(const std::string& pText, float pX, float pY, float pZ, void* pCurrentFont);
00145 void drawString(const char *str, int x, int y, float color[4], void *font);
00146 void drawPlane(const float* points, const float* scale, unsigned int size);
00147
00148 inline
00149 bool __CheckErrorGL(const char *file, const int line) {
00150 bool ret_val = true;
00151
00152
00153 GLenum gl_error = glGetError();
00154
00155 if (gl_error != GL_NO_ERROR) {
00156 #ifdef _WIN32
00157 char tmpStr[512];
00158
00159
00160 sprintf_s(tmpStr, 255, "\n%s(%i) : GL Error : %s\n\n", file, line, gluErrorString(gl_error));
00161 fprintf(stderr, "%s", tmpStr);
00162 #endif
00163 fprintf(stderr, "GL Error in file '%s' in line %d :\n", file, line);
00164 fprintf(stderr, "%s\n", gluErrorString(gl_error));
00165 fflush(stderr);
00166 ret_val = false;
00167 }
00168
00169 return ret_val;
00170 }
00171 #define FV_DEBUG_GL 1
00172 #ifdef FV_DEBUG_GL
00173 #define FV_CHECK_ERROR_GL() \
00174 if( false == __CheckErrorGL( __FILE__, __LINE__)) { \
00175 exit(EXIT_FAILURE); \
00176 }
00177
00178 inline
00179 void print_array(const float array[],size_t size_of_array) {
00180 printf("\n");
00181 for (size_t i(0);i<size_of_array;++i)
00182 printf("tab[%u] = %f\n",i,array[i]);
00183 }
00184
00185 inline
00186 void print_array_vec4f(const float array[],
00187 const size_t size_of_array,
00188 const size_t offset) {
00189 printf("\n");
00190 size_t i(0), j(0);
00191 for (; i < size_of_array; i++,j+=offset) {
00192 printf("vec[%u]: ",i);
00193 print_array(&array[j],4);
00194 }
00195 }
00196
00197 GLuint createQuadGrid(const double orig[],
00198 double dims[],
00199 double density[],
00200 GLuint* nvertces
00201 );
00202 GLuint createGrid3D(const float minb[],const float maxb[],const grid_t* drid, GLuint outBuff[]);
00203 void drawGrid(const GLuint params[2],const float color[3],const float linew = 0.0);
00204
00205 struct colorbar_config_t;
00206 GLuint createColorBar(const FemViewer::colorbar_config_t *cfg,GLuint* buffID);
00207
00208 #else
00209 #define FV_CHECK_ERROR_GL()
00210 #endif
00211
00212
00213
00214 #endif
00215