1 #ifndef MY_GL_WIDGET_H 2 #define MY_GL_WIDGET_H 3 4 #include "vs/sampler.h" 5 6 #include <QGLWidget> 7 #include <QString> 8 9 using namespace vs; 10 11 class MyGLWidget: public QGLWidget 12 { 13 14 public: MyGLWidget(VSParameters * params,MeshModel * inputMeshModel,CMeshO * uniformSamplesMesh,CMeshO * featureSamplesMesh,QGLWidget * shareWidget)15 MyGLWidget( VSParameters* params, 16 MeshModel* inputMeshModel, 17 CMeshO* uniformSamplesMesh, 18 CMeshO* featureSamplesMesh, 19 QGLWidget* shareWidget ) 20 : QGLWidget( (QWidget*)0, shareWidget ) 21 { 22 this->params = params; 23 this->inputMeshModel = inputMeshModel; 24 this->uniformSamplesMesh = uniformSamplesMesh; 25 this->featureSamplesMesh = featureSamplesMesh; 26 this->setFixedSize( 200, 200 ); 27 this->result = false; 28 29 updateGL(); 30 } 31 32 VSParameters* params; 33 MeshModel* inputMeshModel; 34 CMeshO* uniformSamplesMesh; 35 CMeshO* featureSamplesMesh; 36 SamplerListener* samplerListener; 37 bool result; 38 QString errorString; 39 40 protected: initializeGL(void)41 virtual void initializeGL( void ) 42 { 43 // glew initialization 44 GLenum result = glewInit(); 45 if( result != GLEW_OK ) 46 { 47 errorString = "Cannot initialize glew."; 48 result = false; 49 return; 50 } 51 52 // check that everything is supported 53 if( !checkOpenGLCapabilities() ) 54 { 55 result = false; 56 return; 57 } 58 59 // OpenGL initialization 60 glEnable( GL_DEPTH_TEST ); 61 glEnable( GL_TEXTURE_2D ); 62 glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); 63 64 // samples generation 65 if( this->context()->isValid() ) 66 { 67 Sampler< CMeshO >::generateSamples 68 ( params, inputMeshModel, uniformSamplesMesh, featureSamplesMesh, 0 ); 69 this->result = true; 70 } 71 else 72 { 73 errorString = "The new OpenGL context is not valid."; 74 this->result = false; 75 } 76 } 77 paintGL(void)78 virtual void paintGL( void ) 79 { 80 ; 81 } 82 83 private: 84 checkOpenGLCapabilities(void)85 bool checkOpenGLCapabilities( void ) 86 { 87 map< QString, QString > extToErr; 88 extToErr[ "GL_ARB_vertex_shader GL_ARB_fragment_shader" ] = "Vertex and fragment shaders are not supported."; 89 extToErr[ "GL_EXT_framebuffer_object" ] = "Framebuffer objects are not supported."; 90 extToErr[ "GL_ARB_texture_float" ] = "Float textures are not supported."; 91 extToErr[ "GL_ARB_draw_buffers" ] = "Multiple render buffers are not supported."; 92 93 map< QString, QString >::iterator mi = extToErr.begin(); 94 bool everythingOk = true; 95 while( everythingOk && mi != extToErr.end() ) 96 { 97 98 everythingOk = (bool)( glewIsSupported( qPrintable((*mi).first) ) ); 99 ++mi; 100 } 101 102 if( !everythingOk ) 103 { 104 --mi; 105 errorString = (*mi).second; 106 return false; 107 } 108 109 // checks that at least 5 render targets are available 110 GLint v = (GLint)0; 111 glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS, &v ); 112 if( v < 5 ) 113 { 114 errorString = "At least 5 render targets must be available for an FBO."; 115 return false; 116 } 117 118 glGetIntegerv( GL_MAX_DRAW_BUFFERS, &v ); 119 if( v < 5 ) 120 { 121 errorString = "Cannot write to 5 draw buffers at the same time."; 122 return false; 123 } 124 125 return true; 126 } 127 128 }; 129 130 #endif // MY_GL_WIDGET_H 131