From fbebdb71917b3854c3327f790bc3f7f286a7240b Mon Sep 17 00:00:00 2001 From: divverent Date: Sat, 4 Oct 2008 14:01:05 +0000 Subject: [PATCH] use skinframes for R_BeginPolygon; helps with csqc 3D polygon rendering (e.g. mipmapping becomes possible, and no longer conflicts in the GL_CLAMP state between different kinds to draw stuff) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8520 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 31 +++++++++++++++++++++++++++++-- draw.h | 4 +++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index d9fc74bf..d3da4299 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -2574,7 +2574,13 @@ void VM_CL_AddPolygonsToMeshQueue (void) void VM_CL_R_PolygonBegin (void) { const char *picname; + skinframe_t *sf; vmpolygons_t* polys = vmpolygons + PRVM_GetProgNr(); + int tf; + + // TODO instead of using skinframes here (which provides the benefit of + // better management of flags, and is more suited for 3D rendering), what + // about supporting Q3 shaders? VM_SAFEPARMCOUNT(2, VM_CL_R_PolygonBegin); @@ -2586,8 +2592,29 @@ void VM_CL_R_PolygonBegin (void) return; } picname = PRVM_G_STRING(OFS_PARM0); - polys->begin_texture = picname[0] ? Draw_CachePic_Flags (picname, CACHEPICFLAG_NOCLAMP)->tex : r_texture_white; - polys->begin_drawflag = (int)PRVM_G_FLOAT(OFS_PARM1); + + sf = NULL; + if(*picname) + { + tf = TEXF_ALPHA; + if((int)PRVM_G_FLOAT(OFS_PARM1) & DRAWFLAG_MIPMAP) + tf |= TEXF_MIPMAP; + + do + { + sf = R_SkinFrame_FindNextByName(sf, picname); + } + while(sf && sf->textureflags != tf); + + if(!sf || !sf->base) + sf = R_SkinFrame_LoadExternal(picname, tf, true); + + if(sf) + R_SkinFrame_MarkUsed(sf); + } + + polys->begin_texture = (sf && sf->base) ? sf->base : r_texture_white; + polys->begin_drawflag = (int)PRVM_G_FLOAT(OFS_PARM1) & DRAWFLAG_MASK; polys->begin_vertices = 0; polys->begin_active = true; } diff --git a/draw.h b/draw.h index 8646c6a3..c9c8b745 100644 --- a/draw.h +++ b/draw.h @@ -76,7 +76,9 @@ DRAWFLAG_NORMAL, DRAWFLAG_ADDITIVE, DRAWFLAG_MODULATE, DRAWFLAG_2XMODULATE, -DRAWFLAG_NUMFLAGS +DRAWFLAG_NUMFLAGS, +DRAWFLAG_MASK = 0xFF, // ONLY R_BeginPolygon() +DRAWFLAG_MIPMAP = 0x100 // ONLY R_BeginPolygon() }; typedef struct dp_font_s -- 2.39.2