Skip to content

Commit 9911b94

Browse files
Manually define the plane vertex layout in managed code so we're certain it matches the vertex layout in native code
1 parent 397d269 commit 9911b94

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

UnityProject/Assets/UseRenderingPlugin.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System;
33
using System.Collections;
44
using System.Runtime.InteropServices;
5-
5+
using UnityEngine.Rendering;
66

77
public class UseRenderingPlugin : MonoBehaviour
88
{
@@ -80,10 +80,23 @@ private void CreateTextureAndPassToPlugin()
8080
private void SendMeshBuffersToPlugin ()
8181
{
8282
var filter = GetComponent<MeshFilter> ();
83-
var mesh = filter.mesh;
84-
// The plugin will want to modify the vertex buffer -- on many platforms
85-
// for that to work we have to mark mesh as "dynamic" (which makes the buffers CPU writable --
86-
// by default they are immutable and only GPU-readable).
83+
var mesh = filter.mesh;
84+
85+
// This is equivalent to MeshVertex in RenderingPlugin.cpp
86+
var desiredVertexLayout = new[]
87+
{
88+
new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3),
89+
new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3),
90+
new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.Float32, 4),
91+
new VertexAttributeDescriptor(VertexAttribute.TexCoord0, VertexAttributeFormat.Float32, 2)
92+
};
93+
94+
// Let's be certain we'll get the vertex buffer layout we want in native code
95+
mesh.SetVertexBufferParams(mesh.vertexCount, desiredVertexLayout);
96+
97+
// The plugin will want to modify the vertex buffer -- on many platforms
98+
// for that to work we have to mark mesh as "dynamic" (which makes the buffers CPU writable --
99+
// by default they are immutable and only GPU-readable).
87100
mesh.MarkDynamic ();
88101

89102
// Make sure to have vertex colors so that the plugin can rely on a known

0 commit comments

Comments
 (0)