예제 #1
0
bool RTCALL VBoxOglIs3DAccelerationSupported()
{
    if (RTEnvGet("VBOX_CROGL_FORCE_SUPPORTED"))
    {
        LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n"));
        return true;
    }

    CGDirectDisplayID   display = CGMainDisplayID ();
    CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask (display);
    CGLPixelFormatObj   pixelFormat = NULL;
    GLint numPixelFormats = 0;

    CGLPixelFormatAttribute attribs[] = {
        kCGLPFADisplayMask,
        (CGLPixelFormatAttribute)cglDisplayMask,
        kCGLPFAAccelerated,
        kCGLPFADoubleBuffer,
        kCGLPFAWindow,
        (CGLPixelFormatAttribute)NULL
    };

    display = CGMainDisplayID();
    cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(display);
    CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats);

    if (pixelFormat)
    {
        CGLContextObj cglContext = 0;
        CGLCreateContext(pixelFormat, NULL, &cglContext);
        CGLDestroyPixelFormat(pixelFormat);
        if (cglContext)
        {
            GLboolean isSupported = GL_TRUE;
#ifdef VBOX_WITH_COCOA_QT
            /* On the Cocoa port we depend on the GL_EXT_framebuffer_object &
             * the GL_EXT_texture_rectangle extension. If they are not
             * available, disable 3D support. */
            CGLSetCurrentContext(cglContext);
            const GLubyte* strExt;
            strExt = glGetString(GL_EXTENSIONS);
            isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
            if (isSupported)
            {
                isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_texture_rectangle", strExt);
                if (!isSupported)
                    LogRel(("OpenGL Info: GL_EXT_texture_rectangle extension not supported\n"));
            }
            else
                LogRel(("OpenGL Info: GL_EXT_framebuffer_object extension not supported\n"));
#endif /* VBOX_WITH_COCOA_QT */
            CGLDestroyContext(cglContext);
            return isSupported == GL_TRUE ? true : false;
        }
    }

    return false;
}
예제 #2
0
void CheckForGLSL() {
#if _WIN32
  // Missing code for the Windows equivalent :(
#else
  const GLubyte* extensions = glGetString(GL_EXTENSIONS);
  if (!gluCheckExtension((const GLubyte*)"GL_ARB_shader_objects", extensions) ||
      !gluCheckExtension((const GLubyte*)"GL_ARB_vertex_shader", extensions) ||
      !gluCheckExtension((const GLubyte*)"GL_ARB_fragment_shader", extensions) ||
      !gluCheckExtension((const GLubyte*)"GL_ARB_shading_language_100", extensions)) {
    std::cout << glGetString(GL_RENDERER) << " does not support GLSL" << std::endl;
    exit(1);
  }
#endif
}
static inline GLboolean CheckForExtension(const GLchar *extensionName, 
										  const GLubyte *extensions)
{
	GLboolean  bExtensionAvailable = gluCheckExtension((GLubyte *)extensionName, 
													   extensions);
	
	return bExtensionAvailable;
} // CheckForExtension
예제 #4
0
GLboolean GLShader::HasGLSL(void)
{
#ifdef _WIN32
	return GL_TRUE;
#else
	const GLubyte* extensions = glGetString(GL_EXTENSIONS);
	
	if (GL_FALSE == gluCheckExtension((const GLubyte*) "GL_ARB_shader_objects", extensions))
		return GL_FALSE;
	if (GL_FALSE == gluCheckExtension((const GLubyte*)"GL_ARB_vertex_shader", extensions))
		return GL_FALSE;
	if (GL_FALSE == gluCheckExtension((const GLubyte*)"GL_ARB_fragment_shader", extensions))
		return GL_FALSE;
	if (GL_FALSE == gluCheckExtension((const GLubyte*)"GL_ARB_shading_language_100", extensions))
		return GL_FALSE;
	
	return GL_TRUE;
#endif
}
예제 #5
0
bool BMDOpenGLOutput::InitOpenGL()
{
    const GLubyte * strExt;
    GLboolean isFBO;

    pContext->makeCurrent();
    strExt = glGetString (GL_EXTENSIONS);
    isFBO = gluCheckExtension ((const GLubyte*)"GL_EXT_framebuffer_object", strExt);

    if (!isFBO)
    {
        QMessageBox::critical(NULL,"OpenGL initialization error.", "OpenGL extention \"GL_EXT_framebuffer_object\" is not supported.");
        return false;
    }

    return true;
}
const GrGLInterface* SkNativeGLContext::createGLContext() {
    fDisplay = XOpenDisplay(0);

    if (!fDisplay) {
        SkDebugf("Failed to open X display.\n");
        this->destroyGLContext();
        return NULL;
    }

    // Get a matching FB config
    static int visual_attribs[] = {
        GLX_X_RENDERABLE    , True,
        GLX_DRAWABLE_TYPE   , GLX_PIXMAP_BIT,
        None
    };

#ifdef GLX_1_3
    //SkDebugf("Getting matching framebuffer configs.\n");
    int fbcount;
    GLXFBConfig *fbc = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay),
                                          visual_attribs, &fbcount);
    if (!fbc) {
        SkDebugf("Failed to retrieve a framebuffer config.\n");
        this->destroyGLContext();
        return NULL;
    }
    //SkDebugf("Found %d matching FB configs.\n", fbcount);

    // Pick the FB config/visual with the most samples per pixel
    //SkDebugf("Getting XVisualInfos.\n");
    int best_fbc = -1, best_num_samp = -1;

    int i;
    for (i = 0; i < fbcount; ++i) {
        XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, fbc[i]);
        if (vi) {
            int samp_buf, samples;
            glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
            glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLES, &samples);

            //SkDebugf("  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;
        }
        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(fDisplay, bestFbc);
    //SkDebugf("Chosen visual ID = 0x%x\n", (unsigned int)vi->visualid);
