青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

D3D Animation Basis(4)

Loading Vertex Shaders

Moving on in the list of helper functions, you'll find load_vertex_shader. You'll use this function to help you load your vertex shaders, as well as prepare your vertex shader declarations.

The actual code to the load_vertex_shader function is short, so instead of breaking it up to explain it, I'll give it to you all at once.

HRESULT load_vertex_shader(IDirect3DVertexShader9** ret_vertex_shader,
                           IDirect3DDevice9
* device,
                           
const char* filename,
                           
const D3DVERTEXELEMENT9* vertex_elements,
                           IDirect3DVertexDeclaration9
** ret_vertex_decl)
{
    
// error checking
    if(ret_vertex_shader == NULL || device == NULL || filename == NULL)
        
return E_FAIL;

    
// load and assemble the shader
    ID3DXBuffer* shader_buffer;
    HRESULT hr 
= D3DXAssembleShaderFromFile(filename, NULL, NULL, 0&shader_buffer, NULL);

    
if(FAILED(hr))
        
return hr;

    hr 
= device->CreateVertexShader((DWORD*) shader_buffer->GetBufferPointer(), ret_vertex_shader);

    
if(FAILED(hr))
        
return hr;

    shader_buffer
->Release();

    
// create the declaration interface if needed
    if(vertex_elements && ret_vertex_decl)
        device
->CreateVertexDeclaration(vertex_elements, ret_vertex_decl);

    
return S_OK;
}

 

After first checking to make sure the parameters you have passed to the load_vertex_shader function are valid, execution continues by loading and assembling the vertex shader via a call to D3DXAssembleShaderFromFile.

Assemble a shader.

HRESULT D3DXAssembleShaderFromFile(
LPCTSTR pSrcFile,
CONST D3DXMACRO* pDefines,
LPD3DXINCLUDE pInclude,
DWORD Flags,
LPD3DXBUFFER* ppShader,
LPD3DXBUFFER * ppErrorMsgs
);

Parameters

pSrcFile
[in] Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
pDefines
[in] An optional NULL terminated array of D3DXMACRO structures. This value may be NULL.
pInclude
[in] Optional interface pointer, ID3DXInclude, to use for handling #include directives. If this value is NULL, #includes will either be honored when compiling from a file or will cause an error when compiled from a resource or memory.
Flags
[in] Compile options identified by various flags. The Direct3D 10 HLSL compiler is now the default. See D3DXSHADER Flags for details.
ppShader
[out] Returns a buffer containing the created shader. This buffer contains the compiled shader code, as well as any embedded debug and symbol table information.
ppErrorMsgs
[out] Returns a buffer containing a listing of errors and warnings that were encountered during the compile. These are the same messages the debugger displays when running in debug mode. This value may be NULL.

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

Remarks

The compiler setting also determines the function version. If Unicode is defined, the function call resolves to D3DXAssembleShaderFromFileW. Otherwise, the function call resolves to D3DXAssembleShaderFromFileA because ANSI strings are being used.

Using the D3DXBUFFER object returned from that function call, you then use the IDirect3DDevice::CreateVertexShader function to create your vertex shader object.

Finishing up load_vertex_shader, you'll see the call to CreateVertexDeclaration, which you use to create an IDirect3DVertexDeclaration9 interface from the supplied array of vertex elements (vertex_elements in the load_vertex_shader prototype). The vertex declaration object pointer is then stored in the ret_vertex_decl pointer you provide.

To use load_vertex_shader, pass it a pointer to an IDirect3DVertexShader9 object you want to create, along with a valid IDirect3DDevice9 object and file name of the vertex shader file. The last two parameters (vertex_elements and ret_vertex_decl) are optional. By passing a valid D3DVERTEXELEMENT9 array and the IDirect3DVertexDeclaration9 object pointer, you can prepare your vertex declarations for use with the vertex shader being loaded.

Let us see the define of D3DVERTEXELEMENT9:

Defines the vertex data layout. Each vertex can contain one or more data types, and each data type is described by a vertex element.

typedef struct D3DVERTEXELEMENT9 {
WORD Stream;
WORD Offset;
BYTE Type;
BYTE Method;
BYTE Usage;
BYTE UsageIndex;
} D3DVERTEXELEMENT9, *LPD3DVERTEXELEMENT9;

