• <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>

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            managed directx實現讀寫buffer (Read and Write VertexBuffer and IndexBuffer Data)

            Read and Write VertexBuffer and IndexBuffer Data With GraphicsStreams


            using  System;
            using  Microsoft.DirectX;
            using  Microsoft.DirectX.Direct3D;

            public   struct  PositionNormalTexVertex
            {
                
            public  Vector3 Position;
                
            public  Vector3 Normal;
                
            public    float  Tu0, Tv0;
                
            public   static   readonly  VertexFormats FVF  =  VertexFormats.Position  |  VertexFormats.Texture1;
            }

            public   class  Example
            {
                
            public   unsafe   void   GraphicsStreamReadWrite()
                
            {
                    
            // Create a vertex buffer in the managed pool
                    VertexBuffer vb  =   new  VertexBuffer( typeof (PositionNormalTexVertex),  100 , device, Usage.None, PositionNormalTexVertex.FVF, Pool.Managed);

                    
            // First, fill an array of PositionNormalTexVertex elements with data.
                    PositionNormalTexVertex[] vertices  =   new  PositionNormalTexVertex[ 50 ];
                    
            for ( int  i = 0 ; i < 50 ; i ++ )
                    
            {
                        
            // fill the vertices with some data
                        vertices[i].Position  =   new  Vector3(3f,4f,5f);
                    }


                    
            // The size of the verticies are 32-bytes each (float3 (12) + float3 (12) + float(4) + float(4))
                    
            // To lock 50 verticies, the size of the lock would be 1600 (32 * 50)
                    GraphicsStream vbData  =   vb.Lock( 0 , 1600 , LockFlags.None);

                    
            // copy the vertex data into the vertex buffer
                    vbData.Write(vertices);

                    
            // Unlock the VB
                    vb.Unlock();


                    
            // This time, lock the entire VertexBuffer
                    vbData  =   vb.Lock( 0 3200 , LockFlags.None);

                    
            // Cast the InternalDataPointer (a void pointer) to an array of verticies
                    PositionNormalTexVertex *  vbArray  =  (PositionNormalTexVertex * ) vbData.InternalDataPointer;

                    
            for ( int  i = 0 ; i < 100 ; i ++ )
                    
            {
                        
            // perform some operations on the data
                        vbArray[i].Tu0  =  i;
                        vbArray[i].Tv0 
            =  vbArray[i].Tu0  *   2 ;

                        Console.WriteLine(vbArray[i].Tv0.ToString());
                    }


                    
            // Unlock the buffer
                    vb.Unlock();
                    vb.Dispose();
                }

            }

            Read and Write VertexBuffer Data With Arrays

             

            using System;
            using Microsoft.DirectX;
            using Microsoft.DirectX.Direct3D;

            public struct PositionNormalTexVertex
            {
                
            public Vector3 Position;
                
            public Vector3 Normal;
                
            public float Tu0, Tv0;
                
            public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture1;
            }


            public class Example
            {
                
            public void ArrayBasedReadWrite()
                
            {
                    
            //Create a vertex buffer in the managed pool
                    VertexBuffer vb = new VertexBuffer(typeof(PositionNormalTexVertex), 100, device,                 Usage.None, PositionNormalTex1Vertex.FVF, Pool.Managed);

                    
            //Fill an array of the appropriate type with the VB data using Lock()
                    PositionNormalTexVertex[] vbData = (PositionNormalTexVertex[]) vb.Lock(0,                    typeof(PositionNormalTexVertex), LockFlags.None, 50);
                    
            for(int i=0; i<50; i++)
                    
            {
                        
            //set your vertices to something
                        vbData[i].Position = new Vector3(2f,2f,2f);  
                        vbData[i].Normal 
            = new Vector3(1f,0f,0f);
                        vbData[i].Tu0 
            = i;
                        vbData[i].Tv0 
            = i;
                    }

                    
            //Unlock the vb before you can use it elsewhere
                    vb.Unlock();

                    
            //This lock overload simply locks the entire VB -- setting ReadOnly                     //can improve perf when reading a vertexbuffer
                    vbData = (PositionNormalTexVertex[]) vb.Lock(0, LockFlags.ReadOnly);
                    
            for(int i=0; i<100; i++)
                    
            {
                        
            //read some vertex data
                        Console.WriteLine("Vertex " + i + "Tu: " +  vbData[i].Tu0 + " , Tv: " + vbData[i].Tv0);
                    }


                    
            //Unlock the buffer
                    vb.Unlock();


                    vb.Dispose();
                }

            }

            posted on 2006-06-09 16:39 夢在天涯 閱讀(1390) 評論(1)  編輯 收藏 引用 所屬分類: DirectX

            評論

            # re: managed directx實現讀寫buffer (Read and Write VertexBuffer and IndexBuffer Data)[未登錄] 2007-11-09 15:34 夢在天涯

            除了上面提到的vertexbuffer來存model。

            我們還可以使用indexbuffer+vertexbuffer來存,

            還可以使用vertexelement+vertexbuffer來存。  回復  更多評論   

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804303
            • 排名 - 5

            最新評論

            閱讀排行榜

            久久久精品国产sm调教网站| 国产亚州精品女人久久久久久| 亚洲精品无码久久不卡| 一本综合久久国产二区| 青青草原精品99久久精品66| 久久国产成人精品麻豆| 久久99精品久久久久久噜噜| 伊人久久大香线蕉综合5g | 一本一道久久综合狠狠老| 久久国产色av免费看| 久久亚洲欧美国产精品| 天天爽天天爽天天片a久久网| 女同久久| 浪潮AV色综合久久天堂| 久久露脸国产精品| 91精品国产综合久久久久久| 久久久久亚洲av毛片大| 欧美777精品久久久久网| 久久成人国产精品免费软件| 色噜噜狠狠先锋影音久久| 伊人久久大香线蕉亚洲五月天| 久久久久国产成人精品亚洲午夜| 99久久精品国产一区二区| 久久久久亚洲AV成人网人人网站| 久久99国内精品自在现线| 久久久久亚洲av成人无码电影 | 久久久精品人妻一区二区三区四| 久久久久久久综合日本| 日韩亚洲欧美久久久www综合网| 午夜精品久久久久久毛片| 三级片免费观看久久| 国产无套内射久久久国产| 久久精品国内一区二区三区| 久久综合给久久狠狠97色| 亚洲国产视频久久| 久久夜色精品国产噜噜亚洲a| 久久人人爽人人精品视频| 丰满少妇人妻久久久久久4| 久久99国产精品一区二区| 99国产欧美精品久久久蜜芽| 久久亚洲美女精品国产精品|