summaryrefslogtreecommitdiff
path: root/legacy/evas/src/modules/engines/gl_x11/evas_x_main.c
blob: 6e3b0e9823d49a96a4015593439ac6a55b6841c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "evas_common.h"
#include "evas_private.h"
#include "evas_engine.h"
#include "evas_engine_api_gl_x11.h"
#include "Evas_Engine_GL_X11.h"
#include "evas_gl_common.h"

static Evas_GL_X11_Window *_evas_gl_x11_window = NULL;

/* FIXME: this will only work for 1 display connection... :( */
static GLXContext context = 0;

int _evas_gl_x11_configuration[9] =
{
   GLX_DOUBLEBUFFER,
     GLX_RGBA,
     GLX_RED_SIZE,   1,
     GLX_GREEN_SIZE, 1,
     GLX_BLUE_SIZE,  1,
     None
};

XVisualInfo *_evas_gl_x11_vi = NULL;
Colormap     _evas_gl_x11_cmap = 0;

Evas_GL_X11_Window *
eng_window_new(Display *disp,
			      Window   win,
			      int      screen,
			      Visual  *vis,
			      Colormap cmap,
			      int      depth,
			      int      w,
			      int      h)
{
   Evas_GL_X11_Window *gw;

   if (!_evas_gl_x11_vi) return NULL;
   gw = calloc(1, sizeof(Evas_GL_X11_Window));
   if (!gw) return NULL;
   gw->disp = disp;
   gw->win = win;
   gw->screen = screen;
   gw->visual = vis;
   gw->colormap = cmap;
   gw->depth = depth;

   gw->visualinfo = _evas_gl_x11_vi;
   if (!context)
     context = glXCreateContext(disp, gw->visualinfo, NULL, GL_TRUE);
   gw->context = context;
   glXMakeCurrent(gw->disp, gw->win, gw->context);
   gw->gl_context = evas_gl_common_context_new();
   if (!gw->gl_context)
     {
	glXDestroyContext(gw->disp, gw->context);
	free(gw);
	return NULL;
     }
   evas_gl_common_context_resize(gw->gl_context, w, h);
   return gw;
}

void
eng_window_free(Evas_GL_X11_Window *gw)
{
   if (gw == _evas_gl_x11_window) _evas_gl_x11_window = NULL;
   evas_gl_common_context_free(gw->gl_context);
//   glXDestroyContext(gw->disp, gw->context);
   free(gw);
}

void
eng_window_use(Evas_GL_X11_Window *gw)
{
   if (_evas_gl_x11_window != gw)
     {
	_evas_gl_x11_window = gw;
	glXMakeCurrent(gw->disp, gw->win, gw->context);
     }
   evas_gl_common_context_use(gw->gl_context);
}