From edd10b86d923fe06f5e84d5ee69bd76b89c3605e Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 3 Mar 2008 12:45:18 +0000 Subject: [PATCH] Report the size of uploaded VBO data, when an error occurs. --- Source/Examples/Tutorial/T10_GLSL_Cube.cs | 27 +++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Examples/Tutorial/T10_GLSL_Cube.cs b/Source/Examples/Tutorial/T10_GLSL_Cube.cs index 8e980746..87d0e546 100644 --- a/Source/Examples/Tutorial/T10_GLSL_Cube.cs +++ b/Source/Examples/Tutorial/T10_GLSL_Cube.cs @@ -132,24 +132,33 @@ namespace Examples.Tutorial // Upload the vertex data. GL.BindBuffer(BufferTarget.ArrayBuffer, vertex_buffer_object); - GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Vertices.Length * 3 * sizeof(float)), shape.Vertices, BufferUsageHint.StaticDraw); + 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"); + throw new ApplicationException(String.Format( + "Problem uploading vertex data to VBO (vertices). Tried to upload {0} bytes, uploaded {1}.", + shape.Vertices.Length * 3 * sizeof(Single), size)); // Upload the color data. GL.BindBuffer(BufferTarget.ArrayBuffer, color_buffer_object); - GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(shape.Colors.Length * sizeof(int)), shape.Colors, BufferUsageHint.StaticDraw); + 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"); + if (size != shape.Colors.Length * sizeof(int)) + throw new ApplicationException(String.Format( + "Problem uploading vertex data to VBO (colors). Tried to upload {0} bytes, uploaded {1}.", + shape.Colors.Length * sizeof(int), size)); // Upload the index data (elements inside the vertex data, not color indices as per the IndexPointer function!) GL.BindBuffer(BufferTarget.ElementArrayBuffer, element_buffer_object); - GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(shape.Indices.Length * sizeof(Int32)), shape.Indices, BufferUsageHint.StaticDraw); + 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"); + if (size != shape.Indices.Length * sizeof(int)) + throw new ApplicationException(String.Format( + "Problem uploading vertex data to VBO (offsets). Tried to upload {0} bytes, uploaded {1}.", + shape.Indices.Length * sizeof(int), size)); } #endregion @@ -256,7 +265,7 @@ namespace Examples.Tutorial //if (error != 0) // Debug.Print(Glu.ErrorString(Glu.Enums.ErrorCode.INVALID_OPERATION)); - Context.SwapBuffers(); + SwapBuffers(); } #endregion