Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
texturefilter.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:: ww3d2/texturefilter.cpp $*
26 * *
27 * $Org Author:: Kenny Mitchell $*
28 * *
29 * Author : Kenny Mitchell *
30 * *
31 * $Modtime:: 08/05/02 1:27p $*
32 * *
33 * $Revision:: 1 $*
34 * *
35 * 08/05/02 KM Texture filter class abstraction *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include "texturefilter.h"
41#include "dx8wrapper.h"
42
46
47/*************************************************************************
48** TextureFilterClass
49*************************************************************************/
51: TextureMinFilter(FILTER_TYPE_DEFAULT),
52 TextureMagFilter(FILTER_TYPE_DEFAULT),
53 UAddressMode(TEXTURE_ADDRESS_REPEAT),
54 VAddressMode(TEXTURE_ADDRESS_REPEAT)
55{
56 if (mip_level_count!=MIP_LEVELS_1)
57 {
58 MipMapFilter=FILTER_TYPE_DEFAULT;
59 }
60 else
61 {
62 MipMapFilter=FILTER_TYPE_NONE;
63 }
64}
65
66//**********************************************************************************************
68
70void TextureFilterClass::Apply(unsigned int stage)
71{
72 DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MINFILTER,_MinTextureFilters[stage][TextureMinFilter]);
73 DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MAGFILTER,_MagTextureFilters[stage][TextureMagFilter]);
74 DX8Wrapper::Set_DX8_Texture_Stage_State(stage,D3DTSS_MIPFILTER,_MipMapFilters[stage][MipMapFilter]);
75
76 switch (Get_U_Addr_Mode())
77 {
79 DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
80 break;
81
83 DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
84 break;
85 }
86
87 switch (Get_V_Addr_Mode())
88 {
90 DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
91 break;
92
94 DX8Wrapper::Set_DX8_Texture_Stage_State(stage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
95 break;
96 }
97}
98
99//**********************************************************************************************
101
104{
105 const D3DCAPS8& dx8caps=DX8Wrapper::Get_Current_Caps()->Get_DX8_Caps();
106
107#ifndef _XBOX
108 _MinTextureFilters[0][FILTER_TYPE_NONE]=D3DTEXF_POINT;
109 _MagTextureFilters[0][FILTER_TYPE_NONE]=D3DTEXF_POINT;
110 _MipMapFilters[0][FILTER_TYPE_NONE]=D3DTEXF_NONE;
111
112 _MinTextureFilters[0][FILTER_TYPE_FAST]=D3DTEXF_LINEAR;
113 _MagTextureFilters[0][FILTER_TYPE_FAST]=D3DTEXF_LINEAR;
114 _MipMapFilters[0][FILTER_TYPE_FAST]=D3DTEXF_POINT;
115
116 _MagTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_POINT;
117 _MinTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_POINT;
118 _MipMapFilters[0][FILTER_TYPE_BEST]=D3DTEXF_POINT;
119#else
120 _MinTextureFilters[0][FILTER_TYPE_NONE]=D3DTEXF_ANISOTROPIC;
121 _MagTextureFilters[0][FILTER_TYPE_NONE]=D3DTEXF_ANISOTROPIC;
122 _MipMapFilters[0][FILTER_TYPE_NONE]=D3DTEXF_LINEAR;
123
124 _MinTextureFilters[0][FILTER_TYPE_FAST]=D3DTEXF_ANISOTROPIC;
125 _MagTextureFilters[0][FILTER_TYPE_FAST]=D3DTEXF_ANISOTROPIC;
126 _MipMapFilters[0][FILTER_TYPE_FAST]=D3DTEXF_LINEAR;
127
128 _MagTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_ANISOTROPIC;
129 _MinTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_ANISOTROPIC;
130 _MipMapFilters[0][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
131#endif
132
133#ifndef _XBOX
134 if (dx8caps.TextureFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR) _MagTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
135 if (dx8caps.TextureFilterCaps&D3DPTFILTERCAPS_MINFLINEAR) _MinTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
136
137 // Set anisotropic filtering only if requested and available
138 if (filter_type==TEXTURE_FILTER_ANISOTROPIC) {
139 if (dx8caps.TextureFilterCaps&D3DPTFILTERCAPS_MAGFANISOTROPIC) _MagTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_ANISOTROPIC;
140 if (dx8caps.TextureFilterCaps&D3DPTFILTERCAPS_MINFANISOTROPIC) _MinTextureFilters[0][FILTER_TYPE_BEST]=D3DTEXF_ANISOTROPIC;
141 }
142
143 // Set linear mip filter only if requested trilinear or anisotropic, and linear available
144 if (filter_type==TEXTURE_FILTER_ANISOTROPIC || filter_type==TEXTURE_FILTER_TRILINEAR) {
145 if (dx8caps.TextureFilterCaps&D3DPTFILTERCAPS_MIPFLINEAR) _MipMapFilters[0][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
146 }
147#endif
148
149 // For stages above zero, set best filter to the same as the stage zero, except if anisotropic
150 for (int i=1;i<MAX_TEXTURE_STAGES;++i) {
151/* _MinTextureFilters[i][FILTER_TYPE_NONE]=D3DTEXF_POINT;
152 _MagTextureFilters[i][FILTER_TYPE_NONE]=D3DTEXF_POINT;
153 _MipMapFilters[i][FILTER_TYPE_NONE]=D3DTEXF_NONE;
154
155 _MinTextureFilters[i][FILTER_TYPE_FAST]=D3DTEXF_LINEAR;
156 _MagTextureFilters[i][FILTER_TYPE_FAST]=D3DTEXF_LINEAR;
157 _MipMapFilters[i][FILTER_TYPE_FAST]=D3DTEXF_POINT;
158
159 _MagTextureFilters[i][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
160 _MinTextureFilters[i][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
161 _MipMapFilters[i][FILTER_TYPE_BEST]=D3DTEXF_POINT;
162*/
166
170
171 if (_MagTextureFilters[i-1][FILTER_TYPE_BEST]==D3DTEXF_ANISOTROPIC) {
172 _MagTextureFilters[i][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
173 }
174 else {
176 }
177
178 if (_MinTextureFilters[i-1][FILTER_TYPE_BEST]==D3DTEXF_ANISOTROPIC) {
179 _MinTextureFilters[i][FILTER_TYPE_BEST]=D3DTEXF_LINEAR;
180 }
181 else {
183 }
185
186
187 }
188
189 // Set default to best. The level of best filter mode is controlled by the input parameter.
190 for (i=0;i<MAX_TEXTURE_STAGES;++i) {
194
195 DX8Wrapper::Set_DX8_Texture_Stage_State(i,D3DTSS_MAXANISOTROPY,2);
196 }
197
198}
199
200
201//**********************************************************************************************
203
206{
207// if (mipmap != FILTER_TYPE_NONE && Get_Mip_Level_Count() <= 1 && Is_Initialized())
208// {
209// WWASSERT_PRINT(0, "Trying to enable MipMapping on texture w/o Mip levels!\n");
210// return;
211// }
212 MipMapFilter=mipmap;
213}
214
215//**********************************************************************************************
217
226
227
228//**********************************************************************************************
230
239
240//**********************************************************************************************
242
D3DCAPS8 const & Get_DX8_Caps() const
Definition dx8caps.h:251
static const DX8Caps * Get_Current_Caps()
Definition dx8wrapper.h:536
static void Set_DX8_Texture_Stage_State(unsigned stage, D3DTEXTURESTAGESTATETYPE state, unsigned value)
Definition dx8wrapper.h:899
void Apply(unsigned int stage)
Apply filters (legacy)
static void _Set_Default_Mip_Filter(FilterType filter)
Set default mip filter (legacy)
static void _Init_Filters(TextureFilterMode texture_filter)
Init filters (legacy)
static void _Set_Default_Min_Filter(FilterType filter)
Set default min filter (legacy)
void Set_Mip_Mapping(FilterType mipmap)
Set mip mapping filter (legacy)
static void _Set_Default_Mag_Filter(FilterType filter)
Set default mag filter (legacy)
TxtAddrMode Get_U_Addr_Mode(void) const
TxtAddrMode Get_V_Addr_Mode(void) const
TextureFilterClass(MipCountType mip_level_count)
const unsigned MAX_TEXTURE_STAGES
Definition dx8wrapper.h:76
unsigned _MinTextureFilters[MAX_TEXTURE_STAGES][TextureFilterClass::FILTER_TYPE_COUNT]
unsigned _MagTextureFilters[MAX_TEXTURE_STAGES][TextureFilterClass::FILTER_TYPE_COUNT]
unsigned _MipMapFilters[MAX_TEXTURE_STAGES][TextureFilterClass::FILTER_TYPE_COUNT]
MipCountType
@ MIP_LEVELS_1
unsigned char filter
Definition vchannel.cpp:272