From a94063e0be12e9b1729781a56bb3a0afc123adfc Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 16 Jan 2007 03:19:04 +0000 Subject: [PATCH] Dynamically loaded GLU git-svn-id: https://svn.eduke32.com/eduke32@462 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/Makefile.shared | 7 -- polymer/build/include/glbuild.h | 16 ++++- polymer/build/src/glbuild.c | 116 +++++++++++++++++++++++++++++++- polymer/build/src/polymer.c | 30 ++++----- polymer/build/src/sdlayer.c | 4 ++ polymer/build/src/winlayer.c | 4 ++ polymer/eduke32/source/config.c | 2 +- polymer/eduke32/source/game.c | 5 +- 8 files changed, 155 insertions(+), 29 deletions(-) diff --git a/polymer/build/Makefile.shared b/polymer/build/Makefile.shared index d2551fd48..5841a8cc8 100644 --- a/polymer/build/Makefile.shared +++ b/polymer/build/Makefile.shared @@ -62,13 +62,6 @@ ifeq ($(PLATFORM),WINDOWS) RENDERTYPE ?= WIN EXESUFFIX=.exe LIBS+= -lmingwex -lwinmm -L$(DXROOT)/lib -lwsock32 -lcomctl32 #-lshfolder - ifneq (0,$(USE_OPENGL)) - LIBS+= -lglu32 - endif -else - ifneq (0,$(USE_OPENGL)) - LIBS+= -lGLU - endif endif ifeq ($(PLATFORM),BSD) RENDERTYPE=SDL diff --git a/polymer/build/include/glbuild.h b/polymer/build/include/glbuild.h index 6ede0c4a6..263c3d152 100644 --- a/polymer/build/include/glbuild.h +++ b/polymer/build/include/glbuild.h @@ -155,6 +155,19 @@ extern void (APIENTRY * bglBindFramebufferEXT)(GLenum target, GLuint framebuffer extern void (APIENTRY * bglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); extern GLenum (APIENTRY * bglCheckFramebufferStatusEXT)(GLenum target); extern void (APIENTRY * bglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); + +// GLU +extern void (APIENTRY * bgluTessBeginContour) (GLUtesselator* tess); +extern void (APIENTRY * bgluTessBeginPolygon) (GLUtesselator* tess, GLvoid* data); +extern void (APIENTRY * bgluTessCallback) (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc); +extern void (APIENTRY * bgluTessEndContour) (GLUtesselator* tess); +extern void (APIENTRY * bgluTessEndPolygon) (GLUtesselator* tess); +extern void (APIENTRY * bgluTessNormal) (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ); +extern void (APIENTRY * bgluTessProperty) (GLUtesselator* tess, GLenum which, GLdouble data); +extern void (APIENTRY * bgluTessVertex) (GLUtesselator* tess, GLdouble *location, GLvoid* data); +extern GLUtesselator* (APIENTRY * bgluNewTess) (void); +extern void (APIENTRY * bgluPerspective) (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +extern const GLubyte * (APIENTRY * bgluErrorString) (GLenum error); #ifdef RENDERTYPEWIN // Windows @@ -177,4 +190,5 @@ extern char *gldriver; int loadgldriver(const char *driver); int loadglextensions(void); int unloadgldriver(void); - + int loadglulibrary(const char *driver); +int unloadglulibrary(void); diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index 925134466..adfe8072b 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -133,6 +133,19 @@ void (APIENTRY * bglFramebufferTexture2DEXT)(GLenum target, GLenum attachment, G GLenum (APIENTRY * bglCheckFramebufferStatusEXT)(GLenum target); void (APIENTRY * bglDeleteFramebuffersEXT)(GLsizei n, const GLuint *framebuffers); +// GLU +void (APIENTRY * bgluTessBeginContour) (GLUtesselator* tess); +void (APIENTRY * bgluTessBeginPolygon) (GLUtesselator* tess, GLvoid* data); +void (APIENTRY * bgluTessCallback) (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc); +void (APIENTRY * bgluTessEndContour) (GLUtesselator* tess); +void (APIENTRY * bgluTessEndPolygon) (GLUtesselator* tess); +void (APIENTRY * bgluTessNormal) (GLUtesselator* tess, GLdouble valueX, GLdouble valueY, GLdouble valueZ); +void (APIENTRY * bgluTessProperty) (GLUtesselator* tess, GLenum which, GLdouble data); +void (APIENTRY * bgluTessVertex) (GLUtesselator* tess, GLdouble *location, GLvoid* data); +GLUtesselator* (APIENTRY * bgluNewTess) (void); +void (APIENTRY * bgluPerspective) (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +const GLubyte * (APIENTRY * bgluErrorString) (GLenum error); + #ifdef RENDERTYPEWIN // Windows HGLRC (WINAPI * bwglCreateContext)(HDC); @@ -146,11 +159,14 @@ int (WINAPI * bwglDescribePixelFormat)(HDC,int,UINT,LPPIXELFORMATDESCRIPTOR); int (WINAPI * bwglGetPixelFormat)(HDC); BOOL (WINAPI * bwglSetPixelFormat)(HDC,int,const PIXELFORMATDESCRIPTOR*); -static HANDLE hGLDLL; +static HANDLE hGLDLL, hGLUDLL; +#else +#include + +static void *gluhandle = NULL; #endif - -char *gldriver = NULL; +char *gldriver = NULL, *glulibrary = NULL; static void * getproc_(const char *s, int *err, int fatal, int extension) { @@ -496,5 +512,99 @@ int unloadgldriver(void) return 0; } +static void * glugetproc_(const char *s, int *err, int fatal) +{ + void *t; +#if defined _WIN32 + t = (void*)GetProcAddress(hGLUDLL,s); +#else + t = (void*)dlsym(gluhandle,s); +#endif + if (!t && fatal) { + initprintf("Failed to find %s in %s\n", s, glulibrary); + *err = 1; + } + return t; +} +#define GLUGETPROC(s) glugetproc_(s,&err,1) +#define GLUGETPROCSOFT(s) glugetproc_(s,&err,0) + +int loadglulibrary(const char *driver) +{ + void *t; + int err=0; + +#ifdef RENDERTYPEWIN + if (hGLUDLL) return 0; +#endif + + if (!driver) { +#ifdef _WIN32 + driver = "GLU32.DLL"; +#elif defined __APPLE__ + driver = "/System/Library/Frameworks/OpenGL.framework/OpenGL"; // FIXME: like I know anything about Apple. Hah. +#else + driver = "libGLU.so"; +#endif + } + + initprintf("Loading %s\n",driver); + +#if defined _WIN32 + hGLUDLL = LoadLibrary(driver); + if (!hGLUDLL) return -1; +#else + gluhandle = dlopen(driver, RTLD_NOW|RTLD_GLOBAL); + if (!gluhandle) return 0; +#endif + glulibrary = strdup(driver); + + bgluTessBeginContour = GLUGETPROC("gluTessBeginContour"); + bgluTessBeginPolygon = GLUGETPROC("gluTessBeginPolygon"); + bgluTessCallback = GLUGETPROC("gluTessCallback"); + bgluTessEndContour = GLUGETPROC("gluTessEndContour"); + bgluTessEndPolygon = GLUGETPROC("gluTessEndPolygon"); + bgluTessNormal = GLUGETPROC("gluTessNormal"); + bgluTessProperty = GLUGETPROC("gluTessProperty"); + bgluTessVertex = GLUGETPROC("gluTessVertex"); + bgluNewTess = GLUGETPROC("gluNewTess"); + bgluPerspective = GLUGETPROC("gluPerspective"); + bgluErrorString = GLUGETPROC("gluErrorString"); + + if (err) unloadglulibrary(); + return err; +} + +int unloadglulibrary(void) +{ +#ifdef RENDERTYPEWIN + if (!hGLUDLL) return 0; +#endif + + free(glulibrary); + glulibrary = NULL; + +#ifdef RENDERTYPEWIN + FreeLibrary(hGLUDLL); + hGLUDLL = NULL; +#else + if (gluhandle) dlclose(gluhandle); + gluhandle = NULL; +#endif + + bgluTessBeginContour = NULL; + bgluTessBeginPolygon = NULL; + bgluTessCallback = NULL; + bgluTessEndContour = NULL; + bgluTessEndPolygon = NULL; + bgluTessNormal = NULL; + bgluTessProperty = NULL; + bgluTessVertex = NULL; + bgluNewTess = NULL; + bgluPerspective = NULL; + bgluErrorString = NULL; + + return 0; +} #endif diff --git a/polymer/build/src/polymer.c b/polymer/build/src/polymer.c index edbc72805..2c752b6da 100644 --- a/polymer/build/src/polymer.c +++ b/polymer/build/src/polymer.c @@ -53,7 +53,7 @@ int polymer_init(void) cliplanes = NULL; cliplanecount = maxcliplanecount = 0; - prtess = gluNewTess(); + prtess = bgluNewTess(); if (prtess == 0) { if (pr_verbosity >= 1) OSD_Printf("PR : Tesselator initialization failed.\n"); @@ -92,7 +92,7 @@ void polymer_glinit(void) bglMatrixMode(GL_PROJECTION); bglLoadIdentity(); - gluPerspective((float)(pr_fov) / (2048.0f / 360.0f), (float)xdim / (float)ydim, 0.001f, 1000000.0f); + bgluPerspective((float)(pr_fov) / (2048.0f / 360.0f), (float)xdim / (float)ydim, 0.001f, 1000000.0f); bglMatrixMode(GL_MODELVIEW); bglLoadIdentity(); @@ -508,7 +508,7 @@ void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloa void PR_CALLBACK polymer_tesserror(GLenum error) { // This callback is called by the tesselator whenever it raises an error. - if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, gluErrorString(errno)); + if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, bgluErrorString(errno)); } @@ -556,29 +556,29 @@ int polymer_buildfloor(short sectnum) s->curindice = 0; - gluTessCallback(prtess, GLU_TESS_VERTEX_DATA, polymer_tessvertex); - gluTessCallback(prtess, GLU_TESS_EDGE_FLAG, polymer_tessedgeflag); - //gluTessCallback(prtess, GLU_TESS_COMBINE, polymer_tesscombine); - gluTessCallback(prtess, GLU_TESS_ERROR, polymer_tesserror); + bgluTessCallback(prtess, GLU_TESS_VERTEX_DATA, polymer_tessvertex); + bgluTessCallback(prtess, GLU_TESS_EDGE_FLAG, polymer_tessedgeflag); + //bgluTessCallback(prtess, GLU_TESS_COMBINE, polymer_tesscombine); + bgluTessCallback(prtess, GLU_TESS_ERROR, polymer_tesserror); - gluTessProperty(prtess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); + bgluTessProperty(prtess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE); - gluTessBeginPolygon(prtess, s); - gluTessBeginContour(prtess); + bgluTessBeginPolygon(prtess, s); + bgluTessBeginContour(prtess); i = 0; while (i < sec->wallnum) { - gluTessVertex(prtess, s->verts + (3 * i), (void *)i); + bgluTessVertex(prtess, s->verts + (3 * i), (void *)i); if ((i != (sec->wallnum - 1)) && ((sec->wallptr + i) > wall[sec->wallptr + i].point2)) { - gluTessEndContour(prtess); - gluTessBeginContour(prtess); + bgluTessEndContour(prtess); + bgluTessBeginContour(prtess); } i++; } - gluTessEndContour(prtess); - gluTessEndPolygon(prtess); + bgluTessEndContour(prtess); + bgluTessEndPolygon(prtess); i = 0; while (i < s->indicescount) diff --git a/polymer/build/src/sdlayer.c b/polymer/build/src/sdlayer.c index 23c07ea07..7a0d21b3e 100644 --- a/polymer/build/src/sdlayer.c +++ b/polymer/build/src/sdlayer.c @@ -220,6 +220,9 @@ int initsystem(void) initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); nogl = 1; } + else if (loadglulibrary(getenv("BUILD_GLULIB"))) { + initprintf("Failed loading GLU library.\n"); + } #endif #ifndef __APPLE__ @@ -271,6 +274,7 @@ void uninitsystem(void) #ifdef USE_OPENGL unloadgldriver(); + unloadglulibrary(); #endif } diff --git a/polymer/build/src/winlayer.c b/polymer/build/src/winlayer.c index 77b9f3cbd..96c73f2e1 100644 --- a/polymer/build/src/winlayer.c +++ b/polymer/build/src/winlayer.c @@ -430,6 +430,9 @@ int initsystem(void) initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n"); nogl = 1; } + else if (loadglulibrary(getenv("BUILD_GLULIB"))) { + initprintf("Failed loading GLU library.\n"); + } #endif // try and start DirectDraw @@ -457,6 +460,7 @@ void uninitsystem(void) #if defined(USE_OPENGL) && defined(POLYMOST) unloadgldriver(); + unloadglulibrary(); #endif } diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 6af39887c..d0e19eb24 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -793,7 +793,7 @@ void CONFIG_WriteSetup(void) SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLDepthPeeling",r_depthpeeling,false,false); SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLPeelsCount",r_peelscount,false,false); - SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLDetailMapping", &r_detailmapping,false,false); + SCRIPT_PutNumber(scripthandle, "Screen Setup", "GLDetailMapping", r_detailmapping,false,false); #endif #ifdef RENDERTYPEWIN SCRIPT_PutNumber(scripthandle, "Screen Setup", "MaxRefreshFreq",maxrefreshfreq,false,false); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index a8fa2de7a..6711d6396 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2825,7 +2825,7 @@ static void moveclouds(void) { if (totalclock > cloudtotalclock || totalclock < (cloudtotalclock-7)) { - short i; + int i; cloudtotalclock = totalclock+6; @@ -3554,7 +3554,8 @@ void drawbackground(void) if (ud.multimode > 1) y1 += scale(ydim,8,200); if (ud.multimode > 4) y1 += scale(ydim,8,200); } - } else + } + else { // when not rendering a game, fullscreen wipe #define MENUTILE bpp==8?MENUSCREEN:LOADSCREEN