mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 04:06:08 +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 System.Drawing;
|
||||||
|
|
||||||
using OpenTK.Math;
|
using OpenTK.Math;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Examples.Shapes
|
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),
|
||||||
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),
|
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
|
// front face
|
||||||
0, 1, 2, 2, 3, 0,
|
0, 1, 2, 2, 3, 0,
|
||||||
|
@ -43,7 +46,7 @@ namespace Examples.Shapes
|
||||||
1, 5, 6, 6, 2, 1,
|
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),
|
||||||
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),
|
new Vector3(-1.0f, 1.0f, -1.0f),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static readonly int[] Colors =
|
Colors = new int[]
|
||||||
{
|
{
|
||||||
Color.Firebrick.ToArgb(),
|
Color.Firebrick.ToArgb(),
|
||||||
Color.Honeydew.ToArgb(),
|
Color.Honeydew.ToArgb(),
|
||||||
|
@ -68,3 +71,4 @@ namespace Examples.Shapes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using OpenTK.Math;
|
using OpenTK.Math;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace Examples.Shapes
|
namespace Examples.Shapes
|
||||||
{
|
{
|
||||||
|
@ -17,22 +19,14 @@ namespace Examples.Shapes
|
||||||
private Vector3[] vertices, normals;
|
private Vector3[] vertices, normals;
|
||||||
private Vector2[] texcoords;
|
private Vector2[] texcoords;
|
||||||
private int[] indices;
|
private int[] indices;
|
||||||
unsafe int* index_ptr;
|
private int[] colors;
|
||||||
unsafe float* vertex_ptr, normal_ptr, texcoord_ptr;
|
|
||||||
|
|
||||||
public Vector3[] Vertices
|
public Vector3[] Vertices
|
||||||
{
|
{
|
||||||
get { return vertices; }
|
get { return vertices; }
|
||||||
protected set
|
protected set
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
{
|
||||||
vertices = value;
|
vertices = value;
|
||||||
//fixed (float* ptr = (float*)vertices[0])
|
|
||||||
{
|
|
||||||
vertex_ptr = (float*)vertices[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,15 +34,8 @@ namespace Examples.Shapes
|
||||||
{
|
{
|
||||||
get { return normals; }
|
get { return normals; }
|
||||||
protected set
|
protected set
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
{
|
||||||
normals = value;
|
normals = value;
|
||||||
//fixed (float* ptr = (float*)normals[0])
|
|
||||||
{
|
|
||||||
normal_ptr = (float*)normals[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,15 +43,8 @@ namespace Examples.Shapes
|
||||||
{
|
{
|
||||||
get { return texcoords; }
|
get { return texcoords; }
|
||||||
protected set
|
protected set
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
{
|
||||||
texcoords = value;
|
texcoords = value;
|
||||||
//fixed (float* ptr = (float*)texcoords[0])
|
|
||||||
{
|
|
||||||
texcoord_ptr = (float*)texcoords[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,15 +52,17 @@ namespace Examples.Shapes
|
||||||
{
|
{
|
||||||
get { return indices; }
|
get { return indices; }
|
||||||
protected set
|
protected set
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
{
|
||||||
indices = value;
|
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