• <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++ 基礎(chǔ)} {C++ 高級(jí)} {C#界面,C++核心算法} {設(shè)計(jì)模式} {C#基礎(chǔ)}

            managed directx實(shí)現(xiàn)讀寫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 夢(mèng)在天涯 閱讀(1391) 評(píng)論(1)  編輯 收藏 引用 所屬分類: DirectX

            評(píng)論

            # re: managed directx實(shí)現(xiàn)讀寫buffer (Read and Write VertexBuffer and IndexBuffer Data)[未登錄](méi) 2007-11-09 15:34 夢(mèng)在天涯

            除了上面提到的vertexbuffer來(lái)存model。

            我們還可以使用indexbuffer+vertexbuffer來(lái)存,

            還可以使用vertexelement+vertexbuffer來(lái)存。  回復(fù)  更多評(píng)論   

            公告

            EMail:itech001#126.com

            導(dǎo)航

            統(tǒng)計(jì)

            • 隨筆 - 461
            • 文章 - 4
            • 評(píng)論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1804603
            • 排名 - 5

            最新評(píng)論

            閱讀排行榜

            一本久久a久久精品vr综合| 婷婷伊人久久大香线蕉AV| 久久免费的精品国产V∧| 久久人人爽人人人人爽AV| 久久天天日天天操综合伊人av| 久久香蕉综合色一综合色88| 久久99精品久久久久婷婷| 奇米影视7777久久精品| 久久丫精品国产亚洲av| 久久精品国产亚洲av麻豆小说| 伊人久久精品无码av一区| 久久精品国产亚洲αv忘忧草| 久久婷婷人人澡人人爽人人爱| 免费精品久久天干天干| 久久久久久久波多野结衣高潮| 久久久久久国产精品无码下载| 伊人久久大香线蕉亚洲| 久久亚洲国产成人精品性色| 精品一区二区久久| 精品久久久无码中文字幕天天| 久久婷婷人人澡人人| 国产精品久久久香蕉| 国产aⅴ激情无码久久| 久久久久无码精品国产| 亚洲国产精品人久久| 精品国产婷婷久久久| 一本久久免费视频| 久久久久高潮毛片免费全部播放| 99久久99这里只有免费的精品| 91久久精品国产成人久久| 久久久久国色AV免费看图片| 香蕉久久久久久狠狠色| 久久亚洲精精品中文字幕| 狠狠久久综合| 久久久亚洲裙底偷窥综合| AAA级久久久精品无码片| 国产激情久久久久影院老熟女免费| 欧美激情精品久久久久久久九九九| 久久人妻少妇嫩草AV蜜桃| 99久久国产热无码精品免费久久久久| 亚洲人AV永久一区二区三区久久|