HeavenWu / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

DX11: Maybe wrong buffer size when using Quad-Patches? #623

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The problem is a little bit complicated to explain. First of all: I'm using
the current SlimDX SVN-build.

I need to render Quad-Patches with 4 control points. These control points
will be needed by the DX11 tesselation I'm using. For the moment I've 6
Quads â 4 control points. Each control point has a Vector3 position and a
Vector2 texture coordinate. This control point topology is described by the
following lines:

######################################################
/// <summary>
/// The vertex interface.
/// </summary>
public interface Vertex { }

/// <summary>
/// VertexPT struct.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
struct VertexPT : Vertex {
    public Vector3 p;
    public Vector2 t;
}
######################################################

OK. I'm building the vertex buffer by the following code:

######################################################
// count the vertices
int count = m_vertices.Count;

// create the stream using the type of the first vertice
int stride = Marshal.SizeOf(m_vertices[0].GetType());
DataStream stream = new DataStream(count * stride, true, true);
foreach (Vertex vertex in m_vertices) {
    if (vertex is VertexPT) {
        stream.Write((VertexPT)vertex);
    }
}
stream.Position = 0;

// create the buffer description
BufferDescription bufferDescription = new BufferDescription();
bufferDescription.BindFlags = BindFlags.VertexBuffer;
bufferDescription.CpuAccessFlags = CpuAccessFlags.None;
bufferDescription.OptionFlags = ResourceOptionFlags.None;
bufferDescription.SizeInBytes = (int)stream.Length;
bufferDescription.Usage = ResourceUsage.Default;

// create the buffer
buffer = new Buffer(ResourceManager.device, stream, bufferDescription);
stream.Close();
######################################################

Now, if I render this, I get the first 5 quads rendered properly. But the
last one gets wrong texture coordinates. I've investigated this and it
seems, that only the last rendered quad is not rendered property. So again
I tested things and if I do this (look on the +4!):

DataStream stream = new DataStream(count * stride + 4, true, true);

it seems that now all quads renders well. Why? It doesn't matter, how many
quads I'm rendering. Is this a DX problem, or maybe SlimDX, or maybe I'm
doing something wrong ^^. Can you explain this to me, if the last one is
the case?

Original issue reported on code.google.com by remi2...@googlemail.com on 7 Feb 2010 at 3:33

GoogleCodeExporter commented 8 years ago
OK, I've found the problem:

I've specified R32G32B32_Float as format for the texture coordinates on input
elements for the input topology. By I've to specify R32G32_Float. Then it works
correctly.

Sorry for stealing your time.

Original comment by remi2...@googlemail.com on 8 Feb 2010 at 12:01

GoogleCodeExporter commented 8 years ago

Original comment by Mike.Popoloski on 8 Feb 2010 at 4:15