DXGL r723 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r722‎ | r723 | r724 >
Date:02:54, 17 July 2017
Author:admin
Status:new
Tags:
Comment:
Parse all INI entries.
Add cfgmgr variables for debug modes.
Update inih README.md to commit 4b83b02
Modified paths:
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /cfgmgr/inih/README.md (modified) (history)
  • /dxgl-example.ini (modified) (history)

Diff [purge]

Index: cfgmgr/ReadMe.txt
@@ -282,6 +282,85 @@
283283 Valid settings:
284284 0 - Automatic
285285
 286+Default for all Debug variables is 0 or FALSE.
 287+
 288+Member DebugNoExtFramebuffer
 289+INI Entry DebugNoExtFramebuffer
 290+INI Group debug
 291+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoExtFramebuffer
 292+If nonzero, disables use of the EXT_framebuffer_object OpenGL extension.
 293+If both EXT_framebuffer_object and ARB_framebuffer_object are disabled or
 294+unavailable DXGL will fail to initialize.
 295+
 296+Member DebugNoArbFramebuffer
 297+INI Entry DebugNoArbFramebuffer
 298+INI Group debug
 299+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoArbFramebuffer
 300+If nonzero, disables use of the ARB_framebuffer_object OpenGL extension.
 301+If both EXT_framebuffer_object and ARB_framebuffer_object are disabled or
 302+unavailable DXGL will fail to initialize.
 303+
 304+Member DebugNoES2Compatibility
 305+INI Entry DebugNoES2Compatibility
 306+INI Group debug
 307+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoES2Compatibility
 308+If nonzero, disables use of the ARB_ES2_compatibility OpenGL extension.
 309+This will disable use of the 16-bit GL_RGB565 texture format which is part
 310+of OpenGL ES2 but not the desktop OpenGL standard.
 311+
 312+Member DebugNoExtDirectStateAccess
 313+INI Entry DebugNoExtDirectStateAccess
 314+INI Group debug
 315+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoExtDirectStateAccess
 316+If nonzero, disables use of the EXT_direct_state_access OpenGL extension which
 317+simplifies manipulation of certain types of OpenGL objects.
 318+
 319+Member DebugNoArbDirectStateAccess
 320+INI Entry DebugNoArbDirectStateAccess
 321+INI Group debug
 322+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoArbDirectStateAccess
 323+If nonzero, disables use of the ARB_direct_state_access OpenGL extension which
 324+simplifies manipulation of certain types of OpenGL objects.
 325+
 326+Member DebugNoSamplerObjects
 327+INI Entry DebugNoSamplerObjects
 328+INI Group debug
 329+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoSamplerObjects
 330+If nonzero, disables use of sampler objects, either via GL_ARB_sampler_objects
 331+or OpenGL version 3.3+. Disabling sampler objects reduces the accuracy of
 332+Direct3D content in some situations.
 333+
 334+Member DebugNoGpuShader4
 335+INI Entry DebugNoGpuShader4
 336+INI Group debug
 337+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoGpuShader4
 338+If nonzero, disables use of the EXT_gpu_shader4 extension on OpenGL 2.x cards.
 339+This will disable most raster operations in DirectDraw. This has no effect on
 340+OpenGL 3.0 or higher because the functionality is in core, unless DebugNoGLSL130
 341+is also enabled.
 342+
 343+Member DebugNoGLSL130
 344+INI Entry DebugNoGLSL130
 345+INI Group debug
 346+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugNoGLSL130
 347+If nonzero, disables use of GLSL version 1.30. When combined with
 348+DebugNoGpuShader4 this will disable raster operations in DirectDraw.
 349+
 350+Member DebugMaxGLVersionMajor
 351+INI Entry DebugMaxGLVersionMajor
 352+INI Group debug
 353+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugMaxGLVersionMajor
 354+If nonzero, sets the maximum OpenGL major version that DXGL will use,
 355+and uses the value from DebugMaxGLVersionMinor.
 356+
 357+Member DebugMaxGLVersionMinor
 358+INI Entry DebugMaxGLVersionMinor
 359+INI Group debug
 360+REG_DWORD HKCU\DXGL\Profiles\<app>\DebugMaxGLVersionMinor
 361+If DebugMaxGLVersionMajor is nonzero, sets the maximum OpenGL minor version
 362+that DXGL will use, unless the actual major version is less than
 363+DebugMaxGLVersionMajor.
 364+
