From e726484ccc2023f5dd21b2444d224ee3fefbea01 Mon Sep 17 00:00:00 2001 From: Plagman Date: Sun, 21 Oct 2012 04:52:43 +0000 Subject: [PATCH] polymer: add support for negative lights And hook them up to cstat 128 (half-submerged, 'c' in mapster). git-svn-id: https://svn.eduke32.com/eduke32@3092 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/glbuild.h | 1 + polymer/eduke32/build/include/prlights.h | 1 + polymer/eduke32/build/src/engine.c | 3 +++ polymer/eduke32/build/src/glbuild.c | 4 ++++ polymer/eduke32/build/src/polymer.c | 18 +++++++++++++----- polymer/eduke32/source/actors.c | 11 +++++++++++ polymer/eduke32/source/astub.c | 10 ++++++++++ 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/build/include/glbuild.h b/polymer/eduke32/build/include/glbuild.h index 3b6662d0f..28c0263bb 100644 --- a/polymer/eduke32/build/include/glbuild.h +++ b/polymer/eduke32/build/include/glbuild.h @@ -56,6 +56,7 @@ extern void (APIENTRY * bglClear)( GLbitfield mask ); extern void (APIENTRY * bglColorMask)( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha ); extern void (APIENTRY * bglAlphaFunc)( GLenum func, GLclampf ref ); extern void (APIENTRY * bglBlendFunc)( GLenum sfactor, GLenum dfactor ); +extern void (APIENTRY * bglBlendEquation)( GLenum mode ); extern void (APIENTRY * bglCullFace)( GLenum mode ); extern void (APIENTRY * bglFrontFace)( GLenum mode ); extern void (APIENTRY * bglPolygonOffset)( GLfloat factor, GLfloat units ); diff --git a/polymer/eduke32/build/include/prlights.h b/polymer/eduke32/build/include/prlights.h index 94fb00900..f87a34857 100644 --- a/polymer/eduke32/build/include/prlights.h +++ b/polymer/eduke32/build/include/prlights.h @@ -20,6 +20,7 @@ typedef struct s_prlight { int16_t tilenum; struct { int32_t emitshadow : 1; + int32_t negative : 1; } publicflags; // internal members float proj[16]; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index c3a6b25e1..eb8515d52 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -9980,6 +9980,9 @@ int32_t loadmaphack(const char *filename) scriptfile_getnumber(script, &value); light.tilenum = value; + light.publicflags.emitshadow = 1; + light.publicflags.negative = 0; + if (rendmode == 4) { if (maphacklightcnt == PR_MAXLIGHTS) diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index f4736c832..42a2fa7a6 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -16,6 +16,7 @@ void (APIENTRY *bglClear)(GLbitfield mask); void (APIENTRY *bglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void (APIENTRY *bglAlphaFunc)(GLenum func, GLclampf ref); void (APIENTRY *bglBlendFunc)(GLenum sfactor, GLenum dfactor); +void (APIENTRY *bglBlendEquation)(GLenum mode); void (APIENTRY *bglCullFace)(GLenum mode); void (APIENTRY *bglFrontFace)(GLenum mode); void (APIENTRY *bglPolygonOffset)(GLfloat factor, GLfloat units); @@ -495,6 +496,8 @@ int32_t loadglextensions(void) if (!hGLDLL) return 0; #endif + bglBlendEquation = GETPROCEXTSOFT("glBlendEquation"); + bglTexImage3D = GETPROCEXTSOFT("glTexImage3D"); bglCompressedTexImage2DARB = GETPROCEXTSOFT("glCompressedTexImage2DARB"); bglGetCompressedTexImageARB = GETPROCEXTSOFT("glGetCompressedTexImageARB"); @@ -660,6 +663,7 @@ int32_t unloadgldriver(void) bglColorMask = NULL; bglAlphaFunc = NULL; bglBlendFunc = NULL; + bglBlendEquation = NULL; bglCullFace = NULL; bglFrontFace = NULL; bglPolygonOffset = NULL; diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 7bbbb778e..6fc034415 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -4654,11 +4654,13 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights, // PR_BIT_LIGHTING_PASS if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit) { - // Careful with that, it works only if we respect the wrapping order - // or make sure GL_BLEND is the only ENABLE we mess with here. - bglPushAttrib(GL_ENABLE_BIT); - bglEnable(GL_BLEND); + bglPushAttrib(GL_COLOR_BUFFER_BIT); + bglEnable(GL_BLEND); bglBlendFunc(GL_ONE, GL_ONE); + + if (prlights[lights[curlight]].publicflags.negative) { + bglBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + } } // PR_BIT_NORMAL_MAP @@ -4900,6 +4902,13 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights, color[1] = prlights[lights[curlight]].color[1] / 255.0f; color[2] = prlights[lights[curlight]].color[2] / 255.0f; + // If this isn't a lighting-only pass, just negate the components + if (!curlight && prlights[lights[curlight]].publicflags.negative) { + color[0] = -color[0]; + color[1] = -color[1]; + color[2] = -color[2]; + } + bglLightfv(GL_LIGHT0, GL_AMBIENT, pos); bglLightfv(GL_LIGHT0, GL_DIFFUSE, color); if (material.mdspritespace == GL_TRUE) { @@ -4933,7 +4942,6 @@ static void polymer_unbindmaterial(int32_t programbits) if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit) { bglPopAttrib(); - bglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } // PR_BIT_NORMAL_MAP diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 0e1239af0..dba1300bd 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -740,6 +740,9 @@ void G_AddGameLight(int32_t radius, int32_t srcsprite, int32_t zoffset, int32_t mylight.priority = priority; mylight.tilenum = 0; + mylight.publicflags.emitshadow = 1; + mylight.publicflags.negative = 0; + actor[srcsprite].lightId = polymer_addlight(&mylight); if (actor[srcsprite].lightId >= 0) actor[srcsprite].lightptr = &prlights[actor[srcsprite].lightId]; @@ -7752,6 +7755,7 @@ static void G_DoEffectorLights(void) // STATNUM 14 mylight.maxshade = sprite[i].yoffset; mylight.tilenum = 0; mylight.publicflags.emitshadow = 0; + mylight.publicflags.negative = !!(CS & 128); if (CS & 2) { @@ -7788,6 +7792,9 @@ static void G_DoEffectorLights(void) // STATNUM 14 actor[i].lightptr->color[1] = sprite[i].yvel; actor[i].lightptr->color[2] = sprite[i].zvel; } + if (!!(CS & 128) != actor[i].lightptr->publicflags.negative) { + actor[i].lightptr->publicflags.negative = !!(CS & 128); + } } break; } @@ -7816,6 +7823,7 @@ static void G_DoEffectorLights(void) // STATNUM 14 mylight.maxshade = sprite[i].yoffset; mylight.tilenum = actor[i].picnum; mylight.publicflags.emitshadow = !(CS & 64); + mylight.publicflags.negative = !!(CS & 128); if (CS & 2) { @@ -7877,6 +7885,9 @@ static void G_DoEffectorLights(void) // STATNUM 14 if (!(CS & 64) != actor[i].lightptr->publicflags.emitshadow) { actor[i].lightptr->publicflags.emitshadow = !(CS & 64); } + if (!!(CS & 128) != actor[i].lightptr->publicflags.negative) { + actor[i].lightptr->publicflags.negative = !!(CS & 128); + } actor[i].lightptr->tilenum = actor[i].picnum; } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index a0c399b97..2203f978c 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -286,6 +286,8 @@ static void addprlight_common1(_prlight *mylightptr, int32_t i) else mylightptr->priority = PR_LIGHT_PRIO_MAX; + mylightptr->publicflags.negative = !!(CS & 128); + spritelightid[i] = polymer_addlight(mylightptr); if (spritelightid[i] >= 0) spritelightptr[i] = &prlights[spritelightid[i]]; @@ -10697,6 +10699,10 @@ void ExtPreCheckKeys(void) // just before drawrooms } if (check_prlight_colors(i)) copy_prlight_colors(spritelightptr[i], i); + if (!!(CS & 128) != spritelightptr[i]->publicflags.negative) + { + spritelightptr[i]->publicflags.negative = !!(CS & 128); + } } } } @@ -10751,6 +10757,10 @@ void ExtPreCheckKeys(void) // just before drawrooms { spritelightptr[i]->publicflags.emitshadow = !(CS & 64); } + if (!!(CS & 128) != spritelightptr[i]->publicflags.negative) + { + spritelightptr[i]->publicflags.negative = !!(CS & 128); + } spritelightptr[i]->tilenum = OW; } }