[OPENGLCFG]

- Add a simple applet to set a custom OGL ICD or force the use of the built in software implementation.
- It can be used to set the DEBUGCHANNEL to +opengl,+wgl to make obtaining debug info more user friendly.

svn path=/trunk/; revision=74208
This commit is contained in:
Kamil Hornicek 2017-03-19 22:20:51 +00:00
parent ad61fd2df2
commit 3ac876a570
10 changed files with 398 additions and 0 deletions

View file

@ -13,6 +13,7 @@ add_subdirectory(main)
add_subdirectory(mmsys)
add_subdirectory(ncpa)
add_subdirectory(odbccp32)
add_subdirectory(openglcfg)
add_subdirectory(powercfg)
add_subdirectory(sysdm)
add_subdirectory(telephon)

View file

@ -0,0 +1,19 @@
spec2def(openglcfg.cpl openglcfg.spec)
list(APPEND SOURCE
openglcfg.c
general.c
openglcfg.h)
add_rc_deps(openglcfg.rc ${CMAKE_CURRENT_SOURCE_DIR}/resources/openglcfg.ico)
add_library(openglcfg SHARED
${SOURCE}
openglcfg.rc
${CMAKE_CURRENT_BINARY_DIR}/openglcfg.def)
set_module_type(openglcfg cpl UNICODE)
add_importlibs(openglcfg user32 comctl32 advapi32 msvcrt kernel32)
add_pch(openglcfg openglcfg.h SOURCE)
add_cd_file(TARGET openglcfg DESTINATION reactos/system32 FOR all)

View file

@ -0,0 +1,197 @@
#include "openglcfg.h"
#include <winreg.h>
#include <debug.h>
static PWCHAR *pOglDrivers = NULL;
static DWORD dwNumDrivers = 0;
static VOID InitSettings(HWND hWndDlg)
{
HKEY hKeyRenderer;
HKEY hKeyDrivers;
WCHAR szBuffer[MAX_KEY_LENGTH];
WCHAR szBultin[MAX_KEY_LENGTH];
WCHAR szDriver[MAX_KEY_LENGTH];
DWORD dwType = 0;
DWORD dwSize = MAX_KEY_LENGTH;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KEY_DRIVERS, 0, KEY_READ, &hKeyDrivers) != ERROR_SUCCESS)
return;
if (RegCreateKeyExW(HKEY_CURRENT_USER, KEY_RENDERER, 0, NULL, 0, MAXIMUM_ALLOWED, NULL, &hKeyRenderer, NULL) != ERROR_SUCCESS)
{
RegCloseKey(hKeyDrivers);
return;
}
LoadString(hApplet, IDS_DEBUG_DNM, (LPTSTR)szBultin, 127);
SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin);
LoadString(hApplet, IDS_DEBUG_SET, (LPTSTR)szBultin, 127);
SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin);
LoadString(hApplet, IDS_DEBUG_CLEAR, (LPTSTR)szBultin, 127);
SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_ADDSTRING, 0, (LPARAM)szBultin);
SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_SETCURSEL, 0, 0);
LoadString(hApplet, IDS_RENDERER_DEFAULT, (LPTSTR)szBultin, 127);
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBultin, 127);
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBultin);
if (RegQueryValueExW(hKeyRenderer, NULL, NULL, &dwType, (LPBYTE)szDriver, &dwSize) != ERROR_SUCCESS || dwSize == sizeof(WCHAR))
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, RENDERER_DEFAULT, 0);
if (dwType == REG_SZ)
{
DWORD ret;
INT iKey;
if (wcsncmp(szBultin, szDriver, MAX_KEY_LENGTH) == 0)
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, RENDERER_RSWR, 0);
ret = RegQueryInfoKeyW(hKeyDrivers, NULL, NULL, NULL, &dwNumDrivers, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
if (ret != ERROR_SUCCESS || dwNumDrivers <= 0)
{
RegCloseKey(hKeyDrivers);
RegCloseKey(hKeyRenderer);
return;
}
pOglDrivers = HeapAlloc(GetProcessHeap(), 0, dwNumDrivers * sizeof(PWCHAR));
if (!pOglDrivers)
dwNumDrivers = 0;
for (iKey = 0; iKey < dwNumDrivers; iKey++)
{
dwSize = MAX_KEY_LENGTH;
ret = RegEnumKeyEx(hKeyDrivers, iKey, szBuffer, &dwSize, NULL, NULL, NULL, NULL);
if (ret != ERROR_SUCCESS)
break;
/* Mind the null terminator */
dwSize++;
pOglDrivers[iKey] = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
if (!pOglDrivers[iKey])
break;
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_ADDSTRING, 0, (LPARAM)szBuffer);
StringCchCopy(pOglDrivers[iKey], dwSize, szBuffer);
if (wcsncmp(szBuffer, szDriver, MAX_KEY_LENGTH) == 0)
SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_SETCURSEL, iKey + 2, 0);
}
}
RegCloseKey(hKeyDrivers);
RegCloseKey(hKeyRenderer);
return;
}
static VOID SaveSettings(HWND hWndDlg)
{
HKEY hKeyRenderer;
HKEY hKeyDebug;
INT iSel = 0;
if (RegOpenKeyExW(HKEY_CURRENT_USER, KEY_RENDERER, 0, KEY_WRITE, &hKeyRenderer) != ERROR_SUCCESS)
return;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KEY_DEBUG_CHANNEL, 0, KEY_WRITE, &hKeyDebug) == ERROR_SUCCESS)
{
iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_DEBUG_OUTPUT, CB_GETCURSEL, 0, 0);
switch (iSel)
{
case DEBUG_SET:
RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"+opengl,+wgl", 13 * sizeof(WCHAR));
break;
case DEBUG_CLEAR:
RegSetValueExW(hKeyDebug, L"DEBUGCHANNEL", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
break;
}
RegCloseKey(hKeyDebug);
}
iSel = (INT)SendDlgItemMessageW(hWndDlg, IDC_RENDERER, CB_GETCURSEL, 0, 0);
switch (iSel)
{
case CB_ERR:
break;
case RENDERER_DEFAULT:
RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)L"", sizeof(WCHAR));
break;
case RENDERER_RSWR:
{
WCHAR szBuffer[MAX_KEY_LENGTH];
LoadString(hApplet, IDS_RENDERER_RSWR, (LPTSTR)szBuffer, 127);
RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR));
break;
}
default:
{
/* Adjustment for DEFAULT and RSWR renderers */
iSel -= 2;
if (iSel >= 0 && iSel <= dwNumDrivers)
RegSetValueExW(hKeyRenderer, L"", 0, REG_SZ, (PBYTE)pOglDrivers[iSel], (wcslen(pOglDrivers[iSel]) + 1) * sizeof(WCHAR));
break;
}
}
RegCloseKey(hKeyRenderer);
}
INT_PTR CALLBACK GeneralPageProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LPPSHNOTIFY lppsn;
switch (uMsg)
{
case WM_INITDIALOG:
InitSettings(hWndDlg);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_RENDERER || IDC_DEBUG_OUTPUT)
PropSheet_Changed(GetParent(hWndDlg), hWndDlg);
break;
case WM_NOTIFY:
lppsn = (LPPSHNOTIFY)lParam;
if (lppsn->hdr.code == PSN_APPLY)
{
SaveSettings(hWndDlg);
return TRUE;
}
break;
case WM_DESTROY:
{
INT iKey;
for (iKey = 0; iKey <= dwNumDrivers; iKey++)
HeapFree(GetProcessHeap(), 0, pOglDrivers[iKey]);
HeapFree(GetProcessHeap(), 0, pOglDrivers);
}
}
return FALSE;
}

View file

@ -0,0 +1,28 @@
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
IDD_PROPPAGEGENERAL DIALOGEX 0, 0, 246, 228
STYLE DS_SHELLFONT | WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "General"
FONT 8, "MS Shell Dlg"
BEGIN
ICON IDI_CPLICON, IDI_CPLICON, 8, 0, 21, 20
GROUPBOX "Renderer settings", -1, 5, 25, 230, 90
LTEXT "&Renderer:", -1, 15, 42, 37, 10
COMBOBOX IDC_RENDERER, 55, 40, 160, 10, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST
LTEXT "Choose a system wide renderer. This will override the default settings for your graphics driver! Choose ""Default"" if you want to go back to your original settings. Choose ""ReactOS Software Implementation"" if you want to use the built-in software renderer.", -1, 15, 60, 210, 40
GROUPBOX "Debugging", -1, 5, 125, 230, 90
LTEXT "DEBUGCHANNEL:", -1, 15, 142, 65, 10
COMBOBOX IDC_DEBUG_OUTPUT, 80, 140, 135, 10, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST
LTEXT "This will set the DEBUGCHANNEL environment variable to enable/disable debug output from opengl32.\n\nWARNING: Choosing ""Set"" or ""Clear"" will overwrite the content of the DEBUGCHANNEL environment variable!", -1, 15, 165, 210, 40
END
STRINGTABLE
BEGIN
IDS_RENDERER_DEFAULT "System default"
IDS_RENDERER_RSWR "ReactOS Software Implementation"
IDS_CPLNAME "OpenGL configuration"
IDS_CPLDESCRIPTION "Configures OpenGL renderer."
IDS_DEBUG_SET "set"
IDS_DEBUG_CLEAR "clear"
IDS_DEBUG_DNM "do not modify"
END

