Exemple #1
0
bool QGLPixelBuffer::hasOpenGLPbuffers()
{
    bool ret = qt_resolve_pbuffer_extensions();

    if (!ret)
	return false;

    int attribs[40];
    int num_configs = 0;

    qt_format_to_attrib_list(QGLFormat::defaultFormat(), attribs);

    GLXFBConfig *configs = glXChooseFBConfig(X11->display, X11->defaultScreen, attribs, &num_configs);
    GLXPbuffer pbuf = 0;
    GLXContext ctx = 0;

    if (configs && num_configs) {
        int pb_attribs[] = {GLX_PBUFFER_WIDTH, 128, GLX_PBUFFER_HEIGHT, 128, XNone};
        pbuf = glXCreatePbuffer(X11->display, configs[0], pb_attribs);
        ctx = glXCreateNewContext(X11->display, configs[0], GLX_RGBA_TYPE, 0, true);
        XFree(configs);
	glXDestroyContext(X11->display, ctx);
	glXDestroyPbuffer(X11->display, pbuf);
    }
    return pbuf && ctx;
}
Exemple #2
0
std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(PlatformDisplay& platformDisplay, GLXContext sharingContext)
{
    static const int fbConfigAttributes[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_ALPHA_SIZE, 1,
        GLX_DOUBLEBUFFER, GL_FALSE,
        0
    };

    int returnedElements;
    Display* display = downcast<PlatformDisplayX11>(platformDisplay).native();
    XUniquePtr<GLXFBConfig> configs(glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements));
    if (!returnedElements)
        return nullptr;

    // We will be rendering to a texture, so our pbuffer does not need to be large.
    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
    XUniqueGLXPbuffer pbuffer(glXCreatePbuffer(display, configs.get()[0], pbufferAttributes));
    if (!pbuffer)
        return nullptr;

    XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
    if (!context)
        return nullptr;

    return std::unique_ptr<GLContextGLX>(new GLContextGLX(platformDisplay, WTFMove(context), WTFMove(pbuffer)));
}
//----------------------------------------------------------------------------//
void OpenGLGLXPBTextureTarget::initialisePBuffer()
{
    int creation_attrs[] =
    {
        GLX_PBUFFER_WIDTH, d_area.getWidth(),
        GLX_PBUFFER_HEIGHT, d_area.getHeight(),
        GLX_LARGEST_PBUFFER, True,
        GLX_PRESERVED_CONTENTS, True,
        None
    };

    // release any existing pbuffer
    if (d_pbuffer)
        glXDestroyPbuffer(d_dpy, d_pbuffer);

    d_pbuffer = glXCreatePbuffer(d_dpy, d_fbconfig, creation_attrs);

    if (!d_pbuffer)
        throw RendererException("OpenGLGLXPBTextureTarget::initialisePBuffer - "
            "pbuffer creation error:  glXCreatePbuffer() failed");

    // get the real size of the buffer that was created
    GLuint actual_width, actual_height;
    glXQueryDrawable(d_dpy, d_pbuffer, GLX_WIDTH, &actual_width);
    glXQueryDrawable(d_dpy, d_pbuffer, GLX_HEIGHT, &actual_height);
    d_area.setSize(Size(actual_width, actual_height));

    // ensure CEGUI::Texture is wrapping real GL texture and has correct size
    d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize());
}
bool GraphicsContext::acquireGLSystem()
{
    m_window = glXCreateWindow(m_display, m_config, m_xWindow, NULL);
    if (!m_window) {
        printf("%s: %s (%i): ERROR - Invalid glxWindow\n", __FILE__, __FUNCTION__, __LINE__);
        return false;
    }

    const int pbuffer_attribs[] =
      {
        GLX_PBUFFER_WIDTH, 1,
        GLX_PBUFFER_HEIGHT, 1,
        None
      };

    m_pbuffer = glXCreatePbuffer(m_display, m_config, pbuffer_attribs);
    if (!m_window) {
        printf("%s: %s (%i): ERROR - Invalid glxPbuffer\n", __FILE__, __FUNCTION__, __LINE__);
        return false;
    }

    m_context = glXCreateNewContext(m_display, m_config, GLX_RGBA_TYPE, NULL, true);
    if (!m_context) {
        printf("%s: %s (%i): ERROR - Invalid glxContext\n", __FILE__, __FUNCTION__, __LINE__);
        return false;
    }

    return true;
}
void HeadlessView::createContext() {
    xDisplay = display->xDisplay;
    fbConfigs = display->fbConfigs;

    if (!glContext) {
        // Try to create a legacy context
        glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True);
        if (glContext) {
            if (!glXIsDirect(xDisplay, glContext)) {
                Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context");
                glXDestroyContext(xDisplay, glContext);
                glContext = 0;
            }
        }
    }

    if (glContext == 0) {
        throw std::runtime_error("Error creating GL context object.");
    }

    // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to
    // activate the context.
    int pbufferAttributes[] = {
        GLX_PBUFFER_WIDTH, 8,
        GLX_PBUFFER_HEIGHT, 8,
        None
    };
    glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes);
}
Exemple #6
0
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
{
  int maxHeight, maxWidth;

  glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_WIDTH, &maxWidth);
  glXGetFBConfigAttrib(window, *configs, GLX_MAX_PBUFFER_HEIGHT, &maxHeight);

  ms_uint32 uMaxHeight = maxHeight, uMaxWidth = maxWidth;

  this->width = MS_MIN(width, uMaxWidth);
  this->height = MS_MIN(height, uMaxHeight);

  int iPbufferAttributes[] = {
    GLX_PBUFFER_WIDTH, this->width,
    GLX_PBUFFER_HEIGHT, this->height,
    GLX_LARGEST_PBUFFER, false,
    0, 0
  };

  pbuffer = glXCreatePbuffer(window, *configs, iPbufferAttributes);
  if (pbuffer == 0) {
    msSetError(MS_OGLERR, "glXCreatePbuffer failed. glError: %d", "OglContext::init()", glGetError());
    return false;
  }

  return true;
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_GLX13_nglXCreatePbuffer(JNIEnv *__env, jclass clazz, jlong displayAddress, jlong configAddress, jlong attrib_listAddress, jlong __functionAddress) {
	Display *display = (Display *)(intptr_t)displayAddress;
	GLXFBConfig config = (GLXFBConfig)(intptr_t)configAddress;
	const int *attrib_list = (const int *)(intptr_t)attrib_listAddress;
	glXCreatePbufferPROC glXCreatePbuffer = (glXCreatePbufferPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	return (jlong)(intptr_t)glXCreatePbuffer(display, config, attrib_list);
}
Exemple #8
0
/**
 * Create a Pbuffer.  Use an X error handler to deal with potential
 * BadAlloc errors.
 *
 * Input:  dpy - the X display
 *         fbConfig - an FBConfig as returned by glXChooseFBConfigSGIX().
 *         width, height - size of pixel buffer to request, in pixels.
 *         pbAttribs - list of optional pixel buffer attributes
 * Return:  a Pbuffer or None.
 */
PBUFFER
CreatePbuffer(Display *dpy, int screen, FBCONFIG config,
              int width, int height, Bool largest, Bool preserve)
{
   int (*oldHandler)(Display *, XErrorEvent *);
   PBUFFER pBuffer = None;
   int pbSupport = QueryPbuffers(dpy, screen);

   /* Catch X protocol errors with our own error handler */
   oldHandler = XSetErrorHandler(HandleXError);
   XErrorFlag = 0;

#if defined(GLX_VERSION_1_3)
   if (pbSupport == 1) {
      /* GLX 1.3 */
      int attribs[100], i = 0;
      attribs[i++] = GLX_PBUFFER_WIDTH;
      attribs[i++] = width;
      attribs[i++] = GLX_PBUFFER_HEIGHT;
      attribs[i++] = height;
      attribs[i++] = GLX_PRESERVED_CONTENTS;
      attribs[i++] = preserve;
      attribs[i++] = GLX_LARGEST_PBUFFER;
      attribs[i++] = largest;
      attribs[i++] = 0;
      pBuffer = glXCreatePbuffer(dpy, config, attribs);
   }
   else
#endif
#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
   if (pbSupport == 2) {
      int attribs[100], i = 0;
      attribs[i++] = GLX_PRESERVED_CONTENTS;
      attribs[i++] = preserve;
      attribs[i++] = GLX_LARGEST_PBUFFER;
      attribs[i++] = largest;
      attribs[i++] = 0;
      pBuffer = glXCreateGLXPbufferSGIX(dpy, config, width, height, attribs);
   }
   else
#endif
   {
      pBuffer = None;
   }

   /* Restore original X error handler */
   (void) XSetErrorHandler(oldHandler);

   /* Return pbuffer (may be None) */
   if (!XErrorFlag && pBuffer != None) {
      /*printf("config %d worked!\n", i);*/
      return pBuffer;
   }
   else {
      return None;
   }
}
Exemple #9
0
void SnapshotTaker::snapshotCallback(TCAlert *alert)
{
	if (getUseFBO())
	{
		return;
	}
	if (strcmp(alert->getMessage(), "PreFbo") == 0)
	{
		static int visualAttribs[] = { None };
		int numberOfFramebufferConfigurations = 0;
		GLXFBConfig* fbConfigs = glXChooseFBConfig(display, DefaultScreen(display), visualAttribs, &numberOfFramebufferConfigurations);
		if (fbConfigs == NULL)
		{
			return;
		}
		static int attributeList[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_STENCIL_SIZE, 8, None };
		XVisualInfo *vi = glXChooseVisual(display, DefaultScreen(display), attributeList);
		if (vi == NULL)
		{
			size_t count = sizeof(attributeList) / sizeof(attributeList[0]);
			attributeList[count - 3] = None;
			vi = glXChooseVisual(display, DefaultScreen(display), attributeList);
		}
		if (vi == NULL)
		{
			XFree(fbConfigs);
		}
		context = glXCreateContext(display, vi, 0, True);
		XFree(vi);
		if (context == NULL)
		{
			XFree(fbConfigs);
			return;
		}
		// We're using FBO, but we need a PBuffer to bind something to the
		// context, so create a tiny one.
		int pbufferAttribs[] =
		{
			GLX_PBUFFER_WIDTH,  32,
			GLX_PBUFFER_HEIGHT, 32,
			None
		};
		pbuffer = glXCreatePbuffer(display, fbConfigs[0], pbufferAttribs);
		XFree(fbConfigs);
		XSync(display, False);
		if (!glXMakeContextCurrent(display, pbuffer, pbuffer, context))
		{
			cleanupContext();
			return;
		}
		TREGLExtensions::setup();
		ldSnapshotTaker = (LDSnapshotTaker*)alert->getSender()->retain();
		ldSnapshotTaker->setUseFBO(true);
	}
}
COffscreenGLContext::COffscreenGLContext()
{
	//! Get MainCtx & X11-Display
	GLXContext mainCtx = glXGetCurrentContext();
	//GLXDrawable mainDrawable = glXGetCurrentDrawable();
	if(!mainCtx)
		throw opengl_error("Couldn't create an offscreen GL context: glXGetCurrentContext failed!");

	SDL_SysWMinfo info;
	SDL_VERSION(&info.version);
	if(!SDL_GetWMInfo(&info))
		throw opengl_error("Couldn't create an offscreen GL context: SDL_GetWMInfo failed!");

	info.info.x11.lock_func();
		display = info.info.x11.display;
		int scrnum = XDefaultScreen(display);
	info.info.x11.unlock_func();
	if (!display)
		throw opengl_error("Couldn't create an offscreen GL context: Couldn't determine display!");


	//! Create a FBConfig
	int nelements = 0;
	const int fbattrib[] = {
		GLX_RENDER_TYPE, GLX_RGBA_BIT,
		GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
		GLX_BUFFER_SIZE, 32,
		GLX_DEPTH_SIZE, 24,
		GLX_STENCIL_SIZE, 8,
		None
	};
	GLXFBConfig* fbcfg = glXChooseFBConfig(display, scrnum, (const int*)fbattrib, &nelements);
	if (!fbcfg || (nelements == 0))
		throw opengl_error("Couldn't create an offscreen GL context: glXChooseFBConfig failed!");


	//! Create a pbuffer (each render context needs a drawable)
	const int pbuf_attrib[] = {
		GLX_PBUFFER_WIDTH, 1,
		GLX_PBUFFER_HEIGHT, 1,
		GLX_PRESERVED_CONTENTS, false,
		None
	};
	pbuf = glXCreatePbuffer(display, *fbcfg, (const int*)pbuf_attrib);
	if (!pbuf)
		throw opengl_error("Couldn't create an offscreen GL context: glXCreatePbuffer failed!");


	//! Create render context
	workerCtx = glXCreateNewContext(display, *fbcfg, GLX_RGBA_TYPE, mainCtx, true);
	if (!workerCtx)
		throw opengl_error("Couldn't create an offscreen GL context: glXCreateNewContext failed!");

	XFree(fbcfg);
}
Exemple #11
0
GLXState *
glx_context_new_pbuffer (Display * dpy, int width, int height,
        GLXState * shared)
{
    GLXState * c;
    GLXFBConfig * fbconfig;
    int count;
    GLXContext context;
    GLXPbuffer pbdraw;
    GLXContext sh_context = NULL;

    if (shared)
        sh_context = shared->context;

    int pb_attr[] = {
        GLX_PBUFFER_WIDTH, width,
        GLX_PBUFFER_HEIGHT, height,
        None
    };

    fbconfig = glXChooseFBConfig (dpy, DefaultScreen (dpy),
            attr_list_pb, &count);
    if (fbconfig == NULL || count == 0) {
        fprintf (stderr, "GLX Context Error: No FBConfigs found\n");
        return NULL;
    }

    pbdraw = glXCreatePbuffer (dpy, fbconfig[0], pb_attr);
    if (!pbdraw) {
        fprintf (stderr, "GLX Context Error: Failed to create Pbuffer\n");
        XFree (fbconfig);
        return NULL;
    }

    context = glXCreateNewContext (dpy, fbconfig[0], GLX_RGBA_TYPE,
            sh_context, GL_TRUE);
    if (!context) {
        fprintf (stderr, "GLX Context Error: Failed to get GLX PB context\n");
        glXDestroyPbuffer (dpy, pbdraw);
        XFree (fbconfig);
        return NULL;
    }

    c = malloc (sizeof (GLXState));
    memset (c, 0, sizeof (GLXState));

    c->width = width;
    c->height = height;
    c->dpy = dpy;
    c->fbconfig = fbconfig;
    c->pbuffer = pbdraw;
    c->context = context;

    return c;
}
Exemple #12
0
GLOffscreenBuffer::GLOffscreenBuffer(unsigned width, unsigned height)
    : m_width(width)
    , m_height(height)
    , m_display(XOpenDisplay(0))
    , m_pbuffer(0)
    , m_context(0)
{
    if (!m_display) {
        std::cerr << "Error: XOpenDisplay()\n";
        return;
    }

    static const int configAttributes[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_RED_SIZE, 8,
        GLX_GREEN_SIZE, 8,
        GLX_BLUE_SIZE, 8,
        GLX_ALPHA_SIZE, 8,
        GLX_DOUBLEBUFFER, GL_FALSE,
        0
    };
    int configCount;
    GLXFBConfig* config = glXChooseFBConfig(m_display, 0, configAttributes, &configCount);
    if (!configCount) {
        std::cerr << "Error: glXChooseFBConfig()\n";
        XFree(config);
        XCloseDisplay(m_display);
        return;
    }

    static const int pbufferAttributes[] = {
        GLX_PBUFFER_WIDTH, static_cast<int>(width),
        GLX_PBUFFER_HEIGHT, static_cast<int>(height),
        0
    };
    m_pbuffer = glXCreatePbuffer(m_display, config[0], pbufferAttributes);
    if (!m_pbuffer) {
        std::cerr << "Error: glXCreatePbuffer()\n";
        XFree(config);
        XCloseDisplay(m_display);
        return;
    }

    m_context = glXCreateNewContext(m_display, config[0], GLX_RGBA_TYPE, 0, GL_TRUE);
    XFree(config);
    if (!m_context) {
        std::cerr << "Error: glXCreateNewContext()\n";
        glXDestroyPbuffer(m_display, m_pbuffer);
        XCloseDisplay(m_display);
        return;
    }
}
EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
    EGLint width,height,largest;
    srfc->getDim(&width,&height,&largest);

    int attribs[] = {
                     GLX_PBUFFER_WIDTH           ,width,
                     GLX_PBUFFER_HEIGHT          ,height,
                     GLX_LARGEST_PBUFFER         ,largest,
                     None
                    };
    GLXPbuffer pb = glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs);
    return pb ? new SrfcInfo(pb,SrfcInfo::PBUFFER) : NULL;
}
void HeadlessView::createContext() {
    if (!display) {
        throw std::runtime_error("Display is not set");
    }

#if MBGL_USE_CGL
    CGLError error = CGLCreateContext(display->pixelFormat, NULL, &glContext);
    if (error != kCGLNoError) {
        throw std::runtime_error(std::string("Error creating GL context object:") + CGLErrorString(error) + "\n");
    }

    error = CGLEnable(glContext, kCGLCEMPEngine);
    if (error != kCGLNoError) {
        throw std::runtime_error(std::string("Error enabling OpenGL multithreading:") + CGLErrorString(error) + "\n");
    }
#endif

#if MBGL_USE_GLX
    xDisplay = display->xDisplay;
    fbConfigs = display->fbConfigs;

    if (!glContext) {
        // Try to create a legacy context
        glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True);
        if (glContext) {
            if (!glXIsDirect(xDisplay, glContext)) {
                Log::Error(Event::OpenGL, "failed to create direct OpenGL Legacy context");
                glXDestroyContext(xDisplay, glContext);
                glContext = 0;
            }
        }
    }

    if (glContext == 0) {
        throw std::runtime_error("Error creating GL context object.");
    }

    // Create a dummy pbuffer. We will render to framebuffers anyway, but we need a pbuffer to
    // activate the context.
    int pbufferAttributes[] = {
        GLX_PBUFFER_WIDTH, 8,
        GLX_PBUFFER_HEIGHT, 8,
        None
    };
    glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes);
