From 6eca70a5297652a90eb7e50360178a10b56eba0f Mon Sep 17 00:00:00 2001 From: jpark37 Date: Thu, 12 Sep 2019 21:28:26 -0700 Subject: [PATCH] libobs-opengl: Require OpenGL 3.3 instead of 3.2 There don't appear to be any GPUs that support 3.2, but not 3.3. GLSL 330 maps to HLSL Shader Model 4, so this will theoretically make shaders programs less likely to diverge, particularly for behavior around NaNs. --- libobs-opengl/gl-shaderparser.c | 2 +- libobs-opengl/gl-subsystem.c | 32 ++++++++++----------- libobs-opengl/gl-windows.c | 50 +++++++++++++++++---------------- libobs-opengl/gl-x11.c | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/libobs-opengl/gl-shaderparser.c b/libobs-opengl/gl-shaderparser.c index d952899c9..f66e85258 100644 --- a/libobs-opengl/gl-shaderparser.c +++ b/libobs-opengl/gl-shaderparser.c @@ -692,7 +692,7 @@ static bool gl_shader_buildstring(struct gl_shader_parser *glsp) return false; } - dstr_copy(&glsp->gl_string, "#version 150\n\n"); + dstr_copy(&glsp->gl_string, "#version 330\n\n"); dstr_cat(&glsp->gl_string, "const bool obs_glsl_compile = true;\n\n"); gl_write_params(glsp); gl_write_inputs(glsp, main_func); diff --git a/libobs-opengl/gl-subsystem.c b/libobs-opengl/gl-subsystem.c index e9c986fb0..76c54ad75 100644 --- a/libobs-opengl/gl-subsystem.c +++ b/libobs-opengl/gl-subsystem.c @@ -130,23 +130,15 @@ static void gl_enable_debug() {} static bool gl_init_extensions(struct gs_device *device) { - if (!GLAD_GL_VERSION_2_1) { - blog(LOG_ERROR, "obs-studio requires OpenGL version 2.1 or " - "higher."); + if (!GLAD_GL_VERSION_3_3) { + blog(LOG_ERROR, + "obs-studio requires OpenGL version 3.3 or higher."); return false; } gl_enable_debug(); - if (!GLAD_GL_VERSION_3_0 && !GLAD_GL_ARB_framebuffer_object) { - blog(LOG_ERROR, "OpenGL extension ARB_framebuffer_object " - "is required."); - return false; - } - - if (GLAD_GL_VERSION_3_2 || GLAD_GL_ARB_seamless_cube_map) { - gl_enable(GL_TEXTURE_CUBE_MAP_SEAMLESS); - } + gl_enable(GL_TEXTURE_CUBE_MAP_SEAMLESS); if (GLAD_GL_VERSION_4_3 || GLAD_GL_ARB_copy_image) device->copy_type = COPY_TYPE_ARB; @@ -182,8 +174,11 @@ void convert_sampler_info(struct gs_sampler_state *sampler, sampler->max_anisotropy = info->max_anisotropy; max_anisotropy_max = 1; - glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy_max); - gl_success("glGetIntegerv(GL_MAX_TEXTURE_ANISOTROPY_MAX)"); + if (GLAD_GL_EXT_texture_filter_anisotropic) { + glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, + &max_anisotropy_max); + gl_success("glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)"); + } if (1 <= sampler->max_anisotropy && sampler->max_anisotropy <= max_anisotropy_max) @@ -475,9 +470,12 @@ static bool load_texture_sampler(gs_texture_t *tex, gs_samplerstate_t *ss) success = false; if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_WRAP_R, ss->address_w)) success = false; - if (!gl_tex_param_i(tex->gl_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, - ss->max_anisotropy)) - success = false; + if (GLAD_GL_EXT_texture_filter_anisotropic) { + if (!gl_tex_param_i(tex->gl_target, + GL_TEXTURE_MAX_ANISOTROPY_EXT, + ss->max_anisotropy)) + success = false; + } apply_swizzle(tex); diff --git a/libobs-opengl/gl-windows.c b/libobs-opengl/gl-windows.c index 3b2e9cd1b..3326e0143 100644 --- a/libobs-opengl/gl-windows.c +++ b/libobs-opengl/gl-windows.c @@ -154,35 +154,37 @@ static inline HGLRC gl_init_basic_context(HDC hdc) return hglrc; } -static const int attribs[] = { -#ifdef _DEBUG - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, -#endif - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 0, 0}; - static inline HGLRC gl_init_context(HDC hdc) { + static const int attribs[] = { #ifdef _DEBUG - if (GLAD_WGL_ARB_create_context) { - HGLRC hglrc = wglCreateContextAttribsARB(hdc, 0, attribs); - if (!hglrc) { - blog(LOG_ERROR, - "wglCreateContextAttribsARB failed, " - "%lu", - GetLastError()); - return NULL; - } - - if (!wgl_make_current(hdc, hglrc)) { - wglDeleteContext(hglrc); - return NULL; - } - - return hglrc; - } + WGL_CONTEXT_FLAGS_ARB, + WGL_CONTEXT_DEBUG_BIT_ARB, #endif + WGL_CONTEXT_PROFILE_MASK_ARB, + WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + WGL_CONTEXT_MAJOR_VERSION_ARB, + 3, + WGL_CONTEXT_MINOR_VERSION_ARB, + 3, + 0, + 0}; - return gl_init_basic_context(hdc); + HGLRC hglrc = wglCreateContextAttribsARB(hdc, 0, attribs); + if (!hglrc) { + blog(LOG_ERROR, + "wglCreateContextAttribsARB failed, " + "%lu", + GetLastError()); + return NULL; + } + + if (!wgl_make_current(hdc, hglrc)) { + wglDeleteContext(hglrc); + return NULL; + } + + return hglrc; } static bool gl_dummy_context_init(struct dummy_context *dummy) diff --git a/libobs-opengl/gl-x11.c b/libobs-opengl/gl-x11.c index ae35be9a9..07e1dbbf3 100644 --- a/libobs-opengl/gl-x11.c +++ b/libobs-opengl/gl-x11.c @@ -50,7 +50,7 @@ static const int ctx_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, - 2, + 3, None, };