This commit is contained in:
David Rose
2008-05-10 01:45:09 +00:00
parent c2aa7b17e4
commit ccf5056fd6
13 changed files with 2592 additions and 1073 deletions

View File

@@ -30,7 +30,8 @@
specbuf.cxx \
texture.cxx vertex.cxx \
zbuffer.cxx zbuffer.h zdither.cxx zfeatures.h zgl.h zline.cxx \
zline.h zmath.cxx zmath.h ztriangle.cxx ztriangle.h ztriangle_two.h
zline.h zmath.cxx zmath.h ztriangle.cxx ztriangle.h ztriangle_two.h \
ztriangle_code.h ztriangle_table.h
#end lib_target

File diff suppressed because it is too large Load Diff

View File

@@ -106,15 +106,15 @@ private:
void apply_texture(TextureContext *tc);
bool upload_texture(TinyTextureContext *gtc);
void setup_gltex(GLTexture *gltex, int orig_x_size, int orig_y_size);
void choose_tex_size(int &size, int &bits, int orig_size);
bool setup_gltex(GLTexture *gltex, int x_size, int y_size, int num_levels);
int get_tex_shift(int orig_size);
static void copy_lum_image(GLTexture *gltex, Texture *tex);
static void copy_alpha_image(GLTexture *gltex, Texture *tex);
static void copy_one_channel_image(GLTexture *gltex, Texture *tex, int channel);
static void copy_la_image(GLTexture *gltex, Texture *tex);
static void copy_rgb_image(GLTexture *gltex, Texture *tex);
static void copy_rgba_image(GLTexture *gltex, Texture *tex);
static void copy_lum_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_alpha_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_one_channel_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level, int channel);
static void copy_la_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_rgb_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
static void copy_rgba_image(ZTextureLevel *dest, int xsize, int ysize, Texture *tex, int level);
void setup_material(GLMaterial *gl_material, const Material *material);
static void load_matrix(M4 *matrix, const TransformState *transform);
@@ -135,6 +135,7 @@ private:
CMF_diffuse = 0x002,
};
int _color_material_flags;
int _texfilter_state;
SimpleLru _textures_lru;

View File

@@ -40,10 +40,14 @@ void TinyTextureContext::
evict_lru() {
dequeue_lru();
if (_gltex->pixmap != NULL) {
gl_free(_gltex->pixmap);
_gltex->pixmap = NULL;
for (int i = 0; i < _gltex->num_levels; ++i) {
gl_free(_gltex->levels[i].pixmap);
}
if (_gltex->levels != NULL) {
gl_free(_gltex->levels);
_gltex->levels = NULL;
}
_gltex->num_levels = 0;
set_resident(false);
}

View File

@@ -67,7 +67,7 @@ ZBuffer *ZB_open(int xsize, int ysize, int mode,
zb->pbuf = (PIXEL *)frame_buffer;
}
zb->current_texture.pixmap = NULL;
zb->current_texture = NULL;
return zb;
error:
@@ -343,18 +343,18 @@ void ZB_clear_viewport(ZBuffer * zb, int clear_z, ZPOINT z,
#define ZB_ST_FRAC_HIGH (1 << ZB_POINT_ST_FRAC_BITS)
#define ZB_ST_FRAC_MASK (ZB_ST_FRAC_HIGH - 1)
PIXEL lookup_texture_bilinear(ZTexture *texture, unsigned int s, unsigned int t)
PIXEL lookup_texture_bilinear(ZTextureLevel *base_level, int s, int t)
{
PIXEL p1, p2, p3, p4;
unsigned int sf, tf;
unsigned int r, g, b, a;
int sf, tf;
int r, g, b, a;
p1 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s, t);
p2 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s + ZB_ST_FRAC_HIGH, t);
p1 = ZB_LOOKUP_TEXTURE_NEAREST(base_level, s, t);
p2 = ZB_LOOKUP_TEXTURE_NEAREST(base_level, s + ZB_ST_FRAC_HIGH, t);
sf = s & ZB_ST_FRAC_MASK;
p3 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s, t + ZB_ST_FRAC_HIGH);
p4 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s + ZB_ST_FRAC_HIGH, t + ZB_ST_FRAC_HIGH);
p3 = ZB_LOOKUP_TEXTURE_NEAREST(base_level, s, t + ZB_ST_FRAC_HIGH);
p4 = ZB_LOOKUP_TEXTURE_NEAREST(base_level, s + ZB_ST_FRAC_HIGH, t + ZB_ST_FRAC_HIGH);
tf = t & ZB_ST_FRAC_MASK;
r = (((PIXEL_R(p4) * sf + PIXEL_R(p3) * (ZB_ST_FRAC_HIGH - sf)) >> ZB_POINT_ST_FRAC_BITS) * tf +
@@ -371,4 +371,3 @@ PIXEL lookup_texture_bilinear(ZTexture *texture, unsigned int s, unsigned int t)
return RGBA_TO_PIXEL(r, g, b, a);
}

