Mercurial > mplayer.hg
annotate libvo/gl_common.c @ 13981:3e82594ec231
correct encoding
author | diego |
---|---|
date | Fri, 19 Nov 2004 18:34:33 +0000 |
parents | 3f28d2a56758 |
children | c4033dcb986f |
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 | 20 #ifndef GL_WIN32 |
21 /** | |
22 * Returns the XVisualInfo associated with Window win. | |
23 * \param win Window whose XVisualInfo is returne. | |
24 * \return XVisualInfo of the window. Caller must use XFree to free it. | |
25 */ | |
26 static XVisualInfo *getWindowVisualInfo(Window win) { | |
27 XWindowAttributes xw_attr; | |
28 XVisualInfo vinfo_template; | |
29 int tmp; | |
30 XGetWindowAttributes(mDisplay, win, &xw_attr); | |
31 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual); | |
32 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp); | |
33 } | |
34 | |
35 /** | |
36 * \brief Changes the window in which video is displayed. | |
37 * If possible only transfers the context to the new window, otherwise | |
38 * creates a new one, which must be initialized by the caller. | |
39 * \param vinfo Currently used visual. | |
40 * \param context Currently used context. | |
41 * \param win window that should be used for drawing. | |
42 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT. | |
43 * In case of SET_WINDOW_REINIT the context could not be transfered | |
44 * and the caller must initialize it correctly. | |
45 */ | |
46 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win) | |
47 { | |
48 XVisualInfo *new_vinfo; | |
49 GLXContext new_context = NULL; | |
50 int keep_context = 0; | |
51 | |
52 // should only be needed when keeping context, but not doing glFinish | |
53 // can cause flickering even when we do not keep it. | |
54 glFinish(); | |
55 new_vinfo = getWindowVisualInfo(win); | |
56 if (*context && *vinfo && new_vinfo && | |
57 (*vinfo)->visualid == new_vinfo->visualid) { | |
58 // we can keep the GLXContext | |
59 new_context = *context; | |
60 XFree(new_vinfo); | |
61 new_vinfo = *vinfo; | |
62 keep_context = 1; | |
63 } else { | |
64 // create a context | |
65 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True); | |
66 if (!new_context) { | |
67 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GLX context!\n"); | |
68 XFree(new_vinfo); | |
69 return SET_WINDOW_FAILED; | |
70 } | |
71 } | |
72 | |
73 // set context | |
74 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) { | |
75 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GLX context!\n"); | |
76 if (!keep_context) { | |
77 glXDestroyContext (mDisplay, new_context); | |
78 XFree(new_vinfo); | |
79 } | |
80 return SET_WINDOW_FAILED; | |
81 } | |
82 | |
83 // set new values | |
84 vo_window = win; | |
85 { | |
86 Window root; | |
87 int tmp; | |
88 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp, | |
89 &vo_dwidth, &vo_dheight, &tmp, &tmp); | |
90 } | |
91 if (!keep_context) { | |
92 if (*context) | |
93 glXDestroyContext(mDisplay, *context); | |
94 *context = new_context; | |
95 if (*vinfo) | |
96 XFree(*vinfo); | |
97 *vinfo = new_vinfo; | |
98 | |
99 // and inform that reinit is neccessary | |
100 return SET_WINDOW_REINIT; | |
101 } | |
102 return SET_WINDOW_OK; | |
103 } | |
104 | |
105 /** | |
106 * \brief free the VisualInfo and GLXContext of an OpenGL context. | |
107 */ | |
108 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) { | |
109 if (*vinfo) | |
110 XFree(*vinfo); | |
111 *vinfo = NULL; | |
112 if (*context) | |
113 glXDestroyContext(mDisplay, *context); | |
114 *context = 0; | |
115 } | |
116 #endif | |
117 |