View file

@ -0,0 +1,78 @@
#include "openglcfg.h"
#include <cpl.h>
HINSTANCE hApplet = 0;
LONG CALLBACK AppletInit(HWND hWnd)
{
PROPSHEETPAGEW psp;
PROPSHEETHEADERW psh;
WCHAR szCaption[1024];
LoadStringW(hApplet, IDS_CPLNAME, szCaption, sizeof(szCaption) / sizeof(WCHAR));
ZeroMemory(&psp, sizeof(PROPSHEETPAGE));
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_DEFAULT;
psp.hInstance = hApplet;
psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGEGENERAL);
psp.pfnDlgProc = GeneralPageProc;
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE;
psh.hwndParent = hWnd;
psh.hInstance = hApplet;
psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLICON));
psh.pszCaption = szCaption;
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = &psp;
return (LONG)(PropertySheet(&psh) != -1);
}
LONG CALLBACK CPlApplet(HWND hWnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
switch (uMsg)
{
case CPL_INIT:
return TRUE;
case CPL_GETCOUNT:
return 1;
case CPL_INQUIRE:
{
CPLINFO *CPlInfo = (CPLINFO*)lParam2;
CPlInfo->lData = 0;
CPlInfo->idIcon = IDI_CPLICON;
CPlInfo->idInfo = IDS_CPLDESCRIPTION;
CPlInfo->idName = IDS_CPLNAME;
}
break;
case CPL_DBLCLK:
AppletInit(hWnd);
break;
}
return FALSE;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
hApplet = hinstDLL;
break;
}
return TRUE;
}

View file

@ -0,0 +1,30 @@
#ifndef _OPENGLCFG_PCH_
#define _OPENGLCFG_PCH_
#include <stdarg.h>
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <commctrl.h>
#include <strsafe.h>
#include "resource.h"
#define MAX_KEY_LENGTH 256
#define RENDERER_DEFAULT 0
#define RENDERER_RSWR 1
#define DEBUG_SET 1
#define DEBUG_CLEAR 2
#define KEY_RENDERER L"Software\\ReactOS\\OpenGL"
#define KEY_DRIVERS L"Software\\Microsoft\\Windows NT\\CurrentVersion\\OpenGLDrivers"
#define KEY_DEBUG_CHANNEL L"System\\CurrentControlSet\\Control\\Session Manager\\Environment"
INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern HINSTANCE hApplet;
#endif /* _OPENGLCFG_PCH_ */

View file

@ -0,0 +1,23 @@
#include <windef.h>
#include <winuser.h>
#include "resource.h"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#define REACTOS_VERSION_DLL
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS OpenGL Configuration Control Panel"
#define REACTOS_STR_INTERNAL_NAME "OpenGLcfg"
#define REACTOS_STR_ORIGINAL_FILENAME "OpenGLcfg.cpl"
#include <reactos/version.rc>
IDI_CPLICON ICON "resources/openglcfg.ico"
#include <reactos/manifest_hosted.rc>
/* UTF-8 */
#pragma code_page(65001)
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif

View file

@ -0,0 +1,2 @@
@ stdcall CPlApplet(ptr long ptr ptr)

View file

@ -0,0 +1,20 @@
#pragma once
/* Icons */
#define IDI_CPLICON 1
/* Dialogs */
#define IDD_PROPPAGEGENERAL 100
/* Controls */
#define IDC_RENDERER 1001
#define IDC_DEBUG_OUTPUT 1002
/* Strings */
#define IDS_CPLNAME 10000
#define IDS_CPLDESCRIPTION 10001
#define IDS_RENDERER_DEFAULT 10002
#define IDS_RENDERER_RSWR 10003
#define IDS_DEBUG_SET 10004
#define IDS_DEBUG_CLEAR 10005
#define IDS_DEBUG_DNM 10006

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB