Moved platform OpenGL loading code into their respective context implementations.
This commit is contained in:
parent
38f0464ab0
commit
c30a3da8d5
@ -41,6 +41,8 @@ namespace priv
|
|||||||
class GlContext;
|
class GlContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void (*GlFunctionPointer)();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Class holding a valid drawing context
|
/// \brief Class holding a valid drawing context
|
||||||
///
|
///
|
||||||
@ -76,6 +78,15 @@ public:
|
|||||||
bool setActive(bool active);
|
bool setActive(bool active);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the address of an OpenGL function
|
||||||
|
///
|
||||||
|
/// \param name Name of the function to get the address of
|
||||||
|
///
|
||||||
|
/// \return Address of the OpenGL function, 0 on failure
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static GlFunctionPointer getFunction(const char* name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct a in-memory context
|
/// \brief Construct a in-memory context
|
||||||
|
@ -1,91 +1,17 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
////////////////////////////////////////////////////////////
|
||||||
#include <stddef.h>
|
// Headers
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Graphics/GLLoader.hpp>
|
#include <SFML/Graphics/GLLoader.hpp>
|
||||||
|
#include <SFML/Window/Context.hpp>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
static sf::GlFunctionPointer IntGetProcAddress(const char* name)
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
static void* AppleGLGetProcAddress (const char *name)
|
|
||||||
{
|
{
|
||||||
static void* image = NULL;
|
return sf::Context::getFunction(name);
|
||||||
|
|
||||||
if (NULL == image)
|
|
||||||
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
|
||||||
|
|
||||||
return (image ? dlsym(image, name) : NULL);
|
|
||||||
}
|
}
|
||||||
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
|
|
||||||
#endif /* __APPLE__ */
|
|
||||||
|
|
||||||
#if defined(__sgi) || defined (__sun)
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static void* SunGetProcAddress (const GLubyte* name)
|
|
||||||
{
|
|
||||||
static void* h = NULL;
|
|
||||||
static void* gpa;
|
|
||||||
|
|
||||||
if (h == NULL)
|
|
||||||
{
|
|
||||||
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
|
|
||||||
gpa = dlsym(h, "glXGetProcAddress");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gpa != NULL)
|
|
||||||
return ((void*(*)(const GLubyte*))gpa)(name);
|
|
||||||
else
|
|
||||||
return dlsym(h, (const char*)name);
|
|
||||||
}
|
|
||||||
#endif /* __sgi || __sun */
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning(disable: 4055)
|
|
||||||
#pragma warning(disable: 4054)
|
|
||||||
#pragma warning(disable: 4996)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int TestPointer(const PROC pTest)
|
|
||||||
{
|
|
||||||
ptrdiff_t iTest;
|
|
||||||
if(!pTest) return 0;
|
|
||||||
iTest = (ptrdiff_t)pTest;
|
|
||||||
|
|
||||||
if(iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1) return 0;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PROC WinGetProcAddress(const char *name)
|
|
||||||
{
|
|
||||||
static HMODULE glMod = NULL;
|
|
||||||
PROC pFunc = wglGetProcAddress((LPCSTR)name);
|
|
||||||
|
|
||||||
if (TestPointer(pFunc)) return pFunc;
|
|
||||||
|
|
||||||
if (NULL == glMod)
|
|
||||||
glMod = GetModuleHandleA("OpenGL32.dll");
|
|
||||||
|
|
||||||
return (PROC)GetProcAddress(glMod, (LPCSTR)name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define IntGetProcAddress(name) WinGetProcAddress(name)
|
|
||||||
#else
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
|
|
||||||
#else
|
|
||||||
#if defined(__sgi) || defined(__sun)
|
|
||||||
#define IntGetProcAddress(name) SunGetProcAddress(name)
|
|
||||||
#else /* GLX */
|
|
||||||
#include <GL/glx.h>
|
|
||||||
|
|
||||||
#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*)name)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int sfogl_ext_EXT_blend_minmax = sfogl_LOAD_FAILED;
|
int sfogl_ext_EXT_blend_minmax = sfogl_LOAD_FAILED;
|
||||||
int sfogl_ext_EXT_blend_subtract = sfogl_LOAD_FAILED;
|
int sfogl_ext_EXT_blend_subtract = sfogl_LOAD_FAILED;
|
||||||
|
@ -53,6 +53,13 @@ bool Context::setActive(bool active)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GlFunctionPointer Context::getFunction(const char* name)
|
||||||
|
{
|
||||||
|
return priv::GlContext::getFunction(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Context::Context(const ContextSettings& settings, unsigned int width, unsigned int height)
|
Context::Context(const ContextSettings& settings, unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
|
@ -159,7 +159,7 @@ void GlContext::globalCleanup()
|
|||||||
sharedContext = NULL;
|
sharedContext = NULL;
|
||||||
|
|
||||||
// Destroy the internal contexts
|
// Destroy the internal contexts
|
||||||
sf::Lock lock(internalContextsMutex);
|
Lock internalContextsLock(internalContextsMutex);
|
||||||
for (std::set<GlContext*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
for (std::set<GlContext*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
internalContexts.clear();
|
internalContexts.clear();
|
||||||
@ -213,6 +213,21 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GlFunctionPointer GlContext::getFunction(const char* name)
|
||||||
|
{
|
||||||
|
#if !defined(SFML_OPENGL_ES)
|
||||||
|
|
||||||
|
return ContextType::getFunction(name);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
GlContext::~GlContext()
|
GlContext::~GlContext()
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.hpp>
|
#include <SFML/Config.hpp>
|
||||||
|
#include <SFML/Window/Context.hpp>
|
||||||
#include <SFML/Window/ContextSettings.hpp>
|
#include <SFML/Window/ContextSettings.hpp>
|
||||||
#include <SFML/System/NonCopyable.hpp>
|
#include <SFML/System/NonCopyable.hpp>
|
||||||
|
|
||||||
@ -119,6 +120,15 @@ public:
|
|||||||
static GlContext* create(const ContextSettings& settings, unsigned int width, unsigned int height);
|
static GlContext* create(const ContextSettings& settings, unsigned int width, unsigned int height);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the address of an OpenGL function
|
||||||
|
///
|
||||||
|
/// \param name Name of the function to get the address of
|
||||||
|
///
|
||||||
|
/// \return Address of the OpenGL function, 0 on failure
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static GlFunctionPointer getFunction(const char* name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Destructor
|
/// \brief Destructor
|
||||||
|
@ -103,6 +103,16 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~SFContext();
|
~SFContext();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the address of an OpenGL function
|
||||||
|
///
|
||||||
|
/// \param name Name of the function to get the address of
|
||||||
|
///
|
||||||
|
/// \return Address of the OpenGL function, 0 on failure
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static GlFunctionPointer getFunction(const char* name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Display what has been rendered to the context so far
|
/// \brief Display what has been rendered to the context so far
|
||||||
///
|
///
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#include <SFML/Window/OSX/SFContext.hpp>
|
#include <SFML/Window/OSX/SFContext.hpp>
|
||||||
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
#include <SFML/Window/OSX/WindowImplCocoa.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
|
#import <SFML/Window/OSX/AutoreleasePoolWrapper.h>
|
||||||
|
|
||||||
@ -111,6 +113,18 @@ SFContext::~SFContext()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GlFunctionPointer SFContext::getFunction(const char* name)
|
||||||
|
{
|
||||||
|
static void* image = NULL;
|
||||||
|
|
||||||
|
if (!image)
|
||||||
|
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
||||||
|
|
||||||
|
return (image ? reinterpret_cast<GlFunctionPointer>(reinterpret_cast<intptr_t>(dlsym(image, name))) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool SFContext::makeCurrent()
|
bool SFContext::makeCurrent()
|
||||||
{
|
{
|
||||||
|
@ -177,6 +177,13 @@ GlxContext::~GlxContext()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GlFunctionPointer GlxContext::getFunction(const char* name)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<GlFunctionPointer>(glXGetProcAddressARB(reinterpret_cast<const GLubyte*>(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool GlxContext::makeCurrent()
|
bool GlxContext::makeCurrent()
|
||||||
{
|
{
|
||||||
|
@ -81,6 +81,16 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~GlxContext();
|
~GlxContext();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the address of an OpenGL function
|
||||||
|
///
|
||||||
|
/// \param name Name of the function to get the address of
|
||||||
|
///
|
||||||
|
/// \return Address of the OpenGL function, 0 on failure
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static GlFunctionPointer getFunction(const char* name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate the context as the current target for rendering
|
/// \brief Activate the context as the current target for rendering
|
||||||
///
|
///
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
////////////////////////////////////////////////////////////
|
||||||
#include <stddef.h>
|
// Headers
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Unix/GlxExtensions.hpp>
|
#include <SFML/Window/Unix/GlxExtensions.hpp>
|
||||||
|
#include <SFML/Window/Context.hpp>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include <GL/glx.h>
|
static sf::GlFunctionPointer IntGetProcAddress(const char* name)
|
||||||
|
{
|
||||||
#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*)name)
|
return sf::Context::getFunction(name);
|
||||||
|
}
|
||||||
|
|
||||||
int sfglx_ext_EXT_swap_control = sfglx_LOAD_FAILED;
|
int sfglx_ext_EXT_swap_control = sfglx_LOAD_FAILED;
|
||||||
int sfglx_ext_MESA_swap_control = sfglx_LOAD_FAILED;
|
int sfglx_ext_MESA_swap_control = sfglx_LOAD_FAILED;
|
||||||
|
@ -153,6 +153,32 @@ WglContext::~WglContext()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
GlFunctionPointer WglContext::getFunction(const char* name)
|
||||||
|
{
|
||||||
|
GlFunctionPointer address = reinterpret_cast<GlFunctionPointer>(wglGetProcAddress(reinterpret_cast<LPCSTR>(name)));
|
||||||
|
|
||||||
|
if (address)
|
||||||
|
{
|
||||||
|
// Test whether the returned value is a valid error code
|
||||||
|
ptrdiff_t errorCode = reinterpret_cast<ptrdiff_t>(address);
|
||||||
|
|
||||||
|
if ((errorCode != -1) && (errorCode != 1) && (errorCode != 2) && (errorCode != 3))
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HMODULE module = NULL;
|
||||||
|
|
||||||
|
if (!module)
|
||||||
|
module = GetModuleHandleA("OpenGL32.dll");
|
||||||
|
|
||||||
|
if (module)
|
||||||
|
return reinterpret_cast<GlFunctionPointer>(GetProcAddress(module, reinterpret_cast<LPCSTR>(name)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool WglContext::makeCurrent()
|
bool WglContext::makeCurrent()
|
||||||
{
|
{
|
||||||
|
@ -81,6 +81,16 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
~WglContext();
|
~WglContext();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get the address of an OpenGL function
|
||||||
|
///
|
||||||
|
/// \param name Name of the function to get the address of
|
||||||
|
///
|
||||||
|
/// \return Address of the OpenGL function, 0 on failure
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
static GlFunctionPointer getFunction(const char* name);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Activate the context as the current target for rendering
|
/// \brief Activate the context as the current target for rendering
|
||||||
///
|
///
|
||||||
|
@ -1,29 +1,18 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
////////////////////////////////////////////////////////////
|
||||||
#include <stddef.h>
|
// Headers
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Win32/WglExtensions.hpp>
|
#include <SFML/Window/Win32/WglExtensions.hpp>
|
||||||
|
#include <SFML/Window/Context.hpp>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
static sf::GlFunctionPointer IntGetProcAddress(const char* name)
|
||||||
#pragma warning(disable: 4055)
|
|
||||||
#pragma warning(disable: 4054)
|
|
||||||
#pragma warning(disable: 4996)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static PROC WinGetProcAddress(const char *name)
|
|
||||||
{
|
{
|
||||||
static HMODULE glMod = NULL;
|
return sf::Context::getFunction(name);
|
||||||
PROC pFunc = wglGetProcAddress((LPCSTR)name);
|
|
||||||
|
|
||||||
if (pFunc) return pFunc;
|
|
||||||
|
|
||||||
if (NULL == glMod)
|
|
||||||
glMod = GetModuleHandleA("OpenGL32.dll");
|
|
||||||
|
|
||||||
return (PROC)GetProcAddress(glMod, (LPCSTR)name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IntGetProcAddress(name) WinGetProcAddress(name)
|
|
||||||
|
|
||||||
int sfwgl_ext_EXT_swap_control = sfwgl_LOAD_FAILED;
|
int sfwgl_ext_EXT_swap_control = sfwgl_LOAD_FAILED;
|
||||||
int sfwgl_ext_ARB_multisample = sfwgl_LOAD_FAILED;
|
int sfwgl_ext_ARB_multisample = sfwgl_LOAD_FAILED;
|
||||||
int sfwgl_ext_ARB_pixel_format = sfwgl_LOAD_FAILED;
|
int sfwgl_ext_ARB_pixel_format = sfwgl_LOAD_FAILED;
|
||||||
|
Loading…
Reference in New Issue
Block a user