Move Windows WGL context attributes to renderer gl
This commit is contained in:
27
src/main.cpp
27
src/main.cpp
@@ -974,28 +974,7 @@ int main(int argc, char** argv)
|
||||
// If supported create a 3.3 context
|
||||
if (GLAD_WGL_ARB_create_context)
|
||||
{
|
||||
int contex_attribs[] =
|
||||
{
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
0
|
||||
};
|
||||
int pixel_attribs[] =
|
||||
{
|
||||
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
|
||||
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
|
||||
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
|
||||
WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
|
||||
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
||||
WGL_COLOR_BITS_ARB, 24,
|
||||
WGL_DEPTH_BITS_ARB, 16,
|
||||
//WGL_STENCIL_BITS_ARB, 8,
|
||||
//WGL_SAMPLE_BUFFERS_ARB, 1, // Number of buffers (must be 1 at time of writing)
|
||||
//WGL_SAMPLES_ARB, 4, // Number of samples
|
||||
0
|
||||
};
|
||||
const auto wgl_config = pp::renderer::gl::windows_wgl_core_context_3_3_config();
|
||||
UINT numFormat;
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
@@ -1007,9 +986,9 @@ int main(int argc, char** argv)
|
||||
(float)(clientRect.bottom - clientRect.top), 0, 0, hInst, 0);
|
||||
|
||||
hDC = GetDC(hWnd);
|
||||
wglChoosePixelFormatARB(hDC, pixel_attribs, nullptr, 1, &pxfmt, &numFormat);
|
||||
wglChoosePixelFormatARB(hDC, wgl_config.pixel_format_attributes.data(), nullptr, 1, &pxfmt, &numFormat);
|
||||
SetPixelFormat(hDC, pxfmt, &pfd);
|
||||
hRC = wglCreateContextAttribsARB(hDC, NULL, contex_attribs);
|
||||
hRC = wglCreateContextAttribsARB(hDC, NULL, wgl_config.context_attributes.data());
|
||||
wglMakeCurrent(hDC, hRC);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -114,6 +114,21 @@ constexpr std::uint32_t gl_stream_read = 0x88E1U;
|
||||
constexpr std::uint32_t gl_map_read_bit = 0x0001U;
|
||||
constexpr std::uint8_t gl_boolean_false = 0U;
|
||||
constexpr std::uint8_t gl_boolean_true = 1U;
|
||||
constexpr std::int32_t wgl_draw_to_window_arb = 0x2001;
|
||||
constexpr std::int32_t wgl_acceleration_arb = 0x2003;
|
||||
constexpr std::int32_t wgl_support_opengl_arb = 0x2010;
|
||||
constexpr std::int32_t wgl_double_buffer_arb = 0x2011;
|
||||
constexpr std::int32_t wgl_pixel_type_arb = 0x2013;
|
||||
constexpr std::int32_t wgl_color_bits_arb = 0x2014;
|
||||
constexpr std::int32_t wgl_depth_bits_arb = 0x2022;
|
||||
constexpr std::int32_t wgl_full_acceleration_arb = 0x2027;
|
||||
constexpr std::int32_t wgl_type_rgba_arb = 0x202B;
|
||||
constexpr std::int32_t wgl_context_major_version_arb = 0x2091;
|
||||
constexpr std::int32_t wgl_context_minor_version_arb = 0x2092;
|
||||
constexpr std::int32_t wgl_context_flags_arb = 0x2094;
|
||||
constexpr std::int32_t wgl_context_forward_compatible_bit_arb = 0x0002;
|
||||
constexpr std::int32_t wgl_context_profile_mask_arb = 0x9126;
|
||||
constexpr std::int32_t wgl_context_core_profile_bit_arb = 0x00000001;
|
||||
|
||||
[[nodiscard]] bool contains(std::string_view text, std::string_view needle) noexcept
|
||||
{
|
||||
@@ -741,4 +756,27 @@ std::uint32_t sampler_border_color_parameter_name() noexcept
|
||||
return gl_texture_border_color;
|
||||
}
|
||||
|
||||
OpenGlWindowsWglContextConfig windows_wgl_core_context_3_3_config() noexcept
|
||||
{
|
||||
return {
|
||||
.context_attributes = {
|
||||
wgl_context_major_version_arb, 3,
|
||||
wgl_context_minor_version_arb, 3,
|
||||
wgl_context_flags_arb, wgl_context_forward_compatible_bit_arb,
|
||||
wgl_context_profile_mask_arb, wgl_context_core_profile_bit_arb,
|
||||
0,
|
||||
},
|
||||
.pixel_format_attributes = {
|
||||
wgl_draw_to_window_arb, static_cast<std::int32_t>(gl_boolean_true),
|
||||
wgl_support_opengl_arb, static_cast<std::int32_t>(gl_boolean_true),
|
||||
wgl_double_buffer_arb, static_cast<std::int32_t>(gl_boolean_true),
|
||||
wgl_acceleration_arb, wgl_full_acceleration_arb,
|
||||
wgl_pixel_type_arb, wgl_type_rgba_arb,
|
||||
wgl_color_bits_arb, 24,
|
||||
wgl_depth_bits_arb, 16,
|
||||
0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ struct OpenGlReadbackFormat {
|
||||
std::uint32_t bytes_per_pixel = 0;
|
||||
};
|
||||
|
||||
struct OpenGlWindowsWglContextConfig {
|
||||
std::array<std::int32_t, 9> context_attributes {};
|
||||
std::array<std::int32_t, 15> pixel_format_attributes {};
|
||||
};
|
||||
|
||||
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
@@ -141,5 +146,6 @@ struct OpenGlReadbackFormat {
|
||||
std::uint32_t filter_min,
|
||||
std::uint32_t filter_mag) noexcept;
|
||||
[[nodiscard]] std::uint32_t sampler_border_color_parameter_name() noexcept;
|
||||
[[nodiscard]] OpenGlWindowsWglContextConfig windows_wgl_core_context_3_3_config() noexcept;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user