inline void Uniform<vr::Matrix, 3>::apply() { std::stringstream ss; glUniformMatrix4fvARB(location , 1, GL_FALSE, value[0].ptr()); ss << __FILE__ << ":" << __LINE__; CheckErrorsGL( string(ss.str()) ); glUniformMatrix4fvARB(location+1, 1, GL_FALSE, value[1].ptr()); ss << __FILE__ << ":" << __LINE__; CheckErrorsGL( string(ss.str()) ); glUniformMatrix4fvARB(location+2, 1, GL_FALSE, value[2].ptr()); ss << __FILE__ << ":" << __LINE__; CheckErrorsGL( string(ss.str()) ); }
void Window::initGL() { CheckErrorsGL(std::string("initGL() ")); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); GLfloat material_ambient[] = {1.0,1.0,1.0,1.0}; GLfloat material_diffuse[] = {1.0,1.0,1.0,1.0}; GLfloat material_specular[] = {1.0,1.0,1.0,1.0}; GLfloat material_shininess[] = {2.0f}; glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); { GLfloat light_ambient[] = {0.1, 0.1, 0.1, 1.0}; GLfloat light_diffuse[] = {0.4, 0.3, 0.3, 1.0}; GLfloat light_specular[] = {0.8, 0.5, 0.5, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, lightPos.ptr()); } GLfloat light_ambient[] = {0.1, 0.1, 0.1, 1.0}; GLfloat light_diffuse[] = {0.2, 0.3, 0.4, 1.0}; GLfloat light_specular[] = {0.4, 0.5, 0.8, 1.0}; GLfloat light_position[] = {0.0, 5.0, 5.0, 1.0}; glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_POSITION, light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); CheckErrorsGL(std::string("initGLend() ")); }
TextureUnit::TextureUnit(int w, int h, GLenum texTarget, GLenum internalFormat, GLenum texFormat, GLenum datatype, GLenum filterType) { _w = w; _h = h; _texTarget = texTarget; _texInternalFormat = internalFormat; _texFormat = texFormat; _texDataType = datatype; _texFilterType = filterType; CheckErrorsGL("DM::initTextureUnits 00"); // Create Input Image Texture glGenTextures(1,&_texID); glBindTexture (_texTarget,_texID); CheckErrorsGL("DM::initTextureUnits 01"); glPixelStorei (GL_UNPACK_ALIGNMENT , 1); glTexParameteri (_texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB); glTexParameteri (_texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB); CheckErrorsGL("DM::initTextureUnits 02"); glTexParameteri (_texTarget, GL_TEXTURE_MAG_FILTER, _texFilterType); glTexParameteri (_texTarget, GL_TEXTURE_MIN_FILTER, _texFilterType); CheckErrorsGL("DM::initTextureUnits 03"); CheckErrorsGL("DM::initTextureUnits 04"); glTexImage2D (_texTarget, 0, _texInternalFormat,_w,_h, 0, _texFormat, datatype, 0); CheckErrorsGL("DM::initTextureUnits 05"); }
inline void Uniform<float, 1>::apply() { std::stringstream ss; glUniform1fARB(location, value[0]); ss << __FILE__ << ":" << __LINE__; CheckErrorsGL( string(ss.str()) ); }
Uniform(const std::string& name, GLhandleARB program) : location(glGetUniformLocationARB(program, name.c_str())) { CheckErrorsGL(std::string("glGetUniformLocationARB :")); }
bool Shader::initInContext(unsigned int contextId) { // handler for the single shaders GLuint vs = 0; GLuint fs = 0; GLuint gs = 0; // return values for the compile process GLint vsCompiled = 0; GLint fsCompiled = 0; GLint gsCompiled = 0; // iterator for program parameter std::map<GLenum,int>::iterator params; #ifndef GLOOST_SYSTEM_DISABLE_OUTPUT_MESSAGES std::cerr << std::endl; std::cerr << std::endl << "Message from Message from Shader::initInContext() on SharedResource " << getSharedResourceId() << ":"; std::cerr << std::endl << " Building for context " << contextId << "."; std::cerr << std::endl; #endif // remove this resource if it allready exists removeFromContext(contextId); /// create a vertex, a fragment and a geometry shader handle vs = glCreateShader( GL_VERTEX_SHADER ); fs = glCreateShader( GL_FRAGMENT_SHADER ); if (_geometryShaderSource) { gs = glCreateShader( GL_GEOMETRY_SHADER ); } /// send shader source to the driver glShaderSource(vs, 1, &_vertexShaderSource, NULL); glShaderSource(fs, 1, &_fragmentShaderSource, NULL); if (_geometryShaderSource) { glShaderSource(gs, 1, &_geometryShaderSource, NULL); } // vertex shader glCompileShader(vs); glGetShaderiv(vs, GL_COMPILE_STATUS, &vsCompiled); if (vsCompiled == GL_FALSE) { #ifndef GLOOST_SYSTEM_DISABLE_OUTPUT_ERRORS std::cerr << std::endl; std::cerr << std::endl << "ERROR in shader::create() on SharedResource " << getSharedResourceId() << ":"; std::cerr << std::endl << " Can't compile vertexshader \"" << _vertexShaderFileName << "\""; std::cerr << std::endl; #endif } // validate the vertex shader and print compiler log validateShader(vs, _vertexShaderFileName); // fragment shader glCompileShader( fs ); glGetShaderiv(fs, GL_COMPILE_STATUS, &fsCompiled); if (fsCompiled == GL_FALSE) { #ifndef GLOOST_SYSTEM_DISABLE_OUTPUT_ERRORS std::cerr << std::endl; std::cerr << std::endl << "ERROR in shader::create() on SharedResource " << getSharedResourceId() << ":"; std::cerr << std::endl << " Cant't compile fragmentshader \"" << _fragmentShaderFileName << "\""; std::cerr << std::endl; #endif } // validate the fragment shader and print compiler log validateShader(fs, _fragmentShaderFileName); // geometry shader if (gs) { glCompileShader( gs ); glGetShaderiv(gs, GL_COMPILE_STATUS, &gsCompiled); if (gsCompiled == GL_FALSE) { #ifndef GLOOST_SYSTEM_DISABLE_OUTPUT_ERRORS std::cerr << std::endl; std::cerr << std::endl << "ERROR in shader::create() on SharedResource " << getSharedResourceId() << ":"; std::cerr << std::endl << " Cant't compile geometryshader \"" << _geometryShaderFileName << "\""; std::cerr << std::endl; #endif } // validate the fragment shader and print compiler log validateShader(gs, _geometryShaderFileName); } else { // shader not used - set compile flag anyway gsCompiled = GL_TRUE; }// if (geometry shader exist) /// create a shader program and attache the compiled vertex, fragment and geometry binaries unsigned int shaderHandle = glCreateProgram(); /// make a association between the context and the GL handle of this shader setResourceHandleForContext(shaderHandle, contextId); /// attache programs to shaderh handle glAttachShader( shaderHandle, fs ); glAttachShader( shaderHandle, vs ); if (gs) { glAttachShader( shaderHandle, gs ); CheckErrorsGL(("Shader::initInContext() after attaching geometry shader for Shared Resource " + gloost::toString(getSharedResourceId())).c_str()); for ( params =_programParameter.begin(); params != _programParameter.end(); params++ ) { glProgramParameteriEXT(shaderHandle, (*params).first, (*params).second); CheckErrorsGL(("Shader::initInContext() after setting for Shared Resource " + gloost::toString(getSharedResourceId())).c_str()); } } /// link programs glLinkProgram(shaderHandle); // int temp; // glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT,&temp); // std::cerr << std::endl << "GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT: " << temp; #ifndef GLOOST_SYSTEM_DISABLE_OUTPUT_MESSAGES if (vsCompiled == GL_TRUE && fsCompiled == GL_TRUE && gsCompiled == GL_TRUE) { std::cerr << std::endl; std::cerr << std::endl << "Message from Shader::compileToProgram() on SharedResource " << getSharedResourceId() << ":"; std::cerr << std::endl << " Successfully compiled and linked."; std::cerr << std::endl << " \"" << _vertexShaderFileName << "\", "; std::cerr << std::endl << " \"" << _fragmentShaderFileName << "\""; if (gs) { std::cerr << ", "<< std::endl << " \"" << _geometryShaderFileName << "\""; } std::cerr << std::endl; return true; } #endif return false; }
/*! \fn void DataManager::initTextureUnits(int w, int h) \brief Read in Input Image and create the appropriate texture object \param w : Input Image Width. \param h : Input Image Height */ void DataManager::initTextureUnits(int w, int h) { switch(_arch) { case GPU_ATI: _texTarget = GL_TEXTURE_2D; _texInternalFormat = GL_RGBA_FLOAT16_ATI; break; case GPU_NVIDIA: _texTarget = GL_TEXTURE_RECTANGLE_NV; _texInternalFormat = GL_FLOAT_RGBA32_NV; break; } CheckErrorsGL("DM::initTextureUnits 1"); //////////////// Initialize Input Texture //////////////// _inputImageTU = new TextureUnit(w, h, _texTarget, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, GL_LINEAR); CheckErrorsGL("DM::initTextureUnits 2"); //////////////// Initialize Distortion Texture Map /////// _distortionMapTU = new TextureUnit(_image_w, _image_h, _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); CheckErrorsGL("DM::initTextureUnits 3"); //////////////// Generate a Distortion Map //////////////// float * distortionmap = new float [ _image_w * _image_h * 4]; float WMax = 1.0/(1.0* _image_w); float HMax = 1.0/(1.0* _image_h); int i=0; for (int k=0; k< _image_h; k++) { for (int j=0; j < _image_w; j++) { float del_x = WMax * (j - _image_w/2); float del_y = HMax * (k - _image_h/2); float r = sqrt( del_x * del_x + del_y * del_y); float rdist = r * ( 1 + 0.05 * r*r); //0.095 if (r==0.0) { del_x = 0.0; del_y = 0.0; } else { del_x = rdist * ( del_x / r ) - del_x ; del_y = rdist * ( del_y / r ) - del_y ; } distortionmap[i++] = - del_x + 0.5 ; distortionmap[i++] = - del_y + 0.5 ; distortionmap[i++] = 0.0; distortionmap[i++] = 0.0; } } //////////////// Update Distortion Texture Map /////// _distortionMapTU->resetTextureFLOAT(distortionmap); CheckErrorsGL("DM::initTextureUnits 4"); //////////////// Initialize Pyramid Storage /////// _pyramid[0] = new FrameUnit (_arch, _image_w, _image_h, _nLevels, _texTarget, _texInternalFormat); _pyramid[1] = new FrameUnit (_arch, _image_w, _image_h, _nLevels, _texTarget, _texInternalFormat); CheckErrorsGL("DM::initTextureUnits 5"); //////////////// Initialize KLT Data Struct Storage /////// // For FBO Efficiency, ALL TEXTURES UNITS ARE SAME SIZE, (only then FBO's can have multiple attachments) int N = _maxFeatureTableSize; _kltCornernessTU1 = new TextureUnit(_image_w, _image_h, _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _kltCornernessTU2 = new TextureUnit(_image_w, _image_h, _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _kltFeaturesTU = new TextureUnit( N , 100 , _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _kltFloatingWindowTU = new TextureUnit( N , 100 , _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _kltPartialSumTU = new TextureUnit( N , 100 , _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _kltMatrixElemTU = new TextureUnit( N , 100 , _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); debugTable = new TextureUnit( 100, 7*20 , _texTarget, _texInternalFormat, GL_RGBA, GL_FLOAT, GL_NEAREST); _xSize = N; _ySize = 100; switch(_arch) { case GPU_ATI: _xOffset = 1.0 / (1.0 * N); _yOffset = 1.0 / 100.0; break; case GPU_NVIDIA: _xOffset = 1.0 ; _yOffset = 1.0 ; break; } CheckErrorsGL("DM::initTextureUnits 6"); // Buffer Data used to upload feature coordinate list to GPU at the beginning of call to trackFeatures() data = new float [ _xSize * _ySize * 4 ]; //Create the shadow map texture glGenTextures (1, &depthTexture); glBindTexture (_texTarget, depthTexture); glTexParameteri (_texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (_texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (_texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri (_texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexImage2D (_texTarget, 0, GL_DEPTH_COMPONENT, _image_w, _image_h, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); return ; }