public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numbVertices, int startIndex, int primitiveCount) { if (minVertexIndex > 0 || baseVertex > 0) { throw new NotImplementedException("baseVertex > 0 and minVertexIndex > 0 are not supported"); } var vd = VertexDeclaration.FromType(_vertexBuffer._type); // Hmm, can the pointer here be changed with baseVertex? VertexDeclaration.PrepareForUse(vd, IntPtr.Zero); GL.DrawElements(PrimitiveTypeGL11(primitiveType), _indexBuffer._count, All.UnsignedShort, new IntPtr(startIndex)); }
public void DrawUserPrimitives <T> (PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType { // we need to reset vertex states afterwards resetVertexStates = true; // Set up our Graphics States SetGraphicsStates(); // Unbind the VBOs GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL.GenBuffers(1, out VboIdArray); } // Bind the VBO GL.BindBuffer(BufferTarget.ArrayBuffer, VboIdArray); ////Clear previous data GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)null, BufferUsageHint.DynamicDraw); //Get VertexDeclaration //var vd = VertexDeclaration.FromType(typeof(T)); //Pin data var handle = GCHandle.Alloc(vertexData, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexDeclaration.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), vertexData, BufferUsageHint.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vertexDeclaration); //Draw GL.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexOffset, GetElementCountArray(primitiveType, primitiveCount)); // Free resources GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); handle.Free(); // Unset our Graphics States UnsetGraphicsStates(); }
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, int[] indexData, int indexOffset, int primitiveCount) where T : IVertexType { // Unbind the VBOs GL.BindBuffer(All.ArrayBuffer, 0); GL.BindBuffer(All.ElementArrayBuffer, 0); var vd = VertexDeclaration.FromType(typeof(T)); IntPtr arrayStart = GCHandle.Alloc(vertexData, GCHandleType.Pinned).AddrOfPinnedObject(); if (vertexOffset > 0) arrayStart = new IntPtr(arrayStart.ToInt32() + (vertexOffset * vd.VertexStride)); VertexDeclaration.PrepareForUse(vd, arrayStart); GL.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexOffset, getElementCountArray(primitiveType, primitiveCount)); }
public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, short[] indexData, int indexOffset, int primitiveCount) where T : struct { // TODO: This needs testing! if (indexOffset > 0 || vertexOffset > 0) { throw new NotImplementedException("vertexOffset and indexOffset is not yet supported."); } // Unload the VBOs GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); var vd = VertexDeclaration.FromType(typeof(T)); VertexDeclaration.PrepareForUse(vd); GL.DrawElements(PrimitiveTypeGL11(primitiveType), vertexCount, DrawElementsType.UnsignedShort, indexData); }
public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct//, IVertexType GG TODO { // Unbind the VBOs // GG TODO do we need this? //GL.BindBuffer(BufferTarget.ArrayBuffer, 0); //GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); var vd = VertexDeclaration.FromType(typeof(T)); IntPtr arrayStart = GCHandle.Alloc(vertexData, GCHandleType.Pinned).AddrOfPinnedObject(); if (vertexOffset > 0) { arrayStart = new IntPtr(arrayStart.ToInt32() + (vertexOffset * vd.VertexStride)); } VertexDeclaration.PrepareForUse(vd, arrayStart); GL.DrawArrays(PrimitiveTypeGL(primitiveType), vertexOffset, getElementCountArray(primitiveType, primitiveCount)); }
public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct, IVertexType { // Unbind the VBOs GL.BindBuffer(All.ArrayBuffer, 0); GL.BindBuffer(All.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL.GenBuffers(1, ref VboIdArray); } // Bind the VBO GL.BindBuffer(All.ArrayBuffer, VboIdArray); ////Clear previous data GL.BufferData(All.ArrayBuffer, (IntPtr)0, (IntPtr)null, All.DynamicDraw); //Get VertexDeclaration var vd = VertexDeclaration.FromType(typeof(T)); //Pin data var handle = GCHandle.Alloc(vertexData, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 GL.BufferData(All.ArrayBuffer, (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), vertexData, All.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vd); //Draw GL.DrawArrays(PrimitiveTypeGL11(primitiveType), vertexOffset, GetElementCountArray(primitiveType, primitiveCount)); // Free resources GL.BindBuffer(All.ArrayBuffer, 0); GL.BindBuffer(All.ElementArrayBuffer, 0); handle.Free(); }
public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int vertexCount, short[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType { // we need to reset vertex states afterwards resetVertexStates = true; // Set up our Graphics States SetGraphicsStates(); // Unbind the VBOs GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL.GenBuffers(1, out VboIdArray); } if (VboIdElement == 0) { GL.GenBuffers(1, out VboIdElement); } // Bind the VBO GL.BindBuffer(BufferTarget.ArrayBuffer, VboIdArray); GL.BindBuffer(BufferTarget.ElementArrayBuffer, VboIdElement); ////Clear previous data GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)null, BufferUsageHint.DynamicDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)0, (IntPtr)null, BufferUsageHint.DynamicDraw); //Get VertexDeclaration var vd = VertexDeclaration.FromType(typeof(T)); //Pin data var handle = GCHandle.Alloc(vertexData, GCHandleType.Pinned); var handle2 = GCHandle.Alloc(vertexData, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 // int vds = vd.VertexStride; // int ec = GetElementCountArray(primitiveType, primitiveCount); // int sec = vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount); // IntPtr ip = (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)); // IntPtr ip2 = new IntPtr(handle.AddrOfPinnedObject().ToInt64() + (vertexOffset * vd.VertexStride)); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), new IntPtr(handle.AddrOfPinnedObject().ToInt64() + (vertexOffset * vd.VertexStride)), BufferUsageHint.DynamicDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(ushort) * GetElementCountArray(primitiveType, primitiveCount)), indexData, BufferUsageHint.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vd); //Draw GL.DrawElements(PrimitiveTypeGL11(primitiveType), GetElementCountArray(primitiveType, primitiveCount), DrawElementsType.UnsignedShort, (IntPtr)(indexOffset * sizeof(ushort))); // Free resources GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); handle.Free(); handle2.Free(); // Unset our Graphics States UnsetGraphicsStates(); }
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numbVertices, int startIndex, int primitiveCount) { if (minVertexIndex > 0 || baseVertex > 0) { throw new NotImplementedException("baseVertex > 0 and minVertexIndex > 0 are not supported"); } // we need to reset vertex states afterwards resetVertexStates = true; // Set up our Graphics States SetGraphicsStates(); // Unbind the VBOs GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); //Create VBO if not created already if (VboIdArray == 0) { GL.GenBuffers(1, out VboIdArray); } if (VboIdElement == 0) { GL.GenBuffers(1, out VboIdElement); } // Bind the VBO GL.BindBuffer(BufferTarget.ArrayBuffer, VboIdArray); GL.BindBuffer(BufferTarget.ElementArrayBuffer, VboIdElement); ////Clear previous data GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)null, BufferUsageHint.DynamicDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)0, (IntPtr)null, BufferUsageHint.DynamicDraw); //Get VertexDeclaration var vd = _vertexBuffer.VertexDeclaration; if (vd == null) { vd = VertexDeclaration.FromType(_vertexBuffer._type); } //Pin data var handle = GCHandle.Alloc(_vertexBuffer, GCHandleType.Pinned); var handle2 = GCHandle.Alloc(_vertexBuffer, GCHandleType.Pinned); //Buffer data to VBO; This should use stream when we move to ES2.0 GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vd.VertexStride * GetElementCountArray(primitiveType, primitiveCount)), _vertexBuffer._bufferPtr, BufferUsageHint.DynamicDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(ushort) * GetElementCountArray(primitiveType, primitiveCount)), _indexBuffer._bufferPtr, BufferUsageHint.DynamicDraw); //Setup VertexDeclaration VertexDeclaration.PrepareForUse(vd); //Draw GL.DrawElements(PrimitiveTypeGL11(primitiveType), GetElementCountArray(primitiveType, primitiveCount), DrawElementsType.UnsignedShort, (IntPtr)(startIndex * sizeof(ushort))); // Free resources GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); handle.Free(); handle2.Free(); UnsetGraphicsStates(); }