Members

Stream
Stream number.
Offset
Offset from the beginning of the vertex data to the data associated with the particular data type.
Type
The data type, specified as a D3DDECLTYPE. One of several predefined types that define the data size. Some methods have an implied type.
Method
The method specifies the tessellator processing, which determines how the tessellator interprets (or operates on) the vertex data. For more information, see D3DDECLMETHOD.
Usage
Defines what the data will be used for; that is, the interoperability between vertex data layouts and vertex shaders. Each usage acts to bind a vertex declaration to a vertex shader. In some cases, they have a special interpretation. For example, an element that specifies D3DDECLUSAGE_NORMAL or D3DDECLUSAGE_POSITION is used by the N-patch tessellator to set up tessellation. See D3DDECLUSAGE for a list of the available semantics. D3DDECLUSAGE_TEXCOORD can be used for user-defined fields (which don't have an existing usage defined).
UsageIndex
Modifies the usage data to allow the user to specify multiple usage types.

Remarks

Vertex data is defined using an array of D3DVERTEXELEMENT9 structures. Use D3DDECL_END to declare the last element in the declaration.

Defines a vertex declaration data type.

typedef enum D3DDECLTYPE
{
D3DDECLTYPE_FLOAT1 = 0,
D3DDECLTYPE_FLOAT2 = 1,
D3DDECLTYPE_FLOAT3 = 2,
D3DDECLTYPE_FLOAT4 = 3,
D3DDECLTYPE_D3DCOLOR = 4,
D3DDECLTYPE_UBYTE4 = 5,
D3DDECLTYPE_SHORT2 = 6,
D3DDECLTYPE_SHORT4 = 7,
D3DDECLTYPE_UBYTE4N = 8,
D3DDECLTYPE_SHORT2N = 9,
D3DDECLTYPE_SHORT4N = 10,
D3DDECLTYPE_USHORT2N = 11,
D3DDECLTYPE_USHORT4N = 12,
D3DDECLTYPE_UDEC3 = 13,
D3DDECLTYPE_DEC3N = 14,
D3DDECLTYPE_FLOAT16_2 = 15,
D3DDECLTYPE_FLOAT16_4 = 16,
D3DDECLTYPE_UNUSED = 17,
} D3DDECLTYPE, *LPD3DDECLTYPE;

Constants

D3DDECLTYPE_FLOAT1
One-component float expanded to (float, 0, 0, 1).
D3DDECLTYPE_FLOAT2
Two-component float expanded to (float, float, 0, 1).
D3DDECLTYPE_FLOAT3
Three-component float expanded to (float, float, float, 1).
D3DDECLTYPE_FLOAT4
Four-component float expanded to (float, float, float, float).
D3DDECLTYPE_D3DCOLOR
Four-component, packed, unsigned bytes mapped to 0 to 1 range. Input is a D3DCOLOR and is expanded to RGBA order.
D3DDECLTYPE_UBYTE4
Four-component, unsigned byte.
D3DDECLTYPE_SHORT2
Two-component, signed short expanded to (value, value, 0, 1).
D3DDECLTYPE_SHORT4
Four-component, signed short expanded to (value, value, value, value).
D3DDECLTYPE_UBYTE4N
Four-component byte with each byte normalized by dividing with 255.0f.
D3DDECLTYPE_SHORT2N
Normalized, two-component, signed short, expanded to (first short/32767.0, second short/32767.0, 0, 1).
D3DDECLTYPE_SHORT4N
Normalized, four-component, signed short, expanded to (first short/32767.0, second short/32767.0, third short/32767.0, fourth short/32767.0).
D3DDECLTYPE_USHORT2N
Normalized, two-component, unsigned short, expanded to (first short/65535.0, short short/65535.0, 0, 1).
D3DDECLTYPE_USHORT4N
Normalized, four-component, unsigned short, expanded to (first short/65535.0, second short/65535.0, third short/65535.0, fourth short/65535.0).
D3DDECLTYPE_UDEC3
Three-component, unsigned, 10 10 10 format expanded to (value, value, value, 1).
D3DDECLTYPE_DEC3N
Three-component, signed, 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1).
D3DDECLTYPE_FLOAT16_2
Two-component, 16-bit, floating point expanded to (value, value, 0, 1).
D3DDECLTYPE_FLOAT16_4
Four-component, 16-bit, floating point expanded to (value, value, value, value).
D3DDECLTYPE_UNUSED
Type field in the declaration is unused. This is designed for use with D3DDECLMETHOD_UV and D3DDECLMETHOD_LOOKUPPRESAMPLED.

Remarks

Vertex data is declared with an array of D3DVERTEXELEMENT9 structures. Each element in the array contains a vertex declaration data type.

Use the DirectX Caps Viewer Tool tool to see which types are supported on your device.

Identifies the intended use of vertex data.

typedef enum D3DDECLUSAGE
{
D3DDECLUSAGE_POSITION = 0,
D3DDECLUSAGE_BLENDWEIGHT = 1,
D3DDECLUSAGE_BLENDINDICES = 2,
D3DDECLUSAGE_NORMAL = 3,
D3DDECLUSAGE_PSIZE = 4,
D3DDECLUSAGE_TEXCOORD = 5,
D3DDECLUSAGE_TANGENT = 6,
D3DDECLUSAGE_BINORMAL = 7,
D3DDECLUSAGE_TESSFACTOR = 8,
D3DDECLUSAGE_POSITIONT = 9,
D3DDECLUSAGE_COLOR = 10,
D3DDECLUSAGE_FOG = 11,
D3DDECLUSAGE_DEPTH = 12,
D3DDECLUSAGE_SAMPLE = 13,
} D3DDECLUSAGE, *LPD3DDECLUSAGE;

Constants

D3DDECLUSAGE_POSITION
Position data ranging from (-1,-1) to (1,1). Use D3DDECLUSAGE_POSITION with a usage index of 0 to specify untransformed position for fixed function vertex processing and the n-patch tessellator. Use D3DDECLUSAGE_POSITION with a usage index of 1 to specify untransformed position in the fixed function vertex shader for vertex tweening.
D3DDECLUSAGE_BLENDWEIGHT
Blending weight data. Use D3DDECLUSAGE_BLENDWEIGHT with a usage index of 0 to specify the blend weights used in indexed and nonindexed vertex blending.
D3DDECLUSAGE_BLENDINDICES
Blending indices data. Use D3DDECLUSAGE_BLENDINDICES with a usage index of 0 to specify matrix indices for indexed paletted skinning.
D3DDECLUSAGE_NORMAL
Vertex normal data. Use D3DDECLUSAGE_NORMAL with a usage index of 0 to specify vertex normals for fixed function vertex processing and the n-patch tessellator. Use D3DDECLUSAGE_NORMAL with a usage index of 1 to specify vertex normals for fixed function vertex processing for vertex tweening.
D3DDECLUSAGE_PSIZE
Point size data. Use D3DDECLUSAGE_PSIZE with a usage index of 0 to specify the point-size attribute used by the setup engine of the rasterizer to expand a point into a quad for the point-sprite functionality.
D3DDECLUSAGE_TEXCOORD
Texture coordinate data. Use D3DDECLUSAGE_TEXCOORD, n to specify texture coordinates in fixed function vertex processing and in pixel shaders prior to ps_3_0. These can be used to pass user defined data.
D3DDECLUSAGE_TANGENT
Vertex tangent data.
D3DDECLUSAGE_BINORMAL
Vertex binormal data.
D3DDECLUSAGE_TESSFACTOR
Single positive floating point value. Use D3DDECLUSAGE_TESSFACTOR with a usage index of 0 to specify a tessellation factor used in the tessellation unit to control the rate of tessellation. For more information about the data type, see D3DDECLTYPE_FLOAT1.
D3DDECLUSAGE_POSITIONT
Vertex data contains transformed position data ranging from (0,0) to (viewport width, viewport height). Use D3DDECLUSAGE_POSITIONT with a usage index of 0 to specify transformed position. When a declaration containing this is set, the pipeline does not perform vertex processing.
D3DDECLUSAGE_COLOR
Vertex data contains diffuse or specular color. Use D3DDECLUSAGE_COLOR with a usage index of 0 to specify the diffuse color in the fixed function vertex shader and pixel shaders prior to ps_3_0. Use D3DDECLUSAGE_COLOR with a usage index of 1 to specify the specular color in the fixed function vertex shader and pixel shaders prior to ps_3_0.
D3DDECLUSAGE_FOG
Vertex data contains fog data. Use D3DDECLUSAGE_FOG with a usage index of 0 to specify a fog blend value used after pixel shading finishes. This applies to pixel shaders prior to version ps_3_0.
D3DDECLUSAGE_DEPTH
Vertex data contains depth data.
D3DDECLUSAGE_SAMPLE
Vertex data contains sampler data. Use D3DDECLUSAGE_SAMPLE with a usage index of 0 to specify the displacement value to look up. It can be used only with D3DDECLUSAGE_LOOKUPPRESAMPLED or D3DDECLUSAGE_LOOKUP.

Remarks

Vertex data is declared with an array of D3DVERTEXELEMENT9 structures. Each element in the array contains a usage type.

For more information about vertex declarations, see Vertex Declaration (Direct3D 9).

Here's a small example of using load_vertex_shader. First, I declare an array of vertex elements that are used to create the vertex declaration object.

// Declare the vertex shader declaration elements
D3DVERTEXELEMENT9 Elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

Then I instance the vertex shader and vertex declaration objects and call load_vertex_shader.

// Instance objects
IDirect3DVertexShader9 *pShader = NULL;
IDirect3DVertexDeclaration9 *pDecl = NULL;

// Load the vertex shader and create declaration interface
load_vertex_shader(&pShader, pDevice, "Shader.vsh", &Elements, &pDecl);

As you can see, it's a quick and simple function that gets the job done. From here on out, you can set the vertex shader (represented by pShader) using the IDirect3DDevice9::SetVertexShader function. To set the vertex declaration (represented by pDecl), you would call IDirect3DDevice9::SetVertexDeclaration.

pD3DDevice−>SetFVF(NULL); // Clear FVF usages
pD3DDevice−>SetVertexShader(pShader);
pD3DDevice−>SetVertexDeclaration(pDecl);

Okay, enough of initializing and loading vertex shaders, let's move on to the cool stuff, like loading and rendering meshes.


