1 //************************************************************************** 2 //** 3 //** ## ## ## ## ## #### #### ### ### 4 //** ## ## ## ## ## ## ## ## ## ## #### #### 5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6 //** ## ## ######## ## ## ## ## ## ## ## ### ## 7 //** ### ## ## ### ## ## ## ## ## ## 8 //** # ## ## # #### #### ## ## 9 //** 10 //** $Id: drawer.h 4350 2010-12-17 15:36:16Z dj_jl $ 11 //** 12 //** Copyright (C) 1999-2006 Jānis Legzdiņš 13 //** 14 //** This program is free software; you can redistribute it and/or 15 //** modify it under the terms of the GNU General Public License 16 //** as published by the Free Software Foundation; either version 2 17 //** of the License, or (at your option) any later version. 18 //** 19 //** This program is distributed in the hope that it will be useful, 20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 //** GNU General Public License for more details. 23 //** 24 //************************************************************************** 25 26 #ifndef _DRAWER_H_ 27 #define _DRAWER_H_ 28 29 #define BLOCK_WIDTH 128 30 #define BLOCK_HEIGHT 128 31 #define NUM_BLOCK_SURFS 32 32 #define NUM_CACHE_BLOCKS (8 * 1024) 33 34 struct surface_t; 35 struct surfcache_t; 36 struct mmdl_t; 37 struct VMeshModel; 38 class VPortal; 39 40 struct particle_t 41 { 42 // Drawing info 43 TVec org; // position 44 vuint32 colour; // ARGB colour 45 float Size; 46 // Handled by refresh 47 particle_t* next; // next in the list 48 TVec vel; // velocity 49 TVec accel; // acceleration 50 float die; // cl.time when particle will be removed 51 int type; 52 float ramp; 53 float gravity; 54 }; 55 56 struct refdef_t 57 { 58 int x; 59 int y; 60 int width; 61 int height; 62 float fovx; 63 float fovy; 64 bool drawworld; 65 bool DrawCamera; 66 }; 67 68 struct surfcache_t 69 { 70 int s; // position in light surface 71 int t; 72 int width; // size 73 int height; 74 surfcache_t* bprev; // line list in block 75 surfcache_t* bnext; 76 surfcache_t* lprev; // cache list in line 77 surfcache_t* lnext; 78 surfcache_t* chain; // list of drawable surfaces 79 surfcache_t* addchain; // list of specular surfaces 80 int blocknum; // light surface index 81 surfcache_t** owner; 82 vuint32 Light; // checked for strobe flash 83 int dlight; 84 surface_t* surf; 85 vuint32 lastframe; 86 }; 87 88 class VRenderLevelDrawer : public VRenderLevelPublic 89 { 90 public: 91 bool NeedsInfiniteFarClip; 92 93 // Lightmaps. 94 rgba_t light_block[NUM_BLOCK_SURFS][BLOCK_WIDTH * BLOCK_HEIGHT]; 95 bool block_changed[NUM_BLOCK_SURFS]; 96 surfcache_t* light_chain[NUM_BLOCK_SURFS]; 97 98 // Specular lightmaps. 99 rgba_t add_block[NUM_BLOCK_SURFS][BLOCK_WIDTH * BLOCK_HEIGHT]; 100 bool add_changed[NUM_BLOCK_SURFS]; 101 surfcache_t* add_chain[NUM_BLOCK_SURFS]; 102 103 surface_t* SimpleSurfsHead; 104 surface_t* SimpleSurfsTail; 105 surface_t* SkyPortalsHead; 106 surface_t* SkyPortalsTail; 107 surface_t* HorizonPortalsHead; 108 surface_t* HorizonPortalsTail; 109 110 int PortalDepth; 111 112 virtual bool BuildLightMap(surface_t*, int) = 0; 113 }; 114 115 class VDrawer 116 { 117 public: 118 bool HaveStencil; 119 bool HaveMultiTexture; 120 121 VRenderLevelDrawer* RendLev; 122 VDrawer()123 VDrawer() 124 : HaveStencil(false) 125 , HaveMultiTexture(false) 126 , RendLev(NULL) 127 {} ~VDrawer()128 virtual ~VDrawer() 129 {} 130 131 virtual void Init() = 0; 132 virtual bool SetResolution(int, int, int, bool) = 0; 133 virtual void InitResolution() = 0; 134 virtual void StartUpdate() = 0; 135 virtual void Update() = 0; 136 virtual void BeginDirectUpdate() = 0; 137 virtual void EndDirectUpdate() = 0; 138 virtual void Shutdown() = 0; 139 virtual void* ReadScreen(int*, bool*) = 0; 140 virtual void ReadBackScreen(int, int, rgba_t*) = 0; 141 142 // Rendring stuff 143 virtual void SetupView(VRenderLevelDrawer*, const refdef_t*) = 0; 144 virtual void SetupViewOrg() = 0; 145 virtual void WorldDrawing() = 0; 146 virtual void EndView() = 0; 147 148 // Texture stuff 149 virtual void PrecacheTexture(VTexture*) = 0; 150 151 // Polygon drawing 152 virtual void DrawSkyPolygon(surface_t*, bool, VTexture*, float, VTexture*, 153 float, int) = 0; 154 virtual void DrawMaskedPolygon(surface_t*, float, bool) = 0; 155 virtual void DrawSpritePolygon(TVec*, VTexture*, float, bool, 156 VTextureTranslation*, int, vuint32, vuint32, const TVec&, float, 157 const TVec&, const TVec&, const TVec&) = 0; 158 virtual void DrawAliasModel(const TVec&, const TAVec&, const TVec&, 159 const TVec&, VMeshModel*, int, int, VTexture*, VTextureTranslation*, int, 160 vuint32, vuint32, float, bool, bool, float, bool) = 0; 161 virtual bool StartPortal(VPortal*, bool) = 0; 162 virtual void EndPortal(VPortal*, bool) = 0; 163 164 // Particles 165 virtual void StartParticles() = 0; 166 virtual void DrawParticle(particle_t *) = 0; 167 virtual void EndParticles() = 0; 168 169 // Drawing 170 virtual void DrawPic(float, float, float, float, float, float, float, 171 float, VTexture*, VTextureTranslation*, float) = 0; 172 virtual void DrawPicShadow(float, float, float, float, float, float, 173 float, float, VTexture*, float) = 0; 174 virtual void FillRectWithFlat(float, float, float, float, float, float, 175 float, float, VTexture*) = 0; 176 virtual void FillRect(float, float, float, float, vuint32) = 0; 177 virtual void ShadeRect(int, int, int, int, float) = 0; 178 virtual void DrawConsoleBackground(int) = 0; 179 virtual void DrawSpriteLump(float, float, float, float, VTexture*, 180 VTextureTranslation*, bool) = 0; 181 182 // Automap 183 virtual void StartAutomap() = 0; 184 virtual void DrawLine(int, int, vuint32, int, int, vuint32) = 0; 185 virtual void EndAutomap() = 0; 186 187 // Advanced drawing. 188 virtual bool SupportsAdvancedRendering() = 0; 189 virtual void DrawWorldAmbientPass() = 0; 190 virtual void BeginShadowVolumesPass() = 0; 191 virtual void BeginLightShadowVolumes() = 0; 192 virtual void RenderSurfaceShadowVolume(surface_t*, TVec&, float) = 0; 193 virtual void BeginLightPass(TVec&, float, vuint32) = 0; 194 virtual void DrawSurfaceLight(surface_t*) = 0; 195 virtual void DrawWorldTexturesPass() = 0; 196 virtual void DrawWorldFogPass() = 0; 197 virtual void EndFogPass() = 0; 198 virtual void DrawAliasModelAmbient(const TVec&, const TAVec&, const TVec&, 199 const TVec&, VMeshModel*, int, int, VTexture*, vuint32, float, bool) = 0; 200 virtual void DrawAliasModelTextures(const TVec&, const TAVec&, const TVec&, 201 const TVec&, VMeshModel*, int, int, VTexture*, VTextureTranslation*, int, 202 float, bool) = 0; 203 virtual void BeginModelsLightPass(TVec&, float, vuint32) = 0; 204 virtual void DrawAliasModelLight(const TVec&, const TAVec&, const TVec&, 205 const TVec&, VMeshModel*, int, int, VTexture*, float, bool) = 0; 206 virtual void BeginModelsShadowsPass(TVec&, float) = 0; 207 virtual void DrawAliasModelShadow(const TVec&, const TAVec&, const TVec&, 208 const TVec&, VMeshModel*, int, int, float, bool, const TVec&, float) = 0; 209 virtual void DrawAliasModelFog(const TVec&, const TAVec&, const TVec&, 210 const TVec&, VMeshModel*, int, int, VTexture*, vuint32, float, bool) = 0; 211 }; 212 213 // Drawer types, menu system uses these numbers. 214 enum 215 { 216 DRAWER_OpenGL, 217 DRAWER_Direct3D, 218 219 DRAWER_MAX 220 }; 221 222 // Drawer description. 223 struct FDrawerDesc 224 { 225 const char* Name; 226 const char* Description; 227 const char* CmdLineArg; 228 VDrawer* (*Creator)(); 229 230 FDrawerDesc(int Type, const char* AName, const char* ADescription, 231 const char* ACmdLineArg, VDrawer* (*ACreator)()); 232 }; 233 234 // Drawer driver declaration macro. 235 #define IMPLEMENT_DRAWER(TClass, Type, Name, Description, CmdLineArg) \ 236 static VDrawer* Create##TClass() \ 237 { \ 238 return new TClass(); \ 239 } \ 240 FDrawerDesc TClass##Desc(Type, Name, Description, CmdLineArg, Create##TClass); 241 242 extern VDrawer *Drawer; 243 244 #endif 245