mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 16:35:36 +00:00
Updated T08_VBO and T10_GLSL_Cube to use the more specific, updated enums.
This commit is contained in:
parent
fb04abb077
commit
18296ea663
|
@ -22,7 +22,8 @@ using OpenTK.Math;
|
|||
|
||||
namespace Examples.Tutorial
|
||||
{
|
||||
public class T08_VBO : GameWindow, IExample
|
||||
[Example("Vertex Buffer Objects", ExampleCategory.Tutorial, 8)]
|
||||
public class T08_VBO : GameWindow
|
||||
{
|
||||
#region --- Private Fields ---
|
||||
|
||||
|
@ -127,40 +128,25 @@ namespace Examples.Tutorial
|
|||
|
||||
#endregion
|
||||
|
||||
#region public void Launch()
|
||||
|
||||
/// <summary>
|
||||
/// Launches this example.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Provides a simple way for the example launcher to launch the examples.
|
||||
/// </remarks>
|
||||
public void Launch()
|
||||
{
|
||||
Run(60.0, 60.0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Vbo Load(Vector3[] vertices, int[] indices)
|
||||
{
|
||||
Vbo handle = new Vbo();
|
||||
int size;
|
||||
|
||||
GL.GenBuffers(1, out handle.VboID);
|
||||
GL.BindBuffer(Version15.ArrayBuffer, handle.VboID);
|
||||
GL.BufferData(Version15.ArrayBuffer, (IntPtr)(vertices.Length * Vector3.SizeInBytes), vertices,
|
||||
Version15.StaticDraw);
|
||||
GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, handle.VboID);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vector3.SizeInBytes), vertices,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
|
||||
if (vertices.Length * Vector3.SizeInBytes != size)
|
||||
throw new ApplicationException("Vertex array not uploaded correctly");
|
||||
//GL.BindBuffer(Version15.ArrayBuffer, 0);
|
||||
|
||||
GL.GenBuffers(1, out handle.EboID);
|
||||
GL.BindBuffer(Version15.ElementArrayBuffer, handle.EboID);
|
||||
GL.BufferData(Version15.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices,
|
||||
Version15.StaticDraw);
|
||||
GL.GetBufferParameter(Version15.ElementArrayBuffer, Version15.BufferSize, out size);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.EboID);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(int)), indices,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
|
||||
if (indices.Length * sizeof(int) != size)
|
||||
throw new ApplicationException("Element array not uploaded correctly");
|
||||
//GL.BindBuffer(Version15.ElementArrayBuffer, 0);
|
||||
|
@ -176,8 +162,8 @@ namespace Examples.Tutorial
|
|||
//GL.EnableClientState(EnableCap.TextureCoordArray);
|
||||
GL.EnableClientState(EnableCap.VertexArray);
|
||||
|
||||
GL.BindBuffer(Version15.StaticDraw, handle.VboID);
|
||||
GL.BindBuffer(Version15.ElementArrayBuffer, handle.EboID);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, handle.VboID);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.EboID);
|
||||
|
||||
//GL.TexCoordPointer(2, TexCoordPointerType.Float, vector2_size, (IntPtr)vector2_size);
|
||||
GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
|
||||
|
@ -185,13 +171,32 @@ namespace Examples.Tutorial
|
|||
GL.DrawElements(BeginMode.Triangles, handle.NumElements, All.UnsignedInt, IntPtr.Zero);
|
||||
//GL.DrawArrays(BeginMode.LineLoop, 0, vbo.element_count);
|
||||
|
||||
GL.BindBuffer(Version15.ArrayBuffer, 0);
|
||||
GL.BindBuffer(Version15.ElementArrayBuffer, 0);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
||||
|
||||
GL.DisableClientState(EnableCap.VertexArray);
|
||||
//GL.DisableClientState(EnableCap.TextureCoordArray);
|
||||
|
||||
//GL.PopClientAttrib();
|
||||
}
|
||||
|
||||
#region public static void Main()
|
||||
|
||||
/// <summary>
|
||||
/// Entry point of this example.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
using (T08_VBO example = new T08_VBO())
|
||||
{
|
||||
// Get the title and category of this example using reflection.
|
||||
ExampleAttribute info = ((ExampleAttribute)example.GetType().GetCustomAttributes(false)[0]);
|
||||
example.Title = String.Format("OpenTK | {0} {1}: {2}", info.Category, info.Difficulty, info.Title);
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,8 +90,8 @@ namespace Examples.Tutorial
|
|||
int status_code;
|
||||
string info;
|
||||
|
||||
vertexObject = GL.CreateShader(Version20.VertexShader);
|
||||
fragmentObject = GL.CreateShader(Version20.FragmentShader);
|
||||
vertexObject = GL.CreateShader(ShaderObjectType.VertexShader);
|
||||
fragmentObject = GL.CreateShader(ShaderObjectType.FragmentShader);
|
||||
|
||||
// Compile vertex shader
|
||||
GL.ShaderSource(vertexObject, vs);
|
||||
|
@ -132,23 +132,23 @@ namespace Examples.Tutorial
|
|||
GL.GenBuffers(1, out element_buffer_object);
|
||||
|
||||
// Upload the vertex data.
|
||||
GL.BindBuffer(Version15.ArrayBuffer, vertex_buffer_object);
|
||||
GL.BufferData(Version15.ArrayBuffer, (IntPtr)(shape.Vertices.Length * 3 * sizeof(float)), shape.Vertices, Version15.StaticDraw);
|
||||
GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vertex_buffer_object);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Vertices.Length * 3 * sizeof(float)), shape.Vertices, BufferUsageHint.StaticDraw);
|
||||
GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
|
||||
if (size != shape.Vertices.Length * 3 * sizeof(Single))
|
||||
throw new ApplicationException("Problem uploading vertex data to VBO");
|
||||
|
||||
// Upload the color data.
|
||||
GL.BindBuffer(Version15.ArrayBuffer, color_buffer_object);
|
||||
GL.BufferData(Version15.ArrayBuffer, (IntPtr)(shape.Colors.Length * sizeof(int)), shape.Colors, Version15.StaticDraw);
|
||||
GL.GetBufferParameter(Version15.ArrayBuffer, Version15.BufferSize, out size);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, color_buffer_object);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Colors.Length * sizeof(int)), shape.Colors, BufferUsageHint.StaticDraw);
|
||||
GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
|
||||
if (shape.Colors.Length * sizeof(int) != size)
|
||||
throw new ApplicationException("Problem uploading color data to VBO");
|
||||
|
||||
// Upload the index data (elements inside the vertex data, not color indices as per the IndexPointer function!)
|
||||
GL.BindBuffer(Version15.ElementArrayBuffer, element_buffer_object);
|
||||
GL.BufferData(Version15.ElementArrayBuffer, (IntPtr)(shape.Indices.Length * sizeof(Int32)), shape.Indices, Version15.StaticDraw);
|
||||
GL.GetBufferParameter(Version15.ElementArrayBuffer, Version15.BufferSize, out size);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, element_buffer_object);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(shape.Indices.Length * sizeof(Int32)), shape.Indices, BufferUsageHint.StaticDraw);
|
||||
GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
|
||||
if (shape.Indices.Length * 4 != size)
|
||||
throw new ApplicationException("Problem uploading index data to VBO");
|
||||
}
|
||||
|
@ -233,11 +233,11 @@ namespace Examples.Tutorial
|
|||
GL.EnableClientState(EnableCap.VertexArray);
|
||||
GL.EnableClientState(EnableCap.ColorArray);
|
||||
|
||||
GL.BindBuffer(Version15.ArrayBuffer, vertex_buffer_object);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vertex_buffer_object);
|
||||
GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
|
||||
GL.BindBuffer(Version15.ArrayBuffer, color_buffer_object);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, color_buffer_object);
|
||||
GL.ColorPointer(4, ColorPointerType.UnsignedByte, 0, IntPtr.Zero);
|
||||
GL.BindBuffer(Version15.ElementArrayBuffer, element_buffer_object);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, element_buffer_object);
|
||||
|
||||
GL.DrawElements(BeginMode.Triangles, shape.Indices.Length,
|
||||
All.UnsignedInt, IntPtr.Zero);
|
||||
|
|
Loading…
Reference in a new issue