posted on 2008-04-14 13:39 lovedday 閱讀(1391) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美mv日韩mv国产网站| 国产一区二区三区久久悠悠色av | 国产一区二区三区av电影| 国产亚洲第一区| 欧美综合第一页| 久久国产免费| 91久久视频| 99精品国产在热久久下载| 国产精品高潮呻吟久久av黑人| 亚洲欧美国产高清| 香蕉国产精品偷在线观看不卡| 狠狠v欧美v日韩v亚洲ⅴ| 麻豆久久久9性大片| 欧美大胆人体视频| 亚洲深爱激情| 欧美在线观看视频在线| 亚洲国产精品一区在线观看不卡| 亚洲韩日在线| 国产精品乱子乱xxxx| 久久久国产视频91| 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲午夜精品久久久久久浪潮| 国产嫩草一区二区三区在线观看| 久久一区二区视频| 欧美日韩国产天堂| 久久久久久夜| 欧美久久在线| 久久天天躁狠狠躁夜夜爽蜜月| 欧美成人综合网站| 欧美在线观看视频在线| 欧美不卡激情三级在线观看| 欧美国产成人精品| 久久综合久久综合这里只有精品| 亚洲免费在线观看视频| 国产精品乱人伦中文| 欧美3dxxxxhd| 国产精品美女久久| 最新成人av在线| 国产偷自视频区视频一区二区| 亚洲激情欧美激情| 黄色成人91| 国产精品99久久久久久人 | 久久久青草青青国产亚洲免观| 亚洲免费成人av电影| 欧美诱惑福利视频| 亚洲欧美日韩国产精品| 欧美jizzhd精品欧美巨大免费| 欧美在线观看日本一区| 欧美日韩综合在线免费观看| 欧美成人国产va精品日本一级| 国产精品乱码人人做人人爱| 久久精品成人| 亚洲精品日韩在线| 在线免费观看欧美| 欧美综合国产| 欧美在线视频播放| 国产精品美女www爽爽爽| 亚洲精品一区二区三区不| 在线精品福利| 久久久久久欧美| 久久久久久免费| 国产综合色产在线精品| 亚洲免费中文字幕| 欧美亚洲一区| 国产欧美一区二区白浆黑人| 亚洲夜晚福利在线观看| 午夜精品国产更新| 国产精品欧美日韩| 亚洲欧美一区二区三区久久| 欧美一级淫片aaaaaaa视频| 国产精品久久久久av| 中日韩午夜理伦电影免费| 一区二区三区四区国产精品| 欧美日韩亚洲高清一区二区| 一区二区欧美在线| 亚洲欧美不卡| 国产视频一区二区在线观看 | 欧美mv日韩mv国产网站| 影视先锋久久| 欧美大片免费久久精品三p | 欧美中日韩免费视频| 久久精品国产在热久久| 韩国成人精品a∨在线观看| 久久久久久久一区二区| 亚洲电影第三页| 妖精视频成人观看www| 国产精品成人免费视频| 香蕉视频成人在线观看| 欧美freesex8一10精品| 99精品欧美一区| 国产精品一二一区| 久久夜色精品国产| 亚洲三级视频| 欧美自拍偷拍午夜视频| 在线看日韩av| 欧美日韩国产限制| 一本色道久久综合亚洲精品不| 久久人人精品| 亚洲经典一区| 亚洲精品久久久蜜桃| 亚洲欧美精品| 亚洲大胆人体在线| 国产精品magnet| 久久精品亚洲乱码伦伦中文| 亚洲日本中文字幕区 | 欧美色图首页| 欧美综合77777色婷婷| 最新日韩精品| 久久精品一二三区| 夜夜嗨av一区二区三区四季av| 国产精品乱码| 欧美激情网友自拍| 久久国产黑丝| 亚洲一区二区av电影| 亚洲黄色大片| 免费成人高清在线视频| 亚洲欧美日韩网| 99精品久久久| 欧美wwwwww| 亚洲欧美网站| 国产乱码精品一区二区三区不卡| 久久久久在线观看| 午夜欧美电影在线观看| 99热在线精品观看| 欧美激情一区二区三区高清视频| 欧美在线免费一级片| 亚洲深夜影院| 日韩视频一区| 亚洲高清网站| 伊人伊人伊人久久| 国产亚洲日本欧美韩国| 国产精品午夜久久| 欧美香蕉大胸在线视频观看| 欧美精品福利在线| 蜜桃精品一区二区三区| 欧美中文在线视频| 欧美在线视频免费观看| 性刺激综合网| 欧美一级一区| 欧美一区二区国产| 新67194成人永久网站| 亚洲欧美一区二区视频| 一区二区三区视频在线观看| 亚洲精品综合| av不卡在线| 正在播放亚洲| av成人毛片| 一区二区三区日韩精品| 中文无字幕一区二区三区| 中文在线资源观看网站视频免费不卡 | 欧美日韩一二三四五区| 欧美日韩1区2区| 欧美午夜激情小视频| 国产精品伦一区| 国产日韩欧美中文| 一色屋精品视频在线观看网站| 红桃视频一区| 亚洲黄色小视频| 一区二区三区欧美在线| 亚洲一本视频| 欧美专区日韩视频| 久久综合给合| 亚洲国产高清aⅴ视频| 亚洲免费观看在线观看| 亚洲午夜av在线| 久久大逼视频| 欧美激情网友自拍| 国产精品日韩一区二区| 一区二区三区在线观看视频| 亚洲精品乱码| 亚洲欧美日本伦理| 另类天堂视频在线观看| 91久久久久久国产精品| 亚洲综合成人在线| 久久久久久久久久久一区 | 国产精品久久久久高潮| 国产一区美女| 99亚洲精品| 久久午夜精品一区二区| 91久久线看在观草草青青| 亚洲视频免费在线| 久久网站热最新地址| 欧美网站在线| 亚洲第一主播视频| 亚洲欧美日韩电影| 欧美国产在线电影| 午夜久久久久久| 欧美精品在线视频| 激情综合色丁香一区二区| 亚洲天堂视频在线观看| 久久婷婷亚洲| 亚洲图片你懂的| 欧美大香线蕉线伊人久久国产精品| 国产精品wwwwww| 亚洲精品永久免费精品| 久久久99国产精品免费| 一区二区三区精密机械公司 | 久久激五月天综合精品| 欧美性久久久| 9色精品在线|