Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dx8wrapper.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***********************************************************************************************
20 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : ww3d *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/dx8wrapper.h $*
26 * *
27 * Original Author:: Jani Penttinen *
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 08/05/02 2:40p $*
32 * *
33 * $Revision:: 92 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 * 06/27/02 KM Render to shadow buffer texture support *
37 * 08/05/02 KM Texture class redesign
38 *---------------------------------------------------------------------------------------------*
39 * Functions: *
40 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41
42#if defined(_MSC_VER)
43#pragma once
44#endif
45
46#ifndef DX8_WRAPPER_H
47#define DX8_WRAPPER_H
48
49#include "always.h"
50#include "dllist.h"
51#include "d3d8.h"
52#include "matrix4.h"
53#include "statistics.h"
54#include "wwstring.h"
55#include "lightenvironment.h"
56#include "shader.h"
57#include "vector4.h"
58#include "cpudetect.h"
59#include "dx8caps.h"
60
61#include "texture.h"
62#include "dx8vertexbuffer.h"
63#include "dx8indexbuffer.h"
64#include "vertmaterial.h"
65
66/*
67** Registry value names
68*/
69#define VALUE_NAME_RENDER_DEVICE_NAME "RenderDeviceName"
70#define VALUE_NAME_RENDER_DEVICE_WIDTH "RenderDeviceWidth"
71#define VALUE_NAME_RENDER_DEVICE_HEIGHT "RenderDeviceHeight"
72#define VALUE_NAME_RENDER_DEVICE_DEPTH "RenderDeviceDepth"
73#define VALUE_NAME_RENDER_DEVICE_WINDOWED "RenderDeviceWindowed"
74#define VALUE_NAME_RENDER_DEVICE_TEXTURE_DEPTH "RenderDeviceTextureDepth"
75
76const unsigned MAX_TEXTURE_STAGES=8;
77const unsigned MAX_VERTEX_STREAMS=2;
80const unsigned MAX_SHADOW_MAPS=1;
81
82#define prevVer
83#define nextVer
84#define __volatile unsigned
85
86
87enum {
93};
94
96class CameraClass;
101class IndexBufferClass;
103class TextureClass;
104class ZTextureClass;
105class LightClass;
106class SurfaceClass;
107class DX8Caps;
108
109#define DX8_RECORD_MATRIX_CHANGE() matrix_changes++
110#define DX8_RECORD_MATERIAL_CHANGE() material_changes++
111#define DX8_RECORD_VERTEX_BUFFER_CHANGE() vertex_buffer_changes++
112#define DX8_RECORD_INDEX_BUFFER_CHANGE() index_buffer_changes++
113#define DX8_RECORD_LIGHT_CHANGE() light_changes++
114#define DX8_RECORD_TEXTURE_CHANGE() texture_changes++
115#define DX8_RECORD_RENDER_STATE_CHANGE() render_state_changes++
116#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE() texture_stage_state_changes++
117#define DX8_RECORD_DRAW_CALLS() draw_calls++
118
119extern unsigned number_of_DX8_calls;
120extern bool _DX8SingleThreaded;
121
122void DX8_Assert();
123void Log_DX8_ErrorCode(unsigned res);
124
125WWINLINE void DX8_ErrorCode(unsigned res)
126{
127 if (res==D3D_OK) return;
129}
130
131#ifdef WWDEBUG
132#define DX8CALL_HRES(x,res) DX8_Assert(); res = DX8Wrapper::_Get_D3D_Device8()->x; DX8_ErrorCode(res); number_of_DX8_calls++;
133#define DX8CALL(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D_Device8()->x); number_of_DX8_calls++;
134#define DX8CALL_D3D(x) DX8_Assert(); DX8_ErrorCode(DX8Wrapper::_Get_D3D8()->x); number_of_DX8_calls++;
135#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!"); }
136#else
137#define DX8CALL_HRES(x,res) res = DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
138#define DX8CALL(x) DX8Wrapper::_Get_D3D_Device8()->x; number_of_DX8_calls++;
139#define DX8CALL_D3D(x) DX8Wrapper::_Get_D3D8()->x; number_of_DX8_calls++;
140#define DX8_THREAD_ASSERT() ;
141#endif
142
143
144#define no_EXTENDED_STATS
145// EXTENDED_STATS collects additional timing statistics by turning off parts
146// of the 3D drawing system (terrain, objects, etc.)
147#ifdef EXTENDED_STATS
148class DX8_Stats
149{
150public:
151 bool m_showingStats;
152 bool m_disableTerrain;
153 bool m_disableWater;
154 bool m_disableObjects;
155 bool m_disableOverhead;
156 bool m_disableConsole;
157 int m_debugLinesToShow;
158 int m_sleepTime;
159public:
160 DX8_Stats::DX8_Stats(void) {
161 m_disableConsole = m_showingStats = m_disableTerrain = m_disableWater = m_disableOverhead = m_disableObjects = false;
162 m_sleepTime = 0;
163 m_debugLinesToShow = -1; // -1 means show all expected lines of output
164 }
165};
166#endif
167
168
169// This virtual interface was added for the Generals RTS.
170// It is called before resetting the dx8 device to ensure
171// that all dx8 resources are released. Otherwise reset fails. jba.
173{
174public:
175 virtual void ReleaseResources(void)=0;
176 virtual void ReAcquireResources(void)=0;
177};
178
179
204
214{
215 enum ChangedStates {
216 WORLD_CHANGED = 1<<0,
217 VIEW_CHANGED = 1<<1,
218 LIGHT0_CHANGED = 1<<2,
219 LIGHT1_CHANGED = 1<<3,
220 LIGHT2_CHANGED = 1<<4,
221 LIGHT3_CHANGED = 1<<5,
222 TEXTURE0_CHANGED= 1<<6,
223 TEXTURE1_CHANGED= 1<<7,
224 TEXTURE2_CHANGED= 1<<8,
225 TEXTURE3_CHANGED= 1<<9,
226 MATERIAL_CHANGED= 1<<14,
227 SHADER_CHANGED = 1<<15,
228 VERTEX_BUFFER_CHANGED = 1<<16,
229 INDEX_BUFFER_CHANGED = 1 << 17,
230 WORLD_IDENTITY= 1<<18,
231 VIEW_IDENTITY= 1<<19,
232
233 TEXTURES_CHANGED=
234 TEXTURE0_CHANGED|TEXTURE1_CHANGED|TEXTURE2_CHANGED|TEXTURE3_CHANGED,
235 LIGHTS_CHANGED=
236 LIGHT0_CHANGED|LIGHT1_CHANGED|LIGHT2_CHANGED|LIGHT3_CHANGED,
237 };
238
239 static void Draw_Sorting_IB_VB(
240 unsigned primitive_type,
241 unsigned short start_index,
242 unsigned short polygon_count,
243 unsigned short min_vertex_index,
244 unsigned short vertex_count);
245
246 static void Draw(
247 unsigned primitive_type,
248 unsigned short start_index,
249 unsigned short polygon_count,
250 unsigned short min_vertex_index=0,
251 unsigned short vertex_count=0);
252
253public:
254#ifdef EXTENDED_STATS
255 static DX8_Stats stats;
256#endif
257
258 static bool Init(void * hwnd, bool lite = false);
259 static void Shutdown(void);
260
261 static void SetCleanupHook(DX8_CleanupHook *pCleanupHook) {m_pCleanupHook = pCleanupHook;};
262 /*
263 ** Some WW3D sub-systems need to be initialized after the device is created and shutdown
264 ** before the device is released.
265 */
266 static void Do_Onetime_Device_Dependent_Inits(void);
268
269 static bool Is_Device_Lost() { return IsDeviceLost; }
270 static bool Is_Initted(void) { return IsInitted; }
271
272 static bool Has_Stencil (void);
273 static void Get_Format_Name(unsigned int format, StringClass *tex_format);
274
275 /*
276 ** Rendering
277 */
278 static void Begin_Scene(void);
279 static void End_Scene(bool flip_frame = true);
280
281 // Flip until the primary buffer is visible.
282 static void Flip_To_Primary(void);
283
284 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);
285
286 static void Set_Viewport(CONST D3DVIEWPORT8* pViewport);
287
288 static void Set_Vertex_Buffer(const VertexBufferClass* vb, unsigned stream=0);
289 static void Set_Vertex_Buffer(const DynamicVBAccessClass& vba);
290 static void Set_Index_Buffer(const IndexBufferClass* ib,unsigned short index_base_offset);
291 static void Set_Index_Buffer(const DynamicIBAccessClass& iba,unsigned short index_base_offset);
292 static void Set_Index_Buffer_Index_Offset(unsigned offset);
293
294 static void Get_Render_State(RenderStateStruct& state);
295 static void Set_Render_State(const RenderStateStruct& state);
296 static void Release_Render_State();
297
298 static void Set_DX8_Material(const D3DMATERIAL8* mat);
299
300 static void Set_Gamma(float gamma,float bright,float contrast,bool calibrate=true,bool uselimit=true);
301
302 // Set_ and Get_Transform() functions take the matrix in Westwood convention format.
303
304 static void Set_DX8_ZBias(int zbias);
305 static void Set_Projection_Transform_With_Z_Bias(const Matrix4x4& matrix,float znear, float zfar); // pointer to 16 matrices
306
307 static void Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4x4& m);
308 static void Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m);
309 static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4& m);
310 static void Set_World_Identity();
311 static void Set_View_Identity();
312 static bool Is_World_Identity();
313 static bool Is_View_Identity();
314
315 // Note that *_DX8_Transform() functions take the matrix in DX8 format - transposed from Westwood convention.
316
317 static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4x4& m);
318 static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m);
319 static void _Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4& m);
320
321 static void Set_DX8_Light(int index,D3DLIGHT8* light);
322 static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value);
323 static void Set_DX8_Clip_Plane(DWORD Index, CONST float* pPlane);
324 static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value);
325 static void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture);
326 static void Set_Light_Environment(LightEnvironmentClass* light_env);
328 static void Set_Fog(bool enable, const Vector3 &color, float start, float end);
329
330 static WWINLINE const D3DLIGHT8& Peek_Light(unsigned index);
331 static WWINLINE bool Is_Light_Enabled(unsigned index);
332
333 static bool Validate_Device(void);
334
335 // Deferred
336
337 static void Set_Shader(const ShaderClass& shader);
338 static void Get_Shader(ShaderClass& shader);
339 static void Set_Texture(unsigned stage,TextureBaseClass* texture);
340 static void Set_Material(const VertexMaterialClass* material);
341 static void Set_Light(unsigned index,const D3DLIGHT8* light);
342 static void Set_Light(unsigned index,const LightClass &light);
343
344 static void Apply_Render_State_Changes(); // Apply deferred render state changes (will be called automatically by Draw...)
345
346 static void Draw_Triangles(
347 unsigned buffer_type,
348 unsigned short start_index,
349 unsigned short polygon_count,
350 unsigned short min_vertex_index,
351 unsigned short vertex_count);
352 static void Draw_Triangles(
353 unsigned short start_index,
354 unsigned short polygon_count,
355 unsigned short min_vertex_index,
356 unsigned short vertex_count);
357 static void Draw_Strip(
358 unsigned short start_index,
359 unsigned short index_count,
360 unsigned short min_vertex_index,
361 unsigned short vertex_count);
362
363 /*
364 ** Resources
365 */
366
367 static IDirect3DVolumeTexture8* _Create_DX8_Volume_Texture
368 (
369 unsigned int width,
370 unsigned int height,
371 unsigned int depth,
372 WW3DFormat format,
373 MipCountType mip_level_count,
374 D3DPOOL pool=D3DPOOL_MANAGED
375 );
376
377 static IDirect3DCubeTexture8* _Create_DX8_Cube_Texture
378 (
379 unsigned int width,
380 unsigned int height,
381 WW3DFormat format,
382 MipCountType mip_level_count,
383 D3DPOOL pool=D3DPOOL_MANAGED,
384 bool rendertarget=false
385 );
386
387
388 static IDirect3DTexture8* _Create_DX8_ZTexture
389 (
390 unsigned int width,
391 unsigned int height,
392 WW3DZFormat zformat,
393 MipCountType mip_level_count,
394 D3DPOOL pool=D3DPOOL_MANAGED
395 );
396
397
398 static IDirect3DTexture8 * _Create_DX8_Texture
399 (
400 unsigned int width,
401 unsigned int height,
402 WW3DFormat format,
403 MipCountType mip_level_count,
404 D3DPOOL pool=D3DPOOL_MANAGED,
405 bool rendertarget=false
406 );
407 static IDirect3DTexture8 * _Create_DX8_Texture(const char *filename, MipCountType mip_level_count);
408 static IDirect3DTexture8 * _Create_DX8_Texture(IDirect3DSurface8 *surface, MipCountType mip_level_count);
409
410 static IDirect3DSurface8 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format);
411 static IDirect3DSurface8 * _Create_DX8_Surface(const char *filename);
412 static IDirect3DSurface8 * _Get_DX8_Front_Buffer();
413 static SurfaceClass * _Get_DX8_Back_Buffer(unsigned int num=0);
414
415 static void _Copy_DX8_Rects(
416 IDirect3DSurface8* pSourceSurface,
417 CONST RECT* pSourceRectsArray,
418 UINT cRects,
419 IDirect3DSurface8* pDestinationSurface,
420 CONST POINT* pDestPointsArray
421 );
422
423 static void _Update_Texture(TextureClass *system, TextureClass *video);
424 static void Flush_DX8_Resource_Manager(unsigned int bytes=0);
425 static unsigned int Get_Free_Texture_RAM();
426
427 static unsigned _Get_Main_Thread_ID() { return _MainThreadID; }
428 static const D3DADAPTER_IDENTIFIER8& Get_Current_Adapter_Identifier() { return CurrentAdapterIdentifier; }
429
430 /*
431 ** Statistics
432 */
433 static void Begin_Statistics();
434 static void End_Statistics();
435 static unsigned Get_Last_Frame_Matrix_Changes();
436 static unsigned Get_Last_Frame_Material_Changes();
437 static unsigned Get_Last_Frame_Vertex_Buffer_Changes();
438 static unsigned Get_Last_Frame_Index_Buffer_Changes();
439 static unsigned Get_Last_Frame_Light_Changes();
440 static unsigned Get_Last_Frame_Texture_Changes();
441 static unsigned Get_Last_Frame_Render_State_Changes();
443 static unsigned Get_Last_Frame_DX8_Calls();
444 static unsigned Get_Last_Frame_Draw_Calls();
445
446 static unsigned long Get_FrameCount(void);
447
448 // Needed by shader class
449 static bool Get_Fog_Enable() { return FogEnable; }
450 static D3DCOLOR Get_Fog_Color() { return FogColor; }
451
452 // Utilities
453 static Vector4 Convert_Color(unsigned color);
454 static unsigned int Convert_Color(const Vector4& color);
455 static unsigned int Convert_Color(const Vector3& color, const float alpha);
456 static void Clamp_Color(Vector4& color);
457 static unsigned int Convert_Color_Clamp(const Vector4& color);
458
459 static void Set_Alpha (const float alpha, unsigned int &color);
460
461 static void _Enable_Triangle_Draw(bool enable) { _EnableTriangleDraw=enable; }
463
464 /*
465 ** Additional swap chain interface
466 **
467 ** Use this interface to render to multiple windows (in windowed mode).
468 ** To render to an additional window, the sequence of calls should look
469 ** something like this:
470 **
471 ** DX8Wrapper::Set_Render_Target (swap_chain_ptr);
472 **
473 ** WW3D::Begin_Render (true, true, Vector3 (0, 0, 0));
474 ** WW3D::Render (scene, camera, FALSE, FALSE);
475 ** WW3D::End_Render ();
476 **
477 ** swap_chain_ptr->Present (NULL, NULL, NULL, NULL);
478 **
479 ** DX8Wrapper::Set_Render_Target ((IDirect3DSurface8 *)NULL);
480 **
481 */
482 static IDirect3DSwapChain8 * Create_Additional_Swap_Chain (HWND render_window);
483
484 /*
485 ** Render target interface. If render target format is WW3D_FORMAT_UNKNOWN, current display format is used.
486 */
487 static TextureClass * Create_Render_Target (int width, int height, WW3DFormat format = WW3D_FORMAT_UNKNOWN);
488
489 static void Set_Render_Target (IDirect3DSurface8 *render_target, bool use_default_depth_buffer = false);
490 static void Set_Render_Target (IDirect3DSurface8* render_target, IDirect3DSurface8* dpeth_buffer);
491
492 static void Set_Render_Target (IDirect3DSwapChain8 *swap_chain);
493 static bool Is_Render_To_Texture(void) { return IsRenderToTexture; }
494
495 // for depth map support KJM V
496 static void Create_Render_Target
497 (
498 int width,
499 int height,
500 WW3DFormat format,
501 WW3DZFormat zformat,
502 TextureClass** target,
503 ZTextureClass** depth_buffer
504 );
505 static void Set_Render_Target_With_Z (TextureClass * texture, ZTextureClass* ztexture=NULL);
506
507 static void Set_Shadow_Map(int idx, ZTextureClass* ztex) { Shadow_Map[idx]=ztex; }
508 static ZTextureClass* Get_Shadow_Map(int idx) { return Shadow_Map[idx]; }
509 // for depth map support KJM ^
510
511 // shader system udpates KJM v
512 static void Apply_Default_State();
513
514 static void Set_Vertex_Shader(DWORD vertex_shader);
515 static void Set_Pixel_Shader(DWORD pixel_shader);
516
517 static void Set_Vertex_Shader_Constant(int reg, const void* data, int count);
518 static void Set_Pixel_Shader_Constant(int reg, const void* data, int count);
519
521
522 // Needed by scene lighting class
523 static void Set_Ambient(const Vector3& color);
524 static const Vector3& Get_Ambient() { return Ambient_Color; }
525 // shader system updates KJM ^
526
527
528
529
530 static IDirect3DDevice8* _Get_D3D_Device8() { return D3DDevice; }
531 static IDirect3D8* _Get_D3D8() { return D3DInterface; }
533 static WW3DFormat getBackBufferFormat( void );
534 static bool Reset_Device(bool reload_assets=true);
535
537
538 static bool Registry_Save_Render_Device( const char * sub_key );
539 static bool Registry_Load_Render_Device( const char * sub_key, bool resize_window );
540
541 static const char* Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state);
542 static const char* Get_DX8_Texture_Stage_State_Name(D3DTEXTURESTAGESTATETYPE state);
543 static unsigned Get_DX8_Render_State(D3DRENDERSTATETYPE state) { return RenderStates[state]; }
544
545 // Names of the specific values of render states and texture stage states
546 static void Get_DX8_Texture_Stage_State_Value_Name(StringClass& name, D3DTEXTURESTAGESTATETYPE state, unsigned value);
547 static void Get_DX8_Render_State_Value_Name(StringClass& name, D3DRENDERSTATETYPE state, unsigned value);
548
549 static const char* Get_DX8_Texture_Address_Name(unsigned value);
550 static const char* Get_DX8_Texture_Filter_Name(unsigned value);
551 static const char* Get_DX8_Texture_Arg_Name(unsigned value);
552 static const char* Get_DX8_Texture_Op_Name(unsigned value);
553 static const char* Get_DX8_Texture_Transform_Flag_Name(unsigned value);
554 static const char* Get_DX8_ZBuffer_Type_Name(unsigned value);
555 static const char* Get_DX8_Fill_Mode_Name(unsigned value);
556 static const char* Get_DX8_Shade_Mode_Name(unsigned value);
557 static const char* Get_DX8_Blend_Name(unsigned value);
558 static const char* Get_DX8_Cull_Mode_Name(unsigned value);
559 static const char* Get_DX8_Cmp_Func_Name(unsigned value);
560 static const char* Get_DX8_Fog_Mode_Name(unsigned value);
561 static const char* Get_DX8_Stencil_Op_Name(unsigned value);
562 static const char* Get_DX8_Material_Source_Name(unsigned value);
563 static const char* Get_DX8_Vertex_Blend_Flag_Name(unsigned value);
564 static const char* Get_DX8_Patch_Edge_Style_Name(unsigned value);
565 static const char* Get_DX8_Debug_Monitor_Token_Name(unsigned value);
566 static const char* Get_DX8_Blend_Op_Name(unsigned value);
567
568 static void Invalidate_Cached_Render_States(void);
569
571
572protected:
573
574 static bool Create_Device(void);
575 static void Release_Device(void);
576
577 static void Reset_Statistics();
578 static void Enumerate_Devices();
579 static void Set_Default_Global_Render_States(void);
580
581 /*
582 ** Device Selection Code.
583 ** For backward compatibility, the public interface for these functions is in the ww3d.
584 ** header file. These functions are protected so that we aren't exposing two interfaces.
585 */
586 static bool Set_Any_Render_Device(void);
587 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);
588 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);
589 static bool Set_Next_Render_Device(void);
590 static bool Toggle_Windowed(void);
591
592 static int Get_Render_Device_Count(void);
593 static int Get_Render_Device(void);
594 static const RenderDeviceDescClass & Get_Render_Device_Desc(int deviceidx);
595 static const char * Get_Render_Device_Name(int device_index);
596 static bool Set_Device_Resolution(int width=-1,int height=-1,int bits=-1,int windowed=-1, bool resize_window=false);
597 static void Get_Device_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed);
598 static void Get_Render_Target_Resolution(int & set_w,int & set_h,int & set_bits,bool & set_windowed);
599 static int Get_Device_Resolution_Width(void) { return ResolutionWidth; }
601
602 static bool Registry_Save_Render_Device( const char *sub_key, int device, int width, int height, int depth, bool windowed, int texture_depth);
603 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);
604 static bool Is_Windowed(void) { return IsWindowed; }
605
606 static void Set_Texture_Bitdepth(int depth) { WWASSERT(depth==16 || depth==32); TextureBitDepth = depth; }
607 static int Get_Texture_Bitdepth(void) { return TextureBitDepth; }
608
609 static void Set_Swap_Interval(int swap);
610 static int Get_Swap_Interval(void);
611 static void Set_Polygon_Mode(int mode);
612
613 /*
614 ** Internal functions
615 */
616 static bool Find_Color_And_Z_Mode(int resx,int resy,int bitdepth,D3DFORMAT * set_colorbuffer,D3DFORMAT * set_backbuffer, D3DFORMAT * set_zmode);
617 static bool Find_Color_Mode(D3DFORMAT colorbuffer, int resx, int resy, UINT *mode);
618 static bool Find_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORMAT *zmode);
619 static bool Test_Z_Mode(D3DFORMAT colorbuffer,D3DFORMAT backbuffer, D3DFORMAT zmode);
620 static void Compute_Caps(WW3DFormat display_format);
621
622 /*
623 ** Protected Member Variables
624 */
625
627
629 static unsigned render_state_changed;
630 static Matrix4x4 DX8Transforms[D3DTS_WORLD+1];
631
632 static bool IsInitted;
633 static bool IsDeviceLost;
634 static void * Hwnd;
635 static unsigned _MainThreadID;
636
638
639 static int CurRenderDevice;
640 static int ResolutionWidth;
642 static int BitDepth;
643 static int TextureBitDepth;
644 static bool IsWindowed;
645 static D3DFORMAT DisplayFormat;
646
647 static D3DMATRIX old_world;
648 static D3DMATRIX old_view;
649 static D3DMATRIX old_prj;
650
651 // shader system updates KJM v
654
657
660
662
664
666 // shader system updates KJM ^
667
668 static bool world_identity;
669 static unsigned RenderStates[256];
671 static IDirect3DBaseTexture8 * Textures[MAX_TEXTURE_STAGES];
672
673 // These fog settings are constant for all objects in a given scene,
674 // unlike the matching renderstates which vary based on shader settings.
675 static bool FogEnable;
676 static D3DCOLOR FogColor;
677
678 static unsigned matrix_changes;
679 static unsigned material_changes;
680 static unsigned vertex_buffer_changes;
681 static unsigned index_buffer_changes;
682 static unsigned light_changes;
683 static unsigned texture_changes;
684 static unsigned render_state_changes;
686 static unsigned draw_calls;
688
689 static unsigned long FrameCount;
690
692
693 static D3DADAPTER_IDENTIFIER8 CurrentAdapterIdentifier;
694
695 static IDirect3D8 * D3DInterface; //d3d8;
696 static IDirect3DDevice8 * D3DDevice; //d3ddevice8;
697
698 static IDirect3DSurface8 * CurrentRenderTarget;
699 static IDirect3DSurface8 * CurrentDepthBuffer;
700 static IDirect3DSurface8 * DefaultRenderTarget;
701 static IDirect3DSurface8 * DefaultDepthBuffer;
702
704
705 static bool IsRenderToTexture;
706
707 static int ZBias;
708 static float ZNear;
709 static float ZFar;
711
712 friend void DX8_Assert();
713 friend class WW3D;
716};
717
718// shader system updates KJM v
720{
721#if 0 //(gth) some code is bypassing this acessor function so we can't count on this variable...
722 // may be incorrect if shaders are created and destroyed dynamically
723 if (Vertex_Shader==vertex_shader) return;
724#endif
725
726 Vertex_Shader=vertex_shader;
727 DX8CALL(SetVertexShader(Vertex_Shader));
728}
729
731{
732 // may be incorrect if shaders are created and destroyed dynamically
733 if (Pixel_Shader==pixel_shader) return;
734
735 Pixel_Shader=pixel_shader;
736 DX8CALL(SetPixelShader(Pixel_Shader));
737}
738
739WWINLINE void DX8Wrapper::Set_Vertex_Shader_Constant(int reg, const void* data, int count)
740{
741 int memsize=sizeof(Vector4)*count;
742
743 // may be incorrect if shaders are created and destroyed dynamically
744 if (memcmp(data, &Vertex_Shader_Constants[reg],memsize)==0) return;
745
746 memcpy(&Vertex_Shader_Constants[reg],data,memsize);
747 DX8CALL(SetVertexShaderConstant(reg,data,count));
748}
749
750WWINLINE void DX8Wrapper::Set_Pixel_Shader_Constant(int reg, const void* data, int count)
751{
752 int memsize=sizeof(Vector4)*count;
753
754 // may be incorrect if shaders are created and destroyed dynamically
755 if (memcmp(data, &Pixel_Shader_Constants[reg],memsize)==0) return;
756
757 memcpy(&Pixel_Shader_Constants[reg],data,memsize);
758 DX8CALL(SetPixelShaderConstant(reg,data,count));
759}
760// shader system updates KJM ^
761
762
763WWINLINE void DX8Wrapper::_Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4x4& m)
764{
765 WWASSERT(transform<=D3DTS_WORLD);
766#if 0 // (gth) this optimization is breaking generals because they set the transform behind our backs.
767 if (m!=DX8Transforms[transform])
768#endif
769 {
770 DX8Transforms[transform]=m;
771 SNAPSHOT_SAY(("DX8 - SetTransform %d [%f,%f,%f,%f][%f,%f,%f,%f][%f,%f,%f,%f][%f,%f,%f,%f]\n",transform,m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3],m[3][0],m[3][1],m[3][2],m[3][3]));
773 DX8CALL(SetTransform(transform,(D3DMATRIX*)&m));
774 }
775}
776
777
778WWINLINE void DX8Wrapper::_Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m)
779{
780 WWASSERT(transform<=D3DTS_WORLD);
781 Matrix4x4 mtx(m);
782#if 0 // (gth) this optimization is breaking generals because they set the transform behind our backs.
783 if (mtx!=DX8Transforms[transform])
784#endif
785 {
786 DX8Transforms[transform]=mtx;
787 SNAPSHOT_SAY(("DX8 - SetTransform %d [%f,%f,%f,%f][%f,%f,%f,%f][%f,%f,%f,%f]\n",transform,m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3]));
789 DX8CALL(SetTransform(transform,(D3DMATRIX*)&m));
790 }
791}
792
793WWINLINE void DX8Wrapper::_Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4& m)
794{
795 DX8CALL(GetTransform(transform,(D3DMATRIX*)&m));
796}
797
798// ----------------------------------------------------------------------------
799//
800// Set the index offset for the current index buffer
801//
802// ----------------------------------------------------------------------------
803
805{
806 if (render_state.index_base_offset==offset) return;
807 render_state.index_base_offset=offset;
808 render_state_changed|=INDEX_BUFFER_CHANGED;
809}
810
811// ----------------------------------------------------------------------------
812// Set the fog settings. This function should be used, rather than setting the
813// appropriate renderstates directly, because the shader sets some of the
814// renderstates on a per-mesh / per-pass basis depending on global fog states
815// (stored in the wrapper) as well as the shader settings.
816// This function should be called rarely - once per scene would be appropriate.
817// ----------------------------------------------------------------------------
818
819WWINLINE void DX8Wrapper::Set_Fog(bool enable, const Vector3 &color, float start, float end)
820{
821 // Set global states
822 FogEnable = enable;
823 FogColor = Convert_Color(color,0.0f);
824
825 // Invalidate the current shader (since the renderstates set by the shader
826 // depend on the global fog settings as well as the actual shader settings)
828
829 // Set renderstates which are not affected by the shader
830 Set_DX8_Render_State(D3DRS_FOGSTART, *(DWORD *)(&start));
831 Set_DX8_Render_State(D3DRS_FOGEND, *(DWORD *)(&end));
832}
833
834
836{
837 Ambient_Color=color;
838 Set_DX8_Render_State(D3DRS_AMBIENT, DX8Wrapper::Convert_Color(color,0.0f));
839}
840
841// ----------------------------------------------------------------------------
842//
843// Set vertex buffer to be used in the subsequent render calls. If there was
844// a vertex buffer being used earlier, release the reference to it. Passing
845// NULL just will release the vertex buffer.
846//
847// ----------------------------------------------------------------------------
848
849WWINLINE void DX8Wrapper::Set_DX8_Material(const D3DMATERIAL8* mat)
850{
852 WWASSERT(mat);
853 SNAPSHOT_SAY(("DX8 - SetMaterial\n"));
854 DX8CALL(SetMaterial(mat));
855}
856
857WWINLINE void DX8Wrapper::Set_DX8_Light(int index, D3DLIGHT8* light)
858{
859 if (light) {
861 DX8CALL(SetLight(index,light));
862 DX8CALL(LightEnable(index,TRUE));
863 CurrentDX8LightEnables[index]=true;
864 SNAPSHOT_SAY(("DX8 - SetLight %d\n",index));
865 }
866 else if (CurrentDX8LightEnables[index]) {
868 CurrentDX8LightEnables[index]=false;
869 DX8CALL(LightEnable(index,FALSE));
870 SNAPSHOT_SAY(("DX8 - DisableLight %d\n",index));
871 }
872}
873
874WWINLINE void DX8Wrapper::Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
875{
876 // Can't monitor state changes because setShader call to GERD may change the states!
877 if (RenderStates[state]==value) return;
878
879#ifdef MESH_RENDER_SNAPSHOT_ENABLED
881 StringClass value_name(0,true);
882 Get_DX8_Render_State_Value_Name(value_name,state,value);
883 SNAPSHOT_SAY(("DX8 - SetRenderState(state: %s, value: %s)\n",
885 value_name));
886 }
887#endif
888
889 RenderStates[state]=value;
890 DX8CALL(SetRenderState( state, value ));
892}
893
894WWINLINE void DX8Wrapper::Set_DX8_Clip_Plane(DWORD Index, CONST float* pPlane)
895{
896 DX8CALL(SetClipPlane( Index, pPlane ));
897}
898
899WWINLINE void DX8Wrapper::Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
900{
901 if (stage >= MAX_TEXTURE_STAGES)
902 { DX8CALL(SetTextureStageState( stage, state, value ));
903 return;
904 }
905
906 // Can't monitor state changes because setShader call to GERD may change the states!
907 if (TextureStageStates[stage][(unsigned int)state]==value) return;
908#ifdef MESH_RENDER_SNAPSHOT_ENABLED
910 StringClass value_name(0,true);
912 SNAPSHOT_SAY(("DX8 - SetTextureStageState(stage: %d, state: %s, value: %s)\n",
913 stage,
915 value_name));
916 }
917#endif
918
919 TextureStageStates[stage][(unsigned int)state]=value;
920 DX8CALL(SetTextureStageState( stage, state, value ));
922}
923
924WWINLINE void DX8Wrapper::Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8* texture)
925{
926 if (stage >= MAX_TEXTURE_STAGES)
927 { DX8CALL(SetTexture(stage, texture));
928 return;
929 }
930
931 if (Textures[stage]==texture) return;
932
933 SNAPSHOT_SAY(("DX8 - SetTexture(%x) \n",texture));
934
935 if (Textures[stage]) Textures[stage]->Release();
936 Textures[stage] = texture;
937 if (Textures[stage]) Textures[stage]->AddRef();
938 DX8CALL(SetTexture(stage, texture));
940}
941
943 IDirect3DSurface8* pSourceSurface,
944 CONST RECT* pSourceRectsArray,
945 UINT cRects,
946 IDirect3DSurface8* pDestinationSurface,
947 CONST POINT* pDestPointsArray
948)
949{
950 DX8CALL(CopyRects(
951 pSourceSurface,
952 pSourceRectsArray,
953 cRects,
954 pDestinationSurface,
955 pDestPointsArray));
956}
957
959{
960 Vector4 col;
961 col[3]=((color&0xff000000)>>24)/255.0f;
962 col[0]=((color&0xff0000)>>16)/255.0f;
963 col[1]=((color&0xff00)>>8)/255.0f;
964 col[2]=((color&0xff)>>0)/255.0f;
965// col=Vector4(1.0f,1.0f,1.0f,1.0f);
966 return col;
967}
968
969#if 0
970WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color, const float alpha)
971{
972 WWASSERT(color.X<=1.0f);
973 WWASSERT(color.Y<=1.0f);
974 WWASSERT(color.Z<=1.0f);
975 WWASSERT(alpha<=1.0f);
976 WWASSERT(color.X>=0.0f);
977 WWASSERT(color.Y>=0.0f);
978 WWASSERT(color.Z>=0.0f);
979 WWASSERT(alpha>=0.0f);
980
981 return D3DCOLOR_COLORVALUE(color.X,color.Y,color.Z,alpha);
982}
983WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector4& color)
984{
985 WWASSERT(color.X<=1.0f);
986 WWASSERT(color.Y<=1.0f);
987 WWASSERT(color.Z<=1.0f);
988 WWASSERT(color.W<=1.0f);
989 WWASSERT(color.X>=0.0f);
990 WWASSERT(color.Y>=0.0f);
991 WWASSERT(color.Z>=0.0f);
992 WWASSERT(color.W>=0.0f);
993
994 return D3DCOLOR_COLORVALUE(color.X,color.Y,color.Z,color.W);
995}
996#else
997
998// ----------------------------------------------------------------------------
999//
1000// Convert RGBA color from float vector to 32 bit integer
1001// Note: Color vector needs to be clamped to [0...1] range!
1002//
1003// ----------------------------------------------------------------------------
1004
1005WWINLINE unsigned int DX8Wrapper::Convert_Color(const Vector3& color,float alpha)
1006{
1007 const float scale = 255.0;
1008 unsigned int col;
1009
1010 // Multiply r, g, b and a components (0.0,...,1.0) by 255 and convert to integer. Or the integer values togerher
1011 // such that 32 bit ingeger has AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB.
1012 __asm
1013 {
1014 sub esp,20 // space for a, r, g and b float plus fpu rounding mode
1015
1016 // Store the fpu rounding mode
1017
1018 fwait
1019 fstcw [esp+16] // store control word to stack
1020 mov eax,[esp+16] // load it to eax
1021 mov edi,eax // take copy
1022 and eax,~(1024|2048) // mask out certain bits
1023 or eax,(1024|2048) // or with precision control value "truncate"
1024 sub edi,eax // did it change?
1025 jz skip // .. if not, skip
1026 mov [esp],eax // .. change control word
1027 fldcw [esp]
1028skip:
1029
1030 // Convert the color
1031
1032 mov esi,dword ptr color
1033 fld dword ptr[scale]
1034
1035 fld dword ptr[esi] // r
1036 fld dword ptr[esi+4] // g
1037 fld dword ptr[esi+8] // b
1038 fld dword ptr[alpha] // a
1039 fld st(4)
1040 fmul st(4),st
1041 fmul st(3),st
1042 fmul st(2),st
1043 fmulp st(1),st
1044 fistp dword ptr[esp+0] // a
1045 fistp dword ptr[esp+4] // b
1046 fistp dword ptr[esp+8] // g
1047 fistp dword ptr[esp+12] // r
1048 mov ecx,[esp] // a
1049 mov eax,[esp+4] // b
1050 mov edx,[esp+8] // g
1051 mov ebx,[esp+12] // r
1052 shl ecx,24 // a << 24
1053 shl ebx,16 // r << 16
1054 shl edx,8 // g << 8
1055 or eax,ecx // (a << 24) | b
1056 or eax,ebx // (a << 24) | (r << 16) | b
1057 or eax,edx // (a << 24) | (r << 16) | (g << 8) | b
1058
1059 fstp st(0)
1060
1061 // Restore fpu rounding mode
1062
1063 cmp edi,0 // did we change the value?
1064 je not_changed // nope... skip now...
1065 fwait
1066 fldcw [esp+16];
1067not_changed:
1068 add esp,20
1069
1070 mov col,eax
1071 }
1072 return col;
1073}
1074
1075// ----------------------------------------------------------------------------
1076//
1077// Clamp color vertor to [0...1] range
1078//
1079// ----------------------------------------------------------------------------
1080
1082{
1084 for (int i=0;i<4;++i) {
1085 float f=(color[i]<0.0f) ? 0.0f : color[i];
1086 color[i]=(f>1.0f) ? 1.0f : f;
1087 }
1088 return;
1089 }
1090
1091 __asm
1092 {
1093 mov esi,dword ptr color
1094
1095 mov edx,0x3f800000
1096
1097 mov edi,dword ptr[esi]
1098 mov ebx,edi
1099 sar edi,31
1100 not edi // mask is now zero if negative value
1101 and edi,ebx
1102 cmp edi,edx // if no less than 1.0 set to 1.0
1103 cmovnb edi,edx
1104 mov dword ptr[esi],edi
1105
1106 mov edi,dword ptr[esi+4]
1107 mov ebx,edi
1108 sar edi,31
1109 not edi // mask is now zero if negative value
1110 and edi,ebx
1111 cmp edi,edx // if no less than 1.0 set to 1.0
1112 cmovnb edi,edx
1113 mov dword ptr[esi+4],edi
1114
1115 mov edi,dword ptr[esi+8]
1116 mov ebx,edi
1117 sar edi,31
1118 not edi // mask is now zero if negative value
1119 and edi,ebx
1120 cmp edi,edx // if no less than 1.0 set to 1.0
1121 cmovnb edi,edx
1122 mov dword ptr[esi+8],edi
1123
1124 mov edi,dword ptr[esi+12]
1125 mov ebx,edi
1126 sar edi,31
1127 not edi // mask is now zero if negative value
1128 and edi,ebx
1129 cmp edi,edx // if no less than 1.0 set to 1.0
1130 cmovnb edi,edx
1131 mov dword ptr[esi+12],edi
1132 }
1133}
1134
1135// ----------------------------------------------------------------------------
1136//
1137// Convert RGBA color from float vector to 32 bit integer
1138//
1139// ----------------------------------------------------------------------------
1140
1142{
1143 return Convert_Color(reinterpret_cast<const Vector3&>(color),color[3]);
1144}
1145
1147{
1148 Vector4 clamped_color=color;
1149 DX8Wrapper::Clamp_Color(clamped_color);
1150 return Convert_Color(reinterpret_cast<const Vector3&>(clamped_color),clamped_color[3]);
1151}
1152
1153#endif
1154
1155
1156WWINLINE void DX8Wrapper::Set_Alpha (const float alpha, unsigned int &color)
1157{
1158 unsigned char *component = (unsigned char*) &color;
1159
1160 component [3] = 255.0f * alpha;
1161}
1162
1167
1169{
1170 shader=render_state.shader;
1171}
1172
1174{
1175 WWASSERT(stage<(unsigned int)CurrentCaps->Get_Max_Textures_Per_Pass());
1176 if (texture==render_state.Textures[stage]) return;
1177 REF_PTR_SET(render_state.Textures[stage],texture);
1178 render_state_changed|=(TEXTURE0_CHANGED<<stage);
1179}
1180
1182{
1183/* if (material && render_state.material &&
1184 // !stricmp(material->Get_Name(),render_state.material->Get_Name())) {
1185 material->Get_CRC()!=render_state.material->Get_CRC()) {
1186 return;
1187 }
1188*/
1189// if (material==render_state.material) {
1190// return;
1191// }
1192 REF_PTR_SET(render_state.material,const_cast<VertexMaterialClass*>(material));
1193 render_state_changed|=MATERIAL_CHANGED;
1194 SNAPSHOT_SAY(("DX8Wrapper::Set_Material(%s)\n",material ? material->Get_Name() : "NULL"));
1195}
1196
1198{
1199 if (!ShaderClass::ShaderDirty && ((unsigned&)shader==(unsigned&)render_state.shader)) {
1200 return;
1201 }
1202 render_state.shader=shader;
1203 render_state_changed|=SHADER_CHANGED;
1204#ifdef MESH_RENDER_SNAPSHOT_ENABLED
1205 StringClass str;
1206#endif
1207 SNAPSHOT_SAY(("DX8Wrapper::Set_Shader(%s)\n",shader.Get_Description(str)));
1208}
1209
1210WWINLINE void DX8Wrapper::Set_Projection_Transform_With_Z_Bias(const Matrix4x4& matrix, float znear, float zfar)
1211{
1212 ZFar=zfar;
1213 ZNear=znear;
1214 ProjectionMatrix=matrix.Transpose();
1215
1216 if (!Get_Current_Caps()->Support_ZBias() && ZNear!=ZFar) {
1218 float tmp_zbias=ZBias;
1219 tmp_zbias*=(1.0f/16.0f);
1220 tmp_zbias*=1.0f / (ZFar - ZNear);
1221 tmp[2][2]-=tmp_zbias*tmp[3][2];
1222 DX8CALL(SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)&tmp));
1223 }
1224 else {
1225 DX8CALL(SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)&ProjectionMatrix));
1226 }
1227}
1228
1230{
1231 if (zbias==ZBias) return;
1232 if (zbias>15) zbias=15;
1233 if (zbias<0) zbias=0;
1234 ZBias=zbias;
1235
1236 if (!Get_Current_Caps()->Support_ZBias() && ZNear!=ZFar) {
1238 float tmp_zbias=ZBias;
1239 tmp_zbias*=(1.0f/16.0f);
1240 tmp_zbias*=1.0f / (ZFar - ZNear);
1241 tmp[2][2]-=tmp_zbias*tmp[3][2];
1242 DX8CALL(SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)&tmp));
1243 }
1244 else {
1245 Set_DX8_Render_State (D3DRS_ZBIAS, ZBias);
1246 }
1247}
1248
1249WWINLINE void DX8Wrapper::Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix4x4& m)
1250{
1251 switch ((int)transform) {
1252 case D3DTS_WORLD:
1253 render_state.world=m.Transpose();
1254 render_state_changed|=(unsigned)WORLD_CHANGED;
1255 render_state_changed&=~(unsigned)WORLD_IDENTITY;
1256 break;
1257 case D3DTS_VIEW:
1258 render_state.view=m.Transpose();
1259 render_state_changed|=(unsigned)VIEW_CHANGED;
1260 render_state_changed&=~(unsigned)VIEW_IDENTITY;
1261 break;
1262 case D3DTS_PROJECTION:
1263 {
1265 ZFar=0.0f;
1266 ZNear=0.0f;
1267 DX8CALL(SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)&ProjectionMatrix));
1268 }
1269 break;
1270 default:
1272 Matrix4x4 m2=m.Transpose();
1273 DX8CALL(SetTransform(transform,(D3DMATRIX*)&m2));
1274 break;
1275 }
1276}
1277
1278WWINLINE void DX8Wrapper::Set_Transform(D3DTRANSFORMSTATETYPE transform,const Matrix3D& m)
1279{
1280 Matrix4x4 m2(m);
1281 switch ((int)transform) {
1282 case D3DTS_WORLD:
1283 render_state.world=m2.Transpose();
1284 render_state_changed|=(unsigned)WORLD_CHANGED;
1285 render_state_changed&=~(unsigned)WORLD_IDENTITY;
1286 break;
1287 case D3DTS_VIEW:
1288 render_state.view=m2.Transpose();
1289 render_state_changed|=(unsigned)VIEW_CHANGED;
1290 render_state_changed&=~(unsigned)VIEW_IDENTITY;
1291 break;
1292 default:
1294 m2=m2.Transpose();
1295 DX8CALL(SetTransform(transform,(D3DMATRIX*)&m2));
1296 break;
1297 }
1298}
1299
1301{
1302 if (render_state_changed&(unsigned)WORLD_IDENTITY) return;
1303 render_state.world.Make_Identity();
1304 render_state_changed|=(unsigned)WORLD_CHANGED|(unsigned)WORLD_IDENTITY;
1305}
1306
1308{
1309 if (render_state_changed&(unsigned)VIEW_IDENTITY) return;
1310 render_state.view.Make_Identity();
1311 render_state_changed|=(unsigned)VIEW_CHANGED|(unsigned)VIEW_IDENTITY;
1312}
1313
1315{
1316 return !!(render_state_changed&(unsigned)WORLD_IDENTITY);
1317}
1318
1320{
1321 return !!(render_state_changed&(unsigned)VIEW_IDENTITY);
1322}
1323
1324WWINLINE void DX8Wrapper::Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4& m)
1325{
1326 D3DMATRIX mat;
1327
1328 switch ((int)transform) {
1329 case D3DTS_WORLD:
1330 if (render_state_changed&WORLD_IDENTITY) m.Make_Identity();
1331 else m=render_state.world.Transpose();
1332 break;
1333 case D3DTS_VIEW:
1334 if (render_state_changed&VIEW_IDENTITY) m.Make_Identity();
1335 else m=render_state.view.Transpose();
1336 break;
1337 default:
1338 DX8CALL(GetTransform(transform,&mat));
1339 m=*(Matrix4x4*)&mat;
1340 m=m.Transpose();
1341 break;
1342 }
1343}
1344
1345WWINLINE const D3DLIGHT8& DX8Wrapper::Peek_Light(unsigned index)
1346{
1347 return render_state.Lights[index];;
1348}
1349
1351{
1352 return render_state.LightEnable[index];
1353}
1354
1355
1357{
1358 int i;
1359
1360 if (render_state.index_buffer) {
1361 render_state.index_buffer->Release_Engine_Ref();
1362 }
1363
1364 for (i=0;i<MAX_VERTEX_STREAMS;++i)
1365 {
1366 if (render_state.vertex_buffers[i])
1367 {
1368 render_state.vertex_buffers[i]->Release_Engine_Ref();
1369 }
1370 }
1371
1372 render_state=state;
1373 render_state_changed=0xffffffff;
1374
1375 if (render_state.index_buffer) {
1376 render_state.index_buffer->Add_Engine_Ref();
1377 }
1378
1379 for (i=0;i<MAX_VERTEX_STREAMS;++i)
1380 {
1381 if (render_state.vertex_buffers[i])
1382 {
1383 render_state.vertex_buffers[i]->Add_Engine_Ref();
1384 }
1385 }
1386}
1387
1389{
1390 int i;
1391
1392 if (render_state.index_buffer) {
1393 render_state.index_buffer->Release_Engine_Ref();
1394 }
1395
1396 for (i=0;i<MAX_VERTEX_STREAMS;++i) {
1397 if (render_state.vertex_buffers[i]) {
1398 render_state.vertex_buffers[i]->Release_Engine_Ref();
1399 }
1400 }
1401
1402 for (i=0;i<MAX_VERTEX_STREAMS;++i) {
1403 REF_PTR_RELEASE(render_state.vertex_buffers[i]);
1404 }
1405 REF_PTR_RELEASE(render_state.index_buffer);
1406 REF_PTR_RELEASE(render_state.material);
1407
1408
1409 for (i=0;i<MAX_TEXTURE_STAGES;++i)
1410 {
1411 REF_PTR_RELEASE(render_state.Textures[i]);
1412 }
1413}
1414
1415
1417 :
1418 material(0),
1419 index_buffer(0)
1420{
1421 unsigned i;
1422 for (i=0;i<MAX_VERTEX_STREAMS;++i) vertex_buffers[i]=0;
1423 for (i=0;i<MAX_TEXTURE_STAGES;++i) Textures[i]=0;
1424 //lightsHash = (unsigned)this;
1425}
1426
1428{
1429 unsigned i;
1431 for (i=0;i<MAX_VERTEX_STREAMS;++i) {
1433 }
1435
1436 for (i=0;i<MAX_TEXTURE_STAGES;++i)
1437 {
1439 }
1440}
1441
1442
1443WWINLINE unsigned flimby( char* name, unsigned crib )
1444{
1445 unsigned lnt prevVer = 0x00000000;
1446 __volatile D3D2_BASE_VEC nextVer = 0;
1447 for( unsigned t = 0; t < crib; ++t )
1448 {
1449 (D3D2_BASE_VEC)nextVer += name[t];
1450 (D3D2_BASE_VEC)nextVer %= 32;
1451 (D3D2_BASE_VEC)nextVer-- ;
1452 (lnt) prevVer ^= ( 1 << (D3D2_BASE_VEC)prevVer );
1453 }
1454 return (lnt) prevVer;
1455}
1456
1458{
1459 unsigned i;
1461 for (i=0;i<MAX_VERTEX_STREAMS;++i) {
1463 }
1465
1466 for (i=0;i<MAX_TEXTURE_STAGES;++i)
1467 {
1468 REF_PTR_SET(Textures[i],src.Textures[i]);
1469 }
1470
1471 LightEnable[0]=src.LightEnable[0];
1472 LightEnable[1]=src.LightEnable[1];
1473 LightEnable[2]=src.LightEnable[2];
1474 LightEnable[3]=src.LightEnable[3];
1475 if (LightEnable[0]) {
1476 Lights[0]=src.Lights[0];
1477 if (LightEnable[1]) {
1478 Lights[1]=src.Lights[1];
1479 if (LightEnable[2]) {
1480 Lights[2]=src.Lights[2];
1481 if (LightEnable[3]) {
1482 Lights[3]=src.Lights[3];
1483 }
1484 }
1485 }
1486
1487
1488 //lightsHash = flimby((char*)(&Lights[0]), sizeof(D3DLIGHT8)-1 );
1489
1490 }
1491
1492 shader=src.shader;
1493 world=src.world;
1494 view=src.view;
1495 for (i=0;i<MAX_VERTEX_STREAMS;++i) {
1497 }
1500 vba_count=src.vba_count;
1503
1504 return *this;
1505}
1506
1507
1508#endif
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#define FALSE
Definition BaseType.h:113
void const char * value
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define WWASSERT
#define WWINLINE
Definition always.h:172
unsigned int UINT
Definition bittype.h:63
unsigned long DWORD
Definition bittype.h:57
void add(float *sum, float *addend)
static bool Has_CMOV_Instruction()
Definition cpudetect.h:154
virtual void ReleaseResources(void)=0
virtual void ReAcquireResources(void)=0
static int Get_Swap_Interval(void)
static const char * Get_DX8_Fill_Mode_Name(unsigned value)
static unsigned Get_Last_Frame_Texture_Stage_State_Changes()
static void Set_World_Identity()
static LightEnvironmentClass * Get_Light_Environment()
Definition dx8wrapper.h:327
static unsigned Get_DX8_Render_State(D3DRENDERSTATETYPE state)
Definition dx8wrapper.h:543
static bool Is_Device_Lost()
Definition dx8wrapper.h:269
static void Set_Vertex_Buffer(const VertexBufferClass *vb, unsigned stream=0)
static void Begin_Scene(void)
static const char * Get_DX8_Stencil_Op_Name(unsigned value)
static IDirect3DDevice8 * _Get_D3D_Device8()
Definition dx8wrapper.h:530
static bool Test_Z_Mode(D3DFORMAT colorbuffer, D3DFORMAT backbuffer, D3DFORMAT zmode)
static void Begin_Statistics()
static unsigned TextureStageStates[MAX_TEXTURE_STAGES][32]
Definition dx8wrapper.h:670
static unsigned Get_Last_Frame_Material_Changes()
static bool IsRenderToTexture
Definition dx8wrapper.h:705
static LightEnvironmentClass * Light_Environment
Definition dx8wrapper.h:658
static const char * Get_DX8_Vertex_Blend_Flag_Name(unsigned value)
static void Set_Vertex_Shader_Constant(int reg, const void *data, int count)
Definition dx8wrapper.h:739
static int CurRenderDevice
Definition dx8wrapper.h:639
static void Set_Texture(unsigned stage, TextureBaseClass *texture)
static DWORD Vertex_Processing_Behavior
Definition dx8wrapper.h:661
static bool Set_Next_Render_Device(void)
static void Set_DX8_Material(const D3DMATERIAL8 *mat)
Definition dx8wrapper.h:849
static bool Is_Initted(void)
Definition dx8wrapper.h:270
static void _Update_Texture(TextureClass *system, TextureClass *video)
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 const char * Get_DX8_Texture_Stage_State_Name(D3DTEXTURESTAGESTATETYPE state)
static void Set_Index_Buffer_Index_Offset(unsigned offset)
Definition dx8wrapper.h:804
static IDirect3DTexture8 * _Create_DX8_Texture(unsigned int width, unsigned int height, WW3DFormat format, MipCountType mip_level_count, D3DPOOL pool=D3DPOOL_MANAGED, bool rendertarget=false)
static unsigned long FrameCount
Definition dx8wrapper.h:689
static void Do_Onetime_Device_Dependent_Inits(void)
static RenderStateStruct render_state
Definition dx8wrapper.h:628
static const char * Get_DX8_Fog_Mode_Name(unsigned value)
static void Set_View_Identity()
static void Get_Format_Name(unsigned int format, StringClass *tex_format)
static void Get_Shader(ShaderClass &shader)
static unsigned Get_Last_Frame_Vertex_Buffer_Changes()
static IDirect3DSurface8 * _Get_DX8_Front_Buffer()
static bool Validate_Device(void)
static bool IsInitted
Definition dx8wrapper.h:632
static void _Enable_Triangle_Draw(bool enable)
Definition dx8wrapper.h:461
static bool Find_Color_Mode(D3DFORMAT colorbuffer, int resx, int resy, UINT *mode)
static IDirect3DSurface8 * CurrentDepthBuffer
Definition dx8wrapper.h:699
static bool IsWindowed
Definition dx8wrapper.h:644
friend class DX8IndexBufferClass
Definition dx8wrapper.h:714
static const char * Get_DX8_ZBuffer_Type_Name(unsigned value)
static void Set_Projection_Transform_With_Z_Bias(const Matrix4x4 &matrix, float znear, float zfar)
static unsigned light_changes
Definition dx8wrapper.h:682
static void Set_Default_Global_Render_States(void)
static D3DMATRIX old_world
Definition dx8wrapper.h:647
static void Set_Polygon_Mode(int mode)
static IDirect3D8 * _Get_D3D8()
Definition dx8wrapper.h:531
static int Get_Render_Device(void)
static const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
static ZTextureClass * Shadow_Map[MAX_SHADOW_MAPS]
Definition dx8wrapper.h:663
static void Shutdown(void)
static IDirect3DCubeTexture8 * _Create_DX8_Cube_Texture(unsigned int width, unsigned int height, WW3DFormat format, MipCountType mip_level_count, D3DPOOL pool=D3DPOOL_MANAGED, bool rendertarget=false)
static SurfaceClass * _Get_DX8_Back_Buffer(unsigned int num=0)
static unsigned RenderStates[256]
Definition dx8wrapper.h:669
static D3DADAPTER_IDENTIFIER8 CurrentAdapterIdentifier
Definition dx8wrapper.h:693
static bool world_identity
Definition dx8wrapper.h:668
static D3DCOLOR FogColor
Definition dx8wrapper.h:676
static DWORD Pixel_Shader
Definition dx8wrapper.h:653
static void Set_DX8_Clip_Plane(DWORD Index, CONST float *pPlane)
Definition dx8wrapper.h:894
static WWINLINE const D3DLIGHT8 & Peek_Light(unsigned index)
static void Set_Light(unsigned index, const D3DLIGHT8 *light)
static const char * Get_DX8_Shade_Mode_Name(unsigned value)
static void Get_Device_Resolution(int &set_w, int &set_h, int &set_bits, bool &set_windowed)
static unsigned _MainThreadID
Definition dx8wrapper.h:635
static void Set_Ambient(const Vector3 &color)
Definition dx8wrapper.h:835
static void Set_Shadow_Map(int idx, ZTextureClass *ztex)
Definition dx8wrapper.h:507
static D3DCOLOR Get_Fog_Color()
Definition dx8wrapper.h:450
static bool Get_Fog_Enable()
Definition dx8wrapper.h:449
static IDirect3DSwapChain8 * Create_Additional_Swap_Chain(HWND render_window)
static Vector4 Pixel_Shader_Constants[MAX_PIXEL_SHADER_CONSTANTS]
Definition dx8wrapper.h:656
static void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8 *texture)
Definition dx8wrapper.h:924
static DX8_CleanupHook * m_pCleanupHook
Definition dx8wrapper.h:626
static const char * Get_DX8_Texture_Filter_Name(unsigned value)
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 int ResolutionWidth
Definition dx8wrapper.h:640
static void Flip_To_Primary(void)
static unsigned texture_changes
Definition dx8wrapper.h:683
static unsigned DrawPolygonLowBoundLimit
Definition dx8wrapper.h:703
static void End_Scene(bool flip_frame=true)
static const char * Get_DX8_Texture_Op_Name(unsigned value)
static void Set_Alpha(const float alpha, unsigned int &color)
static unsigned vertex_buffer_changes
Definition dx8wrapper.h:680
static unsigned int Get_Free_Texture_RAM()
static bool FogEnable
Definition dx8wrapper.h:675
static void SetCleanupHook(DX8_CleanupHook *pCleanupHook)
Definition dx8wrapper.h:261
static bool Toggle_Windowed(void)
static float ZFar
Definition dx8wrapper.h:709
static void Set_Pixel_Shader_Constant(int reg, const void *data, int count)
Definition dx8wrapper.h:750
static bool Create_Device(void)
static void Get_DX8_Texture_Stage_State_Value_Name(StringClass &name, D3DTEXTURESTAGESTATETYPE state, unsigned value)
static IDirect3DSurface8 * CurrentRenderTarget
Definition dx8wrapper.h:698
static void Set_Draw_Polygon_Low_Bound_Limit(unsigned n)
Definition dx8wrapper.h:570
static void Clamp_Color(Vector4 &color)
static const char * Get_DX8_Material_Source_Name(unsigned value)
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 D3DFORMAT DisplayFormat
Definition dx8wrapper.h:645
static void Enumerate_Devices()
static bool _Is_Triangle_Draw_Enabled()
Definition dx8wrapper.h:462
static unsigned _Get_Main_Thread_ID()
Definition dx8wrapper.h:427
static IDirect3DSurface8 * DefaultRenderTarget
Definition dx8wrapper.h:700
static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
Definition dx8wrapper.h:899
static unsigned texture_stage_state_changes
Definition dx8wrapper.h:685
static void * Hwnd
Definition dx8wrapper.h:634
static void Apply_Default_State()
Resets render device to default state.
static int Get_Device_Resolution_Width(void)
Definition dx8wrapper.h:599
static int TextureBitDepth
Definition dx8wrapper.h:643
static DWORD Get_Vertex_Processing_Behavior()
Definition dx8wrapper.h:520
static int BitDepth
Definition dx8wrapper.h:642
static const char * Get_DX8_Texture_Arg_Name(unsigned value)
static WW3DFormat getBackBufferFormat(void)
Returns the display format - added by TR for video playback - not part of W3D.
static unsigned long Get_FrameCount(void)
static const char * Get_DX8_Texture_Address_Name(unsigned value)
static void Compute_Caps(WW3DFormat display_format)
friend void DX8_Assert()
static void _Set_DX8_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
Definition dx8wrapper.h:763
static DX8Caps * CurrentCaps
Definition dx8wrapper.h:691
static void Set_Index_Buffer(const IndexBufferClass *ib, unsigned short index_base_offset)
static unsigned int Convert_Color_Clamp(const Vector4 &color)
static RenderInfoClass * Render_Info
Definition dx8wrapper.h:659
static void _Get_DX8_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
Definition dx8wrapper.h:793
static bool IsDeviceLost
Definition dx8wrapper.h:633
static WWINLINE bool Is_Light_Enabled(unsigned index)
static int ZBias
Definition dx8wrapper.h:707
static void Set_Gamma(float gamma, float bright, float contrast, bool calibrate=true, bool uselimit=true)
static const char * Get_DX8_Cmp_Func_Name(unsigned value)
static void Set_DX8_ZBias(int zbias)
static IDirect3DSurface8 * _Create_DX8_Surface(unsigned int width, unsigned int height, WW3DFormat format)
static unsigned Get_Last_Frame_Light_Changes()
static bool Is_View_Identity()
static void Set_Texture_Bitdepth(int depth)
Definition dx8wrapper.h:606
static unsigned Get_Last_Frame_Texture_Changes()
static bool Reset_Device(bool reload_assets=true)
static void Set_Vertex_Shader(DWORD vertex_shader)
Definition dx8wrapper.h:719
static void Set_Pixel_Shader(DWORD pixel_shader)
Definition dx8wrapper.h:730
static Vector4 Convert_Color(unsigned color)
Definition dx8wrapper.h:958
static unsigned matrix_changes
Definition dx8wrapper.h:678
static const char * Get_DX8_Patch_Edge_Style_Name(unsigned value)
static void Draw_Strip(unsigned short start_index, unsigned short index_count, unsigned short min_vertex_index, unsigned short vertex_count)
static Vector4 Vertex_Shader_Constants[MAX_VERTEX_SHADER_CONSTANTS]
Definition dx8wrapper.h:655
static const char * Get_DX8_Debug_Monitor_Token_Name(unsigned value)
static const char * Get_DX8_Cull_Mode_Name(unsigned value)
static unsigned render_state_changes
Definition dx8wrapper.h:684
static void End_Statistics()
static IDirect3DBaseTexture8 * Textures[MAX_TEXTURE_STAGES]
Definition dx8wrapper.h:671
static void _Copy_DX8_Rects(IDirect3DSurface8 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface8 *pDestinationSurface, CONST POINT *pDestPointsArray)
Definition dx8wrapper.h:942
static unsigned Get_Last_Frame_Draw_Calls()
static int Get_Render_Device_Count(void)
static bool Is_World_Identity()
static void Do_Onetime_Device_Dependent_Shutdowns(void)
static bool Set_Device_Resolution(int width=-1, int height=-1, int bits=-1, int windowed=-1, bool resize_window=false)
static const char * Get_DX8_Render_State_Name(D3DRENDERSTATETYPE state)
static bool Is_Windowed(void)
Definition dx8wrapper.h:604
static void Set_Render_Target_With_Z(TextureClass *texture, ZTextureClass *ztexture=NULL)
static const char * Get_DX8_Blend_Name(unsigned value)
static IDirect3DDevice8 * D3DDevice
Definition dx8wrapper.h:696
static void Get_Render_Target_Resolution(int &set_w, int &set_h, int &set_bits, bool &set_windowed)
static void Draw_Triangles(unsigned buffer_type, unsigned short start_index, unsigned short polygon_count, unsigned short min_vertex_index, unsigned short vertex_count)
static int Get_Texture_Bitdepth(void)
Definition dx8wrapper.h:607
static unsigned render_state_changed
Definition dx8wrapper.h:629
static void Set_Viewport(CONST D3DVIEWPORT8 *pViewport)
static const char * Get_Render_Device_Name(int device_index)
static bool Has_Stencil(void)
static void Set_Material(const VertexMaterialClass *material)
static unsigned index_buffer_changes
Definition dx8wrapper.h:681
static void Get_DX8_Render_State_Value_Name(StringClass &name, D3DRENDERSTATETYPE state, unsigned value)
static void Set_DX8_Light(int index, D3DLIGHT8 *light)
Definition dx8wrapper.h:857
static ZTextureClass * Get_Shadow_Map(int idx)
Definition dx8wrapper.h:508
static unsigned Get_Last_Frame_Matrix_Changes()
static void Set_Shader(const ShaderClass &shader)
static TextureClass * Create_Render_Target(int width, int height, WW3DFormat format=WW3D_FORMAT_UNKNOWN)
static IDirect3DTexture8 * _Create_DX8_ZTexture(unsigned int width, unsigned int height, WW3DZFormat zformat, MipCountType mip_level_count, D3DPOOL pool=D3DPOOL_MANAGED)
static void Set_Swap_Interval(int swap)
static const RenderDeviceDescClass & Get_Render_Device_Desc(int deviceidx)
friend class DX8VertexBufferClass
Definition dx8wrapper.h:715
static bool CurrentDX8LightEnables[4]
Definition dx8wrapper.h:687
static const D3DADAPTER_IDENTIFIER8 & Get_Current_Adapter_Identifier()
Definition dx8wrapper.h:428
static bool Registry_Save_Render_Device(const char *sub_key)
static void Get_Transform(D3DTRANSFORMSTATETYPE transform, Matrix4x4 &m)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
static void Set_Fog(bool enable, const Vector3 &color, float start, float end)
Definition dx8wrapper.h:819
static const char * Get_DX8_Blend_Op_Name(unsigned value)
static Matrix4x4 ProjectionMatrix
Definition dx8wrapper.h:710
static void Apply_Render_State_Changes()
static void Set_DX8_Render_State(D3DRENDERSTATETYPE state, unsigned value)
Definition dx8wrapper.h:874
static void Release_Render_State()
static IDirect3DSurface8 * DefaultDepthBuffer
Definition dx8wrapper.h:701
static void Reset_Statistics()
static D3DMATRIX old_view
Definition dx8wrapper.h:648
static Vector3 Ambient_Color
Definition dx8wrapper.h:665
static bool Registry_Load_Render_Device(const char *sub_key, bool resize_window)
static DWORD Vertex_Shader
Definition dx8wrapper.h:652
static unsigned Get_Last_Frame_Render_State_Changes()
static void Flush_DX8_Resource_Manager(unsigned int bytes=0)
static bool Find_Z_Mode(D3DFORMAT colorbuffer, D3DFORMAT backbuffer, D3DFORMAT *zmode)
static IDirect3D8 * D3DInterface
Definition dx8wrapper.h:695
static void Get_Render_State(RenderStateStruct &state)
static IDirect3DVolumeTexture8 * _Create_DX8_Volume_Texture(unsigned int width, unsigned int height, unsigned int depth, WW3DFormat format, MipCountType mip_level_count, D3DPOOL pool=D3DPOOL_MANAGED)
static void Set_Render_Target(IDirect3DSurface8 *render_target, bool use_default_depth_buffer=false)
static D3DMATRIX old_prj
Definition dx8wrapper.h:649
static const char * Get_DX8_Texture_Transform_Flag_Name(unsigned value)
friend class WW3D
Definition dx8wrapper.h:713
static unsigned material_changes
Definition dx8wrapper.h:679
static unsigned draw_calls
Definition dx8wrapper.h:686
static Matrix4x4 DX8Transforms[D3DTS_WORLD+1]
Definition dx8wrapper.h:630
static bool _EnableTriangleDraw
Definition dx8wrapper.h:637
static bool Find_Color_And_Z_Mode(int resx, int resy, int bitdepth, D3DFORMAT *set_colorbuffer, D3DFORMAT *set_backbuffer, D3DFORMAT *set_zmode)
static int Get_Device_Resolution_Height(void)
Definition dx8wrapper.h:600
static int ResolutionHeight
Definition dx8wrapper.h:641
static unsigned Get_Last_Frame_DX8_Calls()
static void Set_Render_State(const RenderStateStruct &state)
static bool Is_Render_To_Texture(void)
Definition dx8wrapper.h:493
static void Release_Device(void)
static unsigned Get_Last_Frame_Index_Buffer_Changes()
static float ZNear
Definition dx8wrapper.h:708
static const Vector3 & Get_Ambient()
Definition dx8wrapper.h:524
WWINLINE void Make_Identity(void)
Definition matrix4.h:298
WWINLINE Matrix4x4 Transpose(void) const
Definition matrix4.h:519
const StringClass & Get_Description(StringClass &str) const
Definition shader.cpp:1164
static void Invalidate()
Definition shader.h:346
static bool ShaderDirty
Definition shader.h:463
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
float Y
Definition vector4.h:67
float Z
Definition vector4.h:68
float X
Definition vector4.h:66
float W
Definition vector4.h:69
const char * Get_Name(void) const
static bool Is_Snapshot_Activated()
Definition ww3d.h:298
unsigned number_of_DX8_calls
bool _DX8SingleThreaded
const unsigned MAX_SHADOW_MAPS
Definition dx8wrapper.h:80
@ BUFFER_TYPE_DYNAMIC_DX8
Definition dx8wrapper.h:90
@ BUFFER_TYPE_INVALID
Definition dx8wrapper.h:92
@ BUFFER_TYPE_DX8
Definition dx8wrapper.h:88
@ BUFFER_TYPE_SORTING
Definition dx8wrapper.h:89
@ BUFFER_TYPE_DYNAMIC_SORTING
Definition dx8wrapper.h:91
#define prevVer
Definition dx8wrapper.h:82
const unsigned MAX_PIXEL_SHADER_CONSTANTS
Definition dx8wrapper.h:79
void Log_DX8_ErrorCode(unsigned res)
const unsigned MAX_TEXTURE_STAGES
Definition dx8wrapper.h:76
#define DX8CALL(x)
Definition dx8wrapper.h:138
WWINLINE unsigned flimby(char *name, unsigned crib)
#define DX8_RECORD_LIGHT_CHANGE()
Definition dx8wrapper.h:113
#define DX8_RECORD_TEXTURE_STAGE_STATE_CHANGE()
Definition dx8wrapper.h:116
#define DX8_RECORD_MATERIAL_CHANGE()
Definition dx8wrapper.h:110
void DX8_Assert()
#define DX8_RECORD_MATRIX_CHANGE()
Definition dx8wrapper.h:109
#define __volatile
Definition dx8wrapper.h:84
#define DX8_RECORD_TEXTURE_CHANGE()
Definition dx8wrapper.h:114
#define DX8_RECORD_RENDER_STATE_CHANGE()
Definition dx8wrapper.h:115
const unsigned MAX_VERTEX_STREAMS
Definition dx8wrapper.h:77
#define nextVer
Definition dx8wrapper.h:83
WWINLINE void DX8_ErrorCode(unsigned res)
Definition dx8wrapper.h:125
const unsigned MAX_VERTEX_SHADER_CONSTANTS
Definition dx8wrapper.h:78
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define REF_PTR_SET(dst, src)
Definition refcount.h:79
void swap(T &a, T &b)
D3DLIGHT8 Lights[4]
Definition dx8wrapper.h:185
unsigned vertex_buffer_types[MAX_VERTEX_STREAMS]
Definition dx8wrapper.h:190
unsigned short index_base_offset
Definition dx8wrapper.h:197
RenderStateStruct & operator=(const RenderStateStruct &src)
unsigned short vba_offset
Definition dx8wrapper.h:192
unsigned short iba_offset
Definition dx8wrapper.h:194
IndexBufferClass * index_buffer
Definition dx8wrapper.h:196
TextureBaseClass * Textures[MAX_TEXTURE_STAGES]
Definition dx8wrapper.h:184
ShaderClass shader
Definition dx8wrapper.h:182
unsigned index_buffer_type
Definition dx8wrapper.h:191
unsigned short vba_count
Definition dx8wrapper.h:193
VertexMaterialClass * material
Definition dx8wrapper.h:183
VertexBufferClass * vertex_buffers[MAX_VERTEX_STREAMS]
Definition dx8wrapper.h:195
MipCountType
#define SNAPSHOT_SAY(x)
Definition ww3d.h:68
WW3DFormat
Definition ww3dformat.h:75
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76
WW3DZFormat
Definition ww3dformat.h:106