//
// sub_1800D7320 from 0x1800d7320 to 0x1800d792b (1547 bytes)
//
// 2 xrefs:
// > sub_1800D7E10 @ 0x1800d7ec4
// > ??> @ 0x1801c4908
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:22:33 +0000
//
__int64 __fastcall sub_1800D7320(__int64 a1, _DWORD *a2)
{
const char *v3; // rbp
__int64 v4; // r14
__int64 v6; // rbx
__int64 v7; // rax
__int64 v8; // rdx
__int64 (__fastcall *v9)(__int64); // rax
char *v10; // r15
const char *v11; // rdx
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // r8
size_t v15; // rsi
const char *v16; // rdx
__int64 v17; // rax
bool v18; // zf
int v19; // ecx
__int64 v20; // r8
__int64 v21; // rax
char v22; // al
int v23; // eax
char *v24; // rcx
void (__fastcall *v25)(__int64); // rax
__int64 v27; // rax
__int64 v28; // rdx
const char *v29; // rdx
__int64 v30; // [rsp+20h] [rbp-68h]
int v31; // [rsp+30h] [rbp-58h] BYREF
const char *v32; // [rsp+38h] [rbp-50h]
_QWORD v33[3]; // [rsp+40h] [rbp-48h]
v33[0] = "OpenGL ES-CL ";
v3 = "OpenGL ES-CM ";
v32 = "OpenGL ES-CM ";
v33[1] = "OpenGL ES ";
v4 = 0;
*(_DWORD *)(a1 + 516) = a2[1];
*(_DWORD *)(a1 + 512) = 196609;
v33[2] = 0;
v6 = sub_1800DE110(&unk_1801B520C);
if ( *(_DWORD *)&ModuleName )
{
v7 = sub_1800DE110(&unk_1801B520C);
v8 = v7;
if ( *(_DWORD *)(a1 + 512) )
{
if ( v7 && *(_DWORD *)(a1 + 516) != *(_DWORD *)(v7 + 516) )
(*(void (__fastcall **)(_QWORD))(v7 + 584))(0);
(*(void (__fastcall **)(__int64, __int64))(a1 + 584))(a1, v8);
}
else
{
sub_1800DB260(65546, "Cannot make current with a window that has no OpenGL or OpenGL ES context");
}
}
else
{
sub_1800DB260(65537, nullptr);
}
if ( sub_1800DE110(&unk_1801B520C) != a1 )
return 0;
*(_QWORD *)(a1 + 568) = (*(__int64 (__fastcall **)(const char *))(a1 + 616))("glGetIntegerv");
v9 = (__int64 (__fastcall *)(__int64))(*(__int64 (__fastcall **)(const char *))(a1 + 616))("glGetString");
*(_QWORD *)(a1 + 576) = v9;
if ( *(_QWORD *)(a1 + 568) && v9 )
{
v10 = (char *)v9(7938);
if ( !v10 )
{
v11 = "OpenGL version string retrieval is broken";
if ( *a2 != 196609 )
v11 = "OpenGL ES version string retrieval is broken";
sub_1800DB260(65544, v11);
if ( *(_DWORD *)&ModuleName )
{
v12 = sub_1800DE110(&unk_1801B520C);
v14 = v12;
if ( !v6 || *(_DWORD *)(v6 + 512) )
{
if ( v12 )
{
if ( v6 && *(_DWORD *)(v6 + 516) == *(_DWORD *)(v12 + 516) )
goto LABEL_101;
(*(void (__fastcall **)(_QWORD))(v12 + 584))(0);
}
goto LABEL_100;
}
LABEL_95:
sub_1800DB260(65546, "Cannot make current with a window that has no OpenGL or OpenGL ES context", v14);
return 0;
}
LABEL_41:
sub_1800DB260(65537, nullptr);
return 0;
}
while ( 1 )
{
v15 = -1;
do
++v15;
while ( v3[v15] );
if ( !strncmp(v10, v3, v15) )
break;
v3 = (const char *)v33[v4++];
if ( !v3 )
goto LABEL_28;
}
v10 += v15;
*(_DWORD *)(a1 + 512) = 196610;
LABEL_28:
if ( !sub_18004F430(v10, "%d.%d.%d", a1 + 520, a1 + 524, a1 + 528) )
{
v16 = "No version found in OpenGL version string";
if ( *(_DWORD *)(a1 + 512) != 196609 )
v16 = "No version found in OpenGL ES version string";
sub_1800DB260(65544, v16);
if ( !*(_DWORD *)&ModuleName )
goto LABEL_41;
LABEL_32:
v17 = sub_1800DE110(&unk_1801B520C);
v13 = v17;
if ( !v6 )
goto LABEL_96;
v18 = *(_DWORD *)(v6 + 512) == 0;
goto LABEL_94;
}
v19 = *(_DWORD *)(a1 + 520);
v20 = (unsigned int)a2[2];
if ( v19 < (int)v20 || v19 == (_DWORD)v20 && *(_DWORD *)(a1 + 524) < a2[3] )
{
v29 = "Requested OpenGL version %i.%i, got version %i.%i";
if ( *(_DWORD *)(a1 + 512) != 196609 )
v29 = "Requested OpenGL ES version %i.%i, got version %i.%i";
LODWORD(v30) = *(_DWORD *)(a1 + 520);
sub_1800DB260(65543, v29, v20, (unsigned int)a2[3], v30, *(_DWORD *)(a1 + 524));
LABEL_40:
if ( !*(_DWORD *)&ModuleName )
goto LABEL_41;
goto LABEL_32;
}
if ( v19 >= 3 )
{
v21 = (*(__int64 (__fastcall **)(const char *))(a1 + 616))("glGetStringi");
*(_QWORD *)(a1 + 560) = v21;
if ( !v21 )
{
sub_1800DB260(65544, "Entry point retrieval is broken");
goto LABEL_40;
}
}
if ( *(_DWORD *)(a1 + 512) != 196609 )
{
v24 = "GL_EXT_robustness";
goto LABEL_64;
}
if ( *(int *)(a1 + 520) < 3 )
{
LABEL_53:
v23 = *(_DWORD *)(a1 + 520);
if ( v23 >= 4 || v23 == 3 && *(int *)(a1 + 524) >= 2 )
{
(*(void (__fastcall **)(__int64, int *))(a1 + 568))(37158, &v31);
if ( (v31 & 2) != 0 )
goto LABEL_61;
if ( (v31 & 1) != 0 )
{
*(_DWORD *)(a1 + 544) = 204801;
v24 = "GL_ARB_robustness";
goto LABEL_64;
}
if ( (unsigned int)sub_1800D79A0("GL_ARB_compatibility") )
LABEL_61:
*(_DWORD *)(a1 + 544) = 204802;
}
v24 = "GL_ARB_robustness";
LABEL_64:
if ( (unsigned int)sub_1800D79A0(v24) )
{
(*(void (__fastcall **)(__int64, int *))(a1 + 568))(33366, &v31);
if ( v31 == 33362 )
{
*(_DWORD *)(a1 + 548) = 200706;
}
else if ( v31 == 33377 )
{
*(_DWORD *)(a1 + 548) = 200705;
}
}
if ( (unsigned int)sub_1800D79A0("GL_KHR_context_flush_control") )
{
(*(void (__fastcall **)(__int64, int *))(a1 + 568))(33531, &v31);
if ( v31 )
{
if ( v31 == 33532 )
*(_DWORD *)(a1 + 552) = 217089;
}
else
{
*(_DWORD *)(a1 + 552) = 217090;
}
}
v25 = (void (__fastcall *)(__int64))(*(__int64 (__fastcall **)(const char *))(a1 + 616))("glClear");
v25(0x4000);
if ( *(_DWORD *)(a1 + 40) )
(*(void (__fastcall **)(__int64))(a1 + 592))(a1);
if ( !*(_DWORD *)&ModuleName )
{
sub_1800DB260(65537, nullptr);
return 1;
}
v27 = sub_1800DE110(&unk_1801B520C);
v28 = v27;
if ( v6 && !*(_DWORD *)(v6 + 512) )
{
sub_1800DB260(65546, "Cannot make current with a window that has no OpenGL or OpenGL ES context");
return 1;
}
if ( v27 )
{
if ( v6 && *(_DWORD *)(v6 + 516) == *(_DWORD *)(v27 + 516) )
goto LABEL_86;
(*(void (__fastcall **)(_QWORD))(v27 + 584))(0);
}
if ( !v6 )
return 1;
LABEL_86:
(*(void (__fastcall **)(__int64, __int64))(v6 + 584))(v6, v28);
return 1;
}
(*(void (__fastcall **)(__int64, int *))(a1 + 568))(33310, &v31);
v22 = v31;
if ( (v31 & 1) != 0 )
*(_DWORD *)(a1 + 532) = 1;
if ( (v22 & 2) == 0 )
{
if ( !(unsigned int)sub_1800D79A0("GL_ARB_debug_output") || !a2[5] )
{
v22 = v31;
LABEL_51:
if ( (v22 & 8) != 0 )
*(_DWORD *)(a1 + 540) = 1;
goto LABEL_53;
}
v22 = v31;
}
*(_DWORD *)(a1 + 536) = 1;
goto LABEL_51;
}
sub_1800DB260(65544, "Entry point retrieval is broken");
if ( !*(_DWORD *)&ModuleName )
goto LABEL_41;
v17 = sub_1800DE110(&unk_1801B520C);
v13 = v17;
if ( v6 )
{
v18 = *(_DWORD *)(v6 + 512) == 0;
LABEL_94:
if ( v18 )
goto LABEL_95;
}
LABEL_96:
if ( v13 )
{
if ( v6 && *(_DWORD *)(v6 + 516) == *(_DWORD *)(v17 + 516) )
goto LABEL_101;
(*(void (__fastcall **)(_QWORD))(v13 + 584))(0);
}
LABEL_100:
if ( v6 )
LABEL_101:
(*(void (__fastcall **)(__int64, __int64, __int64))(v6 + 584))(v6, v13, v14);
return 0;
}