comparison libvo/gl_common.c @ 14142:f0c1ee83b216

Improving gl2 under windows, moving some functionality to gl_common
author reimar
date Sat, 11 Dec 2004 16:57:42 +0000
parents 00283cb37fd0
children 718ec28220d6
comparison
equal deleted inserted replaced
14141:38050abfa2ee 14142:f0c1ee83b216
176 *gl_texfmt = TEXTUREFORMAT_ALWAYS; 176 *gl_texfmt = TEXTUREFORMAT_ALWAYS;
177 #endif 177 #endif
178 return 1; 178 return 1;
179 } 179 }
180 180
181 #ifndef GL_WIN32 181 #ifdef GL_WIN32
182 int setGlWindow(int *vinfo, HGLRC *context, HWND win)
183 {
184 int new_vinfo;
185 HDC windc = GetDC(win);
186 HGLRC new_context = 0;
187 int keep_context = 0;
188
189 // should only be needed when keeping context, but not doing glFinish
190 // can cause flickering even when we do not keep it.
191 glFinish();
192 new_vinfo = GetPixelFormat(windc);
193 if (*context && *vinfo && new_vinfo && *vinfo == new_vinfo) {
194 // we can keep the wglContext
195 new_context = *context;
196 keep_context = 1;
197 } else {
198 // create a context
199 new_context = wglCreateContext(windc);
200 if (!new_context) {
201 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GL context!\n");
202 return SET_WINDOW_FAILED;
203 }
204 }
205
206 // set context
207 if (!wglMakeCurrent(windc, new_context)) {
208 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GL context!\n");
209 if (!keep_context) {
210 wglDeleteContext(new_context);
211 }
212 return SET_WINDOW_FAILED;
213 }
214
215 // set new values
216 vo_window = win;
217 vo_hdc = windc;
218 {
219 RECT rect;
220 GetClientRect(win, &rect);
221 vo_dwidth = rect.right;
222 vo_dheight = rect.bottom;
223 }
224 if (!keep_context) {
225 if (*context)
226 wglDeleteContext(*context);
227 *context = new_context;
228 *vinfo = new_vinfo;
229
230 // and inform that reinit is neccessary
231 return SET_WINDOW_REINIT;
232 }
233 return SET_WINDOW_OK;
234 }
235
236 void releaseGlContext(int *vinfo, HGLRC *context) {
237 *vinfo = 0;
238 if (*context) {
239 wglMakeCurrent(0, 0);
240 wglDeleteContext(*context);
241 }
242 *context = 0;
243 }
244 #else
182 /** 245 /**
183 * Returns the XVisualInfo associated with Window win. 246 * Returns the XVisualInfo associated with Window win.
184 * \param win Window whose XVisualInfo is returne. 247 * \param win Window whose XVisualInfo is returne.
185 * \return XVisualInfo of the window. Caller must use XFree to free it. 248 * \return XVisualInfo of the window. Caller must use XFree to free it.
186 */ 249 */