mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
dynamically load OpenGL functions on OSX too
This commit is contained in:
parent
f08cc44485
commit
bbcc64a6e1
@ -995,18 +995,16 @@ static GfxResourceID gl_activeList;
|
|||||||
static void* gl_dynamicListData;
|
static void* gl_dynamicListData;
|
||||||
#else
|
#else
|
||||||
/* Weak linked on OSX, so we don't need to use GetProcAddress */
|
/* Weak linked on OSX, so we don't need to use GetProcAddress */
|
||||||
#ifndef CC_BUILD_OSX
|
|
||||||
typedef void (APIENTRY *FUNC_GLBINDBUFFER) (GLenum target, GLuint buffer);
|
typedef void (APIENTRY *FUNC_GLBINDBUFFER) (GLenum target, GLuint buffer);
|
||||||
typedef void (APIENTRY *FUNC_GLDELETEBUFFERS) (GLsizei n, const GLuint *buffers);
|
typedef void (APIENTRY *FUNC_GLDELETEBUFFERS) (GLsizei n, const GLuint *buffers);
|
||||||
typedef void (APIENTRY *FUNC_GLGENBUFFERS) (GLsizei n, GLuint *buffers);
|
typedef void (APIENTRY *FUNC_GLGENBUFFERS) (GLsizei n, GLuint *buffers);
|
||||||
typedef void (APIENTRY *FUNC_GLBUFFERDATA) (GLenum target, uintptr_t size, const GLvoid* data, GLenum usage);
|
typedef void (APIENTRY *FUNC_GLBUFFERDATA) (GLenum target, uintptr_t size, const GLvoid* data, GLenum usage);
|
||||||
typedef void (APIENTRY *FUNC_GLBUFFERSUBDATA) (GLenum target, uintptr_t offset, uintptr_t size, const GLvoid* data);
|
typedef void (APIENTRY *FUNC_GLBUFFERSUBDATA) (GLenum target, uintptr_t offset, uintptr_t size, const GLvoid* data);
|
||||||
static FUNC_GLBINDBUFFER glBindBuffer;
|
static FUNC_GLBINDBUFFER _glBindBuffer;
|
||||||
static FUNC_GLDELETEBUFFERS glDeleteBuffers;
|
static FUNC_GLDELETEBUFFERS _glDeleteBuffers;
|
||||||
static FUNC_GLGENBUFFERS glGenBuffers;
|
static FUNC_GLGENBUFFERS _glGenBuffers;
|
||||||
static FUNC_GLBUFFERDATA glBufferData;
|
static FUNC_GLBUFFERDATA _glBufferData;
|
||||||
static FUNC_GLBUFFERSUBDATA glBufferSubData;
|
static FUNC_GLBUFFERSUBDATA _glBufferSubData;
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int gl_compare[8] = { GL_ALWAYS, GL_NOTEQUAL, GL_NEVER, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER };
|
static int gl_compare[8] = { GL_ALWAYS, GL_NOTEQUAL, GL_NEVER, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER };
|
||||||
@ -1025,21 +1023,18 @@ static void GL_CheckVboSupport(void) {
|
|||||||
int minor = (int)(version.buffer[2] - '0');
|
int minor = (int)(version.buffer[2] - '0');
|
||||||
|
|
||||||
/* Supported in core since 1.5 */
|
/* Supported in core since 1.5 */
|
||||||
if ((major > 1) || (major == 1 && minor >= 5)) {
|
if (major > 1 || (major == 1 && minor >= 5)) {
|
||||||
/* TODO: Do we still need to think about ARB functions on OSX? */
|
_glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBuffer");
|
||||||
#ifndef CC_BUILD_OSX
|
_glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffers");
|
||||||
glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBuffer");
|
_glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffers");
|
||||||
glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffers");
|
_glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferData");
|
||||||
glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffers");
|
_glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubData");
|
||||||
glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferData");
|
|
||||||
glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubData");
|
|
||||||
} else if (String_CaselessContains(&extensions, &vboExt)) {
|
} else if (String_CaselessContains(&extensions, &vboExt)) {
|
||||||
glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBufferARB");
|
_glBindBuffer = (FUNC_GLBINDBUFFER)GLContext_GetAddress("glBindBufferARB");
|
||||||
glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffersARB");
|
_glDeleteBuffers = (FUNC_GLDELETEBUFFERS)GLContext_GetAddress("glDeleteBuffersARB");
|
||||||
glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffersARB");
|
_glGenBuffers = (FUNC_GLGENBUFFERS)GLContext_GetAddress("glGenBuffersARB");
|
||||||
glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferDataARB");
|
_glBufferData = (FUNC_GLBUFFERDATA)GLContext_GetAddress("glBufferDataARB");
|
||||||
glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubDataARB");
|
_glBufferSubData = (FUNC_GLBUFFERSUBDATA)GLContext_GetAddress("glBufferSubDataARB");
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
Logger_Abort("Only OpenGL 1.1 supported.\n\n" \
|
Logger_Abort("Only OpenGL 1.1 supported.\n\n" \
|
||||||
"Compile the game with CC_BUILD_GL11, or ask on the classicube forums for it");
|
"Compile the game with CC_BUILD_GL11, or ask on the classicube forums for it");
|
||||||
@ -1235,29 +1230,29 @@ void Gfx_SetDepthTestFunc(CompareFunc func) {
|
|||||||
#ifndef CC_BUILD_GL11
|
#ifndef CC_BUILD_GL11
|
||||||
static GLuint GL_GenAndBind(GLenum target) {
|
static GLuint GL_GenAndBind(GLenum target) {
|
||||||
GLuint id;
|
GLuint id;
|
||||||
glGenBuffers(1, &id);
|
_glGenBuffers(1, &id);
|
||||||
glBindBuffer(target, id);
|
_glBindBuffer(target, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
|
GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
|
||||||
GLuint id = GL_GenAndBind(GL_ARRAY_BUFFER);
|
GLuint id = GL_GenAndBind(GL_ARRAY_BUFFER);
|
||||||
uint32_t size = maxVertices * gfx_strideSizes[fmt];
|
uint32_t size = maxVertices * gfx_strideSizes[fmt];
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
|
_glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
||||||
GLuint id = GL_GenAndBind(GL_ARRAY_BUFFER);
|
GLuint id = GL_GenAndBind(GL_ARRAY_BUFFER);
|
||||||
uint32_t size = count * gfx_strideSizes[fmt];
|
uint32_t size = count * gfx_strideSizes[fmt];
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
_glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
||||||
GLuint id = GL_GenAndBind(GL_ELEMENT_ARRAY_BUFFER);
|
GLuint id = GL_GenAndBind(GL_ELEMENT_ARRAY_BUFFER);
|
||||||
uint32_t size = indicesCount * 2;
|
uint32_t size = indicesCount * 2;
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW);
|
_glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1266,13 +1261,13 @@ void Gfx_BindIb(GfxResourceID ib) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib); }
|
|||||||
|
|
||||||
void Gfx_DeleteVb(GfxResourceID* vb) {
|
void Gfx_DeleteVb(GfxResourceID* vb) {
|
||||||
if (!vb || *vb == GFX_NULL) return;
|
if (!vb || *vb == GFX_NULL) return;
|
||||||
glDeleteBuffers(1, vb);
|
_glDeleteBuffers(1, vb);
|
||||||
*vb = GFX_NULL;
|
*vb = GFX_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DeleteIb(GfxResourceID* ib) {
|
void Gfx_DeleteIb(GfxResourceID* ib) {
|
||||||
if (!ib || *ib == GFX_NULL) return;
|
if (!ib || *ib == GFX_NULL) return;
|
||||||
glDeleteBuffers(1, ib);
|
_glDeleteBuffers(1, ib);
|
||||||
*ib = GFX_NULL;
|
*ib = GFX_NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -1360,8 +1355,8 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
|||||||
#ifndef CC_BUILD_GL11
|
#ifndef CC_BUILD_GL11
|
||||||
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
|
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
|
||||||
uint32_t size = vCount * gfx_batchStride;
|
uint32_t size = vCount * gfx_batchStride;
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vb);
|
_glBindBuffer(GL_ARRAY_BUFFER, vb);
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, 0, size, vertices);
|
_glBufferSubData(GL_ARRAY_BUFFER, 0, size, vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_DrawVb_Lines(int verticesCount) {
|
void Gfx_DrawVb_Lines(int verticesCount) {
|
||||||
|
@ -1266,8 +1266,9 @@ static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, v
|
|||||||
#define FONT_CACHE_FILE "fontscache.txt"
|
#define FONT_CACHE_FILE "fontscache.txt"
|
||||||
static void Font_Init(void) {
|
static void Font_Init(void) {
|
||||||
#ifdef CC_BUILD_WIN
|
#ifdef CC_BUILD_WIN
|
||||||
const static String dirs[1] = {
|
const static String dirs[2] = {
|
||||||
String_FromConst("C:\\Windows\\Fonts")
|
String_FromConst("C:/Windows/Fonts"),
|
||||||
|
String_FromConst("C:/WINNT/Fonts")
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#if defined CC_BUILD_LINUX || defined CC_BUILD_BSD || defined CC_BUILD_SOLARIS
|
#if defined CC_BUILD_LINUX || defined CC_BUILD_BSD || defined CC_BUILD_SOLARIS
|
||||||
@ -2023,7 +2024,7 @@ void Platform_Init(void) {
|
|||||||
hasDebugger = IsDebuggerPresent();
|
hasDebugger = IsDebuggerPresent();
|
||||||
/* For when user runs from command prompt */
|
/* For when user runs from command prompt */
|
||||||
/* NOTE: Need to dynamically load, not supported on Windows 2000 */
|
/* NOTE: Need to dynamically load, not supported on Windows 2000 */
|
||||||
AttachConsoleFunc attach = Platform_GetSymbolFrom("Kernel32", "AttachConsole");
|
AttachConsoleFunc attach = Platform_GetSymbolFrom("KERNEL32.DLL", "AttachConsole");
|
||||||
if (attach) attach(ATTACH_PARENT_PROCESS);
|
if (attach) attach(ATTACH_PARENT_PROCESS);
|
||||||
|
|
||||||
conHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
conHandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
@ -2474,8 +2474,8 @@ void GLContext_Free(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* GLContext_GetAddress(const char* function) {
|
void* GLContext_GetAddress(const char* function) {
|
||||||
/* TODO: Apparently we don't need this for OSX */
|
void* address = Platform_GetSymbolFrom("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", function);
|
||||||
return NULL;
|
return GLContext_IsInvalidAddress(address) ? NULL : address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLContext_SwapBuffers(void) {
|
void GLContext_SwapBuffers(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user