Advertisement
Guest User

EglContext.hpp

a guest
Jan 10th, 2019
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.34 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////
  2. //
  3. // SFML - Simple and Fast Multimedia Library
  4. // Copyright (C) 2013 Jonathan De Wachter (dewachter.jonathan@gmail.com)
  5. //
  6. // This software is provided 'as-is', without any express or implied warranty.
  7. // In no event will the authors be held liable for any damages arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it freely,
  11. // subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented;
  14. //    you must not claim that you wrote the original software.
  15. //    If you use this software in a product, an acknowledgment
  16. //    in the product documentation would be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such,
  19. //    and must not be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. ////////////////////////////////////////////////////////////
  24.  
  25. #ifndef SFML_EGLCONTEXT_HPP
  26. #define SFML_EGLCONTEXT_HPP
  27.  
  28. ////////////////////////////////////////////////////////////
  29. // Headers
  30. ////////////////////////////////////////////////////////////
  31. #include <SFML/Window/VideoMode.hpp>
  32. #include <SFML/Window/ContextSettings.hpp>
  33. #include <SFML/Window/EGLCheck.hpp>
  34. #include <SFML/Window/GlContext.hpp>
  35. #include <SFML/OpenGL.hpp>
  36.  
  37.  
  38. namespace sf
  39. {
  40. namespace priv
  41. {
  42. class EglContext : public GlContext
  43. {
  44. public:
  45.  
  46.     ////////////////////////////////////////////////////////////
  47.     /// \brief Create a new context, not associated to a window
  48.     ///
  49.     /// \param shared Context to share the new one with (can be NULL)
  50.     ///
  51.     ////////////////////////////////////////////////////////////
  52.     EglContext(EglContext* shared);
  53.  
  54.     ////////////////////////////////////////////////////////////
  55.     /// \brief Create a new context attached to a window
  56.     ///
  57.     /// \param shared       Context to share the new one with
  58.     /// \param settings     Creation parameters
  59.     /// \param owner        Pointer to the owner window
  60.     /// \param bitsPerPixel Pixel depth, in bits per pixel
  61.     ///
  62.     ////////////////////////////////////////////////////////////
  63.     EglContext(EglContext* shared, const ContextSettings& settings, const WindowImpl* owner, unsigned int bitsPerPixel);
  64.  
  65.     ////////////////////////////////////////////////////////////
  66.     /// \brief Create a new context that embeds its own rendering target
  67.     ///
  68.     /// \param shared   Context to share the new one with
  69.     /// \param settings Creation parameters
  70.     /// \param width    Back buffer width, in pixels
  71.     /// \param height   Back buffer height, in pixels
  72.     ///
  73.     ////////////////////////////////////////////////////////////
  74.     EglContext(EglContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height);
  75.  
  76.     ////////////////////////////////////////////////////////////
  77.     /// \brief Destructor
  78.     ///
  79.     ////////////////////////////////////////////////////////////
  80.     ~EglContext();
  81.  
  82.     ////////////////////////////////////////////////////////////
  83.     /// \brief Activate the context as the current target
  84.     ///        for rendering
  85.     ///
  86.     /// \param current Whether to make the context current or no longer current
  87.     ///
  88.     /// \return True on success, false if any error happened
  89.     ///
  90.     ////////////////////////////////////////////////////////////
  91.     virtual bool makeCurrent(bool current);
  92.  
  93.     ////////////////////////////////////////////////////////////
  94.     /// \brief Display what has been rendered to the context so far
  95.     ///
  96.     ////////////////////////////////////////////////////////////
  97.     virtual void display();
  98.  
  99.     ////////////////////////////////////////////////////////////
  100.     /// \brief Enable or disable vertical synchronization
  101.     ///
  102.     /// Activating vertical synchronization will limit the number
  103.     /// of frames displayed to the refresh rate of the monitor.
  104.     /// This can avoid some visual artifacts, and limit the framerate
  105.     /// to a good value (but not constant across different computers).
  106.     ///
  107.     /// \param enabled: True to enable v-sync, false to deactivate
  108.     ///
  109.     ////////////////////////////////////////////////////////////
  110.     virtual void setVerticalSyncEnabled(bool enabled);
  111.  
  112.     ////////////////////////////////////////////////////////////
  113.     /// \brief Create the context
  114.     ///
  115.     /// \param shared       Context to share the new one with (can be NULL)
  116.     /// \param bitsPerPixel Pixel depth, in bits per pixel
  117.     /// \param settings     Creation parameters
  118.     ///
  119.     ////////////////////////////////////////////////////////////
  120.     void createContext(EglContext* shared);
  121.  
  122.     ////////////////////////////////////////////////////////////
  123.     /// \brief Create the EGL surface
  124.     ///
  125.     /// This function must be called when the activity (re)start, or
  126.     /// when the orientation change.
  127.     ///
  128.     /// \param window: The native window type
  129.     ///
  130.     ////////////////////////////////////////////////////////////
  131.     void createSurface(EGLNativeWindowType window);
  132.  
  133.     ////////////////////////////////////////////////////////////
  134.     /// \brief Destroy the EGL surface
  135.     ///
  136.     /// This function must be called when the activity is stopped, or
  137.     /// when the orientation change.
  138.     ///
  139.     ////////////////////////////////////////////////////////////
  140.     void destroySurface();
  141.  
  142.     ////////////////////////////////////////////////////////////
  143.     /// \brief Get the best EGL visual for a given set of video settings
  144.     ///
  145.     /// \param display      EGL display
  146.     /// \param bitsPerPixel Pixel depth, in bits per pixel
  147.     /// \param settings     Requested context settings
  148.     ///
  149.     /// \return The best EGL config
  150.     ///
  151.     ////////////////////////////////////////////////////////////
  152.     static EGLConfig getBestConfig(EGLDisplay display, unsigned int bitsPerPixel, const ContextSettings& settings);
  153.  
  154. #ifdef SFML_SYSTEM_LINUX
  155.     ////////////////////////////////////////////////////////////
  156.     /// \brief Select the best EGL visual for a given set of settings
  157.     ///
  158.     /// \param display      X display
  159.     /// \param bitsPerPixel Pixel depth, in bits per pixel
  160.     /// \param settings     Requested context settings
  161.     ///
  162.     /// \return The best visual
  163.     ///
  164.     ////////////////////////////////////////////////////////////
  165. //    static XVisualInfo selectBestVisual(::Display* display, unsigned int bitsPerPixel, const ContextSettings& settings);
  166. #endif
  167.  
  168. private:
  169.  
  170.     ////////////////////////////////////////////////////////////
  171.     /// \brief Helper to copy the picked EGL configuration
  172.     ////////////////////////////////////////////////////////////
  173.     void updateSettings();
  174.  
  175.     ////////////////////////////////////////////////////////////
  176.     // Member data
  177.     ////////////////////////////////////////////////////////////
  178.     EGLDisplay  m_display; ///< The internal EGL display
  179.     EGLContext  m_context; ///< The internal EGL context
  180.     EGLSurface  m_surface; ///< The internal EGL surface
  181.     EGLConfig   m_config;  ///< The internal EGL config
  182.  
  183. };
  184.  
  185. } // namespace priv
  186.  
  187. } // namespace sf
  188.  
  189.  
  190. #endif // SFML_EGLCONTEXT_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement