aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-12-11 16:57:42 +0000
committerGravatar reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2004-12-11 16:57:42 +0000
commit84fd90d3e4e24dd9aa5157e7201eba85143c93e6 (patch)
tree38b08e0f1d4bd9db62e722195be29248d3694eda
parent3c88c6d150d804935518d9469bbd2467f3a378c4 (diff)
Improving gl2 under windows, moving some functionality to gl_common
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14143 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--libvo/gl_common.c65
-rw-r--r--libvo/gl_common.h11
-rw-r--r--libvo/vo_gl2.c15
-rw-r--r--libvo/w32_common.c40
-rw-r--r--libvo/w32_common.h1
5 files changed, 95 insertions, 37 deletions
diff --git a/libvo/gl_common.c b/libvo/gl_common.c
index 884d6e8072..9dc7f79242 100644
--- a/libvo/gl_common.c
+++ b/libvo/gl_common.c
@@ -178,7 +178,70 @@ int glFindFormat(uint32_t fmt, uint32_t *bpp, GLenum *gl_texfmt,
return 1;
}
-#ifndef GL_WIN32
+#ifdef GL_WIN32
+int setGlWindow(int *vinfo, HGLRC *context, HWND win)
+{
+ int new_vinfo;
+ HDC windc = GetDC(win);
+ HGLRC new_context = 0;
+ int keep_context = 0;
+
+ // should only be needed when keeping context, but not doing glFinish
+ // can cause flickering even when we do not keep it.
+ glFinish();
+ new_vinfo = GetPixelFormat(windc);
+ if (*context && *vinfo && new_vinfo && *vinfo == new_vinfo) {
+ // we can keep the wglContext
+ new_context = *context;
+ keep_context = 1;
+ } else {
+ // create a context
+ new_context = wglCreateContext(windc);
+ if (!new_context) {
+ mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GL context!\n");
+ return SET_WINDOW_FAILED;
+ }
+ }
+
+ // set context
+ if (!wglMakeCurrent(windc, new_context)) {
+ mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GL context!\n");
+ if (!keep_context) {
+ wglDeleteContext(new_context);
+ }
+ return SET_WINDOW_FAILED;
+ }
+
+ // set new values
+ vo_window = win;
+ vo_hdc = windc;
+ {
+ RECT rect;
+ GetClientRect(win, &rect);
+ vo_dwidth = rect.right;
+ vo_dheight = rect.bottom;
+ }
+ if (!keep_context) {
+ if (*context)
+ wglDeleteContext(*context);
+ *context = new_context;
+ *vinfo = new_vinfo;
+
+ // and inform that reinit is neccessary
+ return SET_WINDOW_REINIT;
+ }
+ return SET_WINDOW_OK;
+}
+
+void releaseGlContext(int *vinfo, HGLRC *context) {
+ *vinfo = 0;
+ if (*context) {
+ wglMakeCurrent(0, 0);
+ wglDeleteContext(*context);
+ }
+ *context = 0;
+}
+#else
/**
* Returns the XVisualInfo associated with Window win.
* \param win Window whose XVisualInfo is returne.
diff --git a/libvo/gl_common.h b/libvo/gl_common.h
index 2a02643483..da7da0eae7 100644
--- a/libvo/gl_common.h
+++ b/libvo/gl_common.h
@@ -7,7 +7,11 @@
#include <GL/gl.h>
#include "video_out.h"
-#ifndef GL_WIN32
+#ifdef GL_WIN32
+#include <windows.h>
+#include <GL/glext.h>
+#include "w32_common.h"
+#else
#include <X11/Xlib.h>
#include <GL/glx.h>
#include "x11_common.h"
@@ -27,7 +31,10 @@ int glFindFormat(uint32_t format, uint32_t *bpp, GLenum *gl_texfmt,
//! new window is set, but the OpenGL context needs to be reinitialized.
#define SET_WINDOW_REINIT 1
-#ifndef GL_WIN32
+#ifdef GL_WIN32
+int setGlWindow(int *vinfo, HGLRC *context, HWND win);
+void releaseGlContext(int *vinfo, HGLRC *context);
+#else
int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win);
void releaseGlContext(XVisualInfo **vinfo, GLXContext *context);
#endif
diff --git a/libvo/vo_gl2.c b/libvo/vo_gl2.c
index 2e33f0919e..8063f181d0 100644
--- a/libvo/vo_gl2.c
+++ b/libvo/vo_gl2.c
@@ -70,7 +70,10 @@ static unsigned char *ImageData=NULL;
//static int texture_id=1;
-#ifndef GL_WIN32
+#ifdef GL_WIN32
+ static int gl_vinfo = 0;
+ static HGLRC gl_context = 0;
+#else
static XVisualInfo *gl_vinfo = NULL;
static GLXContext gl_context = 0;
#endif
@@ -766,7 +769,6 @@ static int config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_
if (vo_fs ^ (flags & VOFLAG_FULLSCREEN))
vo_x11_fullscreen();
- setGlWindow(&gl_vinfo, &gl_context, vo_window);
return 0;
}
@@ -775,7 +777,6 @@ static int config_glx_gui(uint32_t d_width, uint32_t d_height) {
vo_dwidth = d_width;
vo_dheight = d_height;
guiGetEvent( guiSetShVideo,0 ); // the GUI will set up / resize the window
- setGlWindow(&gl_vinfo, &gl_context, vo_window);
return 0;
}
#endif
@@ -862,6 +863,8 @@ config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uin
#endif
return -1;
+ setGlWindow(&gl_vinfo, &gl_context, vo_window);
+
glVersion = glGetString(GL_VERSION);
mp_msg(MSGT_VO, MSGL_V, "[gl2] OpenGL Driver Information:\n");
@@ -1058,9 +1061,7 @@ static void
uninit(void)
{
if ( !vo_config_count ) return;
-#ifndef GL_WIN32
releaseGlContext(&gl_vinfo, &gl_context);
-#endif
if (texgrid) {
free(texgrid);
texgrid = NULL;
@@ -1102,10 +1103,12 @@ static uint32_t control(uint32_t request, void *data, ...)
case VOCTRL_FULLSCREEN:
#ifdef GL_WIN32
vo_w32_fullscreen();
- initGl(vo_dwidth, vo_dheight);
#else
vo_x11_fullscreen();
#endif
+ if (setGlWindow(&gl_vinfo, &gl_context, vo_window) == SET_WINDOW_REINIT)
+ initGl(vo_dwidth, vo_dheight);
+ resize(&vo_dwidth, &vo_dheight);
return VO_TRUE;
#ifndef GL_WIN32
case VOCTRL_SET_EQUALIZER:
diff --git a/libvo/w32_common.c b/libvo/w32_common.c
index fe89cbabf8..13b8839d29 100644
--- a/libvo/w32_common.c
+++ b/libvo/w32_common.c
@@ -19,8 +19,7 @@ uint32_t o_dwidth;
uint32_t o_dheight;
static HINSTANCE hInstance;
-static HWND vo_hwnd = 0;
-static HGLRC wglContext = 0;
+HWND vo_window = 0;
static int cursor = 1;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
@@ -143,10 +142,12 @@ static void changeMode(void) {
vo_dwidth = vo_screenwidth;
vo_dheight = vo_screenheight;
+ if (vo_vm)
ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
}
static void resetMode(void) {
+ if (vo_vm)
ChangeDisplaySettings(0, 0);
DEVMODE dm;
@@ -169,19 +170,18 @@ static void resetMode(void) {
int createRenderingContext(void) {
HWND layer = HWND_NOTOPMOST;
- if (wglContext) return 1;
if (vo_fs || vo_ontop) layer = HWND_TOPMOST;
if (vo_fs) {
changeMode();
- SetWindowPos(vo_hwnd, layer, 0, 0, vo_screenwidth, vo_screenheight, SWP_SHOWWINDOW);
+ SetWindowPos(vo_window, layer, 0, 0, vo_screenwidth, vo_screenheight, SWP_SHOWWINDOW);
if (cursor) {
ShowCursor(0);
cursor = 0;
}
} else {
resetMode();
- SetWindowPos(vo_hwnd, layer, (vo_screenwidth - vo_dwidth) / 2, (vo_screenheight - vo_dheight) / 2, vo_dwidth, vo_dheight, SWP_SHOWWINDOW);
+ SetWindowPos(vo_window, layer, (vo_screenwidth - vo_dwidth) / 2, (vo_screenheight - vo_dheight) / 2, vo_dwidth, vo_dheight, SWP_SHOWWINDOW);
if (!cursor) {
ShowCursor(1);
cursor = 1;
@@ -204,29 +204,13 @@ int createRenderingContext(void) {
SetPixelFormat(vo_hdc, pf, &pfd);
- wglContext = wglCreateContext(vo_hdc);
- if (!wglContext) {
- mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create wgl rendering context!\n");
- return 0;
- }
-
- if (!wglMakeCurrent(vo_hdc, wglContext)) {
- mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to make wgl rendering context current!\n");
- return 0;
- }
-
mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen);
return 1;
}
void destroyRenderingContext(void) {
- if (wglContext) {
- wglMakeCurrent(0, 0);
- wglDeleteContext(wglContext);
- wglContext = 0;
resetMode();
- }
}
int vo_init(void) {
@@ -234,7 +218,7 @@ int vo_init(void) {
char exedir[MAX_PATH];
DEVMODE dm;
- if (vo_hwnd)
+ if (vo_window)
return 1;
hInstance = GetModuleHandle(0);
@@ -251,13 +235,13 @@ int vo_init(void) {
return 0;
}
- vo_hwnd = CreateWindowEx(0, classname, classname, WS_POPUP, CW_USEDEFAULT, 0, 100, 100, 0, 0, hInstance, 0);
- if (!vo_hwnd) {
+ vo_window = CreateWindowEx(0, classname, classname, WS_POPUP, CW_USEDEFAULT, 0, 100, 100, 0, 0, hInstance, 0);
+ if (!vo_window) {
mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create window!\n");
return 0;
}
- vo_hdc = GetDC(vo_hwnd);
+ vo_hdc = GetDC(vo_window);
dm.dmSize = sizeof dm;
dm.dmDriverExtra = 0;
@@ -286,7 +270,7 @@ void vo_w32_ontop( void )
if (!vo_fs) {
HWND layer = HWND_NOTOPMOST;
if (vo_ontop) layer = HWND_TOPMOST;
- SetWindowPos(vo_hwnd, layer, (vo_screenwidth - vo_dwidth) / 2, (vo_screenheight - vo_dheight) / 2, vo_dwidth, vo_dheight, SWP_SHOWWINDOW);
+ SetWindowPos(vo_window, layer, (vo_screenwidth - vo_dwidth) / 2, (vo_screenheight - vo_dheight) / 2, vo_dwidth, vo_dheight, SWP_SHOWWINDOW);
}
}
@@ -296,7 +280,7 @@ void vo_w32_uninit() {
ShowCursor(1);
vo_depthonscreen = 0;
destroyRenderingContext();
- DestroyWindow(vo_hwnd);
- vo_hwnd = 0;
+ DestroyWindow(vo_window);
+ vo_window = 0;
UnregisterClass(classname, 0);
}
diff --git a/libvo/w32_common.h b/libvo/w32_common.h
index ddb86d3571..75a9420826 100644
--- a/libvo/w32_common.h
+++ b/libvo/w32_common.h
@@ -3,6 +3,7 @@ extern int vo_screenwidth;
extern int vo_screenheight;
extern uint32_t o_dwidth;
extern uint32_t o_dheight;
+extern HWND vo_window;
extern HDC vo_hdc;
extern int vo_fs;
extern int vo_vm;