#else
    int numVisuals;
    XVisualInfo visTemplate, *visReturn;

    visReturn = XGetVisualInfo(fDisplay, VisualNoMask, &visTemplate, &numVisuals);
    if (NULL == visReturn)
    {
        SkDebugf("Failed to get visual information.\n");
        this->destroyGLContext();
        return NULL;
    }

    int best = -1, best_num_samp = -1;

    for (int i = 0; i < numVisuals; ++i)
    {
        int samp_buf, samples;

        glXGetConfig(fDisplay, &visReturn[i], GLX_SAMPLE_BUFFERS, &samp_buf);
        glXGetConfig(fDisplay, &visReturn[i], GLX_SAMPLES, &samples);

        if (best < 0 || (samp_buf && samples > best_num_samp))
            best = i, best_num_samp = samples;
    }

    XVisualInfo temp = visReturn[best];
    XVisualInfo *vi = &temp;

    XFree(visReturn);
#endif

    fPixmap = XCreatePixmap(fDisplay, RootWindow(fDisplay, vi->screen), 10, 10, vi->depth);

    if (!fPixmap) {
        SkDebugf("Failed to create pixmap.\n");
        this->destroyGLContext();
        return NULL;
    }

    fGlxPixmap = glXCreateGLXPixmap(fDisplay, vi, fPixmap);

#ifdef GLX_1_3
    // Done with the visual info data
    XFree(vi);
#endif

    // Create the context

    // 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);

    // Get the default screen's GLX extension list
    const char *glxExts = glXQueryExtensionsString(
        fDisplay, DefaultScreen(fDisplay)
    );
    // 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 (!gluCheckExtension(
          reinterpret_cast<const GLubyte*>("GLX_ARB_create_context")
          , reinterpret_cast<const GLubyte*>(glxExts)))
    {
        //SkDebugf("GLX_ARB_create_context not found."
        //       " Using old-style GLX context.\n");
#ifdef GLX_1_3
        fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
#else
        fContext = glXCreateContext(fDisplay, vi, 0, True);
#endif

    }
#ifdef GLX_1_3
    else {
        //SkDebugf("Creating context.\n");

        PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB =
            (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*)"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
        };
        fContext = glXCreateContextAttribsARB(
            fDisplay, bestFbc, 0, True, context_attribs
        );

        // Sync to ensure any errors generated are processed.
        XSync(fDisplay, False);
        if (!ctxErrorOccurred && fContext) {
           //SkDebugf( "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;

            //SkDebugf("Failed to create GL 3.0 context."
            //       " Using old-style GLX context.\n");
            fContext = glXCreateContextAttribsARB(
                fDisplay, bestFbc, 0, True, context_attribs
            );
        }
    }
