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

            搜索

            •  

            積分與排名

            • 積分 - 1804752
            • 排名 - 5

            最新評論

            閱讀排行榜

            人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 久久亚洲春色中文字幕久久久| 午夜精品久久久久久影视777| 一本色道久久综合| 精品乱码久久久久久久| 狠狠久久综合| 99久久超碰中文字幕伊人| 四虎影视久久久免费| 久久国产精品成人影院| 日本加勒比久久精品| 国内精品久久九九国产精品| 亚洲精品第一综合99久久| 成人亚洲欧美久久久久| 婷婷久久久亚洲欧洲日产国码AV | 热re99久久精品国99热| 久久精品成人免费观看97| 久久综合狠狠综合久久综合88| 精品久久久久国产免费| 亚洲va中文字幕无码久久| 久久亚洲欧洲国产综合| 99精品久久精品一区二区| 日本WV一本一道久久香蕉| 久久国产视频99电影| 久久综合久久综合久久| 久久精品国产99久久无毒不卡| 色婷婷综合久久久久中文字幕| 亚洲精品高清久久| 久久不射电影网| 日本道色综合久久影院| 国产高潮国产高潮久久久| 亚洲国产精品成人久久| 久久伊人五月丁香狠狠色| 午夜精品久久久久久久无码| 国産精品久久久久久久| 久久九九久精品国产免费直播| 99久久无码一区人妻| 久久福利青草精品资源站免费| 久久精品九九亚洲精品| 久久99国产综合精品免费| 久久亚洲中文字幕精品有坂深雪| 久久人人爽人人爽人人av东京热|