zoukankan      html  css  js  c++  java
  • DX SetFVF

    自由顶点格式(flexible vertex format,FVF)

    http://www.cnblogs.com/xmzyl/articles/1604096.html

    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
    // Draw the triangles in the vertex buffer. This is broken into a few
    // steps. We are passing the Vertices down a "stream", so first we need
    // to specify the source of that stream, which is our vertex buffer. Then
    // we need to let D3D know what vertex shader to use. Full, custom vertex
    // shaders are an advanced topic, but in most cases the vertex shader is
    // just the FVF, so that D3D knows what type of Vertices we are dealing
    // with. Finally, we call DrawPrimitive() which does the actual rendering
    // of our geometry (in this case, just one triangle).
    g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );

    // End the scene
    g_pd3dDevice->EndScene();
    }

    通过setFVF 按照我的理解 就是告诉shader 他要处理的vertices里面的格式

    注释那段话已经说的很详细了 我们自己定义vertex buffer里的结构类型 ,比如D3DFVF_XYZ,D3DFVF_NORMAL,D3DFVF_TEX0.....

    很眼熟吧,你规定的这些是可以在shader中使用的。

    ------------------------------------------------------------------------------

    因为很多链接会失效,我还是把那段抄过来吧 ,有关fvf的使用步骤

    struct CustomerVertex
    {
      FLOAT x,y,z,rhw;
      DWORD color; 
    };

    #define D3DFVF_CUSTOMVERTEX(D3DFVF_XYZRHW|D3DFVF_DIFFUSE) 

    g_pd3dDevice->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                                     
    0
                                     D3DFVF_CUSTOMVERTEX,
                                     D3DPOOL_DEFAULT, 
                                     
    &g_pVB, NULL )  

    CUSTOMVERTEX vertices[] =
    {
      { 
    100.0f400.0f0.5f1.0f0xffff0000, },
      { 
    300.0f,  50.0f0.5f1.0f0xff00ff00, }, 
      { 
    500.0f400.0f0.5f1.0f0xff0000ff, },
    };

    然后将数据写入缓冲区:

    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0sizeof(vertices), (void**)&pVertices, 0 ) ) )
      
    return E_FAIL;
    memcpy( pVertices, vertices, 
    sizeof(vertices) );
    g_pVB
    ->Unlock();

    这里写入的过程用的是Lock函数得到的缓冲区的地址,然后用memcpy函数将自己写好的数据写进去。到这里,顶点就算是创建好了。

  • 相关阅读:
    5、python中的列表
    Linux---配置新服务器的常见操作(CentOS7)
    MapReduce原理篇
    用MR实现Join逻辑的两种方法
    Linux静态库与共享库
    mysql命令查看表结构及注释
    mysql 数据同步到 elastsearch7 数字类型精度丢失
    canal client-adapter 将mysql数据同步到 es elasticsearch 日期时间少8小时问题解决
    如何用redis做活跃用户统计-HyperLoglog
    jvm 虚拟机内存布局
  • 原文地址:https://www.cnblogs.com/minggoddess/p/3494661.html
Copyright © 2011-2022 走看看