View File

@@ -6,6 +6,7 @@
*/
#include "zfeatures.h"
#include "bitMask.h"
typedef unsigned short ZPOINT;
#define ZB_Z_BITS 16
@@ -19,25 +20,30 @@ typedef unsigned short ZPOINT;
cannot exceed this number of bits).*/
#define ZB_POINT_ST_FRAC_BITS 12
/* Returns the index within a texture for the given (s, t) texel. */
#define ZB_TEXEL(texture, s, t) \
((((t) & (texture)->t_mask) >> (texture)->t_shift) | \
(((s) & (texture)->s_mask) >> ZB_POINT_ST_FRAC_BITS))
/* This is the theoretical max number of bits we have available to
shift down to achieve each next mipmap level, based on the size of
a 32-bit int. We need to preallocate mipmap arrays of this size. */
#define MAX_MIPMAP_LEVELS (32 - ZB_POINT_ST_FRAC_BITS)
#define ZB_LOOKUP_TEXTURE_NEAREST(texture, s, t) \
(texture)->pixmap[ZB_TEXEL(texture, s, t)]
/* Returns the index within a texture level for the given (s, t) texel. */
#define ZB_TEXEL(level, s, t) \
((((t) & (level)->t_mask) >> (level)->t_shift) | \
(((s) & (level)->s_mask) >> ZB_POINT_ST_FRAC_BITS))
#if 1
/* Use no texture filtering by default. It's faster, even though it
looks terrible. */
#define ZB_LOOKUP_TEXTURE(texture, s, t) \
ZB_LOOKUP_TEXTURE_NEAREST(texture, s, t)
#define ZB_LOOKUP_TEXTURE_NEAREST(texture_levels, s, t) \
(texture_levels)->pixmap[ZB_TEXEL(texture_levels, s, t)]
#else
#define ZB_LOOKUP_TEXTURE_NEAREST_MIPMAP(texture_levels, s, t, level) \
ZB_LOOKUP_TEXTURE_NEAREST((texture_levels) + (level), (s) >> (level), (t) >> (level))
#define DO_CALC_MIPMAP_LEVEL \
mipmap_level = count_bits_in_word(flood_bits_down((unsigned int)max(abs(dsdx), abs(dtdx)) >> ZB_POINT_ST_FRAC_BITS))
#if 0
/* Experiment with bilinear filtering. Looks great, but seems to run
about 25% slower. */
#define ZB_LOOKUP_TEXTURE(texture, s, t) \
lookup_texture_bilinear((texture), (s), (t))
#define ZB_LOOKUP_TEXTURE(texture_levels, s, t, level) \
lookup_texture_bilinear((texture_levels), (s), (t))
#endif
@@ -85,22 +91,22 @@ typedef unsigned int PIXEL;
typedef struct {
PIXEL *pixmap;
unsigned int s_mask, t_mask, t_shift;
} ZTexture;
} ZTextureLevel;
typedef struct {
int xsize,ysize;
int linesize; /* line size, in bytes */
int mode;
ZPOINT *zbuf;
PIXEL *pbuf;
int frame_buffer_allocated;
int nb_colors;
unsigned char *dctable;
int *ctable;
ZTexture current_texture;
unsigned int reference_alpha;
int xsize,ysize;
int linesize; /* line size, in bytes */
int mode;
ZPOINT *zbuf;
PIXEL *pbuf;
int frame_buffer_allocated;
int nb_colors;
unsigned char *dctable;
int *ctable;
ZTextureLevel *current_texture; // This is actually an array of texture levels.
unsigned int reference_alpha;
} ZBuffer;
typedef struct {
@@ -129,7 +135,7 @@ void ZB_clear_viewport(ZBuffer * zb, int clear_z, ZPOINT z,
int clear_color, unsigned int r, unsigned int g, unsigned int b, unsigned int a,
int xmin, int ymin, int xsize, int ysize);
PIXEL lookup_texture_bilinear(ZTexture *texture, unsigned int s, unsigned int t);
PIXEL lookup_texture_bilinear(ZTextureLevel *base_level, int s, int t);
/* linesize is in BYTES */
void ZB_copyFrameBuffer(ZBuffer *zb,void *buf,int linesize);

View File

@@ -113,10 +113,11 @@ typedef struct GLVertex {
/* textures */
/* The combination of all mipmap levels: one complete texture. */
typedef struct GLTexture {
PIXEL *pixmap;
ZTextureLevel *levels;
int num_levels;
int xsize, ysize;
int s_mask, t_mask, t_shift;
int s_max, t_max;
} GLTexture;

View File

@@ -2,254 +2,8 @@
#include <stdio.h>
#include "zbuffer.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_noblend_anone_znone
#include "ztriangle_two.h"
/* Pick up all of the generated code references to ztriangle_two.h,
which ultimately calls ztriangle.h, many, many times. */
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_noblend_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_noblend_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_noblend_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_noblend_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_noblend_amore_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_blend_anone_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_blend_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_blend_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_blend_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_blend_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_blend_amore_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_nocolor_anone_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_nocolor_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_nocolor_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_nocolor_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zon_nocolor_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z) (zpix) = (z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zon_nocolor_amore_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_noblend_anone_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_noblend_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_noblend_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_noblend_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_noblend_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_noblend_amore_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_blend_anone_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_blend_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_blend_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_blend_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_blend_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_blend_amore_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_nocolor_anone_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) 1
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_nocolor_anone_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_nocolor_aless_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_nocolor_aless_zless
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) 1
#define FNAME(name) name ## _xx_zoff_nocolor_amore_znone
#include "ztriangle_two.h"
#define STORE_Z(zpix, z)
#define STORE_PIX(pix, rgb, r, g, b, a)
#define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha)
#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))
#define FNAME(name) name ## _xx_zoff_nocolor_amore_zless
#include "ztriangle_two.h"
#include "ztriangle_table.h"
#include "ztriangle_code.h"

