3-stage multitexture

This commit is contained in:
David Rose 2008-12-27 02:21:22 +00:00
parent a9825fe78f
commit a32fe74070
11 changed files with 1143 additions and 466 deletions

View File

@ -55,6 +55,11 @@ void gl_transform_to_viewport(GLContext *c,GLVertex *v)
v->zp.sa = (int)(v->tex_coord[si].v[0] * c->current_textures[si]->s_max);
v->zp.ta = (int)(v->tex_coord[si].v[1] * c->current_textures[si]->t_max);
}
if (c->num_textures_enabled >= 3) {
static const int si = 2;
v->zp.sb = (int)(v->tex_coord[si].v[0] * c->current_textures[si]->s_max);
v->zp.tb = (int)(v->tex_coord[si].v[1] * c->current_textures[si]->t_max);
}
}

View File

@ -52,9 +52,8 @@ PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_textured_pcollecto
PStatCollector TinyGraphicsStateGuardian::_pixel_count_white_perspective_pcollector("Pixels:White perspective");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_flat_perspective_pcollector("Pixels:Flat perspective");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_perspective_pcollector("Pixels:Smooth perspective");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_white_multitex_pcollector("Pixels:White multitex");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_flat_multitex_pcollector("Pixels:Flat multitex");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_multitex_pcollector("Pixels:Smooth multitex");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_multitex2_pcollector("Pixels:Smooth multitex 2");
PStatCollector TinyGraphicsStateGuardian::_pixel_count_smooth_multitex3_pcollector("Pixels:Smooth multitex 3");
////////////////////////////////////////////////////////////////////
// Function: TinyGraphicsStateGuardian::Constructor
@ -398,9 +397,8 @@ begin_frame(Thread *current_thread) {
_pixel_count_white_perspective_pcollector.clear_level();
_pixel_count_flat_perspective_pcollector.clear_level();
_pixel_count_smooth_perspective_pcollector.clear_level();
_pixel_count_white_multitex_pcollector.clear_level();
_pixel_count_flat_multitex_pcollector.clear_level();
_pixel_count_smooth_multitex_pcollector.clear_level();
_pixel_count_smooth_multitex2_pcollector.clear_level();
_pixel_count_smooth_multitex3_pcollector.clear_level();
#endif
return true;
@ -521,9 +519,8 @@ end_frame(Thread *current_thread) {
_pixel_count_white_perspective_pcollector.flush_level();
_pixel_count_flat_perspective_pcollector.flush_level();
_pixel_count_smooth_perspective_pcollector.flush_level();
_pixel_count_white_multitex_pcollector.flush_level();
_pixel_count_flat_multitex_pcollector.flush_level();
_pixel_count_smooth_multitex_pcollector.flush_level();
_pixel_count_smooth_multitex2_pcollector.flush_level();
_pixel_count_smooth_multitex3_pcollector.flush_level();
#endif // DO_PSTATS
}
@ -635,7 +632,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
GeomVertexReader rcolor, rnormal;
// We now support up to 2-stage multitexturing.
// We now support up to 3-stage multitexturing.
GenTexcoordFunc *texgen_func[MAX_TEXTURE_STAGES];
TexCoordData tcdata[MAX_TEXTURE_STAGES];
@ -943,9 +940,8 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader,
pixel_count_white_perspective = 0;
pixel_count_flat_perspective = 0;
pixel_count_smooth_perspective = 0;
pixel_count_white_multitex = 0;
pixel_count_flat_multitex = 0;
pixel_count_smooth_multitex = 0;
pixel_count_smooth_multitex2 = 0;
pixel_count_smooth_multitex3 = 0;
#endif // DO_PSTATS
return true;
@ -1341,9 +1337,8 @@ end_draw_primitives() {
_pixel_count_white_perspective_pcollector.add_level(pixel_count_white_perspective);
_pixel_count_flat_perspective_pcollector.add_level(pixel_count_flat_perspective);
_pixel_count_smooth_perspective_pcollector.add_level(pixel_count_smooth_perspective);
_pixel_count_white_multitex_pcollector.add_level(pixel_count_white_multitex);
_pixel_count_flat_multitex_pcollector.add_level(pixel_count_flat_multitex);
_pixel_count_smooth_multitex_pcollector.add_level(pixel_count_smooth_multitex);
_pixel_count_smooth_multitex2_pcollector.add_level(pixel_count_smooth_multitex2);
_pixel_count_smooth_multitex3_pcollector.add_level(pixel_count_smooth_multitex3);
#endif // DO_PSTATS
GraphicsStateGuardian::end_draw_primitives();
@ -2206,8 +2201,10 @@ do_issue_texture() {
_texture_replace = all_replace;
_texturing_state = 2; // perspective (perspective-correct texturing)
if (num_stages >= 2) {
_texturing_state = 3; // multitexture
if (num_stages >= 3) {
_texturing_state = 4; // multitex3
} else if (num_stages == 2) {
_texturing_state = 3; // multitex2
} else if (!td_perspective_textures) {
_texturing_state = 1; // textured (not perspective correct)
}

View File

@ -189,9 +189,8 @@ private:
static PStatCollector _pixel_count_white_perspective_pcollector;
static PStatCollector _pixel_count_flat_perspective_pcollector;
static PStatCollector _pixel_count_smooth_perspective_pcollector;
static PStatCollector _pixel_count_white_multitex_pcollector;
static PStatCollector _pixel_count_flat_multitex_pcollector;
static PStatCollector _pixel_count_smooth_multitex_pcollector;
static PStatCollector _pixel_count_smooth_multitex2_pcollector;
static PStatCollector _pixel_count_smooth_multitex3_pcollector;
public:
static TypeHandle get_class_type() {

View File

@ -20,9 +20,8 @@ int pixel_count_smooth_textured;
int pixel_count_white_perspective;
int pixel_count_flat_perspective;
int pixel_count_smooth_perspective;
int pixel_count_white_multitex;
int pixel_count_flat_multitex;
int pixel_count_smooth_multitex;
int pixel_count_smooth_multitex2;
int pixel_count_smooth_multitex3;
#endif // DO_PSTATS
ZBuffer *ZB_open(int xsize, int ysize, int mode,

View File

@ -83,6 +83,8 @@ typedef unsigned int PIXEL;
((((unsigned int)(c1) * (unsigned int)(c2))) >> 16)
#define PCOMPONENT_MULT3(c1, c2, c3) \
PCOMPONENT_MULT(c1, PCOMPONENT_MULT(c2, c3))
#define PCOMPONENT_MULT4(c1, c2, c3, c4) \
PCOMPONENT_MULT(PCOMPONENT_MULT(c1, c2), PCOMPONENT_MULT(c3, c4))
// Returns a signed product of c1 * c2, where c1 is initially signed.
// We leave 2 bits on the top to differentiate between c1 < 0 and c1 >
@ -145,6 +147,9 @@ struct ZBufferPoint {
int sa, ta; /* mapping coordinates for optional second texture stage */
float sza,tza;
int sb, tb; /* mapping coordinates for optional third texture stage */
float szb,tzb;
};
/* zbuffer.c */
@ -159,9 +164,8 @@ extern int pixel_count_smooth_textured;
extern int pixel_count_white_perspective;
extern int pixel_count_flat_perspective;
extern int pixel_count_smooth_perspective;
extern int pixel_count_white_multitex;
extern int pixel_count_flat_multitex;
extern int pixel_count_smooth_multitex;
extern int pixel_count_smooth_multitex2;
extern int pixel_count_smooth_multitex3;
#define COUNT_PIXELS(pixel_count, p0, p1, p2) \
(pixel_count) += abs((p0)->x * ((p1)->y - (p2)->y) + (p1)->x * ((p2)->y - (p0)->y) + (p2)->x * ((p0)->y - (p1)->y)) / 2

View File

@ -37,6 +37,6 @@
#define TGL_FEATURE_32_BITS 1
/* Number of simultaneous texture stages supported (multitexture). */
#define MAX_TEXTURE_STAGES 2
#define MAX_TEXTURE_STAGES 3
#endif /* _tgl_features_h_ */

View File

@ -37,12 +37,19 @@
float sza1,dszadx,dszady,dszadl_min,dszadl_max;
float tza1,dtzadx,dtzady,dtzadl_min,dtzadl_max;
#endif
#ifdef INTERP_STZB
float szb1,dszbdx,dszbdy,dszbdl_min,dszbdl_max;
float tzb1,dtzbdx,dtzbdy,dtzbdl_min,dtzbdl_max;
#endif
#if defined(INTERP_MIPMAP) && (defined(INTERP_ST) || defined(INTERP_STZ))
unsigned int mipmap_dx, mipmap_level;
#endif
#ifdef INTERP_STZA
unsigned int mipmap_dxa, mipmap_levela;
#endif
#ifdef INTERP_STZB
unsigned int mipmap_dxb, mipmap_levelb;
#endif
EARLY_OUT();
@ -177,6 +184,31 @@
}
#endif
#ifdef INTERP_STZB
{
float zz;
zz=(float) p0->z;
p0->szb= (float) p0->sb * zz;
p0->tzb= (float) p0->tb * zz;
zz=(float) p1->z;
p1->szb= (float) p1->sb * zz;
p1->tzb= (float) p1->tb * zz;
zz=(float) p2->z;
p2->szb= (float) p2->sb * zz;
p2->tzb= (float) p2->tb * zz;
d1 = p1->szb - p0->szb;
d2 = p2->szb - p0->szb;
dszbdx = (fdy2 * d1 - fdy1 * d2);
dszbdy = (fdx1 * d2 - fdx2 * d1);
d1 = p1->tzb - p0->tzb;
d2 = p2->tzb - p0->tzb;
dtzbdx = (fdy2 * d1 - fdy1 * d2);
dtzbdy = (fdx1 * d2 - fdx2 * d1);
}
#endif
/* screen coordinates */
pp1 = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p0->y);
@ -281,6 +313,15 @@
tza1=l1->tza;
dtzadl_min=(dtzady + dtzadx * dxdy_min);
dtzadl_max=dtzadl_min + dtzadx;
#endif
#ifdef INTERP_STZB
szb1=l1->szb;
dszbdl_min=(dszbdy + dszbdx * dxdy_min);
dszbdl_max=dszbdl_min + dszbdx;
tzb1=l1->tzb;
dtzbdl_min=(dtzbdy + dtzbdx * dxdy_min);
dtzbdl_max=dtzbdl_min + dtzbdx;
#endif
}
@ -321,6 +362,9 @@
#ifdef INTERP_STZA
float sza,tza;
#endif
#ifdef INTERP_STZB
float szb,tzb;
#endif
n=(x2 >> 16) - x1;
pp=(PIXEL *)((char *)pp1 + x1 * PSZB);
@ -345,6 +389,10 @@
#ifdef INTERP_STZA
sza=sza1;
tza=tza1;
#endif
#ifdef INTERP_STZB
szb=szb1;
tzb=tzb1;
#endif
while (n>=3) {
PUT_PIXEL(0);
@ -395,6 +443,10 @@
#ifdef INTERP_STZA
sza1+=dszadl_max;
tza1+=dtzadl_max;
#endif
#ifdef INTERP_STZB
szb1+=dszbdl_max;
tzb1+=dtzbdl_max;
#endif
} else {
x1+=dxdy_min;
@ -418,6 +470,10 @@
#ifdef INTERP_STZA
sza1+=dszadl_min;
tza1+=dtzadl_min;
#endif
#ifdef INTERP_STZB
szb1+=dszbdl_min;
tzb1+=dtzbdl_min;
#endif
}
@ -436,6 +492,7 @@
#undef INTERP_ST
#undef INTERP_STZ
#undef INTERP_STZA
#undef INTERP_STZB
#undef EARLY_OUT
#undef EARLY_OUT_FZ

View File

@ -34,7 +34,7 @@ ExtraOptions = [
[ 'white', 'flat', 'smooth' ],
# texturing
[ 'untextured', 'textured', 'perspective', 'multitex' ],
[ 'untextured', 'textured', 'perspective', 'multitex2', 'multitex3' ],
]
FullOptions = Options + ExtraOptions
@ -91,7 +91,7 @@ def getFname(ops):
keyword = FullOptions[i][ops[i]]
keywordList.append(keyword)
if keywordList[-1] == 'multitex':
if keywordList[-1].startswith('multitex'):
# We don't bother with white_multitex or flat_multitex.
keywordList[-2] = 'smooth'

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
/* This file is generated code--do not edit. See ztriangle.py. */
extern const ZB_fillTriangleFunc fill_tri_funcs[2][4][3][2][3][3][4];
extern const ZB_fillTriangleFunc fill_tri_funcs[2][4][3][2][3][3][5];

View File

@ -655,7 +655,7 @@ static void FNAME(smooth_perspective) (ZBuffer *zb,
* stages of multitexture.
*/
static void FNAME(smooth_multitex) (ZBuffer *zb,
static void FNAME(smooth_multitex2) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
float fdzdx,fndzdx,ndszdx,ndtzdx,ndszadx,ndtzadx;
@ -799,7 +799,191 @@ static void FNAME(smooth_multitex) (ZBuffer *zb,
} \
}
#define PIXEL_COUNT pixel_count_smooth_multitex
#define PIXEL_COUNT pixel_count_smooth_multitex2
#include "ztriangle.h"
}
/*
* Smooth filled triangle, with perspective-correct mapping, on three
* stages of multitexture.
*/
static void FNAME(smooth_multitex3) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
float fdzdx,fndzdx,ndszdx,ndtzdx,ndszadx,ndtzadx,ndszbdx,ndtzbdx;
#define INTERP_Z
#define INTERP_STZ
#define INTERP_STZA
#define INTERP_STZB
#define INTERP_RGB
#define EARLY_OUT() \
{ \
}
#define DRAW_INIT() \
{ \
fdzdx=(float)dzdx; \
fndzdx=NB_INTERP * fdzdx; \
ndszdx=NB_INTERP * dszdx; \
ndtzdx=NB_INTERP * dtzdx; \
ndszadx=NB_INTERP * dszadx; \
ndtzadx=NB_INTERP * dtzadx; \
ndszbdx=NB_INTERP * dszbdx; \
ndtzbdx=NB_INTERP * dtzbdx; \
}
#define PUT_PIXEL(_a) \
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(zb->current_textures[0], s, t, mipmap_level, mipmap_dx); \
int a = PALPHA_MULT(oa1, PIXEL_A(tmp)); \
if (ACMP(zb, a)) { \
int tmpa = ZB_LOOKUP_TEXTURE(zb->current_textures[1], sa, ta, mipmap_levela, mipmap_dxa); \
int tmpb = ZB_LOOKUP_TEXTURE(zb->current_textures[2], sb, tb, mipmap_levelb, mipmap_dxb); \
STORE_PIX(pp[_a], \
RGBA_TO_PIXEL(PCOMPONENT_MULT4(or1, PIXEL_R(tmp), PIXEL_R(tmpa), PIXEL_R(tmpb)), \
PCOMPONENT_MULT4(og1, PIXEL_G(tmp), PIXEL_G(tmpa), PIXEL_G(tmpb)), \
PCOMPONENT_MULT4(ob1, PIXEL_B(tmp), PIXEL_B(tmpa), PIXEL_B(tmpb)), \
a), \
PCOMPONENT_MULT4(or1, PIXEL_R(tmp), PIXEL_R(tmpa), PIXEL_R(tmpb)), \
PCOMPONENT_MULT4(og1, PIXEL_G(tmp), PIXEL_G(tmpa), PIXEL_G(tmpb)), \
PCOMPONENT_MULT4(ob1, PIXEL_B(tmp), PIXEL_B(tmpa), PIXEL_B(tmpb)), \
a); \
STORE_Z(pz[_a], zz); \
} \
} \
z+=dzdx; \
og1+=dgdx; \
or1+=drdx; \
ob1+=dbdx; \
oa1+=dadx; \
s+=dsdx; \
t+=dtdx; \
sa+=dsadx; \
ta+=dtadx; \
sb+=dsbdx; \
tb+=dtbdx; \
}
#define DRAW_LINE() \
{ \
register ZPOINT *pz; \
register PIXEL *pp; \
register int s,t,sa,ta,sb,tb,z,zz; \
register int n,dsdx,dtdx,dsadx,dtadx,dsbdx,dtbdx; \
register int or1,og1,ob1,oa1; \
float sz,tz,sza,tza,szb,tzb,fz,zinv; \
n=(x2>>16)-x1; \
fz=(float)z1; \
zinv=1.0f / fz; \
pp=(PIXEL *)((char *)pp1 + x1 * PSZB); \
pz=pz1+x1; \
z=z1; \
sz=sz1; \
tz=tz1; \
sza=sza1; \
tza=tza1; \
szb=szb1; \
tzb=tzb1; \
or1 = r1; \
og1 = g1; \
ob1 = b1; \
oa1 = a1; \
while (n>=(NB_INTERP-1)) { \
{ \
float ss,tt; \
ss=(sz * zinv); \
tt=(tz * zinv); \
s=(int) ss; \
t=(int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \
} \
{ \
float ssa,tta; \
ssa=(sza * zinv); \
tta=(tza * zinv); \
sa=(int) ssa; \
ta=(int) tta; \
dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \
dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \
} \
{ \
float ssb,ttb; \
ssb=(szb * zinv); \
ttb=(tzb * zinv); \
sb=(int) ssb; \
tb=(int) ttb; \
dsbdx= (int)( (dszbdx - ssb*fdzdx)*zinv ); \
dtbdx= (int)( (dtzbdx - ttb*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_levelb, mipmap_dxb, dsbdx, dtbdx); \
} \
fz+=fndzdx; \
zinv=1.0f / fz; \
PUT_PIXEL(0); \
PUT_PIXEL(1); \
PUT_PIXEL(2); \
PUT_PIXEL(3); \
PUT_PIXEL(4); \
PUT_PIXEL(5); \
PUT_PIXEL(6); \
PUT_PIXEL(7); \
pz+=NB_INTERP; \
pp=(PIXEL *)((char *)pp + NB_INTERP * PSZB); \
n-=NB_INTERP; \
sz+=ndszdx; \
tz+=ndtzdx; \
sza+=ndszadx; \
tza+=ndtzadx; \
szb+=ndszbdx; \
tzb+=ndtzbdx; \
} \
{ \
float ss,tt; \
ss=(sz * zinv); \
tt=(tz * zinv); \
s=(int) ss; \
t=(int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_level, mipmap_dx, dsdx, dtdx); \
} \
{ \
float ssa,tta; \
ssa=(sza * zinv); \
tta=(tza * zinv); \
sa=(int) ssa; \
ta=(int) tta; \
dsadx= (int)( (dszadx - ssa*fdzdx)*zinv ); \
dtadx= (int)( (dtzadx - tta*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_levela, mipmap_dxa, dsadx, dtadx); \
} \
{ \
float ssb,ttb; \
ssb=(szb * zinv); \
ttb=(tzb * zinv); \
sb=(int) ssb; \
tb=(int) ttb; \
dsbdx= (int)( (dszbdx - ssb*fdzdx)*zinv ); \
dtbdx= (int)( (dtzbdx - ttb*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL(mipmap_levelb, mipmap_dxb, dsbdx, dtbdx); \
} \
while (n>=0) { \
PUT_PIXEL(0); \
pz+=1; \
pp=(PIXEL *)((char *)pp + PSZB); \
n-=1; \
} \
}
#define PIXEL_COUNT pixel_count_smooth_multitex3
#include "ztriangle.h"
}