Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
Welcome to the general discussions!
  • Page:
  • 1

TOPIC: [Toolkit] Dynamic updating of point values

[Toolkit] Dynamic updating of point values 1 year 4 months ago #1268


  • Posts:6
  • henriko's Avatar
  • henriko
  • Fresh Boarder
  • OFFLINE
I guess this is a simple question but I’m struggling with updating data when using the SharpDx.toolkit.
I started out with the MiniCube toolkit sample. What I want to do is simply change the VertexPositionColor values for each frame. E.g. initially there are 36 VertexPositionColor values given (the corners of the cube) and then for each frame I just want to change the coordinates and colors of the different points.
I tried using the SetData() function on the vertices Buffer but It just throws an Exception.

(PS: My final goal is to create a live point cloud visualization from the Kinect using PrimitiveType.PointList instead of TriangleList and then change the x,y,z coordinates and the color of the vertices each frame)


protected override void Update(GameTime gameTime)
{
// Rotate the cube.
var time = (float)gameTime.TotalGameTime.TotalSeconds;
VertexPositionColor[] p = new VertexPositionColor[]
{
new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.DarkOrange),
.... < more vertices goes here > ....
new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.DarkOrange),
new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.DarkOrange),
};

vertices.SetData<VertexPositionColor>(p); // <-- THIS DOES NOT WORK
// Handle base.Update
base.Update(gameTime);
}
Last Edit: 1 year 4 months ago by henriko. Reason: Some errors in the text, clarifying
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1273


  • Posts:32
  • ChaosDev's Avatar
  • ChaosDev
  • Junior Boarder
  • OFFLINE
Try create Buffer with Dynamic using. By default buffers can be Default or Immutable which prevents any interaction with them.
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1274


  • Posts:6
  • henriko's Avatar
  • henriko
  • Fresh Boarder
  • OFFLINE
Thank you for the suggestion but I'm not entirely sure if I understood how I'm supposed to do that, sorry. In the code now the vertices Buffer is created like this (its the exact MiniCube example from SharpDx.Toolkit:

private Buffer<VertexPositionColor> vertices;

However, I do believe that the error might be due to something else because the error message is:

HRESULT: [0x80070057], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: The parameter is incorrect.

Fortunately I have managed to do it another way instead. Maybe not the most effective way of doing it, but it works for now. The code that works is instead of inserting data into an already created Buffer (vertices), I create a new buffer for each frame like this:

vertices = Buffer.Vertex.New(GraphicsDevice,p); // <-- WORKS
//vertices.SetData(p); // <-- Does not work producing an error as stated above
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1278


  • Posts:1
  • Erik's Avatar
  • Erik
  • Fresh Boarder
  • OFFLINE
You create a dynamic buffer like this:

vertices = Buffer.Vertex.New(GraphicsDevice, p, SharpDX.Direct3D11.ResourceUsage.Dynamic);


You could also look at primitivebatch, some example code:

load:
pb = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);

draw:
{
GraphicsDevice.Clear(Color.White);
basicEffect.CurrentTechnique.Passes[0].Apply();
pb.Begin();
pb.Draw(PrimitiveType.PointList, vertices);
pb.End();

base.Draw(gameTime);
}
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1284


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
The solution is pretty simple... but you should really learn how to debug this and find the problem yourself: Create the device with Debug flag (something like deviceManager.DeviceCreationFlags = CreationFlags.Debug) and check the box "enable unmanaged debugging" in the project settings/debug tab, and you should get a clear debug message on the output console why it is failing.
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1309


  • Posts:6
  • henriko's Avatar
  • henriko
  • Fresh Boarder
  • OFFLINE
Thank you very much Erik and xoofx.

It was of course that I hadn't created the Buffer dynamic as you pointed out Erik. I was not aware of the details that a Buffer upon creation is eiter GPU only, or both CPU/GPU readable and so forth. It makes Perfect sense though when I understood it :-) It's just that in the beginning DirectX/GPU programming feels a little different to what I'm used to.

Also, xoofx, thank you very much for the information on how to get better debug information. It helped a lot in pin-pointing where exactly the problem was appearing. The actual debug message did not change, it was still "Parameter is incorrect" as before, which doesn't actually give that much. But I did get the stack trace and by downloading the SharpDX source code I could look into the SetData function where I could finally understand what happened and also make the link to what Erik was talking about.
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1310


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
henriko wrote:
Also, xoofx, thank you very much for the information on how to get better debug information. It helped a lot in pin-pointing where exactly the problem was appearing. The actual debug message did not change, it was still "Parameter is incorrect" as before, which doesn't actually give that much.
Are you sure that you setup things correctly? Because doing this:
vertices = Buffer.Vertex.New(GraphicsDevice, data); // Texture is created by default with Immutable, so It cannot be updated later
vertices.SetData(data); // This will generate an exception
Will result in an exception on SetData as expected with the message "The parameter is incorrect", but you should have a log just before this exception:
D3D11 ERROR: ID3D11DeviceContext::Map: Map cannot be called with MAP_WRITE_DISCARD access, because the Resource was not created with the D3D11_CPU_ACCESS_WRITE flag. [ RESOURCE_MANIPULATION ERROR #2097210: RESOURCE_MAP_INVALIDMAPTYPE]
And after this message a more traditional exception message:
A first chance exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: HRESULT: [0x80070057], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: The parameter is incorrect.
This detailed message is only printed while you debug your application. looking at the Output log tab of VS, and if you have turned on "enable unsafe code debugging" in your project settings/debug. Whenever you have an exception in D3D11, you will more likely have a detailled message before this exception is thrown. You could also get a warning (which sometimes can be an invalid usage).
The administrator has disabled public write access.

Re: [Toolkit] Dynamic updating of point values 1 year 4 months ago #1312


  • Posts:6
  • henriko's Avatar
  • henriko
  • Fresh Boarder
  • OFFLINE
Xoofx,

I had some problems with my version of VS 2010 because when I enabled "native code debugging", it started the Visual Studio installer everytime I tried running the program. Since I did not have the DVD with Visual Studio 2010 lying around the installer stopped and asked me to insert it, since I dont know where the DVD was I just cancelled the installation. I guess that means it was not able to turn on native debugging after all. I had a feeling that there was something wrong because of this so I started installing Visual Studio 2012 instead. I was going to upgrade at some point anyhow so.

When I did the same thing in VS 2012 everything worked as expected and I got the same error output as you in the Output window. This is a lot easier to work with and will be of great help for further explorations into your great C# DirectX API and the SharpDX.Toolkit.

Since I know you are a busy man I really appreciate that you took time to point me in the right direction. Made a small donation just now as an appreciation token for the fine work you have done with SharpDX :)
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.292 seconds