1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
2 | //
|
---|
3 | // ## ######
|
---|
4 | // ###### ###
|
---|
5 | // ## ############### Shark 3D Engine (www.shark3d.com)
|
---|
6 | // ########## # # #
|
---|
7 | // ######## Copyright (c) 1996-2006 Spinor GmbH.
|
---|
8 | // ######### # # # All rights reserved.
|
---|
9 | // ## ##########
|
---|
10 | // ##
|
---|
11 | //
|
---|
12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
13 |
|
---|
14 | //@cpp
|
---|
15 |
|
---|
16 | #include "drv_d3d9_progutil.h"
|
---|
17 | #include "drv_d3d9_settings.h"
|
---|
18 | #include "drv_d3d9_util.h"
|
---|
19 | #include "util/base/util_charutil.h"
|
---|
20 | #include "util/stream/util_textstreampos.h"
|
---|
21 | #include "sys/core/sys_endian.h"
|
---|
22 | #include <dxerr9.h>
|
---|
23 | #include <malloc.h>
|
---|
24 |
|
---|
25 | ///////////////////////////////////////////////////////////////////////////////
|
---|
26 |
|
---|
27 | bool s3d_CDrvD3d9ProgUtil::ParseMajorMinor(
|
---|
28 | int &Major, int &Minor,
|
---|
29 | s3d_CSysIntps CapLen, const s3d_CSysChar *CapStart)
|
---|
30 | {
|
---|
31 | if(CapLen == 0)
|
---|
32 | {
|
---|
33 | Major = 0;
|
---|
34 | Minor = 0;
|
---|
35 | return true;
|
---|
36 | }
|
---|
37 |
|
---|
38 | s3d_CSysIntps Parse = 0;
|
---|
39 | if(!ParseNum(Major, CapLen, CapStart, Parse))
|
---|
40 | return false;
|
---|
41 | if(CapStart[Parse] != 'x')
|
---|
42 | return false;
|
---|
43 | Parse++;
|
---|
44 | if(!ParseNum(Minor, CapLen, CapStart, Parse))
|
---|
45 | return false;
|
---|
46 | if(Parse < CapLen)
|
---|
47 | return false;
|
---|
48 | return true;
|
---|
49 | }
|
---|
50 |
|
---|
51 | bool s3d_CDrvD3d9ProgUtil::ParseNum(
|
---|
52 | int &Val,
|
---|
53 | s3d_CSysIntps CapLen, const s3d_CSysChar *CapStart,
|
---|
54 | s3d_CSysIntps &Parse)
|
---|
55 | {
|
---|
56 | bool Ok = false;
|
---|
57 | Val = 0;
|
---|
58 | while(Parse < CapLen && s3d_CUtilCharUtil::IsDigit(CapStart[Parse]))
|
---|
59 | {
|
---|
60 | Ok = true;
|
---|
61 | Val = (Val * 10) + (CapStart[Parse] - '0');
|
---|
62 | Parse++;
|
---|
63 | }
|
---|
64 | return Ok;
|
---|
65 | }
|
---|
66 |
|
---|
67 | int s3d_CDrvD3d9ProgUtil::CompVer(
|
---|
68 | int MajorA, int MinorA, int MajorB, int MinorB)
|
---|
69 | {
|
---|
70 | if(MajorA > MajorB)
|
---|
71 | return 1;
|
---|
72 | if(MajorA < MajorB)
|
---|
73 | return -1;
|
---|
74 | if(MinorA > MinorB)
|
---|
75 | return 1;
|
---|
76 | if(MinorA < MinorB)
|
---|
77 | return -1;
|
---|
78 | return 0;
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool s3d_CDrvD3d9ProgUtil::IsVersAllowed(
|
---|
82 | int MaxMajor, int MaxMinor, s3d_CUtilStr_cr ReqVer)
|
---|
83 | {
|
---|
84 | int ReqMajor, ReqMinor;
|
---|
85 | bool Allowed = s3d_CDrvD3d9ProgUtil::ParseMajorMinor(
|
---|
86 | ReqMajor, ReqMinor, ReqVer.GetLen(), ReqVer.GetChars());
|
---|
87 |
|
---|
88 | if(Allowed)
|
---|
89 | {
|
---|
90 | Allowed = s3d_CDrvD3d9ProgUtil::CompVer(
|
---|
91 | MaxMajor, MaxMinor, ReqMajor, ReqMinor) >= 0;
|
---|
92 | }
|
---|
93 |
|
---|
94 | return Allowed;
|
---|
95 | }
|
---|
96 |
|
---|
97 | s3d_CUtilStr s3d_CDrvD3d9ProgUtil::StrOfVers(DWORD Vers)
|
---|
98 | {
|
---|
99 | s3d_CUtilStrBuf VersBuf;
|
---|
100 | // 0xFFFExxyy d3d vertex shader
|
---|
101 | // 0xFFFFxxyy d3d pixel shader
|
---|
102 | DWORD ShaderType = Vers >> 16;
|
---|
103 | if(ShaderType == 0xFFFE)
|
---|
104 | VersBuf.Append("vs_");
|
---|
105 | else if(ShaderType == 0xFFFF)
|
---|
106 | VersBuf.Append("ps_");
|
---|
107 | else
|
---|
108 | return "<unknown shader type/vers>";
|
---|
109 |
|
---|
110 | int Major = D3DSHADER_VERSION_MAJOR(Vers);
|
---|
111 | int Minor = D3DSHADER_VERSION_MINOR(Vers);
|
---|
112 | VersBuf.AppendInt(Major);
|
---|
113 | VersBuf.Append("_");
|
---|
114 | VersBuf.AppendInt(Minor);
|
---|
115 | return VersBuf;
|
---|
116 | }
|
---|
117 |
|
---|
118 | s3d_CUtilStr s3d_CDrvD3d9ProgUtil::GenProfileString(
|
---|
119 | s3d_CUtilStr_cr Vers, s3d_CUtilStr_cr Type)
|
---|
120 | {
|
---|
121 | int Major, Minor;
|
---|
122 | ParseMajorMinor(Major, Minor, Vers.GetLen(), Vers.GetChars());
|
---|
123 |
|
---|
124 | s3d_CUtilStr Profile = Type + "_" + s3d_CUtilStrUtil::StrOfInt(Major)
|
---|
125 | + "_" + s3d_CUtilStrUtil::StrOfInt(Minor);
|
---|
126 | return Profile;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void s3d_CDrvD3d9ProgUtil::D3dMarcoArrayOfPreprocArray(
|
---|
130 | s3d_CUtilOwnArray<D3DXMACRO> &D3dMacroArray,
|
---|
131 | s3d_CLibStreamPreproState *PreproState)
|
---|
132 | {
|
---|
133 | int nPredDef = PreproState->m_MacroMap.GetCntInt();
|
---|
134 | int AllocCnt = nPredDef + 1;
|
---|
135 | D3dMacroArray.Alloc(AllocCnt);
|
---|
136 | LPD3DXMACRO D3dMacro = D3dMacroArray;
|
---|
137 | s3d_CLibStreamPreproMacroMap::CNode *MacroNode
|
---|
138 | = PreproState->m_MacroMap.GetFirstNode();
|
---|
139 | int i;
|
---|
140 | for(i = 0; i < nPredDef; i++)
|
---|
141 | {
|
---|
142 | s3d_CLibStreamPreproMacro *Macro = MacroNode->m_Data.m_Val;
|
---|
143 | D3dMacro->Name = MacroNode->m_Data.m_Key.GetChars();
|
---|
144 | D3dMacro->Definition = Macro->m_Content.GetChars();
|
---|
145 | D3dMacro++;
|
---|
146 | MacroNode = MacroNode->GetNext();
|
---|
147 | }
|
---|
148 | D3dMacro->Name = 0;
|
---|
149 | D3dMacro->Definition = 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 | void s3d_CDrvD3d9ProgUtil::GetProgDecl(
|
---|
153 | const s3d_CDrvD3d9ProgCtx *ProgCtx, s3d_CDrvD3d9ProgDecl &ProgDecl,
|
---|
154 | s3d_CSysIntps FuncSize, const DWORD *FuncData)
|
---|
155 | {
|
---|
156 | ProgDecl.m_SemanticsCnt = 0;
|
---|
157 | ProgDecl.m_SemanticArray.Reset();
|
---|
158 |
|
---|
159 | if(!FuncData)
|
---|
160 | return;
|
---|
161 |
|
---|
162 | UINT Count = 0;
|
---|
163 | S3D_DRV_D3D9_CHECK(
|
---|
164 | ProgCtx->m_Env, D3DXGetShaderInputSemantics(
|
---|
165 | FuncData, 0, &Count));
|
---|
166 | if(Count <= 0)
|
---|
167 | return;
|
---|
168 |
|
---|
169 | ProgDecl.m_SemanticArray.Alloc(Count);
|
---|
170 |
|
---|
171 | S3D_DRV_D3D9_CHECK(
|
---|
172 | ProgCtx->m_Env, D3DXGetShaderInputSemantics(
|
---|
173 | FuncData, ProgDecl.m_SemanticArray, &Count));
|
---|
174 | if(Count <= 0)
|
---|
175 | {
|
---|
176 | ProgDecl.m_SemanticArray.Reset();
|
---|
177 | return;
|
---|
178 | }
|
---|
179 |
|
---|
180 | ProgDecl.m_SemanticsCnt = Count;
|
---|
181 |
|
---|
182 | ProgDecl.m_ProgUsage
|
---|
183 | = s3d_CDrvD3d9ProgUtil::CalcProgUsage(
|
---|
184 | ProgCtx, ProgDecl.m_SemanticsCnt, ProgDecl.m_SemanticArray);
|
---|
185 | }
|
---|
186 |
|
---|
187 | int s3d_CDrvD3d9ProgUtil::CalcProgUsage(
|
---|
188 | const s3d_CDrvD3d9ProgCtx *ProgCtx,
|
---|
189 | s3d_CSysIntps SemanticsCnt, const D3DXSEMANTIC *SemanticArray)
|
---|
190 | {
|
---|
191 | if(!ProgCtx)
|
---|
192 | return 0;
|
---|
193 | if(!SemanticArray)
|
---|
194 | return 0;
|
---|
195 |
|
---|
196 | int ProgUsage = 0;
|
---|
197 |
|
---|
198 | s3d_CSysIntps iSemantic;
|
---|
199 | for(iSemantic = 0; iSemantic < SemanticsCnt; iSemantic++)
|
---|
200 | {
|
---|
201 | DWORD Usage = SemanticArray->Usage;
|
---|
202 | DWORD UsageIdx = SemanticArray->UsageIndex;
|
---|
203 | switch(Usage)
|
---|
204 | {
|
---|
205 | case D3DDECLUSAGE_BLENDWEIGHT:
|
---|
206 | {
|
---|
207 | ProgUsage |= s3d_CDrvD3d9Prog::Usage_BoneWgh;
|
---|
208 | break;
|
---|
209 | }
|
---|
210 | case D3DDECLUSAGE_BLENDINDICES:
|
---|
211 | {
|
---|
212 | ProgUsage |= s3d_CDrvD3d9Prog::Usage_BoneSubscr;
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | /*
|
---|
216 | case D3DDECLUSAGE_NORMAL:
|
---|
217 | case D3DDECLUSAGE_TEXCOORD:
|
---|
218 | case D3DDECLUSAGE_COLOR:
|
---|
219 | case D3DDECLUSAGE_POSITION:
|
---|
220 | case D3DDECLUSAGE_PSIZE:
|
---|
221 | case D3DDECLUSAGE_TANGENT:
|
---|
222 | case D3DDECLUSAGE_BINORMAL:
|
---|
223 | case D3DDECLUSAGE_TESSFACTOR:
|
---|
224 | case D3DDECLUSAGE_POSITIONT:
|
---|
225 | case D3DDECLUSAGE_FOG:
|
---|
226 | case D3DDECLUSAGE_DEPTH:
|
---|
227 | case D3DDECLUSAGE_SAMPLE:
|
---|
228 | */
|
---|
229 | default:
|
---|
230 | break;
|
---|
231 | }
|
---|
232 | SemanticArray++;
|
---|
233 | }
|
---|
234 |
|
---|
235 | return ProgUsage;
|
---|
236 | }
|
---|
237 |
|
---|
238 | void s3d_CDrvD3d9ProgUtil::CalcVertBufDesc(
|
---|
239 | const s3d_CDrvD3d9ProgCtx *ProgCtx,
|
---|
240 | const s3d_CDrvGfxCharge *Charge,
|
---|
241 | int VertProgUsage, const s3d_CDrvD3d9VertComprFmt *VertComprFmt,
|
---|
242 | s3d_CDrvD3d9VertBufDesc &VertBufDesc)
|
---|
243 | {
|
---|
244 | VertBufDesc.Reset();
|
---|
245 |
|
---|
246 | if(!Charge)
|
---|
247 | return;
|
---|
248 |
|
---|
249 | bool NoDummyBoneVertexBuf = ProgCtx->m_D3dParam->m_NoDummyBoneVertexBuf;
|
---|
250 | bool Complete = true;
|
---|
251 | int VertBufFmtDecl = 0;
|
---|
252 |
|
---|
253 | s3d_CDrvGfxAttr *PointAttr = 0;
|
---|
254 | s3d_CDrvGfxAttr *ColorAlphaAttr = 0;
|
---|
255 | s3d_CDrvGfxAttr *NormalAttr = 0;
|
---|
256 | s3d_CDrvGfxAttr *BoneWghAttr = 0;
|
---|
257 | s3d_CDrvGfxAttr *BoneSubscrAttr = 0;
|
---|
258 | s3d_CDrvGfxAttr *TexAttrArray[S3D_DRV_D3D9_MAX_ATTR_CNT];
|
---|
259 |
|
---|
260 | int TexSlotCnt = 0;
|
---|
261 | const s3d_CDrvDataTypeDesc *TexTypeDescArray[S3D_DRV_D3D9_MAX_ATTR_CNT];
|
---|
262 | BYTE TexSlotArray[S3D_DRV_D3D9_MAX_ATTR_CNT];
|
---|
263 | int iTex;
|
---|
264 | for(iTex = 0; iTex < S3D_DRV_D3D9_MAX_ATTR_CNT; iTex++)
|
---|
265 | {
|
---|
266 | TexTypeDescArray[iTex] = 0;
|
---|
267 | TexAttrArray[iTex] = 0;
|
---|
268 | TexSlotArray[iTex] = 0;
|
---|
269 | }
|
---|
270 |
|
---|
271 | int iAttr;
|
---|
272 | for(iAttr = 0; iAttr < Charge->m_AttrCnt; iAttr++)
|
---|
273 | {
|
---|
274 | s3d_CDrvGfxAttr *Attr = &Charge->m_AttrArray[iAttr];
|
---|
275 |
|
---|
276 | if(Attr->m_BankDyn)
|
---|
277 | Complete = false;
|
---|
278 |
|
---|
279 | s3d_CDrvBankContent BankContent;
|
---|
280 | s3d_DrvBankFetch(
|
---|
281 | ProgCtx->m_MsgHandler, Charge->m_MainInfo,
|
---|
282 | "attr", Attr->m_Bank,
|
---|
283 | BankContent);
|
---|
284 | int Slot = Attr->m_Slot;
|
---|
285 | int Chan = Attr->m_Chan;
|
---|
286 | switch(Chan)
|
---|
287 | {
|
---|
288 | case s3d_CDrvGfxEng::AttrChan_Generic:
|
---|
289 | {
|
---|
290 | if(s3d_SysIsValidArrayIdx(Slot, S3D_DRV_D3D9_MAX_ATTR_CNT))
|
---|
291 | {
|
---|
292 | if(BankContent.m_TypeDesc != 0)
|
---|
293 | {
|
---|
294 | TexTypeDescArray[TexSlotCnt] = BankContent.m_TypeDesc;
|
---|
295 | TexAttrArray[TexSlotCnt] = Attr;
|
---|
296 | TexSlotArray[TexSlotCnt] = Slot;
|
---|
297 | TexSlotCnt++;
|
---|
298 | VertBufFmtDecl
|
---|
299 | |= s3d_CDrvD3d9VertBufDesc::Decl_Generic;
|
---|
300 | }
|
---|
301 | }
|
---|
302 | break;
|
---|
303 | }
|
---|
304 | case s3d_CDrvGfxEng::AttrChan_Point:
|
---|
305 | {
|
---|
306 | if(Slot == 0)
|
---|
307 | {
|
---|
308 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_Point;
|
---|
309 | PointAttr = Attr;
|
---|
310 | }
|
---|
311 | break;
|
---|
312 | }
|
---|
313 | case s3d_CDrvGfxEng::AttrChan_ColorAlpha:
|
---|
314 | {
|
---|
315 | if(Slot == 0)
|
---|
316 | {
|
---|
317 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_ColorAlpha;
|
---|
318 | ColorAlphaAttr = Attr;
|
---|
319 | }
|
---|
320 | break;
|
---|
321 | }
|
---|
322 | case s3d_CDrvGfxEng::AttrChan_Normal:
|
---|
323 | {
|
---|
324 | if(Slot == 0)
|
---|
325 | {
|
---|
326 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_Normal;
|
---|
327 | NormalAttr = Attr;
|
---|
328 | }
|
---|
329 | break;
|
---|
330 | }
|
---|
331 | case s3d_CDrvGfxEng::AttrChan_BoneWgh:
|
---|
332 | {
|
---|
333 | if(Slot == 0)
|
---|
334 | {
|
---|
335 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_BoneWgh;
|
---|
336 | BoneWghAttr = Attr;
|
---|
337 | }
|
---|
338 | break;
|
---|
339 | }
|
---|
340 | case s3d_CDrvGfxEng::AttrChan_BoneSubscr:
|
---|
341 | {
|
---|
342 | if(Slot == 0)
|
---|
343 | {
|
---|
344 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_BoneSubscr;
|
---|
345 | BoneSubscrAttr = Attr;
|
---|
346 | }
|
---|
347 | break;
|
---|
348 | }
|
---|
349 | }
|
---|
350 | }
|
---|
351 | // Put dummy data into same vertexbuffer.
|
---|
352 | if(NoDummyBoneVertexBuf)
|
---|
353 | {
|
---|
354 | int DummyAttrCnt = 0;
|
---|
355 | if(!BoneWghAttr
|
---|
356 | && (VertProgUsage & s3d_CDrvD3d9Prog::Usage_BoneWgh))
|
---|
357 | {
|
---|
358 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneWgh;
|
---|
359 | DummyAttrCnt++;
|
---|
360 | }
|
---|
361 | if(!BoneSubscrAttr
|
---|
362 | && (VertProgUsage & s3d_CDrvD3d9Prog::Usage_BoneSubscr))
|
---|
363 | {
|
---|
364 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneSubscr;
|
---|
365 | DummyAttrCnt++;
|
---|
366 | }
|
---|
367 | }
|
---|
368 |
|
---|
369 | D3DVERTEXELEMENT9 *VertElemArray = VertBufDesc.m_VertElemArray;
|
---|
370 | WORD DeclOffs = 0;
|
---|
371 | WORD VertElemStream = 0;
|
---|
372 | if(VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_Point)
|
---|
373 | {
|
---|
374 | const D3DVERTEXELEMENT9 DeclPoint =
|
---|
375 | {
|
---|
376 | VertElemStream, DeclOffs, D3DDECLTYPE_FLOAT3,
|
---|
377 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0
|
---|
378 | };
|
---|
379 | DeclOffs = DeclOffs + S3D_SYS_SIZEOFS(float) * 3;
|
---|
380 | VertBufDesc.m_PointAttr = PointAttr;
|
---|
381 | *VertElemArray++ = DeclPoint;
|
---|
382 | }
|
---|
383 | if(VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_BoneWgh
|
---|
384 | || VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneWgh)
|
---|
385 | {
|
---|
386 | int Type = D3DDECLTYPE_FLOAT4;
|
---|
387 | if(VertComprFmt && VertComprFmt->m_BoneWgh > 0)
|
---|
388 | Type = VertComprFmt->m_BoneWgh;
|
---|
389 | const D3DVERTEXELEMENT9 DeclBlendWgh =
|
---|
390 | {
|
---|
391 | VertElemStream, DeclOffs, Type,
|
---|
392 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0
|
---|
393 | };
|
---|
394 | DeclOffs = DeclOffs + s3d_CDrvD3d9Util::SizeOfDeclType(Type);
|
---|
395 | VertBufDesc.m_BoneWghAttr = BoneWghAttr;
|
---|
396 | *VertElemArray++ = DeclBlendWgh;
|
---|
397 | }
|
---|
398 | if(VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_BoneSubscr
|
---|
399 | || VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneSubscr)
|
---|
400 | {
|
---|
401 | const D3DVERTEXELEMENT9 DeclBlendIdx =
|
---|
402 | {
|
---|
403 | VertElemStream, DeclOffs, D3DDECLTYPE_UBYTE4,
|
---|
404 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0
|
---|
405 | };
|
---|
406 | DeclOffs = DeclOffs + S3D_SYS_SIZEOFS(DWORD);
|
---|
407 | VertBufDesc.m_BoneSubscrAttr = BoneSubscrAttr;
|
---|
408 | *VertElemArray++ = DeclBlendIdx;
|
---|
409 | }
|
---|
410 | if(VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_ColorAlpha)
|
---|
411 | {
|
---|
412 | const D3DVERTEXELEMENT9 DeclColor =
|
---|
413 | {
|
---|
414 | VertElemStream, DeclOffs, D3DDECLTYPE_D3DCOLOR,
|
---|
415 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0
|
---|
416 | };
|
---|
417 | DeclOffs = DeclOffs + S3D_SYS_SIZEOFS(DWORD);
|
---|
418 | VertBufDesc.m_ColorAlphaAttr = ColorAlphaAttr;
|
---|
419 | *VertElemArray++ = DeclColor;
|
---|
420 | }
|
---|
421 | if(VertBufFmtDecl & s3d_CDrvD3d9VertBufDesc::Decl_Normal)
|
---|
422 | {
|
---|
423 | int Type = D3DDECLTYPE_FLOAT3;
|
---|
424 | if(VertComprFmt && VertComprFmt->m_Normal > 0)
|
---|
425 | Type = VertComprFmt->m_Normal;
|
---|
426 | const D3DVERTEXELEMENT9 DeclNormal =
|
---|
427 | {
|
---|
428 | VertElemStream, DeclOffs, Type,
|
---|
429 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0
|
---|
430 | };
|
---|
431 | DeclOffs = DeclOffs + s3d_CDrvD3d9Util::SizeOfDeclType(Type);
|
---|
432 | VertBufDesc.m_NormalAttr = NormalAttr;
|
---|
433 | *VertElemArray++ = DeclNormal;
|
---|
434 | }
|
---|
435 |
|
---|
436 | for(iTex = 0; iTex < TexSlotCnt; iTex++)
|
---|
437 | {
|
---|
438 | WORD TexOffs = S3D_SYS_SIZEOFS(float) * 2;
|
---|
439 | BYTE TexType = D3DDECLTYPE_FLOAT2;
|
---|
440 | D3DVERTEXELEMENT9 DeclTex;
|
---|
441 | const s3d_CDrvDataTypeDesc *TexTypeDesc = TexTypeDescArray[iTex];
|
---|
442 | if(TexTypeDesc == s3d_DrvDataGetTypeDesc<s3d_CDrvFloat32X2>())
|
---|
443 | {
|
---|
444 | TexType = D3DDECLTYPE_FLOAT2;
|
---|
445 | TexOffs = S3D_SYS_SIZEOFS(float) * 2;
|
---|
446 | }
|
---|
447 | else if(TexTypeDesc == s3d_DrvDataGetTypeDesc<s3d_CDrvFloat32>())
|
---|
448 | {
|
---|
449 | TexOffs = S3D_SYS_SIZEOFS(float);
|
---|
450 | TexType = D3DDECLTYPE_FLOAT1;
|
---|
451 | }
|
---|
452 | else if(TexTypeDesc == s3d_DrvDataGetTypeDesc<s3d_CDrvFloat32X3>())
|
---|
453 | {
|
---|
454 | TexOffs = S3D_SYS_SIZEOFS(float) * 3;
|
---|
455 | TexType = D3DDECLTYPE_FLOAT3;
|
---|
456 | }
|
---|
457 | else if(TexTypeDesc == s3d_DrvDataGetTypeDesc<s3d_CDrvFloat32X4>())
|
---|
458 | {
|
---|
459 | TexOffs = S3D_SYS_SIZEOFS(float) * 4;
|
---|
460 | TexType = D3DDECLTYPE_FLOAT4;
|
---|
461 | }
|
---|
462 | else
|
---|
463 | {
|
---|
464 | S3D_SYS_ASSERT(0);
|
---|
465 | }
|
---|
466 |
|
---|
467 | DeclTex.Stream = VertElemStream;
|
---|
468 | DeclTex.Offset = DeclOffs;
|
---|
469 | DeclTex.Type = TexType;
|
---|
470 | DeclTex.Method = D3DDECLMETHOD_DEFAULT;
|
---|
471 | DeclTex.Usage = D3DDECLUSAGE_TEXCOORD;
|
---|
472 | DeclTex.UsageIndex = TexSlotArray[iTex];
|
---|
473 |
|
---|
474 | DeclOffs += TexOffs;
|
---|
475 | VertBufDesc.m_TexAttrArray[iTex] = TexAttrArray[iTex];
|
---|
476 | *VertElemArray++ = DeclTex;
|
---|
477 | }
|
---|
478 |
|
---|
479 | // Put dummy data into extra vertexbuffer.
|
---|
480 | if(!NoDummyBoneVertexBuf)
|
---|
481 | {
|
---|
482 | // those must be last entries!
|
---|
483 | int DummyAttrCnt = 0;
|
---|
484 | if(!BoneWghAttr
|
---|
485 | && (VertProgUsage & s3d_CDrvD3d9Prog::Usage_BoneWgh))
|
---|
486 | {
|
---|
487 | WORD Stream = S3D_DRV_D3D9_DUMMY_BLENDWGHIDX_STREAM;
|
---|
488 | WORD StreamOffs = 0;
|
---|
489 | const D3DVERTEXELEMENT9 DeclBlendWgh =
|
---|
490 | {
|
---|
491 | Stream, StreamOffs, D3DDECLTYPE_FLOAT3,
|
---|
492 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0
|
---|
493 | };
|
---|
494 | *VertElemArray++ = DeclBlendWgh;
|
---|
495 | DummyAttrCnt++;
|
---|
496 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneWgh;
|
---|
497 | }
|
---|
498 | if(!BoneSubscrAttr
|
---|
499 | && (VertProgUsage & s3d_CDrvD3d9Prog::Usage_BoneSubscr))
|
---|
500 | {
|
---|
501 | WORD Stream = S3D_DRV_D3D9_DUMMY_BLENDWGHIDX_STREAM;
|
---|
502 | WORD StreamOffs = 3 * S3D_SYS_SIZEOFS(DWORD);
|
---|
503 | const D3DVERTEXELEMENT9 DeclBlendIdx =
|
---|
504 | {
|
---|
505 | Stream, StreamOffs, D3DDECLTYPE_UBYTE4,
|
---|
506 | D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0
|
---|
507 | };
|
---|
508 | *VertElemArray++ = DeclBlendIdx;
|
---|
509 | DummyAttrCnt++;
|
---|
510 | VertBufFmtDecl |= s3d_CDrvD3d9VertBufDesc::Decl_DummyBoneSubscr;
|
---|
511 | }
|
---|
512 | }
|
---|
513 |
|
---|
514 | const D3DVERTEXELEMENT9 DeclEnd = D3DDECL_END();
|
---|
515 | *VertElemArray++ = DeclEnd;
|
---|
516 | VertBufDesc.m_VertSize = DeclOffs;
|
---|
517 | VertBufDesc.m_VertBufFmtDecl = VertBufFmtDecl;
|
---|
518 | VertBufDesc.m_VertElemCnt =
|
---|
519 | s3d_CSysIntps(VertElemArray - VertBufDesc.m_VertElemArray);
|
---|
520 | }
|
---|
521 |
|
---|
522 | void s3d_CDrvD3d9ProgUtil::ExtractComprFmt(
|
---|
523 | const s3d_CDrvD3d9ProgCtx *ProgCtx,
|
---|
524 | s3d_CUtilStr_cr CodeInfo, s3d_CUtilStr_cr CodeName,
|
---|
525 | s3d_CDrvD3d9Prog *Prog, s3d_CUtilSnkExtract &SnkExtract)
|
---|
526 | {
|
---|
527 | /*@{ @declare{shaderprog.param}
|
---|
528 | {d3d9.hlsl_vertshader.compr_normal}{$ [str]}
|
---|
529 | Use "ubyte4" to enable compression of vertex normals.
|
---|
530 | @}*/
|
---|
531 | /*@{ @declare{shaderprog.param}
|
---|
532 | {d3d9.asm_vertshader.compr_normal}{$ [str]}
|
---|
533 | See @ident{shaderprog}{d3d9.hlsl_vertshader.compr_normal}
|
---|
534 | @}*/
|
---|
535 | s3d_CUtilStr TypeStr;
|
---|
536 | s3d_CUtilStr TypeInfo;
|
---|
537 | SnkExtract.ExtractStr(TypeInfo, TypeStr, "compr_normal", false);
|
---|
538 | s3d_CUtilSnkExtractEnum SnkExtractEnum;
|
---|
539 | SnkExtractEnum.Assign(ProgCtx->m_MsgHandler, TypeInfo, TypeStr);
|
---|
540 | int ComprNormal = -1;
|
---|
541 | if(SnkExtractEnum.Check(""))
|
---|
542 | ComprNormal = -1;
|
---|
543 | else if(SnkExtractEnum.Check("ubyte4"))
|
---|
544 | ComprNormal = D3DDECLTYPE_UBYTE4;
|
---|
545 | else
|
---|
546 | SnkExtractEnum.ErrorUnknown();
|
---|
547 |
|
---|
548 | /*@{ @declare{shaderprog.param}
|
---|
549 | {d3d9.hlsl_vertshader.compr_bonewgh}{$ [str]}
|
---|
550 | Use "ubyte4" to enable compression of bone weights.
|
---|
551 | @}*/
|
---|
552 | /*@{ @declare{shaderprog.param}
|
---|
553 | {d3d9.asm_vertshader.compr_bonewgh}{$ [str]}
|
---|
554 | See @ident{shaderprog}{d3d9.hlsl_vertshader.compr_bonewgh}
|
---|
555 | @}*/
|
---|
556 | SnkExtract.ExtractStr(TypeInfo, TypeStr, "compr_bonewgh", false);
|
---|
557 | SnkExtractEnum.Assign(ProgCtx->m_MsgHandler, TypeInfo, TypeStr);
|
---|
558 | int ComprBoneWgh = -1;
|
---|
559 | if(SnkExtractEnum.Check(""))
|
---|
560 | ComprBoneWgh = -1;
|
---|
561 | else if(SnkExtractEnum.Check("ubyte4"))
|
---|
562 | ComprBoneWgh = D3DDECLTYPE_UBYTE4;
|
---|
563 | else
|
---|
564 | SnkExtractEnum.ErrorUnknown();
|
---|
565 |
|
---|
566 | /*
|
---|
567 | int SampTexArray[S3D_DRV_D3D9_MAX_ATTR_CNT];
|
---|
568 | s3d_CUtilStrArray TypeStrArray;
|
---|
569 | SnkExtract.ExtractStrArray(TypeStrArray, "compr_attr", false);
|
---|
570 | const s3d_CSysIntps nType = TypeStrArray.GetCnt();
|
---|
571 | s3d_CSysIntps iType;
|
---|
572 | for(iType = 0; iType < nType; iType++)
|
---|
573 | {
|
---|
574 | SnkExtractEnum.Assign(
|
---|
575 | ProgCtx->m_MsgHandler, TypeInfo, TypeStrArray[iType]);
|
---|
576 | SampTexArray[iType] = -1;
|
---|
577 | if(SnkExtractEnum.Check(""))
|
---|
578 | SampTexArray[iType] = -1;
|
---|
579 | else if(SnkExtractEnum.Check("ubyte4"))
|
---|
580 | SampTexArray[iType] = D3DDECLTYPE_UBYTE4;
|
---|
581 | else if(SnkExtractEnum.Check("short2"))
|
---|
582 | SampTexArray[iType] = D3DDECLTYPE_SHORT2;
|
---|
583 | else
|
---|
584 | SnkExtractEnum.ErrorUnknown();
|
---|
585 | }
|
---|
586 | */
|
---|
587 |
|
---|
588 |
|
---|
589 | s3d_CDrvD3d9VertComprFmtPtr VertComprFmt;
|
---|
590 | if(ComprNormal > 0 || ComprBoneWgh > 0)// || nType > 0)
|
---|
591 | {
|
---|
592 | VertComprFmt = S3D_SYS_NEW s3d_CDrvD3d9VertComprFmt;
|
---|
593 | VertComprFmt->m_Normal = ComprNormal;
|
---|
594 | VertComprFmt->m_BoneWgh = ComprBoneWgh;
|
---|
595 | /*
|
---|
596 | s3d_SysMemcpy(
|
---|
597 | VertComprFmt->m_SampTexArray, SampTexArray,
|
---|
598 | S3D_SYS_SIZEOFS(VertComprFmt->m_SampTexArray));
|
---|
599 | */
|
---|
600 | }
|
---|
601 | Prog->m_VertComprFmt = VertComprFmt;
|
---|
602 | }
|
---|
603 |
|
---|
604 | bool s3d_CDrvD3d9ProgUtil::CreateCodeBufOfBinData(
|
---|
605 | const s3d_CDrvD3d9ProgCtx *ProgCtx, s3d_CDrvD3d9Buf &CodeBuf,
|
---|
606 | s3d_CSysIntps BinDataLen, const s3d_CSysIntm *BinData)
|
---|
607 | {
|
---|
608 | DWORD ShaderTypeBin = s3d_SysReadInt32uLitEndian(BinData) >> 16;
|
---|
609 | // 0xFFFExxyy d3d vertex shader
|
---|
610 | // 0xFFFFxxyy d3d pixel shader
|
---|
611 | if(ShaderTypeBin == 0xFFFE || ShaderTypeBin == 0xFFFF)
|
---|
612 | {
|
---|
613 | S3D_DRV_D3D9_CHECK(
|
---|
614 | ProgCtx->m_Env, D3DXCreateBuffer(
|
---|
615 | DWORD(BinDataLen), &CodeBuf.EmptyRef()));
|
---|
616 | if(CodeBuf)
|
---|
617 | {
|
---|
618 | void *Dest = CodeBuf->GetBufferPointer();
|
---|
619 | s3d_SysMemcpy(Dest, BinData, BinDataLen);
|
---|
620 | return true;
|
---|
621 | }
|
---|
622 | }
|
---|
623 | return false;
|
---|
624 | }
|
---|
625 |
|
---|
626 | ///////////////////////////////////////////////////////////////////////////////
|
---|