BsLinuxGLSupport.h 3.9 KB

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