BsLinuxGLSupport.h 3.4 KB

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