annotate libvo/gl_common.c @ 13981:3e82594ec231

correct encoding
author diego
date Fri, 19 Nov 2004 18:34:33 +0000
parents 3f28d2a56758
children c4033dcb986f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
1 #include "gl_common.h"
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
2
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
3 /**
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
4 * \brief adjusts the GL_UNPACK_ALGNMENT to fit the stride.
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
5 * \param stride number of bytes per line for which alignment should fit.
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
6 */
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
7 void glAdjustAlignment(int stride) {
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
8 GLint gl_alignment;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
9 if (stride % 8 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
10 gl_alignment=8;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
11 else if (stride % 4 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
12 gl_alignment=4;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
13 else if (stride % 2 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
14 gl_alignment=2;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
15 else
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
16 gl_alignment=1;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
17 glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment);
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
18 }
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
19
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
20 #ifndef GL_WIN32
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
21 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
22 * Returns the XVisualInfo associated with Window win.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
23 * \param win Window whose XVisualInfo is returne.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
24 * \return XVisualInfo of the window. Caller must use XFree to free it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
25 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
26 static XVisualInfo *getWindowVisualInfo(Window win) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
27 XWindowAttributes xw_attr;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
28 XVisualInfo vinfo_template;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
29 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
30 XGetWindowAttributes(mDisplay, win, &xw_attr);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
31 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
32 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
33 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
34
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
35 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
36 * \brief Changes the window in which video is displayed.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
37 * If possible only transfers the context to the new window, otherwise
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
38 * creates a new one, which must be initialized by the caller.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
39 * \param vinfo Currently used visual.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
40 * \param context Currently used context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
41 * \param win window that should be used for drawing.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
42 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
43 * In case of SET_WINDOW_REINIT the context could not be transfered
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
44 * and the caller must initialize it correctly.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
45 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
46 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
47 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
48 XVisualInfo *new_vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
49 GLXContext new_context = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
50 int keep_context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
51
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
52 // should only be needed when keeping context, but not doing glFinish
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
53 // can cause flickering even when we do not keep it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
54 glFinish();
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
55 new_vinfo = getWindowVisualInfo(win);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
56 if (*context && *vinfo && new_vinfo &&
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
57 (*vinfo)->visualid == new_vinfo->visualid) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
58 // we can keep the GLXContext
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
59 new_context = *context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
60 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
61 new_vinfo = *vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
62 keep_context = 1;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
63 } else {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
64 // create a context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
65 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
66 if (!new_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
67 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GLX context!\n");
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
68 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
69 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
70 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
71 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
72
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
73 // set context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
74 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
75 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GLX context!\n");
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
76 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
77 glXDestroyContext (mDisplay, new_context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
78 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
79 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
80 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
81 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
82
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
83 // set new values
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
84 vo_window = win;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
85 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
86 Window root;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
87 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
88 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp,
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
89 &vo_dwidth, &vo_dheight, &tmp, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
90 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
91 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
92 if (*context)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
93 glXDestroyContext(mDisplay, *context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
94 *context = new_context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
95 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
96 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
97 *vinfo = new_vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
98
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
99 // and inform that reinit is neccessary
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
100 return SET_WINDOW_REINIT;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
101 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
102 return SET_WINDOW_OK;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
103 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
104
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
105 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
106 * \brief free the VisualInfo and GLXContext of an OpenGL context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
107 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
108 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
109 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
110 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
111 *vinfo = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
112 if (*context)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
113 glXDestroyContext(mDisplay, *context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
114 *context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
115 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
116 #endif
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
117