/**************************************************************************/1/* egl_manager.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#ifdef EGL_ENABLED3334// These must come first to avoid windows.h mess.35#include "platform_gl.h"3637#include "core/templates/local_vector.h"38#include "servers/display_server.h"3940class EGLManager {41private:42// An EGL-side representation of a display with its own rendering43// context.44struct GLDisplay {45void *display = nullptr;4647EGLDisplay egl_display = EGL_NO_DISPLAY;48EGLContext egl_context = EGL_NO_CONTEXT;49EGLConfig egl_config = nullptr;5051#ifdef WINDOWS_ENABLED52bool has_EGL_ANGLE_surface_orientation = false;53#endif54};5556// EGL specific window data.57struct GLWindow {58bool initialized = false;59#ifdef WINDOWS_ENABLED60bool flipped_y = false;61#endif6263// An handle to the GLDisplay associated with this window.64int gldisplay_id = -1;6566EGLSurface egl_surface = EGL_NO_SURFACE;67};6869LocalVector<GLDisplay> displays;70LocalVector<GLWindow> windows;7172GLWindow *current_window = nullptr;7374// On EGL the default swap interval is 1 and thus vsync is on by default.75bool use_vsync = true;7677virtual const char *_get_platform_extension_name() const = 0;78virtual EGLenum _get_platform_extension_enum() const = 0;79virtual EGLenum _get_platform_api_enum() const = 0;80virtual Vector<EGLAttrib> _get_platform_display_attributes() const = 0;81virtual Vector<EGLint> _get_platform_context_attribs() const = 0;8283#ifdef EGL_ANDROID_blob_cache84static String shader_cache_dir;8586static void _set_cache(const void *p_key, EGLsizeiANDROID p_key_size, const void *p_value, EGLsizeiANDROID p_value_size);87static EGLsizeiANDROID _get_cache(const void *p_key, EGLsizeiANDROID p_key_size, void *p_value, EGLsizeiANDROID p_value_size);88#endif8990int _get_gldisplay_id(void *p_display);91Error _gldisplay_create_context(GLDisplay &p_gldisplay);9293public:94int display_get_native_visual_id(void *p_display);9596Error open_display(void *p_display);97Error window_create(DisplayServer::WindowID p_window_id, void *p_display, void *p_native_window, int p_width, int p_height);9899void window_destroy(DisplayServer::WindowID p_window_id);100101void release_current();102void swap_buffers();103104void window_make_current(DisplayServer::WindowID p_window_id);105106void set_use_vsync(bool p_use);107bool is_using_vsync() const;108109EGLContext get_context(DisplayServer::WindowID p_window_id);110EGLDisplay get_display(DisplayServer::WindowID p_window_id);111EGLConfig get_config(DisplayServer::WindowID p_window_id);112113Error initialize(void *p_native_display = nullptr);114115EGLManager();116virtual ~EGLManager();117};118119#endif // EGL_ENABLED120121122