00001
00002 #ifndef DRAW_H
00003 #define DRAW_H
00004
00005 #include "texture.h"
00006 #include "world.h"
00007 #include "newcoll.h"
00008
00009
00010
00011 #define POLY_QUAD 1
00012 #define POLY_DOUBLE 2
00013 #define POLY_SEMITRANS 4
00014 #define POLY_MIRROR 128
00015 #define POLY_SEMITRANS_ONE 256
00016 #define POLY_TEXANIM 512
00017 #define POLY_NOENV 1024
00018 #define POLY_ENV 2048
00019
00020 #define MAX_SEMI_POLYS 800
00021 #define MAX_3D_POLYS 128
00022 #define MAX_WORLD_MESH_FX 32
00023 #define MAX_MODEL_MESH_FX 32
00024
00025 #define MESHFX_USENEWVERTS 1
00026
00027 #define MAX_POLY_BUCKETS (TPAGE_NUM)
00028 #define BUCKET_VERT_NUM 200
00029 #define BUCKET_VERT_END (BUCKET_VERT_NUM - 4)
00030
00031 #define ENV_VERT_NUM 2000
00032 #define ENV_VERT_END (ENV_VERT_NUM - 4)
00033
00034 #define JUMPSPARK_STEP_LEN 8.0f
00035 #define JUMPSPARK_STEP_MAX 64
00036 #define JUMPSPARK_OFFSET_NUM 32
00037
00038 #define RGB_ALPHA_MASK 0xff000000
00039 #define RGB_RED_MASK 0xff0000
00040 #define RGB_GREEN_MASK 0xff00
00041 #define RGB_BLUE_MASK 0xff
00042
00043 #define FVF_TEX0 (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX0)
00044 #define FVF_TEX1 (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1)
00045 #define FVF_TEX2 (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2)
00046
00047
00048
00049 #define SEMI_POLY_FREE() \
00050 (SemiCount < MAX_SEMI_POLYS)
00051
00052 #define SEMI_POLY_SETUP(_vert, _fog, _vertnum, _tpage, _clip, _semi) \
00053 { \
00054 SemiPoly[SemiCount].Fog = _fog; \
00055 SemiPoly[SemiCount].VertNum = _vertnum; \
00056 SemiPoly[SemiCount].Tpage = _tpage; \
00057 if (_clip) SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS; \
00058 else SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTCLIP; \
00059 SemiPoly[SemiCount].SemiType = _semi; \
00060 SemiPoly[SemiCount].z = 0.0f; \
00061 _vert = SemiPoly[SemiCount++].Verts; \
00062 }
00063
00064 #define SEMI_POLY_SETUP_RGB(_vert, _fog, _vertnum, _clip, _semi) \
00065 { \
00066 SemiPoly[SemiCount].Fog = _fog; \
00067 SemiPoly[SemiCount].VertNum = _vertnum; \
00068 SemiPoly[SemiCount].Tpage = -1; \
00069 if (_clip) SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS; \
00070 else SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTCLIP; \
00071 SemiPoly[SemiCount].SemiType = _semi; \
00072 SemiPoly[SemiCount].z = 0.0f; \
00073 _vert = SemiPoly[SemiCount++].VertsRGB; \
00074 }
00075
00076 #define SEMI_POLY_SETUP_ZBIAS(_vert, _fog, _vertnum, _tpage, _clip, _semi, _zbias) \
00077 { \
00078 SemiPoly[SemiCount].Fog = _fog; \
00079 SemiPoly[SemiCount].VertNum = _vertnum; \
00080 SemiPoly[SemiCount].Tpage = _tpage; \
00081 if (_clip) SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS; \
00082 else SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTCLIP; \
00083 SemiPoly[SemiCount].SemiType = _semi; \
00084 SemiPoly[SemiCount].z = _zbias; \
00085 _vert = SemiPoly[SemiCount++].Verts; \
00086 }
00087
00088 #define SEMI_POLY_SETUP_RGB_ZBIAS(_vert, _fog, _vertnum, _clip, _semi, _zbias) \
00089 { \
00090 SemiPoly[SemiCount].Fog = _fog; \
00091 SemiPoly[SemiCount].VertNum = _vertnum; \
00092 SemiPoly[SemiCount].Tpage = -1; \
00093 if (_clip) SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS; \
00094 else SemiPoly[SemiCount].DrawFlag = D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTCLIP; \
00095 SemiPoly[SemiCount].SemiType = _semi; \
00096 SemiPoly[SemiCount].z = _zbias; \
00097 _vert = SemiPoly[SemiCount++].VertsRGB; \
00098 }
00099
00100
00101
00102 #if SCREEN_DEBUG
00103 #define INC_POLY_COUNT(_v, _n) \
00104 (_v) += (_n)
00105 #else
00106 #define INC_POLY_COUNT(_v, _n)
00107 #endif
00108
00109 #define CLIP_QUAD() \
00110 { \
00111 if (mp->v0->Clip & mp->v1->Clip & mp->v2->Clip & mp->v3->Clip) continue; \
00112 clip = (mp->v0->Clip | mp->v1->Clip | mp->v2->Clip | mp->v3->Clip); \
00113 }
00114
00115 #define CLIP_TRI() \
00116 { \
00117 if (mp->v0->Clip & mp->v1->Clip & mp->v2->Clip) continue; \
00118 clip = (mp->v0->Clip | mp->v1->Clip | mp->v2->Clip); \
00119 }
00120
00121 #define CLIP_QUAD_MIRROR() \
00122 { \
00123 if (mp->v0->Clip & mp->v1->Clip & mp->v2->Clip & mp->v3->Clip) continue; \
00124 clip = (mp->v0->Clip | mp->v1->Clip | mp->v2->Clip | mp->v3->Clip) & 63; \
00125 }
00126
00127 #define CLIP_TRI_MIRROR() \
00128 { \
00129 if (mp->v0->Clip & mp->v1->Clip & mp->v2->Clip) continue; \
00130 clip = (mp->v0->Clip | mp->v1->Clip | mp->v2->Clip) & 63; \
00131 }
00132
00133 #define COPY_TRI_XYZRHW(_v) \
00134 { \
00135 *(MEM16*)&(_v)[0].sx = *(MEM16*)&mp->v0->sx; \
00136 *(MEM16*)&(_v)[1].sx = *(MEM16*)&mp->v1->sx; \
00137 *(MEM16*)&(_v)[2].sx = *(MEM16*)&mp->v2->sx; \
00138 }
00139
00140 #define COPY_QUAD_XYZRHW(_v) \
00141 { \
00142 *(MEM16*)&(_v)[0].sx = *(MEM16*)&mp->v0->sx; \
00143 *(MEM16*)&(_v)[1].sx = *(MEM16*)&mp->v1->sx; \
00144 *(MEM16*)&(_v)[2].sx = *(MEM16*)&mp->v2->sx; \
00145 *(MEM16*)&(_v)[3].sx = *(MEM16*)&mp->v3->sx; \
00146 }
00147
00148 #define COPY_TRI_UV(_v) \
00149 { \
00150 *(MEM8*)&(_v)[0].tu = *(MEM8*)&mp->tu0; \
00151 *(MEM8*)&(_v)[1].tu = *(MEM8*)&mp->tu1; \
00152 *(MEM8*)&(_v)[2].tu = *(MEM8*)&mp->tu2; \
00153 }
00154
00155 #define COPY_QUAD_UV(_v) \
00156 { \
00157 *(MEM8*)&(_v)[0].tu = *(MEM8*)&mp->tu0; \
00158 *(MEM8*)&(_v)[1].tu = *(MEM8*)&mp->tu1; \
00159 *(MEM8*)&(_v)[2].tu = *(MEM8*)&mp->tu2; \
00160 *(MEM8*)&(_v)[3].tu = *(MEM8*)&mp->tu3; \
00161 }
00162
00163 #define COPY_TRI_SPECULAR(_v) \
00164 { \
00165 (_v)[0].specular = mp->v0->specular; \
00166 (_v)[1].specular = mp->v1->specular; \
00167 (_v)[2].specular = mp->v2->specular; \
00168 }
00169
00170 #define COPY_QUAD_SPECULAR(_v) \
00171 { \
00172 (_v)[0].specular = mp->v0->specular; \
00173 (_v)[1].specular = mp->v1->specular; \
00174 (_v)[2].specular = mp->v2->specular; \
00175 (_v)[3].specular = mp->v3->specular; \
00176 }
00177
00178
00179
00180 typedef struct {
00181 float sx, sy, sz, rhw;
00182 DWORD color, specular;
00183 } VERTEX_TEX0;
00184
00185 typedef struct {
00186 float sx, sy, sz, rhw;
00187 DWORD color, specular;
00188 float tu, tv;
00189 } VERTEX_TEX1;
00190
00191 typedef struct {
00192 float sx, sy, sz, rhw;
00193 DWORD color, specular;
00194 float tu, tv;
00195 float tu2, tv2;
00196 } VERTEX_TEX2;
00197
00198 typedef struct {
00199 unsigned short Index[ENV_VERT_NUM * 2];
00200 unsigned short *CurrentIndex;
00201 VERTEX_TEX1 *CurrentVerts;
00202 VERTEX_TEX1 Verts[ENV_VERT_NUM];
00203 } BUCKET_ENV;
00204
00205 typedef struct {
00206 unsigned short Index[BUCKET_VERT_NUM * 2];
00207 unsigned short *CurrentIndex;
00208 VERTEX_TEX0 *CurrentVerts;
00209 VERTEX_TEX0 Verts[BUCKET_VERT_NUM];
00210 } BUCKET_TEX0;
00211
00212 typedef struct {
00213 unsigned short Index[BUCKET_VERT_NUM * 2];
00214 unsigned short *CurrentIndex;
00215 VERTEX_TEX1 *CurrentVerts;
00216 VERTEX_TEX1 Verts[BUCKET_VERT_NUM];
00217 } BUCKET_TEX1;
00218
00219 typedef struct {
00220 long DrawFlag, VertNum, Tpage, Fog, SemiType;
00221 float z;
00222 union {
00223 VERTEX_TEX1 Verts[4];
00224 VERTEX_TEX0 VertsRGB[4];
00225 };
00226 } DRAW_SEMI_POLY;
00227
00228 typedef struct {
00229 long VertNum, Tpage, Fog, SemiType;
00230 VEC Pos[4];
00231 VERTEX_TEX1 Verts[4];
00232 } DRAW_3D_POLY;
00233
00234 typedef struct {
00235 float Xsize, Ysize;
00236 float U, V, Usize, Vsize;
00237 short Tpage, pad;
00238 long RGB;
00239 } FACING_POLY;
00240
00241 typedef struct {
00242 void (*Checker)(void *data);
00243 void *Data;
00244 } WORLD_MESH_FX;
00245
00246 typedef struct {
00247 void (*Checker)(void *data);
00248 void *Data;
00249 } MODEL_MESH_FX;
00250
00251
00252
00253 extern void InitPolyBuckets(void);
00254 extern void KillPolyBuckets(void);
00255 extern void FlushPolyBuckets(void);
00256 extern void FlushEnvBuckets(void);
00257 extern void FlushOneBucketTEX0(BUCKET_TEX0 *bucket, long clip);
00258 extern void FlushOneBucketTEX1(BUCKET_TEX1 *bucket, long clip);
00259 extern void FlushOneBucketEnv(BUCKET_ENV *bucket, long clip);
00260 extern void Reset3dPolyList(void);
00261 extern void Draw3dPolyList(void);
00262 extern DRAW_3D_POLY *Get3dPoly(void);
00263 extern void DrawNearClipPolyTEX0(VEC *pos, long *rgb, long vertnum);
00264 extern void ResetSemiList(void);
00265 extern void DrawSemiList(void);
00266 extern void DrawFacingPolyMirror(VEC *pos, FACING_POLY *poly, long semi, float zbias);
00267 extern void DrawFacingPoly(VEC *pos, FACING_POLY *poly, long semi, float zbias);
00268 extern void DrawFacingPolyRotMirror(VEC *pos, MAT *mat, FACING_POLY *poly, long semi, float zbias);
00269 extern void DrawFacingPolyRot(VEC *pos, MAT *mat, FACING_POLY *poly, long semi, float zbias);
00270 extern void InitRenderStates(void);
00271 extern void SetNearFar(REAL n, REAL f);
00272 extern void SetFogVars(REAL fogstart, REAL vertstart, REAL vertend);
00273 extern void DrawAxis(MAT *mat, VEC *pos);
00274 extern void DumpImage(char handle, float x, float y, float w, float h, float u, float v, float tw, float th, unsigned long col);
00275 extern void DrawMousePointer(unsigned long color);
00276 extern BOOL LoadBitmap(char *bitmap, HBITMAP *hbm);
00277 extern BOOL FreeBitmap(HBITMAP hbm);
00278 extern BOOL BlitBitmap(HBITMAP hbm, IDirectDrawSurface4 **surface);
00279 extern void DrawBoundingBox(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax, long c0, long c1, long c2, long c3, long c4, long c5);
00280 extern void DrawCubeNormals(WORLD_MODEL *m);
00281 extern bool DrawCollSkin(CONVEX *skin, INDEX count);
00282 extern void DrawLine(VEC *v0, VEC *v1, long col0, long col1);
00283 extern void DrawTriClip(VERTEX_TEX1 *v0, VERTEX_TEX1 *v1, VERTEX_TEX1 *v2);
00284 extern void DrawQuadClip(VERTEX_TEX1 *v0, VERTEX_TEX1 *v1, VERTEX_TEX1 *v2, VERTEX_TEX1 *v3);
00285 extern void DrawFanClip(void);
00286 extern void ClipLineTEX0(VERTEX_TEX0 *v0, VERTEX_TEX0 *v1, float mul, VERTEX_TEX0 *out);
00287 extern void ClipLineTEX1(VERTEX_TEX1 *v0, VERTEX_TEX1 *v1, float mul, VERTEX_TEX1 *out);
00288 extern void DrawCollPoly(NEWCOLLPOLY *poly);
00289 extern void SaveFrontBuffer(char *file);
00290 extern void ResetMeshFxList(void);
00291 extern void AddWorldMeshFx(void (*checker)(void *data), void *data);
00292 extern void AddModelMeshFx(void (*checker)(void *data), void *data);
00293 extern void InitJumpSparkOffsets(void);
00294 extern void DrawJumpSpark(VEC *v1, VEC *v2);
00295 extern void DrawJumpSpark2(VEC *v1, VEC *v2);
00296
00297
00298
00299
00300 extern BUCKET_ENV BucketEnvStill, BucketEnvStillFog, BucketEnvStillClip, BucketEnvStillClipFog;
00301 extern BUCKET_ENV BucketEnvRoll, BucketEnvRollFog, BucketEnvRollClip, BucketEnvRollClipFog;
00302 extern BUCKET_ENV BucketEnv, BucketEnvFog, BucketEnvClip, BucketEnvClipFog;
00303 extern BUCKET_TEX0 BucketRGB, BucketFogRGB, BucketClipRGB, BucketClipFogRGB;
00304 extern BUCKET_TEX1 Bucket[], BucketFog[], BucketClip[], BucketClipFog[];
00305 extern VERTEX_TEX0 DrawVertsTEX0[];
00306 extern VERTEX_TEX1 DrawVertsTEX1[];
00307 extern VERTEX_TEX2 DrawVertsTEX2[];
00308 extern DRAW_SEMI_POLY SemiPoly[];
00309 extern WORLD_MESH_FX WorldMeshFx[];
00310 extern MODEL_MESH_FX ModelMeshFx[];
00311 extern long SemiCount, WorldMeshFxCount, ModelMeshFxCount;
00312
00313
00314 #endif