2007-03-29 13:54:55 -07:00
|
|
|
/*
|
2022-12-11 11:04:30 -08:00
|
|
|
* Copyright (C) 2007-2022 Kim Woelders
|
2007-03-29 13:54:55 -07:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-03-29 13:54:55 -07:00
|
|
|
#define GLX_GLXEXT_PROTOTYPES 1
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
|
|
|
#include <GL/glx.h>
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
|
2015-01-15 22:25:38 -08:00
|
|
|
#include "E.h"
|
|
|
|
#include "eglx.h"
|
|
|
|
#include "eimage.h"
|
|
|
|
#include "xwin.h"
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
#define ENABLE_DEBUG 1
|
|
|
|
#if ENABLE_DEBUG
|
|
|
|
#define Dprintf(fmt...) do { if(EDebug(EDBUG_TYPE_GLX))Eprintf(fmt); } while(0)
|
|
|
|
#define D2printf(fmt...) do { if(EDebug(EDBUG_TYPE_GLX)>1)Eprintf(fmt); } while(0)
|
|
|
|
#else
|
|
|
|
#define Dprintf(fmt...)
|
|
|
|
#define D2printf(fmt...)
|
|
|
|
#endif /* ENABLE_DEBUG */
|
|
|
|
|
|
|
|
#define ETEX_TYPE_IMAGE 1
|
|
|
|
#define ETEX_TYPE_PIXMAP 2
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
#define TEXTURE_TARGET GL_TEXTURE_2D
|
|
|
|
#else
|
|
|
|
#define TEXTURE_TARGET GLX_TEXTURE_RECTANGLE_EXT
|
|
|
|
#endif
|
|
|
|
|
2007-06-14 15:38:22 -07:00
|
|
|
#ifdef HAVE_GLX_glXBindTexImageEXT
|
|
|
|
|
|
|
|
#define _glXBindTexImageEXT glXBindTexImageEXT
|
|
|
|
#define _glXReleaseTexImageEXT glXReleaseTexImageEXT
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
/* GL functions and helper */
|
2019-08-14 09:45:13 -07:00
|
|
|
typedef void (*glXBindTexImageEXT_func)(Display * dpy,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer,
|
|
|
|
const int *attrib_list);
|
|
|
|
typedef void (*glXReleaseTexImageEXT_func)(Display * dpy,
|
|
|
|
GLXDrawable drawable,
|
|
|
|
int buffer);
|
|
|
|
typedef void (*glXFuncPtr)(void);
|
2007-06-14 15:38:22 -07:00
|
|
|
typedef glXFuncPtr(*glXGetProcAddress_func) (const GLubyte *);
|
|
|
|
|
|
|
|
static glXBindTexImageEXT_func _glXBindTexImageEXT;
|
|
|
|
static glXReleaseTexImageEXT_func _glXReleaseTexImageEXT;
|
|
|
|
static glXGetProcAddress_func glx_get_proc_address;
|
|
|
|
|
|
|
|
static glXFuncPtr
|
|
|
|
get_func_addr(const char *name)
|
|
|
|
{
|
|
|
|
glXFuncPtr ret = NULL;
|
|
|
|
|
|
|
|
if (glx_get_proc_address)
|
|
|
|
ret = glx_get_proc_address((const GLubyte *)name);
|
|
|
|
if (!ret)
|
|
|
|
ret = (glXFuncPtr) dlsym(RTLD_DEFAULT, name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
glx_funcs_init(void)
|
|
|
|
{
|
|
|
|
glx_get_proc_address = (glXGetProcAddress_func)
|
|
|
|
get_func_addr("glXGetProcAddress");
|
|
|
|
if (!glx_get_proc_address)
|
|
|
|
glx_get_proc_address = (glXGetProcAddress_func)
|
|
|
|
get_func_addr("glXGetProcAddressARB");
|
|
|
|
|
|
|
|
_glXBindTexImageEXT = (glXBindTexImageEXT_func)
|
|
|
|
get_func_addr("glXBindTexImageEXT");
|
|
|
|
|
|
|
|
_glXReleaseTexImageEXT = (glXReleaseTexImageEXT_func)
|
|
|
|
get_func_addr("glXReleaseTexImageEXT");
|
|
|
|
|
|
|
|
return !_glXBindTexImageEXT || !_glXReleaseTexImageEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_GLX_glXBindTexImageEXT */
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
static void EobjTexturesFree(void);
|
|
|
|
|
2008-03-23 04:54:24 -07:00
|
|
|
typedef struct {
|
2007-03-29 13:54:55 -07:00
|
|
|
XVisualInfo *vi;
|
|
|
|
GLXContext ctx;
|
|
|
|
GLXFBConfig fbc;
|
|
|
|
unsigned ctx_initialised:1;
|
|
|
|
} EGlContext;
|
|
|
|
|
|
|
|
static EGlContext egl;
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
#define FBCATTR(fbc, attr, want) _EGlFbcAttrib(fbc, #attr, attr, want)
|
|
|
|
static int
|
|
|
|
_EGlFbcAttrib(GLXFBConfig fbc, const char *name, int attr, int want)
|
|
|
|
{
|
|
|
|
int err, value;
|
|
|
|
|
|
|
|
value = 0xabbabeef;
|
|
|
|
err = glXGetFBConfigAttrib(disp, fbc, attr, &value);
|
|
|
|
if (err)
|
|
|
|
Eprintf(" %s *** Error %d ***\n", name, err);
|
|
|
|
else if (want > 0)
|
|
|
|
D2printf(" %s=%#x (want %#x)\n", name, value, want);
|
|
|
|
else
|
|
|
|
D2printf(" %s=%#x\n", name, value);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
int
|
|
|
|
EGlInit(void)
|
|
|
|
{
|
|
|
|
/* From NV's README.txt (AddARGBGLXVisuals) */
|
|
|
|
static const int attrs[] = {
|
2007-04-08 13:24:06 -07:00
|
|
|
GLX_VISUAL_CAVEAT_EXT, GLX_NONE_EXT,
|
|
|
|
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PIXMAP_BIT,
|
2007-03-29 13:54:55 -07:00
|
|
|
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_ALPHA_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER, True,
|
|
|
|
GLX_DEPTH_SIZE, 1,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
XVisualInfo *vi;
|
|
|
|
GLXFBConfig *fbc;
|
|
|
|
int i, ix, num;
|
|
|
|
int value;
|
|
|
|
char *s;
|
2013-12-28 09:59:09 -08:00
|
|
|
XID vid = NoXID;
|
2007-03-29 13:54:55 -07:00
|
|
|
XRenderPictFormat *pictFormat;
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
Dprintf("EGlInit\n");
|
|
|
|
|
|
|
|
memset(&egl, 0, sizeof(EGlContext));
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
s = getenv("EVISUAL");
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
vid = strtoul(s, NULL, 0);
|
|
|
|
Eprintf("Want Visual Id=%#lx\n", vid);
|
|
|
|
}
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
/* Create a GLX context */
|
|
|
|
fbc = glXChooseFBConfig(disp, DefaultScreen(disp), attrs, &num);
|
2007-03-29 13:54:55 -07:00
|
|
|
if (!fbc)
|
|
|
|
{
|
|
|
|
Eprintf("No FB configs\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
D2printf("Visuals found: %d\n", num);
|
|
|
|
ix = -1;
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
vi = glXGetVisualFromFBConfig(disp, fbc[i]);
|
|
|
|
if (!vi)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
D2printf("Checking Visual ID=%#lx depth=%d\n", vi->visualid, vi->depth);
|
|
|
|
if (vid && vi->visualid != vid)
|
|
|
|
continue;
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
#if 1
|
2022-09-18 04:31:05 -07:00
|
|
|
FBCATTR(fbc[i], GLX_FBCONFIG_ID, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_CONFIG_CAVEAT, GLX_NONE);
|
|
|
|
FBCATTR(fbc[i], GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT);
|
|
|
|
FBCATTR(fbc[i], GLX_RENDER_TYPE, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_X_VISUAL_TYPE, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_X_RENDERABLE, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_BUFFER_SIZE, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_LEVEL, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_TRANSPARENT_TYPE, -1);
|
2007-03-29 13:54:55 -07:00
|
|
|
#endif
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
#if 1
|
2022-09-18 04:31:05 -07:00
|
|
|
FBCATTR(fbc[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, 1);
|
2007-04-08 13:24:06 -07:00
|
|
|
value = FBCATTR(fbc[i], GLX_BIND_TO_TEXTURE_RGB_EXT, 1);
|
|
|
|
if (!value)
|
2007-03-29 13:54:55 -07:00
|
|
|
continue;
|
2022-09-18 04:31:05 -07:00
|
|
|
FBCATTR(fbc[i], GLX_BIND_TO_MIPMAP_TEXTURE_EXT, -1);
|
|
|
|
FBCATTR(fbc[i], GLX_BIND_TO_TEXTURE_TARGETS_EXT,
|
|
|
|
GLX_TEXTURE_2D_BIT_EXT);
|
2007-03-29 13:54:55 -07:00
|
|
|
#if 0
|
|
|
|
if (!(value & GLX_TEXTURE_2D_BIT_EXT))
|
|
|
|
continue;
|
|
|
|
#endif
|
2022-09-18 04:31:05 -07:00
|
|
|
FBCATTR(fbc[i], GLX_Y_INVERTED_EXT, -1);
|
2007-04-08 13:24:06 -07:00
|
|
|
#endif
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
/* We want an ARGB visual */
|
|
|
|
pictFormat = XRenderFindVisualFormat(disp, vi->visual);
|
|
|
|
if (!pictFormat)
|
|
|
|
continue;
|
|
|
|
if (pictFormat->direct.alphaMask == 0)
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
D2printf(" - passed\n");
|
|
|
|
if (ix < 0)
|
|
|
|
ix = i;
|
|
|
|
|
|
|
|
XFree(vi);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ix >= 0)
|
|
|
|
egl.fbc = fbc[ix];
|
|
|
|
XFree(fbc);
|
|
|
|
|
|
|
|
if (ix < 0)
|
|
|
|
{
|
|
|
|
Eprintf("No FB config match\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-06-14 15:38:22 -07:00
|
|
|
#ifndef HAVE_GLX_glXBindTexImageEXT
|
|
|
|
if (glx_funcs_init())
|
|
|
|
{
|
|
|
|
Eprintf("glXBindTexImageEXT or glXReleaseTexImageEXT not available\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
egl.vi = glXGetVisualFromFBConfig(disp, egl.fbc);
|
|
|
|
|
|
|
|
egl.ctx = glXCreateNewContext(disp, egl.fbc, GLX_RGBA_TYPE, NULL, True);
|
|
|
|
|
|
|
|
Dprintf("Direct Rendering %s\n",
|
|
|
|
glXIsDirect(disp, egl.ctx) ? "enabled" : "not available");
|
|
|
|
Dprintf("Visual ID=%#lx depth %d\n", egl.vi->visualid, egl.vi->depth);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EGlExit(void)
|
|
|
|
{
|
|
|
|
Dprintf("EGlExit\n");
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
EobjTexturesFree();
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
if (egl.vi)
|
|
|
|
{
|
|
|
|
XFree(egl.vi);
|
|
|
|
egl.vi = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (egl.ctx)
|
|
|
|
{
|
|
|
|
EGlWindowDisconnect();
|
|
|
|
glXDestroyContext(disp, egl.ctx);
|
|
|
|
egl.ctx = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
Visual *
|
|
|
|
EGlGetVisual(void)
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
2007-04-08 13:24:06 -07:00
|
|
|
if (!egl.vi)
|
|
|
|
EGlInit();
|
2007-06-24 09:48:16 -07:00
|
|
|
return (egl.vi) ? egl.vi->visual : NULL;
|
2007-03-29 13:54:55 -07:00
|
|
|
}
|
|
|
|
|
2007-04-08 13:24:06 -07:00
|
|
|
unsigned int
|
|
|
|
EGlGetDepth(void)
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
2007-04-08 13:24:06 -07:00
|
|
|
if (!egl.vi)
|
|
|
|
EGlInit();
|
2007-06-24 09:48:16 -07:00
|
|
|
return (egl.vi) ? egl.vi->depth : 0;
|
2007-03-29 13:54:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-03 11:29:30 -08:00
|
|
|
EGlWindowConnect(EX_Window xwin)
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
|
|
|
glXMakeContextCurrent(disp, xwin, xwin, egl.ctx);
|
|
|
|
|
|
|
|
if (egl.ctx_initialised)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* First time */
|
2007-07-21 13:28:40 -07:00
|
|
|
glEnable(TEXTURE_TARGET);
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glClearDepth(1.0f);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
|
|
|
|
|
|
|
egl.ctx_initialised = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EGlWindowDisconnect(void)
|
|
|
|
{
|
2013-12-28 09:59:09 -08:00
|
|
|
if (!glXMakeContextCurrent(disp, NoXID, NoXID, NULL))
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
|
|
|
Eprintf("Failed to release GL context.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ETexture *
|
|
|
|
EGlTextureFromImage(EImage * im, int mode)
|
|
|
|
{
|
|
|
|
ETexture *et;
|
|
|
|
int w, h;
|
|
|
|
unsigned char *data;
|
|
|
|
|
|
|
|
if (!im)
|
|
|
|
return NULL;
|
|
|
|
|
2018-12-22 06:44:43 -08:00
|
|
|
et = ECALLOC(ETexture, 1);
|
2007-03-29 13:54:55 -07:00
|
|
|
if (!et)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-21 13:28:40 -07:00
|
|
|
et->type = ETEX_TYPE_IMAGE;
|
2007-03-29 13:54:55 -07:00
|
|
|
et->target = TEXTURE_TARGET;
|
|
|
|
glGenTextures(1, &et->texture);
|
|
|
|
glBindTexture(et->target, et->texture);
|
|
|
|
|
|
|
|
EImageGetSize(im, &w, &h);
|
2020-01-13 10:22:06 -08:00
|
|
|
data = (unsigned char *)EImageGetData(im);
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 0: /* No filtering */
|
|
|
|
glTexImage2D(et->target, 0, GL_RGB8, w, h, 0, GL_BGRA,
|
|
|
|
GL_UNSIGNED_BYTE, data);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
break;
|
|
|
|
case 1: /* Linear filtering */
|
|
|
|
glTexImage2D(et->target, 0, GL_RGB8, w, h, 0, GL_BGRA,
|
|
|
|
GL_UNSIGNED_BYTE, data);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
break;
|
|
|
|
case 2: /* Mipmapping */
|
|
|
|
gluBuild2DMipmaps(et->target, GL_RGB8, w, h, GL_BGRA,
|
|
|
|
GL_UNSIGNED_BYTE, data);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR_MIPMAP_NEAREST);
|
|
|
|
glTexParameteri(et->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLXPixmap
|
2009-12-03 11:29:30 -08:00
|
|
|
GetGlPixmap(EX_Window xwin, EX_Drawable draw)
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
|
|
|
static const int attrs[] = {
|
2009-12-24 01:19:22 -08:00
|
|
|
GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
|
2007-03-29 13:54:55 -07:00
|
|
|
GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT,
|
|
|
|
0
|
|
|
|
};
|
2009-12-03 11:29:30 -08:00
|
|
|
EX_Pixmap pixmap;
|
2007-03-29 13:54:55 -07:00
|
|
|
GLXPixmap glxpixmap;
|
|
|
|
|
2013-12-28 09:59:09 -08:00
|
|
|
if (xwin == NoXID && draw == NoXID)
|
2007-03-29 13:54:55 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pixmap = (draw) ? draw : XCompositeNameWindowPixmap(disp, xwin);
|
|
|
|
glxpixmap = glXCreatePixmap(disp, egl.fbc, pixmap, attrs);
|
2009-12-03 11:29:30 -08:00
|
|
|
Dprintf("GetGlPixmap: Window=%#x Drawable=%#x glxpixmap=%#lx\n",
|
2007-03-29 13:54:55 -07:00
|
|
|
xwin, draw, glxpixmap);
|
|
|
|
|
|
|
|
return glxpixmap;
|
|
|
|
}
|
|
|
|
|
2007-07-21 13:28:40 -07:00
|
|
|
static void
|
2009-12-03 11:29:30 -08:00
|
|
|
_EGlTextureFromDrawable(ETexture * et, EX_Drawable draw, int mode)
|
2007-07-21 13:28:40 -07:00
|
|
|
{
|
2013-12-28 09:59:09 -08:00
|
|
|
if (!et || draw == NoXID)
|
2007-07-21 13:28:40 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
glBindTexture(et->target, et->texture);
|
2013-12-28 09:59:09 -08:00
|
|
|
et->glxpmap = GetGlPixmap(draw, (mode & 0x100) ? NoXID : draw);
|
|
|
|
if (et->glxpmap == NoXID)
|
2007-07-21 13:28:40 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glXBindTexImageEXT(disp, et->glxpmap, GLX_FRONT_LEFT_EXT, NULL);
|
|
|
|
#if 0 /* No! */
|
|
|
|
glXDestroyPixmap(disp, et->glxpmap);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:54:55 -07:00
|
|
|
ETexture *
|
2009-12-03 11:29:30 -08:00
|
|
|
EGlTextureFromDrawable(EX_Drawable draw, int mode)
|
2007-03-29 13:54:55 -07:00
|
|
|
{
|
|
|
|
ETexture *et;
|
|
|
|
|
2013-12-28 09:59:09 -08:00
|
|
|
if (draw == NoXID)
|
2007-03-29 13:54:55 -07:00
|
|
|
return NULL;
|
|
|
|
|
2018-12-22 06:44:43 -08:00
|
|
|
et = ECALLOC(ETexture, 1);
|
2007-03-29 13:54:55 -07:00
|
|
|
if (!et)
|
|
|
|
return NULL;
|
|
|
|
|
2007-07-21 13:28:40 -07:00
|
|
|
et->type = ETEX_TYPE_PIXMAP;
|
2007-03-29 13:54:55 -07:00
|
|
|
et->target = TEXTURE_TARGET;
|
|
|
|
glGenTextures(1, &et->texture);
|
|
|
|
glBindTexture(et->target, et->texture);
|
|
|
|
|
2007-07-21 13:28:40 -07:00
|
|
|
_EGlTextureFromDrawable(et, draw, mode);
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EGlTextureDestroy(ETexture * et)
|
|
|
|
{
|
|
|
|
if (!et)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Dprintf("EGlTextureDestroy %d type=%u pmap=%#x\n", et->texture, et->type,
|
|
|
|
et->glxpmap);
|
|
|
|
|
2007-07-21 13:28:40 -07:00
|
|
|
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);
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
switch (et->type)
|
|
|
|
{
|
|
|
|
case ETEX_TYPE_IMAGE:
|
|
|
|
break;
|
|
|
|
case ETEX_TYPE_PIXMAP:
|
|
|
|
if (!et->glxpmap)
|
|
|
|
break;
|
2007-06-14 15:38:22 -07:00
|
|
|
_glXReleaseTexImageEXT(disp, et->glxpmap, GLX_FRONT_LEFT_EXT);
|
2007-03-29 13:54:55 -07:00
|
|
|
glXDestroyPixmap(disp, et->glxpmap);
|
2013-12-28 09:59:09 -08:00
|
|
|
et->glxpmap = NoXID;
|
2007-03-29 13:54:55 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "eobj.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
EobjTexturesFree(void)
|
|
|
|
{
|
|
|
|
int i, num;
|
2007-04-08 13:24:06 -07:00
|
|
|
EObj *const *eol;
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
eol = EobjListStackGet(&num);
|
|
|
|
for (i = 0; i < num; i++)
|
2007-04-08 13:24:06 -07:00
|
|
|
EobjTextureDestroy(eol[i]);
|
2007-03-29 13:54:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ETexture *
|
|
|
|
EobjGetTexture(EObj * eo)
|
|
|
|
{
|
|
|
|
if (eo->glhook)
|
2007-07-21 13:28:40 -07:00
|
|
|
{
|
2013-12-28 09:59:09 -08:00
|
|
|
if (eo->glhook->glxpmap == NoXID)
|
2010-06-06 03:05:53 -07:00
|
|
|
_EGlTextureFromDrawable(eo->glhook, EobjGetPixmap(eo), 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EobjTextureCreate(eo);
|
2007-07-21 13:28:40 -07:00
|
|
|
}
|
|
|
|
|
2010-06-06 03:05:53 -07:00
|
|
|
return eo->glhook;
|
2007-07-21 13:28:40 -07:00
|
|
|
}
|
|
|
|
|
2010-06-06 03:05:53 -07:00
|
|
|
void
|
2007-07-21 13:28:40 -07:00
|
|
|
EobjTextureCreate(EObj * eo)
|
|
|
|
{
|
2009-12-03 11:29:30 -08:00
|
|
|
EX_Pixmap pmap;
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
pmap = EobjGetPixmap(eo);
|
2013-12-28 09:59:09 -08:00
|
|
|
if (pmap == NoXID)
|
2010-06-06 03:05:53 -07:00
|
|
|
return;
|
2007-03-29 13:54:55 -07:00
|
|
|
|
|
|
|
eo->glhook = EGlTextureFromDrawable(pmap, 0);
|
|
|
|
}
|
2007-04-08 13:24:06 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
EobjTextureDestroy(EObj * eo)
|
|
|
|
{
|
|
|
|
EGlTextureDestroy(eo->glhook);
|
|
|
|
eo->glhook = NULL;
|
|
|
|
}
|
2007-07-21 13:28:40 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
EobjTextureInvalidate(EObj * eo)
|
|
|
|
{
|
|
|
|
EGlTextureInvalidate(eo->glhook);
|
|
|
|
}
|