#endif
}
Exemple #15
0
Window
GlxDrawable::createPbuffer(Display *dpy, const GlxVisual *visinfo,
                           const glws::pbuffer_info *pbInfo, int w, int h)
{
    int samples = 0;

    // XXX ideally, we'd populate these attributes according to the Visual info
    Attributes<int> attribs;
    attribs.add(GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT);
    attribs.add(GLX_RENDER_TYPE, GLX_RGBA_BIT);
    attribs.add(GLX_RED_SIZE, 1);
    attribs.add(GLX_GREEN_SIZE, 1);
    attribs.add(GLX_BLUE_SIZE, 1);
    attribs.add(GLX_ALPHA_SIZE, 1);
    //attribs.add(GLX_DOUBLEBUFFER, doubleBuffer ? GL_TRUE : GL_FALSE);
    attribs.add(GLX_DEPTH_SIZE, 1);
    attribs.add(GLX_STENCIL_SIZE, 1);
    if (samples > 1) {
        attribs.add(GLX_SAMPLE_BUFFERS, 1);
        attribs.add(GLX_SAMPLES_ARB, samples);
    }
    attribs.end();

    int num_configs = 0;
    GLXFBConfig *fbconfigs;
    fbconfigs = glXChooseFBConfig(dpy, screen, attribs, &num_configs);
    if (!num_configs || !fbconfigs) {
        std::cerr << "error: glXChooseFBConfig for pbuffer failed.\n";
        exit(1);
    }

    Attributes<int> pbAttribs;
    pbAttribs.add(GLX_PBUFFER_WIDTH, w);
    pbAttribs.add(GLX_PBUFFER_HEIGHT, h);
    pbAttribs.add(GLX_PRESERVED_CONTENTS, True);
    pbAttribs.end();

    GLXDrawable pbuffer = glXCreatePbuffer(dpy, fbconfigs[0], pbAttribs);
    if (!pbuffer) {
        std::cerr << "error: glXCreatePbuffer() failed\n";
        exit(1);
    }

    return pbuffer;
}
Exemple #16
0
static bool gl_context_create(struct gl_platform *plat)
{
	Display *display = plat->display;
	int frame_buf_config_count = 0;
	GLXFBConfig *config = NULL;
	GLXContext context;
	bool success = false;

	if (!GLAD_GLX_ARB_create_context) {
		blog(LOG_ERROR, "ARB_GLX_create_context not supported!");
		return false;
	}

	config = glXChooseFBConfig(display, DefaultScreen(display),
			ctx_visual_attribs, &frame_buf_config_count);
	if (!config) {
		blog(LOG_ERROR, "Failed to create OpenGL frame buffer config");
		return false;
	}

	context = glXCreateContextAttribsARB(display, config[0], NULL,
			true, ctx_attribs);
	if (!context) {
		blog(LOG_ERROR, "Failed to create OpenGL context.");
		goto error;
	}

	plat->context = context;
	plat->display = display;

	plat->pbuffer = glXCreatePbuffer(display, config[0],
			ctx_pbuffer_attribs);
	if (!plat->pbuffer) {
		blog(LOG_ERROR, "Failed to create OpenGL pbuffer");
		goto error;
	}

	success = true;

error:
	XFree(config);
	XSync(display, false);
	return success;
}
Exemple #17
0
bool Window::configInitGLXPBuffer( GLXFBConfig* fbConfig )
{
    if( !_xDisplay )
    {
        setError( ERROR_GLXWINDOW_NO_DISPLAY );
        return false;
    }
    if( !fbConfig )
    {
        setError( ERROR_SYSTEMWINDOW_NO_PIXELFORMAT );
        return false;
    }
    if( !GLXEW_VERSION_1_3 )
    {
        setError( ERROR_GLXWINDOW_GLX_1_3_REQUIRED );
        return false;
    }

    // Create PBuffer
    const PixelViewport& pvp = getWindow()->getPixelViewport();
    const int attributes[] = { GLX_PBUFFER_WIDTH, pvp.w,
                               GLX_PBUFFER_HEIGHT, pvp.h,
                               GLX_LARGEST_PBUFFER, True,
                               GLX_PRESERVED_CONTENTS, True,
                               0 };

    // TODO: Could check for GLX_SGIX_pbuffer, but the only GLX 1.2 platform at
    // hand is OS X, which does not support this extension.

    XID pbuffer = glXCreatePbuffer( _xDisplay, fbConfig[ 0 ], attributes );
    if ( !pbuffer )
    {
        setError( ERROR_GLXWINDOW_CREATEPBUFFER_FAILED );
        return false;
    }

    XFlush( _xDisplay );
    setXDrawable( pbuffer );

    EQINFO << "Created X11 PBuffer " << pbuffer << std::endl;
    return true;
}
Exemple #18
0
void BC_PBuffer::create_pbuffer(int w, int h)
{
#ifdef HAVE_GL
	int ww = (w + 3) & ~3, hh = (h + 3) & ~3;
	int pb_attrs[] = {
		GLX_PBUFFER_WIDTH, ww,
		GLX_PBUFFER_HEIGHT, hh,
		GLX_LARGEST_PBUFFER, False,
		GLX_PRESERVED_CONTENTS, True,
		None
	};

	BC_WindowBase *current_window = BC_WindowBase::get_synchronous()->current_window;
	Display *dpy = current_window->get_display();
	GLXFBConfig *fb_cfgs = current_window->glx_pbuffer_fb_configs();
	int nfb_cfgs = current_window->n_fbcfgs_pbuffer;
	XVisualInfo *visinfo = 0;

	for( int i=0; !pbuffer && i<nfb_cfgs; ++i ) {
		if( visinfo ) { XFree(visinfo);  visinfo = 0; }
		BC_Resources::error = 0;
                visinfo = glXGetVisualFromFBConfig(dpy, fb_cfgs[i]);
		if( !visinfo || BC_Resources::error ) continue;
		pbuffer = glXCreatePbuffer(dpy, fb_cfgs[i], pb_attrs);
		if( BC_Resources::error ) pbuffer = 0;
	}

// printf("BC_PBuffer::create_pbuffer %d current_config=%d visinfo=%p error=%d pbuffer=%p\n",
// __LINE__, current_config, visinfo, BC_Resources::error, pbuffer);

	if( pbuffer ) {
		window_id = current_window->get_id();
		glx_context = glXCreateContext(dpy, visinfo, current_window->glx_win_context, 1);
		BC_WindowBase::get_synchronous()->put_pbuffer(w, h, pbuffer, glx_context);
	}
	else
		printf("BC_PBuffer::create_pbuffer: failed\n");

	if( visinfo ) XFree(visinfo);
#endif
}
GraphicsContext3DPrivate* GraphicsContext3DPrivate::createPbufferContext()
{
    int fbConfigAttributes[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        GLX_RENDER_TYPE, GLX_RGBA_BIT,
        GLX_RED_SIZE, 1,
        GLX_GREEN_SIZE, 1,
        GLX_BLUE_SIZE, 1,
        GLX_ALPHA_SIZE, 1,
        GLX_DEPTH_SIZE, 1,
        GLX_STENCIL_SIZE, 1,
        GLX_SAMPLE_BUFFERS, 1,
        GLX_DOUBLEBUFFER, GL_FALSE,
        GLX_SAMPLES, 4,
        0
    };
    int returnedElements;
    GLXFBConfig* configs = glXChooseFBConfig(sharedDisplay(), 0, fbConfigAttributes, &returnedElements);
    if (!configs) {
        fbConfigAttributes[20] = 0; // Attempt without anti-aliasing.
        configs = glXChooseFBConfig(sharedDisplay(), 0, fbConfigAttributes, &returnedElements);
    }
    if (!returnedElements) {
        XFree(configs);
        return 0;
    }

    // We will be rendering to a texture, so our pbuffer does not need to be large.
    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
    GLXPbuffer pbuffer = glXCreatePbuffer(sharedDisplay(), configs[0], pbufferAttributes);
    if (!pbuffer) {
        XFree(configs);
        return 0;
    }

    GLXContext context = glXCreateNewContext(sharedDisplay(), configs[0], GLX_RGBA_TYPE, 0, GL_TRUE);
    XFree(configs);
    if (!context)
        return 0;
    return new GraphicsContext3DPrivate(context, pbuffer);
}
Exemple #20
0
GLXPbuffer get_pbuffer(Display     *XJ_disp,
                       GLXFBConfig  glx_fbconfig,
                       const QSize &video_dim)
{
    int attrib_pbuffer[16];
    bzero(attrib_pbuffer, sizeof(int) * 16);
    attrib_pbuffer[0] = GLX_PBUFFER_WIDTH;
    attrib_pbuffer[1] = video_dim.width();
    attrib_pbuffer[2] = GLX_PBUFFER_HEIGHT;
    attrib_pbuffer[3] = video_dim.height();
    attrib_pbuffer[4] = GLX_PRESERVED_CONTENTS;
    attrib_pbuffer[5] = 0;

    GLXPbuffer tmp = 0;

#ifdef GLX_VERSION_1_3
    X11S(tmp = glXCreatePbuffer(XJ_disp, glx_fbconfig, attrib_pbuffer));
#endif // GLX_VERSION_1_3

    return tmp;
}
Exemple #21
0
void *platform_pbuffer_surface_create (PlatformDisplay *display,
                                       EGLProxyConfig *egl_config,
                                       SurfaceAttributes *attributes)
{
    GLXDrawable result = NULL;
    int attrib_list[] = {
        GLX_PBUFFER_WIDTH, 0,
        GLX_PBUFFER_HEIGHT, 0,
        GLX_LARGEST_PBUFFER, False,
        GLX_PRESERVED_CONTENTS, True
    };
    attrib_list[1] = attributes->specific.pbuffer.width;
    attrib_list[3] = attributes->specific.pbuffer.height;
    attrib_list[5] = (attributes->specific.pbuffer.largest_pbuffer == EGL_TRUE) ?
                     True : False;
    if (display->is_modern) {
        GLXFBConfig glx_config = (GLXFBConfig) egl_config->platform;
        result = glXCreatePbuffer (display->x11_display, glx_config,
                                   attrib_list);
    }
    return (void *) result;
}
int main()
{
#ifdef USE_EGL
	EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	if( d )
		printf("eglGetDisplay success!\n");
	else
		printf("eglGetDisplay failed!\n");
	
	int maj, min;
	if( eglInitialize(d, &maj, &min) )
		printf("eglInitialize success!\n");
	else
		printf("eglInitialize failed!\n");
	printf("EGL version = %d.%d\n", maj, min);
	printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
	
	EGLConfig first_config;
	EGLint numConfigs;
	eglGetConfigs(d, &first_config, 1, &numConfigs);
	
	if( eglBindAPI(EGL_OPENGL_API) )
		printf("eglBindAPI success!\n");
	else
		printf("eglBindAPI failed!\n");
	
	EGLContext ctx = eglCreateContext(d, first_config, EGL_NO_CONTEXT, NULL);
	if (ctx != EGL_NO_CONTEXT)
		printf("create context success!\n");
	else
		printf("create context failed!\n");

	const EGLint pbufAttribs[] = {
		EGL_WIDTH, width,
		EGL_HEIGHT, height,
		EGL_NONE
	};
	EGLSurface pbuffer = eglCreatePbufferSurface(d, first_config, pbufAttribs);
	if (pbuffer == EGL_NO_SURFACE) {
		printf("failed to create pbuffer!\n");
		return 0;
	}

	EGLBoolean b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
	if (b)
		printf("make current success!\n");
	else
		printf("make current failed!\n");
#else
	typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
	typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
	static glXCreateContextAttribsARBProc
		glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *)"glXCreateContextAttribsARB");
	static glXMakeContextCurrentARBProc
		glXMakeContextCurrentARB   = (glXMakeContextCurrentARBProc)   glXGetProcAddressARB( (const GLubyte *)"glXMakeContextCurrent");
	if(!glXCreateContextAttribsARB)
		std::cout << "glXGetProcAddressARB \"glXCreateContextAttribsARB\" failed!\n";
	if(!glXMakeContextCurrentARB)
		std::cout << "glXGetProcAddressARB \"glXMakeContextCurrentARB\" failed!\n";

	const char *displayName = NULL;
	Display* display = XOpenDisplay( displayName );

	if(!display)
		std::cout << "XOpenDisplay failed!\n";

	static int visualAttribs[] = { None };
	int numberOfFramebufferConfigurations = 0;
	GLXFBConfig* fbConfigs = glXChooseFBConfig( display, DefaultScreen(display), visualAttribs, &numberOfFramebufferConfigurations );

	if(!fbConfigs)
		std::cout << "glXChooseFBConfig failed!\n";

	int context_attribs[] = {
	    None
	};

	GLXContext openGLContext = glXCreateContextAttribsARB( display, fbConfigs[0], 0, True, context_attribs);

	if(!openGLContext)
		std::cout << "glXCreateContextAttribsARB failed!\n";

	int pbufferAttribs[] = {
	    GLX_PBUFFER_WIDTH,  width,
	    GLX_PBUFFER_HEIGHT, height,
	    None
	};
	GLXPbuffer pbuffer = glXCreatePbuffer( display, fbConfigs[0], pbufferAttribs );

	// clean up:
	XFree( fbConfigs );
	XSync( display, False );

	if ( !glXMakeContextCurrent( display, pbuffer, pbuffer, openGLContext ) ){
	    std::cout << "glXMakeContextCurrent failed!\n";
	}
