mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Added methods to get the currently active context, query whether an OpenGL extension is available and query the actual OpenGL version of a context, made context switches during initialization of texture and shader static values unnecessary, fixed code style in loaders.
This commit is contained in:
parent
b7d7ac44f3
commit
2752bbcfb0
@ -36,13 +36,6 @@ int main()
|
||||
text.setColor(sf::Color(255, 255, 255, 170));
|
||||
text.setPosition(250.f, 450.f);
|
||||
|
||||
// Make the window the active target for OpenGL calls
|
||||
// Note: If using sf::Texture or sf::Shader with OpenGL,
|
||||
// be sure to call sf::Texture::getMaximumSize() and/or
|
||||
// sf::Shader::isAvailable() at least once before calling
|
||||
// setActive(), as those functions will cause a context switch
|
||||
window.setActive();
|
||||
|
||||
// Load an OpenGL texture.
|
||||
// We could directly use a sf::Texture as an OpenGL texture (with its Bind() member function),
|
||||
// but here we want more control on it (generate mipmaps, ...) so we create a new one from an image
|
||||
|
@ -498,9 +498,6 @@ public:
|
||||
/// the shader features. If it returns false, then
|
||||
/// any attempt to use sf::Shader will fail.
|
||||
///
|
||||
/// Note: The first call to this function, whether by your
|
||||
/// code or SFML will result in a context switch.
|
||||
///
|
||||
/// \return True if shaders are supported, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -472,9 +472,6 @@ public:
|
||||
/// You can expect a value of 512 pixels for low-end graphics
|
||||
/// card, and up to 8192 pixels or more for newer hardware.
|
||||
///
|
||||
/// Note: The first call to this function, whether by your
|
||||
/// code or SFML will result in a context switch.
|
||||
///
|
||||
/// \return Maximum size allowed for textures, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -77,7 +77,28 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
bool setActive(bool active);
|
||||
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the settings of the context
|
||||
///
|
||||
/// Note that these settings may be different than the ones
|
||||
/// passed to the constructor; they are indeed adjusted if the
|
||||
/// original settings are not directly supported by the system.
|
||||
///
|
||||
/// \return Structure containing the settings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& getSettings() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check whether a given OpenGL extension is available
|
||||
///
|
||||
/// \param name Name of the extension to check for
|
||||
///
|
||||
/// \return True if available, false if unavailable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isExtensionAvailable(const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the address of an OpenGL function
|
||||
///
|
||||
@ -88,6 +109,14 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
static GlFunctionPointer getFunction(const char* name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the currently active context
|
||||
///
|
||||
/// \return The currently active context or NULL if none is active
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static const Context* getActiveContext();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a in-memory context
|
||||
///
|
||||
|
@ -26,6 +26,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/GLExtensions.hpp>
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
|
||||
@ -40,9 +41,16 @@ void ensureExtensionsInit()
|
||||
static bool initialized = false;
|
||||
if (!initialized)
|
||||
{
|
||||
const Context* context = Context::getActiveContext();
|
||||
|
||||
if (!context)
|
||||
return;
|
||||
|
||||
sfogl_LoadFunctions();
|
||||
|
||||
if (!sfogl_IsVersionGEQ(1, 1))
|
||||
ContextSettings settings = context->getSettings();
|
||||
|
||||
if ((settings.majorVersion < 1) || ((settings.majorVersion == 1) && (settings.minorVersion < 1)))
|
||||
{
|
||||
err() << "sfml-graphics requires support for OpenGL 1.1 or greater" << std::endl;
|
||||
err() << "Ensure that hardware acceleration is enabled if available" << std::endl;
|
||||
|
@ -1,10 +1,8 @@
|
||||
// Created with:
|
||||
// https://bitbucket.org/KhronosGroup/glloadgen
|
||||
// Commit d143d66ac90d538ed06f806188714861b8e8e2f9
|
||||
// lua LoadGen.lua -style=pointer_c -spec=gl -version=1.1 -indent=space -prefix=sf -extfile=GLExtensions.txt GLLoader
|
||||
// lua LoadGen.lua
|
||||
|
||||
SGIS_texture_edge_clamp
|
||||
//EXT_texture_edge_clamp
|
||||
EXT_texture_edge_clamp
|
||||
EXT_blend_minmax
|
||||
EXT_blend_subtract
|
||||
ARB_multitexture
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -119,6 +119,8 @@ namespace
|
||||
// Create a temporary context in case the user checks
|
||||
// before a GlResource is created, thus initializing
|
||||
// the shared context
|
||||
if (!sf::Context::getActiveContext())
|
||||
{
|
||||
sf::Context context;
|
||||
|
||||
// Make sure that extensions are initialized
|
||||
@ -132,6 +134,18 @@ namespace
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
// Make sure that extensions are initialized
|
||||
sf::priv::ensureExtensionsInit();
|
||||
|
||||
bool available = GLEXT_multitexture &&
|
||||
GLEXT_shading_language_100 &&
|
||||
GLEXT_shader_objects &&
|
||||
GLEXT_vertex_shader &&
|
||||
GLEXT_fragment_shader;
|
||||
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,6 +58,8 @@ namespace
|
||||
// Create a temporary context in case the user queries
|
||||
// the size before a GlResource is created, thus
|
||||
// initializing the shared context
|
||||
if (!sf::Context::getActiveContext())
|
||||
{
|
||||
sf::Context context;
|
||||
|
||||
GLint size;
|
||||
@ -65,6 +67,12 @@ namespace
|
||||
|
||||
return static_cast<unsigned int>(size);
|
||||
}
|
||||
|
||||
GLint size;
|
||||
glCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size));
|
||||
|
||||
return static_cast<unsigned int>(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,32 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Context.hpp>
|
||||
#include <SFML/Window/GlContext.hpp>
|
||||
#include <SFML/System/ThreadLocalPtr.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
typedef const GLubyte* (APIENTRY *glGetStringiFuncType)(GLenum, GLuint);
|
||||
|
||||
#else
|
||||
|
||||
typedef const GLubyte* (*glGetStringiFuncType)(GLenum, GLuint);
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(GL_NUM_EXTENSIONS)
|
||||
#define GL_NUM_EXTENSIONS 0x821D
|
||||
#endif
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// This per-thread variable holds the current context for each thread
|
||||
sf::ThreadLocalPtr<sf::Context> currentContext(NULL);
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
@ -42,6 +67,7 @@ Context::Context()
|
||||
////////////////////////////////////////////////////////////
|
||||
Context::~Context()
|
||||
{
|
||||
setActive(false);
|
||||
delete m_context;
|
||||
}
|
||||
|
||||
@ -49,7 +75,26 @@ Context::~Context()
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Context::setActive(bool active)
|
||||
{
|
||||
return m_context->setActive(active);
|
||||
bool result = m_context->setActive(active);
|
||||
|
||||
if (result)
|
||||
currentContext = (active ? this : NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const ContextSettings& Context::getSettings() const
|
||||
{
|
||||
return m_context->getSettings();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Context* Context::getActiveContext()
|
||||
{
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +105,67 @@ GlFunctionPointer Context::getFunction(const char* name)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Context::isExtensionAvailable(const char* name)
|
||||
{
|
||||
static std::vector<std::string> extensions;
|
||||
static bool loaded = false;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
const Context* context = getActiveContext();
|
||||
|
||||
if (!context)
|
||||
return false;
|
||||
|
||||
const char* extensionString = NULL;
|
||||
|
||||
if(context->getSettings().majorVersion < 3)
|
||||
{
|
||||
// Try to load the < 3.0 way
|
||||
extensionString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
|
||||
|
||||
do
|
||||
{
|
||||
const char* extension = extensionString;
|
||||
|
||||
while(*extensionString && (*extensionString != ' '))
|
||||
extensionString++;
|
||||
|
||||
extensions.push_back(std::string(extension, extensionString));
|
||||
}
|
||||
while (*extensionString++);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to load the >= 3.0 way
|
||||
glGetStringiFuncType glGetStringiFunc = NULL;
|
||||
glGetStringiFunc = reinterpret_cast<glGetStringiFuncType>(getFunction("glGetStringi"));
|
||||
|
||||
if (glGetStringiFunc)
|
||||
{
|
||||
int numExtensions = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
|
||||
|
||||
if (numExtensions)
|
||||
{
|
||||
for (unsigned int i = 0; i < static_cast<unsigned int>(numExtensions); ++i)
|
||||
{
|
||||
extensionString = reinterpret_cast<const char*>(glGetStringiFunc(GL_EXTENSIONS, i));
|
||||
|
||||
extensions.push_back(extensionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
return std::find(extensions.begin(), extensions.end(), name) != extensions.end();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Context::Context(const ContextSettings& settings, unsigned int width, unsigned int height)
|
||||
{
|
||||
|
@ -131,8 +131,8 @@ namespace
|
||||
ContextType* sharedContext = NULL;
|
||||
|
||||
// Internal contexts
|
||||
sf::ThreadLocalPtr<sf::priv::GlContext> internalContext(NULL);
|
||||
std::set<sf::priv::GlContext*> internalContexts;
|
||||
sf::ThreadLocalPtr<sf::Context> internalContext(NULL);
|
||||
std::set<sf::Context*> internalContexts;
|
||||
sf::Mutex internalContextsMutex;
|
||||
|
||||
// Check if the internal context of the current thread is valid
|
||||
@ -148,11 +148,11 @@ namespace
|
||||
}
|
||||
|
||||
// Retrieve the internal context for the current thread
|
||||
sf::priv::GlContext* getInternalContext()
|
||||
sf::Context* getInternalContext()
|
||||
{
|
||||
if (!hasInternalContext())
|
||||
{
|
||||
internalContext = sf::priv::GlContext::create();
|
||||
internalContext = new sf::Context;
|
||||
sf::Lock lock(internalContextsMutex);
|
||||
internalContexts.insert(internalContext);
|
||||
}
|
||||
@ -171,6 +171,9 @@ void GlContext::globalInit()
|
||||
{
|
||||
Lock lock(mutex);
|
||||
|
||||
if (sharedContext)
|
||||
return;
|
||||
|
||||
// Create the shared context
|
||||
sharedContext = new ContextType(NULL);
|
||||
sharedContext->initialize();
|
||||
@ -187,13 +190,16 @@ void GlContext::globalCleanup()
|
||||
{
|
||||
Lock lock(mutex);
|
||||
|
||||
if (!sharedContext)
|
||||
return;
|
||||
|
||||
// Destroy the shared context
|
||||
delete sharedContext;
|
||||
sharedContext = NULL;
|
||||
|
||||
// Destroy the internal contexts
|
||||
Lock internalContextsLock(internalContextsMutex);
|
||||
for (std::set<GlContext*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
||||
for (std::set<Context*>::iterator it = internalContexts.begin(); it != internalContexts.end(); ++it)
|
||||
delete *it;
|
||||
internalContexts.clear();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
static sf::GlFunctionPointer IntGetProcAddress(const char* name)
|
||||
{
|
||||
@ -43,13 +44,14 @@ int sfglx_ext_ARB_multisample = sfglx_LOAD_FAILED;
|
||||
int sfglx_ext_ARB_create_context = sfglx_LOAD_FAILED;
|
||||
int sfglx_ext_ARB_create_context_profile = sfglx_LOAD_FAILED;
|
||||
|
||||
void (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalEXT)(Display *, GLXDrawable, int) = NULL;
|
||||
void (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalEXT)(Display*, GLXDrawable, int) = NULL;
|
||||
|
||||
static int Load_EXT_swap_control(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_glXSwapIntervalEXT = (void (CODEGEN_FUNCPTR *)(Display *, GLXDrawable, int))IntGetProcAddress("glXSwapIntervalEXT");
|
||||
if(!sf_ptrc_glXSwapIntervalEXT) numFailed++;
|
||||
sf_ptrc_glXSwapIntervalEXT = reinterpret_cast<void (CODEGEN_FUNCPTR*)(Display*, GLXDrawable, int)>(IntGetProcAddress("glXSwapIntervalEXT"));
|
||||
if (!sf_ptrc_glXSwapIntervalEXT)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
@ -58,8 +60,9 @@ int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalMESA)(int) = NULL;
|
||||
static int Load_MESA_swap_control(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_glXSwapIntervalMESA = (int (CODEGEN_FUNCPTR *)(int))IntGetProcAddress("glXSwapIntervalMESA");
|
||||
if(!sf_ptrc_glXSwapIntervalMESA) numFailed++;
|
||||
sf_ptrc_glXSwapIntervalMESA = reinterpret_cast<int (CODEGEN_FUNCPTR*)(int)>(IntGetProcAddress("glXSwapIntervalMESA"));
|
||||
if (!sf_ptrc_glXSwapIntervalMESA)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
@ -68,26 +71,28 @@ int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalSGI)(int) = NULL;
|
||||
static int Load_SGI_swap_control(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_glXSwapIntervalSGI = (int (CODEGEN_FUNCPTR *)(int))IntGetProcAddress("glXSwapIntervalSGI");
|
||||
if(!sf_ptrc_glXSwapIntervalSGI) numFailed++;
|
||||
sf_ptrc_glXSwapIntervalSGI = reinterpret_cast<int (CODEGEN_FUNCPTR *)(int)>(IntGetProcAddress("glXSwapIntervalSGI"));
|
||||
if (!sf_ptrc_glXSwapIntervalSGI)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *) = NULL;
|
||||
GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext, Bool, const int*) = NULL;
|
||||
|
||||
static int Load_ARB_create_context(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_glXCreateContextAttribsARB = (GLXContext (CODEGEN_FUNCPTR *)(Display *, GLXFBConfig, GLXContext, Bool, const int *))IntGetProcAddress("glXCreateContextAttribsARB");
|
||||
if(!sf_ptrc_glXCreateContextAttribsARB) numFailed++;
|
||||
sf_ptrc_glXCreateContextAttribsARB = reinterpret_cast<GLXContext (CODEGEN_FUNCPTR*)(Display*, GLXFBConfig, GLXContext, Bool, const int*)>(IntGetProcAddress("glXCreateContextAttribsARB"));
|
||||
if (!sf_ptrc_glXCreateContextAttribsARB)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
typedef int (*PFN_LOADFUNCPOINTERS)(void);
|
||||
typedef struct sfglx_StrToExtMap_s
|
||||
{
|
||||
const char *extensionName;
|
||||
int *extensionVariable;
|
||||
const char* extensionName;
|
||||
int* extensionVariable;
|
||||
PFN_LOADFUNCPOINTERS LoadExtension;
|
||||
} sfglx_StrToExtMap;
|
||||
|
||||
@ -102,19 +107,20 @@ static sfglx_StrToExtMap ExtensionMap[6] = {
|
||||
|
||||
static int g_extensionMapSize = 6;
|
||||
|
||||
static sfglx_StrToExtMap *FindExtEntry(const char *extensionName)
|
||||
|
||||
static sfglx_StrToExtMap* FindExtEntry(const char* extensionName)
|
||||
{
|
||||
int loop;
|
||||
sfglx_StrToExtMap *currLoc = ExtensionMap;
|
||||
for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
|
||||
sfglx_StrToExtMap* currLoc = ExtensionMap;
|
||||
for (int loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
|
||||
{
|
||||
if(strcmp(extensionName, currLoc->extensionName) == 0)
|
||||
if (std::strcmp(extensionName, currLoc->extensionName) == 0)
|
||||
return currLoc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void ClearExtensionVars(void)
|
||||
{
|
||||
sfglx_ext_EXT_swap_control = sfglx_LOAD_FAILED;
|
||||
@ -126,16 +132,16 @@ static void ClearExtensionVars(void)
|
||||
}
|
||||
|
||||
|
||||
static void LoadExtByName(const char *extensionName)
|
||||
static void LoadExtByName(const char* extensionName)
|
||||
{
|
||||
sfglx_StrToExtMap *entry = NULL;
|
||||
sfglx_StrToExtMap* entry = NULL;
|
||||
entry = FindExtEntry(extensionName);
|
||||
if(entry)
|
||||
if (entry)
|
||||
{
|
||||
if(entry->LoadExtension)
|
||||
if (entry->LoadExtension)
|
||||
{
|
||||
int numFailed = entry->LoadExtension();
|
||||
if(numFailed == 0)
|
||||
if (numFailed == 0)
|
||||
{
|
||||
*(entry->extensionVariable) = sfglx_LOAD_SUCCEEDED;
|
||||
}
|
||||
@ -152,46 +158,25 @@ static void LoadExtByName(const char *extensionName)
|
||||
}
|
||||
|
||||
|
||||
static void ProcExtsFromExtString(const char *strExtList)
|
||||
static void ProcExtsFromExtString(const char* strExtList)
|
||||
{
|
||||
size_t iExtListLen = strlen(strExtList);
|
||||
const char *strExtListEnd = strExtList + iExtListLen;
|
||||
const char *strCurrPos = strExtList;
|
||||
char strWorkBuff[256];
|
||||
|
||||
while(*strCurrPos)
|
||||
do
|
||||
{
|
||||
/*Get the extension at our position.*/
|
||||
int iStrLen = 0;
|
||||
const char *strEndStr = strchr(strCurrPos, ' ');
|
||||
int iStop = 0;
|
||||
if(strEndStr == NULL)
|
||||
{
|
||||
strEndStr = strExtListEnd;
|
||||
iStop = 1;
|
||||
}
|
||||
const char* begin = strExtList;
|
||||
|
||||
iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos);
|
||||
while ((*strExtList != ' ') && *strExtList)
|
||||
strExtList++;
|
||||
|
||||
if(iStrLen > 255)
|
||||
return;
|
||||
|
||||
strncpy(strWorkBuff, strCurrPos, iStrLen);
|
||||
strWorkBuff[iStrLen] = '\0';
|
||||
|
||||
LoadExtByName(strWorkBuff);
|
||||
|
||||
strCurrPos = strEndStr + 1;
|
||||
if(iStop) break;
|
||||
}
|
||||
LoadExtByName(std::string(begin, strExtList).c_str());
|
||||
} while (*strExtList++);
|
||||
}
|
||||
|
||||
int sfglx_LoadFunctions(Display *display, int screen)
|
||||
|
||||
int sfglx_LoadFunctions(Display* display, int screen)
|
||||
{
|
||||
ClearExtensionVars();
|
||||
|
||||
|
||||
ProcExtsFromExtString((const char *)glXQueryExtensionsString(display, screen));
|
||||
ProcExtsFromExtString(reinterpret_cast<const char*>(glXQueryExtensionsString(display, screen)));
|
||||
return sfglx_LOAD_SUCCEEDED;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <GL/glx.h>
|
||||
#ifdef CODEGEN_FUNCPTR
|
||||
#undef CODEGEN_FUNCPTR
|
||||
#endif /*CODEGEN_FUNCPTR*/
|
||||
#endif // CODEGEN_FUNCPTR
|
||||
#define CODEGEN_FUNCPTR
|
||||
|
||||
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
@ -58,21 +58,21 @@ typedef double GLdouble;
|
||||
typedef double GLclampd;
|
||||
#define GLvoid void
|
||||
|
||||
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
|
||||
#endif // GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
|
||||
#endif // GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
#ifndef GLEXT_64_TYPES_DEFINED
|
||||
/* This code block is duplicated in glext.h, so must be protected */
|
||||
// This code block is duplicated in glext.h, so must be protected
|
||||
#define GLEXT_64_TYPES_DEFINED
|
||||
/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
|
||||
/* (as used in the GLX_OML_sync_control extension). */
|
||||
// Define int32_t, int64_t, and uint64_t types for UST/MSC
|
||||
// (as used in the GLX_OML_sync_control extension).
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
#include <inttypes.h>
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
@ -84,8 +84,8 @@ typedef unsigned long int uint64_t;
|
||||
#else
|
||||
typedef long long int int64_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#endif /* __STDC__ */
|
||||
#endif // __arch64__
|
||||
#endif // __STDC__
|
||||
#elif defined( __VMS ) || defined(__sgi)
|
||||
#include <inttypes.h>
|
||||
#elif defined(__SCO__) || defined(__USLC__)
|
||||
@ -101,7 +101,7 @@ typedef __int32 int32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
/* Fallback if nothing above works */
|
||||
// Fallback if nothing above works
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#endif
|
||||
@ -118,28 +118,28 @@ typedef unsigned __int64 uint64_t;
|
||||
typedef struct __GLXFBConfigRec *GLXFBConfigSGIX;
|
||||
typedef XID GLXPbufferSGIX;
|
||||
typedef struct {
|
||||
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
|
||||
char pipeName[80]; // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]
|
||||
int networkId;
|
||||
} GLXHyperpipeNetworkSGIX;
|
||||
typedef struct {
|
||||
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
|
||||
char pipeName[80]; // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]
|
||||
int channel;
|
||||
unsigned int participationType;
|
||||
int timeSlice;
|
||||
} GLXHyperpipeConfigSGIX;
|
||||
typedef struct {
|
||||
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
|
||||
char pipeName[80]; // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]
|
||||
int srcXOrigin, srcYOrigin, srcWidth, srcHeight;
|
||||
int destXOrigin, destYOrigin, destWidth, destHeight;
|
||||
} GLXPipeRect;
|
||||
typedef struct {
|
||||
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
|
||||
char pipeName[80]; // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX]
|
||||
int XOrigin, YOrigin, maxHeight, maxWidth;
|
||||
} GLXPipeRectLimits;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
#endif // __cplusplus
|
||||
|
||||
extern int sfglx_ext_EXT_swap_control;
|
||||
extern int sfglx_ext_MESA_swap_control;
|
||||
@ -168,7 +168,7 @@ extern int sfglx_ext_ARB_create_context_profile;
|
||||
#define GLX_EXT_swap_control 1
|
||||
extern void (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalEXT)(Display *, GLXDrawable, int);
|
||||
#define glXSwapIntervalEXT sf_ptrc_glXSwapIntervalEXT
|
||||
#endif /*GLX_EXT_swap_control*/
|
||||
#endif // GLX_EXT_swap_control
|
||||
|
||||
// Declare entry point even if GLX header already provides glXSwapIntervalMESA
|
||||
// We won't make use of an alias here
|
||||
@ -178,13 +178,13 @@ extern int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalMESA)(int);
|
||||
#define GLX_SGI_swap_control 1
|
||||
extern int (CODEGEN_FUNCPTR *sf_ptrc_glXSwapIntervalSGI)(int);
|
||||
#define glXSwapIntervalSGI sf_ptrc_glXSwapIntervalSGI
|
||||
#endif /*GLX_SGI_swap_control*/
|
||||
#endif // GLX_SGI_swap_control
|
||||
|
||||
#ifndef GLX_ARB_create_context
|
||||
#define GLX_ARB_create_context 1
|
||||
extern GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
|
||||
extern GLXContext (CODEGEN_FUNCPTR *sf_ptrc_glXCreateContextAttribsARB)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||
#define glXCreateContextAttribsARB sf_ptrc_glXCreateContextAttribsARB
|
||||
#endif /*GLX_ARB_create_context*/
|
||||
#endif // GLX_ARB_create_context
|
||||
|
||||
|
||||
enum sfglx_LoadStatus
|
||||
@ -198,6 +198,6 @@ int sfglx_LoadFunctions(Display *display, int screen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* SF_POINTER_C_GENERATED_HEADER_GLXWIN_HPP */
|
||||
#endif // SF_POINTER_C_GENERATED_HEADER_GLXWIN_HPP
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
static sf::GlFunctionPointer IntGetProcAddress(const char* name)
|
||||
{
|
||||
@ -48,47 +49,53 @@ BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglSwapIntervalEXT)(int) = NULL;
|
||||
static int Load_EXT_swap_control(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_wglGetSwapIntervalEXT = (int (CODEGEN_FUNCPTR *)(void))IntGetProcAddress("wglGetSwapIntervalEXT");
|
||||
if(!sf_ptrc_wglGetSwapIntervalEXT) numFailed++;
|
||||
sf_ptrc_wglSwapIntervalEXT = (BOOL (CODEGEN_FUNCPTR *)(int))IntGetProcAddress("wglSwapIntervalEXT");
|
||||
if(!sf_ptrc_wglSwapIntervalEXT) numFailed++;
|
||||
sf_ptrc_wglGetSwapIntervalEXT = reinterpret_cast<int (CODEGEN_FUNCPTR*)(void)>(IntGetProcAddress("wglGetSwapIntervalEXT"));
|
||||
if (!sf_ptrc_wglGetSwapIntervalEXT)
|
||||
numFailed++;
|
||||
sf_ptrc_wglSwapIntervalEXT = reinterpret_cast<BOOL (CODEGEN_FUNCPTR*)(int)>(IntGetProcAddress("wglSwapIntervalEXT"));
|
||||
if (!sf_ptrc_wglSwapIntervalEXT)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *) = NULL;
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int *, FLOAT *) = NULL;
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *) = NULL;
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int*, const FLOAT*, UINT, int*, UINT*) = NULL;
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int*, FLOAT*) = NULL;
|
||||
BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int*, int*) = NULL;
|
||||
|
||||
static int Load_ARB_pixel_format(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_wglChoosePixelFormatARB = (BOOL (CODEGEN_FUNCPTR *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))IntGetProcAddress("wglChoosePixelFormatARB");
|
||||
if(!sf_ptrc_wglChoosePixelFormatARB) numFailed++;
|
||||
sf_ptrc_wglGetPixelFormatAttribfvARB = (BOOL (CODEGEN_FUNCPTR *)(HDC, int, int, UINT, const int *, FLOAT *))IntGetProcAddress("wglGetPixelFormatAttribfvARB");
|
||||
if(!sf_ptrc_wglGetPixelFormatAttribfvARB) numFailed++;
|
||||
sf_ptrc_wglGetPixelFormatAttribivARB = (BOOL (CODEGEN_FUNCPTR *)(HDC, int, int, UINT, const int *, int *))IntGetProcAddress("wglGetPixelFormatAttribivARB");
|
||||
if(!sf_ptrc_wglGetPixelFormatAttribivARB) numFailed++;
|
||||
sf_ptrc_wglChoosePixelFormatARB = reinterpret_cast<BOOL (CODEGEN_FUNCPTR*)(HDC, const int*, const FLOAT*, UINT, int*, UINT*)>(IntGetProcAddress("wglChoosePixelFormatARB"));
|
||||
if (!sf_ptrc_wglChoosePixelFormatARB)
|
||||
numFailed++;
|
||||
sf_ptrc_wglGetPixelFormatAttribfvARB = reinterpret_cast<BOOL (CODEGEN_FUNCPTR *)(HDC, int, int, UINT, const int*, FLOAT*)>(IntGetProcAddress("wglGetPixelFormatAttribfvARB"));
|
||||
if (!sf_ptrc_wglGetPixelFormatAttribfvARB)
|
||||
numFailed++;
|
||||
sf_ptrc_wglGetPixelFormatAttribivARB = reinterpret_cast<BOOL (CODEGEN_FUNCPTR*)(HDC, int, int, UINT, const int*, int*)>(IntGetProcAddress("wglGetPixelFormatAttribivARB"));
|
||||
if (!sf_ptrc_wglGetPixelFormatAttribivARB)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int *) = NULL;
|
||||
HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int*) = NULL;
|
||||
|
||||
static int Load_ARB_create_context(void)
|
||||
{
|
||||
int numFailed = 0;
|
||||
sf_ptrc_wglCreateContextAttribsARB = (HGLRC (CODEGEN_FUNCPTR *)(HDC, HGLRC, const int *))IntGetProcAddress("wglCreateContextAttribsARB");
|
||||
if(!sf_ptrc_wglCreateContextAttribsARB) numFailed++;
|
||||
sf_ptrc_wglCreateContextAttribsARB = reinterpret_cast<HGLRC (CODEGEN_FUNCPTR*)(HDC, HGLRC, const int*)>(IntGetProcAddress("wglCreateContextAttribsARB"));
|
||||
if (!sf_ptrc_wglCreateContextAttribsARB)
|
||||
numFailed++;
|
||||
return numFailed;
|
||||
}
|
||||
|
||||
|
||||
static const char * (CODEGEN_FUNCPTR *sf_ptrc_wglGetExtensionsStringARB)(HDC) = NULL;
|
||||
static const char* (CODEGEN_FUNCPTR *sf_ptrc_wglGetExtensionsStringARB)(HDC) = NULL;
|
||||
|
||||
typedef int (*PFN_LOADFUNCPOINTERS)(void);
|
||||
typedef struct sfwgl_StrToExtMap_s
|
||||
{
|
||||
const char *extensionName;
|
||||
int *extensionVariable;
|
||||
const char* extensionName;
|
||||
int* extensionVariable;
|
||||
PFN_LOADFUNCPOINTERS LoadExtension;
|
||||
} sfwgl_StrToExtMap;
|
||||
|
||||
@ -102,19 +109,20 @@ static sfwgl_StrToExtMap ExtensionMap[5] = {
|
||||
|
||||
static int g_extensionMapSize = 5;
|
||||
|
||||
static sfwgl_StrToExtMap *FindExtEntry(const char *extensionName)
|
||||
|
||||
static sfwgl_StrToExtMap* FindExtEntry(const char* extensionName)
|
||||
{
|
||||
int loop;
|
||||
sfwgl_StrToExtMap *currLoc = ExtensionMap;
|
||||
for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
|
||||
sfwgl_StrToExtMap* currLoc = ExtensionMap;
|
||||
for (int loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
|
||||
{
|
||||
if(strcmp(extensionName, currLoc->extensionName) == 0)
|
||||
if (std::strcmp(extensionName, currLoc->extensionName) == 0)
|
||||
return currLoc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void ClearExtensionVars(void)
|
||||
{
|
||||
sfwgl_ext_EXT_swap_control = sfwgl_LOAD_FAILED;
|
||||
@ -125,16 +133,16 @@ static void ClearExtensionVars(void)
|
||||
}
|
||||
|
||||
|
||||
static void LoadExtByName(const char *extensionName)
|
||||
static void LoadExtByName(const char* extensionName)
|
||||
{
|
||||
sfwgl_StrToExtMap *entry = NULL;
|
||||
sfwgl_StrToExtMap* entry = NULL;
|
||||
entry = FindExtEntry(extensionName);
|
||||
if(entry)
|
||||
if (entry)
|
||||
{
|
||||
if(entry->LoadExtension)
|
||||
if (entry->LoadExtension)
|
||||
{
|
||||
int numFailed = entry->LoadExtension();
|
||||
if(numFailed == 0)
|
||||
if (numFailed == 0)
|
||||
{
|
||||
*(entry->extensionVariable) = sfwgl_LOAD_SUCCEEDED;
|
||||
}
|
||||
@ -151,48 +159,29 @@ static void LoadExtByName(const char *extensionName)
|
||||
}
|
||||
|
||||
|
||||
static void ProcExtsFromExtString(const char *strExtList)
|
||||
static void ProcExtsFromExtString(const char* strExtList)
|
||||
{
|
||||
size_t iExtListLen = strlen(strExtList);
|
||||
const char *strExtListEnd = strExtList + iExtListLen;
|
||||
const char *strCurrPos = strExtList;
|
||||
char strWorkBuff[256];
|
||||
|
||||
while(*strCurrPos)
|
||||
do
|
||||
{
|
||||
/*Get the extension at our position.*/
|
||||
int iStrLen = 0;
|
||||
const char *strEndStr = strchr(strCurrPos, ' ');
|
||||
int iStop = 0;
|
||||
if(strEndStr == NULL)
|
||||
{
|
||||
strEndStr = strExtListEnd;
|
||||
iStop = 1;
|
||||
}
|
||||
const char* begin = strExtList;
|
||||
|
||||
iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos);
|
||||
while ((*strExtList != ' ') && *strExtList)
|
||||
strExtList++;
|
||||
|
||||
if(iStrLen > 255)
|
||||
return;
|
||||
|
||||
strncpy(strWorkBuff, strCurrPos, iStrLen);
|
||||
strWorkBuff[iStrLen] = '\0';
|
||||
|
||||
LoadExtByName(strWorkBuff);
|
||||
|
||||
strCurrPos = strEndStr + 1;
|
||||
if(iStop) break;
|
||||
}
|
||||
LoadExtByName(std::string(begin, strExtList).c_str());
|
||||
} while (*strExtList++);
|
||||
}
|
||||
|
||||
|
||||
int sfwgl_LoadFunctions(HDC hdc)
|
||||
{
|
||||
ClearExtensionVars();
|
||||
|
||||
sf_ptrc_wglGetExtensionsStringARB = (const char * (CODEGEN_FUNCPTR *)(HDC))IntGetProcAddress("wglGetExtensionsStringARB");
|
||||
if(!sf_ptrc_wglGetExtensionsStringARB) return sfwgl_LOAD_FAILED;
|
||||
sf_ptrc_wglGetExtensionsStringARB = reinterpret_cast<const char* (CODEGEN_FUNCPTR*)(HDC)>(IntGetProcAddress("wglGetExtensionsStringARB"));
|
||||
if (!sf_ptrc_wglGetExtensionsStringARB)
|
||||
return sfwgl_LOAD_FAILED;
|
||||
|
||||
ProcExtsFromExtString((const char *)sf_ptrc_wglGetExtensionsStringARB(hdc));
|
||||
ProcExtsFromExtString(reinterpret_cast<const char*>(sf_ptrc_wglGetExtensionsStringARB(hdc)));
|
||||
return sfwgl_LOAD_SUCCEEDED;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#ifdef CODEGEN_FUNCPTR
|
||||
#undef CODEGEN_FUNCPTR
|
||||
#endif /*CODEGEN_FUNCPTR*/
|
||||
#endif // CODEGEN_FUNCPTR
|
||||
#define CODEGEN_FUNCPTR WINAPI
|
||||
|
||||
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
@ -63,14 +63,14 @@ typedef double GLdouble;
|
||||
typedef double GLclampd;
|
||||
#define GLvoid void
|
||||
|
||||
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
|
||||
#endif // GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
|
||||
#endif // GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
|
||||
|
||||
|
||||
struct _GPU_DEVICE {
|
||||
@ -90,7 +90,7 @@ typedef struct _GPU_DEVICE *PGPU_DEVICE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
#endif // __cplusplus
|
||||
|
||||
extern int sfwgl_ext_EXT_swap_control;
|
||||
extern int sfwgl_ext_ARB_multisample;
|
||||
@ -170,24 +170,24 @@ extern int (CODEGEN_FUNCPTR *sf_ptrc_wglGetSwapIntervalEXT)(void);
|
||||
#define wglGetSwapIntervalEXT sf_ptrc_wglGetSwapIntervalEXT
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglSwapIntervalEXT)(int);
|
||||
#define wglSwapIntervalEXT sf_ptrc_wglSwapIntervalEXT
|
||||
#endif /*WGL_EXT_swap_control*/
|
||||
#endif // WGL_EXT_swap_control
|
||||
|
||||
|
||||
#ifndef WGL_ARB_pixel_format
|
||||
#define WGL_ARB_pixel_format 1
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int *, const FLOAT *, UINT, int *, UINT *);
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglChoosePixelFormatARB)(HDC, const int*, const FLOAT*, UINT, int*, UINT*);
|
||||
#define wglChoosePixelFormatARB sf_ptrc_wglChoosePixelFormatARB
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int *, FLOAT *);
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribfvARB)(HDC, int, int, UINT, const int*, FLOAT*);
|
||||
#define wglGetPixelFormatAttribfvARB sf_ptrc_wglGetPixelFormatAttribfvARB
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int *, int *);
|
||||
extern BOOL (CODEGEN_FUNCPTR *sf_ptrc_wglGetPixelFormatAttribivARB)(HDC, int, int, UINT, const int*, int*);
|
||||
#define wglGetPixelFormatAttribivARB sf_ptrc_wglGetPixelFormatAttribivARB
|
||||
#endif /*WGL_ARB_pixel_format*/
|
||||
#endif // WGL_ARB_pixel_format
|
||||
|
||||
#ifndef WGL_ARB_create_context
|
||||
#define WGL_ARB_create_context 1
|
||||
extern HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int *);
|
||||
extern HGLRC (CODEGEN_FUNCPTR *sf_ptrc_wglCreateContextAttribsARB)(HDC, HGLRC, const int*);
|
||||
#define wglCreateContextAttribsARB sf_ptrc_wglCreateContextAttribsARB
|
||||
#endif /*WGL_ARB_create_context*/
|
||||
#endif // WGL_ARB_create_context
|
||||
|
||||
|
||||
enum sfwgl_LoadStatus
|
||||
@ -201,6 +201,6 @@ int sfwgl_LoadFunctions(HDC hdc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* SF_POINTER_C_GENERATED_HEADER_WINDOWSGL_HPP */
|
||||
#endif // SF_POINTER_C_GENERATED_HEADER_WINDOWSGL_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user