Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I developed a small 3d games xna and uses a "DynamicVertexBuffer" and "DynamicIndexBuffer" to store and draw my vertices. Everything works fine, but my problem is the "Update" function where I update my buffer. Each apel update I have to reset my buffer using the keyword "new DynamicVertexBuffer (...." It goes down the performance and reduce the frames per second of my games.

Do I have to initialize my buffer each time in my function "Update ()"? Is it okay to reset every time my buffer to each call / frame

I can not find a solution to update correctly my Dynamicbuffer with "setData ()" function without having to initialize whenever my buffer just before. Am I obliged to Reset-"DynamicVertexBuffer" and "DynamicIndexBuffer" before the update? If I call "setData ()" before reset it, I throw an exception:

Works well but I have initialized every time "dynamicIndexBuffer" and "dynamicVertexBuffer" before update! (Consumes more resources?)

    public override void Update(GameTime gameTime)
    {
                foreach (Octree.Node node in regions[regionIndex].Nodes.Where(n => n.ItemGroup == a).Where(m => arcadia.camera.Frustum.Contains(m.boundingBox) != ContainmentType.Disjoint))
                {
                    //build indices 
                    node.Cube.SetUpIndices(indexIndiceBuild);
                    //Add indices tho the collectionList
                    foreach (int indice in node.Cube.Indices)
                    {
                        list_structure_indices.Add(indice);
                    }
                    //Add vertex to the collectionList
                    foreach (VertexPositionTexture posText in node.Cube.Vertices)
                    {
                        vertexPositionStructureCube.Add(posText);
                    }
                    //Add vertexBuffer to the collectionList
                    indexIndiceBuild += 24;
                }
                    //Declare and initialize new buffers
                    //VertexBuffer Initialize again
                    vertexBuffer_cube = new DynamicVertexBuffer(
                    arcadia.Game.GraphicsDevice,
                    VertexPositionTexture.VertexDeclaration,
                    vertexPositionStructureCube.Count,
                    BufferUsage.WriteOnly);

                    //VertexBuffer SetData (update)
                    vertexBuffer_cube.SetData<VertexPositionTexture>(vertexPositionStructureCube.ToArray());
                    //IndexBuffer Initialize again
                    indexBuffer_cube = new DynamicIndexBuffer(Game.GraphicsDevice, IndexElementSize.ThirtyTwoBits, list_structure_indices.Count, BufferUsage.WriteOnly);
                    //IndexBuffer SetData (update)
                    indexBuffer_cube.SetData(list_structure_indices.ToArray());
                    .........
}

I'm just trying to update with "SetData" with new vertices and indices but i throws the exception: "The array is not the proper size for the Amount of data requested."

    public override void Update(GameTime gameTime)
    {
                    .........
                    //Only "setdata()" without initialize buffer again ??
                    //VertexBuffer SetData (update)
                    vertexBuffer_cube.SetData<VertexPositionTexture>(vertexPositionStructureCube.ToArray());

                    //IndexBuffer SetData (update)
                    indexBuffer_cube.SetData(list_structure_indices.ToArray());

                    .........
}
share|improve this question
    
Dynamic Vertex Buffers are a pain. Tried something similar to what you are attempting, then dropped them completely. They dont really improve performance in large scale voxel (cube) terrain engines. –  Jason Coombes Apr 9 '13 at 12:00

1 Answer 1

Are your vertices changing every update? If not then you don't have to worry about updating them each frame.

share|improve this answer
    
Yes almost. Whenever the player moves the camera, I get and draws only the vertices that is in the field of view of the camera. This is why I often need to update. –  Mehdi Bugnard Apr 7 '13 at 19:33
    
@MehdiBugnard that sounds horribly inefficient compared to, say, per-object frustum culling –  Tetrad Apr 9 '13 at 0:00
    
But in fact I use the "Frustum" to update it to draw only the cubes that is in my field of vision. But with his, my data buffer must change every time the player moves the camera ... Do I have to initialize my buffer each time in my function "Update ()"? Is it okay to reset every time my buffer to each call / frame ... I have edited my function for more information with "frustum" –  Mehdi Bugnard Apr 9 '13 at 9:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.