286365 Member Windows8Detected
287366 Not in INI file
288367 REG_DWORD HKCU\DXGL\Global\Windows8Detected
@@ -290,3 +369,18 @@
291370 Global key is set to 1 and Windows8Detected is also set to 1.
292371 If nonzero, AllColorDepths is not affected.
293372
 373+Member PasrsedAddColorDepths
 374+Not in INI file
 375+Not in registry
 376+Nonzero if the INI parser has read the AddColorDepths entry.
 377+This prevents the AddColorDepths variable from being overridden by
 378+AllColorDepths. If zero, the AllColorDepths INI entry will overwrite the
 379+AddColorDepths configuration variable.
 380+
 381+Member ParsedAddModes
 382+Not in INI file
 383+Not in registry
 384+Nonzero if the INI parser has read the AddModes entry.
 385+This prevents the AddModes variable from being overridden by ExtraModes.
 386+If zero, the ExtraModes INI entry will overwrite the AddModes configuration
 387+variable.
\ No newline at end of file
Index: cfgmgr/cfgmgr.c
@@ -776,13 +776,47 @@
777777
778778 DWORD INIBoolValue(const char *value)
779779 {
780 - DWORD ret = 1;
781 - if (value[0] == 'F') ret = 0;
782 - if (value[0] == 'f') ret = 0;
783 - if (value[0] == '0') ret = 0;
784 - return ret;
 780+ if (value[0] == 'F') return 0;
 781+ if (value[0] == 'f') return 0;
 782+ if (!atoi(value)) return 0;
 783+ return 1;
785784 }
786785
 786+DWORD INIIntValue(const char *value)
 787+{
 788+ return atoi(value);
 789+}
 790+
 791+DWORD INIHexValue(const char *value)
 792+{
 793+ return (DWORD)strtoul(value, NULL, 0);
 794+}
 795+
 796+float INIAspectValue(const char *value)
 797+{
 798+ char *ptr;
 799+ float numerator, denominator;
 800+ if (!strcmp(value, "Default")) return 0.0f;
 801+ else
 802+ {
 803+ // Check for colon
 804+ ptr = strstr(value, ":");
 805+ if (ptr)
 806+ {
 807+ *ptr = 0;
 808+ numerator = atof(value);
 809+ denominator = atof(ptr + 1);
 810+ return numerator / denominator;
 811+ }
 812+ else return atof(value);
 813+ }
 814+}
 815+
 816+float INIFloatValue(const char *value)
 817+{
 818+ return (float)atof(value);
 819+}
 820+