#endif

	std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << ".\n";

	draw_and_save();

#ifdef USE_EGL
	eglDestroySurface(d, pbuffer);
	eglDestroyContext(d, ctx);
	eglTerminate(d);
#else
	glXDestroyPbuffer( display, pbuffer );
	glXDestroyContext( display, openGLContext );
#endif

	return 0;
}
Exemple #23
0
void init(int w, int h) {
    display = XOpenDisplay( NULL );
    if ( display == NULL ) {
        fprintf( stderr, "Bad DISPLAY (%s).\n", getenv( "DISPLAY" ) );
        exit( 1 );
    }

    int pbuffer_attributes[] = {
        GLX_RED_SIZE, 8,
        GLX_GREEN_SIZE, 8,
        GLX_BLUE_SIZE, 8,
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        0
    };

    int attributes[] = {
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
        GLX_RED_SIZE,      8,   /* Request a single buffered color buffer */
        GLX_GREEN_SIZE,    8,   /* with the maximum number of color bits  */
        GLX_BLUE_SIZE,     8,   /* for each component                     */
        None
    };


    int pb_nconfigs = 0;
    GLXFBConfig *pb_configs = glXChooseFBConfig( display,
                        DefaultScreen( display ),
                        pbuffer_attributes,
                        &pb_nconfigs );
    int nconfigs = 0;
    GLXFBConfig *configs = glXChooseFBConfig( display,
                        DefaultScreen( display ),
                        attributes,
                        &nconfigs );

    if ( !configs || !pb_configs) {
        fprintf( stderr, "Num configs: %d.\n", nconfigs );
        fprintf( stderr, "Num pbconfigs: %d.\n", pb_nconfigs );
        exit( 1 );
    }


    Window root = DefaultRootWindow(display);
    XVisualInfo* vi = glXGetVisualFromFBConfig(display, configs[0] );
    XSetWindowAttributes swa;
    swa.border_pixel = 0;
    swa.event_mask = StructureNotifyMask;
    swa.colormap = XCreateColormap( display, root, vi->visual, AllocNone );
    win = XCreateWindow(display, root, 0, 0, w, h, 0, vi->depth, InputOutput, vi->visual, CWEventMask | CWColormap, &swa);


    int pbuffer_create_attributes[] = {
        GLX_PBUFFER_WIDTH, w,
        GLX_PBUFFER_HEIGHT, h,
        0
    };


    XMapWindow(display, win);
    XStoreName(display, win, "Trajectory Visualizer");
    XEvent event;
    XIfEvent( display, &event, WaitForNotify, (XPointer) win);



    GLXPbuffer pbuffer = glXCreatePbuffer( display,
                     configs[ 0 ],
                     pbuffer_create_attributes );
    if ( !pbuffer ) {
        perror( "glXCreatePbuffer" );
        exit( 1 );
    }


    GLXWindow glxwin = glXCreateWindow( display, configs[0], win, NULL );

    GLXContext context = glXCreateNewContext( display,
                        configs[ 0 ],
                        GLX_RGBA_TYPE,
                        0,
                        GL_TRUE );


    GLXContext pbuffercontext = glXCreateNewContext( display,
                        pb_configs[ 0 ],
                        GLX_RGBA_TYPE,
                        0,
                        GL_TRUE );

    if ( glXMakeCurrent( display, pbuffer, context ) == 0 ) {
        perror( "glXMakeCurrent" );
        exit( 1 );
    }
    if (glXMakeContextCurrent( display, glxwin, glxwin, context ) == 0) {
        perror( "glXMakeContextCurrent" );
        exit( 1 );
    }
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
	//-------------------------------------------------------------------------------------------------//
	GLXPBuffer::GLXPBuffer(GLXGLSupport* glsupport, PixelComponentType format, size_t width, size_t height):
		mGLSupport(glsupport), GLPBuffer(format, width, height), mContext(0)
	{
		Display *glDisplay = mGLSupport->getGLDisplay();
		::GLXDrawable glxDrawable = 0;
		::GLXFBConfig fbConfig = 0;
		
		bool isFloat = false;
		int bits = 0;
		
		switch (mFormat)
		{
		case PCT_BYTE:
			bits = 8; 
			break;
			
		case PCT_SHORT:
			bits = 16; 
			break;
			
		case PCT_FLOAT16:
			bits = 16; 
			break;
			
		case PCT_FLOAT32:
			bits = 32; 
			break;
			
		default: 
			break;
		}
		
		int renderAttrib = GLX_RENDER_TYPE;
		int renderValue  = GLX_RGBA_BIT;
		
		if (mFormat == PCT_FLOAT16 || mFormat == PCT_FLOAT32)
		{
			if (GLXEW_NV_float_buffer)
			{
				renderAttrib = GLX_FLOAT_COMPONENTS_NV;
				renderValue  = GL_TRUE;
			}
			
			if (GLXEW_ATI_pixel_format_float)
			{
				renderAttrib = GLX_RENDER_TYPE;
				renderValue  = GLX_RGBA_FLOAT_ATI_BIT;
			}
			
			if (GLXEW_ARB_fbconfig_float)
			{
				renderAttrib = GLX_RENDER_TYPE;
				renderValue  = GLX_RGBA_FLOAT_BIT;
			}
			
			if (renderAttrib == GLX_RENDER_TYPE && renderValue == GLX_RGBA_BIT)
			{
				OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "No support for Floating point PBuffers",  "GLRenderTexture::createPBuffer");
			}
		}
		
		int minAttribs[] = {
			GLX_DRAWABLE_TYPE, GLX_PBUFFER,
			renderAttrib,	  renderValue,
			GLX_DOUBLEBUFFER,  0,
			None
		};
		
		int maxAttribs[] = {
			GLX_RED_SIZE,	  bits,
			GLX_GREEN_SIZE,	bits,
			GLX_BLUE_SIZE,	 bits,
			GLX_ALPHA_SIZE,	bits,
			GLX_STENCIL_SIZE,  INT_MAX,
			None
		};
		
		int pBufferAttribs[] = {
			GLX_PBUFFER_WIDTH,	  mWidth,
			GLX_PBUFFER_HEIGHT,	 mHeight,
			GLX_PRESERVED_CONTENTS, GL_TRUE,
			None
		};
		
		fbConfig = mGLSupport->selectFBConfig(minAttribs, maxAttribs);
		
		glxDrawable = glXCreatePbuffer(glDisplay, fbConfig, pBufferAttribs);
		
		if (! fbConfig || ! glxDrawable) 
		{
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to create Pbuffer", "GLXPBuffer::GLXPBuffer");
		}
		
		GLint fbConfigID;
		GLuint iWidth, iHeight;
		
		glXGetFBConfigAttrib(glDisplay, fbConfig, GLX_FBCONFIG_ID, &fbConfigID);
		glXQueryDrawable(glDisplay, glxDrawable, GLX_WIDTH, &iWidth);
		glXQueryDrawable(glDisplay, glxDrawable, GLX_HEIGHT, &iHeight);
		
		mWidth = iWidth;  
		mHeight = iHeight;
		LogManager::getSingleton().logMessage(LML_NORMAL, "GLXPBuffer::create used final dimensions " + StringConverter::toString(mWidth) + " x " + StringConverter::toString(mHeight));
		LogManager::getSingleton().logMessage("GLXPBuffer::create used FBConfigID " + StringConverter::toString(fbConfigID));
		
		mContext = new GLXContext(mGLSupport, fbConfig, glxDrawable);
	}
bool               P3DGLMemoryContextPBuffer::Create
                                      (unsigned int        Width,
                                       unsigned int        Height,
                                       bool                NeedAlpha)
 {
  bool                                 Result;
  GLXFBConfig                         *FBConfigList;
  int                                  FBConfigCount;

  Result = true;

  if (Connection == NULL)
   {
    OwnConnection = true;
    Connection = XOpenDisplay(NULL);

    if (Connection == NULL)
     {
      return(false);
     }
   }
  else
   {
    OwnConnection = false;
   }

  Result = true;

  FBConfigList = glXChooseFBConfig( Connection,
                                    DefaultScreen(Connection),
                                    NeedAlpha ? FBAttrsAlphaArray : FBAttrsArray,
                                   &FBConfigCount);


  if (FBConfigList != NULL)
   {
    int            AttrList[8];

    AttrList[0] = GLX_PBUFFER_WIDTH;      AttrList[1] = Width;
    AttrList[2] = GLX_PBUFFER_HEIGHT;     AttrList[3] = Height;
    AttrList[4] = GLX_PRESERVED_CONTENTS; AttrList[5] = True;
    AttrList[6] = None; AttrList[7] = None;

    PBuffer = glXCreatePbuffer(Connection,FBConfigList[0],AttrList);

    /*FIXME: check for errors here */

    OffScreenGLXContext = glXCreateNewContext(Connection,FBConfigList[0],GLX_RGBA_TYPE,NULL,True);

    if (OffScreenGLXContext != NULL)
     {
      Ok = true;

      Result = MakeCurrent();

      if (Result)
       {
        Result = P3DGLExtInit();
       }

      Ok = Result;
     }
    else
     {
      Result = false;
     }

    if (!Result)
     {
      glXDestroyPbuffer(Connection,PBuffer);
     }

    XFree(FBConfigList);
   }
  else
   {
    Result = false;
   }

  if (!Result)
   {
    if (OwnConnection)
     {
      XCloseDisplay(Connection);
     }

    Connection = NULL;
   }

  Ok = Result;

  return(Result);
 }
bool WindowlessGlxApplication::tryCreateContext(const Configuration&) {
    CORRADE_ASSERT(!c, "Platform::WindowlessGlxApplication::tryCreateContext(): context already created", false);

    display = XOpenDisplay(nullptr);

    /* Check version */
    int major, minor;
    glXQueryVersion(display, &major, &minor);
    if(major == 1 && minor < 4) {
        Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): GLX version 1.4 or greater is required";
        return false;
    }

    /* Choose config */
    int configCount = 0;
    static const int fbAttributes[] = { None };
    GLXFBConfig* configs = glXChooseFBConfig(display, DefaultScreen(display), fbAttributes, &configCount);
    if(!configCount) {
        Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): no supported framebuffer configuration found";
        return false;
    }

    GLint contextAttributes[] = {
#ifdef MAGNUM_TARGET_GLES
#ifdef MAGNUM_TARGET_GLES3
        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
#elif defined(MAGNUM_TARGET_GLES2)
        GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
#else
#error Unsupported OpenGL ES version
#endif
        GLX_CONTEXT_MINOR_VERSION_ARB, 0,
        GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
#endif
        0
    };

    /** @todo Use some extension wrangler for this, not GLEW, as it apparently needs context to create context, yo dawg wtf. */
    PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
    context = glXCreateContextAttribsARB(display, configs[0], nullptr, True, contextAttributes);
    if(!context) {
        Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot create context";
        return false;
    }

    /* Create pbuffer */
    int pbufferAttributes[] = {
        GLX_PBUFFER_WIDTH,  32,
        GLX_PBUFFER_HEIGHT, 32,
        None
    };
    pbuffer = glXCreatePbuffer(display, configs[0], pbufferAttributes);

    XFree(configs);

    /* Set OpenGL context as current */
    if(!glXMakeContextCurrent(display, pbuffer, pbuffer, context)) {
        Error() << "Platform::WindowlessGlxApplication::tryCreateContext(): cannot make context current";
        return false;
    }

    c = new Context;
    return true;
}
WindowLessGLContext::WindowLessGLContext(int width, int height)
    : _width(width), _height(height) {
  typedef GLXContext (*glXCreateContextAttribsARBProc)(
      Display *, GLXFBConfig, GLXContext, Bool, const int *);
  typedef Bool (*glXMakeContextCurrentARBProc)(Display *, GLXDrawable,
                                               GLXDrawable, GLXContext);
  static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
  static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = 0;

  static int visual_attribs[] = { None };
  int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
                            GLX_CONTEXT_MINOR_VERSION_ARB, 2,
                            None };

  int fbcount = 0;
  GLXFBConfig *fbc = NULL;

  /* open display */
  if (!(dpy = XOpenDisplay(0)))
    throw std::runtime_error(std::string(
        "WindowLessGLContext::WindowLessGLContext: Failed to open display\n"));

  /* get framebuffer configs, any is usable (might want to add proper attribs)
   */
  if (!(fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), visual_attribs,
                                &fbcount)))
    throw std::runtime_error(std::string(
        "WindowLessGLContext::WindowLessGLContext: Failed to get FBConfig\n"));

  /* get the required extensions */
  glXCreateContextAttribsARB =
      (glXCreateContextAttribsARBProc)glXGetProcAddressARB(
          (const GLubyte *)"glXCreateContextAttribsARB");
  glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc)glXGetProcAddressARB(
      (const GLubyte *)"glXMakeContextCurrent");
  if (!(glXCreateContextAttribsARB && glXMakeContextCurrentARB)) {
    XFree(fbc);
    throw std::runtime_error(
        std::string("WindowLessGLContext::WindowLessGLContext: Missing support "
                    "for GLX_ARB_create_context\n"));
  }

  /* create a context using glXCreateContextAttribsARB */
  if (!(ctx = glXCreateContextAttribsARB(dpy, fbc[0], 0, True,
                                         context_attribs))) {
    XFree(fbc);
    throw std::runtime_error(
        std::string("WindowLessGLContext::WindowLessGLContext: Failed to "
                    "create opengl context\n"));
  }

  /* create temporary pbuffer */
  int pbuffer_attribs[] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT,
                            height,            None };
  pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs);

  XFree(fbc);
  XSync(dpy, False);

  makeActive();
}
void PBuffer::initialise()
{
    /// Smaller dimensions are not sane
    if(mWidth < 64)
        mWidth = 64;
    if(mHeight < 64)
        mHeight = 64;

    Display *dpy = GLEngine::getInstance().getDisplay();
	GLXContext context = GLEngine::getInstance().getSharedContext();
	int screen = DefaultScreen(dpy);
    
    /// Find out which extension to use for floating point
/// Possible floating point extensions, in order of preference
#define RTF_NONE 0
#define RTF_NV 1    /** GLX_NV_float_buffer */
#define RTF_ATI 2   /** GLX_ATI_pixel_format_float */
#define RTF_ARB 3   /** GLX_ARB_fbconfig_float */
    
    int floatBuffer = RTF_NONE;
    if(mIsFloat)
    {
        /// Query supported float buffer extensions
        /// Choose the best one
        std::stringstream ext;
        std::string instr;
		ext << glXQueryExtensionsString(dpy, screen) << " " << glXGetClientString(dpy, GLX_EXTENSIONS);
        while(ext >> instr)
        {
            if(instr == "GLX_NV_float_buffer" && floatBuffer<RTF_NV)
                floatBuffer = RTF_NV;
            if(instr == "GLX_ATI_pixel_format_float" && floatBuffer<RTF_ATI)
                floatBuffer = RTF_ATI;
            if(instr == "GLX_ARB_fbconfig_float" && floatBuffer<RTF_ARB)
                floatBuffer = RTF_ARB;
        }
        if(floatBuffer == RTF_NONE)
        {
            GPGPU_EXCEPT(ERR_RENDERSYSTEM, "Floating point rendertargets not supported on this hardware");
        }
    }
    
    /// Make the buffer
	int attribs[50];
	int attrib = 0;
    if (floatBuffer == RTF_ATI) {
	    attribs[attrib++] = GLX_RENDER_TYPE;
	    attribs[attrib++] = GLX_RGBA_FLOAT_ATI_BIT;
    } 
    else if (floatBuffer == RTF_ARB) 
    {
        attribs[attrib++] = GLX_RENDER_TYPE;
	    attribs[attrib++] = GLX_RGBA_FLOAT_BIT;
    }
    else
    {
    	attribs[attrib++] = GLX_RENDER_TYPE;
	    attribs[attrib++] = GLX_RGBA_BIT;
    }
	attribs[attrib++] = GLX_DRAWABLE_TYPE;
	attribs[attrib++] = GLX_PBUFFER_BIT;
	attribs[attrib++] = GLX_STENCIL_SIZE;
	attribs[attrib++] = 8;
	attribs[attrib++] = GLX_DEPTH_SIZE;
	attribs[attrib++] = 24;
	
    attribs[attrib++] = GLX_RED_SIZE;
    attribs[attrib++] = mBitDepth;
    attribs[attrib++] = GLX_GREEN_SIZE;
    attribs[attrib++] = mBitDepth;
    attribs[attrib++] = GLX_BLUE_SIZE;
    attribs[attrib++] = mBitDepth;
    attribs[attrib++] = GLX_ALPHA_SIZE;
    attribs[attrib++] = mBitDepth;
    if (floatBuffer == RTF_NV) {
		attribs[attrib++] = GLX_FLOAT_COMPONENTS_NV;
		attribs[attrib++] = 1;
	}
	attribs[attrib++] = None;

	GLXFBConfig * fbConfigs;
	int nConfigs;
	fbConfigs = glXChooseFBConfig(dpy, screen, attribs, &nConfigs);
	if (nConfigs == 0 || !fbConfigs)
		GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() creation error: Couldn't find a suitable pixel format");
    
    /// Determine the type of context to create
    int renderType = GLX_RGBA_TYPE;
    if(floatBuffer == RTF_ARB)
    {
        renderType = GLX_RGBA_FLOAT_TYPE;
    }
    
	/// Pick the first returned format that will return a pbuffer
	for (int i = 0; i < nConfigs; i++) {
        // Check colour format
        int redSize, greenSize, blueSize, alphaSize;
        glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_RED_SIZE, &redSize);
        glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_GREEN_SIZE, &greenSize);
        glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_BLUE_SIZE, &blueSize);
        glXGetFBConfigAttrib(dpy, fbConfigs[i], GLX_ALPHA_SIZE, &alphaSize);
        
        if(redSize == mBitDepth && greenSize == mBitDepth && 
                blueSize == mBitDepth && alphaSize == mBitDepth)
            {
                attrib = 0;
                attribs[attrib++] = GLX_PBUFFER_WIDTH;
                attribs[attrib++] = mWidth; // Get from texture?
                attribs[attrib++] = GLX_PBUFFER_HEIGHT;
                attribs[attrib++] = mHeight; // Get from texture?
                attribs[attrib++] = GLX_PRESERVED_CONTENTS;
                attribs[attrib++] = 1;
                attribs[attrib++] = None;
                mPBuffer =
                    glXCreatePbuffer(dpy, fbConfigs[i], attribs);
                if (mPBuffer) {
                    mContext =
                        glXCreateNewContext(dpy,
                                                    fbConfigs[i],
                                                    renderType,
                                                    context, True);
                    break;
                }
        }
	}
	if (!mPBuffer)
		GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() pbuffer creation error: No exact match found");
	if (!mContext) 
        GPGPU_EXCEPT(ERR_RENDERSYSTEM, "RenderTexture::Initialize() creation error:  glXCreateContext() failed");

    /// Read final size
    int _iWidth, _iHeight;
	glXQueryDrawable(dpy, mPBuffer, GLX_WIDTH,
						   (GLuint *) & _iWidth);
	glXQueryDrawable(dpy, mPBuffer, GLX_HEIGHT,
						   (GLuint *) & _iHeight);
	mWidth = _iWidth;
    mHeight = _iHeight;
}
DECLEXPORT(EGLSurface) eglCreatePbufferSurface(EGLDisplay hDisplay, EGLConfig config, EGLint const *paAttributes)
{
    Display *pDisplay = (Display *)hDisplay;
    enum { CPS_WIDTH = 0, CPS_HEIGHT, CPS_LARGEST, CPS_PRESERVED, CPS_TEX_FORMAT, CPS_TEX_TARGET, CPS_MIPMAP_TEX, CPS_END };
    int acIndices[CPS_END];
    int aAttributes[CPS_END * 2];
    int cIndex = 0;
    unsigned i;
    GLXPbuffer hPbuffer;

    if (!VALID_PTR(hDisplay))
    {
        setEGLError(EGL_NOT_INITIALIZED);
        return EGL_NO_SURFACE;
    }
    for (i = 0; i < RT_ELEMENTS(acIndices); ++i)
        acIndices[i] = -1;
    if (paAttributes != NULL)
        while (*paAttributes != EGL_NONE)
        {
            switch (*paAttributes)
            {
                case EGL_WIDTH:
                    setAttribute(&acIndices[CPS_WIDTH], &cIndex, aAttributes, GLX_PBUFFER_WIDTH, paAttributes[1]);
                    break;
                case EGL_HEIGHT:
                    setAttribute(&acIndices[CPS_HEIGHT], &cIndex, aAttributes, GLX_LARGEST_PBUFFER, paAttributes[1]);
                    break;
                case EGL_LARGEST_PBUFFER:
                    setAttribute(&acIndices[CPS_LARGEST], &cIndex, aAttributes, GLX_PBUFFER_HEIGHT, paAttributes[1]);
                    break;
                case EGL_BUFFER_PRESERVED:
                    setAttribute(&acIndices[CPS_PRESERVED], &cIndex, aAttributes, GLX_PRESERVED_CONTENTS, paAttributes[1]);
                    break;
                case EGL_TEXTURE_FORMAT:
                    setAttribute(&acIndices[CPS_TEX_FORMAT], &cIndex, aAttributes, GLX_TEXTURE_FORMAT_EXT, paAttributes[1]);
                    break;
                case EGL_TEXTURE_TARGET:
                    setAttribute(&acIndices[CPS_TEX_TARGET], &cIndex, aAttributes, GLX_TEXTURE_TARGET_EXT, paAttributes[1]);
                    break;
                case EGL_MIPMAP_TEXTURE:
                    setAttribute(&acIndices[CPS_MIPMAP_TEX], &cIndex, aAttributes, GLX_MIPMAP_TEXTURE_EXT, paAttributes[1]);
                    break;
                case EGL_VG_ALPHA_FORMAT:
                case EGL_VG_COLORSPACE:
                {
                    setEGLError(EGL_BAD_MATCH);
                    return EGL_NO_SURFACE;
                }
            }
            paAttributes += 2;
        }
    EGL_ASSERT((unsigned)cIndex < RT_ELEMENTS(aAttributes) - 1U);
    aAttributes[cIndex + 1] = None;
    hPbuffer = glXCreatePbuffer(pDisplay, (GLXFBConfig)config, aAttributes);
    if (hPbuffer == None)
    {
        setEGLError(EGL_BAD_ALLOC);
        return EGL_NO_SURFACE;
    }
    EGL_ASSERT(hPbuffer < VBEGL_WINDOW_SURFACE);  /* Greater than the maximum XID. */
    clearEGLError();
    return (EGLSurface)(hPbuffer | VBEGL_PBUFFER_SURFACE);
}
Exemple #30
0
bool OglContext::initWindow()
{
  const char* const display_name = getenv("DISPLAY");
  if (!display_name) {
    msSetError(MS_OGLERR, "DISPLAY environment variable not set", "OglContext::init()");
    return false;
  }

  window = XOpenDisplay(display_name);
  if (!window) {
    msSetError(MS_OGLERR, "XOpenDisplay() failed.", "OglContext::init()");
    return false;
  }

  const int fb_attributes[] = {
    GLX_RENDER_TYPE, GLX_RGBA_BIT,
    GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
    GLX_RED_SIZE, 8,
    GLX_GREEN_SIZE, 8,
    GLX_BLUE_SIZE, 8,
    GLX_ALPHA_SIZE, 8,
    GLX_DEPTH_SIZE, 16,
    GLX_DOUBLEBUFFER, 0,
    GLX_SAMPLE_BUFFERS_ARB, 1,
    0
  };

  int num_configs = 0;
  GLXFBConfig* tempConfigs = glXChooseFBConfig(window, DefaultScreen(window), fb_attributes, &num_configs);

  if (tempConfigs == NULL || num_configs == 0) {
    msSetError(MS_OGLERR, "glXChooseFBConfig could not find any configs. Likely your video card or drivers are not supported.", "OglContext::initWindow()");
    return false;
  }

  GLXContext tempContext = glXCreateNewContext(window, *tempConfigs, GLX_RGBA_TYPE, NULL, 1);
  if (tempContext == NULL) {
    msSetError(MS_OGLERR, "glXCreateNewContext failed.", "OglContext::initWindow()");
    return false;
  }

  int iPbufferAttributes[] =    {0, 0};

  GLXPbuffer tempBuffer = glXCreatePbuffer(window, *tempConfigs, iPbufferAttributes);
  if (tempBuffer == 0) {
    msSetError(MS_OGLERR, "glXCreatePbuffer failed.", "OglContext::initWindow()");
    return false;
  }

  if (!glXMakeCurrent(window, tempBuffer, tempContext)) {
    msSetError(MS_OGLERR, "glXMakeCurrent failed.", "OglContext::initWindow()");
    return false;
  }

  glGetIntegerv(GL_MAX_SAMPLES_EXT, (GLint*)&MAX_MULTISAMPLE_SAMPLES);
  glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint*) &MAX_ANISOTROPY);
  glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&MAX_TEXTURE_SIZE);

  MIN_TEXTURE_SIZE = 8;

  return true;
}