| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include <X11/Xutil.h> |
| 6 | #include "BsGLSupport.h" |
| 7 | #include "BsGLRenderAPI.h" |
| 8 | |
| 9 | namespace bs { namespace ct |
| 10 | { |
| 11 | class LinuxContext; |
| 12 | |
| 13 | /** @addtogroup GL |
| 14 | * @{ |
| 15 | */ |
| 16 | |
| 17 | typedef XID GLXDrawable; |
| 18 | typedef struct __GLXcontextRec *GLXContext; |
| 19 | typedef XID GLXWindow; |
| 20 | typedef struct __GLXFBConfigRec *GLXFBConfig; |
| 21 | |
| 22 | // Extensions |
| 23 | extern bool extGLX_ARB_multisample; |
| 24 | extern bool extGLX_ARB_framebuffer_sRGB; |
| 25 | extern bool extGLX_EXT_framebuffer_sRGB; |
| 26 | extern bool extGLX_ARB_create_context; |
| 27 | extern bool extGLX_ARB_create_context_profile; |
| 28 | extern bool extGLX_EXT_swap_control; |
| 29 | extern bool extGLX_MESA_swap_control; |
| 30 | extern bool extGLX_SGI_swap_control; |
| 31 | |
| 32 | typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); |
| 33 | extern glXCreateContextAttribsARBProc glXCreateContextAttribsARB; |
| 34 | |
| 35 | typedef void (*glXSwapIntervalEXTProc)(::Display*, GLXDrawable, int); |
| 36 | typedef int (*glXSwapIntervalMESAProc)(int); |
| 37 | typedef int (*glXSwapIntervalSGIProc)(int); |
| 38 | |
| 39 | extern glXSwapIntervalEXTProc glXSwapIntervalEXT; |
| 40 | extern glXSwapIntervalMESAProc glXSwapIntervalMESA; |
| 41 | extern glXSwapIntervalSGIProc glXSwapIntervalSGI; |
| 42 | |
| 43 | typedef GLXFBConfig* (*glXChooseFBConfigProc) (Display *dpy, int screen, const int *attrib_list, int *nelements); |
| 44 | typedef int (*glXGetFBConfigAttribProc) (Display *dpy, GLXFBConfig config, int attribute, int *value); |
| 45 | typedef XVisualInfo* (*glXGetVisualFromFBConfigProc) (Display *dpy, GLXFBConfig config); |
| 46 | |
| 47 | extern glXChooseFBConfigProc glXChooseFBConfig; |
| 48 | extern glXGetFBConfigAttribProc glXGetFBConfigAttrib; |
| 49 | extern glXGetVisualFromFBConfigProc glXGetVisualFromFBConfig; |
| 50 | |
| 51 | /** Determines which features are supported by a particular framebuffer configuration. */ |
| 52 | struct GLVisualCapabilities |
| 53 | { |
| 54 | bool depthStencil = false; |
| 55 | UINT32 numSamples = 1; |
| 56 | bool srgb = false; |
| 57 | }; |
| 58 | |
| 59 | /** Contains information about a framebuffer configuration that can be used to initialize a window and GL context. */ |
| 60 | struct GLVisualConfig |
| 61 | { |
| 62 | GLVisualCapabilities caps; |
| 63 | XVisualInfo visualInfo; |
| 64 | }; |
| 65 | |
| 66 | /** Handles OpenGL initialization, window creation and extensions on Linux. */ |
| 67 | class LinuxGLSupport : public GLSupport |
| 68 | { |
| 69 | public: |
| 70 | LinuxGLSupport(); |
| 71 | |
| 72 | /** @copydoc GLSupport::newWindow */ |
| 73 | SPtr<bs::RenderWindow> newWindow(RENDER_WINDOW_DESC& desc, UINT32 windowId, SPtr<bs::RenderWindow> parentWindow) override; |
| 74 | |
| 75 | /** @copydoc GLSupport::start */ |
| 76 | void start() override; |
| 77 | |
| 78 | /** @copydoc GLSupport::stop */ |
| 79 | void stop() override; |
| 80 | |
| 81 | /** @copydoc GLSupport::getProcAddress */ |
| 82 | void* getProcAddress(const String& procname) override; |
| 83 | |
| 84 | /** Creates a new OpenGL context. */ |
| 85 | SPtr<LinuxContext> createContext(::Display* x11display, XVisualInfo& visualInfo); |
| 86 | |
| 87 | /** |
| 88 | * Selects an appropriate X11 visual info depending on the provided parameters. Visual info should then be used |
| 89 | * for creation of an X11 window. |
| 90 | * |
| 91 | * @param[in] display X11 display the window will be created on. |
| 92 | * @param[in] depthStencil True if the window requires a depth-stencil buffer. |
| 93 | * @param[in] multisample Number of samples per pixel, if window back buffer requires support for multiple samples. |
| 94 | * Set to 0 or 1 if multisampling is not required. |
| 95 | * @param[in] srgb If enabled the pixels written to the back-buffer are assumed to be in linear space and |
| 96 | * will automatically be encoded into gamma space on write. |
| 97 | * @return X11 visual info structure you may use to initialize a window. |
| 98 | */ |
| 99 | GLVisualConfig findBestVisual(::Display* display, bool depthStencil, UINT32 multisample, bool srgb) const; |
| 100 | |
| 101 | /** @copydoc GLSupport::getVideoModeInfo */ |
| 102 | SPtr<VideoModeInfo> getVideoModeInfo() const override; |
| 103 | |
| 104 | private: |
| 105 | }; |
| 106 | |
| 107 | /** @} */ |
| 108 | }} |