mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
[iOS] Added (fake) implementation of vertical synchronization
This commit is contained in:
parent
cd89e462fa
commit
728f11701b
@ -31,6 +31,7 @@
|
|||||||
#include <SFML/Window/GlContext.hpp>
|
#include <SFML/Window/GlContext.hpp>
|
||||||
#include <SFML/Window/iOS/ObjCType.hpp>
|
#include <SFML/Window/iOS/ObjCType.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <OpenGLES/ES1/gl.h>
|
#include <OpenGLES/ES1/gl.h>
|
||||||
|
|
||||||
|
|
||||||
@ -153,6 +154,8 @@ private:
|
|||||||
GLuint m_framebuffer; ///< Frame buffer associated to the context
|
GLuint m_framebuffer; ///< Frame buffer associated to the context
|
||||||
GLuint m_colorbuffer; ///< Color render buffer
|
GLuint m_colorbuffer; ///< Color render buffer
|
||||||
GLuint m_depthbuffer; ///< Depth render buffer
|
GLuint m_depthbuffer; ///< Depth render buffer
|
||||||
|
bool m_vsyncEnabled; ///< Vertical sync activation flag
|
||||||
|
Clock m_clock; ///< Measures the elapsed time for the fake v-sync implementation
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <SFML/Window/iOS/WindowImplUIKit.hpp>
|
#include <SFML/Window/iOS/WindowImplUIKit.hpp>
|
||||||
#include <SFML/Window/iOS/SFView.hpp>
|
#include <SFML/Window/iOS/SFView.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
|
#include <SFML/System/Sleep.hpp>
|
||||||
#include <OpenGLES/EAGL.h>
|
#include <OpenGLES/EAGL.h>
|
||||||
#include <OpenGLES/EAGLDrawable.h>
|
#include <OpenGLES/EAGLDrawable.h>
|
||||||
#include <OpenGLES/ES1/glext.h>
|
#include <OpenGLES/ES1/glext.h>
|
||||||
@ -41,10 +42,12 @@ namespace priv
|
|||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
EaglContext::EaglContext(EaglContext* shared) :
|
EaglContext::EaglContext(EaglContext* shared) :
|
||||||
m_context (nil),
|
m_context (nil),
|
||||||
m_framebuffer(0),
|
m_framebuffer (0),
|
||||||
m_colorbuffer(0),
|
m_colorbuffer (0),
|
||||||
m_depthbuffer(0)
|
m_depthbuffer (0),
|
||||||
|
m_vsyncEnabled(false),
|
||||||
|
m_clock ()
|
||||||
{
|
{
|
||||||
// Create the context
|
// Create the context
|
||||||
if (shared)
|
if (shared)
|
||||||
@ -57,10 +60,12 @@ m_depthbuffer(0)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||||
const WindowImpl* owner, unsigned int bitsPerPixel) :
|
const WindowImpl* owner, unsigned int bitsPerPixel) :
|
||||||
m_context (nil),
|
m_context (nil),
|
||||||
m_framebuffer(0),
|
m_framebuffer (0),
|
||||||
m_colorbuffer(0),
|
m_colorbuffer (0),
|
||||||
m_depthbuffer(0)
|
m_depthbuffer (0),
|
||||||
|
m_vsyncEnabled(false),
|
||||||
|
m_clock ()
|
||||||
{
|
{
|
||||||
const WindowImplUIKit* window = static_cast<const WindowImplUIKit*>(owner);
|
const WindowImplUIKit* window = static_cast<const WindowImplUIKit*>(owner);
|
||||||
|
|
||||||
@ -71,10 +76,12 @@ m_depthbuffer(0)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
EaglContext::EaglContext(EaglContext* shared, const ContextSettings& settings,
|
||||||
unsigned int width, unsigned int height) :
|
unsigned int width, unsigned int height) :
|
||||||
m_context (nil),
|
m_context (nil),
|
||||||
m_framebuffer(0),
|
m_framebuffer (0),
|
||||||
m_colorbuffer(0),
|
m_colorbuffer (0),
|
||||||
m_depthbuffer(0)
|
m_depthbuffer (0),
|
||||||
|
m_vsyncEnabled(false),
|
||||||
|
m_clock ()
|
||||||
{
|
{
|
||||||
// This constructor shoult never be used by implementation
|
// This constructor shoult never be used by implementation
|
||||||
err() << "Calling bad EaglContext constructor, please contact your developer :)" << std::endl;
|
err() << "Calling bad EaglContext constructor, please contact your developer :)" << std::endl;
|
||||||
@ -167,12 +174,23 @@ void EaglContext::display()
|
|||||||
{
|
{
|
||||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorbuffer);
|
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorbuffer);
|
||||||
[m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
[m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
||||||
|
|
||||||
|
// The proper way of doing v-sync on iOS would be to use CADisplayLink
|
||||||
|
// notifications, but it is not compatible with the way SFML is designed;
|
||||||
|
// therefore we fake it with a manual framerate limit
|
||||||
|
if (m_vsyncEnabled)
|
||||||
|
{
|
||||||
|
static const Time frameDuration = seconds(1.f / 60.f);
|
||||||
|
sleep(frameDuration - m_clock.getElapsedTime());
|
||||||
|
m_clock.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void EaglContext::setVerticalSyncEnabled(bool enabled)
|
void EaglContext::setVerticalSyncEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
|
m_vsyncEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user