From 883b29ef5529e110502edabce469717ca5b1ef1d Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 11 Feb 2010 04:44:36 +0000 Subject: [PATCH] added texturename parameter in particles/particlefont.txt fixed bug where alphatest was sometimes used on particles as a result of previous transparent materials rendered before it changed MAX_PARTICLETEXTURES to 256 because a byte index is used git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9952 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_particles.c | 69 +++++++++++++++++++++++++++++--------------------- gl_rmain.c | 29 ++++++++------------- quakedef.h | 4 +-- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/cl_particles.c b/cl_particles.c index e908de77..0975d1fb 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -1924,10 +1924,11 @@ static void R_InitParticleTexture (void) { int x, y, d, i, k, m; int basex, basey, w, h; - float dx, dy, f; + float dx, dy, f, s1, t1, s2, t2; vec3_t light; char *buf; fs_offset_t filesize; + char texturename[MAX_QPATH]; // a note: decals need to modulate (multiply) the background color to // properly darken it (stain), and they need to be able to alpha fade, @@ -2145,44 +2146,53 @@ static void R_InitParticleTexture (void) break; if(!strcmp(com_token, "\n")) continue; // empty line - i = atoi(com_token) % MAX_PARTICLETEXTURES; - particletexture[i].texture = particlefonttexture; + i = atoi(com_token); - if (!COM_ParseToken_Simple(&bufptr, true, false)) - break; - if (!strcmp(com_token, "\n")) - { - Con_Printf("particlefont file: syntax should be texnum texturename or texnum x y w h\n"); - continue; - } - particletexture[i].s1 = atof(com_token); + texturename[0] = 0; + s1 = 0; + t1 = 0; + s2 = 1; + t2 = 1; - if (!COM_ParseToken_Simple(&bufptr, true, false)) - break; - if (!strcmp(com_token, "\n")) + if (COM_ParseToken_Simple(&bufptr, true, false) && strcmp(com_token, "\n")) { - Con_Printf("particlefont file: syntax should be texnum texturename or texnum x y w h\n"); - continue; + s1 = atof(com_token); + if (COM_ParseToken_Simple(&bufptr, true, false) && strcmp(com_token, "\n")) + { + t1 = atof(com_token); + if (COM_ParseToken_Simple(&bufptr, true, false) && strcmp(com_token, "\n")) + { + s2 = atof(com_token); + if (COM_ParseToken_Simple(&bufptr, true, false) && strcmp(com_token, "\n")) + { + t2 = atof(com_token); + strlcpy(texturename, "particles/particlefont.tga", sizeof(texturename)); + if (COM_ParseToken_Simple(&bufptr, true, false) && strcmp(com_token, "\n")) + strlcpy(texturename, com_token, sizeof(texturename)); + } + } + } + else + { + s1 = 0; + strlcpy(texturename, com_token, sizeof(texturename)); + } } - particletexture[i].t1 = atof(com_token); - - if (!COM_ParseToken_Simple(&bufptr, true, false)) - break; - if (!strcmp(com_token, "\n")) + if (!texturename[0]) { - Con_Printf("particlefont file: syntax should be texnum texturename or texnum x y w h\n"); + Con_Printf("particles/particlefont.txt: syntax should be texnum x1 y1 x2 y2 texturename or texnum x1 y1 x2 y2 or texnum texturename\n"); continue; } - particletexture[i].s2 = atof(com_token); - - if (!COM_ParseToken_Simple(&bufptr, true, false)) - break; - if (!strcmp(com_token, "\n")) + if (i < 0 || i >= MAX_PARTICLETEXTURES) { - Con_Printf("particlefont file: syntax should be texnum texturename or texnum x y w h\n"); + Con_Printf("particles/particlefont.txt: texnum %i outside valid range (0 to %i)\n", i, MAX_PARTICLETEXTURES); continue; } - particletexture[i].t2 = atof(com_token); + particletexture[i].texture = R_SkinFrame_LoadExternal(texturename, TEXF_ALPHA | TEXF_FORCELINEAR, false)->base; + particletexture[i].s1 = s1; + particletexture[i].t1 = t1; + particletexture[i].s2 = s2; + particletexture[i].t2 = t2; } Mem_Free(buf); } @@ -2415,6 +2425,7 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh GL_DepthRange(0, 1); GL_PolygonOffset(0, 0); GL_DepthTest(true); + GL_AlphaTest(false); GL_CullFace(GL_NONE); // first generate all the vertices at once diff --git a/gl_rmain.c b/gl_rmain.c index 2ccf7b19..604df149 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -12028,6 +12028,16 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent) VectorCopy(decal->vertex3f[2], v3f + 6); } + if (r_refdef.fogenabled) + { + alpha = RSurf_FogVertex(v3f); + VectorScale(c4f, alpha, c4f); + alpha = RSurf_FogVertex(v3f + 3); + VectorScale(c4f + 4, alpha, c4f + 4); + alpha = RSurf_FogVertex(v3f + 6); + VectorScale(c4f + 8, alpha, c4f + 8); + } + v3f += 9; c4f += 12; t2f += 6; @@ -12038,25 +12048,6 @@ static void R_DrawModelDecals_Entity(entity_render_t *ent) { r_refdef.stats.drawndecals += numtris; - if (r_refdef.fogenabled) - { - switch(vid.renderpath) - { - case RENDERPATH_GL20: - case RENDERPATH_CGGL: - case RENDERPATH_GL13: - case RENDERPATH_GL11: - for (i = 0, v3f = decalsystem->vertex3f, c4f = decalsystem->color4f;i < numtris*3;i++, v3f += 3, c4f += 4) - { - alpha = RSurf_FogVertex(v3f); - c4f[0] *= alpha; - c4f[1] *= alpha; - c4f[2] *= alpha; - } - break; - } - } - // now render the decals all at once // (this assumes they all use one particle font texture!) RSurf_ActiveCustomEntity(&rsurface.matrix, &rsurface.inversematrix, rsurface.ent_flags, rsurface.ent_shadertime, 1, 1, 1, 1, numdecals*3, decalsystem->vertex3f, decalsystem->texcoord2f, NULL, NULL, NULL, decalsystem->color4f, numtris, decalsystem->element3i, decalsystem->element3s, false, false); diff --git a/quakedef.h b/quakedef.h index 9c62b5d9..98a997ff 100644 --- a/quakedef.h +++ b/quakedef.h @@ -95,7 +95,7 @@ extern char engineversion[128]; #define CACHEPICHASHSIZE 256 #define MAX_PARTICLEEFFECTNAME 256 #define MAX_PARTICLEEFFECTINFO 1024 -#define MAX_PARTICLETEXTURES 96 +#define MAX_PARTICLETEXTURES 256 #define MAXCLVIDEOS 1 #define MAX_GECKO_INSTANCES 1 #define MAX_DYNAMIC_TEXTURE_COUNT 2 @@ -158,7 +158,7 @@ extern char engineversion[128]; #define CACHEPICHASHSIZE 256 ///< number of hash buckets for accelerating 2D pic name lookups #define MAX_PARTICLEEFFECTNAME 256 ///< maximum number of unique names of particle effects (for particleeffectnum) #define MAX_PARTICLEEFFECTINFO 4096 ///< maximum number of unique particle effects (each name may associate with several of these) -#define MAX_PARTICLETEXTURES 1024 ///< maximum number of unique particle textures in the particle font +#define MAX_PARTICLETEXTURES 256 ///< maximum number of unique particle textures in the particle font #define MAXCLVIDEOS 65 ///< maximum number of video streams being played back at once (1 is reserved for the playvideo command) #define MAX_GECKO_INSTANCES 16 ///< maximum number of web browser textures active at once #define MAX_DYNAMIC_TEXTURE_COUNT 64 ///< maximum number of dynamic textures (web browsers, playvideo, etc) -- 2.39.2