Cut down on code duplication

This commit is contained in:
twinaphex 2019-08-28 23:58:15 +02:00
parent 01cb2b8d44
commit 3a7515c82f
4 changed files with 22 additions and 36 deletions

View File

@ -1605,3 +1605,21 @@ void win32_get_video_output_size(unsigned *width, unsigned *height)
*height = dm.dmPelsHeight;
}
}
void win32_setup_pixel_format(HDC hdc, bool supports_gl)
{
PIXELFORMATDESCRIPTOR pfd = {0};
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 0;
pfd.cStencilBits = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
if (supports_gl)
pfd.dwFlags |= PFD_SUPPORT_OPENGL;
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
}

View File

@ -143,6 +143,8 @@ LRESULT win32_menu_loop(HWND owner, WPARAM wparam);
bool win32_load_content_from_gui(const char *szFilename);
void win32_setup_pixel_format(HDC hdc, bool supports_gl);
RETRO_END_DECLS
#endif

View File

@ -56,21 +56,6 @@ typedef struct gfx_ctx_gdi_data
void *dinput_gdi;
static void setup_gdi_pixel_format(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd = {0};
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 0;
pfd.cStencilBits = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
}
static void gfx_ctx_gdi_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, bool is_shutdown)
{
@ -345,10 +330,9 @@ static void gfx_ctx_gdi_swap_buffers(void *data, void *data2)
void create_gdi_context(HWND hwnd, bool *quit)
{
(void)quit;
win32_gdi_hdc = GetDC(hwnd);
setup_gdi_pixel_format(win32_gdi_hdc);
win32_setup_pixel_format(win32_gdi_hdc, false);
g_win32_inited = true;
}

View File

@ -173,24 +173,6 @@ static gfx_ctx_proc_t gfx_ctx_wgl_get_proc_address(const char *symbol)
}
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGL1) || defined(HAVE_OPENGL_CORE)
static void setup_pixel_format(HDC hdc, bool supports_gl)
{
PIXELFORMATDESCRIPTOR pfd = {0};
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 0;
pfd.cStencilBits = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
if (supports_gl)
pfd.dwFlags |= PFD_SUPPORT_OPENGL;
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
}
static void create_gl_context(HWND hwnd, bool *quit)
{
struct retro_hw_render_callback *hwr = video_driver_get_hw_context();
@ -198,7 +180,7 @@ static void create_gl_context(HWND hwnd, bool *quit)
bool core_context = (win32_major * 1000 + win32_minor) >= 3001;
win32_hdc = GetDC(hwnd);
setup_pixel_format(win32_hdc, true);
win32_setup_pixel_format(win32_hdc, true);
#ifdef GL_DEBUG
debug = true;