#endif

    // Sync to ensure any errors generated are processed.
    XSync(fDisplay, False);

    // Restore the original error handler
    XSetErrorHandler(oldHandler);

    if (ctxErrorOccurred || !fContext) {
        SkDebugf("Failed to create an OpenGL context.\n");
        this->destroyGLContext();
        return NULL;
    }

    // Verify that context is a direct context
    if (!glXIsDirect(fDisplay, fContext)) {
        //SkDebugf("Indirect GLX rendering context obtained.\n");
    } else {
        //SkDebugf("Direct GLX rendering context obtained.\n");
    }

    //SkDebugf("Making context current.\n");
    if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
      SkDebugf("Could not set the context.\n");
        this->destroyGLContext();
        return NULL;
    }

    const GrGLInterface* interface = GrGLCreateNativeInterface();
    if (!interface) {
        SkDebugf("Failed to create gl interface");
        this->destroyGLContext();
        return NULL;
    }
    return interface;
}
예제 #7
0
bool RTCALL VBoxOglIs3DAccelerationSupported()
{
    if (RTEnvExist("VBOX_CROGL_FORCE_SUPPORTED"))
    {
        LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n"));
        return true;
    }

    CGDirectDisplayID   display = CGMainDisplayID ();
    CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask (display);
    CGLPixelFormatObj   pixelFormat = NULL;
    GLint numPixelFormats = 0;
    CGLError            rcCgl;

    CGLPixelFormatAttribute attribs[] = {
        kCGLPFADisplayMask,
        (CGLPixelFormatAttribute)cglDisplayMask,
        kCGLPFAAccelerated,
        kCGLPFADoubleBuffer,
        VBoxOglIsOfflineRenderingAppropriate() ? kCGLPFAAllowOfflineRenderers : (CGLPixelFormatAttribute)NULL,
        (CGLPixelFormatAttribute)NULL
    };

    display = CGMainDisplayID();
    cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(display);
    rcCgl = CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats);
    if (rcCgl != kCGLNoError)
    {
        LogRel(("OpenGL Info: 3D test unable to choose pixel format (rcCgl=0x%X)\n", rcCgl));
        return false;
    }

    if (pixelFormat)
    {
        CGLContextObj cglContext = 0;
        rcCgl = CGLCreateContext(pixelFormat, NULL, &cglContext);
        CGLDestroyPixelFormat(pixelFormat);

        if (rcCgl != kCGLNoError)
        {
            LogRel(("OpenGL Info: 3D test unable to create context (rcCgl=0x%X)\n", rcCgl));
            return false;
        }

        if (cglContext)
        {
            GLboolean isSupported = GL_TRUE;
#ifdef VBOX_WITH_COCOA_QT
            /* On the Cocoa port we depend on the GL_EXT_framebuffer_object &
             * the GL_EXT_texture_rectangle extension. If they are not
             * available, disable 3D support. */
            CGLSetCurrentContext(cglContext);
            const GLubyte* strExt;
            strExt = glGetString(GL_EXTENSIONS);
            isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt);
            if (isSupported)
            {
                isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_texture_rectangle", strExt);
                if (!isSupported)
                    LogRel(("OpenGL Info: 3D test found that GL_EXT_texture_rectangle extension not supported\n"));
            }
            else
                LogRel(("OpenGL Info: 3D test found that GL_EXT_framebuffer_object extension not supported\n"));
#endif /* VBOX_WITH_COCOA_QT */
            CGLDestroyContext(cglContext);
            LogRel(("OpenGL Info: 3D test %spassed\n", isSupported == GL_TRUE ? "" : "not "));
            return isSupported == GL_TRUE ? true : false;
        }
        else
            LogRel(("OpenGL Info: 3D test unable to create context (internal error)\n"));
    }
    else
        LogRel(("OpenGL Info: 3D test unable to choose pixel format (internal error)\n"));

    return false;
}
예제 #8
0
파일: GLCheck.c 프로젝트: akosma/Lorenz
void CheckOpenGLCaps (CGDisplayCount maxDspys, 
                      GLCaps dCaps[], 
                      CGDisplayCount * dCnt)
{
  CGLContextObj curr_ctx = 0;
  CGDirectDisplayID dspys[32];
  CGDisplayErr theErr;
  short i;
  short size = sizeof (GLCaps);
  
  // no devices
  *dCnt = 0;
  
  if (maxDspys == 0) { // find number of displays
    *dCnt = 0;
    theErr = CGGetActiveDisplayList (32, dspys, dCnt);
    if (theErr) // theErr getting list
      *dCnt = 0; // 0 displays since can't correctly find any
    // zero list to ensure the routines are used correctly
    memset (dspys, 0, sizeof (CGDirectDisplayID) * *dCnt);
    return; // return dCnt
  }
  if (NULL == dCaps) return;

  theErr = CGGetActiveDisplayList(maxDspys, dspys, dCnt);
  if (theErr) return; // theErr getting list
  if (0 == *dCnt) return; // no displays
  
  memset (dCaps, 0, size * *dCnt); // zero memory
  
  for (i = 0; i < *dCnt; i++) {
    // get device ids
    dCaps[i].cgDisplayID = dspys[i];
    dCaps[i].cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(dspys[i]);
    
    { // get current geometry
      CGRect displayRect = CGDisplayBounds (dspys[i]);
      // get mode dictionary
      CFDictionaryRef dispMode = CGDisplayCurrentMode (dspys[i]); 
      dCaps[i].deviceWidth = (long) displayRect.size.width;   
      dCaps[i].deviceHeight = (long) displayRect.size.height;   
      dCaps[i].deviceOriginX = (long) displayRect.origin.x;   
      dCaps[i].deviceOriginY = (long) displayRect.origin.y;   
      dCaps[i].deviceDepth = (short) _getDictLong (dispMode,  
                                              kCGDisplayBitsPerPixel);    
      dCaps[i].deviceRefresh = (short) (_getDictDouble (dispMode,
                                        kCGDisplayRefreshRate) + 0.5); 
    }    

    { // get renderer info based on gDevice
      CGLRendererInfoObj info;
        long j;
        GLint numRenderers = 0;
        GLint rv = 0;
      CGLError theErr2 = 0;
      
      theErr2 = CGLQueryRendererInfo (dCaps[i].cglDisplayMask, 
                                  &info, 
                                  &numRenderers);
      if(0 == theErr2) {
        CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers);
        for (j = 0; j < numRenderers; j++) {
          // find accelerated renderer (assume only one)
          CGLDescribeRenderer (info, j, kCGLRPAccelerated, &rv); 
          if (true == rv) { // if accelerated
            // what is the renderer ID
            CGLDescribeRenderer (info, j, kCGLRPRendererID,
                                 &dCaps[i].rendererID);
            // can we do full screen?
            CGLDescribeRenderer (info, j, kCGLRPFullScreen, &rv); 
            dCaps[i].fullScreenCapable = (bool) rv;
            // what is the VRAM?
            CGLDescribeRenderer (info, j, kCGLRPVideoMemory,
                                 &dCaps[i].deviceVRAM);
            // what is the current texture memory? 
            CGLDescribeRenderer (info, j, kCGLRPTextureMemory,
                                 &dCaps[i].deviceTextureRAM);
            break; // done
          }
        }
      }
      CGLDestroyRendererInfo (info);
    }

    { // build context and context specific info
      CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask,
                                            dCaps[i].cglDisplayMask, 
                                            (CGLPixelFormatAttribute)0 };
      CGLPixelFormatObj pixelFormat = NULL;
      GLint numPixelFormats = 0;
      CGLContextObj cglContext;
      
      curr_ctx = CGLGetCurrentContext (); // get current CGL context
      CGLChoosePixelFormat (attribs, &pixelFormat, &numPixelFormats);
      if (pixelFormat) {
        CGLCreateContext(pixelFormat, NULL, &cglContext);
        CGLDestroyPixelFormat (pixelFormat);
        CGLSetCurrentContext (cglContext);
        if (cglContext) {
          const GLubyte * strExt;
          const GLubyte * strRend;
          const GLubyte * strVers;
          const GLubyte * strVend;

          // get renderer strings
          strRend = glGetString (GL_RENDERER);
          strncpy (dCaps[i].strRendererName, (char *) strRend, 255);
          strVend = glGetString (GL_VENDOR);
          strncpy (dCaps[i].strRendererVendor, (char *) strVend, 255);
          strVers = glGetString (GL_VERSION);
          strncpy (dCaps[i].strRendererVersion, (char *) strVers, 255);
          { // get BCD version
            short j = 0;
            short shiftVal = 8;
            while (((strVers[j] <= '9') && (strVers[j] >= '0')) ||
                                            (strVers[j] == '.')) { 
            // get only basic version info (until first non-digit or non-.)
              if ((strVers[j] <= '9') && (strVers[j] >= '0')) {
                dCaps[i].glVersion += (strVers[j] - '0') << shiftVal;
                shiftVal -= 4;
              }
              j++;
            }
          }
          strExt = glGetString (GL_EXTENSIONS);

          // get caps
          glGetIntegerv (GL_MAX_TEXTURE_UNITS, 
                         &dCaps[i].textureUnits);
          glGetIntegerv (GL_MAX_TEXTURE_SIZE,
                         &dCaps[i].maxTextureSize); 
          glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE, 
                         &dCaps[i].max3DTextureSize);
          glGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE, 
                         &dCaps[i].maxCubeMapTextureSize);

          // get functionality info
		  dCaps[i].fSpecularVector = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_specular_vector", strExt);
          dCaps[i].fTransformHint = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_transform_hint", strExt);
          dCaps[i].fPackedPixels = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixels", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixel", strExt)  || 
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fClientStorage = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_client_storage", strExt);
          dCaps[i].fYCbCr = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_ycbcr_422", strExt);
          dCaps[i].fTextureRange = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_texture_range", strExt);
          dCaps[i].fFence = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_fence", strExt);
          dCaps[i].fVAR = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_range", strExt);
          dCaps[i].fVAO = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_object", strExt);
          dCaps[i].fElementArray = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_element_array", strExt);
          dCaps[i].fVPEvals = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_program_evaluators",strExt);
          dCaps[i].fFloatPixels = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_float_pixels", strExt);
          dCaps[i].fFlushRenderer = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_render", strExt);
          dCaps[i].fPixelBuffer = 
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_pixel_buffer", strExt);
          dCaps[i].fImaging = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fTransposeMatrix = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_transpose_matrix", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fMultitexture = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_multitexture", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvAdd = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_add", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_env_add", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvCombine = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_combine", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvDot3 = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_dot3", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexEnvCrossbar = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_crossbar", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTexCubeMap = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_cube_map", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexCompress = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_compression", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fMultisample = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_multisample", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fTexBorderClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_border_clamp", strExt) ||
			  (dCaps[i].glVersion >= 0x0130);
          dCaps[i].fPointParam = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_point_parameters", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fVertexProg = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_program", strExt);
          dCaps[i].fFragmentProg = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program", strExt);
          dCaps[i].fTexMirrorRepeat = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_mirrored_repeat", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fDepthTex = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_depth_texture", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadow = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shadow", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadowAmbient = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shadow_ambient", strExt);
          dCaps[i].fVertexBlend = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_blend", strExt);
          dCaps[i].fWindowPos = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_window_pos", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTex3D = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture3D", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fClipVolHint = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_clip_volume_hint", strExt);
          dCaps[i].fRescaleNorm = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_rescale_normal", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fBlendColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_color", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fBlendMinMax = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_minmax", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fBlendSub = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_subtract", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fCVA = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_compiled_vertex_array", strExt);
          dCaps[i].fTexLODBias = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_lod_bias", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fABGR = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_abgr", strExt);
          dCaps[i].fBGRA = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_bgra", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fTexFilterAniso = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_filter_anisotropic",strExt);
          dCaps[i].fPaletteTex = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_paletted_texture", strExt);
          dCaps[i].fShareTexPalette = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_shared_texture_palette", strExt);
          dCaps[i].fSecColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_secondary_color", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fTexCompressS3TC = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_s3tc", strExt);
          dCaps[i].fTexRect = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_rectangle", strExt);
          dCaps[i].fFogCoord = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_fog_coord", strExt);
          dCaps[i].fDrawRangeElements = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_draw_range_elements", strExt);
          dCaps[i].fStencilWrap = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_wrap", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fBlendFuncSep = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_func_separate", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fMultiDrawArrays = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_multi_draw_arrays", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fShadowFunc = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_shadow_funcs", strExt);
          dCaps[i].fStencil2Side = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_two_side", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fColorSubtable = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_color_subtable", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fConvolution = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_convolution", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fHistogram = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_histogram", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fColorTable = 
			  gluCheckExtension ((const GLubyte *) "GL_SGI_color_table", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fColorMatrix = 
			  gluCheckExtension ((const GLubyte *) "GL_SGI_color_matrix", strExt) || 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
          dCaps[i].fTexEdgeClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_edge_clamp", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fGenMipmap = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_generate_mipmap", strExt);
          dCaps[i].fTexLOD = 
			  gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_lod", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
          dCaps[i].fPointCull = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_point_cull_mode", strExt);
          dCaps[i].fTexMirrorOnce = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_mirror_once", strExt);
          dCaps[i].fPNtriangles = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_pn_triangles", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ATIX_pn_triangles", strExt);
          dCaps[i].fTextFragShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_text_fragment_shader", strExt);
          dCaps[i].fATIBlendEqSep = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_blend_equation_separate", strExt);
          dCaps[i].fBlendWeightMinMax = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_blend_weighted_minmax", strExt);
          dCaps[i].fCombine3 = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_env_combine3", strExt);
          dCaps[i].fSepStencil = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_separate_stencil", strExt);
          dCaps[i].fArrayRevComps4Byte = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_array_rev_comps_in_4_bytes",strExt);
          dCaps[i].fNVPointSprite = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_point_sprite", strExt);
          dCaps[i].fRegCombiners = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners", strExt);
          dCaps[i].fRegCombiners2 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners2", strExt);
          dCaps[i].fTexEnvCombine4 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_env_combine4", strExt);
          dCaps[i].fBlendSquare = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_blend_square", strExt) ||
			  (dCaps[i].glVersion >= 0x0140);
          dCaps[i].fFogDist = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_fog_distance", strExt);
          dCaps[i].fMultisampleFilterHint = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_multisample_filter_hint", strExt);
          dCaps[i].fTexGenReflect = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texgen_reflection", strExt);
          dCaps[i].fTexShader = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader", strExt);
          dCaps[i].fTexShader2 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader2", strExt);
          dCaps[i].fTexShader3 = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader3", strExt);
          dCaps[i].fDepthClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_depth_clamp", strExt);
          dCaps[i].fLightMaxExp = 
			  gluCheckExtension ((const GLubyte *) "GL_NV_light_max_exponent", strExt);
          dCaps[i].fRasterPosClip = 
			  gluCheckExtension ((const GLubyte *) "GL_IBM_rasterpos_clip", strExt);
          dCaps[i].fConvBorderModes = 
			  gluCheckExtension ((const GLubyte *) "GL_HP_convolution_border_modes", strExt) ||
			  gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt);
		  dCaps[i].fAuxDeptStencil =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_aux_depth_stencil", strExt);
		  dCaps[i].fFlushBufferRange =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_buffer_range", strExt);
		  dCaps[i].fObjectPurgeable =
			  gluCheckExtension ((const GLubyte *) "GL_APPLE_object_purgeable", strExt);
		  dCaps[i].fDrawBuffers =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_draw_buffers", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fFragmentProgShadow =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program_shadow", strExt);
		  dCaps[i].fFragmentShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_shader", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fHalfFloatPixel = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_half_float_pixel", strExt);
		  dCaps[i].fOcclusionQuery = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_occlusion_query", strExt) ||
			  (dCaps[i].glVersion >= 0x0150);
		  dCaps[i].fPBO = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_pixel_buffer_object", strExt) ||
			  (dCaps[i].glVersion >= 0x0210);
		  dCaps[i].fPointSprite = 			
			  gluCheckExtension ((const GLubyte *) "GL_ARB_point_sprite", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fShaderObjects = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shader_objects", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fShaderTextureLOD = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shader_texture_lod", strExt);
		  dCaps[i].fShadingLanguage100 =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_shading_language_100", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fTexFloat =
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_float", strExt);
		  dCaps[i].fTexNPOT = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_texture_non_power_of_two", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fVBO = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_buffer_object", strExt) ||
			  (dCaps[i].glVersion >= 0x0150);
		  dCaps[i].fVertexShader = 
			  gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_shader", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fTexComp3dc = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_compression_3dc", strExt);
		  dCaps[i].fTexATIfloat = 
			  gluCheckExtension ((const GLubyte *) "GL_ATI_texture_float", strExt);
		  dCaps[i].fBlendEqSep = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_blend_equation_separate", strExt) ||
			  (dCaps[i].glVersion >= 0x0200);
		  dCaps[i].fDepthBounds = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_depth_bounds_test", strExt);
		  dCaps[i].fFBOblit =
			  gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_blit", strExt);
		  dCaps[i].fFBO = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_object", strExt);
		  dCaps[i].fGeometryShader4 = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_geometry_shader4", strExt);
		  dCaps[i].fGPUProgParams = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_program_parameters", strExt);
		  dCaps[i].fGPUShader4 = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_shader4", strExt);
		  dCaps[i].fDepthStencil = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_packed_depth_stencil", strExt);
		  dCaps[i].fSepSpecColor = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_separate_specular_color", strExt) ||
			  (dCaps[i].glVersion >= 0x0120);
		  dCaps[i].fTexCompDXT1 =
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_dxt1", strExt);
		  dCaps[i].fTexMirrorClamp = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_mirror_clamp", strExt);
		  dCaps[i].fTexSRGB = 
			  gluCheckExtension ((const GLubyte *) "GL_EXT_texture_sRGB", strExt) ||
			  (dCaps[i].glVersion >= 0x0210);		  
		  
		  if (dCaps[i].fTexRect) // only check if extension supported
				glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT,
							   &dCaps[i].maxRectTextureSize);
			else
				dCaps[i].maxRectTextureSize = 0;
			
          CGLDestroyContext (cglContext);
        }
      }
      CGLSetCurrentContext (curr_ctx); // reset current CGL context
    }
  }
}
void COpenGLExtensionHandler::initExtensions(bool stencilBuffer)
{
	const f32 ver = (f32)atof((c8*)glGetString(GL_VERSION));
	Version = core::floor32(ver)*100+(s32)(ver-floor(ver));
	if ( Version >= 102)
		os::Printer::log("OpenGL driver version is 1.2 or better.", ELL_INFORMATION);
	else
		os::Printer::log("OpenGL driver version is not 1.2 or better.", ELL_WARNING);

	const GLubyte* t = glGetString(GL_EXTENSIONS);
//	os::Printer::log((const c8*)t, ELL_INFORMATION);
	#ifdef GLU_VERSION_1_3
	const GLubyte* gluVersion = gluGetString(GLU_VERSION);

	if (gluVersion[0]>1 || gluVersion[3]>2)
	{
		for (u32 i=0; i<IRR_OpenGL_Feature_Count; ++i)
			FeatureAvailable[i] = gluCheckExtension((const GLubyte*)OpenGLFeatureStrings[i], t);
	}
	else
	#endif
	{
		s32 len = (s32)strlen((const char*)t);
		c8 *str = new c8[len+1];
		c8* p = str;

		for (s32 i=0; i<len; ++i)
		{
			str[i] = (char)t[i];

			if (str[i] == ' ')
			{
				str[i] = 0;
				for (u32 i=0; i<IRR_OpenGL_Feature_Count; ++i)
					if (strstr(p, OpenGLFeatureStrings[i]))
						FeatureAvailable[i] = true;

				p = p + strlen(p) + 1;
			}
		}

		delete [] str;
	}

	MultiTextureExtension = FeatureAvailable[IRR_ARB_multitexture];
	MultiSamplingExtension = FeatureAvailable[IRR_ARB_multisample];
	AnisotropyExtension = FeatureAvailable[IRR_EXT_texture_filter_anisotropic];
	SeparateStencilExtension = FeatureAvailable[IRR_ATI_separate_stencil];
	TextureCompressionExtension = FeatureAvailable[IRR_ARB_texture_compression];
	PackedDepthStencilExtension = FeatureAvailable[IRR_EXT_packed_depth_stencil];
	SeparateSpecularColorExtension = FeatureAvailable[IRR_EXT_separate_specular_color];
	StencilBuffer=stencilBuffer;

#ifdef _IRR_WINDOWS_API_
	// get multitexturing function pointers
	pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
	pGlClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC) wglGetProcAddress("glClientActiveTextureARB");

	// get fragment and vertex program function pointers
	pGlGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) wglGetProcAddress("glGenProgramsARB");
	pGlBindProgramARB = (PFNGLBINDPROGRAMARBPROC) wglGetProcAddress("glBindProgramARB");
	pGlProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) wglGetProcAddress("glProgramStringARB");
	pGlDeleteProgramsARB = (PFNGLDELETEPROGRAMSNVPROC) wglGetProcAddress("glDeleteProgramsARB");
	pGlProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) wglGetProcAddress("glProgramLocalParameter4fvARB");
	pGlCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress("glCreateShaderObjectARB");
	pGlShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress("glShaderSourceARB");
	pGlCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress("glCompileShaderARB");
	pGlCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress("glCreateProgramObjectARB");
	pGlAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress("glAttachObjectARB");
	pGlLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress("glLinkProgramARB");
	pGlUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress("glUseProgramObjectARB");
	pGlDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) wglGetProcAddress("glDeleteObjectARB");
	pGlGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) wglGetProcAddress("glGetInfoLogARB");
	pGlGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) wglGetProcAddress("glGetObjectParameterivARB");
	pGlGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) wglGetProcAddress("glGetUniformLocationARB");
	pGlUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) wglGetProcAddress("glUniform4fvARB");
	pGlUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) wglGetProcAddress("glUniform1ivARB");
	pGlUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) wglGetProcAddress("glUniform1fvARB");
	pGlUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) wglGetProcAddress("glUniform2fvARB");
	pGlUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) wglGetProcAddress("glUniform3fvARB");
	pGlUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) wglGetProcAddress("glUniformMatrix2fvARB");
	pGlUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) wglGetProcAddress("glUniformMatrix3fvARB");
	pGlUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) wglGetProcAddress("glUniformMatrix4fvARB");
	pGlGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) wglGetProcAddress("glGetActiveUniformARB");

	// get point parameter extension
	pGlPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC) wglGetProcAddress("glPointParameterfARB");
	pGlPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC) wglGetProcAddress("glPointParameterfvARB");

	// get stencil extension
	pGlStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) wglGetProcAddress("glStencilFuncSeparate");
	pGlStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) wglGetProcAddress("glStencilOpSeparate");
	pGlStencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC) wglGetProcAddress("glStencilFuncSeparateATI");
	pGlStencilOpSeparateATI = (PFNGLSTENCILOPSEPARATEATIPROC) wglGetProcAddress("glStencilOpSeparateATI");

	// compressed textures
	#ifdef PFNGLCOMPRESSEDTEXIMAGE2DPROC
	pGlCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) wglGetProcAddress("glCompressedTexImage2D");
	#endif

        // FrameBufferObjects
        pGlBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) wglGetProcAddress("glBindFramebufferEXT");
        pGlDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
        pGlGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) wglGetProcAddress("glGenFramebuffersEXT");
        pGlCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
        pGlFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
        pGlBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) wglGetProcAddress("glBindRenderbufferEXT");
        pGlDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
        pGlGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) wglGetProcAddress("glGenRenderbuffersEXT");
        pGlRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) wglGetProcAddress("glRenderbufferStorageEXT");
        pGlFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");

	// vsync extension
	wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress( "wglSwapIntervalEXT" );

