132#define DEFAULT_DEBUG_SHADER_BITS ( SHADE_CNST(\
133 ShaderClass::PASS_LEQUAL,\
134 ShaderClass::DEPTH_WRITE_ENABLE,\
135 ShaderClass::COLOR_WRITE_ENABLE,\
136 ShaderClass::SRCBLEND_ONE,\
137 ShaderClass::DSTBLEND_ZERO,\
138 ShaderClass::FOG_DISABLE,\
139 ShaderClass::GRADIENT_MODULATE,\
140 ShaderClass::SECONDARY_GRADIENT_DISABLE,\
141 ShaderClass::TEXTURING_DISABLE,\
142 ShaderClass::ALPHATEST_DISABLE,\
143 ShaderClass::CULL_MODE_ENABLE, \
144 ShaderClass::DETAILCOLOR_DISABLE,\
145 ShaderClass::DETAILALPHA_DISABLE) )
147#define LIGHTMAP_DEBUG_SHADER_BITS ( SHADE_CNST(\
148 ShaderClass::PASS_LEQUAL,\
149 ShaderClass::DEPTH_WRITE_ENABLE,\
150 ShaderClass::COLOR_WRITE_ENABLE,\
151 ShaderClass::SRCBLEND_ONE,\
152 ShaderClass::DSTBLEND_ZERO,\
153 ShaderClass::FOG_DISABLE,\
154 ShaderClass::GRADIENT_DISABLE,\
155 ShaderClass::SECONDARY_GRADIENT_DISABLE,\
156 ShaderClass::TEXTURING_ENABLE,\
157 ShaderClass::ALPHATEST_DISABLE,\
158 ShaderClass::CULL_MODE_ENABLE, \
159 ShaderClass::DETAILCOLOR_DISABLE,\
160 ShaderClass::DETAILALPHA_DISABLE) )
170unsigned int WW3D::SyncTime = 0;
171unsigned int WW3D::PreviousSyncTime = 0;
172bool WW3D::IsSortingEnabled =
true;
174float WW3D::PixelCenterX = 0.0f;
175float WW3D::PixelCenterY = 0.0f;
178bool WW3D::IsInitted =
false;
179bool WW3D::IsRendering =
false;
180bool WW3D::IsCapturing =
false;
181bool WW3D::IsScreenUVBiased =
false;
183bool WW3D::AreDecalsEnabled =
true;
184float WW3D::DecalRejectionDistance = 1000000.0f;
186bool WW3D::AreStaticSortListsEnabled =
false;
187bool WW3D::MungeSortOnLoad =
false;
189bool WW3D::OverbrightModifyOnLoad =
false;
192bool WW3D::PauseRecord;
193bool WW3D::RecordNextFrame;
195int WW3D::FrameCount = 0;
200float WW3D::DefaultNativeScreenSize = 1.0f;
211bool WW3D::ExposePrelit =
false;
213bool WW3D::SnapshotActivated=
false;
214bool WW3D::ThumbnailEnabled=
true;
218unsigned WW3D::NPatchesLevel=1;
219bool WW3D::IsTexturingEnabled=
true;
220bool WW3D::IsColoringEnabled=
false;
222static HWND _Hwnd =
NULL;
223static int _TextureReduction = 0;
224static int _TextureMinDim = 1;
225static bool _LargeTextureExtraReductionEnabled =
false;
226int WW3D::LastFrameMemoryAllocations;
227int WW3D::LastFrameMemoryFrees;
229int WW3D::TextureFilter = 0;
231bool WW3D::Lite =
false;
241 if (NPatchesGapFillingMode!=mode) {
242 NPatchesGapFillingMode=mode;
249 if (level>8) level=8;
250 if (level<1) level=1;
253 NPatchesLevel = level;
270 assert(IsInitted ==
false);
284 Allocate_Debug_Resources();
286 MMRESULT r=timeBeginPeriod(1);
295 if (dazzle_ini_file) {
296 INIClass dazzle_ini(*dazzle_ini_file);
334 assert(Lite || IsInitted ==
true);
344 MMRESULT r=timeEndPeriod(1);
361 Release_Debug_Resources();
374 delete DefaultStaticSortLists;
772 if (texture_filter<0) texture_filter=0;
774 TextureFilter=texture_filter;
801 SNAPSHOT_SAY((
"==========================================\r\n"));
802 SNAPSHOT_SAY((
"========== WW3D::Begin_Render ============\r\n"));
803 SNAPSHOT_SAY((
"==========================================\r\n\r\n"));
808 if( D3DERR_DEVICELOST == hr )
812 if( D3DERR_DEVICENOTRESET == hr )
830 TextureFileClass::Update_Texture_Flash();
834 if (IsCapturing && (!PauseRecord || RecordNextFrame)) {
836 RecordNextFrame =
false;
843 if (clear || clearz) {
845 int width, height, bits;
893 layer = layer->
Prev();
955 if (clear || clearz) {
1098 IsRendering =
false;
1112 SNAPSHOT_SAY((
"==========================================\r\n"));
1113 SNAPSHOT_SAY((
"========== WW3D::End_Render ==============\r\n"));
1114 SNAPSHOT_SAY((
"==========================================\r\n\r\n"));
1182 PreviousSyncTime = SyncTime;
1183 SyncTime = sync_time;
1319 static int frame_number = 1;
1323 sprintf( filename,
"%s%.2d.%s", filename_base, frame_number++, ext);
1334 WWDEBUG_SAY((
"Creating Screen Shot %s\n", filename ));
1338 unsigned char gamma_lut[256];
1341 recip = 1.0f / gamma;
1343 for (i = 0; i < 256; i++) {
1344 gamma_lut[i] = (
unsigned char) (256.0f * powf(i / 256.0f, recip));
1349 IDirect3DSurface8 *fb;
1351 D3DSURFACE_DESC desc;
1355 GetWindowRect(_Hwnd,&bounds);
1357 D3DLOCKED_RECT lrect;
1359 DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
1361 unsigned int x,y,index,index2,width,height;
1363 width=bounds.right-bounds.left;
1364 height=bounds.bottom-bounds.top;
1366 unsigned char *image=
W3DNEWARRAY unsigned char[3*width*height];
1368 for (y=0; y<height; y++)
1370 for (x=0; x<width; x++)
1373 index=3*(x+y*width);
1375 index2=y*lrect.Pitch+4*x;
1377 image[index] = gamma_lut[*((
unsigned char *) lrect.pBits + index2+2)];
1378 image[index+1] = gamma_lut[*((
unsigned char *) lrect.pBits + index2+1)];
1379 image[index+2] = gamma_lut[*((
unsigned char *) lrect.pBits + index2+0)];
1391 targ.
Header.Height=height;
1392 targ.
Header.PixelDepth=24;
1409 BITMAPFILEHEADER fileheader;
1410 BITMAPINFOHEADER header;
1411 memset(&header, 0,
sizeof(BITMAPINFOHEADER));
1412 header.biSize =
sizeof(BITMAPINFOHEADER);
1413 header.biWidth = width;
1414 header.biHeight = height;
1415 header.biPlanes = 1;
1416 header.biBitCount = 24;
1417 header.biCompression = BI_RGB;
1418 header.biXPelsPerMeter = 0xB12;
1419 header.biYPelsPerMeter = 0xB12;
1420 int len = ((width * 24 +31) & ~31) /8;
1422 memset(&fileheader, 0,
sizeof(BITMAPFILEHEADER));
1423 fileheader.bfType = 19778;
1424 fileheader.bfOffBits =
sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER);
1425 fileheader.bfSize =
sizeof(BITMAPFILEHEADER) +
sizeof(BITMAPINFOHEADER) + 3 * len * height *
sizeof(char);
1432 num = file->Write(&fileheader,
sizeof(BITMAPFILEHEADER));
1433 WWASSERT(num ==
sizeof(BITMAPFILEHEADER));
1434 num = file->Write(&header,
sizeof(BITMAPINFOHEADER));
1435 WWASSERT(num ==
sizeof(BITMAPINFOHEADER));
1436 char *temp =
new char [3 * len];
1437 memset(temp, 0, 3 * len *
sizeof(
char));
1439 for (y = 0; y < (int) height; y++) {
1440 memcpy(&temp[0], &image[ 3 * width * (height - y - 1)], 3 * width *
sizeof(
char));
1441 for (x = 0; x < width; x++) {
1442 char t2 = temp[3 * x];
1443 temp[3 * x] = temp[3 * x + 2];
1444 temp[3 * x + 2] = t2;
1446 num = file->Write(&temp[0], len *
sizeof(
char));
1447 WWASSERT(num == len * (
int)
sizeof(
char));
1484 GetWindowRect(_Hwnd,&bounds);
1485 int height=bounds.bottom-bounds.top;
1486 int width=bounds.right-bounds.left;
1491 if (frame_rate == 0.0f) {
1495 PauseRecord =
false;
1500 WWDEBUG_SAY((
"Starting Movie %s\n", filename_base ));
1521 IsCapturing =
false;
1586 RecordNextFrame =
true;
1640 return (Movie != 0) && (!PauseRecord || RecordNextFrame);
1679 WWPROFILE(
"WW3D::Update_Movie_Capture");
1684 IDirect3DSurface8 *fb;
1686 D3DSURFACE_DESC desc;
1690 GetWindowRect(_Hwnd,&bounds);
1692 D3DLOCKED_RECT lrect;
1694 DX8_ErrorCode(fb->LockRect(&lrect,&bounds,D3DLOCK_READONLY));
1696 unsigned int x,y,index,index2,width,height;
1698 width=bounds.right-bounds.left;
1699 height=bounds.bottom-bounds.top;
1701 char *image=(
char *)Movie->GetBuffer();
1703 for (y=0; y<height; y++)
1705 for (x=0; x<width; x++)
1708 index=3*(x+(height-y-1)*width);
1710 index2=y*lrect.Pitch+4*x;
1712 image[index]=*((
char *) lrect.pBits + index2+0);
1713 image[index+1]=*((
char *) lrect.pBits + index2+1);
1714 image[index+2]=*((
char *) lrect.pBits + index2+2);
1741 return Movie->GetFrameRate();
1762 if (_TextureReduction !=
value || _TextureMinDim != minDim) {
1763 _TextureReduction=
value;
1764 _TextureMinDim=minDim;
1772 if (b==IsTexturingEnabled)
return;
1773 IsTexturingEnabled=b;
1779 IsColoringEnabled = (color == 0) ?
false :
true;
1796 return _TextureReduction;
1813 return _TextureMinDim;
1818 if (_LargeTextureExtraReductionEnabled != onoff) {
1819 _LargeTextureExtraReductionEnabled = onoff;
1826 return _LargeTextureExtraReductionEnabled;
1845 return DefaultDebugMaterial;
1865 return DefaultDebugShader;
1882 return LightmapDebugShader;
1897void WW3D::Allocate_Debug_Resources(
void)
1923void WW3D::Release_Debug_Resources(
void)
1949 x = PixelCenterX; y = PixelCenterY;
1953void WW3D::Update_Pixel_Center(
void)
1956 const char *name = _RenderDeviceShortNameTable.getString(CurRenderDevice);
1957 if ( strstr(name,
"OpenGL") ) {
1958 PixelCenterX = 0.0f; PixelCenterY = 0.0f;
1959 }
else if ( strstr(name,
"Glide") ) {
1960 PixelCenterX = 0.0f; PixelCenterY = 0.0f;
1961 }
else if ( strstr(name,
"DirectX") ) {
1962 PixelCenterX = 0.5f; PixelCenterY = 0.5f;
1963 }
else if ( strstr(name,
"Software") ) {
1964 PixelCenterX = 0.0f; PixelCenterY = 0.0f;
1965 }
else if ( strstr(name,
"Null") ) {
1966 PixelCenterX = 0.0f; PixelCenterY = 0.0f;
1969 PixelCenterX = 0.0f; PixelCenterY = 0.0f;
1986 CurrentStaticSortLists->Add_To_List(robj, sort_level);
1993 bool old_enable = AreStaticSortListsEnabled;
1994 AreStaticSortListsEnabled =
false;
1995 CurrentStaticSortLists->Render_And_Clear(rinfo);
1996 AreStaticSortListsEnabled = old_enable;
2001 IsSortingEnabled = onoff;
2010 CurrentStaticSortLists = sort_list;
2019 CurrentStaticSortLists = DefaultStaticSortLists;
T Bound(T original, T minval, T maxval)
static void Shutdown(void)
static void Initialize(const char *ini_filename=NULL)
static int Get_Box_Display_Mask(void)
static void Set_Box_Display_Mask(int mask)
static int Get_Swap_Interval(void)
static void Begin_Scene(void)
static IDirect3DDevice8 * _Get_D3D_Device8()
static bool Set_Next_Render_Device(void)
static void Clear(bool clear_color, bool clear_z_stencil, const Vector3 &color, float dest_alpha=0.0f, float z=1.0f, unsigned int stencil=0)
Clear current render device.
static IDirect3DSurface8 * _Get_DX8_Front_Buffer()
static int Get_Render_Device(void)
static void Shutdown(void)
static void Get_Device_Resolution(int &set_w, int &set_h, int &set_bits, bool &set_windowed)
static void Set_Ambient(const Vector3 &color)
static bool Set_Any_Render_Device(void)
static void Invalidate_Cached_Render_States(void)
static bool Init(void *hwnd, bool lite=false)
static void Set_Light_Environment(LightEnvironmentClass *light_env)
Set the light environment. This is a lighting model which used up to four directional lights to produ...
static void Flip_To_Primary(void)
static void End_Scene(bool flip_frame=true)
static bool Toggle_Windowed(void)
static bool Set_Render_Device(const char *dev_name, int width=-1, int height=-1, int bits=-1, int windowed=-1, bool resize_window=false)
static int Get_Device_Resolution_Width(void)
static void Set_Gamma(float gamma, float bright, float contrast, bool calibrate=true, bool uselimit=true)
static void Set_Texture_Bitdepth(int depth)
static bool Reset_Device(bool reload_assets=true)
static int Get_Render_Device_Count(void)
static bool Set_Device_Resolution(int width=-1, int height=-1, int bits=-1, int windowed=-1, bool resize_window=false)
static bool Is_Windowed(void)
static void Get_Render_Target_Resolution(int &set_w, int &set_h, int &set_bits, bool &set_windowed)
static int Get_Texture_Bitdepth(void)
static void Set_Viewport(CONST D3DVIEWPORT8 *pViewport)
static const char * Get_Render_Device_Name(int device_index)
static void Set_Swap_Interval(int swap)
static const RenderDeviceDescClass & Get_Render_Device_Desc(int deviceidx)
static bool Registry_Save_Render_Device(const char *sub_key)
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
static bool Registry_Load_Render_Device(const char *sub_key, bool resize_window)
static int Get_Device_Resolution_Height(void)
static void Init_From_INI(const INIClass *ini)
static void _Reset(bool frame_changed)
static void _Reset(bool frame_changed)
virtual int Create(void)=0
virtual bool Is_Available(int forced=false)=0
virtual void Close(void)=0
virtual int Open(char const *filename, int rights=READ)=0
bool Is_Valid(void) const
LightEnvironmentClass * light_environment
virtual void On_Frame_Update()
virtual void Render(RenderInfoClass &rinfo)=0
virtual const Vector3 & Get_Ambient_Light(void)
virtual void Render(RenderInfoClass &rinfo)
PolyRenderType Get_Polygon_Mode(void)
char * SetImage(char *buffer)
long Save(const char *name, long flags, bool addextension=false)
void Invalidate()
Invalidate this texture.
static void _Init_Filters(TextureFilterMode texture_filter)
Init filters (legacy)
@ TEXTURE_FILTER_ANISOTROPIC
static void Flush_Pending_Load_Tasks(void)
static void Update(void(*network_callback)(void)=NULL)
void Set_Specular(const Vector3 &color)
void Set_Diffuse(const Vector3 &color)
void Set_Ambient(const Vector3 &color)
void Set_Shininess(float shin)
void Set_Emissive(const Vector3 &color)
void Set_Opacity(float o)
static WW3DAssetManager * Get_Instance(void)
virtual void Free_Assets(void)
static WW3DErrorType On_Activate_App(void)
static WW3DErrorType Render(const LayerListClass &layerlist)
static bool Is_Recording_Next_Frame()
static ShaderClass Peek_Lightmap_Debug_Shader(void)
static WW3DErrorType Registry_Save_Render_Device(const char *sub_key)
static void Set_Ext_Swap_Interval(long swap)
static bool Is_Movie_Paused()
static void Render_And_Clear_Static_Sort_Lists(RenderInfoClass &rinfo)
static int Get_Texture_Reduction(void)
static VertexMaterialClass * Peek_Default_Debug_Material(void)
static WW3DErrorType Set_Render_Device(int dev=-1, int resx=-1, int resy=-1, int bits=-1, int windowed=-1, bool resize_window=false, bool reset_device=false, bool restore_assets=true)
static WW3DErrorType Init(void *hwnd, char *defaultpal=NULL, bool lite=false)
static WW3DErrorType Set_Device_Resolution(int w=-1, int h=-1, int bits=-1, int windowed=-1, bool resize_window=false)
static void Add_To_Static_Sort_List(RenderObjClass *robj, unsigned int sort_level)
static void Enable_Texturing(bool b)
static void Activate_Snapshot(bool b)
static WW3DErrorType Toggle_Windowed(void)
static void * Get_Window(void)
static WW3DErrorType Begin_Render(bool clear=false, bool clearz=true, const Vector3 &color=Vector3(0, 0, 0), float dest_alpha=0.0f, void(*network_callback)(void)=NULL)
static void Pause_Movie(bool mode)
static bool Is_Windowed(void)
static WW3DErrorType On_Deactivate_App(void)
static void Set_Gamma(float gamma, float bright, float contrast, bool calibrate=true)
static WW3DErrorType Shutdown(void)
static int Get_Texture_Bitdepth()
static void Flip_To_Primary(void)
static void Update_Movie_Capture(void)
static void Enable_Coloring(unsigned int color)
when non-zero color is passed, it will override vertex colors
static void Enable_Large_Texture_Extra_Reduction(bool onoff)
static void Toggle_Movie_Capture(const char *filename_base="Movie", float frame_rate=15)
static void Normalize_Coordinates(int x, int y, float &fx, float &fy)
static const RenderDeviceDescClass & Get_Render_Device_Desc(int device=-1)
static bool Is_Large_Texture_Extra_Reduction_Enabled(void)
static void Start_Single_Frame_Movie_Capture(const char *filename_base="Frames")
static void Get_Device_Resolution(int &set_w, int &set_h, int &get_bits, bool &get_windowed)
static void _Invalidate_Textures()
static const char * Get_Render_Device_Name(int device_index)
static void Set_Texture_Filter(int filter)
static float Get_Movie_Capture_Frame_Rate(void)
static bool Is_Movie_Ready()
static const int Get_Render_Device_Count(void)
static WW3DErrorType Set_Any_Render_Device(void)
static WW3DErrorType Registry_Load_Render_Device(const char *sub_key, bool resize_window=false)
static void Sync(unsigned int sync_time)
static int Get_Texture_Min_Dimension(void)
static void Flush(RenderInfoClass &rinfo)
static WW3DErrorType End_Render(bool flip_frame=true)
static void Set_Texture_Bitdepth(int bitdepth)
static void Set_Texture_Reduction(int value, int min_dim=1)
static int Get_Render_Device(void)
static int Get_Collision_Box_Display_Mask(void)
static void Enable_Sorting(bool onoff)
static void Start_Movie_Capture(const char *filename_base="Movie", float frame_rate=15)
static void _Invalidate_Mesh_Cache()
static void Capture_Next_Movie_Frame()
static void Make_Screen_Shot(const char *filename="ScreenShot", const float gamma=1.3f, const ScreenShotFormatEnum format=TGA)
static void Reset_Current_Static_Sort_Lists_To_Default(void)
static long Get_Ext_Swap_Interval(void)
static unsigned int Get_Last_Frame_Vertex_Count(void)
NPatchesGapFillingModeEnum
static void Set_NPatches_Gap_Filling_Mode(NPatchesGapFillingModeEnum mode)
static void Set_NPatches_Level(unsigned level)
static void Stop_Movie_Capture(void)
static unsigned int Get_Last_Frame_Poly_Count(void)
static void Override_Current_Static_Sort_Lists(StaticSortListClass *sort_list)
static ShaderClass Peek_Default_Debug_Shader(void)
static void Get_Pixel_Center(float &x, float &y)
static void Set_Collision_Box_Display_Mask(int mask)
static void Get_Render_Target_Resolution(int &set_w, int &set_h, int &get_bits, bool &get_windowed)
static WW3DErrorType Set_Next_Render_Device(void)
static int Get_Free_Count()
static int Get_Allocate_Count()
static void Reset_Counters()
DX8MeshRendererClass TheDX8MeshRenderer
WWINLINE void DX8_ErrorCode(unsigned res)
RawFileFactoryClass * _TheWritingFileFactory
FileFactoryClass * _TheFileFactory
List< LayerClass * > LayerListClass
#define REF_PTR_RELEASE(x)
@ WW3D_ERROR_INITIALIZATION_FAILED
#define LIGHTMAP_DEBUG_SHADER_BITS
const char * DAZZLE_INI_FILENAME
#define DEFAULT_DEBUG_SHADER_BITS
#define WWMEMLOG(category)