//------------------------------------------------------------- // ARBProgram::isSupported() return true if shader is supported //------------------------------------------------------------- bool ARBProgram::isSupported(){ if (isExtensionSupported ("GL_ARB_fragment_program") && isExtensionSupported ("GL_ARB_vertex_program") ) return true; return false; }
int main( int argc, char **argv ) { int success = 0; GLcharARB *VertexShaderSource, *FragmentShaderSource; int error = 0; if (Args(argc, argv) == FALSE) exit(0); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); glutInitWindowSize(500, 500); window = glutCreateWindow( "Fire and Smoke" ); glutIdleFunc( play ); glutDisplayFunc( display ); glutKeyboardFunc( key ); glutReshapeFunc( reshape ); printOpenGLError(); if ( !isExtensionSupported( "GL_ARB_shader_objects" ) || !isExtensionSupported( "GL_ARB_fragment_shader" ) || !isExtensionSupported( "GL_ARB_vertex_shader" ) || !isExtensionSupported( "GL_ARB_shading_language_100" ) ) { printf("OpenGL Shading Language extensions not available\n" ); return 1; } if( error ) { printf( "ERROR from wglGetProcAddress\n" ); } createPoints( numParticles ); glDepthFunc( GL_LESS ); glEnable( GL_DEPTH_TEST ); glClearColor( 0.0f, 0.67f, 0.94f, 1.0f ); ParticleTime = 0.0f; readShaderSource( "smoke", &VertexShaderSource, &FragmentShaderSource ); success = installParticleShaders( VertexShaderSource, FragmentShaderSource ); if ( success ) { glutMainLoop(); } else { printf( "Error installing particle shaders" ); scanf( "%d", ParticleTime ); } return 0; }
void Renderer::loadExtensions(){ if(isExtensionSupported("GL_EXT_fog_coord")) glFogCoordf = (PFNGLFOGCOORDFPROC) wglGetProcAddress("glFogCoordf"); else glFogCoordf = 0; if(isExtensionSupported("GL_EXT_blend_color")) glBlendColor = (PFNGLBLENDCOLORPROC)wglGetProcAddress("glBlendColor"); else glBlendColor = 0; }
//caches various system checks void ofxFBOTexture::supportCheck(){ if(!bSupportChecked){ bSupportsFBO = isExtensionSupported("GL_EXT_framebuffer_object"); bSupportsBlit = isExtensionSupported("GL_EXT_framebuffer_blit"); bSupportsMulti = isExtensionSupported("GL_EXT_framebuffer_multisample"); glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT,&maxRenderBufferSize); glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxTextureSize); glGetIntegerv(GL_SAMPLES,&maxSamples); bSupportChecked = true; } }
bool initializeSecondaryColorExtension() { if ( isExtensionSupported( "GL_EXT_secondary_color" )) { #ifndef GL_GLEXT_VERSION glSecondaryColor3bEXT = (PFNGLSECONDARYCOLOR3BEXTPROC)wglGetProcAddress( "glSecondaryColor3bEXT" ); glSecondaryColor3bvEXT = (PFNGLSECONDARYCOLOR3BVEXTPROC)wglGetProcAddress( "glSecondaryColor3bvEXT" ); glSecondaryColor3dEXT = (PFNGLSECONDARYCOLOR3DEXTPROC)wglGetProcAddress( "glSecondaryColor3dEXT" ); glSecondaryColor3dvEXT = (PFNGLSECONDARYCOLOR3DVEXTPROC)wglGetProcAddress( "glSecondaryColor3dvEXT" ); glSecondaryColor3fEXT = (PFNGLSECONDARYCOLOR3FEXTPROC)wglGetProcAddress( "glSecondaryColor3fEXT" ); glSecondaryColor3fvEXT = (PFNGLSECONDARYCOLOR3FVEXTPROC)wglGetProcAddress( "glSecondaryColor3fvEXT" ); glSecondaryColor3iEXT = (PFNGLSECONDARYCOLOR3IEXTPROC)wglGetProcAddress( "glSecondaryColor3iEXT" ); glSecondaryColor3ivEXT = (PFNGLSECONDARYCOLOR3IVEXTPROC)wglGetProcAddress( "glSecondaryColor3ivEXT" ); glSecondaryColor3sEXT = (PFNGLSECONDARYCOLOR3SEXTPROC)wglGetProcAddress( "glSecondaryColor3sEXT" ); glSecondaryColor3svEXT = (PFNGLSECONDARYCOLOR3SVEXTPROC)wglGetProcAddress( "glSecondaryColor3svEXT" ); glSecondaryColor3ubEXT = (PFNGLSECONDARYCOLOR3UBEXTPROC)wglGetProcAddress( "glSecondaryColor3ubEXT" ); glSecondaryColor3ubvEXT = (PFNGLSECONDARYCOLOR3UBVEXTPROC)wglGetProcAddress( "glSecondaryColor3ubvEXT" ); glSecondaryColor3uiEXT = (PFNGLSECONDARYCOLOR3UIEXTPROC)wglGetProcAddress( "glSecondaryColor3uiEXT" ); glSecondaryColor3uivEXT = (PFNGLSECONDARYCOLOR3UIVEXTPROC)wglGetProcAddress( "glSecondaryColor3uivEXT" ); glSecondaryColor3usEXT = (PFNGLSECONDARYCOLOR3USEXTPROC)wglGetProcAddress( "glSecondaryColor3usEXT" ); glSecondaryColor3usvEXT = (PFNGLSECONDARYCOLOR3USVEXTPROC)wglGetProcAddress( "glSecondaryColor3usvEXT" ); glSecondaryColorPointerEXT = (PFNGLSECONDARYCOLORPOINTEREXTPROC)wglGetProcAddress( "glSecondaryColorPointerEXT" ); #endif return true; } return false; }
//好了,现在到了初始化的地方了。首先我将分配并载入纹理数据。接着检测是否支持VBO扩展。 //如果支持我们将把函数指针和它对应的函数关联起来,如果不支持将只返回数据。 void MyGLWidget::initializeGL() { // 载入纹理数据 m_pMesh = new CMesh(); if( !m_pMesh->loadHeightmap(MESH_HEIGHTSCALE, MESH_RESOLUTION) ) { QMessageBox::critical(this, "Error", "Error Loading Heightmap"); } // 检测是否支持VBO扩展 #ifndef NO_VBOS g_fVBOSupported = isExtensionSupported( "GL_ARB_vertex_buffer_object" ); if( g_fVBOSupported ) { // 获得函数的指针 glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB"); glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB"); glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB"); glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) wglGetProcAddress("glDeleteBuffersARB"); // 创建VBO对象 m_pMesh->buildVBOs(); } #else g_fVBOSupported = false; #endif //设置OpenGL状态 glClearColor (0.0f, 0.0f, 0.0f, 0.5f); glClearDepth (1.0f); glDepthFunc (GL_LEQUAL); glEnable (GL_DEPTH_TEST); glShadeModel (GL_SMOOTH); glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable( GL_TEXTURE_2D ); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); }
void Renderer::initGlState() { // move this to an extra function - otherwice it's called twice due to mulitsampling loadExtensions(); glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearDepth(1.0f); // Depth Buffer Setup glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glHint(GL_TEXTURE_COMPRESSION_HINT,GL_FASTEST); glEnable(GL_TEXTURE_2D); GLint maxTexSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize); ImgTexture::setMaxGlTextureSize(maxTexSize); if (isExtensionSupported("GL_EXT_fog_coord")){ glFogi(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 5); GLfloat fogColor[4] = {0.0f, 0.0f, 0.0f, 1.0f}; // Fog Color - should be BG color glFogfv(GL_FOG_COLOR, fogColor); // Set The Fog Color glHint(GL_FOG_HINT, GL_NICEST); // Per-Pixel Fog Calculation glFogi(GL_FOG_COORD_SRC, GL_FOG_COORD); // Set Fog Based On Vertice Coordinates } glfwSwapInterval(0); vSyncEnabled = false; }
//----------------------------------------------------------------------------- //* Initialize //! Initializes fog extensions //----------------------------------------------------------------------------- void FogManager::initialize() { m_multiplier = 0; m_offset = 0; //Initialize extensions static bool fogExtensionInitialized = false; if ( !fogExtensionInitialized ) { m_fogExtensionsSupported = isExtensionSupported("GL_EXT_fog_coord"); if ( m_fogExtensionsSupported ) { #ifndef GL_GLEXT_VERSION glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC)wglGetProcAddress( "glFogCoordfEXT" ); glFogCoordfvEXT = (PFNGLFOGCOORDFVEXTPROC)wglGetProcAddress( "glFogCoordfvEXT" ); glFogCoorddEXT = (PFNGLFOGCOORDDEXTPROC)wglGetProcAddress( "glFogCoorddEXT" ); glFogCoorddvEXT = (PFNGLFOGCOORDDVEXTPROC)wglGetProcAddress( "glFogCoorddvEXT" ); glFogCoordPointerEXT = (PFNGLFOGCOORDPOINTEREXTPROC)wglGetProcAddress( "glFogCoordPointerEXT" ); #endif fogExtensionInitialized = true; } } glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); }
void DrawBuffersIndexedBase::init() { if (!isExtensionSupported("GL_OES_draw_buffers_indexed")) { throw tcu::NotSupportedError(DRAW_BUFFERS_INDEXED_NOT_SUPPORTED); } }
void X11Window::setVerticalSync(bool enable) { #ifdef OPENGL_ES //TODO #else typedef GLint (*glSwapIntervalProc)(GLint); glSwapIntervalProc glSwapInterval = NULL; if(isExtensionSupported("GLX_MESA_swap_control")) glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA"); else if(isExtensionSupported("GLX_SGI_swap_control")) glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalSGI"); if(glSwapInterval) glSwapInterval(enable ? 1 : 0); #endif }
void GLGraphicsContext::loadCapabilities() { GLint maxViewportDims[2]; GLint maxTextureSize; GLint max3DTextureSize; GLint maxCubeMapTextureSize; GLint maxVertexAttribs; GLint maxVertexTextureImageUnits; GLint maxVertexUniformComponents; GLint maxTextureImageUnits; GLint maxFragmentUniformComponents; GLint maxVaryingFloats; GLint maxDrawBuffers; glGetIntegerv(GL_MAX_VIEWPORT_DIMS, maxViewportDims); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &max3DTextureSize); glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxCubeMapTextureSize); glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxVertexTextureImageUnits); glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &maxVertexUniformComponents); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &maxFragmentUniformComponents); glGetIntegerv(GL_MAX_VARYING_FLOATS, &maxVaryingFloats); glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); capabilities.setMaxViewportWidth(maxViewportDims[0]); capabilities.setMaxViewportHeight(maxViewportDims[1]); capabilities.setMaxTexture1DSize(maxTextureSize); capabilities.setMaxTexture2DSize(maxTextureSize); capabilities.setMaxTexture3DSize(max3DTextureSize); capabilities.setMaxTextureCubeSize(maxCubeMapTextureSize); // Anistropic filtering extension if (isExtensionSupported("GL_EXT_texture_filter_anisotropic")) { GLfloat maxTextureMaxAnisotropy; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxTextureMaxAnisotropy); capabilities.setMaxAnisotropyLevel(maxTextureMaxAnisotropy); } else { capabilities.setMaxAnisotropyLevel(1.0f); } capabilities.setMaxVertexAttributes(maxVertexAttribs); capabilities.setMaxVertexShaderTextureUnits(maxVertexTextureImageUnits); capabilities.setMaxVertexShaderUniformComponents(maxVertexUniformComponents); capabilities.setMaxPixelShaderTextureUnits(maxTextureImageUnits); capabilities.setMaxPixelShaderUniformComponents(maxFragmentUniformComponents); capabilities.setMaxVaryingFloats(maxVaryingFloats); }
bool isExtensionSupported ( const char * ext ) { initExtensions (); // since we will need it for platform-specific extensions const char * extensions = (const char *) glGetString ( GL_EXTENSIONS ); if ( isExtensionSupported ( ext, extensions ) ) return true; #ifdef _WIN32 // check Windoze extensions if ( wglGetExtensionsStringARB == NULL ) return false; return isExtensionSupported ( ext, wglGetExtensionsStringARB ( wglGetCurrentDC () ) ); #else // check GLX extensions Display * display = glXGetCurrentDisplay (); int screen = DefaultScreen ( display ); return isExtensionSupported ( ext, glXQueryExtensionsString ( display, screen ) ); #endif }
void assertExtensionsSupported ( const char * extList ) { char * str = strdup ( extList ); for ( char * ptr = strtok ( str, " ,;\t" ); ptr != NULL; ptr = strtok ( NULL, " ,;\t" ) ) if ( !isExtensionSupported ( ptr ) ) { fprintf ( stderr, "Error - extension %s not supported.\n", ptr ); free ( str ); //exit ( 1 ); } free ( str ); }
int yglQueryTexCube(void) { int res; if(glCurrWin3d->hascubetex >= 0) return glCurrWin3d->hascubetex; /* Make sure the OpenGL context is current */ yglMakeCurrent(glCurrWin3d); res = isExtensionSupported("GL_EXT_texture_cube_map"); if(res) { glCurrWin3d->hascubetex= 1; /* has cube-map texture support */ } else { glCurrWin3d->hascubetex= 0; /* not supported */ } return glCurrWin3d->hascubetex; }
void WIN32Window::setVerticalSync(bool enable) { #ifdef OPENGL_ES eglSwapInterval(m_eglDisplay, enable ? 1 : 0); #else if(!isExtensionSupported("WGL_EXT_swap_control")) return; typedef BOOL (WINAPI * wglSwapIntervalProc)(int); wglSwapIntervalProc wglSwapInterval = (wglSwapIntervalProc)getExtensionProcAddress("wglSwapIntervalEXT"); if(!wglSwapInterval) return; wglSwapInterval(enable ? 1 : 0); #endif }
void CheckExtensionsProc(HWND hDlg) { if (isExtensionSupported("GL_ARB_multitexture") != FALSE) //scan for multitexture support {SetDlgItemText(hDlg,IDC_TEXTURE, "YES");} else SetDlgItemText(hDlg,IDC_TEXTURE, "NO"); if (isExtensionSupported("GL_EXT_packed_pixels") != FALSE) //scan for compressed texture support {SetDlgItemText(hDlg,IDC_TEXCOMP, "YES");} else SetDlgItemText(hDlg,IDC_TEXCOMP, "NO"); if (isExtensionSupported("GL_EXT_framebuffer_object") != FALSE) //scan for compressed texture support {SetDlgItemText(hDlg,IDC_FBO, "YES");} else SetDlgItemText(hDlg,IDC_FBO, "NO"); if (isExtensionSupported("GL_ARB_shading_language_100") && isExtensionSupported("GL_ARB_shader_objects") && isExtensionSupported("GL_ARB_fragment_shader") && isExtensionSupported("GL_ARB_vertex_shader") != FALSE){ SetDlgItemText(hDlg,IDC_SHADERS, "YES");} else SetDlgItemText(hDlg,IDC_SHADERS, "NO"); if (isExtensionSupported("GL_ARB_texture_non_power_of_two") != FALSE){ SetDlgItemText(hDlg,IDC_NPOT, "YES"); } else SetDlgItemText(hDlg,IDC_NPOT, "NO"); if (isExtensionSupported("GL_EXT_texture_compression_s3tc") != FALSE){ SetDlgItemText(hDlg,IDC_S3TC, "YES"); } else SetDlgItemText(hDlg,IDC_S3TC, "NO"); if (isExtensionSupported("GL_3DFX_texture_compression_FXT1") != FALSE){ SetDlgItemText(hDlg,IDC_FXT1, "YES"); } else SetDlgItemText(hDlg,IDC_FXT1, "NO"); }
int yglTexExtSetup(void) { int res; yglMakeCurrent(glCurrWin3d); if(glCurrWin3d->hasTexExt >= 0) return glCurrWin3d->hasTexExt; res = isExtensionSupported("GL_EXT_texture"); res= 1; if(res) { glCurrWin3d->hasTexExt= 1; glCurrWin3d->myglBindTexture3D = (glBindTextureProc) LookupFunction("glBindTexture3DEXT"); } else { glCurrWin3d->hasTexExt= 0; glCurrWin3d->myglBindTexture3D = NULL; } return glCurrWin3d->hasTexExt; }
void printfInfo () // print info about card, driver, version & etc { const char * vendor = (const char *)glGetString ( GL_VENDOR ); const char * renderer = (const char *)glGetString ( GL_RENDERER ); const char * version = (const char *)glGetString ( GL_VERSION ); printf ( "Graphics card and driver information:\n" ); printf ( "Vendor: %s\nRenderer: %s\nVersion: %s\n", vendor, renderer, version ); if ( isExtensionSupported ( "GL_ARB_multitexture" ) ) { int maxTextureUnits; glGetIntegerv ( GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits ); printf ( "ARB_multitexture supported.\nMax texture units %d.\n", maxTextureUnits ); } if ( isExtensionSupported ( "GL_NV_register_combiners" ) ) { int maxCombiners; glGetIntegerv ( GL_MAX_GENERAL_COMBINERS_NV, &maxCombiners ); printf ( "NV_register_combiners supported.\nMax general combiners %d.\n", maxCombiners ); } if ( isExtensionSupported ( "GL_ARB_vertex_buffer_object" ) ) printf ( "VBO supported.\n" ); if ( isExtensionSupported ( "GL_NV_occlusion_query" ) ) printf ( "NV_occlusion_query extension supported.\n" ); if ( isExtensionSupported ( "GL_SGIS_generate_mipmap" ) ) printf ( "GL_SGIS_generate_mipmap extension supported.\n" ); if ( isExtensionSupported ( "GL_ARB_vertex_program" ) ) printf ( "GL_ARB_vertex_program extension supported.\n" ); }
int InitialOpenGL() { int pfmt; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 24, // z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; if ((hdc = GetDC(gDemulInfo->hGpuWnd)) == 0) { MessageBox(NULL, "GetDC failed", "Error", MB_OK); DeleteOpenGL(); return 0; } if ((pfmt = ChoosePixelFormat(hdc, &pfd)) == 0) { MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK); DeleteOpenGL(); return 0; } if ((SetPixelFormat(hdc, pfmt, &pfd)) == 0) { MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK); DeleteOpenGL(); return 0; } if ((hrc = wglCreateContext(hdc)) == 0) { MessageBox(NULL, "wglCreateContext failed", "Error", MB_OK); DeleteOpenGL(); return 0; } if ((wglMakeCurrent(hdc, hrc)) == 0) { MessageBox(NULL, "wglMakeCurrent failed", "Error", MB_OK); DeleteOpenGL(); return 0; } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearDepth(0.0f); glDepthRange(0.0f, 1.0f); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDisable(GL_LIGHTING); glGenTextures(1, &backbufname); glBindTexture(GL_TEXTURE_2D, backbufname); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, &VRAM[0]); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(VERTEX), &pVertex->x); glTexCoordPointer(2, GL_FLOAT, sizeof(VERTEX), &pVertex->tu); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VERTEX), &pVertex->color); if (isExtensionSupported("GL_EXT_secondary_color")) { glEnableClientState(GL_SECONDARY_COLOR_ARRAY); glSecondaryColorPointer = (PFNGLSECONDARYCOLORPOINTEREXTPROC)wglGetProcAddress("glSecondaryColorPointerEXT"); glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, sizeof(VERTEX), &pVertex->extcolor); } return 1; }
void *glx_init(glx_opengl_version_t version) { Display *display; struct state_glx *context; context = (struct state_glx *) malloc(sizeof(struct state_glx)); context->magic = GLX_MAGIC; x11_lock(); display = x11_acquire_display(); if(!display) { free(context); x11_unlock(); return NULL; } #ifdef HAVE_GPUPERFAPI GPA_Status gpa_status; gpa_status = GPA_Initialize(); assert(gpa_status == GPA_STATUS_OK); #endif // Get a matching FB config static int visual_attribs[] = { GLX_X_RENDERABLE , True, GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, GLX_RENDER_TYPE , GLX_RGBA_BIT, GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_ALPHA_SIZE , 8, GLX_DEPTH_SIZE , 24, GLX_STENCIL_SIZE , 8, GLX_DOUBLEBUFFER , True, //GLX_SAMPLE_BUFFERS , 1, //GLX_SAMPLES , 4, None }; int glx_major, glx_minor; // FBConfigs were added in GLX version 1.3. if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) ) { printf( "Invalid GLX version" ); goto error; } printf( "Getting matching framebuffer configs\n" ); int fbcount; GLXFBConfig *fbc = glXChooseFBConfig( display, DefaultScreen( display ), visual_attribs, &fbcount ); if ( !fbc ) { printf( "Failed to retrieve a framebuffer config\n" ); goto error; } printf( "Found %d matching FB configs.\n", fbcount ); // Pick the FB config/visual with the most samples per pixel printf( "Getting XVisualInfos\n" ); int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999; int i; for ( i = 0; i < fbcount; i++ ) { XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] ); if ( vi ) { int samp_buf, samples; glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf ); glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES , &samples ); printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d," " SAMPLES = %d\n", i, (unsigned int) vi -> visualid, samp_buf, samples ); if ( best_fbc < 0 || (samp_buf && samples > best_num_samp )) best_fbc = i, best_num_samp = samples; if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp ) worst_fbc = i, worst_num_samp = samples; } XFree( vi ); } GLXFBConfig bestFbc = fbc[ best_fbc ]; // Be sure to free the FBConfig list allocated by glXChooseFBConfig() XFree( fbc ); // Get a visual XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc ); printf( "Chosen visual ID = 0x%x\n", (unsigned int) vi->visualid ); printf( "Creating colormap\n" ); XSetWindowAttributes swa; swa.colormap = context->cmap = XCreateColormap( display, RootWindow( display, vi->screen ), vi->visual, AllocNone ); swa.background_pixmap = None ; swa.border_pixel = 0; swa.event_mask = StructureNotifyMask; printf( "Creating window\n" ); context->win = XCreateWindow( display, RootWindow( display, vi->screen ), 0, 0, 1920, 1080, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa ); XMoveWindow(display, context->win, 0, 0); if ( !context->win ) { printf( "Failed to create window.\n" ); goto error; } // Done with the visual info data XFree( vi ); /* We don't need this for UG */ /*XStoreName( display, win, "GL 3.0 Window" ); printf( "Mapping window\n" ); XMapWindow( display, win );*/ // Get the default screen's GLX extension list const char *glxExts = glXQueryExtensionsString( display, DefaultScreen( display ) ); // NOTE: It is not necessary to create or make current to a context before // calling glXGetProcAddressARB glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); context->ctx = 0; // Install an X error handler so the application won't exit if GL 3.0 // context allocation fails. // // Note this error handler is global. All display connections in all threads // of a process use the same error handler, so be sure to guard against other // threads issuing X commands while this code is running. ctxErrorOccurred = FALSE; int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); // Check for the GLX_ARB_create_context extension string and the function. // If either is not present, use GLX 1.3 context creation method. if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) || !glXCreateContextAttribsARB ) { printf( "glXCreateContextAttribsARB() not found" " ... using old-style GLX context\n" ); context->ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True ); if(!VERSION_IS_UNSPECIFIED(version)) { return NULL; } } // If it does, try to get a GL 3.0 context! else { int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None }; if(!VERSION_IS_UNSPECIFIED(version)) { context_attribs[1] = VERSION_GET_MAJOR(version); context_attribs[3] = VERSION_GET_MINOR(version); } printf( "Creating context\n" ); context->ctx = glXCreateContextAttribsARB( display, bestFbc, 0, True, context_attribs ); // Sync to ensure any errors generated are processed. XSync( display, False ); if ( !ctxErrorOccurred && context->ctx ) printf( "Created GL %d.%d context\n", context_attribs[1], context_attribs[3]); else { if(VERSION_IS_UNSPECIFIED(version)) { // Couldn't create GL 3.0 context. Fall back to old-style 2.x context. // When a context version below 3.0 is requested, implementations will // return the newest context version compatible with OpenGL versions less // than version 3.0. // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 context_attribs[1] = 1; // GLX_CONTEXT_MINOR_VERSION_ARB = 0 context_attribs[3] = 0; ctxErrorOccurred = FALSE; printf( "Failed to create GL 3.0 context" " ... using old-style GLX context\n" ); context->ctx = glXCreateContextAttribsARB( display, bestFbc, 0, True, context_attribs ); } else { // we explicitly requested context which we cannot obtain - return error then goto error; } } } // Sync to ensure any errors generated are processed. XSync( display, False ); // Restore the original error handler XSetErrorHandler( oldHandler ); if ( ctxErrorOccurred || !context->ctx ) { printf( "Failed to create an OpenGL context\n" ); goto error; } // Verifying that context is a direct context if ( ! glXIsDirect ( display, context->ctx ) ) { printf( "Indirect GLX rendering context obtained\n" ); } else { printf( "Direct GLX rendering context obtained\n" ); } printf( "Making context current\n" ); glXMakeCurrent( display, context->win, context->ctx ); glewInit(); x11_unlock(); glx_validate(context); #ifdef HAVE_GPUPERFAPI gpa_status = GPA_OpenContext( context->ctx ); assert(gpa_status == GPA_STATUS_OK); #endif return (void *) context; error: free(context); x11_unlock(); return NULL; }
void GLWindow::initializeGL() { mInitialized = true; if( checkGLError() ) LOG_TRACE // Set up the rendering context, define display lists etc.: glClearColor( 8/256.0, 5/256.0, 76/256.0, 0.0 ); glDisable(GL_DEPTH_TEST); if( checkGLError() ) LOG_TRACE #ifdef COMPILE_CG if( mUseCG && cgGLIsProfileSupported( CG_PROFILE_FP20 ) ){ //LOG_3("Using Cg"); // This is the most basic fragment profile, should run on quite a few cards cgFragmentProfile = CG_PROFILE_FP20; cgSetErrorCallback(cgErrorCallback); cgContext = cgCreateContext(); // TODO: Include the shader source in the executable cgProgram = cgCreateProgram( cgContext, CG_SOURCE, FRAGMENT_SHADER, cgFragmentProfile, 0, 0); cgGLLoadProgram( cgProgram ); cgImageParam = cgGetNamedParameter( cgProgram, "image" ); cgColorClampParam = cgGetNamedParameter( cgProgram, "colorClamp" ); cgGLBindProgram( cgProgram ); }else #endif { //LOG_3("Using stock OpenGL"); mUseCG = false; } // GL_TEXTURE_ENV_MODE defaults to GL_MODULATE // GL_TEXTURE_ENV_COLOR defaults to (0,0,0,0) #ifdef GL_NV_texture_rectangle mUseGL_NV_texture_rectangle = isExtensionSupported( "GL_NV_texture_rectangle" ); if( checkGLError() ) LOG_TRACE #endif // GL_NV_texture_rectangle #ifdef GL_NV_texture_rectangle if( mUseGL_NV_texture_rectangle ){ //LOG_5( "Using GL_TEXTURE_RECTANGLE_NV" ); mTextureMode = GL_TEXTURE_RECTANGLE_NV; // Only try to use cg, if texture_rectangle is supported // 4/23/04 WHY? mUseCG = true; } else #endif // GL_NV_texture_rectangle { //qWarning("NOT USING GL_TEXTURE_RECTANGLE_NV"); mTextureMode = GL_TEXTURE_2D; // Set up the texturing params GLint wrapMode = GL_CLAMP; int glMajor, glMinor; glVersion(glMajor,glMinor); if( glMajor >= 1 && glMinor >=2 ) wrapMode = GL_CLAMP_TO_EDGE; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, wrapMode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, wrapMode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); } }
int CreateX11Window( const std::string& title, int width, int height, bool glx_doublebuffer,int glx_sample_buffers, int glx_samples ) { display = XOpenDisplay(NULL); if (!display) { throw std::runtime_error("Pangolin X11: Failed to open X display"); } // Desired attributes static int visual_attribs[] = { GLX_X_RENDERABLE , True, GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, GLX_RENDER_TYPE , GLX_RGBA_BIT, GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_ALPHA_SIZE , 8, GLX_DEPTH_SIZE , 24, GLX_STENCIL_SIZE , 8, GLX_DOUBLEBUFFER , glx_doublebuffer ? True : False, GLX_SAMPLE_BUFFERS , glx_sample_buffers, GLX_SAMPLES , glx_sample_buffers > 0 ? glx_samples : 0, None }; int glx_major, glx_minor; if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) ) { // FBConfigs were added in GLX version 1.3. throw std::runtime_error("Pangolin X11: Invalid GLX version. Require GLX >= 1.3"); } int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &fbcount); if (!fbc) { throw std::runtime_error("Pangolin X11: Unable to retrieve framebuffer options"); } int best_fbc = -1; int worst_fbc = -1; int best_num_samp = -1; int worst_num_samp = 999; // Enumerate framebuffer options, storing the best and worst that match our attribs for (int i=0; i<fbcount; ++i) { XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] ); if ( vi ) { int samp_buf, samples; glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf ); glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES , &samples ); if ( (best_fbc < 0) || (samp_buf>0 && samples>best_num_samp) ) best_fbc = i, best_num_samp = samples; if ( (worst_fbc < 0) || (samp_buf>0 && samples<worst_num_samp) ) worst_fbc = i, worst_num_samp = samples; } XFree( vi ); } // Select the minimum suitable option. The 'best' is often too slow. GLXFBConfig bestFbc = fbc[ worst_fbc ]; XFree( fbc ); // Get a visual XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc ); // Create colourmap XSetWindowAttributes swa; swa.colormap = cmap = XCreateColormap( display, RootWindow( display, vi->screen ), vi->visual, AllocNone ); swa.background_pixmap = None ; swa.border_pixel = 0; swa.event_mask = StructureNotifyMask; // Create window win = XCreateWindow( display, RootWindow( display, vi->screen ), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa ); XFree( vi ); if ( !win ) { throw std::runtime_error("Pangolin X11: Failed to create window." ); } XStoreName( display, win, title.c_str() ); XMapWindow( display, win ); // Request to be notified of these events XSelectInput(display, win, EVENT_MASKS ); // Get the default screen's GLX extension list const char *glxExts = glXQueryExtensionsString( display, DefaultScreen( display ) ); glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); // Install an X error handler so the application won't exit if GL 3.0 // context allocation fails. Handler is global and shared across all threads. ctxErrorOccurred = false; int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); if ( isExtensionSupported( glxExts, "GLX_ARB_create_context" ) && glXCreateContextAttribsARB ) { int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None }; ctx = glXCreateContextAttribsARB( display, bestFbc, 0, True, context_attribs ); // Sync to ensure any errors generated are processed. XSync( display, False ); if ( ctxErrorOccurred || !ctx ) { ctxErrorOccurred = false; // Fall back to old-style 2.x context. Implementations will return the newest // context version compatible with OpenGL versions less than version 3.0. context_attribs[1] = 1; // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 context_attribs[3] = 0; // GLX_CONTEXT_MINOR_VERSION_ARB = 0 ctx = glXCreateContextAttribsARB( display, bestFbc, 0, True, context_attribs ); } } else { // Fallback to GLX 1.3 Context ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True ); } // Sync to ensure any errors generated are processed. XSync( display, False ); // Restore the original error handler XSetErrorHandler( oldHandler ); if ( ctxErrorOccurred || !ctx ) { throw std::runtime_error("Pangolin X11: Failed to create an OpenGL context"); } // Verifying that context is a direct context if ( ! glXIsDirect ( display, ctx ) ) { pango_print_warn("Pangolin X11: Indirect GLX rendering context obtained\n"); } glXMakeCurrent( display, win, ctx ); return 0; }
bool initOpenGLExtensions() { bool r = true; getOpenGLVersion(); // GL 1.2 r &= (glBlendColor = (PFNGLBLENDCOLORPROC) platGetProcAddress( "glBlendColor" )) != 0x0; r &= (glBlendEquation = (PFNGLBLENDEQUATIONPROC) platGetProcAddress( "glBlendEquation" )) != 0x0; r &= (glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) platGetProcAddress( "glDrawRangeElements" )) != 0x0; r &= (glTexImage3D = (PFNGLTEXIMAGE3DPROC) platGetProcAddress( "glTexImage3D" )) != 0x0; r &= (glTexSubImage3D = (PFNGLTEXSUBIMAGE3DPROC) platGetProcAddress( "glTexSubImage3D" )) != 0x0; r &= (glCopyTexSubImage3D = (PFNGLCOPYTEXSUBIMAGE3DPROC) platGetProcAddress( "glCopyTexSubImage3D" )) != 0x0; // GL 1.3 r &= (glActiveTexture = (PFNGLACTIVETEXTUREPROC) platGetProcAddress( "glActiveTexture" )) != 0x0; r &= (glSampleCoverage = (PFNGLSAMPLECOVERAGEPROC) platGetProcAddress( "glSampleCoverage" )) != 0x0; r &= (glCompressedTexImage3D = (PFNGLCOMPRESSEDTEXIMAGE3DPROC) platGetProcAddress( "glCompressedTexImage3D" )) != 0x0; r &= (glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) platGetProcAddress( "glCompressedTexImage2D" )) != 0x0; r &= (glCompressedTexImage1D = (PFNGLCOMPRESSEDTEXIMAGE1DPROC) platGetProcAddress( "glCompressedTexImage1D" )) != 0x0; r &= (glCompressedTexSubImage3D = (PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) platGetProcAddress( "glCompressedTexSubImage3D" )) != 0x0; r &= (glCompressedTexSubImage2D = (PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) platGetProcAddress( "glCompressedTexSubImage2D" )) != 0x0; r &= (glCompressedTexSubImage1D = (PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) platGetProcAddress( "glCompressedTexSubImage1D" )) != 0x0; r &= (glGetCompressedTexImage = (PFNGLGETCOMPRESSEDTEXIMAGEPROC) platGetProcAddress( "glGetCompressedTexImage" )) != 0x0; // GL 1.4 r &= (glBlendFuncSeparate = (PFNGLBLENDFUNCSEPARATEPROC) platGetProcAddress( "glBlendFuncSeparate" )) != 0x0; r &= (glMultiDrawArrays = (PFNGLMULTIDRAWARRAYSPROC) platGetProcAddress( "glMultiDrawArrays" )) != 0x0; r &= (glMultiDrawElements = (PFNGLMULTIDRAWELEMENTSPROC) platGetProcAddress( "glMultiDrawElements" )) != 0x0; r &= (glPointParameterf = (PFNGLPOINTPARAMETERFPROC) platGetProcAddress( "glPointParameterf" )) != 0x0; r &= (glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC) platGetProcAddress( "glPointParameterfv" )) != 0x0; r &= (glPointParameteri = (PFNGLPOINTPARAMETERIPROC) platGetProcAddress( "glPointParameteri" )) != 0x0; r &= (glPointParameteriv = (PFNGLPOINTPARAMETERIVPROC) platGetProcAddress( "glPointParameteriv" )) != 0x0; // GL 1.5 r &= (glGenQueries = (PFNGLGENQUERIESPROC) platGetProcAddress( "glGenQueries" )) != 0x0; r &= (glDeleteQueries = (PFNGLDELETEQUERIESPROC) platGetProcAddress( "glDeleteQueries" )) != 0x0; r &= (glIsQuery = (PFNGLISQUERYPROC) platGetProcAddress( "glIsQuery" )) != 0x0; r &= (glBeginQuery = (PFNGLBEGINQUERYPROC) platGetProcAddress( "glBeginQuery" )) != 0x0; r &= (glEndQuery = (PFNGLENDQUERYPROC) platGetProcAddress( "glEndQuery" )) != 0x0; r &= (glGetQueryiv = (PFNGLGETQUERYIVPROC) platGetProcAddress( "glGetQueryiv" )) != 0x0; r &= (glGetQueryObjectiv = (PFNGLGETQUERYOBJECTIVPROC) platGetProcAddress( "glGetQueryObjectiv" )) != 0x0; r &= (glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVPROC) platGetProcAddress( "glGetQueryObjectuiv" )) != 0x0; r &= (glBindBuffer = (PFNGLBINDBUFFERPROC) platGetProcAddress( "glBindBuffer" )) != 0x0; r &= (glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) platGetProcAddress( "glDeleteBuffers" )) != 0x0; r &= (glGenBuffers = (PFNGLGENBUFFERSPROC) platGetProcAddress( "glGenBuffers" )) != 0x0; r &= (glIsBuffer = (PFNGLISBUFFERPROC) platGetProcAddress( "glIsBuffer" )) != 0x0; r &= (glBufferData = (PFNGLBUFFERDATAPROC) platGetProcAddress( "glBufferData" )) != 0x0; r &= (glBufferSubData = (PFNGLBUFFERSUBDATAPROC) platGetProcAddress( "glBufferSubData" )) != 0x0; r &= (glGetBufferSubData = (PFNGLGETBUFFERSUBDATAPROC) platGetProcAddress( "glGetBufferSubData" )) != 0x0; r &= (glMapBuffer = (PFNGLMAPBUFFERPROC) platGetProcAddress( "glMapBuffer" )) != 0x0; r &= (glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) platGetProcAddress( "glUnmapBuffer" )) != 0x0; r &= (glGetBufferParameteriv = (PFNGLGETBUFFERPARAMETERIVPROC) platGetProcAddress( "glGetBufferParameteriv" )) != 0x0; r &= (glGetBufferPointerv = (PFNGLGETBUFFERPOINTERVPROC) platGetProcAddress( "glGetBufferPointerv" )) != 0x0; // GL 2.0 r &= (glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) platGetProcAddress( "glBlendEquationSeparate" )) != 0x0; r &= (glDrawBuffers = (PFNGLDRAWBUFFERSPROC) platGetProcAddress( "glDrawBuffers" )) != 0x0; r &= (glStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) platGetProcAddress( "glStencilOpSeparate" )) != 0x0; r &= (glStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) platGetProcAddress( "glStencilFuncSeparate" )) != 0x0; r &= (glStencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC) platGetProcAddress( "glStencilMaskSeparate" )) != 0x0; r &= (glAttachShader = (PFNGLATTACHSHADERPROC) platGetProcAddress( "glAttachShader" )) != 0x0; r &= (glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) platGetProcAddress( "glBindAttribLocation" )) != 0x0; r &= (glCompileShader = (PFNGLCOMPILESHADERPROC) platGetProcAddress( "glCompileShader" )) != 0x0; r &= (glCreateProgram = (PFNGLCREATEPROGRAMPROC) platGetProcAddress( "glCreateProgram" )) != 0x0; r &= (glCreateShader = (PFNGLCREATESHADERPROC) platGetProcAddress( "glCreateShader" )) != 0x0; r &= (glDeleteProgram = (PFNGLDELETEPROGRAMPROC) platGetProcAddress( "glDeleteProgram" )) != 0x0; r &= (glDeleteShader = (PFNGLDELETESHADERPROC) platGetProcAddress( "glDeleteShader" )) != 0x0; r &= (glDetachShader = (PFNGLDETACHSHADERPROC) platGetProcAddress( "glDetachShader" )) != 0x0; r &= (glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) platGetProcAddress( "glDisableVertexAttribArray" )) != 0x0; r &= (glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) platGetProcAddress( "glEnableVertexAttribArray" )) != 0x0; r &= (glGetActiveAttrib = (PFNGLGETACTIVEATTRIBPROC) platGetProcAddress( "glGetActiveAttrib" )) != 0x0; r &= (glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) platGetProcAddress( "glGetActiveUniform" )) != 0x0; r &= (glGetAttachedShaders = (PFNGLGETATTACHEDSHADERSPROC) platGetProcAddress( "glGetAttachedShaders" )) != 0x0; r &= (glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) platGetProcAddress( "glGetAttribLocation" )) != 0x0; r &= (glGetProgramiv = (PFNGLGETPROGRAMIVPROC) platGetProcAddress( "glGetProgramiv" )) != 0x0; r &= (glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) platGetProcAddress( "glGetProgramInfoLog" )) != 0x0; r &= (glGetShaderiv = (PFNGLGETSHADERIVPROC) platGetProcAddress( "glGetShaderiv" )) != 0x0; r &= (glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) platGetProcAddress( "glGetShaderInfoLog" )) != 0x0; r &= (glGetShaderSource = (PFNGLGETSHADERSOURCEPROC) platGetProcAddress( "glGetShaderSource" )) != 0x0; r &= (glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) platGetProcAddress( "glGetUniformLocation" )) != 0x0; r &= (glGetUniformfv = (PFNGLGETUNIFORMFVPROC) platGetProcAddress( "glGetUniformfv" )) != 0x0; r &= (glGetUniformiv = (PFNGLGETUNIFORMIVPROC) platGetProcAddress( "glGetUniformiv" )) != 0x0; r &= (glGetVertexAttribdv = (PFNGLGETVERTEXATTRIBDVPROC) platGetProcAddress( "glGetVertexAttribdv" )) != 0x0; r &= (glGetVertexAttribfv = (PFNGLGETVERTEXATTRIBFVPROC) platGetProcAddress( "glGetVertexAttribfv" )) != 0x0; r &= (glGetVertexAttribiv = (PFNGLGETVERTEXATTRIBIVPROC) platGetProcAddress( "glGetVertexAttribiv" )) != 0x0; r &= (glGetVertexAttribPointerv = (PFNGLGETVERTEXATTRIBPOINTERVPROC) platGetProcAddress( "glGetVertexAttribPointerv" )) != 0x0; r &= (glIsProgram = (PFNGLISPROGRAMPROC) platGetProcAddress( "glIsProgram" )) != 0x0; r &= (glIsShader = (PFNGLISSHADERPROC) platGetProcAddress( "glIsShader" )) != 0x0; r &= (glLinkProgram = (PFNGLLINKPROGRAMPROC) platGetProcAddress( "glLinkProgram" )) != 0x0; r &= (glShaderSource = (PFNGLSHADERSOURCEPROC) platGetProcAddress( "glShaderSource" )) != 0x0; r &= (glUseProgram = (PFNGLUSEPROGRAMPROC) platGetProcAddress( "glUseProgram" )) != 0x0; r &= (glUniform1f = (PFNGLUNIFORM1FPROC) platGetProcAddress( "glUniform1f" )) != 0x0; r &= (glUniform2f = (PFNGLUNIFORM2FPROC) platGetProcAddress( "glUniform2f" )) != 0x0; r &= (glUniform3f = (PFNGLUNIFORM3FPROC) platGetProcAddress( "glUniform3f" )) != 0x0; r &= (glUniform4f = (PFNGLUNIFORM4FPROC) platGetProcAddress( "glUniform4f" )) != 0x0; r &= (glUniform1i = (PFNGLUNIFORM1IPROC) platGetProcAddress( "glUniform1i" )) != 0x0; r &= (glUniform2i = (PFNGLUNIFORM2IPROC) platGetProcAddress( "glUniform2i" )) != 0x0; r &= (glUniform3i = (PFNGLUNIFORM3IPROC) platGetProcAddress( "glUniform3i" )) != 0x0; r &= (glUniform4i = (PFNGLUNIFORM4IPROC) platGetProcAddress( "glUniform4i" )) != 0x0; r &= (glUniform1fv = (PFNGLUNIFORM1FVPROC) platGetProcAddress( "glUniform1fv" )) != 0x0; r &= (glUniform2fv = (PFNGLUNIFORM2FVPROC) platGetProcAddress( "glUniform2fv" )) != 0x0; r &= (glUniform3fv = (PFNGLUNIFORM3FVPROC) platGetProcAddress( "glUniform3fv" )) != 0x0; r &= (glUniform4fv = (PFNGLUNIFORM4FVPROC) platGetProcAddress( "glUniform4fv" )) != 0x0; r &= (glUniform1iv = (PFNGLUNIFORM1IVPROC) platGetProcAddress( "glUniform1iv" )) != 0x0; r &= (glUniform2iv = (PFNGLUNIFORM2IVPROC) platGetProcAddress( "glUniform2iv" )) != 0x0; r &= (glUniform3iv = (PFNGLUNIFORM3IVPROC) platGetProcAddress( "glUniform3iv" )) != 0x0; r &= (glUniform4iv = (PFNGLUNIFORM4IVPROC) platGetProcAddress( "glUniform4iv" )) != 0x0; r &= (glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC) platGetProcAddress( "glUniformMatrix2fv" )) != 0x0; r &= (glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) platGetProcAddress( "glUniformMatrix3fv" )) != 0x0; r &= (glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) platGetProcAddress( "glUniformMatrix4fv" )) != 0x0; r &= (glValidateProgram = (PFNGLVALIDATEPROGRAMPROC) platGetProcAddress( "glValidateProgram" )) != 0x0; r &= (glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) platGetProcAddress( "glVertexAttribPointer" )) != 0x0; /*// GL 2.1 r &= (glUniformMatrix2x3fv = (PFNGLUNIFORMMATRIX2X3FVPROC) platGetProcAddress( "glUniformMatrix2x3fv" )) != 0x0; r &= (glUniformMatrix3x2fv = (PFNGLUNIFORMMATRIX3X2FVPROC) platGetProcAddress( "glUniformMatrix3x2fv" )) != 0x0; r &= (glUniformMatrix2x4fv = (PFNGLUNIFORMMATRIX2X4FVPROC) platGetProcAddress( "glUniformMatrix2x4fv" )) != 0x0; r &= (glUniformMatrix4x2fv = (PFNGLUNIFORMMATRIX4X2FVPROC) platGetProcAddress( "glUniformMatrix4x2fv" )) != 0x0; r &= (glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC) platGetProcAddress( "glUniformMatrix3x4fv" )) != 0x0; r &= (glUniformMatrix4x3fv = (PFNGLUNIFORMMATRIX4X3FVPROC) platGetProcAddress( "glUniformMatrix4x3fv" )) != 0x0;*/ // GL 3.0 if( glExt::majorVersion >= 3 ) { r &= (glGetStringi = (PFNGLGETSTRINGIPROC) platGetProcAddress( "glGetStringi" )) != 0x0; } // Extensions glExt::EXT_framebuffer_object = isExtensionSupported( "GL_EXT_framebuffer_object" ); if( glExt::EXT_framebuffer_object ) { r &= (glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC) platGetProcAddress( "glIsRenderbufferEXT" )) != 0x0; r &= (glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) platGetProcAddress( "glBindRenderbufferEXT" )) != 0x0; r &= (glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) platGetProcAddress( "glDeleteRenderbuffersEXT" )) != 0x0; r &= (glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) platGetProcAddress( "glGenRenderbuffersEXT" )) != 0x0; r &= (glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) platGetProcAddress( "glRenderbufferStorageEXT" )) != 0x0; r &= (glGetRenderbufferParameterivEXT = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) platGetProcAddress( "glGetRenderbufferParameterivEXT" )) != 0x0; r &= (glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC) platGetProcAddress( "glIsFramebufferEXT" )) != 0x0; r &= (glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) platGetProcAddress( "glBindFramebufferEXT" )) != 0x0; r &= (glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) platGetProcAddress( "glDeleteFramebuffersEXT" )) != 0x0; r &= (glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) platGetProcAddress( "glGenFramebuffersEXT" )) != 0x0; r &= (glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) platGetProcAddress( "glCheckFramebufferStatusEXT" )) != 0x0; r &= (glFramebufferTexture1DEXT = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) platGetProcAddress( "glFramebufferTexture1DEXT" )) != 0x0; r &= (glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) platGetProcAddress( "glFramebufferTexture2DEXT" )) != 0x0; r &= (glFramebufferTexture3DEXT = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) platGetProcAddress( "glFramebufferTexture3DEXT" )) != 0x0; r &= (glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) platGetProcAddress( "glFramebufferRenderbufferEXT" )) != 0x0; r &= (glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) platGetProcAddress( "glGetFramebufferAttachmentParameterivEXT" )) != 0x0; r &= (glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) platGetProcAddress( "glGenerateMipmapEXT" )) != 0x0; } glExt::EXT_texture_filter_anisotropic = isExtensionSupported( "GL_EXT_texture_filter_anisotropic" ); glExt::EXT_texture_compression_s3tc = isExtensionSupported( "GL_EXT_texture_compression_s3tc" ); glExt::EXT_texture_sRGB = isExtensionSupported( "GL_EXT_texture_sRGB" ); glExt::ARB_texture_float = isExtensionSupported( "GL_ARB_texture_float" ) || isExtensionSupported( "GL_ATI_texture_float" ); glExt::ARB_texture_non_power_of_two = isExtensionSupported( "GL_ARB_texture_non_power_of_two" ); glExt::EXT_framebuffer_multisample = isExtensionSupported( "GL_EXT_framebuffer_multisample" ) && isExtensionSupported( "GL_EXT_framebuffer_blit" ); if( glExt::EXT_framebuffer_multisample ) { // From GL_EXT_framebuffer_blit r &= (glBlitFramebufferEXT = (PFNGLBLITFRAMEBUFFEREXTPROC) platGetProcAddress( "glBlitFramebufferEXT" )) != 0x0; // From GL_EXT_framebuffer_multisample r &= (glRenderbufferStorageMultisampleEXT = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) platGetProcAddress( "glRenderbufferStorageMultisampleEXT" )) != 0x0; } glExt::ARB_timer_query = isExtensionSupported( "GL_ARB_timer_query" ); if( glExt::ARB_timer_query ) { r &= (glQueryCounter = (PFNGLQUERYCOUNTERPROC) platGetProcAddress( "glQueryCounter" )) != 0x0; r &= (glGetQueryObjecti64v = (PFNGLGETQUERYOBJECTI64VPROC) platGetProcAddress( "glGetQueryObjecti64v" )) != 0x0; r &= (glGetQueryObjectui64v = (PFNGLGETQUERYOBJECTUI64VPROC) platGetProcAddress( "glGetQueryObjectui64v" )) != 0x0; } return r; }
std::string TestCaseBase::getGLSLExtDirective(ExtensionType type, ExtensionName name, ExtensionBehavior behavior) { if (type == EXTENSIONTYPE_NONE && name != EXTENSIONNAME_GEOMETRY_POINT_SIZE && name != EXTENSIONNAME_TESSELLATION_POINT_SIZE) { return ""; } const char* type_str = NULL; const char* name_str = NULL; const char* behavior_str = NULL; if (name == EXTENSIONNAME_SHADER_IMAGE_ATOMIC) { // There is no EXT version of shader_image_atomic; use OES type = EXTENSIONTYPE_OES; } if (name == EXTENSIONNAME_TESSELLATION_POINT_SIZE) { // there is no core version of tessellation_point_size, use OES or EXT if (isExtensionSupported("GL_OES_tessellation_point_size")) { type = EXTENSIONTYPE_OES; } else if (isExtensionSupported("GL_EXT_tessellation_point_size")) { type = EXTENSIONTYPE_EXT; } else { return ""; } } if (name == EXTENSIONNAME_GEOMETRY_POINT_SIZE) { // there is no core version of geometry_point_size, use OES or EXT if (isExtensionSupported("GL_OES_geometry_point_size")) { type = EXTENSIONTYPE_OES; } else if (isExtensionSupported("GL_EXT_geometry_point_size")) { type = EXTENSIONTYPE_EXT; } else { return ""; } } switch (type) { case EXTENSIONTYPE_EXT: type_str = "EXT_"; break; case EXTENSIONTYPE_OES: type_str = "OES_"; break; default: DE_ASSERT(0); return "#error unknown extension type\n"; } switch (name) { case EXTENSIONNAME_SHADER_IMAGE_ATOMIC: name_str = "shader_image_atomic"; break; case EXTENSIONNAME_SHADER_IO_BLOCKS: name_str = "shader_io_blocks"; break; case EXTENSIONNAME_GEOMETRY_SHADER: name_str = "geometry_shader"; break; case EXTENSIONNAME_GEOMETRY_POINT_SIZE: name_str = "geometry_point_size"; break; case EXTENSIONNAME_TESSELLATION_SHADER: name_str = "tessellation_shader"; break; case EXTENSIONNAME_TESSELLATION_POINT_SIZE: name_str = "tessellation_point_size"; break; case EXTENSIONNAME_TEXTURE_BUFFER: name_str = "texture_buffer"; break; case EXTENSIONNAME_TEXTURE_CUBE_MAP_ARRAY: name_str = "texture_cube_map_array"; break; case EXTENSIONNAME_GPU_SHADER5: name_str = "gpu_shader5"; break; case EXTENSIONNAME_VIEWPORT_ARRAY: name_str = "viewport_array"; break; default: DE_ASSERT(0); return "#error unknown extension name\n"; } switch (behavior) { case EXTENSIONBEHAVIOR_DISABLE: behavior_str = "disable"; break; case EXTENSIONBEHAVIOR_WARN: behavior_str = "warn"; break; case EXTENSIONBEHAVIOR_ENABLE: behavior_str = "enable"; break; case EXTENSIONBEHAVIOR_REQUIRE: behavior_str = "require"; break; default: DE_ASSERT(0); return "#error unknown extension behavior"; } std::stringstream str; str << "#extension GL_" << type_str << name_str << " : " << behavior_str; return str.str(); }
void X11OpenGLWindow::enableOpenGL() { if (forceOpenGL3) { // Get the default screen's GLX extension list const char *glxExts = glXQueryExtensionsString( m_data->m_dpy, DefaultScreen( m_data->m_dpy ) ); // NOTE: It is not necessary to create or make current to a context before // calling glXGetProcAddressARB, unless we dynamically load OpenGL/GLX/X11 glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); GLXContext ctx = 0; // Install an X error handler so the application won't exit if GL 3.0 // context allocation fails. // // Note this error handler is global. All display connections in all threads // of a process use the same error handler, so be sure to guard against other // threads issuing X commands while this code is running. ctxErrorOccurred = false; int (*oldHandler)(Display*, XErrorEvent*) = MyXSetErrorHandler(&ctxErrorHandler); // Check for the GLX_ARB_create_context extension string and the function. // If either is not present, use GLX 1.3 context creation method. if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) || !glXCreateContextAttribsARB ) { printf( "glXCreateContextAttribsARB() not found" " ... using old-style GLX context\n" ); ctx = glXCreateNewContext( m_data->m_dpy, m_data->m_bestFbc, GLX_RGBA_TYPE, 0, True ); } // If it does, try to get a GL 3.0 context! else { int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB ,3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,None }; /* int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None }; */ printf( "Creating context\n" ); ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0, True, context_attribs ); // Sync to ensure any errors generated are processed. MyXSync( m_data->m_dpy, False ); if ( !ctxErrorOccurred && ctx ) printf( "Created GL 3.0 context\n" ); else { // Couldn't create GL 3.0 context. Fall back to old-style 2.x context. // When a context version below 3.0 is requested, implementations will // return the newest context version compatible with OpenGL versions less // than version 3.0. // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 context_attribs[1] = 1; // GLX_CONTEXT_MINOR_VERSION_ARB = 0 context_attribs[3] = 0; ctxErrorOccurred = false; printf( "Failed to create GL 3.0 context" " ... using old-style GLX context\n" ); ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0, True, context_attribs ); } } // Sync to ensure any errors generated are processed. MyXSync( m_data->m_dpy, False ); // Restore the original error handler MyXSetErrorHandler( oldHandler ); if ( ctxErrorOccurred || !ctx ) { printf( "Failed to create an OpenGL context\n" ); exit(1); } // Verifying that context is a direct context if ( ! glXIsDirect ( m_data->m_dpy, ctx ) ) { printf( "Indirect GLX rendering context obtained\n" ); } else { printf( "Direct GLX rendering context obtained\n" ); } printf( "Making context current\n" ); glXMakeCurrent( m_data->m_dpy, m_data->m_win, ctx ); m_data->m_glc = ctx; } else { m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE); glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc); } #ifdef GLEW_INIT_OPENGL11_FUNCTIONS { GLboolean res = glewOpenGL11Init(); if (res==0) { printf("glewOpenGL11Init OK!\n"); } else { printf("ERROR: glewOpenGL11Init failed, exiting!\n"); exit(0); } } #endif //GLEW_INIT_OPENGL11_FUNCTIONS const GLubyte* ven = glGetString(GL_VENDOR); printf("GL_VENDOR=%s\n", ven); const GLubyte* ren = glGetString(GL_RENDERER); printf("GL_RENDERER=%s\n",ren); const GLubyte* ver = glGetString(GL_VERSION); printf("GL_VERSION=%s\n", ver); const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION); printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl); //Access pthreads as a workaround for a bug in Linux/Ubuntu //See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642 int i=pthread_getconcurrency(); printf("pthread_getconcurrency()=%d\n",i); // const GLubyte* ext = glGetString(GL_EXTENSIONS); // printf("GL_EXTENSIONS=%s\n", ext); }
//----------------------------------------------------------------------------- //* Initialize //! Checks if multitexturing is supported //----------------------------------------------------------------------------- void DummyCombiner::initialize() { ARB_multitexture = isExtensionSupported("GL_ARB_multitexture"); }
bool window_create(const char *caption,int width,int height) { // windowData.display = XOpenDisplay(NULL); if(!windowData.display) { fprintf(stderr,"window_create: Failed to open X display.\n"); return false; } // if(!window_check_glx(windowData.display)) { //todo close display fprintf(stderr,"window_create: Invalid GLX version.\n"); return false; } // int screen; screen = XDefaultScreen(windowData.display); // GLXFBConfig bestFbc=get_gl_bestFbc(windowData.display,screen); // XVisualInfo *vi = glXGetVisualFromFBConfig(windowData.display,bestFbc); if(!vi) { //todo close display fprintf(stderr,"Could not get visual info.\n"); return false; } fprintf(stderr,"Chosen visual ID = 0x%d\n",vi->visualid); Visual *viVisual=vi->visual; int viScreen=vi->screen; int viDepth=vi->depth; XFree(vi); // // int depth = DefaultDepth(windowData.display, screen); // XVisualInfo vi; // XMatchVisualInfo(windowData.display, screen, depth, TrueColor, &vi); // fprintf(stderr,"Chosen visual ID = 0x%d\n",vi.visualid); // visual=vi.visual; // if(!create_window_x11(windowData.display,viScreen,viVisual,viDepth, caption,width,height, &windowData.cmap,&windowData.win)) { //todo close display return false; } // windowData.wmDelete=XInternAtom(windowData.display, "WM_DELETE_WINDOW", True); XSetWMProtocols(windowData.display, windowData.win, &windowData.wmDelete, 1); // windowData.xiopcode=setupXiInput(windowData.display); if(!windowData.xiopcode) { //todo destroy window //todo free colormap //todo close display return false; } // windowData.blankCursor=createBlankCursor(windowData.display,windowData.win); if(!windowData.blankCursor) { //todo destroy xi //todo destroy window //todo free colormap //todo close display return false; } // const char *glxExts = glXQueryExtensionsString(windowData.display,viScreen); if(!isExtensionSupported(glxExts,"GLX_ARB_create_context")) { //todo destroy blank cursor //todo destroy xi //todo destroy window //todo free colormap //todo close display fprintf(stderr,"window_create: glXCreateContextAttribsARB not supported.\n"); return false; } glXCreateContextAttribsARBProc glXCreateContextAttribsARB; glXCreateContextAttribsARB=(glXCreateContextAttribsARBProc) glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); if(!glXCreateContextAttribsARB) { //todo destroy blank cursor //todo destroy xi //todo destroy window //todo free colormap //todo close display fprintf(stderr,"glXCreateContextAttribsARB err.\n"); return false; } // windowData.ctx=0; // if( !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,3,3,false) && !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,3,2,false) && !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,3,1,false) && !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,3,0,false) && !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,2,1,false) && !window_gl_context(windowData.display,windowData.win, glXCreateContextAttribsARB,bestFbc, &windowData.ctx,2,0,false)) { //todo destroy blank cursor //todo destroy xi //todo destroy window //todo free colormap //todo close display return false; } // if(!glXIsDirect(windowData.display,windowData.ctx)) { fprintf(stderr,"window_create: Indirect GLX rendering context obtained.\n"); } else { fprintf(stderr,"window_create: Direct GLX rendering context obtained.\n"); } // run_gl_swap_interval(windowData.display); // int i; // windowData.iconic=false; windowData.restored=false; windowData.sized=false; windowData.clientWidth=-1; windowData.clientHeight=-1; windowData.cursorX=0; windowData.cursorY=0; windowData.mouseX=0; windowData.mouseY=0; windowData.mouseZ=0; windowData.lockCursor=false; windowData.cursorLocked=false; for(i=0;i<INPUTS_SIZE;i++) { windowData.inputs[i]=INPUT_UP; } // int event_mask=ButtonPressMask|ButtonReleaseMask| // PointerMotionMask |FocusChangeMask| // EnterWindowMask|LeaveWindowMask; // if(GrabSuccess !=XGrabPointer(windowData.display,windowData.win, True, // event_mask,GrabModeAsync,GrabModeAsync, // windowData.win, None, CurrentTime)) { // printf("grabfail\n"); // } // return true; }
/** Initializes function pointers for ES3.1 extensions, as well as determines * availability of these extensions. **/ void TestCaseBase::initExtensions() { const glu::ContextType& context_type = m_context.getRenderContext().getType(); /* OpenGL 4.0 or higher is minimum expectation for any of these tests */ if (glu::contextSupports(context_type, glu::ApiType::core(4, 0))) { m_is_geometry_shader_extension_supported = true; m_is_geometry_shader_point_size_supported = true; m_is_gpu_shader5_supported = true; m_is_tessellation_shader_supported = true; m_is_tessellation_shader_point_size_supported = true; m_is_texture_cube_map_array_supported = true; m_is_texture_border_clamp_supported = true; m_is_texture_buffer_supported = true; m_is_shader_image_atomic_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 2)); m_is_texture_storage_multisample_2d_array_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 3)); m_is_framebuffer_no_attachments_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 3)); m_is_program_interface_query_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 3)); m_is_texture_storage_multisample_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 3)); m_is_shader_image_load_store_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 2)); m_is_viewport_array_supported = glu::contextSupports(context_type, glu::ApiType::core(4, 1)); } else if (glu::contextSupports(context_type, glu::ApiType::es(3, 2))) { m_is_geometry_shader_extension_supported = true; m_is_gpu_shader5_supported = true; m_is_tessellation_shader_supported = true; m_is_texture_cube_map_array_supported = true; m_is_texture_border_clamp_supported = true; m_is_texture_buffer_supported = true; m_is_shader_image_atomic_supported = true; m_is_texture_storage_multisample_2d_array_supported = true; m_is_framebuffer_no_attachments_supported = true; m_is_program_interface_query_supported = true; m_is_texture_storage_multisample_supported = true; m_is_shader_image_load_store_supported = true; m_is_geometry_shader_point_size_supported = isExtensionSupported("GL_OES_geometry_point_size") || isExtensionSupported("GL_EXT_geometry_point_size"); m_is_tessellation_shader_point_size_supported = isExtensionSupported("GL_OES_tessellation_point_size") || isExtensionSupported("GL_EXT_tessellation_point_size"); m_is_viewport_array_supported = isExtensionSupported("GL_OES_viewport_array"); } else { /* ES3.1 core functionality is assumed*/ DE_ASSERT(isContextTypeES(context_type)); DE_ASSERT(glu::contextSupports(context_type, glu::ApiType::es(3, 1))); /* these are part of ES 3.1 */ m_is_framebuffer_no_attachments_supported = true; m_is_program_interface_query_supported = true; m_is_texture_storage_multisample_supported = true; m_is_shader_image_load_store_supported = true; /* AEP extensions - either test OES variants or EXT variants */ if (m_extType == EXTENSIONTYPE_OES) { /* These are all ES 3.1 extensions */ m_is_geometry_shader_extension_supported = isExtensionSupported("GL_OES_geometry_shader"); m_is_geometry_shader_point_size_supported = isExtensionSupported("GL_OES_geometry_point_size"); m_is_gpu_shader5_supported = isExtensionSupported("GL_OES_gpu_shader5"); m_is_tessellation_shader_supported = isExtensionSupported("GL_OES_tessellation_shader"); m_is_tessellation_shader_point_size_supported = isExtensionSupported("GL_OES_tessellation_point_size"); m_is_texture_cube_map_array_supported = isExtensionSupported("GL_OES_texture_cube_map_array"); m_is_texture_border_clamp_supported = isExtensionSupported("GL_OES_texture_border_clamp"); m_is_texture_buffer_supported = isExtensionSupported("GL_OES_texture_buffer"); } else { DE_ASSERT(m_extType == EXTENSIONTYPE_EXT); /* These are all ES 3.1 extensions */ m_is_geometry_shader_extension_supported = isExtensionSupported("GL_EXT_geometry_shader"); m_is_geometry_shader_point_size_supported = isExtensionSupported("GL_EXT_geometry_point_size"); m_is_gpu_shader5_supported = isExtensionSupported("GL_EXT_gpu_shader5"); m_is_tessellation_shader_supported = isExtensionSupported("GL_EXT_tessellation_shader"); m_is_tessellation_shader_point_size_supported = isExtensionSupported("GL_EXT_tessellation_point_size"); m_is_texture_cube_map_array_supported = isExtensionSupported("GL_EXT_texture_cube_map_array"); m_is_texture_border_clamp_supported = isExtensionSupported("GL_EXT_texture_border_clamp"); m_is_texture_buffer_supported = isExtensionSupported("GL_EXT_texture_buffer"); } /* other ES 3.1 extensions */ m_is_shader_image_atomic_supported = isExtensionSupported("GL_OES_shader_image_atomic"); m_is_texture_storage_multisample_2d_array_supported = isExtensionSupported("GL_OES_texture_storage_multisample_2d_array"); m_is_viewport_array_supported = isExtensionSupported("GL_OES_viewport_array"); } }
FX_ENTRY GrContext_t FX_CALL grSstWinOpen( GrScreenResolution_t screen_resolution, GrScreenRefresh_t refresh_rate, GrColorFormat_t color_format, GrOriginLocation_t origin_location, int nColBuffers, int nAuxBuffers) { uint32_t screen_width, screen_height; struct retro_variable var = { "mupen64-screensize", 0 }; // ZIGGY // allocate static texture names // the initial value should be big enough to support the maximal resolution free_texture = 32*1024*1024; default_texture = free_texture++; color_texture = free_texture++; depth_texture = free_texture++; LOG("grSstWinOpen(%d, %d, %d, %d, %d %d)\r\n", screen_resolution&~0x80000000, refresh_rate, color_format, origin_location, nColBuffers, nAuxBuffers); width = 640; height = 480; bool ret = environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var); if (ret && var.value) { if (sscanf(var.value ? var.value : "640x480", "%dx%d", &width, &height) != 2) { width = 640; height = 480; } } glViewport(0, 0, width, height); lfb_color_fmt = color_format; if (origin_location != GR_ORIGIN_UPPER_LEFT) DISPLAY_WARNING("origin must be in upper left corner"); if (nColBuffers != 2) DISPLAY_WARNING("number of color buffer is not 2"); if (nAuxBuffers != 1) DISPLAY_WARNING("number of auxiliary buffer is not 1"); if (isExtensionSupported("GL_ARB_texture_env_combine") == 0 && isExtensionSupported("GL_EXT_texture_env_combine") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_texture_env_combine extension"); if (isExtensionSupported("GL_ARB_multitexture") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_multitexture extension"); if (isExtensionSupported("GL_ARB_texture_mirrored_repeat") == 0) DISPLAY_WARNING("Your video card doesn't support GL_ARB_texture_mirrored_repeat extension"); nbAuxBuffers = 4; //glGetIntegerv(GL_AUX_BUFFERS, &nbAuxBuffers); if (nbAuxBuffers > 0) printf("Congratulations, you have %d auxilliary buffers, we'll use them wisely !\n", nbAuxBuffers); blend_func_separate_support = 1; packed_pixels_support = 0; if (isExtensionSupported("GL_EXT_blend_func_separate") == 0) { DISPLAY_WARNING("GL_EXT_blend_func_separate not supported.\n"); blend_func_separate_support = 0; } else { printf("GL_EXT_blend_func_separate supported.\n"); blend_func_separate_support = 1; } // we can assume that non-GLES has GL_EXT_packed_pixels // support -it's included since OpenGL 1.2 #ifdef GLES if (isExtensionSupported("GL_EXT_packed_pixels") != 0) #endif packed_pixels_support = 1; if (isExtensionSupported("GL_ARB_texture_non_power_of_two") == 0) { DISPLAY_WARNING("GL_ARB_texture_non_power_of_two supported.\n"); npot_support = 0; } else { printf("GL_ARB_texture_non_power_of_two supported.\n"); npot_support = 1; } if (isExtensionSupported("GL_EXT_fog_coord") == 0) { DISPLAY_WARNING("GL_EXT_fog_coord not supported.\n"); fog_coord_support = 0; } else { printf("GL_EXT_fog_coord supported.\n"); fog_coord_support = 1; } if (isExtensionSupported("GL_ARB_shading_language_100") && isExtensionSupported("GL_ARB_shader_objects") && isExtensionSupported("GL_ARB_fragment_shader") && isExtensionSupported("GL_ARB_vertex_shader")) {} #ifdef GLES if (isExtensionSupported("GL_EXT_texture_format_BGRA8888")) { printf("GL_EXT_texture_format_BGRA8888 supported.\n"); bgra8888_support = 1; } else { DISPLAY_WARNING("GL_EXT_texture_format_BGRA8888 not supported.\n"); bgra8888_support = 0; } #endif glViewport(0, 0, width, height); viewport_width = width; viewport_height = height; // VP try to resolve z precision issues // glMatrixMode(GL_MODELVIEW); // glLoadIdentity(); // glTranslatef(0, 0, 1-zscale); // glScalef(1, 1, zscale); widtho = width/2; heighto = height/2; pBufferWidth = pBufferHeight = -1; current_buffer = GL_BACK; texture_unit = GL_TEXTURE0; { int i; for (i=0; i<NB_TEXBUFS; i++) texbufs[i].start = texbufs[i].end = 0xffffffff; } FindBestDepthBias(); init_geometry(); init_textures(); init_combiner(); return 1; }
MyWindow::MyWindow(const std::string &title,int width,int height) : initError(false),clientWidth(0),clientHeight(0),iconified(false),focused(true),sized(false), justCreated(true),mouseMoveCallback(0),inputCallback(0),lockCursor(false),foreground(true) { #ifdef WIN32 hglrc=0; hdc=0; // HINSTANCE hInstance=GetModuleHandle(0); WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL,IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; #ifdef UNICODE wcex.lpszClassName = L"win32app"; #else wcex.lpszClassName = "win32app"; #endif wcex.hIconSm = LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_APPLICATION)); if(!RegisterClassEx(&wcex)) { std::cout << "MyWindow : Call to RegisterClassEx failed!\n"; } #ifdef UNICODE wchar_t title2[256]; MultiByteToWideChar(CP_ACP,0,title.c_str(),-1,title2,256); #else const char *title2=title.c_str(); #endif hWnd = CreateWindow(wcex.lpszClassName,title2,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,width,height,NULL,NULL,hInstance,NULL); SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG_PTR)this); ShowWindow(hWnd,SW_SHOW); // hdc= GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd; ZeroMemory(&pfd,sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_GENERIC_ACCELERATED | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cRedBits = pfd.cGreenBits = pfd.cBlueBits = 8; pfd.cDepthBits = 32; int iPixelFormat = ChoosePixelFormat(hdc,&pfd); if(iPixelFormat == 0) { std::cout << "MyWindow : ChoosePixelFormat failed.\n"; initError=true; return; } if(SetPixelFormat(hdc,iPixelFormat,&pfd) != TRUE) { std::cout << "MyWindow : SetPixelFormat failed.\n"; initError=true; return; } // HGLRC tempContext = wglCreateContext(hdc); wglMakeCurrent(hdc,tempContext); // PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB= (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); PFNWGLSWAPINTERVALEXTPROC wglSwapInterval= (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); // wglMakeCurrent(0,0); wglDeleteContext(tempContext); // int attribs[] ={ WGL_CONTEXT_MAJOR_VERSION_ARB,3, WGL_CONTEXT_MINOR_VERSION_ARB,3, WGL_CONTEXT_FLAGS_ARB,0, 0 }; hglrc=wglCreateContextAttribsARB(hdc,0,attribs); for(int i=2;i>=0;i--) { if(!hglrc) { attribs[3]=i; hglrc=wglCreateContextAttribsARB(hdc,0,attribs); } } if(!hglrc) { std::cout << "OpenGL 3+ not supported.\n"; initError=true; return; } wglMakeCurrent(hdc,hglrc); wglSwapInterval(1); // RAWINPUTDEVICE Rid[2]; Rid[0].usUsagePage = (USHORT)0x01;//HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = (USHORT)0x02;//HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hWnd; Rid[1].usUsagePage = (USHORT)0x01;//HID_USAGE_PAGE_GENERIC; Rid[1].usUsage = (USHORT)0x06;//HID_USAGE_GENERIC_KEYBOARD; Rid[1].dwFlags = RIDEV_INPUTSINK; Rid[1].hwndTarget = hWnd; RegisterRawInputDevices(Rid,2,sizeof(RAWINPUTDEVICE)); // //inputCodeMap[65]=keyA; //inputCodeMap[68]=keyD; //inputCodeMap[83]=keyS; //inputCodeMap[87]=keyW; #endif #ifdef LINUX // bool ctxErrorOccurred=false; display = XOpenDisplay(NULL); if(!display) { std::cout << "Window : Failed to open X display.\n"; initError=true; return; } static int visual_attribs[] ={ GLX_X_RENDERABLE,True, GLX_DRAWABLE_TYPE,GLX_WINDOW_BIT, GLX_RENDER_TYPE,GLX_RGBA_BIT, GLX_X_VISUAL_TYPE,GLX_TRUE_COLOR, GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, GLX_ALPHA_SIZE,8, GLX_DEPTH_SIZE,24, GLX_STENCIL_SIZE,8, GLX_DOUBLEBUFFER,True, //GLX_SAMPLE_BUFFERS , 1, //GLX_SAMPLES , 4, None }; int glx_major,glx_minor; if(!glXQueryVersion(display,&glx_major,&glx_minor) || ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) { std::cout << "Window : Invalid GLX version.\n"; initError=true; return; } int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(display,DefaultScreen(display),visual_attribs,&fbcount); if(!fbc) { std::cout << "Window :Failed to retrieve a framebuffer config.\n"; initError=true; return; } int best_fbc = -1,worst_fbc = -1,best_num_samp = -1,worst_num_samp = 999; for(int i=0; i<fbcount; ++i) { XVisualInfo *vi = glXGetVisualFromFBConfig(display,fbc[i]); if(vi) { int samp_buf,samples; glXGetFBConfigAttrib(display,fbc[i],GLX_SAMPLE_BUFFERS,&samp_buf); glXGetFBConfigAttrib(display,fbc[i],GLX_SAMPLES,&samples); std::cout << "Matching fbconfig " << i <<", visual ID 0x" << vi->visualid << ": SAMPLE_BUFFERS = " << samp_buf <<", SAMPLES = " << samples <<"\n"; if(best_fbc < 0 || samp_buf && samples > best_num_samp) { best_fbc = i; best_num_samp = samples; } if(worst_fbc < 0 || !samp_buf || samples < worst_num_samp) { worst_fbc = i; worst_num_samp = samples; } } XFree(vi); } GLXFBConfig bestFbc = fbc[best_fbc]; XFree(fbc); XVisualInfo *vi = glXGetVisualFromFBConfig(display,bestFbc); std::cout << "Chosen visual ID = 0x" << vi->visualid <<"\n"; XSetWindowAttributes swa; swa.colormap = cmap = XCreateColormap(display, RootWindow(display,vi->screen), vi->visual,AllocNone); swa.background_pixmap = None; swa.border_pixel = 0; swa.event_mask = ExposureMask | VisibilityChangeMask |KeyPressMask | PointerMotionMask |StructureNotifyMask; swa.bit_gravity = StaticGravity; win = XCreateWindow(display,RootWindow(display,vi->screen), 0,0,100,100,0,vi->depth,InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask,&swa); if(!win) { std::cout << "Window : Failed to create window.\n"; initError=true; return; } XFree(vi); XStoreName(display,win,title.c_str()); XMapWindow(display,win); const char *glxExts = glXQueryExtensionsString(display,DefaultScreen(display)); glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB((const GLubyte *) "glXCreateContextAttribsARB"); ctx = 0; ctxErrorOccurred = false; int(*oldHandler)(Display*,XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); if(!isExtensionSupported(glxExts,"GLX_ARB_create_context") || !glXCreateContextAttribsARB) { std::cout << "Window : glXCreateContextAttribsARB() not found.\n"; initError=true; return; } else { int context_attribs[] ={ GLX_CONTEXT_MAJOR_VERSION_ARB,3, GLX_CONTEXT_MINOR_VERSION_ARB,0, GLX_CONTEXT_FLAGS_ARB,0, None }; ctx = glXCreateContextAttribsARB(display,bestFbc,0, True,context_attribs); XSync(display,False); if(!ctxErrorOccurred && ctx) { std::cout << "Created GL 3.0 context\n"; } else { std::cout << "Window : Failed to create GL 3.0 context.\n"; initError=true; return; } } // XSync(display,False); XSetErrorHandler(oldHandler); if(ctxErrorOccurred || !ctx) { std::cout << "Window : Failed to create an OpenGL context.\n"; initError=true; return; } // Verifying that context is a direct context if(!glXIsDirect(display,ctx)) { std::cout << "Indirect GLX rendering context obtained.\n"; } else { std::cout << "Direct GLX rendering context obtained.\n"; } // glXMakeCurrent(display,win,ctx); if(PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA= (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA")) { glXSwapIntervalMESA(1); } else if(PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT= (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalEXT")) { glXSwapIntervalEXT(display,glXGetCurrentDrawable(),1); } else if(PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI= (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalSGI")) { glXSwapIntervalSGI(1); } #endif }