787821 int ReadINICallback(DXGLCFG *cfg, const char *section, const char *name,
788822 const char *value)
789823 {
@@ -789,12 +823,84 @@
790824 if (!stricmp(section, "system"))
791825 {
792826 if (!stricmp(name, "NoWriteRegistry")) cfg->NoWriteRegistry = INIBoolValue(value);
793 - if (!stricmp(name, "OverrideDefaults"))cfg->OverrideDefaults = INIBoolValue(value);
 827+ if (!stricmp(name, "OverrideDefaults")) cfg->OverrideDefaults = INIBoolValue(value);
794828 }
795829 if (!stricmp(section, "display"))
796830 {
797 -
 831+ if (!stricmp(name, "ScalingMode")) cfg->scaler = INIIntValue(value);
 832+ if (!stricmp(name, "FullscreenWindowMode")) cfg->fullmode = INIIntValue(value);
 833+ if (!stricmp(name, "ChangeColorDepth")) cfg->colormode = INIBoolValue(value);
 834+ if (!stricmp(name, "AllColorDepths"))
 835+ {
 836+ if (!cfg->ParsedAddColorDepths)
 837+ {
 838+ if (INIBoolValue(value)) cfg->AddColorDepths = 1 | 4 | 16;
 839+ else cfg->AddColorDepths = 0;
 840+ }
 841+ }
 842+ if (!stricmp(name, "AddColorDepths"))
 843+ {
 844+ cfg->ParsedAddColorDepths = TRUE;
 845+ cfg->AddColorDepths = INIIntValue(value);
 846+ }
 847+ if (!stricmp(name, "ExtraModes"))
 848+ {
 849+ if (!cfg->ParsedAddModes)
 850+ {
 851+ if (INIBoolValue(value)) cfg->AddModes = 7;
 852+ else cfg->AddModes = 0;
 853+ }
 854+ }
 855+ if (!stricmp(name, "AddModes"))
 856+ {
 857+ cfg->ParsedAddModes = TRUE;
 858+ cfg->AddModes = INIIntValue(value);
 859+ }
 860+ if (!stricmp(name, "SortModes")) cfg->SortModes = INIIntValue(value);
798861 }
 862+ if (!stricmp(section, "scaling"))
 863+ {
 864+ if (!stricmp(name, "ScalingFilter")) cfg->scalingfilter = INIIntValue(value);
 865+ if (!stricmp(name, "AdjustPrimaryResolution")) cfg->primaryscale = INIIntValue(value);
 866+ if (!stricmp(name, "PrimaryScaleX")) cfg->primaryscalex = INIFloatValue(value);
 867+ if (!stricmp(name, "PrimaryScaleY")) cfg->primaryscaley = INIFloatValue(value);
 868+ if (!stricmp(name, "ScreenAspect")) cfg->aspect = INIAspectValue(value);
 869+ if (!stricmp(name, "DPIScale")) cfg->DPIScale = INIIntValue(value);
 870+ }
 871+ if (!stricmp(section, "postprocess"))
 872+ {
 873+ if (!stricmp(name, "PostprocessFilter")) cfg->postfilter = INIIntValue(value);
 874+ if (!stricmp(name, "PostprocessScaleX")) cfg->postsizex = INIFloatValue(value);
 875+ if (!stricmp(name, "PostprocessScaleY")) cfg->postsizex = INIFloatValue(value);
 876+ if (!stricmp(name, "EnableShader")) cfg->EnableShader = INIBoolValue(value);
 877+ if (!stricmp(name, "ShaderFile")) strncpy(cfg->shaderfile, value, MAX_PATH);
 878+ }
 879+ if (!stricmp(section, "d3d"))
 880+ {
 881+ if (!stricmp(name, "TextureFilter")) cfg->texfilter = INIIntValue(value);
 882+ if (!stricmp(name, "AnisotropicFiltering")) cfg->anisotropic = INIIntValue(value);
 883+ if (!stricmp(name, "Antialiasing")) cfg->msaa = INIHexValue(value);
 884+ if (!stricmp(name, "D3DAspect")) cfg->aspect3d = INIIntValue(value);
 885+ }
 886+ if (!stricmp(section, "advanced"))
 887+ {
 888+ if (!stricmp(name, "VSync")) cfg->vsync = INIIntValue(value);
 889+ if (!stricmp(name, "TextureFormat")) cfg->TextureFormat = INIIntValue(value);
 890+ if (!stricmp(name, "TexUpload")) cfg->TexUpload = INIIntValue(value);
 891+ }
 892+ if (!stricmp(section, "debug"))
 893+ {
 894+ if (!stricmp(name, "DebugNoExtFramebuffer")) cfg->DebugNoExtFramebuffer = INIBoolValue(value);
 895+ if (!stricmp(name, "DebugNoArbFramebuffer")) cfg->DebugNoArbFramebuffer = INIBoolValue(value);
 896+ if (!stricmp(name, "DebugNoES2Compatibility")) cfg->DebugNoES2Compatibility = INIBoolValue(value);
 897+ if (!stricmp(name, "DebugNoExtDirectStateAccess")) cfg->DebugNoExtDirectStateAccess = INIBoolValue(value);
 898+ if (!stricmp(name, "DebugNoArbDirectStateAccess")) cfg->DebugNoArbDirectStateAccess = INIBoolValue(value);
 899+ if (!stricmp(name, "DebugNoSamplerObjects")) cfg->DebugNoSamplerObjects = INIBoolValue(value);
 900+ if (!stricmp(name, "DebugNoGpuShader4")) cfg->DebugNoGpuShader4 = INIBoolValue(value);
 901+ if (!stricmp(name, "DebugNoGLSL130")) cfg->DebugNoGLSL130 = INIBoolValue(value);
 902+ if (!stricmp(name, "DebugMaxGLVersionMajor")) cfg->DebugMaxGLVersionMajor = INIIntValue(value);
 903+ if (!stricmp(name, "DebugMaxGLVersionMinor")) cfg->DebugMaxGLVersionMinor = INIIntValue(value);
 904+ }
799905 return 1;
800906 }
801907
@@ -806,7 +912,11 @@
807913 GetDirFromPath(inipath);
808914 _tcscat(inipath, _T("\\dxgl.ini"));
809915 file = _tfopen(inipath, _T("r"));
810 - if (file) ini_parse_file(file, ReadINICallback, cfg);
 916+ if (file)
 917+ {
 918+ ini_parse_file(file, ReadINICallback, cfg);
 919+ fclose(file);
 920+ }
