glx_obs.c 8.0 KB
Newer Older
1
/* AUTOGENERATED BY glLoadGen, DO NOT EDIT */
2 3 4 5 6 7
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "glx_obs.h"

#if defined(__APPLE__)
8
#include <dlfcn.h>
9

Z
Zachary Lund 已提交
10
static void* AppleGLGetProcAddress (const const char *name)
11
{
12
	static void* image = NULL;
Z
Zachary Lund 已提交
13 14
	
	if (NULL == image)
15 16 17
		image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);

	return (image ? dlsym(image, name) : NULL);
18
}
Z
Zachary Lund 已提交
19
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
20 21 22 23 24 25 26
#endif /* __APPLE__ */

#if defined(_WIN32)

#ifdef _MSC_VER
#pragma warning(disable: 4055)
#pragma warning(disable: 4054)
Z
Zachary Lund 已提交
27
#pragma warning(disable: 4996)
28 29
#endif
	
Z
Zachary Lund 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43
static PROC WinGetProcAddress(const char *name)
{
	static HMODULE glMod = NULL;
	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)
Z
Zachary Lund 已提交
44
#endif
45

Z
Zachary Lund 已提交
46 47
/* Linux, FreeBSD, other */
#ifndef IntGetProcAddress
48
	extern void ( * glXGetProcAddressARB (const GLubyte *procName)) (void);
49

Z
Zachary Lund 已提交
50
	#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*)name)
51 52
#endif

53 54 55
/* TODO: Need to eventually use eglGetProcAddress */

int glx_ext_NV_copy_image = glx_LOAD_FAILED;
56 57 58 59 60 61 62 63 64 65 66 67 68
int glx_ext_ARB_create_context = glx_LOAD_FAILED;
int glx_ext_ARB_create_context_profile = glx_LOAD_FAILED;
int glx_ext_ARB_create_context_robustness = glx_LOAD_FAILED;
int glx_ext_ARB_fbconfig_float = glx_LOAD_FAILED;
int glx_ext_ARB_framebuffer_sRGB = glx_LOAD_FAILED;
int glx_ext_ARB_multisample = glx_LOAD_FAILED;
int glx_ext_EXT_create_context_es2_profile = glx_LOAD_FAILED;
int glx_ext_EXT_fbconfig_packed_float = glx_LOAD_FAILED;
int glx_ext_EXT_framebuffer_sRGB = glx_LOAD_FAILED;
int glx_ext_EXT_import_context = glx_LOAD_FAILED;
int glx_ext_EXT_swap_control = glx_LOAD_FAILED;
int glx_ext_EXT_swap_control_tear = glx_LOAD_FAILED;

69 70 71 72 73 74 75 76 77 78
void (CODEGEN_FUNCPTR *_ptrc_glXCopyImageSubDataNV)(Display *, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei) = NULL;

static int Load_NV_copy_image(void)
{
	int numFailed = 0;
	_ptrc_glXCopyImageSubDataNV = (void (CODEGEN_FUNCPTR *)(Display *, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLXContext, GLuint, GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei))IntGetProcAddress("glXCopyImageSubDataNV");
	if(!_ptrc_glXCopyImageSubDataNV) numFailed++;
	return numFailed;
}

79 80
GLXContext (CODEGEN_FUNCPTR *_ptrc_glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *) = NULL;

81
static int Load_ARB_create_context(void)
82 83 84 85 86 87 88 89 90
{
	int numFailed = 0;
	_ptrc_glXCreateContextAttribsARB = (GLXContext (CODEGEN_FUNCPTR *)(Display *, GLXFBConfig, GLXContext, Bool, const int *))IntGetProcAddress("glXCreateContextAttribsARB");
	if(!_ptrc_glXCreateContextAttribsARB) numFailed++;
	return numFailed;
}

void (CODEGEN_FUNCPTR *_ptrc_glXFreeContextEXT)(Display *, GLXContext) = NULL;
GLXContextID (CODEGEN_FUNCPTR *_ptrc_glXGetContextIDEXT)(const GLXContext) = NULL;
91
Display * (CODEGEN_FUNCPTR *_ptrc_glXGetCurrentDisplayEXT)(void) = NULL;
92 93 94
GLXContext (CODEGEN_FUNCPTR *_ptrc_glXImportContextEXT)(Display *, GLXContextID) = NULL;
int (CODEGEN_FUNCPTR *_ptrc_glXQueryContextInfoEXT)(Display *, GLXContext, int, int *) = NULL;

95
static int Load_EXT_import_context(void)
96 97 98 99 100 101
{
	int numFailed = 0;
	_ptrc_glXFreeContextEXT = (void (CODEGEN_FUNCPTR *)(Display *, GLXContext))IntGetProcAddress("glXFreeContextEXT");
	if(!_ptrc_glXFreeContextEXT) numFailed++;
	_ptrc_glXGetContextIDEXT = (GLXContextID (CODEGEN_FUNCPTR *)(const GLXContext))IntGetProcAddress("glXGetContextIDEXT");
	if(!_ptrc_glXGetContextIDEXT) numFailed++;
102
	_ptrc_glXGetCurrentDisplayEXT = (Display * (CODEGEN_FUNCPTR *)(void))IntGetProcAddress("glXGetCurrentDisplayEXT");
103 104 105 106 107 108 109 110 111 112
	if(!_ptrc_glXGetCurrentDisplayEXT) numFailed++;
	_ptrc_glXImportContextEXT = (GLXContext (CODEGEN_FUNCPTR *)(Display *, GLXContextID))IntGetProcAddress("glXImportContextEXT");
	if(!_ptrc_glXImportContextEXT) numFailed++;
	_ptrc_glXQueryContextInfoEXT = (int (CODEGEN_FUNCPTR *)(Display *, GLXContext, int, int *))IntGetProcAddress("glXQueryContextInfoEXT");
	if(!_ptrc_glXQueryContextInfoEXT) numFailed++;
	return numFailed;
}

