glx bits.

SVN revision: 30928
This commit is contained in:
Kim Woelders 2007-07-21 20:28:40 +00:00
parent aaa7ffa563
commit c3707a6d71
4 changed files with 97 additions and 63 deletions

View File

@ -1228,6 +1228,9 @@ ECompMgrWinInvalidate(EObj * eo, int what)
cw->pixmap = None;
if (Mode_compmgr.use_pixmap)
what |= INV_PICTURE;
#if USE_GLX
EobjTextureInvalidate(eo);
#endif
}
if (what & (INV_SIZE | INV_SHAPE))

View File

@ -318,7 +318,8 @@ EGlWindowConnect(Window xwin)
return;
/* First time */
glEnable(GL_TEXTURE_2D); /* ??? */
glEnable(TEXTURE_TARGET);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
@ -352,10 +353,10 @@ EGlTextureFromImage(EImage * im, int mode)
if (!et)
return NULL;
et->type = ETEX_TYPE_IMAGE;
et->target = TEXTURE_TARGET;
glGenTextures(1, &et->texture);
glBindTexture(et->target, et->texture);
et->type = ETEX_TYPE_IMAGE;
EImageGetSize(im, &w, &h);
data = EImageGetData(im);
@ -407,11 +408,27 @@ GetGlPixmap(Window xwin, Drawable draw)
return glxpixmap;
}
static void
_EGlTextureFromDrawable(ETexture * et, Drawable draw, int mode)
{
if (!et || draw == None)
return;
glBindTexture(et->target, et->texture);
et->glxpmap = GetGlPixmap(draw, (mode & 0x100) ? None : draw);
if (et->glxpmap == None)
return;
_glXBindTexImageEXT(disp, et->glxpmap, GLX_FRONT_LEFT_EXT, NULL);
#if 0 /* No! */
glXDestroyPixmap(disp, et->glxpmap);
#endif
}
ETexture *
EGlTextureFromDrawable(Drawable draw, int mode)
{
ETexture *et;
GLXPixmap glxpixmap;
if (draw == None)
return NULL;
@ -420,41 +437,12 @@ EGlTextureFromDrawable(Drawable draw, int mode)
if (!et)
return NULL;
et->type = ETEX_TYPE_PIXMAP;
et->target = TEXTURE_TARGET;
glGenTextures(1, &et->texture);
glEnable(et->target); /* Why ??? */
glBindTexture(et->target, et->texture);
et->type = ETEX_TYPE_PIXMAP;
glxpixmap = GetGlPixmap(draw, (mode & 0x100) ? None : draw);
if (glxpixmap == None)
return NULL;
et->glxpmap = glxpixmap;
#if 0
unsigned int trg;
glXQueryDrawable(disp, et->glxpmap, GLX_TEXTURE_TARGET_EXT, &trg);
Dprintf("TARGET: %#x\n", trg);
#endif
switch (mode & 0xff)
{
case 0:
_glXBindTexImageEXT(disp, glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
glTexParameteri(et->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(et->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case 1:
_glXBindTexImageEXT(disp, glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
glTexParameteri(et->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(et->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
break;
}
#if 0 /* No! */
glXDestroyPixmap(disp, glxpixmap);
#endif
glBindTexture(et->target, 0);
_EGlTextureFromDrawable(et, draw, mode);
return et;
}
@ -468,8 +456,19 @@ EGlTextureDestroy(ETexture * et)
Dprintf("EGlTextureDestroy %d type=%u pmap=%#x\n", et->texture, et->type,
et->glxpmap);
glEnable(et->target); /* Why ??? */
glBindTexture(et->target, et->texture);
EGlTextureInvalidate(et);
glDeleteTextures(1, &et->texture);
Efree(et);
}
void
EGlTextureInvalidate(ETexture * et)
{
if (!et)
return;
Dprintf("EGlTextureInvalidate %d type=%u pmap=%#x\n", et->texture, et->type,
et->glxpmap);
switch (et->type)
{
@ -479,16 +478,10 @@ EGlTextureDestroy(ETexture * et)
if (!et->glxpmap)
break;
_glXReleaseTexImageEXT(disp, et->glxpmap, GLX_FRONT_LEFT_EXT);
glBindTexture(et->target, 0);
glDisable(et->target);
glXDestroyPixmap(disp, et->glxpmap);
et->glxpmap = None;
break;
}
glBindTexture(et->target, 0);
glDeleteTextures(1, &et->texture);
Efree(et);
}
#include "eobj.h"
@ -507,10 +500,22 @@ EobjTexturesFree(void)
ETexture *
EobjGetTexture(EObj * eo)
{
Pixmap pmap;
if (eo->glhook)
return eo->glhook;
{
if (eo->glhook->glxpmap)
return eo->glhook;
_EGlTextureFromDrawable(eo->glhook, EobjGetPixmap(eo), 0);
return eo->glhook;
}
return EobjTextureCreate(eo);
}
ETexture *
EobjTextureCreate(EObj * eo)
{
Pixmap pmap;
pmap = EobjGetPixmap(eo);
if (pmap == None)
@ -527,3 +532,9 @@ EobjTextureDestroy(EObj * eo)
EGlTextureDestroy(eo->glhook);
eo->glhook = NULL;
}
void
EobjTextureInvalidate(EObj * eo)
{
EGlTextureInvalidate(eo->glhook);
}

View File

@ -53,5 +53,6 @@ void EGlWindowDisconnect(void);
ETexture *EGlTextureFromImage(EImage * im, int mode);
ETexture *EGlTextureFromDrawable(Drawable draw, int mode);
void EGlTextureDestroy(ETexture * et);
void EGlTextureInvalidate(ETexture * et);
#endif /* _EGLX_H_ */

View File

@ -170,7 +170,7 @@ DrawBackground(ETexture * et, GLfloat w, GLfloat h)
if (!et)
return;
glBindTexture(GL_TEXTURE_2D, et->texture);
glBindTexture(et->target, et->texture);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
@ -194,7 +194,7 @@ DrawQube(ETexture * et, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h,
if (!et)
return;
glBindTexture(GL_TEXTURE_2D, et->texture);
glBindTexture(et->target, et->texture);
switch (filter)
{
@ -310,21 +310,17 @@ DrawQube(ETexture * et, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h,
}
static void
SceneDraw1(double t)
SceneDraw1(double t, EWin ** ewins, int num)
{
unsigned int i, j, nx, ny;
int i, j, k, nx, ny;
GLfloat x, y, w, h, dx, dy, sz;
EWin *const *ewins;
EObj *eo;
int k, num;
w = EobjGetW(GLWin.eo);
h = EobjGetH(GLWin.eo);
DrawBackground(texture[sel_bg], w, h);
ewins = EwinListGetAll(&num);
i = sqrt(w * h / (1.5 * num));
ny = h / i;
nx = num / ny;
@ -377,22 +373,18 @@ SceneDraw1(double t)
}
static void
SceneDraw2(double t)
SceneDraw2(double t, EWin ** ewins, int num)
{
static double t1;
int i;
GLfloat w, h, dx, dy, sz, dx1, dy1;
EWin *const *ewins;
EObj *eo;
int num;
w = EobjGetW(GLWin.eo);
h = EobjGetH(GLWin.eo);
DrawBackground(texture[sel_bg], w, h);
ewins = EwinListGetAll(&num);
for (i = 0; i < num; i++)
{
dx1 = (.5 + .3 * cos(t1 + t + (i + .5) * 2. * M_PI / num)) * w;
@ -413,30 +405,57 @@ SceneDraw2(double t)
}
}
static EWin **
GlwinEwins(int *pnum)
{
int i, j, num;
EWin *const *ewins;
EWin **lst;
ewins = EwinListGetAll(&num);
lst = EMALLOC(EWin *, num);
for (i = j = 0; i < num; i++)
{
if (!EoIsShown(ewins[i]))
continue;
lst[j++] = ewins[i];
}
*pnum = j;
return lst;
}
static void
SceneDraw(void)
{
double t;
EWin **ewins;
int num;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
t = GetDTime();
ewins = GlwinEwins(&num);
switch (Conf_glwin.mode)
{
default:
SceneDraw1(t);
SceneDraw1(t, ewins, num);
break;
case 1:
SceneDraw2(t);
SceneDraw2(t, ewins, num);
break;
}
glXSwapBuffers(disp, EobjGetXwin(GLWin.eo));
Efree(ewins);
rot_x += speed_x;
rot_y += speed_y;
glXSwapBuffers(disp, EobjGetXwin(GLWin.eo));
}
static int