#elif defined(_IRR_USE_LINUX_DEVICE_) || defined (_IRR_USE_SDL_DEVICE_)
	#ifdef _IRR_OPENGL_USE_EXTPOINTER_

	#ifdef _IRR_USE_SDL_DEVICE_
		#define IRR_OGL_LOAD_EXTENSION(x) SDL_GL_GetProcAddress(reinterpret_cast<const char*>(x))
	#else
	// Accessing the correct function is quite complex
	// All libraries should support the ARB version, however
	// since GLX 1.4 the non-ARB version is the official one
	// So we have to check the runtime environment and
	// choose the proper symbol
	// In case you still have problems please enable the
	// next line by uncommenting it
	// #define _IRR_GETPROCADDRESS_WORKAROUND_

	#ifndef _IRR_GETPROCADDRESS_WORKAROUND_
	__GLXextFuncPtr (*IRR_OGL_LOAD_EXTENSION)(const GLubyte*)=0;
	#ifdef GLX_VERSION_1_4
		int major,minor;
		glXQueryVersion(glXGetCurrentDisplay(), &major, &minor);
		if ((major>1) || (minor>3))
			IRR_OGL_LOAD_EXTENSION=glXGetProcAddress;
		else
	#endif
			IRR_OGL_LOAD_EXTENSION=glXGetProcAddressARB;
	#else
		#define IRR_OGL_LOAD_EXTENSION glXGetProcAddressARB
	#endif
	#endif

	pGlActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glActiveTextureARB"));

	pGlClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glClientActiveTextureARB"));

	// get fragment and vertex program function pointers
	pGlGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGenProgramsARB"));

	pGlBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glBindProgramARB"));

	pGlProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glProgramStringARB"));

	pGlDeleteProgramsARB = (PFNGLDELETEPROGRAMSNVPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glDeleteProgramsARB"));

	pGlProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glProgramLocalParameter4fvARB"));

	pGlCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glCreateShaderObjectARB"));

	pGlShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glShaderSourceARB"));

	pGlCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glCompileShaderARB"));

	pGlCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glCreateProgramObjectARB"));

	pGlAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glAttachObjectARB"));

	pGlLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glLinkProgramARB"));

	pGlUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUseProgramObjectARB"));

	pGlDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glDeleteObjectARB"));

	pGlGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGetInfoLogARB"));

	pGlGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGetObjectParameterivARB"));

	pGlGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGetUniformLocationARB"));

	pGlUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform4fvARB"));

	pGlUniform1ivARB = (PFNGLUNIFORM1IVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform1ivARB"));

	pGlUniform1fvARB = (PFNGLUNIFORM1FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform1fvARB"));

	pGlUniform2fvARB = (PFNGLUNIFORM2FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform2fvARB"));

	pGlUniform3fvARB = (PFNGLUNIFORM3FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform3fvARB"));

	pGlUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniform4fvARB"));

	pGlUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniformMatrix2fvARB"));

	pGlUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniformMatrix3fvARB"));

	pGlUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glUniformMatrix4fvARB"));

	pGlGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGetActiveUniformARB"));

	// get point parameter extension
	pGlPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glPointParameterfARB"));
	pGlPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glPointParameterfvARB"));

	// get stencil extension
	pGlStencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glStencilFuncSeparate"));
	pGlStencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glStencilOpSeparate"));
	pGlStencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glStencilFuncSeparateATI"));
	pGlStencilOpSeparateATI = (PFNGLSTENCILOPSEPARATEATIPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glStencilOpSeparateATI"));

	// compressed textures
	#ifdef PFNGLCOMPRESSEDTEXIMAGE2DPROC
	pGlCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC)
		IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glCompressedTexImage2D"));
	#endif

	#if defined(GLX_SGI_swap_control) && !defined(_IRR_USE_SDL_DEVICE_)
		// get vsync extension
		glxSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glXSwapIntervalSGI"));
	#endif

	// FrameBufferObjects
	pGlBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glBindFramebufferEXT"));

	pGlDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glDeleteFramebuffersEXT"));

	pGlGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGenFramebuffersEXT"));

	pGlCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glCheckFramebufferStatusEXT"));

	pGlFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glFramebufferTexture2DEXT"));

	pGlBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glBindRenderbufferEXT"));

	pGlDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glDeleteRenderbuffersEXT"));

	pGlGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glGenRenderbuffersEXT"));

	pGlRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glRenderbufferStorageEXT"));

	pGlFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC)
	IRR_OGL_LOAD_EXTENSION(reinterpret_cast<const GLubyte*>("glFramebufferRenderbufferEXT"));

	#endif // _IRR_OPENGL_USE_EXTPOINTER_
#endif // _IRR_WINDOWS_API_

	// set some properties
	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &MaxTextureUnits);
	glGetIntegerv(GL_MAX_LIGHTS, &MaxLights);
	glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &MaxAnisotropy);

#ifdef _IRR_OPENGL_USE_EXTPOINTER_
	if (!pGlActiveTextureARB || !pGlClientActiveTextureARB)
	{
		MultiTextureExtension = false;
		os::Printer::log("Failed to load OpenGL's multitexture extension, proceeding without.", ELL_WARNING);
	}
	else
#endif
	if (MaxTextureUnits < 2)
	{
		MultiTextureExtension = false;
		os::Printer::log("Warning: OpenGL device only has one texture unit. Disabling multitexturing.", ELL_WARNING);
	}
	MaxTextureUnits = core::min_((u32)MaxTextureUnits,MATERIAL_MAX_TEXTURES);
	glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &MaxIndices);

}
예제 #10
0
const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
    fDisplay = XOpenDisplay(0);

    if (!fDisplay) {
        SkDebugf("Failed to open X display.\n");
        this->destroyGLContext();
        return NULL;
    }

    // Get a matching FB config
    static int visual_attribs[] = {
        GLX_X_RENDERABLE    , True,
        GLX_DRAWABLE_TYPE   , GLX_PIXMAP_BIT,
        None
    };

    int glx_major, glx_minor;

    // FBConfigs were added in GLX version 1.3.
    if (!glXQueryVersion(fDisplay, &glx_major, &glx_minor) ||
            ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) {
        SkDebugf("GLX version 1.3 or higher required.\n");
        this->destroyGLContext();
        return NULL;
    }

    //SkDebugf("Getting matching framebuffer configs.\n");
    int fbcount;
    GLXFBConfig *fbc = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay),
                                          visual_attribs, &fbcount);
    if (!fbc) {
        SkDebugf("Failed to retrieve a framebuffer config.\n");
        this->destroyGLContext();
        return NULL;
    }
    //SkDebugf("Found %d matching FB configs.\n", fbcount);

    // Pick the FB config/visual with the most samples per pixel
    //SkDebugf("Getting XVisualInfos.\n");
    int best_fbc = -1, best_num_samp = -1;

    int i;
    for (i = 0; i < fbcount; ++i) {
        XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, fbc[i]);
        if (vi) {
            int samp_buf, samples;
            glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
            glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLES, &samples);

            //SkDebugf("  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;
        }
        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(fDisplay, bestFbc);
    //SkDebugf("Chosen visual ID = 0x%x\n", (unsigned int)vi->visualid);

    fPixmap = XCreatePixmap(fDisplay, RootWindow(fDisplay, vi->screen), 10, 10, vi->depth);

    if (!fPixmap) {
        SkDebugf("Failed to create pixmap.\n");
        this->destroyGLContext();
        return NULL;
    }

    fGlxPixmap = glXCreateGLXPixmap(fDisplay, vi, fPixmap);

    // Done with the visual info data
    XFree(vi);

    // Create the context

    // 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);

    // Get the default screen's GLX extension list
    const char *glxExts = glXQueryExtensionsString(
        fDisplay, DefaultScreen(fDisplay)
    );


    // 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 (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_context"),
                           reinterpret_cast<const GLubyte*>(glxExts))) {
        if (kGLES_GrGLStandard != forcedGpuAPI) {
            fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
        }
    } else {
        //SkDebugf("Creating context.\n");
        PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB =
            (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*)"glXCreateContextAttribsARB");

        if (kGLES_GrGLStandard == forcedGpuAPI) {
            if (gluCheckExtension(
                    reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2_profile"),
                    reinterpret_cast<const GLubyte*>(glxExts))) {
                static const int context_attribs_gles[] = {
                    GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
                    GLX_CONTEXT_MINOR_VERSION_ARB, 0,
                    GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
                    None
                };
                fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
                                                      context_attribs_gles);
            }
        } else {
            // Well, unfortunately GLX will not just give us the highest context so instead we have
            // to do this nastiness
            for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) {
                /* don't bother below GL 3.0 */
                if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) {
                    break;
                }
                // On Nvidia GPUs, to use Nv Path rendering we need a compatibility profile for the
                // time being.
                // TODO when Nvidia implements NVPR on Core profiles, we should start requesting
                // core here
                static const int context_attribs_gl[] = {
                      GLX_CONTEXT_MAJOR_VERSION_ARB, gl_versions[i].major,
                      GLX_CONTEXT_MINOR_VERSION_ARB, gl_versions[i].minor,
                      GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
                      None
                };
                fContext =
                        glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, context_attribs_gl);

                // Sync to ensure any errors generated are processed.
                XSync(fDisplay, False);

                if (!ctxErrorOccurred && fContext) {
                    break;
                }
                // try again
                ctxErrorOccurred = false;
            }

            // 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.
            if (ctxErrorOccurred || !fContext) {
                static const int context_attribs_gl_fallback[] = {
                    GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
                    GLX_CONTEXT_MINOR_VERSION_ARB, 0,
                    None
                };

                ctxErrorOccurred = false;

                fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
                                                      context_attribs_gl_fallback);
            }
        }
    }

    // Sync to ensure any errors generated are processed.
    XSync(fDisplay, False);

    // Restore the original error handler
    XSetErrorHandler(oldHandler);

    if (ctxErrorOccurred || !fContext) {
        SkDebugf("Failed to create an OpenGL context.\n");
        this->destroyGLContext();
        return NULL;
    }

    // Verify that context is a direct context
    if (!glXIsDirect(fDisplay, fContext)) {
        //SkDebugf("Indirect GLX rendering context obtained.\n");
    } else {
        //SkDebugf("Direct GLX rendering context obtained.\n");
    }

    //SkDebugf("Making context current.\n");
    if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) {
      SkDebugf("Could not set the context.\n");
        this->destroyGLContext();
        return NULL;
    }

    const GrGLInterface* interface = GrGLCreateNativeInterface();
    if (!interface) {
        SkDebugf("Failed to create gl interface");
        this->destroyGLContext();
        return NULL;
    }
    return interface;
}