void (CODEGEN_FUNCPTR *_ptrc_glXSwapIntervalEXT)(Display *, GLXDrawable, int) = NULL;

113
static int Load_EXT_swap_control(void)
114 115 116 117 118 119 120
{
	int numFailed = 0;
	_ptrc_glXSwapIntervalEXT = (void (CODEGEN_FUNCPTR *)(Display *, GLXDrawable, int))IntGetProcAddress("glXSwapIntervalEXT");
	if(!_ptrc_glXSwapIntervalEXT) numFailed++;
	return numFailed;
}

121
typedef int (*PFN_LOADFUNCPOINTERS)(void);
122 123
typedef struct glx_StrToExtMap_s
{
124
	const char *extensionName;
125 126 127 128
	int *extensionVariable;
	PFN_LOADFUNCPOINTERS LoadExtension;
} glx_StrToExtMap;

129 130
static glx_StrToExtMap ExtensionMap[13] = {
	{"GLX_NV_copy_image", &glx_ext_NV_copy_image, Load_NV_copy_image},
131 132 133 134 135 136 137 138 139 140 141 142 143 144
	{"GLX_ARB_create_context", &glx_ext_ARB_create_context, Load_ARB_create_context},
	{"GLX_ARB_create_context_profile", &glx_ext_ARB_create_context_profile, NULL},
	{"GLX_ARB_create_context_robustness", &glx_ext_ARB_create_context_robustness, NULL},
	{"GLX_ARB_fbconfig_float", &glx_ext_ARB_fbconfig_float, NULL},
	{"GLX_ARB_framebuffer_sRGB", &glx_ext_ARB_framebuffer_sRGB, NULL},
	{"GLX_ARB_multisample", &glx_ext_ARB_multisample, NULL},
	{"GLX_EXT_create_context_es2_profile", &glx_ext_EXT_create_context_es2_profile, NULL},
	{"GLX_EXT_fbconfig_packed_float", &glx_ext_EXT_fbconfig_packed_float, NULL},
	{"GLX_EXT_framebuffer_sRGB", &glx_ext_EXT_framebuffer_sRGB, NULL},
	{"GLX_EXT_import_context", &glx_ext_EXT_import_context, Load_EXT_import_context},
	{"GLX_EXT_swap_control", &glx_ext_EXT_swap_control, Load_EXT_swap_control},
	{"GLX_EXT_swap_control_tear", &glx_ext_EXT_swap_control_tear, NULL},
};

145
static int g_extensionMapSize = 13;
146 147 148 149 150 151 152 153 154 155 156 157 158 159

static glx_StrToExtMap *FindExtEntry(const char *extensionName)
{
	int loop;
	glx_StrToExtMap *currLoc = ExtensionMap;
	for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
	{
		if(strcmp(extensionName, currLoc->extensionName) == 0)
			return currLoc;
	}
	
	return NULL;
}

160
static void ClearExtensionVars(void)
161
{
162
	glx_ext_NV_copy_image = glx_LOAD_FAILED;
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
	glx_ext_ARB_create_context = glx_LOAD_FAILED;
	glx_ext_ARB_create_context_profile = glx_LOAD_FAILED;
	glx_ext_ARB_create_context_robustness = glx_LOAD_FAILED;
	glx_ext_ARB_fbconfig_float = glx_LOAD_FAILED;
	glx_ext_ARB_framebuffer_sRGB = glx_LOAD_FAILED;
	glx_ext_ARB_multisample = glx_LOAD_FAILED;
	glx_ext_EXT_create_context_es2_profile = glx_LOAD_FAILED;
	glx_ext_EXT_fbconfig_packed_float = glx_LOAD_FAILED;
	glx_ext_EXT_framebuffer_sRGB = glx_LOAD_FAILED;
	glx_ext_EXT_import_context = glx_LOAD_FAILED;
	glx_ext_EXT_swap_control = glx_LOAD_FAILED;
	glx_ext_EXT_swap_control_tear = glx_LOAD_FAILED;
}


static void LoadExtByName(const char *extensionName)
{
	glx_StrToExtMap *entry = NULL;
	entry = FindExtEntry(extensionName);
	if(entry)
	{
		if(entry->LoadExtension)
		{
			int numFailed = entry->LoadExtension();
			if(numFailed == 0)
			{
				*(entry->extensionVariable) = glx_LOAD_SUCCEEDED;
			}
			else
			{
				*(entry->extensionVariable) = glx_LOAD_SUCCEEDED + numFailed;
			}
		}
		else
		{
			*(entry->extensionVariable) = glx_LOAD_SUCCEEDED;
		}
	}
}


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)
	{
		/*Get the extension at our position.*/
		int iStrLen = 0;
		const char *strEndStr = strchr(strCurrPos, ' ');
		int iStop = 0;
		if(strEndStr == NULL)
		{
			strEndStr = strExtListEnd;
			iStop = 1;
		}

		iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos);

		if(iStrLen > 255)
			return;

		strncpy(strWorkBuff, strCurrPos, iStrLen);
		strWorkBuff[iStrLen] = '\0';

		LoadExtByName(strWorkBuff);

		strCurrPos = strEndStr + 1;
		if(iStop) break;
	}
}

int glx_LoadFunctions(Display *display, int screen)
{
	ClearExtensionVars();
	
	
	ProcExtsFromExtString((const char *)glXQueryExtensionsString(display, screen));
	return glx_LOAD_SUCCEEDED;
}