Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: [OpenGL] Load all OpenGL functions dynamically. #8730

Merged
merged 2 commits into from Feb 24, 2021

Conversation

@michicc
Copy link
Member

@michicc michicc commented Feb 22, 2021

Motivation / Problem

Some Linux OpenGL drivers don't use the global system dispatch table.

Description

Link all OpenGL functions dynamically to make sure we use the right one.

Limitations

OpenGL headers are not uniform among systems, which might cause compile problems on more obscure systems.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
@Milek7
Copy link
Contributor

@Milek7 Milek7 commented Feb 22, 2021

Alternative approach for consideration, use autogenerated loader instead: Milek7@127aaa9

As system OpenGL headers are not used at all, I removed library searching and linking from CMake files.
For win32 it also needs win32_v.cpp from this PR.

src/video/opengl.cpp Outdated Show resolved Hide resolved
src/video/opengl.cpp Outdated Show resolved Hide resolved
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Feb 24, 2021

With this PR, I can remove link_package(OpenGL TARGET OpenGL::GL) from CMakeLists.txt. This has the benefit that our generic linux binaries are a lot smaller again, as it no longer drags in OpenGL.so and because of that, X11 and friends. That won't really be a generic linux binary.

Without the link_package, SDL takes care of all the dynamic loading, removing those dependencies from the binary.

I can PR that after this PR, if you like, but maybe the link_package is also not needed on other targets now?

@michicc
Copy link
Member Author

@michicc michicc commented Feb 24, 2021

It is still needed for Win32 because of the wgl calls, but opengl32.dll is a system DLL everywhere, so no problem.
OSX I'd have to check.

@michicc michicc force-pushed the michicc:pr/gl_dynamic branch from 56b9ae1 to e9ac6d7 Feb 24, 2021
@michicc michicc force-pushed the michicc:pr/gl_dynamic branch from e9ac6d7 to 7c1603b Feb 24, 2021
Copy link
Member

@frosch123 frosch123 left a comment

works for me

@michicc michicc merged commit 311df31 into OpenTTD:master Feb 24, 2021
11 checks passed
11 checks passed
Emscripten
Details
Commit checker
Details
Check preview needs update Check preview needs update
Details
Linux (clang, clang++, libsdl2-dev)
Details
Linux (gcc, g++, libsdl2-dev)
Details
Linux (gcc, g++, libsdl1.2-dev)
Details
Mac OS (x64, x86_64)
Details
Windows (windows-latest, x86)
Details
Windows (windows-latest, x64)
Details
Windows (windows-2016, x86)
Details
Windows (windows-2016, x64)
Details
@michicc michicc deleted the michicc:pr/gl_dynamic branch Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants