diff --git a/source/graphics/ShaderProgram.cpp b/source/graphics/ShaderProgram.cpp index 60760ac319..0a92a26870 100644 --- a/source/graphics/ShaderProgram.cpp +++ b/source/graphics/ShaderProgram.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -270,8 +270,8 @@ public: m_VertexAttribs(vertexAttribs) { m_Program = 0; - m_VertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER); - m_FragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER); + m_VertexShader = glCreateShader(GL_VERTEX_SHADER); + m_FragmentShader = glCreateShader(GL_FRAGMENT_SHADER); m_FileDependencies = {m_VertexFile, m_FragmentFile}; } @@ -291,9 +291,9 @@ public: const char* code_string = code.c_str(); GLint code_length = code.length(); - glShaderSourceARB(shader, 1, &code_string, &code_length); + glShaderSource(shader, 1, &code_string, &code_length); - glCompileShaderARB(shader); + glCompileShader(shader); GLint ok = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); @@ -329,20 +329,20 @@ public: TIMER_ACCRUE(tc_ShaderGLSLLink); ENSURE(!m_Program); - m_Program = glCreateProgramObjectARB(); + m_Program = glCreateProgram(); - glAttachObjectARB(m_Program, m_VertexShader); + glAttachShader(m_Program, m_VertexShader); ogl_WarnIfError(); - glAttachObjectARB(m_Program, m_FragmentShader); + glAttachShader(m_Program, m_FragmentShader); ogl_WarnIfError(); // Set up the attribute bindings explicitly, since apparently drivers // don't always pick the most efficient bindings automatically, // and also this lets us hardcode indexes into VertexPointer etc for (std::map::iterator it = m_VertexAttribs.begin(); it != m_VertexAttribs.end(); ++it) - glBindAttribLocationARB(m_Program, it->second, it->first.c_str()); + glBindAttribLocation(m_Program, it->second, it->first.c_str()); - glLinkProgramARB(m_Program); + glLinkProgram(m_Program); GLint ok = 0; glGetProgramiv(m_Program, GL_LINK_STATUS, &ok); @@ -387,10 +387,10 @@ public: GLsizei nameLength = 0; GLint size = 0; GLenum type = 0; - glGetActiveUniformARB(m_Program, i, ARRAY_SIZE(name), &nameLength, &size, &type, name); + glGetActiveUniform(m_Program, i, ARRAY_SIZE(name), &nameLength, &size, &type, name); ogl_WarnIfError(); - GLint loc = glGetUniformLocationARB(m_Program, name); + GLint loc = glGetUniformLocation(m_Program, name); CStrIntern nameIntern(name); m_Uniforms[nameIntern] = std::make_pair(loc, type); @@ -406,7 +406,7 @@ public: int unit = (int)m_Samplers.size(); m_Samplers[nameIntern].first = (type == GL_SAMPLER_CUBE ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D); m_Samplers[nameIntern].second = unit; - glUniform1iARB(loc, unit); // link uniform to unit + glUniform1i(loc, unit); // link uniform to unit ogl_WarnIfError(); } } @@ -502,18 +502,18 @@ public: void Bind() override { - glUseProgramObjectARB(m_Program); + glUseProgram(m_Program); for (std::map::iterator it = m_VertexAttribs.begin(); it != m_VertexAttribs.end(); ++it) - glEnableVertexAttribArrayARB(it->second); + glEnableVertexAttribArray(it->second); } void Unbind() override { - glUseProgramObjectARB(0); + glUseProgram(0); for (std::map::iterator it = m_VertexAttribs.begin(); it != m_VertexAttribs.end(); ++it) - glDisableVertexAttribArrayARB(it->second); + glDisableVertexAttribArray(it->second); // TODO: should unbind textures, probably } @@ -533,7 +533,7 @@ public: if (it == m_Samplers.end()) return; - glActiveTextureARB(GL_TEXTURE0 + it->second.second); + glActiveTexture(GL_TEXTURE0 + it->second.second); glBindTexture(it->second.first, tex); } @@ -542,7 +542,7 @@ public: if (id.second == -1) return; - glActiveTextureARB(GL_TEXTURE0 + id.second); + glActiveTexture(GL_TEXTURE0 + id.second); glBindTexture(id.first, tex); } @@ -560,13 +560,13 @@ public: if (id.first != -1) { if (id.second == GL_FLOAT) - glUniform1fARB(id.first, v0); + glUniform1f(id.first, v0); else if (id.second == GL_FLOAT_VEC2) - glUniform2fARB(id.first, v0, v1); + glUniform2f(id.first, v0, v1); else if (id.second == GL_FLOAT_VEC3) - glUniform3fARB(id.first, v0, v1, v2); + glUniform3f(id.first, v0, v1, v2); else if (id.second == GL_FLOAT_VEC4) - glUniform4fARB(id.first, v0, v1, v2, v3); + glUniform4f(id.first, v0, v1, v2, v3); else LOGERROR("CShaderProgramGLSL::Uniform(): Invalid uniform type (expected float, vec2, vec3, vec4)"); } @@ -577,7 +577,7 @@ public: if (id.first != -1) { if (id.second == GL_FLOAT_MAT4) - glUniformMatrix4fvARB(id.first, 1, GL_FALSE, &v._11); + glUniformMatrix4fv(id.first, 1, GL_FALSE, &v._11); else LOGERROR("CShaderProgramGLSL::Uniform(): Invalid uniform type (expected mat4)"); } @@ -588,7 +588,7 @@ public: if (id.first != -1) { if (id.second == GL_FLOAT_MAT4) - glUniformMatrix4fvARB(id.first, count, GL_FALSE, &v->_11); + glUniformMatrix4fv(id.first, count, GL_FALSE, &v->_11); else LOGERROR("CShaderProgramGLSL::Uniform(): Invalid uniform type (expected mat4)"); } @@ -599,7 +599,7 @@ public: if (id.first != -1) { if (id.second == GL_FLOAT) - glUniform1fvARB(id.first, count, v); + glUniform1fv(id.first, count, v); else LOGERROR("CShaderProgramGLSL::Uniform(): Invalid uniform type (expected float)"); } @@ -610,25 +610,25 @@ public: void VertexPointer(GLint size, GLenum type, GLsizei stride, const void* pointer) override { - glVertexAttribPointerARB(0, size, type, GL_FALSE, stride, pointer); + glVertexAttribPointer(0, size, type, GL_FALSE, stride, pointer); m_ValidStreams |= STREAM_POS; } void NormalPointer(GLenum type, GLsizei stride, const void* pointer) override { - glVertexAttribPointerARB(2, 3, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); + glVertexAttribPointer(2, 3, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); m_ValidStreams |= STREAM_NORMAL; } void ColorPointer(GLint size, GLenum type, GLsizei stride, const void* pointer) override { - glVertexAttribPointerARB(3, size, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); + glVertexAttribPointer(3, size, type, (type == GL_FLOAT ? GL_FALSE : GL_TRUE), stride, pointer); m_ValidStreams |= STREAM_COLOR; } void TexCoordPointer(GLenum texture, GLint size, GLenum type, GLsizei stride, const void* pointer) override { - glVertexAttribPointerARB(8 + texture - GL_TEXTURE0, size, type, GL_FALSE, stride, pointer); + glVertexAttribPointer(8 + texture - GL_TEXTURE0, size, type, GL_FALSE, stride, pointer); m_ValidStreams |= STREAM_UV0 << (texture - GL_TEXTURE0); } @@ -637,7 +637,7 @@ public: std::map::iterator it = m_VertexAttribs.find(id); if (it != m_VertexAttribs.end()) { - glVertexAttribPointerARB(it->second, size, type, normalized, stride, pointer); + glVertexAttribPointer(it->second, size, type, normalized, stride, pointer); } } diff --git a/source/ps/VideoMode.cpp b/source/ps/VideoMode.cpp index 7133f5a59c..465c4269b8 100644 --- a/source/ps/VideoMode.cpp +++ b/source/ps/VideoMode.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -522,7 +522,13 @@ void CVideoMode::Shutdown() bool CVideoMode::CreateBackendDevice(const bool createSDLContext) { - m_BackendDevice = Renderer::Backend::GL::CDevice::Create(createSDLContext ? m_Window : nullptr); + m_BackendDevice = Renderer::Backend::GL::CDevice::Create(createSDLContext ? m_Window : nullptr, m_Backend == Backend::GL_ARB); + if (!m_BackendDevice && m_Backend == Backend::GL) + { + LOGERROR("Unable to create device for GL backend, switching to ARB.", static_cast(m_Backend)); + m_Backend = Backend::GL_ARB; + return CreateBackendDevice(createSDLContext); + } return !!m_BackendDevice; } diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index b62f36f77c..767989179f 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -340,18 +340,14 @@ void CRenderer::EnumCaps() m_Caps.m_ARBProgramShadow = true; } - if (0 == ogl_HaveExtensions(0, "GL_ARB_shader_objects", "GL_ARB_shading_language_100", NULL)) - { - if (ogl_HaveExtension("GL_ARB_vertex_shader")) - m_Caps.m_VertexShader = true; - if (ogl_HaveExtension("GL_ARB_fragment_shader")) - m_Caps.m_FragmentShader = true; - } + // GLSL shaders are in core since GL2.0. + if (ogl_HaveVersion(2, 0)) + m_Caps.m_VertexShader = m_Caps.m_FragmentShader = true; #if CONFIG2_GLES m_Caps.m_Shadows = true; #else - if (0 == ogl_HaveExtensions(0, "GL_ARB_shadow", "GL_ARB_depth_texture", "GL_EXT_framebuffer_object", NULL)) + if (0 == ogl_HaveExtensions(0, "GL_ARB_shadow", "GL_ARB_depth_texture", NULL)) { if (ogl_max_tex_units >= 4) m_Caps.m_Shadows = true; @@ -361,7 +357,7 @@ void CRenderer::EnumCaps() #if CONFIG2_GLES m_Caps.m_PrettyWater = true; #else - if (0 == ogl_HaveExtensions(0, "GL_ARB_vertex_shader", "GL_ARB_fragment_shader", "GL_EXT_framebuffer_object", NULL)) + if (m_Caps.m_VertexShader && m_Caps.m_FragmentShader) m_Caps.m_PrettyWater = true; #endif } diff --git a/source/renderer/backend/gl/Device.cpp b/source/renderer/backend/gl/Device.cpp index cc12a9f6b5..2838035c6c 100644 --- a/source/renderer/backend/gl/Device.cpp +++ b/source/renderer/backend/gl/Device.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -127,7 +127,7 @@ std::vector GetExtensionsImpl() } // anonymous namespace // static -std::unique_ptr CDevice::Create(SDL_Window* window) +std::unique_ptr CDevice::Create(SDL_Window* window, const bool arb) { std::unique_ptr device(new CDevice()); @@ -167,8 +167,12 @@ std::unique_ptr CDevice::Create(SDL_Window* window) #endif } + // If we don't have GL2.0 then we don't have GLSL in core. + if (!arb && !ogl_HaveVersion(2, 0)) + return nullptr; + if ((ogl_HaveExtensions(0, "GL_ARB_vertex_program", "GL_ARB_fragment_program", nullptr) // ARB - && ogl_HaveExtensions(0, "GL_ARB_vertex_shader", "GL_ARB_fragment_shader", nullptr)) // GLSL + && !ogl_HaveVersion(2, 0)) // GLSL || !ogl_HaveExtension("GL_ARB_vertex_buffer_object") // VBO || ogl_HaveExtensions(0, "GL_ARB_multitexture", "GL_EXT_draw_range_elements", nullptr) || (!ogl_HaveExtension("GL_EXT_framebuffer_object") && !ogl_HaveExtension("GL_ARB_framebuffer_object"))) diff --git a/source/renderer/backend/gl/Device.h b/source/renderer/backend/gl/Device.h index 22c6065221..175bd2b38e 100644 --- a/source/renderer/backend/gl/Device.h +++ b/source/renderer/backend/gl/Device.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -44,7 +44,7 @@ public: /** * Creates the GL device and the GL context for the window if it presents. */ - static std::unique_ptr Create(SDL_Window* window); + static std::unique_ptr Create(SDL_Window* window, const bool arb); const std::string& GetName() const { return m_Name; } const std::string& GetVersion() const { return m_Version; }