Path: blob/master/platform/linuxbsd/x11/gl_manager_x11.h
10278 views
/**************************************************************************/1/* gl_manager_x11.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#if defined(X11_ENABLED) && defined(GLES3_ENABLED)3334#include "core/os/os.h"35#include "core/templates/local_vector.h"36#include "servers/display_server.h"3738#ifdef SOWRAP_ENABLED39#include "dynwrappers/xlib-so_wrap.h"4041#include "dynwrappers/xext-so_wrap.h"42#include "dynwrappers/xrender-so_wrap.h"43#else44#include <X11/XKBlib.h>45#include <X11/Xlib.h>46#include <X11/Xutil.h>4748#include <X11/extensions/Xext.h>49#include <X11/extensions/Xrender.h>50#include <X11/extensions/shape.h>51#endif5253struct GLManager_X11_Private;5455class GLManager_X11 {56public:57enum ContextType {58GLES_3_0_COMPATIBLE,59};6061private:62// any data specific to the window63struct GLWindow {64bool in_use = false;6566// the external ID .. should match the GL window number .. unused I think67DisplayServer::WindowID window_id = DisplayServer::INVALID_WINDOW_ID;68int width = 0;69int height = 0;70::Window x11_window;71int gldisplay_id = 0;72};7374struct GLDisplay {75GLDisplay() {}76~GLDisplay();77GLManager_X11_Private *context = nullptr;78::Display *x11_display = nullptr;79XVisualInfo x_vi = {};80};8182// just for convenience, window and display struct83struct XWinDisp {84::Window x11_window;85::Display *x11_display = nullptr;86} _x_windisp;8788LocalVector<GLWindow> _windows;89LocalVector<GLDisplay> _displays;9091GLWindow *_current_window = nullptr;9293void _internal_set_current_window(GLWindow *p_win);9495GLWindow &get_window(unsigned int id) { return _windows[id]; }96const GLWindow &get_window(unsigned int id) const { return _windows[id]; }9798const GLDisplay &get_current_display() const { return _displays[_current_window->gldisplay_id]; }99const GLDisplay &get_display(unsigned int id) { return _displays[id]; }100101bool double_buffer;102bool direct_render;103int glx_minor, glx_major;104bool use_vsync;105ContextType context_type;106107private:108int _find_or_create_display(Display *p_x11_display);109Error _create_context(GLDisplay &gl_display);110111public:112XVisualInfo get_vi(Display *p_display, Error &r_error);113Error window_create(DisplayServer::WindowID p_window_id, ::Window p_window, Display *p_display, int p_width, int p_height);114void window_destroy(DisplayServer::WindowID p_window_id);115void window_resize(DisplayServer::WindowID p_window_id, int p_width, int p_height);116117void release_current();118void swap_buffers();119120void window_make_current(DisplayServer::WindowID p_window_id);121122Error initialize(Display *p_display);123124void set_use_vsync(bool p_use);125bool is_using_vsync() const;126127void *get_glx_context(DisplayServer::WindowID p_window_id);128129Error open_display(Display *p_display);130GLManager_X11(const Vector2i &p_size, ContextType p_context_type);131~GLManager_X11();132};133134#endif // X11_ENABLED && GLES3_ENABLED135136137