mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 21:25:41 +00:00
Fixed memory corruption issue with (Cube's vertices were being moved by the GC). I think.
This commit is contained in:
parent
d526f5a3a4
commit
6341ced26c
|
@ -10,12 +10,15 @@ using System.Text;
|
|||
using System.Drawing;
|
||||
|
||||
using OpenTK.Math;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Examples.Shapes
|
||||
{
|
||||
public static class Cube
|
||||
public class Cube : Shape
|
||||
{
|
||||
public static readonly Vector3[] Vertices = new Vector3[8]
|
||||
public Cube()
|
||||
{
|
||||
Vertices = new Vector3[]
|
||||
{
|
||||
new Vector3(-1.0f, -1.0f, 1.0f),
|
||||
new Vector3( 1.0f, -1.0f, 1.0f),
|
||||
|
@ -24,10 +27,10 @@ namespace Examples.Shapes
|
|||
new Vector3(-1.0f, -1.0f, -1.0f),
|
||||
new Vector3( 1.0f, -1.0f, -1.0f),
|
||||
new Vector3( 1.0f, 1.0f, -1.0f),
|
||||
new Vector3(-1.0f, 1.0f, -1.0f),
|
||||
new Vector3(-1.0f, 1.0f, -1.0f)
|
||||
};
|
||||
|
||||
public static readonly ushort[] Indices =
|
||||
Indices = new int[]
|
||||
{
|
||||
// front face
|
||||
0, 1, 2, 2, 3, 0,
|
||||
|
@ -43,7 +46,7 @@ namespace Examples.Shapes
|
|||
1, 5, 6, 6, 2, 1,
|
||||
};
|
||||
|
||||
public static readonly Vector3[] Normals =
|
||||
Normals = new Vector3[]
|
||||
{
|
||||
new Vector3(-1.0f, -1.0f, 1.0f),
|
||||
new Vector3( 1.0f, -1.0f, 1.0f),
|
||||
|
@ -55,7 +58,7 @@ namespace Examples.Shapes
|
|||
new Vector3(-1.0f, 1.0f, -1.0f),
|
||||
};
|
||||
|
||||
public static readonly int[] Colors =
|
||||
Colors = new int[]
|
||||
{
|
||||
Color.Firebrick.ToArgb(),
|
||||
Color.Honeydew.ToArgb(),
|
||||
|
@ -68,3 +71,4 @@ namespace Examples.Shapes
|
|||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
|
||||
using OpenTK.Math;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Examples.Shapes
|
||||
{
|
||||
|
@ -17,22 +19,14 @@ namespace Examples.Shapes
|
|||
private Vector3[] vertices, normals;
|
||||
private Vector2[] texcoords;
|
||||
private int[] indices;
|
||||
unsafe int* index_ptr;
|
||||
unsafe float* vertex_ptr, normal_ptr, texcoord_ptr;
|
||||
private int[] colors;
|
||||
|
||||
public Vector3[] Vertices
|
||||
{
|
||||
get { return vertices; }
|
||||
protected set
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
vertices = value;
|
||||
//fixed (float* ptr = (float*)vertices[0])
|
||||
{
|
||||
vertex_ptr = (float*)vertices[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,15 +34,8 @@ namespace Examples.Shapes
|
|||
{
|
||||
get { return normals; }
|
||||
protected set
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
normals = value;
|
||||
//fixed (float* ptr = (float*)normals[0])
|
||||
{
|
||||
normal_ptr = (float*)normals[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,15 +43,8 @@ namespace Examples.Shapes
|
|||
{
|
||||
get { return texcoords; }
|
||||
protected set
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
texcoords = value;
|
||||
//fixed (float* ptr = (float*)texcoords[0])
|
||||
{
|
||||
texcoord_ptr = (float*)texcoords[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,15 +52,17 @@ namespace Examples.Shapes
|
|||
{
|
||||
get { return indices; }
|
||||
protected set
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
indices = value;
|
||||
fixed (int* ptr = indices)
|
||||
}
|
||||
}
|
||||
|
||||
public int[] Colors
|
||||
{
|
||||
index_ptr = ptr;
|
||||
}
|
||||
}
|
||||
get { return colors; }
|
||||
protected set
|
||||
{
|
||||
colors = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue