GLX_EXT_texture_from_pixmap: Use client provided texture target when available.

This prevents situations where the server doesn't use the target the
client thinks it does, usually resulting in the texture being sampled as all
white.
This commit is contained in:
Michel Dänzer 2007-08-01 18:13:18 +02:00
parent a4197db950
commit 17cb4f64e3
5 changed files with 48 additions and 29 deletions

View File

@ -1260,13 +1260,15 @@ static int ValidateCreateDrawable(ClientPtr client,
** Create a GLX Pixmap from an X Pixmap.
*/
int DoCreateGLXPixmap(__GLXclientState *cl, XID fbconfigId,
GLuint screenNum, XID pixmapId, XID glxPixmapId)
GLuint screenNum, XID pixmapId, XID glxPixmapId,
CARD32 *attribs, CARD32 numAttribs)
{
ClientPtr client = cl->client;
DrawablePtr pDraw;
__GLXpixmap *pGlxPixmap;
__GLcontextModes *modes;
int retval;
GLenum target = 0;
int retval, i;
retval = ValidateCreateDrawable (client, screenNum, fbconfigId,
pixmapId, glxPixmapId,
@ -1292,6 +1294,30 @@ int DoCreateGLXPixmap(__GLXclientState *cl, XID fbconfigId,
pGlxPixmap->modes = modes;
for (i = 0; i < numAttribs; i++) {
if (attribs[2 * i] == GLX_TEXTURE_TARGET_EXT) {
switch (attribs[2 * i + 1]) {
case GLX_TEXTURE_2D_EXT:
target = GL_TEXTURE_2D;
break;
case GLX_TEXTURE_RECTANGLE_EXT:
target = GL_TEXTURE_RECTANGLE_ARB;
break;
}
}
}
if (!target) {
int w = pDraw->width, h = pDraw->height;
if (h & (h - 1) || w & (w - 1))
target = GL_TEXTURE_RECTANGLE_ARB;
else
target = GL_TEXTURE_2D;
}
pGlxPixmap->target = target;
/*
** Bump the ref count on the X pixmap so it won't disappear.
*/
@ -1304,14 +1330,16 @@ int __glXDisp_CreateGLXPixmap(__GLXclientState *cl, GLbyte *pc)
{
xGLXCreateGLXPixmapReq *req = (xGLXCreateGLXPixmapReq *) pc;
return DoCreateGLXPixmap( cl, req->visual, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap, NULL, 0 );
}
int __glXDisp_CreatePixmap(__GLXclientState *cl, GLbyte *pc)
{
xGLXCreatePixmapReq *req = (xGLXCreatePixmapReq *) pc;
return DoCreateGLXPixmap( cl, req->fbconfig, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap,
(CARD32*)(req + 1),
req->numAttribs );
}
int __glXDisp_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
@ -1319,7 +1347,7 @@ int __glXDisp_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
xGLXCreateGLXPixmapWithConfigSGIXReq *req =
(xGLXCreateGLXPixmapWithConfigSGIXReq *) pc;
return DoCreateGLXPixmap( cl, req->fbconfig, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap, NULL, 0 );
}
@ -1681,7 +1709,6 @@ DoGetDrawableAttributes(__GLXclientState *cl, XID drawId)
xGLXGetDrawableAttributesReply reply;
CARD32 attributes[4];
int numAttribs;
PixmapPtr pixmap;
glxPixmap = (__GLXpixmap *)LookupIDByType(drawId, __glXPixmapRes);
if (!glxPixmap) {
@ -1696,19 +1723,11 @@ DoGetDrawableAttributes(__GLXclientState *cl, XID drawId)
reply.numAttribs = numAttribs;
attributes[0] = GLX_TEXTURE_TARGET_EXT;
attributes[1] = glxPixmap->target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT :
GLX_TEXTURE_RECTANGLE_EXT;
attributes[2] = GLX_Y_INVERTED_EXT;
attributes[3] = GL_FALSE;
/* XXX this is merely less wrong, see fdo bug #8991 */
pixmap = (PixmapPtr) glxPixmap->pDraw;
if ((pixmap->drawable.width & (pixmap->drawable.width - 1)) ||
(pixmap->drawable.height & (pixmap->drawable.height - 1))
/* || strstr(CALL_GetString(GL_EXTENSIONS,
"GL_ARB_texture_non_power_of_two")) */)
attributes[1] = GLX_TEXTURE_RECTANGLE_EXT;
else
attributes[1] = GLX_TEXTURE_2D_EXT;
if (client->swapped) {
__glXSwapGetDrawableAttributesReply(client, &reply, attributes);
} else {

View File

@ -266,7 +266,7 @@ int __glXDispSwap_CreateGLXPixmap(__GLXclientState *cl, GLbyte *pc)
__GLX_SWAP_INT(&req->glxpixmap);
return DoCreateGLXPixmap( cl, req->visual, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap, NULL, 0 );
}
int __glXDispSwap_CreatePixmap(__GLXclientState *cl, GLbyte *pc)
@ -279,9 +279,12 @@ int __glXDispSwap_CreatePixmap(__GLXclientState *cl, GLbyte *pc)
__GLX_SWAP_INT(&req->fbconfig);
__GLX_SWAP_INT(&req->pixmap);
__GLX_SWAP_INT(&req->glxpixmap);
__GLX_SWAP_INT(&req->numAttribs);
return DoCreateGLXPixmap( cl, req->fbconfig, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap,
(CARD32*)(req + 1),
req->numAttribs );
}
int __glXDispSwap_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
@ -297,7 +300,7 @@ int __glXDispSwap_CreateGLXPixmapWithConfigSGIX(__GLXclientState *cl, GLbyte *pc
__GLX_SWAP_INT(&req->glxpixmap);
return DoCreateGLXPixmap( cl, req->fbconfig, req->screen,
req->pixmap, req->glxpixmap );
req->pixmap, req->glxpixmap, NULL, 0 );
}
int __glXDispSwap_DestroyGLXPixmap(__GLXclientState *cl, GLbyte *pc)

View File

@ -54,6 +54,7 @@ typedef struct {
ScreenPtr pScreen;
Bool idExists;
int refcnt;
GLenum target;
#ifdef XF86DRI
DamagePtr pDamage;
__DRIcontext *pDRICtx;

View File

@ -375,7 +375,7 @@ __glXDRIbindTexImage(__GLXcontext *baseContext,
RegionPtr pRegion = NULL;
PixmapPtr pixmap;
int w, h, bpp, override = 0;
GLenum target, format, type;
GLenum format, type;
ScreenPtr pScreen = glxPixmap->pScreen;
__GLXDRIscreen * const screen =
(__GLXDRIscreen *) __glXgetActiveScreen(pScreen->myNum);
@ -384,11 +384,6 @@ __glXDRIbindTexImage(__GLXcontext *baseContext,
w = pixmap->drawable.width;
h = pixmap->drawable.height;
if (h & (h - 1) || w & (w - 1))
target = GL_TEXTURE_RECTANGLE_ARB;
else
target = GL_TEXTURE_2D;
if (screen->texOffsetStart && screen->driScreen.setTexOffset) {
__GLXpixmap **texOffsetOverride = screen->texOffsetOverride;
int i, firstEmpty = 16, texname;
@ -416,7 +411,7 @@ alreadyin:
glxPixmap->pDRICtx = &((__GLXDRIcontext*)baseContext)->driContext;
CALL_GetIntegerv(GET_DISPATCH(), (target == GL_TEXTURE_2D ?
CALL_GetIntegerv(GET_DISPATCH(), (glxPixmap->target == GL_TEXTURE_2D ?
GL_TEXTURE_BINDING_2D :
GL_TEXTURE_BINDING_RECTANGLE_NV,
&texname));
@ -481,7 +476,7 @@ nooverride:
pixmap->drawable.y) );
CALL_TexImage2D( GET_DISPATCH(),
(target,
(glxPixmap->target,
0,
bpp == 4 ? 4 : 3,
pixmap->drawable.width,
@ -511,7 +506,7 @@ nooverride:
pixmap->drawable.y + p[i].y1) );
CALL_TexSubImage2D( GET_DISPATCH(),
(target,
(glxPixmap->target,
0,
p[i].x1, p[i].y1,
p[i].x2 - p[i].x1, p[i].y2 - p[i].y1,

View File

@ -80,7 +80,8 @@ extern int DoGetFBConfigs(__GLXclientState *cl, unsigned screen,
extern int DoCreateContext(__GLXclientState *cl, GLXContextID gcId,
GLXContextID shareList, VisualID visual, GLuint screen, GLboolean isDirect);
extern int DoCreateGLXPixmap(__GLXclientState *cl, XID fbconfigId,
GLuint screenNum, XID pixmapId, XID glxpixmapId);
GLuint screenNum, XID pixmapId, XID glxpixmapId, CARD32 *attribs,
CARD32 numAttribs);
extern int DoDestroyPixmap(__GLXclientState *cl, XID glxpixmapId);
extern int DoQueryContext(__GLXclientState *cl, GLXContextID gcId);