View File

@@ -33,6 +33,9 @@
float sz1,dszdx,dszdy,dszdl_min,dszdl_max;
float tz1,dtzdx,dtzdy,dtzdl_min,dtzdl_max;
#endif
#if defined(INTERP_MIPMAP) && (defined(INTERP_ST) || defined(INTERP_STZ))
int mipmap_level;
#endif
EARLY_OUT();
@@ -111,6 +114,8 @@
d2 = (float) (p2->t - p0->t);
dtdx = (int) (fdy2 * d1 - fdy1 * d2);
dtdy = (int) (fdx1 * d2 - fdx2 * d1);
CALC_MIPMAP_LEVEL;
#endif
#ifdef INTERP_STZ

View File

@@ -0,0 +1,160 @@
""" This simple Python script can be run to generate ztriangle_code.h
and ztriangle_table.h, which are a poor man's form of generated code
to cover the explosion of different rendering options while scanning
out triangles.
Each different combination of options is compiled to a different
inner-loop triangle scan function. The code in
tinyGraphicsStateGuardian.cxx will select the appropriate function
pointer at draw time. """
# We generate an #include "ztriangle_two.h" for each combination of
# these options.
Options = [
# depth write
[ 'zon', 'zoff' ],
# color write
[ 'noblend', 'blend', 'nocolor' ],
# alpha test
[ 'anone', 'aless', 'amore' ],
# depth test
[ 'znone', 'zless' ],
# texture filters
[ 'nearest', 'mipmap' ],
]
# The various combinations of these options are explicit within
# ztriangle_two.h.
ExtraOptions = [
# shading
[ 'white', 'flat', 'smooth' ],
# texturing
[ 'untextured', 'textured', 'perspective' ],
]
FullOptions = Options + ExtraOptions
CodeTable = {
# depth write
'zon' : '#define STORE_Z(zpix, z) (zpix) = (z)',
'zoff' : '#define STORE_Z(zpix, z)',
# color write
'noblend' : '#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb)',
'blend' : '#define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a)',
'nocolor' : '#define STORE_PIX(pix, rgb, r, g, b, a)',
# alpha test
'anone' : '#define ACMP(zb, a) 1',
'aless' : '#define ACMP(zb, a) (((unsigned int)(a)) < (zb)->reference_alpha)',
'amore' : '#define ACMP(zb, a) (((unsigned int)(a)) > (zb)->reference_alpha)',
# depth test
'znone' : '#define ZCMP(zpix, z) 1',
'zless' : '#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z))',
# texture filters
'nearest' : '#define CALC_MIPMAP_LEVEL\n#define ZB_LOOKUP_TEXTURE(texture_levels, s, t, level) ZB_LOOKUP_TEXTURE_NEAREST(texture_levels, s, t)',
'mipmap' : '#define CALC_MIPMAP_LEVEL DO_CALC_MIPMAP_LEVEL\n#define INTERP_MIPMAP\n#define ZB_LOOKUP_TEXTURE(texture_levels, s, t, level) ZB_LOOKUP_TEXTURE_NEAREST_MIPMAP(texture_levels, s, t, level)',
}
ops = [0] * len(Options)
class DoneException:
pass
def incrementOptions(ops, i = -1):
if i < -len(ops):
raise DoneException
# Increment the least-significant place if we can.
if ops[i] + 1 < len(Options[i]):
ops[i] += 1
return
# Recurse for the next-most-significant place.
ops[i] = 0
incrementOptions(ops, i - 1)
def getFname(ops):
# Returns the function name corresponding to the indicated ops
# vector.
keywordList = []
for i in range(len(ops)):
keyword = FullOptions[i][ops[i]]
keywordList.append(keyword)
fname = 'FB_triangle_%s' % ('_'.join(keywordList))
return fname
# We write the code that actually instantiates the various
# triangle-filling functions to ztriangle_code.h.
code = open('ztriangle_code.h', 'wb')
print >> code, '/* This file is generated code--do not edit. See ztriangle.py. */'
print >> code, ''
# The external reference for the table containing the above function
# pointers gets written here.
table = open('ztriangle_table.h', 'wb')
print >> table, '/* This file is generated code--do not edit. See ztriangle.py. */'
print >> table, ''
# First, generate the code.
try:
while True:
for i in range(len(ops)):
keyword = Options[i][ops[i]]
print >> code, CodeTable[keyword]
fname = getFname(ops)
print >> code, '#define FNAME(name) %s_ ## name' % (fname)
print >> code, '#include "ztriangle_two.h"'
print >> code, ''
incrementOptions(ops)
except DoneException:
pass
# Now, generate the table of function pointers.
arraySizeList = []
for opList in FullOptions:
arraySizeList.append('[%s]' % (len(opList)))
arraySize = ''.join(arraySizeList)
print >> code, 'const ZB_fillTriangleFunc fill_tri_funcs%s = {' % (arraySize)
print >> table, 'extern const ZB_fillTriangleFunc fill_tri_funcs%s;' % (arraySize)
def writeTableEntry(ops):
indent = ' ' * (len(ops) + 1)
i = len(ops)
numOps = len(FullOptions[i])
if i + 1 == len(FullOptions):
# The last level: write out the actual function names.
for j in range(numOps - 1):
print >> code, indent + getFname(ops + [j]) + ','
print >> code, indent + getFname(ops + [numOps - 1])
else:
# Intermediate levels: write out a nested reference.
for j in range(numOps - 1):
print >> code, indent + '{'
writeTableEntry(ops + [j])
print >> code, indent + '},'
print >> code, indent + '{'
writeTableEntry(ops + [numOps - 1])
print >> code, indent + '}'
writeTableEntry([])
print >> code, '};'

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,5 +1,34 @@
void FNAME(ZB_fillTriangleFlat) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(white_untextured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
#define INTERP_Z
#define EARLY_OUT() \
{ \
}
#define DRAW_INIT() \
{ \
if (!ACMP(zb, p2->a)) { \
return; \
} \
}
#define PUT_PIXEL(_a) \
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
STORE_PIX(pp[_a], 0xffffffffUL, 0xffffUL, 0xffffUL, 0xffffUL, 0xffffUL); \
STORE_Z(pz[_a], zz); \
} \
z+=dzdx; \
}
#include "ztriangle.h"
}
static void FNAME(flat_untextured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
int color;
int or0, og0, ob0, oa0;
@@ -40,8 +69,8 @@ void FNAME(ZB_fillTriangleFlat) (ZBuffer *zb,
* The code below is very tricky :)
*/
void FNAME(ZB_fillTriangleSmooth) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(smooth_untextured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
#define INTERP_Z
#define INTERP_RGB
@@ -54,7 +83,7 @@ void FNAME(ZB_fillTriangleSmooth) (ZBuffer *zb,
c2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a); \
if (c0 == c1 && c0 == c2) { \
/* It's really a flat-shaded triangle. */ \
FNAME(ZB_fillTriangleFlat)(zb, p0, p1, p2); \
FNAME(flat_untextured)(zb, p0, p1, p2); \
return; \
} \
}
@@ -82,10 +111,10 @@ void FNAME(ZB_fillTriangleSmooth) (ZBuffer *zb,
#include "ztriangle.h"
}
void FNAME(ZB_fillTriangleMapping) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(white_textured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
#define INTERP_Z
#define INTERP_ST
@@ -96,14 +125,14 @@ void FNAME(ZB_fillTriangleMapping) (ZBuffer *zb,
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
}
#define PUT_PIXEL(_a) \
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
if (ACMP(zb, PIXEL_A(tmp))) { \
STORE_PIX(pp[_a], tmp, PIXEL_R(tmp), PIXEL_G(tmp), PIXEL_B(tmp), PIXEL_A(tmp)); \
STORE_Z(pz[_a], zz); \
@@ -117,10 +146,10 @@ void FNAME(ZB_fillTriangleMapping) (ZBuffer *zb,
#include "ztriangle.h"
}
void FNAME(ZB_fillTriangleMappingFlat) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(flat_textured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
int or0, og0, ob0, oa0;
#define INTERP_Z
@@ -132,7 +161,7 @@ void FNAME(ZB_fillTriangleMappingFlat) (ZBuffer *zb,
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
or0 = p2->r; \
og0 = p2->g; \
ob0 = p2->b; \
@@ -143,7 +172,7 @@ void FNAME(ZB_fillTriangleMappingFlat) (ZBuffer *zb,
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
int a = oa0 * PIXEL_A(tmp) >> 16; \
if (ACMP(zb, a)) { \
STORE_PIX(pp[_a], \
@@ -166,10 +195,10 @@ void FNAME(ZB_fillTriangleMappingFlat) (ZBuffer *zb,
#include "ztriangle.h"
}
void FNAME(ZB_fillTriangleMappingSmooth) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(smooth_textured) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
#define INTERP_Z
#define INTERP_ST
@@ -185,24 +214,24 @@ void FNAME(ZB_fillTriangleMappingSmooth) (ZBuffer *zb,
/* It's really a flat-shaded triangle. */ \
if (c0 == 0xffffffff) { \
/* Actually, it's a white triangle. */ \
FNAME(ZB_fillTriangleMapping)(zb, p0, p1, p2); \
FNAME(white_textured)(zb, p0, p1, p2); \
return; \
} \
FNAME(ZB_fillTriangleMappingFlat)(zb, p0, p1, p2); \
FNAME(flat_textured)(zb, p0, p1, p2); \
return; \
} \
}
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
}
#define PUT_PIXEL(_a) \
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
int a = oa1 * PIXEL_A(tmp) >> 16; \
if (ACMP(zb, a)) { \
STORE_PIX(pp[_a], \
@@ -234,10 +263,10 @@ void FNAME(ZB_fillTriangleMappingSmooth) (ZBuffer *zb,
* We use the gradient method to make less divisions.
* TODO: pipeline the division
*/
void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(white_perspective) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
float fdzdx,fndzdx,ndszdx,ndtzdx;
#define INTERP_Z
@@ -251,7 +280,7 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
fdzdx=(float)dzdx; \
fndzdx=NB_INTERP * fdzdx; \
ndszdx=NB_INTERP * dszdx; \
@@ -263,7 +292,7 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
if (ACMP(zb, PIXEL_A(tmp))) { \
STORE_PIX(pp[_a], tmp, PIXEL_R(tmp), PIXEL_G(tmp), PIXEL_B(tmp), PIXEL_A(tmp)); \
STORE_Z(pz[_a], zz); \
@@ -298,6 +327,7 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
fz+=fndzdx; \
zinv=1.0f / fz; \
} \
@@ -323,6 +353,7 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
} \
while (n>=0) { \
PUT_PIXEL(0); \
@@ -339,10 +370,10 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb,
* Flat shaded triangle, with perspective-correct mapping.
*/
void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(flat_perspective) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
float fdzdx,fndzdx,ndszdx,ndtzdx;
int or0, og0, ob0, oa0;
@@ -357,7 +388,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
fdzdx=(float)dzdx; \
fndzdx=NB_INTERP * fdzdx; \
ndszdx=NB_INTERP * dszdx; \
@@ -372,7 +403,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
int a = oa0 * PIXEL_A(tmp) >> 16; \
if (ACMP(zb, a)) { \
STORE_PIX(pp[_a], \
@@ -421,6 +452,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
fz+=fndzdx; \
zinv=1.0f / fz; \
} \
@@ -446,6 +478,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
} \
while (n>=0) { \
PUT_PIXEL(0); \
@@ -462,10 +495,10 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb,
* Smooth filled triangle, with perspective-correct mapping.
*/
void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
static void FNAME(smooth_perspective) (ZBuffer *zb,
ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2)
{
ZTexture *texture;
ZTextureLevel *texture_levels;
float fdzdx,fndzdx,ndszdx,ndtzdx;
#define INTERP_Z
@@ -482,17 +515,17 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
/* It's really a flat-shaded triangle. */ \
if (c0 == 0xffffffff) { \
/* Actually, it's a white triangle. */ \
FNAME(ZB_fillTriangleMappingPerspective)(zb, p0, p1, p2); \
FNAME(white_perspective)(zb, p0, p1, p2); \
return; \
} \
FNAME(ZB_fillTriangleMappingPerspectiveFlat)(zb, p0, p1, p2); \
FNAME(flat_perspective)(zb, p0, p1, p2); \
return; \
} \
}
#define DRAW_INIT() \
{ \
texture = &zb->current_texture; \
texture_levels = zb->current_texture; \
fdzdx=(float)dzdx; \
fndzdx=NB_INTERP * fdzdx; \
ndszdx=NB_INTERP * dszdx; \
@@ -503,7 +536,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
{ \
zz=z >> ZB_POINT_Z_FRAC_BITS; \
if (ZCMP(pz[_a], zz)) { \
tmp = ZB_LOOKUP_TEXTURE(texture, s, t); \
tmp = ZB_LOOKUP_TEXTURE(texture_levels, s, t, mipmap_level); \
int a = oa1 * PIXEL_A(tmp) >> 16; \
if (ACMP(zb, a)) { \
STORE_PIX(pp[_a], \
@@ -556,6 +589,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
fz+=fndzdx; \
zinv=1.0f / fz; \
} \
@@ -581,6 +615,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
t=(unsigned int) tt; \
dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \
dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \
CALC_MIPMAP_LEVEL; \
} \
while (n>=0) { \
PUT_PIXEL(0); \
@@ -598,3 +633,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb,
#undef STORE_PIX
#undef STORE_Z
#undef FNAME
#undef INTERP_MIPMAP
#undef CALC_MIPMAP_LEVEL
#undef ZB_LOOKUP_TEXTURE