1 /*
2
3 Memonix, Viewizard Game Core ver 2.0
4 Copyright (c) 2001-2006 Michael Kurinnoy, Viewizard Games
5 All Rights Reserved.
6
7 Memonix game source codes available under "dual licensing" model.
8 The licensing options available are:
9
10 * Commercial Licensing. This is the appropriate option if you are creating proprietary
11 applications and you are not prepared to distribute and share the source code of your application.
12 Contact us for pricing at viewizard@viewizard.com
13
14 * Open Source Licensing. This is the appropriate option if you want to share the source code of
15 your application with everyone you distribute it to, and you also want to give them the right to share who uses it.
16 You should have received a copy of the GNU General Public License version 3 with this source codes. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20 #include "../../Core.h"
21 #include "Texture.h"
22
23
24
25
26 //------------------------------------------------------------------------------------
27 // переменные
28 //------------------------------------------------------------------------------------
29 eTexture *StartTexMan = 0;// Указатель на первую текстуру в списке...
30 eTexture *EndTexMan = 0; // Указатель на последнюю текстуру в списке...
31 int NumTexMan = 0; // Последний использов. уникальный номер
32 // Ключ прорисовки текстуры (near, linear, ... )
33 int FilteringTexMan = RI_MAGFILTER_POINT | RI_MINFILTER_POINT | RI_MIPFILTER_POINT;
34 // Ключ прорисовки текстуры (wrap, clamp ... )
35 int Address_ModeTexMan = RI_WRAP_U | RI_WRAP_V;
36 // указывает, что канал есть...(или нужно создать по цвету...)
37 bool AlphaTexMan = false;
38 // цвет прозрачности для создания Alpha канала...
39 BYTE ARedTexMan = 0;
40 BYTE AGreenTexMan = 0;
41 BYTE ABlueTexMan = 0;
42 int AFlagTexMan = TX_ALPHA_EQUAL;
43
44 bool MipMap = true;
45
46
47
48
49
50
51
52 //------------------------------------------------------------------------------------
53 // проверка приоритета текстур
54 //------------------------------------------------------------------------------------
vw_CheckTexturesPrior()55 void vw_CheckTexturesPrior()
56 {
57 eTexture *Tmp = StartTexMan;
58
59 // находим эквивалент еденице
60 float MaxCount = 0.0f;
61 while (Tmp != 0)
62 {
63 eTexture *Tmp1 = Tmp->Next;
64 if (Tmp->TexturePrior > 0.0f)
65 if (Tmp->Width*Tmp->Height > MaxCount) MaxCount = Tmp->Width*Tmp->Height*1.0f;
66 Tmp = Tmp1;
67 }
68
69
70 // устанавливаем правильный приоритет
71 Tmp = StartTexMan;
72 while (Tmp != 0)
73 {
74 eTexture *Tmp1 = Tmp->Next;
75 float CurrPr = 0.0f;
76 vw_GetPrioritizeTextures(Tmp->OffsetID, &CurrPr);
77
78 if (Tmp->TexturePrior > 0.0f)
79 {
80 vw_SetPrioritizeTextures(Tmp->OffsetID, (Tmp->Width*Tmp->Height*1.0f)/MaxCount);
81 }
82 else
83 {
84 if (CurrPr > 0.0f)
85 vw_SetPrioritizeTextures(Tmp->OffsetID, 0.0f);
86 }
87 Tmp->TexturePrior = 0.0f;
88
89 Tmp = Tmp1;
90 }
91
92 }
93
94
95
96
97
98
99
100 //------------------------------------------------------------------------------------
101 // освобождаем все текстуры подключенные к менеджеру текстур
102 //------------------------------------------------------------------------------------
vw_ReleaseAllTextures()103 void vw_ReleaseAllTextures()
104 {
105 // Чистка памяти...
106 eTexture *Tmp = StartTexMan;
107 while (Tmp != 0)
108 {
109 eTexture *Tmp1 = Tmp->Next;
110 vw_ReleaseTexture(Tmp);
111 Tmp = Tmp1;
112 }
113
114
115 StartTexMan = 0;
116 EndTexMan = 0;
117 NumTexMan = 0;
118
119 FilteringTexMan = RI_MAGFILTER_POINT | RI_MINFILTER_POINT | RI_MIPFILTER_POINT;
120 Address_ModeTexMan = RI_WRAP_U | RI_WRAP_V;
121 AlphaTexMan = false;
122 }
123
124
125
126
127
128
129
130 //------------------------------------------------------------------------------------
131 // подключение текстуры к менеджеру текстур
132 //------------------------------------------------------------------------------------
AttachTexture(eTexture * Texture)133 void AttachTexture(eTexture* Texture)
134 {
135 if (Texture == 0) return;
136
137 // первый в списке...
138 if (EndTexMan == 0)
139 {
140 Texture->Prev = 0;
141 Texture->Next = 0;
142 NumTexMan += 1;
143 Texture->Num = NumTexMan;
144 StartTexMan = Texture;
145 EndTexMan = Texture;
146 }
147 else // продолжаем заполнение...
148 {
149 Texture->Prev = EndTexMan;
150 Texture->Next = 0;
151 EndTexMan->Next = Texture;
152 NumTexMan += 1;
153 Texture->Num = NumTexMan;
154 EndTexMan = Texture;
155 }
156
157 }
158
159
160
161
162
163 //------------------------------------------------------------------------------------
164 // отключение текстуры от менеджера текстур
165 //------------------------------------------------------------------------------------
DetachTexture(eTexture * Texture)166 void DetachTexture(eTexture* Texture)
167 {
168 if (Texture == 0) return;
169
170 // переустанавливаем указатели...
171 if (StartTexMan == Texture) StartTexMan = Texture->Next;
172 if (EndTexMan == Texture) EndTexMan = Texture->Prev;
173
174
175 if (Texture->Next != 0) Texture->Next->Prev = Texture->Prev;
176 else if (Texture->Prev != 0) Texture->Prev->Next = 0;
177 if (Texture->Prev != 0) Texture->Prev->Next = Texture->Next;
178 else if (Texture->Next != 0) Texture->Next->Prev = 0;
179 }
180
181
182
183
184
185
186
187
188 //------------------------------------------------------------------------------------
189 // Установка свойств текстур...
190 //------------------------------------------------------------------------------------
vw_SetTextureProp(int nFiltering,int nAddress_Mode,bool nAlpha,int nAFlag,bool nMipMap)191 void vw_SetTextureProp(int nFiltering, int nAddress_Mode, bool nAlpha, int nAFlag, bool nMipMap)
192 {
193 FilteringTexMan = nFiltering;
194 Address_ModeTexMan = nAddress_Mode;
195 AlphaTexMan = nAlpha;
196 AFlagTexMan = nAFlag;
197 MipMap = nMipMap;
198 }
199
200
201
202
203
204
205
206
207 //------------------------------------------------------------------------------------
208 // Установка цвета альфа канала
209 //------------------------------------------------------------------------------------
vw_SetTextureAlpha(BYTE nARed,BYTE nAGreen,BYTE nABlue)210 void vw_SetTextureAlpha(BYTE nARed, BYTE nAGreen, BYTE nABlue)
211 {
212 ARedTexMan = nARed;
213 AGreenTexMan = nAGreen;
214 ABlueTexMan = nABlue;
215 }
216
217
218
219
220
221
222
223
224
225 //------------------------------------------------------------------------------------
226 // Нахождение текстуры по уникальному номеру...
227 //------------------------------------------------------------------------------------
vw_FindTextureByNum(int Num)228 eTexture* vw_FindTextureByNum(int Num)
229 {
230 eTexture *Tmp = StartTexMan;
231
232 while (Tmp != 0)
233 {
234 eTexture *Tmp1 = Tmp->Next;
235 if (Tmp->Num == Num) return Tmp;
236 Tmp = Tmp1;
237 }
238
239 return 0;
240 }
241
242
243
244
245
246 //------------------------------------------------------------------------------------
247 // Нахождение текстуры по имени...
248 //------------------------------------------------------------------------------------
vw_FindTextureByName(const char * Name)249 eTexture* vw_FindTextureByName(const char *Name)
250 {
251 eTexture *Tmp = StartTexMan;
252
253 while (Tmp != 0)
254 {
255 eTexture *Tmp1 = Tmp->Next;
256 if( vw_strcmp(Tmp->Name, Name) == 0 ) return Tmp;
257 Tmp = Tmp1;
258 }
259
260 return 0;
261 }
262
263
264
265