Separated OpenGL contexts from Window implementations
Added support for OpenGL 3.0 Replaced WindowSettings with ContextSettings Synchronized with trunk git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1065 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
9c370e38da
110 changed files with 2758 additions and 2335 deletions
|
@ -161,9 +161,10 @@ public :
|
|||
/// \param DestX : X coordinate of the destination position
|
||||
/// \param DestY : Y coordinate of the destination position
|
||||
/// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)
|
||||
/// \param ApplyAlpha : Should the copy take in account the source transparency? (false by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
|
||||
void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create the image from the current contents of the
|
||||
|
|
|
@ -58,19 +58,19 @@ public :
|
|||
/// \param Mode : Video mode to use
|
||||
/// \param Title : Title of the window
|
||||
/// \param WindowStyle : Window style (Resize | Close by default)
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
|
||||
RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the window from an existing control
|
||||
///
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
|
||||
RenderWindow(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
|
|
|
@ -30,7 +30,13 @@
|
|||
/// This file just includes the OpenGL (GL and GLU) headers,
|
||||
/// which have actually different paths on each system
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_SYSTEM_WINDOWS) || defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <windows.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
|
@ -277,7 +277,7 @@ private :
|
|||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const char UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
|
||||
static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
|
||||
static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions
|
||||
static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences
|
||||
};
|
||||
|
|
|
@ -104,7 +104,7 @@ inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement
|
|||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = 0;
|
||||
int TrailingBytes = UTF8TrailingBytes[*Begin];
|
||||
int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
|
||||
if (Begin + TrailingBytes < End)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
|
@ -165,7 +165,7 @@ inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement
|
|||
while (Begin < End)
|
||||
{
|
||||
Uint32 c = 0;
|
||||
int TrailingBytes = UTF8TrailingBytes[*Begin];
|
||||
int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
|
||||
if (Begin + TrailingBytes < End)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
|
@ -424,7 +424,7 @@ inline std::size_t Unicode::GetUTF8Length(In Begin, In End)
|
|||
std::size_t Length = 0;
|
||||
while (Begin < End)
|
||||
{
|
||||
int NbBytes = UTF8TrailingBytes[*Begin];
|
||||
int NbBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
|
||||
if (Begin + NbBytes < End)
|
||||
++Length;
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <SFML/Window/Window.hpp>
|
||||
#include <SFML/Window/WindowListener.hpp>
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
#include <SFML/Window/OpenGL.hpp>
|
||||
|
||||
|
||||
#endif // SFML_SFML_WINDOW_HPP
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
||||
|
||||
|
@ -36,62 +37,132 @@ namespace sf
|
|||
{
|
||||
namespace priv
|
||||
{
|
||||
class WindowImpl;
|
||||
class WindowImpl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Class wrapping an OpenGL context.
|
||||
/// All SFML windows already have their own context, so
|
||||
/// this class is more a helper for specific issues involving
|
||||
/// OpenGL and multi-threading.
|
||||
/// It's meant to be used internally.
|
||||
/// Abstract class representing an OpenGL context
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Context : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor, create the context
|
||||
/// Create a new context, not associated to a window
|
||||
///
|
||||
/// \return Pointer to the created context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Context();
|
||||
static Context* New();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor, destroy the context
|
||||
/// Create a new context attached to a window
|
||||
///
|
||||
/// \param Owner : Pointer to the owner window
|
||||
/// \param BitsPerPixel : Pixel depth (in bits per pixel)
|
||||
/// \param Settings : Creation parameters
|
||||
///
|
||||
/// \return Pointer to the created context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Context();
|
||||
static Context* New(const priv::WindowImpl* Owner, unsigned int BitsPerPixel, const ContextSettings& Settings);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Activate or deactivate the context
|
||||
/// Check if a context is active on the current thread
|
||||
///
|
||||
/// \param Active : True to activate the context, false to deactivate it
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetActive(bool Active);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check if there's a context bound to the current thread
|
||||
///
|
||||
/// \return True if there's a context bound to the current thread
|
||||
/// \return True if there's an active context, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool IsContextActive();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the global context
|
||||
/// Return the default context
|
||||
///
|
||||
/// \return Reference to the global context
|
||||
/// \return Reference to the default context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Context& GetGlobal();
|
||||
static Context& GetDefault();
|
||||
|
||||
private :
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Context();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the settings of the context
|
||||
///
|
||||
/// \return Structure containing the settings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& GetSettings() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Activate or deactivate the context as the current target
|
||||
/// for rendering
|
||||
///
|
||||
/// \param Active : True to activate, false to deactivate
|
||||
///
|
||||
/// \return True if operation was successful, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SetActive(bool Active);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Display the contents of the context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void Display() = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Enable / disable vertical synchronization
|
||||
///
|
||||
/// \param Enabled : True to enable v-sync, false to deactivate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void UseVerticalSync(bool Enabled) = 0;
|
||||
|
||||
protected :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Context();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Make this context the current one
|
||||
///
|
||||
/// \param Active : True to activate, false to deactivate
|
||||
///
|
||||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool MakeCurrent(bool Active) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Evaluate a pixel format configuration.
|
||||
/// This functions can be used by implementations that have
|
||||
/// several valid formats and want to get the best one
|
||||
///
|
||||
/// \param BitsPerPixel : Requested pixel depth (bits per pixel)
|
||||
/// \param Settings : Requested additionnal settings
|
||||
/// \param ColorBits : Color bits of the configuration to evaluate
|
||||
/// \param DepthBits : Depth bits of the configuration to evaluate
|
||||
/// \param StencilBits : Stencil bits of the configuration to evaluate
|
||||
/// \param Antialiasing : Antialiasing level of the configuration to evaluate
|
||||
///
|
||||
/// \return Score of the configuration : the lower the better
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static int EvaluateFormat(unsigned int BitsPerPixel, const ContextSettings& Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::WindowImpl* myDummyWindow; ///< Dummy window holding the context
|
||||
ContextSettings mySettings; ///< Creation settings of the context
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -22,16 +22,17 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_WINDOWSETTINGS_HPP
|
||||
#define SFML_WINDOWSETTINGS_HPP
|
||||
#ifndef SFML_CONTEXTSETTINGS_HPP
|
||||
#define SFML_CONTEXTSETTINGS_HPP
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Structure defining the creation settings of windows
|
||||
/// Structure defining the settings of the OpenGL
|
||||
/// context attached to a window
|
||||
////////////////////////////////////////////////////////////
|
||||
struct WindowSettings
|
||||
struct ContextSettings
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
|
@ -41,7 +42,7 @@ struct WindowSettings
|
|||
/// \param Antialiasing : Antialiasing level (0 by default)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit WindowSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) :
|
||||
explicit ContextSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) :
|
||||
DepthBits (Depth),
|
||||
StencilBits (Stencil),
|
||||
AntialiasingLevel(Antialiasing)
|
||||
|
@ -59,4 +60,4 @@ struct WindowSettings
|
|||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_WINDOWSETTINGS_HPP
|
||||
#endif // SFML_CONTEXTSETTINGS_HPP
|
|
@ -33,7 +33,7 @@
|
|||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <SFML/Window/WindowHandle.hpp>
|
||||
#include <SFML/Window/WindowListener.hpp>
|
||||
#include <SFML/Window/WindowSettings.hpp>
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
@ -48,6 +48,8 @@ namespace priv
|
|||
class WindowImpl;
|
||||
}
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Window is a rendering window ; it can create a new window
|
||||
/// or connect to an existing one
|
||||
|
@ -68,19 +70,19 @@ public :
|
|||
/// \param Mode : Video mode to use
|
||||
/// \param Title : Title of the window
|
||||
/// \param WindowStyle : Window style (Resize | Close by default)
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
|
||||
Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the window from an existing control
|
||||
///
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
|
||||
Window(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
|
@ -94,19 +96,19 @@ public :
|
|||
/// \param Mode : Video mode to use
|
||||
/// \param Title : Title of the window
|
||||
/// \param WindowStyle : Window style (Resize | Close by default)
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
|
||||
void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create (or recreate) the window from an existing control
|
||||
///
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Params : Creation parameters (see default constructor for default values)
|
||||
/// \param Handle : Platform-specific handle of the control
|
||||
/// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
|
||||
void Create(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Close (destroy) the window.
|
||||
|
@ -143,12 +145,12 @@ public :
|
|||
unsigned int GetHeight() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the creation settings of the window
|
||||
/// Get the settinsg of the OpenGL context of the window
|
||||
///
|
||||
/// \return Structure containing the creation settings
|
||||
/// \return Structure containing the context settings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const WindowSettings& GetSettings() const;
|
||||
const ContextSettings& GetSettings() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the event on top of events stack, if any, and pop it
|
||||
|
@ -232,7 +234,7 @@ public :
|
|||
void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Activate of deactivate the window as the current target
|
||||
/// Activate or deactivate the window as the current target
|
||||
/// for rendering
|
||||
///
|
||||
/// \param Active : True to activate, false to deactivate (true by default)
|
||||
|
@ -298,21 +300,19 @@ private :
|
|||
virtual void OnEvent(const Event& EventReceived);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Initialize internal window
|
||||
///
|
||||
/// \param Impl : New internal window implementation
|
||||
/// Do some common internal initializations
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Initialize(priv::WindowImpl* Impl);
|
||||
void Initialize();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::WindowImpl* myWindow; ///< Platform-specific implementation of window
|
||||
priv::WindowImpl* myWindow; ///< Platform-specific implementation of the window
|
||||
Context* myContext; ///< Platform-specific implementation of the OpenGL context
|
||||
std::queue<Event> myEvents; ///< Queue of received events
|
||||
Input myInput; ///< Input manager connected to window
|
||||
Clock myClock; ///< Clock for measuring the elapsed time between frames
|
||||
WindowSettings mySettings; ///< Creation settings of the window
|
||||
float myLastFrameTime; ///< Time elapsed since last frame
|
||||
bool myIsExternal; ///< Tell whether the window is internal or external (created by SFML or not)
|
||||
unsigned int myFramerateLimit; ///< Current framerate limit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue