我有这段代码,反汇编的DX:
.text:004386D3 push ecx
.text:004386D4 fld1
.text:004386D6 fstp [esp+26Ch+var_26C] ;load 1.0 value texture coords
.text:004386D9 push ecx
.text:004386DA fld1
.text:004386DC fstp [esp+270h+var_270] ;load 1.0 value texture coords
.text:004386DF push ecx
.text:004386E0 fld ds:__real@c1700000
.text:004386E6 fstp [esp+274h+var_274] ;load -15.0 value x vertex
.text:004386E9 push ecx
.text:004386EA fld ds:__real@c1700000
.text:004386F0 fstp [esp+278h+var_278] ;load -15.0 value y vertex
.text:004386F3 push ecx
.text:004386F4 fld ds:__real@c1700000
.text:004386FA fstp [esp+27Ch+var_27C] ;load -15.0 value z vertex
.text:004386FD lea ecx, [ebp+var_22C] ;this pointer
.text:00438703 call j_D3DVERTEX__D3DVERTEX ;fills structure with values
.text:00438708 mov ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func
.text:0043870B mov edx, [eax]
.text:0043870D mov [ecx], edx
.text:0043870F mov edx, [eax+4]
.text:00438712 mov [ecx+4], edx
.text:00438715 mov edx, [eax+8]
.text:00438718 mov [ecx+8], edx
.text:0043871B mov edx, [eax+0Ch]
.text:0043871E mov [ecx+0Ch], edx
.text:00438721 mov eax, [eax+10h]
.text:00438724 mov [ecx+10h], eax
这段代码用值填充了一个顶点结构:
-15.000000,-15.000000,-15.000000, 1.0,1.0
似乎值存储为两个副本。此值的第一个副本相对存储在 ebp+var_22C 中,并通过此指针传入 ecx:
.text:004386FD lea ecx, [ebp+var_22C] ; ecx has pointer this to store values
.text:00438703 call j_D3DVERTEX__D3DVERTEX ;fills structure with values
在调用 j_D3DVERTEX__D3DVERTEX 之后,第二次复制这个值存储在相对 ebp+var_8 中:
.text:00438708 mov ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func
即完全它看起来像:
.text:004386FD lea ecx, [ebp+var_22C] ; ecx has pointer this to store values
.text:00438703 call j_D3DVERTEX__D3DVERTEX ;store values into structure
.text:00438708 mov ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func
如果我理解正确 - 为什么需要这个顶点值的两个副本?也许使用 D3DPOOL_MANAGED 和 D3DUSAGE_WRITEONLY 参数创建的顶点缓冲区很重要。