📄 可编程数据流模型 (programmable stream model).htm
字号:
lang=EN-US>IDirect3DDevice9::CreateVertexShader</SPAN></U>方法创建顶点着色器。但首先,必须先对着色器进行汇编。<SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">TCHAR<SPAN
style="mso-spacerun: yes">
</SPAN><SPAN class=SpellE><SPAN
class=GramE>strVertexShaderPath</SPAN></SPAN><SPAN
class=GramE>[</SPAN>512];<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">LPD3DXBUFFER<SPAN
style="mso-spacerun: yes">
</SPAN><SPAN class=SpellE>pCode</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">LPDIRECT3DVERTEXSHADER9<SPAN
style="mso-tab-count: 1"> </SPAN><SPAN
class=SpellE>m_pVertexShader</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN class=GramE><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">hr</SPAN></SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
= <SPAN class=SpellE>DXUtil_FindMediaFileCb</SPAN>( <SPAN
class=SpellE>strVertexShaderPath</SPAN>, <o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><SPAN
style="mso-spacerun: yes">
</SPAN><SPAN class=SpellE>sizeof</SPAN>(<SPAN
class=SpellE>strVertexShaderPath</SPAN>), _T("<SPAN
class=SpellE>ShaderFile.vsh</SPAN>");<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN class=GramE><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">hr</SPAN></SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
= D3DXAssembleShaderFromFile( <SPAN class=SpellE>strVertexShaderPath</SPAN>,
NULL, NULL, <o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><SPAN
style="mso-spacerun: yes">
</SPAN><SPAN class=SpellE>dwFlags</SPAN>, &<SPAN class=SpellE>pCode</SPAN>,
NULL );<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>CreateVertexShader</SPAN></SPAN><SPAN
class=GramE>(</SPAN> (DWORD*)<SPAN class=SpellE>pCode</SPAN>-><SPAN
class=SpellE>GetBufferPointer</SPAN>(),<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><SPAN
style="mso-spacerun: yes">
</SPAN>&<SPAN class=SpellE>m_<SPAN
class=GramE>pVertexShader</SPAN></SPAN><SPAN class=GramE>
)</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">以下示例代码显示了如何设置顶点着色器,设置数据流的源,然后渲染三角形表。<SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_pd3dDevice-><SPAN
class=SpellE><SPAN class=GramE>SetVertexDeclaration</SPAN></SPAN><SPAN
class=GramE>(</SPAN> <SPAN class=SpellE>m_pVertexDeclaration</SPAN>
);<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>SetVertexShader</SPAN></SPAN><SPAN
class=GramE>(</SPAN> <SPAN class=SpellE>m_pVertexShader</SPAN>
);<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>SetStreamSource</SPAN></SPAN><SPAN
class=GramE>(</SPAN> 0, <SPAN class=SpellE>xyzbuf</SPAN>, <SPAN
class=SpellE>sizeof</SPAN>(<SPAN
class=SpellE>XYZBuffer</SPAN>));<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>SetStreamSource</SPAN></SPAN><SPAN
class=GramE>(</SPAN> 1, <SPAN class=SpellE>colbuf</SPAN>, <SPAN
class=SpellE>sizeof</SPAN>(<SPAN
class=SpellE>ColBuffer</SPAN>));<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>SetIndices</SPAN></SPAN><SPAN
class=GramE>(</SPAN> <SPAN class=SpellE>pIB</SPAN>, 0 );<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">g_d3dDevice-><SPAN
class=SpellE><SPAN class=GramE>DrawIndexedPrimitive</SPAN></SPAN><SPAN
class=GramE>(</SPAN> D3DPT_TRIANGLELIST, 0, max - min + 1, 0, count / 3
);<o:p></o:p></SPAN></P>
<DIV class=MsoNormal style="TEXT-ALIGN: center; mso-pagination: widow-orphan"
align=center><SPAN lang=EN-US
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
<HR align=center width="100%" SIZE=1>
</SPAN></DIV>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan; mso-outline-level: 1"
align=left><A name=单纹理着色器><B><SPAN
style="FONT-SIZE: 24pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 18.0pt">单纹理着色器<SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN></B></A></P><SPAN
style="mso-bookmark: 单纹理着色器"></SPAN>
<DIV class=MsoNormal style="TEXT-ALIGN: center; mso-pagination: widow-orphan"
align=center><SPAN lang=EN-US
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
<HR align=center width="100%" SIZE=1>
</SPAN></DIV>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">本主题显示了初始化和使用一个用到了位置和一组纹理坐标的简单顶点着色器的必须步骤。<SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan"
align=left><SPAN
style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">第一步是声明用来保存位置和纹理坐标的结构,如以下示例代码所示。<SPAN
lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN class=SpellE><SPAN class=GramE><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">struct</SPAN></SPAN></SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
<SPAN class=SpellE>XYZBuffer</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">{<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN
class=GramE>float</SPAN> x, y, z;<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">};<o:p></o:p></SPAN></P>
<P class=MsoNormal
style="TEXT-ALIGN: left; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"
align=left><SPAN lang=EN-US
style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -