Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
texture.cpp
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/texture.cpp $*
26 * *
27 * $Org Author:: Steve_t $*
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 08/05/02 1:27p $*
32 * *
33 * $Revision:: 85 $*
34 * *
35 * 06/27/02 KM Texture class abstraction *
36 * 08/05/02 KM Texture class redesign (revisited)
37 *---------------------------------------------------------------------------------------------*
38 * Functions: *
39 * FileListTextureClass::Load_Frame_Surface -- Load source texture *
40 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41
42#include "texture.h"
43
44#include <d3d8.h>
45#include <stdio.h>
46#include <D3dx8core.h>
47#include "dx8wrapper.h"
48#include "targa.h"
49#include <nstrdup.h>
50#include "w3d_file.h"
51#include "assetmgr.h"
52#include "formconv.h"
53#include "textureloader.h"
54#include "missingtexture.h"
55#include "ffactory.h"
56#include "dx8caps.h"
57#include "dx8texman.h"
58#include "meshmatdesc.h"
59#include "texturethumbnail.h"
60#include "wwprofile.h"
61
62//#pragma optimize("", off)
63//#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
64
65const unsigned DEFAULT_INACTIVATION_TIME=20000;
66
67/*
68** Definitions of static members:
69*/
70
71static unsigned unused_texture_id;
72
73// This throttles submissions to the background texture loading queue.
74static unsigned TexturesAppliedPerFrame;
76
77
82(
83 unsigned int width,
84 unsigned int height,
85 enum MipCountType mip_level_count,
86 enum PoolType pool,
87 bool rendertarget,
88 bool reducible
89)
90: MipLevelCount(mip_level_count),
91 D3DTexture(NULL),
93 Name(""),
94 FullPath(""),
95 texture_id(unused_texture_id++),
98 IsReducible(reducible),
103 LastAccessed(0),
104 Width(width),
105 Height(height),
106 Pool(pool),
107 Dirty(false),
108 TextureLoadTask(NULL),
109 ThumbnailLoadTask(NULL),
110 HSVShift(0.0f,0.0f,0.0f)
111{
112}
113
114
115//**********************************************************************************************
117
120{
121 delete TextureLoadTask;
122 TextureLoadTask=NULL;
123 delete ThumbnailLoadTask;
124 ThumbnailLoadTask=NULL;
125
126 if (D3DTexture)
127 {
128 D3DTexture->Release();
129 D3DTexture = NULL;
130 }
131
133}
134
135
136
137
138//**********************************************************************************************
140
142void TextureBaseClass::Invalidate_Old_Unused_Textures(unsigned invalidation_time_override)
143{
144 // (gth) If thumbnails are not enabled, then we don't run this code.
145 if (WW3D::Get_Thumbnail_Enabled() == false) {
146 return;
147 }
148
149 // Zero the texture apply count in this function because this is called every frame...(this wasn't in E&B main branch KJM)
150 TexturesAppliedPerFrame=0;
151
152 unsigned synctime=WW3D::Get_Sync_Time();
154 // Loop through all the textures in the manager
155
156 for (ite.First ();!ite.Is_Done();ite.Next ())
157 {
158 TextureClass* tex=ite.Peek_Value();
159
160 // Consider invalidating if texture has been initialized and defines inactivation time
161 if (tex->Initialized && tex->InactivationTime)
162 {
163 unsigned age=synctime-tex->LastAccessed;
164
165 if (invalidation_time_override)
166 {
167 if (age>invalidation_time_override)
168 {
169 tex->Invalidate();
170 tex->LastInactivationSyncTime=synctime;
171 }
172 }
173 else
174 {
175 // Not used in the last n milliseconds?
176 if (age>(tex->InactivationTime+tex->ExtendedInactivationTime))
177 {
178 tex->Invalidate();
179 tex->LastInactivationSyncTime=synctime;
180 }
181 }
182 }
183 }
184}
185
186
187
188
189
190//**********************************************************************************************
192
195{
196 if (TextureLoadTask) {
197 return;
198 }
199 if (ThumbnailLoadTask) {
200 return;
201 }
202
203 // Don't invalidate procedural textures
204 if (IsProcedural) {
205 return;
206 }
207
208 if (D3DTexture)
209 {
210 D3DTexture->Release();
211 D3DTexture = NULL;
212 }
213
214 Initialized=false;
215
217/* was battlefield version// If the texture has already been initialised we should exit now
218 if (Initialized) return;
219
220 WWPROFILE(("TextureClass::Init()"));
221
222 // If the texture has recently been inactivated, increase the inactivation time (this texture obviously
223 // should not have been inactivated yet).
224
225 if (InactivationTime && LastInactivationSyncTime) {
226 if ((WW3D::Get_Sync_Time()-LastInactivationSyncTime)<InactivationTime) {
227 ExtendedInactivationTime=3*InactivationTime;
228 }
229 LastInactivationSyncTime=0;
230 }
231
232 if (ThumbnailLoadTask)
233 {
234 return;
235 }
236
237 // Don't invalidate procedural textures
238 if (IsProcedural)
239 {
240 return;
241 }
242
243 if (D3DTexture)
244 {
245 D3DTexture->Release();
246 D3DTexture = NULL;
247 }
248
249 Initialized=false;
250
251 LastAccessed=WW3D::Get_Sync_Time();*/
252}
253
254//**********************************************************************************************
256
258IDirect3DBaseTexture8 * TextureBaseClass::Peek_D3D_Base_Texture() const
259{
261 return D3DTexture;
262}
263
264//**********************************************************************************************
266
268void TextureBaseClass::Set_D3D_Base_Texture(IDirect3DBaseTexture8* tex)
269{
270 // (gth) Generals does stuff directly with the D3DTexture pointer so lets
271 // reset the access timer whenever someon messes with this pointer.
273
274 if (D3DTexture != NULL) {
275 D3DTexture->Release();
276 }
277 D3DTexture = tex;
278 if (D3DTexture != NULL) {
279 D3DTexture->AddRef();
280 }
281}
282
283
284//**********************************************************************************************
286
289{
290 WWPROFILE(("TextureClass::Load_Locked_Surface()"));
291 if (D3DTexture) D3DTexture->Release();
292 D3DTexture=0;
294 Initialized=false;
295}
296
297
298//**********************************************************************************************
300
303{
304 bool flag = false;
305 IDirect3DBaseTexture8 *missing_texture = MissingTexture::_Get_Missing_Texture();
306
307 if (D3DTexture == missing_texture)
308 flag = true;
309
310 if (missing_texture)
311 {
312 missing_texture->Release();
313 }
314
315 return flag;
316}
317
318
319//**********************************************************************************************
321
324{
325 Name=name;
326}
327
328
329
330
331//**********************************************************************************************
333
336{
337 if (!D3DTexture)
338 {
339 WWASSERT_PRINT(0, "Get_Priority: D3DTexture is NULL!\n");
340 return 0;
341 }
342
343#ifndef _XBOX
344 return D3DTexture->GetPriority();
345#else
346 return 0;
347#endif
348}
349
350
351//**********************************************************************************************
353
355unsigned int TextureBaseClass::Set_Priority(unsigned int priority)
356{
357 if (!D3DTexture)
358 {
359 WWASSERT_PRINT(0, "Set_Priority: D3DTexture is NULL!\n");
360 return 0;
361 }
362
363#ifndef _XBOX
364 return D3DTexture->SetPriority(priority);
365#else
366 return 0;
367#endif
368}
369
370
371//**********************************************************************************************
373
376{
377 // don't reduce if the texture is too small already or
378 // has no mip map levels
379 if (MipLevelCount==MIP_LEVELS_1) return 0;
380 if (Width <= 32 || Height <= 32) return 0;
381
382 int reduction=WW3D::Get_Texture_Reduction();
383
384 // 'large texture extra reduction' causes textures above 256x256 to be reduced one more step.
386 reduction++;
387 }
388 if (MipLevelCount && reduction>MipLevelCount) {
389 reduction=MipLevelCount;
390 }
391 return reduction;
392}
393
394
395
396//**********************************************************************************************
398
400void TextureBaseClass::Apply_Null(unsigned int stage)
401{
402 // This function sets the render states for a "NULL" texture
404}
405
406// ----------------------------------------------------------------------------
407// Setting HSV_Shift value is always relative to the original texture. This function invalidates the
408// texture surface and causes the texture to be reloaded. For thumbnailable textures, the hue shifting
409// is done in the background loading thread.
410// ----------------------------------------------------------------------------
412{
413 Invalidate();
414 HSVShift=hsv_shift;
415}
416
417//**********************************************************************************************
419
422{
423 int total_locked_surface_size=0;
424
426 // Loop through all the textures in the manager
427 for (ite.First ();!ite.Is_Done();ite.Next ())
428 {
429 // Get the current texture
430 TextureBaseClass* tex=ite.Peek_Value();
431 if (!tex->Initialized)
432 {
433 total_locked_surface_size+=tex->Get_Texture_Memory_Usage();
434 }
435 }
436 return total_locked_surface_size;
437}
438
439//**********************************************************************************************
441
444{
445 int total_texture_size=0;
446
448 // Loop through all the textures in the manager
449 for (ite.First ();!ite.Is_Done();ite.Next ())
450 {
451 // Get the current texture
452 TextureBaseClass* tex=ite.Peek_Value();
453 total_texture_size+=tex->Get_Texture_Memory_Usage();
454 }
455 return total_texture_size;
456}
457
458// ----------------------------------------------------------------------------
459
460
461//**********************************************************************************************
463
466{
467 int total_texture_size=0;
468
470 // Loop through all the textures in the manager
471 for (ite.First ();!ite.Is_Done();ite.Next ())
472 {
473 // Get the current texture
474 TextureBaseClass* tex=ite.Peek_Value();
475 if (tex->Is_Lightmap())
476 {
477 total_texture_size+=tex->Get_Texture_Memory_Usage();
478 }
479 }
480 return total_texture_size;
481}
482
483
484//**********************************************************************************************
486
489{
490 int total_texture_size=0;
491
493 // Loop through all the textures in the manager
494 for (ite.First ();!ite.Is_Done();ite.Next ())
495 {
496 // Get the current texture
497 TextureBaseClass* tex=ite.Peek_Value();
498 if (tex->Is_Procedural())
499 {
500 total_texture_size+=tex->Get_Texture_Memory_Usage();
501 }
502 }
503 return total_texture_size;
504}
505
506//**********************************************************************************************
508
511{
512 int texture_count=0;
513
515 // Loop through all the textures in the manager
516 for (ite.First ();!ite.Is_Done();ite.Next ())
517 {
518 texture_count++;
519 }
520
521 return texture_count;
522}
523
524// ----------------------------------------------------------------------------
525
526
527//**********************************************************************************************
529
532{
533 int texture_count=0;
534
536 // Loop through all the textures in the manager
537 for (ite.First ();!ite.Is_Done();ite.Next ())
538 {
539 if (ite.Peek_Value()->Is_Lightmap())
540 {
541 texture_count++;
542 }
543 }
544
545 return texture_count;
546}
547
548//**********************************************************************************************
550
553{
554 int texture_count=0;
555
557 // Loop through all the textures in the manager
558 for (ite.First ();!ite.Is_Done();ite.Next ())
559 {
560 if (ite.Peek_Value()->Is_Procedural())
561 {
562 texture_count++;
563 }
564 }
565
566 return texture_count;
567}
568
569
570//**********************************************************************************************
572
575{
576 int texture_count=0;
577
579 // Loop through all the textures in the manager
580 for (ite.First ();!ite.Is_Done();ite.Next ())
581 {
582 // Get the current texture
583 TextureBaseClass* tex=ite.Peek_Value();
584 if (!tex->Initialized)
585 {
586 texture_count++;
587 }
588 }
589
590 return texture_count;
591}
592
593/*************************************************************************
594** TextureClass
595*************************************************************************/
597(
598 unsigned width,
599 unsigned height,
600 WW3DFormat format,
601 MipCountType mip_level_count,
602 PoolType pool,
603 bool rendertarget,
604 bool allow_reduction
605)
606: TextureBaseClass(width, height, mip_level_count, pool, rendertarget,allow_reduction),
607 Filter(mip_level_count),
608 TextureFormat(format)
609{
610 Initialized=true;
611 IsProcedural=true;
612 IsReducible=false;
613
614 switch (format)
615 {
616 case WW3D_FORMAT_DXT1:
617 case WW3D_FORMAT_DXT2:
618 case WW3D_FORMAT_DXT3:
619 case WW3D_FORMAT_DXT4:
620 case WW3D_FORMAT_DXT5:
622 break;
623 default : break;
624 }
625
626 D3DPOOL d3dpool=(D3DPOOL)0;
627 switch(pool)
628 {
629 case POOL_DEFAULT : d3dpool=D3DPOOL_DEFAULT; break;
630 case POOL_MANAGED : d3dpool=D3DPOOL_MANAGED; break;
631 case POOL_SYSTEMMEM : d3dpool=D3DPOOL_SYSTEMMEM; break;
632 default: WWASSERT(0);
633 }
634
636 (
638 (
639 width,
640 height,
641 format,
642 mip_level_count,
643 d3dpool,
644 rendertarget
645 )
646 );
647
648 if (pool==POOL_DEFAULT)
649 {
650 Set_Dirty();
652 (
653 width,
654 height,
655 format,
656 mip_level_count,
657 this,
658 rendertarget
659 );
661 }
663}
664
665
666
667// ----------------------------------------------------------------------------
669(
670 const char *name,
671 const char *full_path,
672 MipCountType mip_level_count,
673 WW3DFormat texture_format,
674 bool allow_compression,
675 bool allow_reduction
676)
677: TextureBaseClass(0, 0, mip_level_count),
678 Filter(mip_level_count),
679 TextureFormat(texture_format)
680{
681 IsCompressionAllowed=allow_compression;
682 InactivationTime=DEFAULT_INACTIVATION_TIME; // Default inactivation time 30 seconds
683 IsReducible=allow_reduction;
684
685 switch (TextureFormat)
686 {
687 case WW3D_FORMAT_DXT1:
688 case WW3D_FORMAT_DXT2:
689 case WW3D_FORMAT_DXT3:
690 case WW3D_FORMAT_DXT4:
691 case WW3D_FORMAT_DXT5:
693 break;
694 case WW3D_FORMAT_U8V8: // Bumpmap
695 case WW3D_FORMAT_L6V5U5: // Bumpmap
696 case WW3D_FORMAT_X8L8V8U8: // Bumpmap
697 // If requesting bumpmap format that isn't available we'll just return the surface in whatever color
698 // format the texture file is in. (This is illegal case, the format support should always be queried
699 // before creating a bump texture!)
700 if (!DX8Wrapper::Is_Initted() || !DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(TextureFormat))
701 {
703 }
704 // If bump format is valid, make sure compression is not allowed so that we don't even attempt to load
705 // from a compressed file (quality isn't good enough for bump map). Also disable mipmapping.
706 else
707 {
711 }
712 break;
713 default: break;
714 }
715
716 WWASSERT_PRINT(name && name[0], "TextureClass CTor: NULL or empty texture name\n");
717 int len=strlen(name);
718 for (int i=0;i<len;++i)
719 {
720 if (name[i]=='+')
721 {
722 IsLightmap=true;
723
724 // Set bilinear filtering for lightmaps (they are very stretched and
725 // low detail so we don't care for anisotropic or trilinear filtering...)
728 if (mip_level_count!=MIP_LEVELS_1) Filter.Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_FAST);
729 break;
730 }
731 }
732 Set_Texture_Name(name);
733 Set_Full_Path(full_path);
734 WWASSERT(name[0]!='\0');
736 {
737 Initialized=true;
739 }
740
741 // Find original size from the thumbnail (but don't create thumbnail texture yet!)
743 if (thumb)
744 {
749 }
750 }
751
753
754 // If the thumbnails are not enabled, init the texture at this point to avoid stalling when the
755 // mesh is rendered.
757 {
759 {
760 Init();
761 }
762 }
763}
764
765// ----------------------------------------------------------------------------
767(
768 SurfaceClass *surface,
769 MipCountType mip_level_count
770)
771: TextureBaseClass(0,0,mip_level_count),
772 Filter(mip_level_count),
773 TextureFormat(surface->Get_Surface_Format())
774{
775 IsProcedural=true;
776 Initialized=true;
777 IsReducible=false;
778
780 surface->Get_Description(sd);
781 Width=sd.Width;
782 Height=sd.Height;
783 switch (sd.Format)
784 {
785 case WW3D_FORMAT_DXT1:
786 case WW3D_FORMAT_DXT2:
787 case WW3D_FORMAT_DXT3:
788 case WW3D_FORMAT_DXT4:
789 case WW3D_FORMAT_DXT5:
790 IsCompressionAllowed=true;
791 break;
792 default: break;
793 }
794
796 (
798 (
799 surface->Peek_D3D_Surface(),
800 mip_level_count
801 )
802 );
804}
805
806// ----------------------------------------------------------------------------
807TextureClass::TextureClass(IDirect3DBaseTexture8* d3d_texture)
809 (
810 0,
811 0,
812 ((MipCountType)d3d_texture->GetLevelCount())
813 ),
814 Filter((MipCountType)d3d_texture->GetLevelCount())
815{
816 Initialized=true;
817 IsProcedural=true;
818 IsReducible=false;
819
820 Set_D3D_Base_Texture(d3d_texture);
821 IDirect3DSurface8* surface;
822 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
823 D3DSURFACE_DESC d3d_desc;
824 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
825 DX8_ErrorCode(surface->GetDesc(&d3d_desc));
826 Width=d3d_desc.Width;
827 Height=d3d_desc.Height;
828 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
829 switch (TextureFormat)
830 {
831 case WW3D_FORMAT_DXT1:
832 case WW3D_FORMAT_DXT2:
833 case WW3D_FORMAT_DXT3:
834 case WW3D_FORMAT_DXT4:
835 case WW3D_FORMAT_DXT5:
837 break;
838 default: break;
839 }
840
842}
843
844//**********************************************************************************************
846
849{
850 // If the texture has already been initialised we should exit now
851 if (Initialized) return;
852
853 WWPROFILE("TextureClass::Init");
854
855 // If the texture has recently been inactivated, increase the inactivation time (this texture obviously
856 // should not have been inactivated yet).
858 {
860 {
862 }
864 }
865
866
867 if (!Peek_D3D_Base_Texture())
868 {
870 {
871// if (MipLevelCount==MIP_LEVELS_1) {
873 }
874 else
875 {
878 TextureFormat=format;
879 }
880 }
881
882 if (!Initialized)
883 {
885 }
886
888}
889
890//**********************************************************************************************
892
895(
896 IDirect3DBaseTexture8* d3d_texture,
897 bool initialized,
898 bool disable_auto_invalidation
899)
900{
901 IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();
902
903 if (d3d_tex) d3d_tex->Release();
904
905 Poke_Texture(d3d_texture);//TextureLoadTask->Peek_D3D_Texture();
906 d3d_texture->AddRef();
907
908 if (initialized) Initialized=true;
909 if (disable_auto_invalidation) InactivationTime = 0;
910
911 WWASSERT(d3d_texture);
912 IDirect3DSurface8* surface;
913 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
914 D3DSURFACE_DESC d3d_desc;
915 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
916 DX8_ErrorCode(surface->GetDesc(&d3d_desc));
917 if (initialized)
918 {
919 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
920 Width=d3d_desc.Width;
921 Height=d3d_desc.Height;
922 }
923 surface->Release();
924
925}
926
927
928//**********************************************************************************************
930
932void TextureClass::Apply(unsigned int stage)
933{
934 // Initialization needs to be done when texture is used if it hasn't been done before.
935 // XBOX always initializes textures at creation time.
936 if (!Initialized)
937 {
938 Init();
939
940 /* was in battlefield// Non-thumbnailed textures are always initialized when used
941 if (MipLevelCount==MIP_LEVELS_1)
942 {
943 }
944 // Thumbnailed textures have delayed initialization and a background loading system
945 else
946 {
947 // Limit the number of texture initializations per frame to reduce stuttering
948 if (TexturesAppliedPerFrame<MAX_TEXTURES_APPLIED_PER_FRAME)
949 {
950 TexturesAppliedPerFrame++;
951 Init();
952 }
953 else
954 {
955 // If texture can't be initialized in this frame, at least make sure we have the thumbnail.
956 if (!Peek_Texture())
957 {
958 WW3DFormat format=TextureFormat;
959 Load_Locked_Surface();
960 TextureFormat=format;
961 }
962 }
963 }*/
964 }
966
967 DX8_RECORD_TEXTURE(this);
968
969 // Set texture itself
971 {
973 }
974 else
975 {
977 }
978
979 Filter.Apply(stage);
980}
981
982//**********************************************************************************************
984
987{
988 if (!Peek_D3D_Texture())
989 {
990 WWASSERT_PRINT(0, "Get_Surface_Level: D3DTexture is NULL!\n");
991 return 0;
992 }
993
994 IDirect3DSurface8 *d3d_surface = NULL;
995 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));
996 SurfaceClass *surface = new SurfaceClass(d3d_surface);
997 d3d_surface->Release();
998
999 return surface;
1000}
1001
1002//**********************************************************************************************
1004
1007{
1008 SurfaceClass * surf = Get_Surface_Level(level);
1009 if (surf != NULL) {
1010 surf->Get_Description(desc);
1011 }
1012 REF_PTR_RELEASE(surf);
1013}
1014
1015//**********************************************************************************************
1017
1019IDirect3DSurface8 *TextureClass::Get_D3D_Surface_Level(unsigned int level)
1020{
1021 if (!Peek_D3D_Texture())
1022 {
1023 WWASSERT_PRINT(0, "Get_D3D_Surface_Level: D3DTexture is NULL!\n");
1024 return 0;
1025 }
1026
1027 IDirect3DSurface8 *d3d_surface = NULL;
1028 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));
1029 return d3d_surface;
1030}
1031
1032//**********************************************************************************************
1034
1037{
1038 int size=0;
1039 if (!Peek_D3D_Texture()) return 0;
1040 for (unsigned i=0;i<Peek_D3D_Texture()->GetLevelCount();++i)
1041 {
1042 D3DSURFACE_DESC desc;
1043 DX8_ErrorCode(Peek_D3D_Texture()->GetLevelDesc(i,&desc));
1044 size+=desc.Size;
1045 }
1046 return size;
1047}
1048
1049
1050// Utility functions
1052{
1053 // Assume failure
1054 TextureClass *newtex = NULL;
1055
1056 char name[256];
1057 if (cload.Open_Chunk () && (cload.Cur_Chunk_ID () == W3D_CHUNK_TEXTURE))
1058 {
1059
1060 W3dTextureInfoStruct texinfo;
1061 bool hastexinfo = false;
1062
1063 /*
1064 ** Read in the texture filename, and a possible texture info structure.
1065 */
1066 while (cload.Open_Chunk()) {
1067 switch (cload.Cur_Chunk_ID()) {
1069 cload.Read(&name,cload.Cur_Chunk_Length());
1070 break;
1071
1073 cload.Read(&texinfo,sizeof(W3dTextureInfoStruct));
1074 hastexinfo = true;
1075 break;
1076 };
1077 cload.Close_Chunk();
1078 }
1079 cload.Close_Chunk();
1080
1081 /*
1082 ** Get the texture from the asset manager
1083 */
1084 if (hastexinfo)
1085 {
1086
1087 MipCountType mipcount;
1088
1089 bool no_lod = ((texinfo.Attributes & W3DTEXTURE_NO_LOD) == W3DTEXTURE_NO_LOD);
1090
1091 if (no_lod)
1092 {
1093 mipcount = MIP_LEVELS_1;
1094 }
1095 else
1096 {
1097 switch (texinfo.Attributes & W3DTEXTURE_MIP_LEVELS_MASK) {
1098
1100 mipcount = MIP_LEVELS_ALL;
1101 break;
1102
1104 mipcount = MIP_LEVELS_2;
1105 break;
1106
1108 mipcount = MIP_LEVELS_3;
1109 break;
1110
1112 mipcount = MIP_LEVELS_4;
1113 break;
1114
1115 default:
1116 WWASSERT (false);
1117 mipcount = MIP_LEVELS_ALL;
1118 break;
1119 }
1120 }
1121
1123
1124 switch (texinfo.Attributes & W3DTEXTURE_TYPE_MASK)
1125 {
1126
1128 // Do nothing.
1129 break;
1130
1132 {
1133 if (DX8Wrapper::Is_Initted() && DX8Wrapper::Get_Current_Caps()->Support_Bump_Envmap())
1134 {
1135 // No mipmaps to bumpmap for now
1136 mipcount=MIP_LEVELS_1;
1137
1138 if (DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(WW3D_FORMAT_U8V8)) format=WW3D_FORMAT_U8V8;
1139 else if (DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(WW3D_FORMAT_X8L8V8U8)) format=WW3D_FORMAT_X8L8V8U8;
1140 else if (DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(WW3D_FORMAT_L6V5U5)) format=WW3D_FORMAT_L6V5U5;
1141 }
1142 break;
1143 }
1144
1145 default:
1146 WWASSERT (false);
1147 break;
1148 }
1149
1150 newtex = WW3DAssetManager::Get_Instance()->Get_Texture (name, mipcount, format);
1151
1152 if (no_lod)
1153 {
1155 }
1156 bool u_clamp = ((texinfo.Attributes & W3DTEXTURE_CLAMP_U) != 0);
1158 bool v_clamp = ((texinfo.Attributes & W3DTEXTURE_CLAMP_V) != 0);
1160
1161 } else
1162 {
1164 }
1165
1166 WWASSERT(newtex);
1167 }
1168
1169 // Return a pointer to the new texture
1170 return newtex;
1171}
1172
1173// Utility function used by Save_Texture
1182
1183
1185{
1186 const char * filename;
1187 W3dTextureInfoStruct texinfo;
1188 memset(&texinfo,0,sizeof(texinfo));
1189
1190 filename = texture->Get_Full_Path();
1191
1192 setup_texture_attributes(texture, &texinfo);
1193
1195 csave.Write(filename,strlen(filename)+1);
1196 csave.End_Chunk();
1197
1198 if ((texinfo.Attributes != 0) || (texinfo.AnimType != 0) || (texinfo.FrameCount != 0)) {
1200 csave.Write(&texinfo, sizeof(texinfo));
1201 csave.End_Chunk();
1202 }
1203}
1204
1205
1210(
1211 unsigned width,
1212 unsigned height,
1213 WW3DZFormat zformat,
1214 MipCountType mip_level_count,
1215 PoolType pool
1216)
1217: TextureBaseClass(width,height, mip_level_count, pool),
1218 DepthStencilTextureFormat(zformat)
1219{
1220 D3DPOOL d3dpool=(D3DPOOL)0;
1221 switch (pool)
1222 {
1223 case POOL_DEFAULT: d3dpool=D3DPOOL_DEFAULT; break;
1224 case POOL_MANAGED: d3dpool=D3DPOOL_MANAGED; break;
1225 case POOL_SYSTEMMEM: d3dpool=D3DPOOL_SYSTEMMEM; break;
1226 default: WWASSERT(0);
1227 }
1228
1230 (
1232 (
1233 width,
1234 height,
1235 zformat,
1236 mip_level_count,
1237 d3dpool
1238 )
1239 );
1240
1241 if (pool==POOL_DEFAULT)
1242 {
1243 Set_Dirty();
1245 (
1246 width,
1247 height,
1248 zformat,
1249 mip_level_count,
1250 this
1251 );
1253 }
1254 Initialized=true;
1255 IsProcedural=true;
1256 IsReducible=false;
1257
1259}
1260
1261
1262//**********************************************************************************************
1264
1266void ZTextureClass::Apply(unsigned int stage)
1267{
1269}
1270
1271//**********************************************************************************************
1273
1276(
1277 IDirect3DBaseTexture8* d3d_texture,
1278 bool initialized,
1279 bool disable_auto_invalidation
1280)
1281{
1282 IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();
1283
1284 if (d3d_tex) d3d_tex->Release();
1285
1286 Poke_Texture(d3d_texture);//TextureLoadTask->Peek_D3D_Texture();
1287 d3d_texture->AddRef();
1288
1289 if (initialized) Initialized=true;
1290 if (disable_auto_invalidation) InactivationTime = 0;
1291
1293 IDirect3DSurface8* surface;
1294 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
1295 D3DSURFACE_DESC d3d_desc;
1296 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
1297 DX8_ErrorCode(surface->GetDesc(&d3d_desc));
1298 if (initialized)
1299 {
1300 DepthStencilTextureFormat=D3DFormat_To_WW3DZFormat(d3d_desc.Format);
1301 Width=d3d_desc.Width;
1302 Height=d3d_desc.Height;
1303 }
1304 surface->Release();
1305}
1306
1307//**********************************************************************************************
1309
1311IDirect3DSurface8* ZTextureClass::Get_D3D_Surface_Level(unsigned int level)
1312{
1313 if (!Peek_D3D_Texture())
1314 {
1315 WWASSERT_PRINT(0, "Get_D3D_Surface_Level: D3DTexture is NULL!\n");
1316 return 0;
1317 }
1318
1319 IDirect3DSurface8 *d3d_surface = NULL;
1320 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(level, &d3d_surface));
1321 return d3d_surface;
1322}
1323
1324//**********************************************************************************************
1326
1329{
1330 int size=0;
1331 if (!Peek_D3D_Texture()) return 0;
1332 for (unsigned i=0;i<Peek_D3D_Texture()->GetLevelCount();++i)
1333 {
1334 D3DSURFACE_DESC desc;
1335 DX8_ErrorCode(Peek_D3D_Texture()->GetLevelDesc(i,&desc));
1336 size+=desc.Size;
1337 }
1338 return size;
1339}
1340
1341
1342
1343/*************************************************************************
1344** CubeTextureClass
1345*************************************************************************/
1347(
1348 unsigned width,
1349 unsigned height,
1350 WW3DFormat format,
1351 MipCountType mip_level_count,
1352 PoolType pool,
1353 bool rendertarget,
1354 bool allow_reduction
1355)
1356: TextureClass(width, height, format, mip_level_count, pool, rendertarget)
1357{
1358 Initialized=true;
1359 IsProcedural=true;
1360 IsReducible=false;
1361
1362 switch (format)
1363 {
1364 case WW3D_FORMAT_DXT1:
1365 case WW3D_FORMAT_DXT2:
1366 case WW3D_FORMAT_DXT3:
1367 case WW3D_FORMAT_DXT4:
1368 case WW3D_FORMAT_DXT5:
1370 break;
1371 default : break;
1372 }
1373
1374 D3DPOOL d3dpool=(D3DPOOL)0;
1375 switch(pool)
1376 {
1377 case POOL_DEFAULT : d3dpool=D3DPOOL_DEFAULT; break;
1378 case POOL_MANAGED : d3dpool=D3DPOOL_MANAGED; break;
1379 case POOL_SYSTEMMEM : d3dpool=D3DPOOL_SYSTEMMEM; break;
1380 default: WWASSERT(0);
1381 }
1382
1384 (
1386 (
1387 width,
1388 height,
1389 format,
1390 mip_level_count,
1391 d3dpool,
1392 rendertarget
1393 )
1394 );
1395
1396 if (pool==POOL_DEFAULT)
1397 {
1398 Set_Dirty();
1400 (
1401 width,
1402 height,
1403 format,
1404 mip_level_count,
1405 this,
1406 rendertarget
1407 );
1409 }
1411}
1412
1413
1414
1415// ----------------------------------------------------------------------------
1417(
1418 const char *name,
1419 const char *full_path,
1420 MipCountType mip_level_count,
1421 WW3DFormat texture_format,
1422 bool allow_compression,
1423 bool allow_reduction
1424)
1425: TextureClass(0,0,mip_level_count, POOL_MANAGED, false, texture_format)
1426{
1427 IsCompressionAllowed=allow_compression;
1428 InactivationTime=DEFAULT_INACTIVATION_TIME; // Default inactivation time 30 seconds
1429
1430 switch (TextureFormat)
1431 {
1432 case WW3D_FORMAT_DXT1:
1433 case WW3D_FORMAT_DXT2:
1434 case WW3D_FORMAT_DXT3:
1435 case WW3D_FORMAT_DXT4:
1436 case WW3D_FORMAT_DXT5:
1438 break;
1439 case WW3D_FORMAT_U8V8: // Bumpmap
1440 case WW3D_FORMAT_L6V5U5: // Bumpmap
1441 case WW3D_FORMAT_X8L8V8U8: // Bumpmap
1442 // If requesting bumpmap format that isn't available we'll just return the surface in whatever color
1443 // format the texture file is in. (This is illegal case, the format support should always be queried
1444 // before creating a bump texture!)
1445 if (!DX8Wrapper::Is_Initted() || !DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(TextureFormat))
1446 {
1448 }
1449 // If bump format is valid, make sure compression is not allowed so that we don't even attempt to load
1450 // from a compressed file (quality isn't good enough for bump map). Also disable mipmapping.
1451 else
1452 {
1456 }
1457 break;
1458 default: break;
1459 }
1460
1461 WWASSERT_PRINT(name && name[0], "TextureClass CTor: NULL or empty texture name\n");
1462 int len=strlen(name);
1463 for (int i=0;i<len;++i)
1464 {
1465 if (name[i]=='+')
1466 {
1467 IsLightmap=true;
1468
1469 // Set bilinear filtering for lightmaps (they are very stretched and
1470 // low detail so we don't care for anisotropic or trilinear filtering...)
1473 if (mip_level_count!=MIP_LEVELS_1) Filter.Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_FAST);
1474 break;
1475 }
1476 }
1477 Set_Texture_Name(name);
1478 Set_Full_Path(full_path);
1479 WWASSERT(name[0]!='\0');
1481 {
1482 Initialized=true;
1484 }
1485
1486 // Find original size from the thumbnail (but don't create thumbnail texture yet!)
1488 if (thumb)
1489 {
1494 }
1495 }
1496
1498
1499 // If the thumbnails are not enabled, init the texture at this point to avoid stalling when the
1500 // mesh is rendered.
1502 {
1504 {
1505 Init();
1506 }
1507 }
1508}
1509
1510// don't know if these are needed
1511#if 0
1512// ----------------------------------------------------------------------------
1514(
1515 SurfaceClass *surface,
1516 MipCountType mip_level_count
1517)
1518: TextureClass(0,0,mip_level_count, POOL_MANAGED, false, surface->Get_Surface_Format())
1519{
1520 IsProcedural=true;
1521 Initialized=true;
1522 IsReducible=false;
1523
1525 surface->Get_Description(sd);
1526 Width=sd.Width;
1527 Height=sd.Height;
1528 switch (sd.Format)
1529 {
1530 case WW3D_FORMAT_DXT1:
1531 case WW3D_FORMAT_DXT2:
1532 case WW3D_FORMAT_DXT3:
1533 case WW3D_FORMAT_DXT4:
1534 case WW3D_FORMAT_DXT5:
1535 IsCompressionAllowed=true;
1536 break;
1537 default: break;
1538 }
1539
1541 (
1543 (
1544 surface->Peek_D3D_Surface(),
1545 mip_level_count
1546 )
1547 );
1549}
1550
1551// ----------------------------------------------------------------------------
1552CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)
1554 (
1555 0,
1556 0,
1557 ((MipCountType)d3d_texture->GetLevelCount())
1558 ),
1559 Filter((MipCountType)d3d_texture->GetLevelCount())
1560{
1561 Initialized=true;
1562 IsProcedural=true;
1563 IsReducible=false;
1564
1565 Peek_Texture()->AddRef();
1566 IDirect3DSurface8* surface;
1567 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
1568 D3DSURFACE_DESC d3d_desc;
1569 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
1570 DX8_ErrorCode(surface->GetDesc(&d3d_desc));
1571 Width=d3d_desc.Width;
1572 Height=d3d_desc.Height;
1573 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
1574 switch (TextureFormat)
1575 {
1576 case WW3D_FORMAT_DXT1:
1577 case WW3D_FORMAT_DXT2:
1578 case WW3D_FORMAT_DXT3:
1579 case WW3D_FORMAT_DXT4:
1580 case WW3D_FORMAT_DXT5:
1582 break;
1583 default: break;
1584 }
1585
1587}
1588#endif
1589
1590//**********************************************************************************************
1592
1595(
1596 IDirect3DBaseTexture8* d3d_texture,
1597 bool initialized,
1598 bool disable_auto_invalidation
1599)
1600{
1601 IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();
1602
1603 if (d3d_tex) d3d_tex->Release();
1604
1605 Poke_Texture(d3d_texture);//TextureLoadTask->Peek_D3D_Texture();
1606 d3d_texture->AddRef();
1607
1608 if (initialized) Initialized=true;
1609 if (disable_auto_invalidation) InactivationTime = 0;
1610
1611 WWASSERT(d3d_texture);
1612 D3DSURFACE_DESC d3d_desc;
1613 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
1614 DX8_ErrorCode(Peek_D3D_CubeTexture()->GetLevelDesc(0,&d3d_desc));
1615
1616 if (initialized)
1617 {
1618 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
1619 Width=d3d_desc.Width;
1620 Height=d3d_desc.Height;
1621 }
1622}
1623
1624
1625/*************************************************************************
1626** VolumeTextureClass
1627*************************************************************************/
1629(
1630 unsigned width,
1631 unsigned height,
1632 unsigned depth,
1633 WW3DFormat format,
1634 MipCountType mip_level_count,
1635 PoolType pool,
1636 bool rendertarget,
1637 bool allow_reduction
1638)
1639: TextureClass(width, height, format, mip_level_count, pool, rendertarget),
1640 Depth(depth)
1641{
1642 Initialized=true;
1643 IsProcedural=true;
1644 IsReducible=false;
1645
1646 switch (format)
1647 {
1648 case WW3D_FORMAT_DXT1:
1649 case WW3D_FORMAT_DXT2:
1650 case WW3D_FORMAT_DXT3:
1651 case WW3D_FORMAT_DXT4:
1652 case WW3D_FORMAT_DXT5:
1654 break;
1655 default : break;
1656 }
1657
1658 D3DPOOL d3dpool=(D3DPOOL)0;
1659 switch(pool)
1660 {
1661 case POOL_DEFAULT : d3dpool=D3DPOOL_DEFAULT; break;
1662 case POOL_MANAGED : d3dpool=D3DPOOL_MANAGED; break;
1663 case POOL_SYSTEMMEM : d3dpool=D3DPOOL_SYSTEMMEM; break;
1664 default: WWASSERT(0);
1665 }
1666
1668 (
1670 (
1671 width,
1672 height,
1673 depth,
1674 format,
1675 mip_level_count,
1676 d3dpool
1677 )
1678 );
1679
1680 if (pool==POOL_DEFAULT)
1681 {
1682 Set_Dirty();
1684 (
1685 width,
1686 height,
1687 format,
1688 mip_level_count,
1689 this,
1690 rendertarget
1691 );
1693 }
1695}
1696
1697
1698
1699// ----------------------------------------------------------------------------
1701(
1702 const char *name,
1703 const char *full_path,
1704 MipCountType mip_level_count,
1705 WW3DFormat texture_format,
1706 bool allow_compression,
1707 bool allow_reduction
1708)
1709: TextureClass(0,0,mip_level_count, POOL_MANAGED, false, texture_format),
1710 Depth(0)
1711{
1712 IsCompressionAllowed=allow_compression;
1713 InactivationTime=DEFAULT_INACTIVATION_TIME; // Default inactivation time 30 seconds
1714
1715 switch (TextureFormat)
1716 {
1717 case WW3D_FORMAT_DXT1:
1718 case WW3D_FORMAT_DXT2:
1719 case WW3D_FORMAT_DXT3:
1720 case WW3D_FORMAT_DXT4:
1721 case WW3D_FORMAT_DXT5:
1723 break;
1724 case WW3D_FORMAT_U8V8: // Bumpmap
1725 case WW3D_FORMAT_L6V5U5: // Bumpmap
1726 case WW3D_FORMAT_X8L8V8U8: // Bumpmap
1727 // If requesting bumpmap format that isn't available we'll just return the surface in whatever color
1728 // format the texture file is in. (This is illegal case, the format support should always be queried
1729 // before creating a bump texture!)
1730 if (!DX8Wrapper::Is_Initted() || !DX8Wrapper::Get_Current_Caps()->Support_Texture_Format(TextureFormat))
1731 {
1733 }
1734 // If bump format is valid, make sure compression is not allowed so that we don't even attempt to load
1735 // from a compressed file (quality isn't good enough for bump map). Also disable mipmapping.
1736 else
1737 {
1741 }
1742 break;
1743 default: break;
1744 }
1745
1746 WWASSERT_PRINT(name && name[0], "TextureClass CTor: NULL or empty texture name\n");
1747 int len=strlen(name);
1748 for (int i=0;i<len;++i)
1749 {
1750 if (name[i]=='+')
1751 {
1752 IsLightmap=true;
1753
1754 // Set bilinear filtering for lightmaps (they are very stretched and
1755 // low detail so we don't care for anisotropic or trilinear filtering...)
1758 if (mip_level_count!=MIP_LEVELS_1) Filter.Set_Mip_Mapping(TextureFilterClass::FILTER_TYPE_FAST);
1759 break;
1760 }
1761 }
1762 Set_Texture_Name(name);
1763 Set_Full_Path(full_path);
1764 WWASSERT(name[0]!='\0');
1766 {
1767 Initialized=true;
1769 }
1770
1771 // Find original size from the thumbnail (but don't create thumbnail texture yet!)
1773 if (thumb)
1774 {
1779 }
1780 }
1781
1783
1784 // If the thumbnails are not enabled, init the texture at this point to avoid stalling when the
1785 // mesh is rendered.
1787 {
1789 {
1790 Init();
1791 }
1792 }
1793}
1794
1795// don't know if these are needed
1796#if 0
1797// ----------------------------------------------------------------------------
1799(
1800 SurfaceClass *surface,
1801 MipCountType mip_level_count
1802)
1803: TextureClass(0,0,mip_level_count, POOL_MANAGED, false, surface->Get_Surface_Format())
1804{
1805 IsProcedural=true;
1806 Initialized=true;
1807 IsReducible=false;
1808
1810 surface->Get_Description(sd);
1811 Width=sd.Width;
1812 Height=sd.Height;
1813 switch (sd.Format)
1814 {
1815 case WW3D_FORMAT_DXT1:
1816 case WW3D_FORMAT_DXT2:
1817 case WW3D_FORMAT_DXT3:
1818 case WW3D_FORMAT_DXT4:
1819 case WW3D_FORMAT_DXT5:
1820 IsCompressionAllowed=true;
1821 break;
1822 default: break;
1823 }
1824
1826 (
1828 (
1829 surface->Peek_D3D_Surface(),
1830 mip_level_count
1831 )
1832 );
1834}
1835
1836// ----------------------------------------------------------------------------
1837CubeTextureClass::CubeTextureClass(IDirect3DBaseTexture8* d3d_texture)
1839 (
1840 0,
1841 0,
1842 ((MipCountType)d3d_texture->GetLevelCount())
1843 ),
1844 Filter((MipCountType)d3d_texture->GetLevelCount())
1845{
1846 Initialized=true;
1847 IsProcedural=true;
1848 IsReducible=false;
1849
1850 Peek_Texture()->AddRef();
1851 IDirect3DSurface8* surface;
1852 DX8_ErrorCode(Peek_D3D_Texture()->GetSurfaceLevel(0,&surface));
1853 D3DSURFACE_DESC d3d_desc;
1854 ::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
1855 DX8_ErrorCode(surface->GetDesc(&d3d_desc));
1856 Width=d3d_desc.Width;
1857 Height=d3d_desc.Height;
1858 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
1859 switch (TextureFormat)
1860 {
1861 case WW3D_FORMAT_DXT1:
1862 case WW3D_FORMAT_DXT2:
1863 case WW3D_FORMAT_DXT3:
1864 case WW3D_FORMAT_DXT4:
1865 case WW3D_FORMAT_DXT5:
1867 break;
1868 default: break;
1869 }
1870
1872}
1873#endif
1874
1875
1876
1877
1878//**********************************************************************************************
1880
1883(
1884 IDirect3DBaseTexture8* d3d_texture,
1885 bool initialized,
1886 bool disable_auto_invalidation
1887)
1888{
1889 IDirect3DBaseTexture8* d3d_tex=Peek_D3D_Base_Texture();
1890
1891 if (d3d_tex) d3d_tex->Release();
1892
1893 Poke_Texture(d3d_texture);//TextureLoadTask->Peek_D3D_Texture();
1894 d3d_texture->AddRef();
1895
1896 if (initialized) Initialized=true;
1897 if (disable_auto_invalidation) InactivationTime = 0;
1898
1899 WWASSERT(d3d_texture);
1900 D3DVOLUME_DESC d3d_desc;
1901 ::ZeroMemory(&d3d_desc, sizeof(D3DVOLUME_DESC));
1902
1903 DX8_ErrorCode(Peek_D3D_VolumeTexture()->GetLevelDesc(0,&d3d_desc));
1904
1905 if (initialized)
1906 {
1907 TextureFormat=D3DFormat_To_WW3DFormat(d3d_desc.Format);
1908 Width=d3d_desc.Width;
1909 Height=d3d_desc.Height;
1910 Depth=d3d_desc.Depth;
1911 }
1912}
#define NULL
Definition BaseType.h:92
#define DX8_RECORD_TEXTURE(t)
Definition statistics.h:74
#define WWASSERT
#define W3DTEXTURE_CLAMP_U
Definition w3d_file.h:1004
#define W3DTEXTURE_MIP_LEVELS_MASK
Definition w3d_file.h:1009
#define W3DTEXTURE_MIP_LEVELS_ALL
Definition w3d_file.h:1010
#define W3DTEXTURE_MIP_LEVELS_3
Definition w3d_file.h:1012
#define W3DTEXTURE_MIP_LEVELS_2
Definition w3d_file.h:1011
#define W3DTEXTURE_CLAMP_V
Definition w3d_file.h:1005
#define W3DTEXTURE_TYPE_BUMPMAP
Definition w3d_file.h:1027
#define W3DTEXTURE_MIP_LEVELS_4
Definition w3d_file.h:1013
#define W3DTEXTURE_NO_LOD
Definition w3d_file.h:1003
#define W3DTEXTURE_TYPE_MASK
Definition w3d_file.h:1025
@ W3D_CHUNK_TEXTURE_NAME
Definition w3d_file.h:368
@ W3D_CHUNK_TEXTURE_INFO
Definition w3d_file.h:369
@ W3D_CHUNK_TEXTURE
Definition w3d_file.h:367
#define W3DTEXTURE_TYPE_COLORMAP
Definition w3d_file.h:1026
@ false
Definition bool.h:59
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Cur_Chunk_Length()
Definition chunkio.cpp:503
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
uint32 Write(const void *buf, uint32 nbytes)
Definition chunkio.cpp:264
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
virtual void Apply_New_Surface(IDirect3DBaseTexture8 *tex, bool initialized, bool disable_auto_invalidation=false)
Apply new surface to texture.
Definition texture.cpp:1595
CubeTextureClass(unsigned width, unsigned height, WW3DFormat format, MipCountType mip_level_count=MIP_LEVELS_ALL, PoolType pool=POOL_MANAGED, bool rendertarget=false, bool allow_reduction=true)
Definition texture.cpp:1347
static void Remove(TextureBaseClass *tex)
static void Add(TextureTrackerClass *track)
static bool Is_Initted(void)
Definition dx8wrapper.h:270
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 const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
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 void Set_DX8_Texture(unsigned int stage, IDirect3DBaseTexture8 *texture)
Definition dx8wrapper.h:924
static IDirect3DTexture8 * _Create_DX8_ZTexture(unsigned int width, unsigned int height, WW3DZFormat zformat, MipCountType mip_level_count, D3DPOOL pool=D3DPOOL_MANAGED)
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)
ValueType & Peek_Value()
static IDirect3DTexture8 * _Get_Missing_Texture()
void Get_Description(SurfaceDescription &surface_desc)
IDirect3DSurface8 * Peek_D3D_Surface(void)
bool Is_Missing_Texture()
Is missing texture.
Definition texture.cpp:302
unsigned Get_Reduction() const
Get reduction mip levels.
Definition texture.cpp:375
static int _Get_Total_Procedural_Texture_Count()
Get total procedural texture count.
Definition texture.cpp:552
IDirect3DTexture8 * Peek_D3D_Texture() const
Definition texture.h:205
friend class DX8TextureTrackerClass
Definition texture.h:75
bool Is_Procedural() const
Definition texture.h:147
static int _Get_Total_Procedural_Texture_Size()
Get total procedural texture size.
Definition texture.cpp:488
static int _Get_Total_Texture_Size()
Get total texture size.
Definition texture.cpp:443
MipCountType MipLevelCount
Definition texture.h:187
unsigned int Get_Priority(void)
Get priority.
Definition texture.cpp:335
IDirect3DVolumeTexture8 * Peek_D3D_VolumeTexture() const
Definition texture.h:206
unsigned int Set_Priority(unsigned int priority)
Set priority.
Definition texture.cpp:355
static void Apply_Null(unsigned int stage)
Apply NULL texture state.
Definition texture.cpp:400
IDirect3DBaseTexture8 * Peek_D3D_Base_Texture() const
Returns a pointer to the d3d texture.
Definition texture.cpp:258
unsigned LastAccessed
Definition texture.h:226
void Set_D3D_Base_Texture(IDirect3DBaseTexture8 *tex)
Set the d3d texture pointer. Handles ref counts properly.
Definition texture.cpp:268
static void Invalidate_Old_Unused_Textures(unsigned inactive_time_override)
Invalidate old unused textures.
Definition texture.cpp:142
const StringClass & Get_Full_Path(void) const
Definition texture.h:113
void Set_HSV_Shift(const Vector3 &hsv_shift)
Definition texture.cpp:411
void Invalidate()
Invalidate this texture.
Definition texture.cpp:194
void Set_Full_Path(const char *path)
Definition texture.h:111
static int _Get_Total_Lightmap_Texture_Size()
Get total lightmap texture size.
Definition texture.cpp:465
static int _Get_Total_Texture_Count()
Get total texture count.
Definition texture.cpp:510
virtual ~TextureBaseClass()
Base texture class destructor.
Definition texture.cpp:119
void Set_Texture_Name(const char *name)
Set texture name.
Definition texture.cpp:323
unsigned LastInactivationSyncTime
Definition texture.h:225
Vector3 HSVShift
Definition texture.h:231
bool IsCompressionAllowed
Definition texture.h:218
void Poke_Texture(IDirect3DBaseTexture8 *tex)
Definition texture.h:212
void Set_Dirty()
Definition texture.h:174
static int _Get_Total_Lightmap_Texture_Count()
Get total light map texture count.
Definition texture.cpp:531
unsigned InactivationTime
Definition texture.h:223
TextureBaseClass(unsigned width, unsigned height, MipCountType mip_level_count=MIP_LEVELS_ALL, PoolType pool=POOL_MANAGED, bool rendertarget=false, bool reducible=true)
Definition texture.cpp:82
friend class DX8ZTextureTrackerClass
Definition texture.h:76
virtual unsigned Get_Texture_Memory_Usage() const =0
void Load_Locked_Surface()
Load locked surface.
Definition texture.cpp:288
static int _Get_Total_Locked_Surface_Size()
Get total locked surface size.
Definition texture.cpp:421
bool Is_Lightmap() const
Definition texture.h:146
static int _Get_Total_Locked_Surface_Count()
Get total locked surface count.
Definition texture.cpp:574
IDirect3DCubeTexture8 * Peek_D3D_CubeTexture() const
Definition texture.h:207
unsigned ExtendedInactivationTime
Definition texture.h:224
TextureFilterClass Filter
Definition texture.h:351
IDirect3DSurface8 * Get_D3D_Surface_Level(unsigned int level=0)
Get D3D surface from mip level.
Definition texture.cpp:1019
virtual unsigned Get_Texture_Memory_Usage() const
Get texture memory usage.
Definition texture.cpp:1036
void Get_Level_Description(SurfaceClass::SurfaceDescription &desc, unsigned int level=0)
Get surface description for a mip level.
Definition texture.cpp:1006
SurfaceClass * Get_Surface_Level(unsigned int level=0)
Get surface from mip level.
Definition texture.cpp:986
TextureClass(unsigned width, unsigned height, WW3DFormat format, MipCountType mip_level_count=MIP_LEVELS_ALL, PoolType pool=POOL_MANAGED, bool rendertarget=false, bool allow_reduction=true)
Definition texture.cpp:597
WW3DFormat TextureFormat
Definition texture.h:348
virtual void Init()
Initialise the texture.
Definition texture.cpp:848
TextureFilterClass & Get_Filter()
Definition texture.h:336
virtual void Apply(unsigned int stage)
Apply texture states.
Definition texture.cpp:932
virtual void Apply_New_Surface(IDirect3DBaseTexture8 *tex, bool initialized, bool disable_auto_invalidation=false)
Apply new surface to texture.
Definition texture.cpp:895
void Set_Mip_Mapping(FilterType mipmap)
Set mip mapping filter (legacy)
FilterType Get_Mip_Mapping(void) const
TxtAddrMode Get_U_Addr_Mode(void) const
void Set_V_Addr_Mode(TxtAddrMode mode)
TxtAddrMode Get_V_Addr_Mode(void) const
void Set_U_Addr_Mode(TxtAddrMode mode)
static void Request_Background_Loading(TextureBaseClass *tc)
static void Request_Thumbnail(TextureBaseClass *tc)
static bool Is_DX8_Thread(void)
static void Request_Foreground_Loading(TextureBaseClass *tc)
unsigned Get_Original_Texture_Mip_Level_Count() const
unsigned Get_Original_Texture_Height() const
unsigned Get_Original_Texture_Width() const
static ThumbnailClass * Peek_Thumbnail_Instance_From_Any_Manager(const StringClass &name)
VolumeTextureClass(unsigned width, unsigned height, unsigned depth, WW3DFormat format, MipCountType mip_level_count=MIP_LEVELS_ALL, PoolType pool=POOL_MANAGED, bool rendertarget=false, bool allow_reduction=true)
Definition texture.cpp:1629
virtual void Apply_New_Surface(IDirect3DBaseTexture8 *tex, bool initialized, bool disable_auto_invalidation=false)
Apply new surface to texture.
Definition texture.cpp:1883
virtual TextureClass * Get_Texture(const char *filename, MipCountType mip_level_count=MIP_LEVELS_ALL, WW3DFormat texture_format=WW3D_FORMAT_UNKNOWN, bool allow_compression=true, TextureBaseClass::TexAssetType type=TextureBaseClass::TEX_REGULAR, bool allow_reduction=true)
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
static unsigned int Get_Sync_Time(void)
Definition ww3d.h:172
static int Get_Texture_Reduction(void)
Definition ww3d.cpp:1794
static bool Is_Texturing_Enabled()
Definition ww3d.h:257
static bool Is_Large_Texture_Extra_Reduction_Enabled(void)
Definition ww3d.cpp:1824
static bool Get_Thumbnail_Enabled()
Definition ww3d.h:217
virtual void Apply_New_Surface(IDirect3DBaseTexture8 *tex, bool initialized, bool disable_auto_invalidation=false)
Apply new surface to texture.
Definition texture.cpp:1276
virtual unsigned Get_Texture_Memory_Usage() const
Get texture memory usage.
Definition texture.cpp:1328
IDirect3DSurface8 * Get_D3D_Surface_Level(unsigned int level=0)
Get D3D surface from mip level.
Definition texture.cpp:1311
virtual void Apply(unsigned int stage)
Apply depth stencil texture.
Definition texture.cpp:1266
ZTextureClass(unsigned width, unsigned height, WW3DZFormat zformat, MipCountType mip_level_count=MIP_LEVELS_ALL, PoolType pool=POOL_MANAGED)
Definition texture.cpp:1210
WWINLINE void DX8_ErrorCode(unsigned res)
Definition dx8wrapper.h:125
WW3DZFormat D3DFormat_To_WW3DZFormat(D3DFORMAT d3d_format)
D3D to Depth Stencil W3D format conversion.
Definition formconv.cpp:189
WW3DFormat D3DFormat_To_WW3DFormat(D3DFORMAT d3d_format)
Definition formconv.cpp:150
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
TextureClass * Load_Texture(ChunkLoadClass &cload)
Definition texture.cpp:1051
const unsigned MAX_TEXTURES_APPLIED_PER_FRAME
Definition texture.cpp:75
const unsigned DEFAULT_INACTIVATION_TIME
Definition texture.cpp:65
void Save_Texture(TextureClass *texture, ChunkSaveClass &csave)
Definition texture.cpp:1184
void setup_texture_attributes(TextureClass *tex, W3dTextureInfoStruct *texinfo)
Definition texture.cpp:1174
MipCountType
@ MIP_LEVELS_3
@ MIP_LEVELS_ALL
@ MIP_LEVELS_4
@ MIP_LEVELS_2
@ MIP_LEVELS_1
unsigned char flag
Definition vchannel.cpp:273
WW3DFormat
Definition ww3dformat.h:75
@ WW3D_FORMAT_X8L8V8U8
Definition ww3dformat.h:95
@ WW3D_FORMAT_DXT3
Definition ww3dformat.h:98
@ WW3D_FORMAT_DXT2
Definition ww3dformat.h:97
@ WW3D_FORMAT_DXT5
Definition ww3dformat.h:100
@ WW3D_FORMAT_UNKNOWN
Definition ww3dformat.h:76
@ WW3D_FORMAT_L6V5U5
Definition ww3dformat.h:94
@ WW3D_FORMAT_DXT4
Definition ww3dformat.h:99
@ WW3D_FORMAT_DXT1
Definition ww3dformat.h:96
@ WW3D_FORMAT_U8V8
Definition ww3dformat.h:93
WW3DZFormat
Definition ww3dformat.h:106
#define WWASSERT_PRINT(expr, string)
Definition wwdebug.h:135
#define WWPROFILE(name)
Definition wwprofile.h:270