|
1 | 1 | #include "stdafx.h" |
2 | 2 | #pragma hdrstop |
3 | 3 |
|
4 | | -#pragma warning(disable:4995) |
5 | | -#include <d3dx9.h> |
6 | | -#pragma warning(default:4995) |
7 | 4 | #include "FMesh.hpp" |
8 | 5 |
|
9 | | -//BOOL ValidateIndices(u32 vCount, u32 iCount, u16* pIndices) |
10 | | -//{ |
11 | | -// if (vCount>65535) return FALSE; |
12 | | -// if (iCount%3) return FALSE; |
13 | | -// |
14 | | -// for (u32 I=0; I<iCount; I++) |
15 | | -// { |
16 | | -// if (u32(pIndices[I])>=vCount) return FALSE; |
17 | | -// } |
18 | | -// return TRUE; |
19 | | -//} |
20 | | - |
21 | | -//static u32 dwPositionPart[8] = |
22 | | -//{ |
23 | | -// 0, // no position |
24 | | -// 3, // x,y,z |
25 | | -// 4, // sx,sy,sz,rhw |
26 | | -// 4, // x,y,z,b1 |
27 | | -// 5, // x,y,z,b1,b2 |
28 | | -// 6, // x,y,z,b1,b2,b3 |
29 | | -// 7, // x,y,z,b1,b2,b3,b4 |
30 | | -// 8 // x,y,z,b1,b2,b3,b4,b5 |
31 | | -//}; |
32 | | - |
33 | | -//#define FAKES 0xffffffff |
34 | | -//#define FAKEZ 0xfffffffe |
35 | | - |
36 | | -/* |
37 | | -void ConvertVertices(u32 dwTypeDest, void *pDest, u32 dwTypeSrc, void *pSource, u32 dwCount) |
38 | | -// assuming that pDest is large enought to maintain all the data |
39 | | -{ |
40 | | -u32 TransferMask [64]; |
41 | | -u32 tmPos = 0; |
42 | | -u32 tmPosSrc = 0; |
43 | | -u32 dwSizeSrc = D3DXGetFVFVertexSize(dwTypeSrc)/4; |
44 | | -u32 dwSizeDest = D3DXGetFVFVertexSize(dwTypeDest)/4; |
45 | | -u32* dest = (u32*)pDest; |
46 | | -u32* src = (u32*)pSource; |
47 | | -
|
48 | | -// avoid redundant processing |
49 | | -if (dwTypeDest==dwTypeSrc) { |
50 | | -CopyMemory (pDest,pSource,dwSizeDest*dwCount*4); |
51 | | -return; |
52 | | -} |
53 | | -
|
54 | | -// how many bytes to 'simple copy' |
55 | | -u32 dwPosDest = (dwTypeDest&D3DFVF_POSITION_MASK)>>1; |
56 | | -u32 dwPosSrc = (dwTypeSrc&D3DFVF_POSITION_MASK)>>1; |
57 | | -if (dwPosDest==dwPosSrc) { |
58 | | -u32 cnt = dwPositionPart[dwPosSrc]; |
59 | | -for (u32 i=0; i<cnt; i++) TransferMask[tmPos++]=i; |
60 | | -tmPosSrc = tmPos; |
61 | | -} else { |
62 | | -FATAL ("Can't convert between different vertex positions"); |
63 | | -} |
64 | | -
|
65 | | -// ---------------------- "Reserved" property |
66 | | -if ((dwTypeDest&D3DFVF_PSIZE) && (dwTypeSrc&D3DFVF_PSIZE)) |
67 | | -{ // DEST & SRC |
68 | | -TransferMask[tmPos++]=tmPosSrc++; |
69 | | -} |
70 | | -if ((dwTypeDest&D3DFVF_PSIZE) && !(dwTypeSrc&D3DFVF_PSIZE)) |
71 | | -{ // DEST & !SRC |
72 | | -TransferMask[tmPos++]=FAKEZ;// fake data |
73 | | -} |
74 | | -if (!(dwTypeDest&D3DFVF_PSIZE) && (dwTypeSrc&D3DFVF_PSIZE)) |
75 | | -{ // !DEST & SRC |
76 | | -tmPosSrc++; // skip it |
77 | | -} |
78 | | -
|
79 | | -// ---------------------- "Normal" property |
80 | | -if ((dwTypeDest&D3DFVF_NORMAL) && (dwTypeSrc&D3DFVF_NORMAL)) |
81 | | -{ // DEST & SRC |
82 | | -TransferMask[tmPos++]=tmPosSrc++; |
83 | | -TransferMask[tmPos++]=tmPosSrc++; |
84 | | -TransferMask[tmPos++]=tmPosSrc++; |
85 | | -} |
86 | | -if ((dwTypeDest&D3DFVF_NORMAL) && !(dwTypeSrc&D3DFVF_NORMAL)) |
87 | | -{ // DEST & !SRC |
88 | | -FATAL ("Source format doesn't have NORMAL but destination HAS"); |
89 | | -} |
90 | | -if (!(dwTypeDest&D3DFVF_NORMAL) && (dwTypeSrc&D3DFVF_NORMAL)) |
91 | | -{ // !DEST & SRC |
92 | | -tmPosSrc++; // skip it |
93 | | -tmPosSrc++; // skip it |
94 | | -tmPosSrc++; // skip it |
95 | | -} |
96 | | -
|
97 | | -// ---------------------- "Diffuse" property |
98 | | -if ((dwTypeDest&D3DFVF_DIFFUSE) && (dwTypeSrc&D3DFVF_DIFFUSE)) |
99 | | -{ // DEST & SRC |
100 | | -TransferMask[tmPos++]=tmPosSrc++; |
101 | | -} |
102 | | -if ((dwTypeDest&D3DFVF_DIFFUSE) && !(dwTypeSrc&D3DFVF_DIFFUSE)) |
103 | | -{ // DEST & !SRC |
104 | | -TransferMask[tmPos++]=FAKES; // fake data - white |
105 | | -} |
106 | | -if (!(dwTypeDest&D3DFVF_DIFFUSE) && (dwTypeSrc&D3DFVF_DIFFUSE)) |
107 | | -{ // !DEST & SRC |
108 | | -tmPosSrc++; // skip it |
109 | | -} |
110 | | -
|
111 | | -// ---------------------- "Specular" property |
112 | | -if ((dwTypeDest&D3DFVF_SPECULAR) && (dwTypeSrc&D3DFVF_SPECULAR)) |
113 | | -{ // DEST & SRC |
114 | | -TransferMask[tmPos++]=tmPosSrc++; |
115 | | -} |
116 | | -if ((dwTypeDest&D3DFVF_SPECULAR) && !(dwTypeSrc&D3DFVF_SPECULAR)) |
117 | | -{ // DEST & !SRC |
118 | | -TransferMask[tmPos++]=FAKES; // fake data - white |
119 | | -} |
120 | | -if (!(dwTypeDest&D3DFVF_SPECULAR) && (dwTypeSrc&D3DFVF_SPECULAR)) |
121 | | -{ // !DEST & SRC |
122 | | -tmPosSrc++; // skip it |
123 | | -} |
124 | | -
|
125 | | -// ---------------------- "Texture coords" property |
126 | | -u32 dwTDest = ((dwTypeDest&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); |
127 | | -u32 dwTSrc = ((dwTypeSrc &D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT); |
128 | | -if (dwTDest<=dwTSrc) { |
129 | | -for (u32 i=0; i<dwTDest; i++) { |
130 | | -TransferMask[tmPos++]=tmPosSrc++; |
131 | | -TransferMask[tmPos++]=tmPosSrc++; |
132 | | -} |
133 | | -} else { |
134 | | -if (dwTSrc==0) { |
135 | | -FATAL ("Source vertex format doesn't has texture coords at all"); |
136 | | -} |
137 | | -// Copy real TC |
138 | | -u32 dwStage0TC = tmPosSrc; |
139 | | -for (u32 i=0; i<dwTSrc; i++) { |
140 | | -TransferMask[tmPos++]=tmPosSrc++; |
141 | | -TransferMask[tmPos++]=tmPosSrc++; |
142 | | -} |
143 | | -// Duplicate stage0 TC |
144 | | -for (i=dwTSrc; i<dwTDest; i++) { |
145 | | -TransferMask[tmPos++]=dwStage0TC; |
146 | | -TransferMask[tmPos++]=dwStage0TC+1; |
147 | | -} |
148 | | -} |
149 | | -
|
150 | | -// ---------------------- REAL CONVERTION USING BUILDED MASK |
151 | | -for (u32 i=0; i<dwCount; i++) { |
152 | | -// one vertex |
153 | | -for (u32 j=0; j<dwSizeDest; j++) { |
154 | | -u32 m = TransferMask[j]; |
155 | | -if (m == FAKES) dest[j]=0xffffffff; |
156 | | -else if (m == FAKEZ) dest[j]=0; |
157 | | -else dest[j]=src[m]; |
158 | | -} |
159 | | -dest += dwSizeDest; |
160 | | -src += dwSizeSrc; |
161 | | -} |
162 | | -return; |
163 | | -} |
164 | | -*/ |
165 | 6 | void ogf_desc::Load(IReader& F) |
166 | 7 | { |
167 | 8 | F.r_stringZ(source_file); |
|
0 commit comments