private void CreateVertexArray(Context context) { // TODO: Buffer hint. _positionBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, SizeInBytes<Vector2F>.Value); VertexBufferAttribute positionAttribute = new VertexBufferAttribute( _positionBuffer, ComponentDatatype.Float, 2); _drawState.VertexArray = context.CreateVertexArray(); _drawState.VertexArray.Attributes[_drawState.ShaderProgram.VertexAttributes["position"].Location] = positionAttribute; }
public void VertexArray() { Vector3F[] positions = new Vector3F[] { new Vector3F(0, 0, 0), new Vector3F(1, 0, 0), new Vector3F(0, 1, 0) }; int vbSizeInBytes = ArraySizeInBytes.Size(positions); uint[] indices = new uint[] { 0, 1, 2 }; int ibSizeInBytes = indices.Length * sizeof(uint); using (GraphicsWindow window = Device.CreateWindow(1, 1)) using (VertexBuffer vertexBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, vbSizeInBytes)) using (IndexBuffer indexBuffer = Device.CreateIndexBuffer(BufferHint.StreamDraw, ibSizeInBytes)) using (VertexArray va = window.Context.CreateVertexArray()) { vertexBuffer.CopyFromSystemMemory(positions); indexBuffer.CopyFromSystemMemory(indices); // // Create and verify vertex buffer attribute // VertexBufferAttribute vertexBufferAttribute = new VertexBufferAttribute( vertexBuffer, ComponentDatatype.Float, 3, false, 0, 0); Assert.AreEqual(vertexBuffer, vertexBufferAttribute.VertexBuffer); Assert.AreEqual(ComponentDatatype.Float, vertexBufferAttribute.ComponentDatatype); Assert.AreEqual(3, vertexBufferAttribute.NumberOfComponents); Assert.IsFalse(vertexBufferAttribute.Normalize); Assert.AreEqual(0, vertexBufferAttribute.OffsetInBytes); Assert.AreEqual(SizeInBytes<Vector3F>.Value, vertexBufferAttribute.StrideInBytes); // // Verify vertex array // va.Attributes[0] = vertexBufferAttribute; va.IndexBuffer = indexBuffer; Assert.AreEqual(vertexBufferAttribute, va.Attributes[0]); Assert.AreEqual(indexBuffer, va.IndexBuffer); va.Attributes[0] = null; va.IndexBuffer = null; Assert.IsNull(va.Attributes[0]); Assert.IsNull(va.IndexBuffer); } }
public void VertexArray() { Vector3F[] positions = new Vector3F[] { new Vector3F(0, 0, 0), new Vector3F(1, 0, 0), new Vector3F(0, 1, 0) }; int vbSizeInBytes = ArraySizeInBytes.Size(positions); uint[] indices = new uint[] { 0, 1, 2 }; int ibSizeInBytes = indices.Length * sizeof(uint); using (GraphicsWindow window = Device.CreateWindow(1, 1)) using (VertexBuffer vertexBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, vbSizeInBytes)) using (IndexBuffer indexBuffer = Device.CreateIndexBuffer(BufferHint.StreamDraw, ibSizeInBytes)) using (VertexArray va = window.Context.CreateVertexArray()) { vertexBuffer.CopyFromSystemMemory(positions); indexBuffer.CopyFromSystemMemory(indices); // // Create and verify vertex buffer attribute // VertexBufferAttribute vertexBufferAttribute = new VertexBufferAttribute( vertexBuffer, ComponentDatatype.Float, 3, false, 0, 0); Assert.AreEqual(vertexBuffer, vertexBufferAttribute.VertexBuffer); Assert.AreEqual(ComponentDatatype.Float, vertexBufferAttribute.ComponentDatatype); Assert.AreEqual(3, vertexBufferAttribute.NumberOfComponents); Assert.IsFalse(vertexBufferAttribute.Normalize); Assert.AreEqual(0, vertexBufferAttribute.OffsetInBytes); Assert.AreEqual(SizeInBytes <Vector3F> .Value, vertexBufferAttribute.StrideInBytes); // // Verify vertex array // va.Attributes[0] = vertexBufferAttribute; va.IndexBuffer = indexBuffer; Assert.AreEqual(vertexBufferAttribute, va.Attributes[0]); Assert.AreEqual(indexBuffer, va.IndexBuffer); va.Attributes[0] = null; va.IndexBuffer = null; Assert.IsNull(va.Attributes[0]); Assert.IsNull(va.IndexBuffer); } }
internal void Update(Context context, ShaderProgram sp) { if (_va == null) { VertexBufferAttribute positionAttribute = new VertexBufferAttribute( _positionBuffer, ComponentDatatype.Float, 2); VertexBufferAttribute textureCoordinatesAttribute = new VertexBufferAttribute( _textureCoordinatesBuffer, ComponentDatatype.HalfFloat, 2); _va = context.CreateVertexArray(); _va.Attributes[sp.VertexAttributes["position"].Location] = positionAttribute; _va.Attributes[sp.VertexAttributes["textureCoordinates"].Location] = textureCoordinatesAttribute; } if (_viewport != context.Viewport) { // // Bottom and top swapped: MS -> OpenGL // float left = context.Viewport.Left; float bottom = context.Viewport.Top; float right = context.Viewport.Right; float top = context.Viewport.Bottom; Vector2F[] positions = new Vector2F[] { new Vector2F(left, bottom), new Vector2F(right, bottom), new Vector2F(left, top), new Vector2F(right, top) }; _positionBuffer.CopyFromSystemMemory(positions); Vector2H[] textureCoordinates = new Vector2H[] { new Vector2H(0, 0), new Vector2H(1, 0), new Vector2H(0, 1), new Vector2H(1, 1) }; _textureCoordinatesBuffer.CopyFromSystemMemory(textureCoordinates); _viewport = context.Viewport; } }
public MeshVertexBufferAttributes() { _attributes = new VertexBufferAttribute[Device.MaximumNumberOfVertexAttributes]; }
private static int NumberOfVertices(VertexBufferAttribute attribute) { return attribute.VertexBuffer.SizeInBytes / attribute.StrideInBytes; }
public MeshVertexBufferAttributes() { _attributes = new VertexBufferAttribute[Device.MaximumNumberOfVertexAttributes]; }