811921 }
812922
813923 void GetCurrentConfig(DXGLCFG *cfg, BOOL initial)
Index: cfgmgr/cfgmgr.h
@@ -57,8 +57,21 @@
5858 DWORD vsync;
5959 DWORD TextureFormat;
6060 DWORD TexUpload;
 61+ // [debug]
 62+ BOOL DebugNoExtFramebuffer;
 63+ BOOL DebugNoArbFramebuffer;
 64+ BOOL DebugNoES2Compatibility;
 65+ BOOL DebugNoExtDirectStateAccess;
 66+ BOOL DebugNoArbDirectStateAccess;
 67+ BOOL DebugNoSamplerObjects;
 68+ BOOL DebugNoGpuShader4;
 69+ BOOL DebugNoGLSL130;
 70+ DWORD DebugMaxGLVersionMajor;
 71+ DWORD DebugMaxGLVersionMinor;
6172 // internal
6273 BOOL Windows8Detected;
 74+ BOOL ParsedAddColorDepths;
 75+ BOOL ParsedAddModes;
6376 } DXGLCFG;
6477
6578 typedef struct
Index: cfgmgr/inih/README.md
@@ -104,3 +104,8 @@
105105
106106 * INI name=value pairs given above any section headers are treated as valid items with no section (section name is an empty string). In ConfigParser having no section is an error.
107107 * Line continuations are handled with leading whitespace on continued lines (like ConfigParser). However, instead of concatenating continued lines together, they are treated as separate values for the same key (unlike ConfigParser).
 108+
 109+
 110+## Platform-specific notes ##
 111+
 112+* Windows/Win32 uses UTF-16 filenames natively, so to handle Unicode paths you need to call `_wfopen()` to open a file and then `ini_parse_file()` to parse it; inih does not include `wchar_t` or Unicode handling.
Index: dxgl-example.ini
@@ -60,7 +60,7 @@
6161 ; AllColorDepths - Boolean
6262 ; Adds 8, 16, 24, and 32-bit color modes if they are not already
6363 ; added to the list of display modes passed to the program.
64 -; (future)Equivalent to setting AddColorDepths to 29.
 64+; (future)Equivalent to setting AddColorDepths to 21.
6565 ; (future)Overridden by AddColorDepths.
6666 ; Default is true if Windows 8 or higher is detected, false otherwise.
6767 AllColorDepths = true
@@ -75,10 +75,10 @@
7676 ; 4 - Add 16-bit modes
7777 ; 8 - Add 24-bit modes
7878 ; 16 - Add 32-bit modes
79 -; Default is 29 if Windows 8 or higher is detected, 0 otherwise.
 79+; Default is 21 if Windows 8 or higher is detected, 0 otherwise.
8080 ; Adding both 15 and 16 bit modes at the same time may cause
8181 ; crashes or undefined behavior in some programs.
82 -AddColorDepths = 29
 82+AddColorDepths = 21
8383
8484 ; ExtraModes - Boolean
8585 ; Adds additional video modes to the list of resolutions.
@@ -137,7 +137,7 @@
138138 ; The following will be added in the future:
139139 ; 2 - Adjust primary surface to nearest integer multiple of native.
140140 ; 3 - Use exact 1.5x scale.
141 -; 4 - Use exact 2x scale.
 141+ ; 4 - Use exact 2x scale.
142142 ; 5 - Use exact 2.5x scale.
143143 ; 6 - Use exact 3x scale.
144144 ; 7 - Use exact 4x scale.