TEST_F(glXCreateContextAttribARB_test, sent_correct_share_list)
{
    GLXContext share =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, share);

    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, share,
                               False, NULL);

    struct glx_context *glx_ctx = (struct glx_context *) share;
    EXPECT_EQ(glx_ctx->xid, req.share_list);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_indirect_screen_and_direct_set_to_false)
{
    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_FALSE(req.is_direct);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_fbconfig)
{
    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_EQ(0xbeefcafe, req.fbconfig);
}
/*@{*/
TEST_F(glXCreateContextAttribARB_test, does_send_protocol)
{
    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_TRUE(CreateContextAttribsARB_was_sent);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_context)
{
    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_EQ(99u, req.context);
}
static bool try_render_type(int type)
{
	const int attribs[] = {
		GLX_RENDER_TYPE, type,
		None
	};
	GLXContext ctx;
	bool pass = true;

	ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs);
	XSync(dpy, 0);

	if (ctx != NULL) {
		fprintf(stderr,
			"Created OpenGL context with invalid render-type "
			"0x%08x, but this should have failed.\n",
			type);
		glXDestroyContext(dpy, ctx);
		pass = false;
	}

	/* The GLX_ARB_create_context spec says:
	 *
	 *     "* If attribute GLX_RENDER_TYPE does not describe a valid
	 *        rendering type, BadValue is generated."
	 */
	if (!validate_glx_error_code(BadValue, -1)) {
		if (ctx == NULL)
			fprintf(stderr, "Render type = 0x%08x\n", type);

		pass = false;
	}

	return pass;
}
示例#7
0
文件: x11.c 项目: madokama/mpv
static bool create_context_x11_gl3(struct MPGLContext *ctx, int vo_flags,
                                   int gl_version, bool es)
{
    struct glx_context *glx_ctx = ctx->priv;
    struct vo *vo = ctx->vo;

    if (glx_ctx->context)
        return true;

    glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
        (glXCreateContextAttribsARBProc)
            glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");

    const char *glxstr =
        glXQueryExtensionsString(vo->x11->display, vo->x11->screen);
    bool have_ctx_ext = glxstr && !!strstr(glxstr, "GLX_ARB_create_context");

    if (!(have_ctx_ext && glXCreateContextAttribsARB)) {
        return false;
    }

    int ctx_flags = vo_flags & VOFLAG_GL_DEBUG ? GLX_CONTEXT_DEBUG_BIT_ARB : 0;
    int profile_mask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;

    if (es) {
        profile_mask = GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
        if (!(glxstr && strstr(glxstr, "GLX_EXT_create_context_es2_profile")))
            return false;
    }

    int context_attribs[] = {
        GLX_CONTEXT_MAJOR_VERSION_ARB, MPGL_VER_GET_MAJOR(gl_version),
        GLX_CONTEXT_MINOR_VERSION_ARB, MPGL_VER_GET_MINOR(gl_version),
        GLX_CONTEXT_PROFILE_MASK_ARB, profile_mask,
        GLX_CONTEXT_FLAGS_ARB, ctx_flags,
        None
    };
    vo_x11_silence_xlib(1);
    GLXContext context = glXCreateContextAttribsARB(vo->x11->display,
                                                    glx_ctx->fbc, 0, True,
                                                    context_attribs);
    vo_x11_silence_xlib(-1);
    if (!context) {
        MP_VERBOSE(vo, "Could not create GL3 context. Retrying with legacy context.\n");
        return false;
    }

    // set context
    if (!glXMakeCurrent(vo->x11->display, vo->x11->window, context)) {
        MP_FATAL(vo, "Could not set GLX context!\n");
        glXDestroyContext(vo->x11->display, context);
        return false;
    }

    glx_ctx->context = context;

    mpgl_load_functions(ctx->gl, (void *)glXGetProcAddressARB, glxstr, vo->log);

    return true;
}
示例#8
0
Context *
createContext(const Visual *_visual, Context *shareContext, Profile profile)
{
    const GlxVisual *visual = static_cast<const GlxVisual *>(_visual);
    GLXContext share_context = NULL;
    GLXContext context;

    if (profile != PROFILE_COMPAT) {
        return NULL;
    }

    if (shareContext) {
        share_context = static_cast<GlxContext*>(shareContext)->context;
    }

    if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) {
        Attributes<int> attribs;
        attribs.add(GLX_RENDER_TYPE, GLX_RGBA_TYPE);
        if (debug) {
            attribs.add(GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB);
        }
        attribs.end();

        context = glXCreateContextAttribsARB(display, visual->fbconfig, share_context, True, attribs);
    } else 
           if (glxVersion >= 0x103) {
        context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True);
    } else {
        context = glXCreateContext(display, visual->visinfo, share_context, True);
    }

    return new GlxContext(visual, profile, context);
}
GLXContext createContext(Display* display, GLXFBConfig bestFbc) {
    // NOTE: It is not necessary to create or make current to a context before
    // calling glXGetProcAddressARB
    glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
    glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
        glXGetProcAddressARB((const GLubyte *) "glXCreateContextAttribsARB");

    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
    };
    printf("Creating context\n");
    GLXContext context = 0;
    context = glXCreateContextAttribsARB(display, bestFbc, 0,
              true, context_attribs);
    // Sync to ensure any errors generated are processed.
    XSync(display, false);
    if (context) printf("Created GL 3.0 context\n");
    else         fail("Failed to create GL 3.0 context\n");
    // Sync to ensure any errors generated are processed.
    XSync(display, false);

    if (! glXIsDirect(display, context))
        printf("Indirect GLX rendering context obtained\n");
    else
        printf("Direct GLX rendering context obtained\n");
    return context;
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_num_attribs_NULL_list_pointer)
{
    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_EQ(0u, req.num_attribs);
}
TEST_F(glXCreateContextAttribARB_test, NULL_fbconfig_returns_None)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, NULL, 0, False, NULL);

    EXPECT_EQ(None, ctx);
    EXPECT_EQ(0, fake_glx_context::contexts_allocated);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_direct_screen_and_direct_set_to_true)
{
    this->use_direct_rendering_screen();

    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               True, NULL);

    EXPECT_TRUE(req.is_direct);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_share_xid)
{
    GLXContext first =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, first);

    GLXContext second =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, first,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, second);

    struct glx_context *share = (struct glx_context *) first;
    struct glx_context *ctx = (struct glx_context *) second;
    EXPECT_EQ(share->xid, ctx->share_xid);
}
/*@{*/
TEST_F(glXCreateContextAttribARB_test, NULL_display_returns_None)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(NULL, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    EXPECT_EQ(None, ctx);
    EXPECT_EQ(0, fake_glx_context::contexts_allocated);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_screen)
{
    this->fbc.screen = 7;
    psc->scr = 7;

    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, NULL);

    EXPECT_EQ(7u, req.screen);
}
示例#16
0
文件: gl_x11.c 项目: Bilalh/mpv
static bool create_context_x11_gl3(struct MPGLContext *ctx, bool debug)
{
    struct glx_context *glx_ctx = ctx->priv;
    struct vo *vo = ctx->vo;

    if (glx_ctx->context)
        return true;

    glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
        (glXCreateContextAttribsARBProc)
            glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");

    const char *glxstr = "";
    const char *(*glXExtStr)(Display *, int)
        = mp_getdladdr("glXQueryExtensionsString");
    if (glXExtStr)
        glxstr = glXExtStr(vo->x11->display, vo->x11->screen);
    bool have_ctx_ext = glxstr && !!strstr(glxstr, "GLX_ARB_create_context");

    if (!(have_ctx_ext && glXCreateContextAttribsARB)) {
        return false;
    }

    int gl_version = ctx->requested_gl_version;
    int context_attribs[] = {
        GLX_CONTEXT_MAJOR_VERSION_ARB, MPGL_VER_GET_MAJOR(gl_version),
        GLX_CONTEXT_MINOR_VERSION_ARB, MPGL_VER_GET_MINOR(gl_version),
        GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
        GLX_CONTEXT_FLAGS_ARB, debug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
        None
    };
    GLXContext context = glXCreateContextAttribsARB(vo->x11->display,
                                                    glx_ctx->fbc, 0, True,
                                                    context_attribs);
    if (!context) {
        MP_ERR(vo, "Could not create GL3 context. Retrying with legacy context.\n");
        return false;
    }

    // set context
    if (!glXMakeCurrent(vo->x11->display, vo->x11->window, context)) {
        MP_FATAL(vo, "Could not set GLX context!\n");
        glXDestroyContext(vo->x11->display, context);
        return false;
    }

    glx_ctx->context = context;

    mpgl_load_functions(ctx->gl, (void *)glXGetProcAddress, glxstr, vo->log);

    if (!glXIsDirect(vo->x11->display, context))
        ctx->gl->mpgl_caps &= ~MPGL_CAP_NO_SW;

    return true;
}
示例#17
0
文件: egl_x11.c 项目: angevad/EGL
EGLBoolean __createContext(NativeContextContainer* nativeContextContainer, const EGLDisplayImpl* walkerDpy, const NativeSurfaceContainer* nativeSurfaceContainer, const NativeContextContainer* sharedNativeContextContainer, const EGLint* attribList)
{
	if (!nativeContextContainer || !walkerDpy || !nativeSurfaceContainer)
	{
		return EGL_FALSE;
	}

	nativeContextContainer->ctx = glXCreateContextAttribsARB(walkerDpy->display_id, nativeSurfaceContainer->config, sharedNativeContextContainer ? sharedNativeContextContainer->ctx : 0, True, attribList);

	return nativeContextContainer->ctx != 0;
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_num_attribs_empty_list)
{
    static const int attribs[] = {
        0,
    };

    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, attribs);

    EXPECT_EQ(0u, req.num_attribs);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_screen_pointer)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, ctx);

    struct glx_context *gc = (struct glx_context *) ctx;

    EXPECT_EQ(psc, gc->psc);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_indirect_screen_and_direct_set_to_false)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, ctx);

    struct glx_context *gc = (struct glx_context *) ctx;

    EXPECT_FALSE(gc->isDirect);
}
TEST_F(glXCreateContextAttribARB_test, NULL_screen_returns_None)
{
    delete psc;
    psc = NULL;

    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    EXPECT_EQ(None, ctx);
    EXPECT_EQ(0, fake_glx_context::contexts_allocated);
}
TEST_F(glXCreateContextAttribARB_test, correct_indirect_context_client_state_private)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, ctx);

    struct glx_context *gc = (struct glx_context *) ctx;

    ASSERT_FALSE(gc->isDirect);
    EXPECT_EQ((struct __GLXattributeRec *) 0xcafebabe,
              gc->client_state_private);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_direct_screen_and_direct_set_to_true)
{
    this->use_direct_rendering_screen();

    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   True, NULL);

    ASSERT_NE((GLXContext) 0, ctx);

    struct glx_context *gc = (struct glx_context *) ctx;

    EXPECT_TRUE(gc->isDirect);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_xid)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    /* Since the server did not return an error, the GLXContext should not be
     * NULL.
     */
    ASSERT_NE((GLXContext)0, ctx);

    struct glx_context *glx_ctx = (struct glx_context *) ctx;
    EXPECT_EQ(99u, glx_ctx->xid);
}
TEST_F(glXCreateContextAttribARB_test, correct_context_screen_number)
{
    this->fbc.screen = 7;
    psc->scr = 7;

    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    ASSERT_NE((GLXContext) 0, ctx);

    struct glx_context *gc = (struct glx_context *) ctx;

    EXPECT_EQ(7, gc->screen);
}
/*@{*/
TEST_F(glXCreateContextAttribARB_test, correct_context)
{
    GLXContext ctx =
        glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                                   False, NULL);

    /* Since the server did not return an error, the GLXContext should not be
     * NULL.
     */
    EXPECT_NE((GLXContext)0, ctx);

    /* It shouldn't be the XID of the context either.
     */
    EXPECT_NE((GLXContext)99, ctx);
}
示例#27
0
	void EnableDrawing( XVisualInfo** vi, GLXContext* ctx )
	{
		// -- Check the GLX version, 1.3+ added FBConfigs
		if ( ( x11::glx[0] == 1 && x11::glx[1] < 3 ) || ( x11::glx[0] < 1 ) )
		{
			// -- Give us a GL context
            if ( (*ctx = glXCreateContext( x11::disp, *vi, NULL, True)) == 0 )
            {
                printf( "GL3 Failed to get Legacy context\n" );
                exit( EXIT_FAILURE );
            }
		}
		else
        {
			printf( "EnableDrawing() :: GLX 1.3+ Context Creation\n" );

            if ( !glXCreateContextAttribsARB )
            {
                printf( "glXCreateContextAttribsARB() not found ... using old-style GLX context\n" );
                *ctx = glXCreateNewContext( x11::disp, x11::fbconfig, GLX_RGBA_TYPE, 0, True );
            }
            else
            {
                int context_attribs[] =
                {
                    GLX_CONTEXT_MAJOR_VERSION_ARB,	3,
                    GLX_CONTEXT_MINOR_VERSION_ARB,	0,
                    GLX_CONTEXT_PROFILE_MASK_ARB,	GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
					#if defined( _DEBUG ) || defined( DEBUG ) || defined( ENIGMA_DEBUG )
					GLX_CONTEXT_FLAGS_ARB,			GLX_CONTEXT_DEBUG_BIT_ARB,
					#endif
                    None
                };

                if ( (*ctx = glXCreateContextAttribsARB( x11::disp, x11::fbconfig, 0, True, context_attribs )) == 0 )
				{
					printf( "GL3 Failed to get Core context\n" );
					exit( EXIT_FAILURE );
				}
            }
        }

		// -- Make the context current to this thread
		glXMakeCurrent( x11::disp, x11::win, *ctx );

        // -- Clear the back buffers
        glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT );
	}
示例#28
0
void		X11Win::init(void) {
	XSetWindowAttributes				swa;
	XVisualInfo							*vi;

	glXCreateContextAttribsARBProc	glXCreateContextAttribsARB;
	static 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
	};

	assignBestFBC();
	vi = glXGetVisualFromFBConfig(_d, _fbc);
	swa.colormap = _cmap = XCreateColormap(_d,
												RootWindow(_d, vi->screen),
												vi->visual, AllocNone);
	swa.background_pixmap = None;
	swa.border_pixel = 0;
	swa.event_mask = ExposureMask|KeyPressMask|ButtonPressMask|StructureNotifyMask;
	/*Window XCreateWindow(
	_d, parent, x, y, width, height, border_width, depth,
		class, visual, valuemask, attributes)*/
	_w = XCreateWindow(_d,
							RootWindow(_d, vi->screen)
							, 0
							, 0
							, _width
							, _height
							, 0
							, vi->depth
							, InputOutput
							, vi->visual
							, CWBackPixel|CWBackPixmap|CWBorderPixel|CWColormap|CWEventMask
							, &swa);
	_glxWin = glXCreateWindow(_d, _fbc, _w, NULL);
	XStoreName(_d, _w, "GL Window");
	XMapWindow(_d, _w);

	glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB(
		(const GLubyte *)"glXCreateContextAttribsARB");
	_ctx = glXCreateContextAttribsARB(_d, _fbc, 0, True, context_attribs);
	XFree(vi);

	XSync(_d, True);
	glXMakeCurrent(_d, _glxWin, _ctx);
	glClearColor(0, 0.5, 1, 1);
}
TEST_F(glXCreateContextAttribARB_test, sent_correct_attrib_list)
{
    int attribs[] = {
        GLX_RENDER_TYPE, GLX_RGBA_TYPE,
        GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
        GLX_CONTEXT_MINOR_VERSION_ARB, 2,
        0
    };

    glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
                               False, attribs);

    for (unsigned i = 0; i < 6; i++) {
        EXPECT_EQ((uint32_t) attribs[i], sent_attribs[i]);
    }
}
示例#30
0
struct ephyr_glamor *
ephyr_glamor_glx_screen_init(xcb_window_t win)
{
    GLXContext ctx;
    struct ephyr_glamor *glamor;
    GLXWindow glx_win;

    glamor = calloc(1, sizeof(struct ephyr_glamor));
    if (!glamor) {
        FatalError("malloc");
        return NULL;
    }

    glx_win = glXCreateWindow(dpy, fb_config, win, NULL);

    if (ephyr_glamor_gles2) {
        static const int context_attribs[] = {
            GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
            GLX_CONTEXT_MINOR_VERSION_ARB, 0,
            GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES_PROFILE_BIT_EXT,
            0,
        };
        if (epoxy_has_glx_extension(dpy, DefaultScreen(dpy),
                                    "GLX_EXT_create_context_es2_profile")) {
            ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, True,
                                             context_attribs);
        } else {
            FatalError("Xephyr -glamor_gles2 rquires "
                       "GLX_EXT_create_context_es2_profile\n");
        }
    } else {
        ctx = glXCreateContext(dpy, visual_info, NULL, True);
    }
    if (ctx == NULL)
        FatalError("glXCreateContext failed\n");

    if (!glXMakeCurrent(dpy, glx_win, ctx))
        FatalError("glXMakeCurrent failed\n");

    glamor->ctx = ctx;
    glamor->win = win;
    glamor->glx_win = glx_win;
    ephyr_glamor_setup_texturing_shader(glamor);

    return glamor;
}