| 1 | /**************************************************************************/ |
| 2 | /* detect_prime_egl.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #pragma once |
| 32 | |
| 33 | #ifdef GLES3_ENABLED |
| 34 | #ifdef EGL_ENABLED |
| 35 | |
| 36 | #ifdef GLAD_ENABLED |
| 37 | #include "thirdparty/glad/glad/egl.h" |
| 38 | #include "thirdparty/glad/glad/gl.h" |
| 39 | #else |
| 40 | #include <EGL/egl.h> |
| 41 | #include <EGL/eglext.h> |
| 42 | #include <GL/glcorearb.h> |
| 43 | |
| 44 | #define GLAD_EGL_VERSION_1_5 1 |
| 45 | |
| 46 | #ifdef EGL_EXT_platform_base |
| 47 | #define GLAD_EGL_EXT_platform_base 1 |
| 48 | #endif |
| 49 | |
| 50 | #define KHRONOS_STATIC 1 |
| 51 | extern "C" EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platform, void *native_display, const EGLint *attrib_list); |
| 52 | #undef KHRONOS_STATIC |
| 53 | |
| 54 | #endif // GLAD_ENABLED |
| 55 | |
| 56 | #ifndef EGL_EXT_platform_base |
| 57 | #define GLAD_EGL_EXT_platform_base 0 |
| 58 | #endif |
| 59 | |
| 60 | class DetectPrimeEGL { |
| 61 | private: |
| 62 | struct Vendor { |
| 63 | const char *glxvendor = nullptr; |
| 64 | int priority = 0; |
| 65 | }; |
| 66 | |
| 67 | static constexpr Vendor vendor_map[] = { |
| 68 | { "Advanced Micro Devices, Inc.", 30 }, |
| 69 | { "AMD", 30 }, |
| 70 | { "NVIDIA Corporation", 30 }, |
| 71 | { "X.Org", 30 }, |
| 72 | { "Intel Open Source Technology Center", 20 }, |
| 73 | { "Intel", 20 }, |
| 74 | { "nouveau", 10 }, |
| 75 | { "Mesa Project", 0 }, |
| 76 | { nullptr, 0 } |
| 77 | }; |
| 78 | |
| 79 | public: |
| 80 | static void create_context(EGLenum p_platform_enum); |
| 81 | |
| 82 | static int detect_prime(EGLenum p_platform_enum); |
| 83 | }; |
| 84 | |
| 85 | #endif // GLES3_ENABLED |
| 86 | #endif // EGL_ENABLED |