• <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 夢在天涯 閱讀(1395) 評論(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

            搜索

            •  

            積分與排名

            • 積分 - 1807508
            • 排名 - 5

            最新評論

            閱讀排行榜

            www.久久热.com| 亚洲精品NV久久久久久久久久| 精品综合久久久久久88小说| 久久福利片| 久久久久久国产a免费观看黄色大片| 久久久久久国产a免费观看黄色大片| 久久精品桃花综合| 国产亚洲精久久久久久无码| 久久综合伊人77777麻豆| 精品久久久久久亚洲精品 | 777午夜精品久久av蜜臀| 国产亚洲欧美精品久久久| 精品一久久香蕉国产线看播放| 亚洲精品无码久久千人斩| 午夜精品久久久久成人| 亚洲精品高清国产一久久| 亚洲AV无码久久精品蜜桃| 国内精品久久久久久久久电影网| 国产精品中文久久久久久久| 久久激情五月丁香伊人| 国产精品99久久精品爆乳| 久久国产热精品波多野结衣AV| 奇米影视7777久久精品人人爽 | 久久亚洲国产精品成人AV秋霞| 久久国产精品99久久久久久老狼| 久久亚洲国产成人精品性色| 五月丁香综合激情六月久久| 久久一本综合| 国产99久久九九精品无码| 丁香五月网久久综合| 久久久精品人妻一区二区三区蜜桃 | 久久午夜无码鲁丝片秋霞 | 欧洲国产伦久久久久久久| 久久精品亚洲精品国产欧美| 欧美精品一区二区精品久久| 99久久精品九九亚洲精品| 69久久精品无码一区二区| 久久国产精品77777| 国产精品久久网| 久久免费国产精品一区二区| 久久亚洲精品视频|