dx8wrapper.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : ww3d *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/dx8wrapper.h $*
  25. * *
  26. * Original Author:: Jani Penttinen *
  27. * *
  28. * $Author:: Vss_sync $*
  29. * *
  30. * $Modtime:: 8/29/01 7:29p $*
  31. * *
  32. * $Revision:: 76 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef DX8_WRAPPER_H
  41. #define DX8_WRAPPER_H
  42. #include "always.h"
  43. #include "dllist.h"
  44. #include "d3d8.h"
  45. #include "matrix4.h"
  46. #include "statistics.h"
  47. #include "wwstring.h"
  48. #include "lightenvironment.h"
  49. #include "shader.h"
  50. #include "vector4.h"
  51. #include "cpudetect.h"
  52. #include "texture.h"
  53. #include "dx8vertexbuffer.h"
  54. #include "dx8indexbuffer.h"
  55. #include "vertmaterial.h"
  56. const unsigned MAX_TEXTURE_STAGES=2;
  57. enum {
  58. BUFFER_TYPE_DX8,
  59. BUFFER_TYPE_SORTING,
  60. BUFFER_TYPE_DYNAMIC_DX8,
  61. BUFFER_TYPE_DYNAMIC_SORTING,
  62. BUFFER_TYPE_INVALID
  63. };
  64. class VertexMaterialClass;
  65. class CameraClass;
  66. class LightEnvironmentClass;
  67. class RenderDeviceDescClass;
  68. class VertexBufferClass;
  69. class DynamicVBAccessClass;
  70. class IndexBufferClass;
  71. class DynamicIBAccessClass;
  72. class TextureClass;
  73. class LightClass;
  74. class SurfaceClass;
  75. #define DX8_RECORD_MATRIX_CHANGE() matrix_changes++
  76. #define DX8_RECORD_MATERIAL_CHANGE() material_changes++
  77. #define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++
  78. #define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++
  79. #define DX8_RECORD_LIGHT_CHANGE() light_changes++
  80. #define DX8_RECORD_TEXTURE_CHANGE() texture_changes++
  81. #define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++
  82. #define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++
  83. extern unsigned number_of_DX8_calls;
  84. extern bool _DX8SingleThreaded;
  85. void DX8_Assert();
  86. void Log_DX8_ErrorCode(unsigned res);
  87. WWINLINE void DX8_ErrorCode(unsigned res)
  88. {
  89. if (res==D3D_OK) return;
  90. Log_DX8_ErrorCode(res);
  91. }
  92. #ifdef WWDEBUG
  93. #define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++;
  94. #define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++;
  95. #define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++;
  96. #define DX8_THREAD_ASSERT() if (_DX8SingleThreaded) { WWASSERT_PRINT(DX8Wrapper::_Get_Main_Thread_ID()==ThreadClass::_Get_Current_Thread_ID(),"DX8Wrapper::DX8 calls must be called from the main thread!"); }
  97. #else
  98. #define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
  99. #define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
  100. #define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++;
  101. #define DX8_THREAD_ASSERT() ;
  102. #endif
  103. #define no_EXTENDED_STATS
  104. // EXTENDED_STATS collects additional timing statistics by turning off parts
  105. // of the 3D drawing system (terrain, objects, etc.)
  106. #ifdef EXTENDED_STATS
  107. class DX8_Stats
  108. {
  109. public:
  110. bool m_showingStats;
  111. bool m_disableTerrain;
  112. bool m_disableWater;
  113. bool m_disableObjects;
  114. bool m_disableOverhead;
  115. bool m_disableConsole;
  116. int m_debugLinesToShow;
  117. int m_sleepTime;
  118. public:
  119. DX8_Stats::DX8_Stats(void) {
  120. m_disableConsole = m_showingStats = m_disableTerrain = m_disableWater = m_disableOverhead = m_disableObjects = false;
  121. m_sleepTime = 0;
  122. m_debugLinesToShow = -1; // -1 means show all expected lines of output
  123. }
  124. };
  125. #endif
  126. // This virtual interface was added for the Generals RTS.
  127. // It is called before resetting the dx8 device to ensure
  128. // that all dx8 resources are released. Otherwise reset fails. jba.
  129. class DX8_CleanupHook
  130. {
  131. public:
  132. virtual void ReleaseResources(void)=0;
  133. virtual void ReAcquireResources(void)=0;
  134. };
  135. struct RenderStateStruct
  136. {
  137. ShaderClass shader;
  138. VertexMaterialClass* material;
  139. TextureClass * Textures[MAX_TEXTURE_STAGES];
  140. D3DLIGHT8 Lights[4];
  141. bool LightEnable[4];
  142. Matrix4 world;
  143. Matrix4 view;
  144. unsigned vertex_buffer_type;
  145. unsigned index_buffer_type;
  146. unsigned short vba_offset;
  147. unsigned short vba_count;
  148. unsigned short iba_offset;
  149. VertexBufferClass* vertex_buffer;
  150. IndexBufferClass* index_buffer;
  151. unsigned short index_base_offset;
  152. RenderStateStruct();
  153. ~RenderStateStruct();
  154. RenderStateStruct& operator= (const RenderStateStruct& src);
  155. };
  156. /**
  157. ** DX8Wrapper
  158. **
  159. ** DX8 interface wrapper class. This encapsulates the DX8 interface; adding redundant state
  160. ** detection, stat tracking, etc etc. In general, we will wrap all DX8 calls with at least
  161. ** an WWINLINE function so that we can add stat tracking, etc if needed. Direct access to the
  162. ** D3D device will require "friend" status and should be granted only in extreme circumstances :-)
  163. */
  164. class DX8Wrapper
  165. {
  166. enum ChangedStates {
  167. WORLD_CHANGED = 1<<0,
  168. VIEW_CHANGED = 1<<1,
  169. LIGHT0_CHANGED = 1<<2,
  170. LIGHT1_CHANGED = 1<<3,
  171. LIGHT2_CHANGED = 1<<4,
  172. LIGHT3_CHANGED = 1<<5,
  173. TEXTURE0_CHANGED= 1<<6,
  174. TEXTURE1_CHANGED= 1<<7,
  175. TEXTURE2_CHANGED= 1<<8,
  176. TEXTURE3_CHANGED= 1<<9,
  177. MATERIAL_CHANGED= 1<<14,
  178. SHADER_CHANGED = 1<<15,
  179. VERTEX_BUFFER_CHANGED = 1<<16,
  180. INDEX_BUFFER_CHANGED = 1 << 17,
  181. WORLD_IDENTITY= 1<<18,
  182. VIEW_IDENTITY= 1<<19,
  183. TEXTURES_CHANGED=
  184. TEXTURE0_CHANGED|TEXTURE1_CHANGED|TEXTURE2_CHANGED|TEXTURE3_CHANGED,
  185. LIGHTS_CHANGED=
  186. LIGHT0_CHANGED|LIGHT1_CHANGED|LIGHT2_CHANGED|LIGHT3_CHANGED,
  187. };
  188. static void Draw_Sorting_IB_VB(
  189. unsigned primitive_type,
  190. unsigned short start_index,
  191. unsigned short polygon_count,
  192. unsigned short min_vertex_index,
  193. unsigned short vertex_count);
  194. static void Draw(
  195. unsigned primitive_type,
  196. unsigned short start_index,
  197. unsigned short polygon_count,
  198. unsigned short min_vertex_index=0,
  199. unsigned short vertex_count=0);
  200. public:
  201. #ifdef EXTENDED_STATS
  202. static DX8_Stats stats;
  203. #endif
  204. static bool Init(void * hwnd);
  205. static void Shutdown(void);
  206. static void SetCleanupHook(DX8_CleanupHook *pCleanupHook) {m_pCleanupHook = pCleanupHook;};
  207. /*
  208. ** Some WW3D sub-systems need to be initialized after the device is created and shutdown
  209. ** before the device is released.
  210. */
  211. static void Do_Onetime_Device_Dependent_Inits(void);
  212. static void Do_Onetime_Device_Dependent_Shutdowns(void);
  213. static bool Has_Stencil (void);
  214. static void Get_Format_Name(unsigned int format, StringClass *tex_format);
  215. /*
  216. ** Rendering
  217. */
  218. static void Begin_Scene(void);
  219. static void End_Scene(bool flip_frame = true);
  220. // Flip until the primary buffer is visible.
  221. static void Flip_To_Primary(void);
  222. 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);
  223. static void Set_Viewport(CONST D3DVIEWPORT8* pViewport);
  224. static void Set_Vertex_Buffer(const VertexBufferClass* vb);
  225. static void Set_Vertex_Buffer(const DynamicVBAccessClass& vba);
  226. static void Set_Index_Buffer(const IndexBufferClass* ib,unsigned short index_base_offset);
  227. static void Set_Index_Buffer(const DynamicIBAccessClass& iba,unsigned short index_base_offset);
  228. static void Set_Index_Buffer_Index_Offset(unsigned offset);
  229. static void Get_Render_State(RenderStateStruct& state);
  230. static void Set_Render_State(const RenderStateStruct& state);
  231. static void Release_Render_State();
  232. static void Set_DX8_Material(const D3DMATERIAL8* mat);
  233. static void Set_Gamma(float gamma,float bright,float contrast,bool calibrate=true,bool uselimit=true);
  234. // Set_ and Get_Transform() functions take the matrix in Westwood convention format.
  235. static void Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4& m);
  236. static void Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m);
  237. static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4& m);
  238. static void Set_World_Identity();
  239. static void Set_View_Identity();
  240. static bool Is_World_Identity();
  241. static bool Is_View_Identity();
  242. // Note that *_DX8_Transform() functions take the matrix in DX8 format - transposed from Westwood convention.
  243. static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4& m);
  244. static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m);
  245. static void _Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4& m);
  246. static void Set_DX8_Light(int index,D3DLIGHT8* light);
  247. static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value);
  248. static void Set_DX8_Clip_Plane(DWORD Index, CONST float* pPlane);
  249. static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value);
  250. static void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture);
  251. static void Set_Light_Environment(LightEnvironmentClass* light_env);
  252. static void Set_Fog(bool enable, const Vector3 &color, float start, float end);
  253. static WWINLINE const D3DLIGHT8& Peek_Light(unsigned index);
  254. static WWINLINE bool Is_Light_Enabled(unsigned index);
  255. static bool Validate_Device(void);
  256. // Deferred
  257. static void Set_Shader(const ShaderClass& shader);
  258. static void Get_Shader(ShaderClass& shader);
  259. static void Set_Texture(unsigned stage,TextureClass* texture);
  260. static void Set_Material(const VertexMaterialClass* material);
  261. static void Set_Light(unsigned index,const D3DLIGHT8* light);
  262. static void Set_Light(unsigned index,const LightClass &light);
  263. static void Apply_Render_State_Changes(); // Apply deferred render state changes (will be called automatically by Draw...)
  264. static void Draw_Triangles(
  265. unsigned buffer_type,
  266. unsigned short start_index,
  267. unsigned short polygon_count,
  268. unsigned short min_vertex_index,
  269. unsigned short vertex_count);
  270. static void Draw_Triangles(
  271. unsigned short start_index,
  272. unsigned short polygon_count,
  273. unsigned short min_vertex_index,
  274. unsigned short vertex_count);
  275. static void Draw_Strip(
  276. unsigned short start_index,
  277. unsigned short index_count,
  278. unsigned short min_vertex_index,
  279. unsigned short vertex_count);
  280. /*
  281. ** Resources
  282. */
  283. static IDirect3DTexture8 * _Create_DX8_Texture(
  284. unsigned int width,
  285. unsigned int height,
  286. WW3DFormat format,
  287. TextureClass::MipCountType mip_level_count,
  288. D3DPOOL pool=D3DPOOL_MANAGED,
  289. bool rendertarget=false);
  290. static IDirect3DTexture8 * _Create_DX8_Texture(const char *filename, TextureClass::MipCountType mip_level_count);
  291. static IDirect3DTexture8 * _Create_DX8_Texture(IDirect3DSurface8 *surface, TextureClass::MipCountType mip_level_count);
  292. static IDirect3DSurface8 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format);
  293. static IDirect3DSurface8 * _Create_DX8_Surface(const char *filename);
  294. static IDirect3DSurface8 * _Get_DX8_Front_Buffer();
  295. static SurfaceClass * _Get_DX8_Back_Buffer(unsigned int num=0);
  296. static void _Copy_DX8_Rects(
  297. IDirect3DSurface8* pSourceSurface,
  298. CONST RECT* pSourceRectsArray,
  299. UINT cRects,
  300. IDirect3DSurface8* pDestinationSurface,
  301. CONST POINT* pDestPointsArray
  302. );
  303. static void _Update_Texture(TextureClass *system, TextureClass *video);
  304. static void Flush_DX8_Resource_Manager(unsigned int bytes=0);
  305. static unsigned int Get_Free_Texture_RAM();
  306. static unsigned _Get_Main_Thread_ID() { return _MainThreadID; }
  307. static const D3DADAPTER_IDENTIFIER8& Get_Current_Adapter_Identifier() { return CurrentAdapterIdentifier; }
  308. /*
  309. ** Statistics
  310. */
  311. static void Begin_Statistics();
  312. static void End_Statistics();
  313. static unsigned Get_Last_Frame_Matrix_Changes();
  314. static unsigned Get_Last_Frame_Material_Changes();
  315. static unsigned Get_Last_Frame_Vertex_Buffer_Changes();
  316. static unsigned Get_Last_Frame_Index_Buffer_Changes();
  317. static unsigned Get_Last_Frame_Light_Changes();
  318. static unsigned Get_Last_Frame_Texture_Changes();
  319. static unsigned Get_Last_Frame_Render_State_Changes();
  320. static unsigned Get_Last_Frame_Texture_Stage_State_Changes();
  321. static unsigned Get_Last_Frame_DX8_Calls();
  322. static unsigned long Get_FrameCount(void);
  323. // Needed by shader class
  324. static bool Get_Fog_Enable() { return FogEnable; }
  325. static D3DCOLOR Get_Fog_Color() { return FogColor; }
  326. // Utilities
  327. static Vector4 Convert_Color(unsigned color);
  328. static unsigned int Convert_Color(const Vector4& color);
  329. static unsigned int Convert_Color(const Vector3& color, const float alpha);
  330. static void Clamp_Color(Vector4& color);
  331. static unsigned int Convert_Color_Clamp(const Vector4& color);
  332. static void Set_Alpha (const float alpha, unsigned int &color);
  333. static void _Enable_Triangle_Draw(bool enable) { _EnableTriangleDraw=enable; }
  334. static bool _Is_Triangle_Draw_Enabled() { return _EnableTriangleDraw; }
  335. /*
  336. ** Additional swap chain interface
  337. **
  338. ** Use this interface to render to multiple windows (in windowed mode).
  339. ** To render to an additional window, the sequence of calls should look
  340. ** something like this:
  341. **
  342. ** DX8Wrapper::Set_Render_Target (swap_chain_ptr);
  343. **
  344. ** WW3D::Begin_Render (true, true, Vector3 (0, 0, 0));
  345. ** WW3D::Render (scene, camera, FALSE, FALSE);
  346. ** WW3D::End_Render ();
  347. **
  348. ** swap_chain_ptr->Present (NULL, NULL, NULL, NULL);
  349. **
  350. ** DX8Wrapper::Set_Render_Target ((IDirect3DSurface8 *)NULL);
  351. **
  352. */
  353. static IDirect3DSwapChain8 * Create_Additional_Swap_Chain (HWND render_window);
  354. /*
  355. ** Render target interface
  356. */
  357. static TextureClass * Create_Render_Target (int width, int height, bool alpha=false);
  358. static void Set_Render_Target (TextureClass * texture);
  359. static void Set_Render_Target (IDirect3DSurface8 *render_target);
  360. static void Set_Render_Target (IDirect3DSwapChain8 *swap_chain);
  361. static IDirect3DDevice8* _Get_D3D_Device8() { return D3DDevice; }
  362. static IDirect3D8* _Get_D3D8() { return D3DInterface; }
  363. static void Invalidate_Cached_Render_States(void);
  364. /// Returns the display format - added by TR for video playback - not part of W3D
  365. static WW3DFormat getBackBufferFormat( void );
  366. static bool Reset_Device(bool reload_assets=true);
  367. protected:
  368. static bool Create_Device(void);
  369. static void Release_Device(void);
  370. static void Reset_Statistics();
  371. static void Enumerate_Devices();
  372. static void Set_Default_Global_Render_States(void);
  373. /*
  374. ** Device Selection Code.
  375. ** For backward compatibility, the public interface for these functions is in the ww3d.
  376. ** header file. These functions are protected so that we aren't exposing two interfaces.
  377. */
  378. static bool Set_Any_Render_Device(void);
  379. 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);
  380. static bool 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);
  381. static bool Set_Next_Render_Device(void);
  382. static bool Toggle_Windowed(void);
  383. static int Get_Render_Device_Count(void);
  384. static int Get_Render_Device(void);
  385. static const RenderDeviceDescClass & Get_Render_Device_Desc(int deviceidx);
  386. static const char * Get_Render_Device_Name(int device_index);
  387. static bool Set_Device_Resolution(int width=-1,int height=-1,int bits=-1,int windowed=-1, bool resize_window=false);
  388. static void Get_Device_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed);
  389. static void Get_Render_Target_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed);
  390. static int Get_Device_Resolution_Width(void) { return ResolutionWidth; }
  391. static int Get_Device_Resolution_Height(void) { return ResolutionHeight; }
  392. static bool Registry_Save_Render_Device( const char * sub_key );
  393. static bool Registry_Save_Render_Device( const char *sub_key, int device, int width, int height, int depth, bool windowed, int texture_depth);
  394. static bool Registry_Load_Render_Device( const char * sub_key, bool resize_window );
  395. static bool Registry_Load_Render_Device( const char * sub_key, char *device, int device_len, int &width, int &height, int &depth, int &windowed, int &texture_depth);
  396. static bool Is_Windowed(void) { return IsWindowed; }
  397. static void Set_Texture_Bitdepth(int depth) { WWASSERT(depth==16 || depth==32); TextureBitDepth = depth; }
  398. static int Get_Texture_Bitdepth(void) { return TextureBitDepth; }
  399. static void Set_Swap_Interval(int swap);
  400. static int Get_Swap_Interval(void);
  401. static void Set_Polygon_Mode(int mode);
  402. /*
  403. ** Internal functions
  404. */
  405. static bool Find_Color_And_Z_Mode(int resx,int resy,int bitdepth,D3DFORMAT * set_colorbuffer,D3DFORMAT * set_backbuffer, D3DFORMAT * set_zmode);
  406. static bool Find_Color_Mode(D3DFORMAT colorbuffer, int resx, int resy, UINT *mode);
  407. static bool Find_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORMAT *zmode);
  408. static bool Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORMAT zmode);
  409. static void Compute_Caps(D3DFORMAT display_format,D3DFORMAT depth_stencil_format);
  410. /*
  411. ** Protected Member Variables
  412. */
  413. static DX8_CleanupHook *m_pCleanupHook;
  414. static RenderStateStruct render_state;
  415. static unsigned render_state_changed;
  416. static bool IsInitted;
  417. static void * Hwnd;
  418. static unsigned _MainThreadID;
  419. static bool _EnableTriangleDraw;
  420. static int CurRenderDevice;
  421. static int ResolutionWidth;
  422. static int ResolutionHeight;
  423. static int BitDepth;
  424. static int TextureBitDepth;
  425. static bool IsWindowed;
  426. static D3DFORMAT DisplayFormat;
  427. static D3DMATRIX old_world;
  428. static D3DMATRIX old_view;
  429. static D3DMATRIX old_prj;
  430. static bool world_identity;
  431. static unsigned RenderStates[256];
  432. static unsigned TextureStageStates[MAX_TEXTURE_STAGES][32];
  433. static IDirect3DBaseTexture8 * Textures[MAX_TEXTURE_STAGES];
  434. // These fog settings are constant for all objects in a given scene,
  435. // unlike the matching renderstates which vary based on shader settings.
  436. static bool FogEnable;
  437. static D3DCOLOR FogColor;
  438. static unsigned matrix_changes;
  439. static unsigned material_changes;
  440. static unsigned vertex_buffer_changes;
  441. static unsigned index_buffer_changes;
  442. static unsigned light_changes;
  443. static unsigned texture_changes;
  444. static unsigned render_state_changes;
  445. static unsigned texture_stage_state_changes;
  446. static bool CurrentDX8LightEnables[4];
  447. static unsigned long FrameCount;
  448. static D3DADAPTER_IDENTIFIER8 CurrentAdapterIdentifier;
  449. static IDirect3D8 * D3DInterface; //d3d8;
  450. static IDirect3DDevice8 * D3DDevice; //d3ddevice8;
  451. static IDirect3DSurface8 * CurrentRenderTarget;
  452. static IDirect3DSurface8 * DefaultRenderTarget;
  453. friend void DX8_Assert();
  454. friend class WW3D;
  455. friend class DX8IndexBufferClass;
  456. friend class DX8VertexBufferClass;
  457. };
  458. WWINLINE void DX8Wrapper::_Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4& m)
  459. {
  460. SNAPSHOT_SAY(("DX8 - SetTransform\n"));
  461. DX8_RECORD_MATRIX_CHANGE();
  462. DX8CALL(SetTransform(transform,(D3DMATRIX*)&m));
  463. }
  464. WWINLINE void DX8Wrapper::_Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m)
  465. {
  466. SNAPSHOT_SAY(("DX8 - SetTransform\n"));
  467. DX8_RECORD_MATRIX_CHANGE();
  468. DX8CALL(SetTransform(transform,(D3DMATRIX*)&m));
  469. }
  470. WWINLINE void DX8Wrapper::_Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4& m)
  471. {
  472. DX8CALL(GetTransform(transform,(D3DMATRIX*)&m));
  473. }
  474. // ----------------------------------------------------------------------------
  475. //
  476. // Set the index offset for the current index buffer
  477. //
  478. // ----------------------------------------------------------------------------
  479. WWINLINE void DX8Wrapper::Set_Index_Buffer_Index_Offset(unsigned offset)
  480. {
  481. if (render_state.index_base_offset==offset) return;
  482. render_state.index_base_offset=offset;
  483. render_state_changed|=INDEX_BUFFER_CHANGED;
  484. }
  485. // ----------------------------------------------------------------------------
  486. // Set the fog settings. This function should be used, rather than setting the
  487. // appropriate renderstates directly, because the shader sets some of the
  488. // renderstates on a per-mesh / per-pass basis depending on global fog states
  489. // (stored in the wrapper) as well as the shader settings.
  490. // This function should be called rarely - once per scene would be appropriate.
  491. // ----------------------------------------------------------------------------
  492. WWINLINE void DX8Wrapper::Set_Fog(bool enable, const Vector3 &color, float start, float end)
  493. {
  494. // Set global states
  495. FogEnable = enable;
  496. FogColor = Convert_Color(color,0.0f);
  497. // Invalidate the current shader (since the renderstates set by the shader
  498. // depend on the global fog settings as well as the actual shader settings)
  499. ShaderClass::Invalidate();
  500. // Set renderstates which are not affected by the shader
  501. Set_DX8_Render_State(D3DRS_FOGSTART, *(DWORD *)(&start));
  502. Set_DX8_Render_State(D3DRS_FOGEND, *(DWORD *)(&end));
  503. }
  504. // ----------------------------------------------------------------------------
  505. //
  506. // Set vertex buffer to be used in the subsequent render calls. If there was
  507. // a vertex buffer being used earlier, release the reference to it. Passing
  508. // NULL just will release the vertex buffer.
  509. //
  510. // ----------------------------------------------------------------------------
  511. WWINLINE void DX8Wrapper::Set_DX8_Material(const D3DMATERIAL8* mat)
  512. {
  513. DX8_RECORD_MATERIAL_CHANGE();
  514. WWASSERT(mat);
  515. SNAPSHOT_SAY(("DX8 - SetMaterial\n"));
  516. DX8CALL(SetMaterial(mat));
  517. }
  518. WWINLINE void DX8Wrapper::Set_DX8_Light(int index, D3DLIGHT8* light)
  519. {
  520. if (light) {
  521. DX8_RECORD_LIGHT_CHANGE();
  522. DX8CALL(SetLight(index,light));
  523. DX8CALL(LightEnable(index,TRUE));
  524. CurrentDX8LightEnables[index]=true;
  525. SNAPSHOT_SAY(("DX8 - SetLight\n"));
  526. }
  527. else if (CurrentDX8LightEnables[index]) {
  528. DX8_RECORD_LIGHT_CHANGE();
  529. CurrentDX8LightEnables[index]=false;
  530. DX8CALL(LightEnable(index,FALSE));
  531. SNAPSHOT_SAY(("DX8 - DisableLight\n"));
  532. }
  533. }
  534. WWINLINE void DX8Wrapper::Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
  535. {
  536. // Can't monitor state changes because setShader call to GERD may change the states!
  537. if (RenderStates[state]==value) return;
  538. SNAPSHOT_SAY(("DX8 - SetRenderState(%d,%d)\n",state,value));
  539. RenderStates[state]=value;
  540. DX8CALL(SetRenderState( state, value ));
  541. DX8_RECORD_RENDER_STATE_CHANGE();
  542. }
  543. WWINLINE void DX8Wrapper::Set_DX8_Clip_Plane(DWORD Index, CONST float* pPlane)
  544. {
  545. DX8CALL(SetClipPlane( Index, pPlane ));
  546. }
  547. WWINLINE void DX8Wrapper::Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
  548. {
  549. if (stage >= MAX_TEXTURE_STAGES)
  550. { DX8CALL(SetTextureStageState( stage, state, value ));
  551. return;
  552. }
  553. // Can't monitor state changes because setShader call to GERD may change the states!
  554. if (TextureStageStates[stage][(unsigned int)state]==value) return;
  555. SNAPSHOT_SAY(("DX8 - SetTextureStageState(%d,%d,%d)\n",stage,state,value));
  556. TextureStageStates[stage][(unsigned int)state]=value;
  557. DX8CALL(SetTextureStageState( stage, state, value ));
  558. DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE();
  559. }
  560. WWINLINE void DX8Wrapper::Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture)
  561. {
  562. if (stage >= MAX_TEXTURE_STAGES)
  563. { DX8CALL(SetTexture(stage, texture));
  564. return;
  565. }
  566. if (Textures[stage]==texture) return;
  567. SNAPSHOT_SAY(("DX8 - SetTexture(%x) \n",texture));
  568. if (Textures[stage]) Textures[stage]->Release();
  569. Textures[stage] = texture;
  570. if (Textures[stage]) Textures[stage]->AddRef();
  571. DX8CALL(SetTexture(stage, texture));
  572. DX8_RECORD_TEXTURE_CHANGE();
  573. }
  574. WWINLINE void DX8Wrapper::_Copy_DX8_Rects(
  575. IDirect3DSurface8* pSourceSurface,
  576. CONST RECT* pSourceRectsArray,
  577. UINT cRects,
  578. IDirect3DSurface8* pDestinationSurface,
  579. CONST POINT* pDestPointsArray
  580. )
  581. {
  582. DX8CALL(CopyRects(
  583. pSourceSurface,
  584. pSourceRectsArray,
  585. cRects,
  586. pDestinationSurface,
  587. pDestPointsArray));
  588. }
  589. WWINLINE Vector4 DX8Wrapper::Convert_Color(unsigned color)
  590. {
  591. Vector4 col;
  592. col[3]=((color&0xff000000)>>24)/255.0f;
  593. col[0]=((color&0xff0000)>>16)/255.0f;
  594. col[1]=((color&0xff00)>>8)/255.0f;
  595. col[2]=((color&0xff)>>0)/255.0f;
  596. // col=Vector4(1.0f,1.0f,1.0f,1.0f);
  597. return col;
  598. }
  599. #if 0
  600. WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color, const float alpha)
  601. {
  602. WWASSERT(color.X<=1.0f);
  603. WWASSERT(color.Y<=1.0f);
  604. WWASSERT(color.Z<=1.0f);
  605. WWASSERT(alpha<=1.0f);
  606. WWASSERT(color.X>=0.0f);
  607. WWASSERT(color.Y>=0.0f);
  608. WWASSERT(color.Z>=0.0f);
  609. WWASSERT(alpha>=0.0f);
  610. return D3DCOLOR_COLORVALUE(color.X,color.Y,color.Z,alpha);
  611. }
  612. WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector4& color)
  613. {
  614. WWASSERT(color.X<=1.0f);
  615. WWASSERT(color.Y<=1.0f);
  616. WWASSERT(color.Z<=1.0f);
  617. WWASSERT(color.W<=1.0f);
  618. WWASSERT(color.X>=0.0f);
  619. WWASSERT(color.Y>=0.0f);
  620. WWASSERT(color.Z>=0.0f);
  621. WWASSERT(color.W>=0.0f);
  622. return D3DCOLOR_COLORVALUE(color.X,color.Y,color.Z,color.W);
  623. }
  624. #else
  625. // ----------------------------------------------------------------------------
  626. //
  627. // Convert RGBA color from float vector to 32 bit integer
  628. // Note: Color vector needs to be clamped to [0...1] range!
  629. //
  630. // ----------------------------------------------------------------------------
  631. WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color,float alpha)
  632. {
  633. const float scale = 255.0;
  634. unsigned int col;
  635. // Multiply r, g, b and a components (0.0,...,1.0) by 255 and convert to integer. Or the integer values togerher
  636. // such that 32 bit ingeger has AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB.
  637. __asm
  638. {
  639. sub esp,20 // space for a, r, g and b float plus fpu rounding mode
  640. // Store the fpu rounding mode
  641. fwait
  642. fstcw [esp+16] // store control word to stack
  643. mov eax,[esp+16] // load it to eax
  644. mov edi,eax // take copy
  645. and eax,~(1024|2048) // mask out certain bits
  646. or eax,(1024|2048) // or with precision control value "truncate"
  647. sub edi,eax // did it change?
  648. jz skip // .. if not, skip
  649. mov [esp],eax // .. change control word
  650. fldcw [esp]
  651. skip:
  652. // Convert the color
  653. mov esi,dword ptr color
  654. fld dword ptr[scale]
  655. fld dword ptr[esi] // r
  656. fld dword ptr[esi+4] // g
  657. fld dword ptr[esi+8] // b
  658. fld dword ptr[alpha] // a
  659. fld st(4)
  660. fmul st(4),st
  661. fmul st(3),st
  662. fmul st(2),st
  663. fmulp st(1),st
  664. fistp dword ptr[esp+0] // a
  665. fistp dword ptr[esp+4] // b
  666. fistp dword ptr[esp+8] // g
  667. fistp dword ptr[esp+12] // r
  668. mov ecx,[esp] // a
  669. mov eax,[esp+4] // b
  670. mov edx,[esp+8] // g
  671. mov ebx,[esp+12] // r
  672. shl ecx,24 // a << 24
  673. shl ebx,16 // r << 16
  674. shl edx,8 // g << 8
  675. or eax,ecx // (a << 24) | b
  676. or eax,ebx // (a << 24) | (r << 16) | b
  677. or eax,edx // (a << 24) | (r << 16) | (g << 8) | b
  678. fstp st(0)
  679. // Restore fpu rounding mode
  680. cmp edi,0 // did we change the value?
  681. je not_changed // nope... skip now...
  682. fwait
  683. fldcw [esp+16];
  684. not_changed:
  685. add esp,20
  686. mov col,eax
  687. }
  688. return col;
  689. }
  690. // ----------------------------------------------------------------------------
  691. //
  692. // Clamp color vertor to [0...1] range
  693. //
  694. // ----------------------------------------------------------------------------
  695. WWINLINE void DX8Wrapper::Clamp_Color(Vector4& color)
  696. {
  697. if (!CPUDetectClass::Has_CMOV_Instruction()) {
  698. for (int i=0;i<4;++i) {
  699. float f=(color[i]<0.0f) ? 0.0f : color[i];
  700. color[i]=(f>1.0f) ? 1.0f : f;
  701. }
  702. return;
  703. }
  704. __asm
  705. {
  706. mov esi,dword ptr color
  707. mov edx,0x3f800000
  708. mov edi,dword ptr[esi]
  709. mov ebx,edi
  710. sar edi,31
  711. not edi // mask is now zero if negative value
  712. and edi,ebx
  713. cmp edi,edx // if no less than 1.0 set to 1.0
  714. cmovnb edi,edx
  715. mov dword ptr[esi],edi
  716. mov edi,dword ptr[esi+4]
  717. mov ebx,edi
  718. sar edi,31
  719. not edi // mask is now zero if negative value
  720. and edi,ebx
  721. cmp edi,edx // if no less than 1.0 set to 1.0
  722. cmovnb edi,edx
  723. mov dword ptr[esi+4],edi
  724. mov edi,dword ptr[esi+8]
  725. mov ebx,edi
  726. sar edi,31
  727. not edi // mask is now zero if negative value
  728. and edi,ebx
  729. cmp edi,edx // if no less than 1.0 set to 1.0
  730. cmovnb edi,edx
  731. mov dword ptr[esi+8],edi
  732. mov edi,dword ptr[esi+12]
  733. mov ebx,edi
  734. sar edi,31
  735. not edi // mask is now zero if negative value
  736. and edi,ebx
  737. cmp edi,edx // if no less than 1.0 set to 1.0
  738. cmovnb edi,edx
  739. mov dword ptr[esi+12],edi
  740. }
  741. }
  742. // ----------------------------------------------------------------------------
  743. //
  744. // Convert RGBA color from float vector to 32 bit integer
  745. //
  746. // ----------------------------------------------------------------------------
  747. WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector4& color)
  748. {
  749. return Convert_Color(reinterpret_cast<const Vector3&>(color),color[3]);
  750. }
  751. WWINLINE unsigned int DX8Wrapper::Convert_Color_Clamp(const Vector4& color)
  752. {
  753. Vector4 clamped_color=color;
  754. DX8Wrapper::Clamp_Color(clamped_color);
  755. return Convert_Color(reinterpret_cast<const Vector3&>(clamped_color),clamped_color[3]);
  756. }
  757. #endif
  758. WWINLINE void DX8Wrapper::Set_Alpha (const float alpha, unsigned int &color)
  759. {
  760. unsigned char *component = (unsigned char*) &color;
  761. component [3] = 255.0f * alpha;
  762. }
  763. WWINLINE void DX8Wrapper::Get_Render_State(RenderStateStruct& state)
  764. {
  765. state=render_state;
  766. }
  767. WWINLINE void DX8Wrapper::Get_Shader(ShaderClass& shader)
  768. {
  769. shader=render_state.shader;
  770. }
  771. WWINLINE void DX8Wrapper::Set_Texture(unsigned stage,TextureClass* texture)
  772. {
  773. WWASSERT(stage<MAX_TEXTURE_STAGES);
  774. if (texture==render_state.Textures[stage]) return;
  775. REF_PTR_SET(render_state.Textures[stage],texture);
  776. render_state_changed|=(TEXTURE0_CHANGED<<stage);
  777. }
  778. WWINLINE void DX8Wrapper::Set_Material(const VertexMaterialClass* material)
  779. {
  780. if (material==render_state.material) return;
  781. REF_PTR_SET(render_state.material,const_cast<VertexMaterialClass*>(material));
  782. render_state_changed|=MATERIAL_CHANGED;
  783. }
  784. WWINLINE void DX8Wrapper::Set_Shader(const ShaderClass& shader)
  785. {
  786. if (!ShaderClass::ShaderDirty && ((unsigned&)shader==(unsigned&)render_state.shader)) return;
  787. render_state.shader=shader;
  788. render_state_changed|=SHADER_CHANGED;
  789. }
  790. WWINLINE void DX8Wrapper::Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4& m)
  791. {
  792. switch ((int)transform) {
  793. case D3DTS_WORLD:
  794. render_state.world=m.Transpose();
  795. render_state_changed|=(unsigned)WORLD_CHANGED;
  796. render_state_changed&=~(unsigned)WORLD_IDENTITY;
  797. break;
  798. case D3DTS_VIEW:
  799. render_state.view=m.Transpose();
  800. render_state_changed|=(unsigned)VIEW_CHANGED;
  801. render_state_changed&=~(unsigned)VIEW_IDENTITY;
  802. break;
  803. default:
  804. DX8_RECORD_MATRIX_CHANGE();
  805. Matrix4 m2=m.Transpose();
  806. DX8CALL(SetTransform(transform,(D3DMATRIX*)&m2));
  807. break;
  808. }
  809. }
  810. WWINLINE void DX8Wrapper::Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m)
  811. {
  812. Matrix4 m2(m);
  813. switch ((int)transform) {
  814. case D3DTS_WORLD:
  815. render_state.world=m2.Transpose();
  816. render_state_changed|=(unsigned)WORLD_CHANGED;
  817. render_state_changed&=~(unsigned)WORLD_IDENTITY;
  818. break;
  819. case D3DTS_VIEW:
  820. render_state.view=m2.Transpose();
  821. render_state_changed|=(unsigned)VIEW_CHANGED;
  822. render_state_changed&=~(unsigned)VIEW_IDENTITY;
  823. break;
  824. default:
  825. DX8_RECORD_MATRIX_CHANGE();
  826. m2=m2.Transpose();
  827. DX8CALL(SetTransform(transform,(D3DMATRIX*)&m2));
  828. break;
  829. }
  830. }
  831. WWINLINE void DX8Wrapper::Set_World_Identity()
  832. {
  833. if (render_state_changed&(unsigned)WORLD_IDENTITY) return;
  834. render_state.world.Make_Identity();
  835. render_state_changed|=(unsigned)WORLD_CHANGED|(unsigned)WORLD_IDENTITY;
  836. }
  837. WWINLINE void DX8Wrapper::Set_View_Identity()
  838. {
  839. if (render_state_changed&(unsigned)VIEW_IDENTITY) return;
  840. render_state.view.Make_Identity();
  841. render_state_changed|=(unsigned)VIEW_CHANGED|(unsigned)VIEW_IDENTITY;
  842. }
  843. WWINLINE bool DX8Wrapper::Is_World_Identity()
  844. {
  845. return !!(render_state_changed&(unsigned)WORLD_IDENTITY);
  846. }
  847. WWINLINE bool DX8Wrapper::Is_View_Identity()
  848. {
  849. return !!(render_state_changed&(unsigned)VIEW_IDENTITY);
  850. }
  851. WWINLINE void DX8Wrapper::Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4& m)
  852. {
  853. D3DMATRIX mat;
  854. switch ((int)transform) {
  855. case D3DTS_WORLD:
  856. if (render_state_changed&WORLD_IDENTITY) m.Make_Identity();
  857. else m=render_state.world.Transpose();
  858. break;
  859. case D3DTS_VIEW:
  860. if (render_state_changed&VIEW_IDENTITY) m.Make_Identity();
  861. else m=render_state.view.Transpose();
  862. break;
  863. default:
  864. DX8CALL(GetTransform(transform,&mat));
  865. m=*(Matrix4*)&mat;
  866. m=m.Transpose();
  867. break;
  868. }
  869. }
  870. WWINLINE void DX8Wrapper::Set_Light(unsigned index, const D3DLIGHT8* light)
  871. {
  872. if (light) {
  873. render_state.Lights[index]=*light;
  874. render_state.LightEnable[index]=true;
  875. }
  876. else {
  877. render_state.LightEnable[index]=false;
  878. }
  879. render_state_changed|=(LIGHT0_CHANGED<<index);
  880. }
  881. WWINLINE const D3DLIGHT8& DX8Wrapper::Peek_Light(unsigned index)
  882. {
  883. return render_state.Lights[index];;
  884. }
  885. WWINLINE bool DX8Wrapper::Is_Light_Enabled(unsigned index)
  886. {
  887. return render_state.LightEnable[index];
  888. }
  889. WWINLINE void DX8Wrapper::Set_Render_State(const RenderStateStruct& state)
  890. {
  891. if (render_state.index_buffer) {
  892. render_state.index_buffer->Release_Engine_Ref();
  893. }
  894. if (render_state.vertex_buffer) {
  895. render_state.vertex_buffer->Release_Engine_Ref();
  896. }
  897. render_state=state;
  898. render_state_changed=0xffffffff;
  899. if (render_state.index_buffer) {
  900. render_state.index_buffer->Add_Engine_Ref();
  901. }
  902. if (render_state.vertex_buffer) {
  903. render_state.vertex_buffer->Add_Engine_Ref();
  904. }
  905. }
  906. WWINLINE void DX8Wrapper::Release_Render_State()
  907. {
  908. if (render_state.index_buffer) {
  909. render_state.index_buffer->Release_Engine_Ref();
  910. }
  911. if (render_state.vertex_buffer) {
  912. render_state.vertex_buffer->Release_Engine_Ref();
  913. }
  914. REF_PTR_RELEASE(render_state.vertex_buffer);
  915. REF_PTR_RELEASE(render_state.index_buffer);
  916. REF_PTR_RELEASE(render_state.material);
  917. for (unsigned i=0;i<MAX_TEXTURE_STAGES;++i) REF_PTR_RELEASE(render_state.Textures[i]);
  918. }
  919. WWINLINE RenderStateStruct::RenderStateStruct()
  920. :
  921. material(0),
  922. vertex_buffer(0),
  923. index_buffer(0)
  924. {
  925. for (unsigned i=0;i<MAX_TEXTURE_STAGES;++i) Textures[i]=0;
  926. }
  927. WWINLINE RenderStateStruct::~RenderStateStruct()
  928. {
  929. REF_PTR_RELEASE(material);
  930. REF_PTR_RELEASE(vertex_buffer);
  931. REF_PTR_RELEASE(index_buffer);
  932. for (unsigned i=0;i<MAX_TEXTURE_STAGES;++i) REF_PTR_RELEASE(Textures[i]);
  933. }
  934. WWINLINE RenderStateStruct& RenderStateStruct::operator= (const RenderStateStruct& src)
  935. {
  936. REF_PTR_SET(material,src.material);
  937. REF_PTR_SET(vertex_buffer,src.vertex_buffer);
  938. REF_PTR_SET(index_buffer,src.index_buffer);
  939. for (unsigned i=0;i<MAX_TEXTURE_STAGES;++i) REF_PTR_SET(Textures[i],src.Textures[i]);
  940. LightEnable[0]=src.LightEnable[0];
  941. LightEnable[1]=src.LightEnable[1];
  942. LightEnable[2]=src.LightEnable[2];
  943. LightEnable[3]=src.LightEnable[3];
  944. if (LightEnable[0]) {
  945. Lights[0]=src.Lights[0];
  946. if (LightEnable[1]) {
  947. Lights[1]=src.Lights[1];
  948. if (LightEnable[2]) {
  949. Lights[2]=src.Lights[2];
  950. if (LightEnable[3]) {
  951. Lights[3]=src.Lights[3];
  952. }
  953. }
  954. }
  955. }
  956. shader=src.shader;
  957. world=src.world;
  958. view=src.view;
  959. vertex_buffer_type=src.vertex_buffer_type;
  960. index_buffer_type=src.index_buffer_type;
  961. vba_offset=src.vba_offset;
  962. vba_count=src.vba_count;
  963. iba_offset=src.iba_offset;
  964. index_base_offset=src.index_base_offset;
  965. return *this;
  966. }
  967. #endif