From a6d349c90acffc12ac27b4c9f279963f00731c1f Mon Sep 17 00:00:00 2001 From: plagman Date: Sun, 2 Oct 2011 00:32:00 +0000 Subject: [PATCH] Polymer: account for model flipping for backface culling. The winding order of faces is different if only flipping about X or Y, and we were unconditionally culling CW faces. git-svn-id: https://svn.eduke32.com/eduke32@2052 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/polymer.h | 2 +- polymer/eduke32/build/src/polymer.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/polymer/eduke32/build/include/polymer.h b/polymer/eduke32/build/include/polymer.h index 880e4149a..8145a1491 100644 --- a/polymer/eduke32/build/include/polymer.h +++ b/polymer/eduke32/build/include/polymer.h @@ -375,7 +375,7 @@ static void polymer_initrendertargets(int32_t count); #define INDICE(n) ((p->indices) ? (p->indices[(i+n)%p->indicescount]*5) : (((i+n)%p->vertcount)*5)) -#define SWITCH_CULL_DIRECTION culledface = (culledface == GL_FRONT) ? GL_BACK : GL_FRONT; bglCullFace(culledface) +#define SWITCH_CULL_DIRECTION { culledface = (culledface == GL_FRONT) ? GL_BACK : GL_FRONT; bglCullFace(culledface); } static inline GLfloat dot2f(GLfloat *v1, GLfloat *v2) { diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 366892a27..ef2512ac8 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -3943,6 +3943,12 @@ static void polymer_drawmdsprite(spritetype *tspr) if (tspr->cstat & 4) bglScalef(1.0f, -1.0f, 1.0f); + if (!(tspr->cstat & 4) != !(tspr->cstat & 8)) { + // Only inverting one coordinate will reverse the winding order of + // faces, so we need to account for that when culling. + SWITCH_CULL_DIRECTION; + } + bglScalef(scale * tspr->xrepeat, scale * tspr->xrepeat, scale * tspr->yrepeat); bglTranslatef(0.0f, 0.0, m->zadd * 64); @@ -4272,6 +4278,10 @@ static void polymer_drawmdsprite(spritetype *tspr) bglPopMatrix(); + if (!(tspr->cstat & 4) != !(tspr->cstat & 8)) { + SWITCH_CULL_DIRECTION; + } + globalnoeffect = 0; }