public PixelBufferGL3x( BufferTarget type, BufferHint usageHint, int sizeInBytes) { if (sizeInBytes <= 0) { throw new ArgumentOutOfRangeException("sizeInBytes", "sizeInBytes must be greater than zero."); } _name = new BufferNameGL3x(); _sizeInBytes = sizeInBytes; _type = type; _usageHint = TypeConverterGL3x.To(usageHint); // // Allocating here with GL.BufferData, then writing with GL.BufferSubData // in CopyFromSystemMemory() should not have any serious overhead: // // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=267373#Post267373 // // Alternately, we can delay GL.BufferData until the first // CopyFromSystemMemory() call. // Bind(); GL.BufferData(_type, new IntPtr(sizeInBytes), new IntPtr(), _usageHint); GC.AddMemoryPressure(sizeInBytes); }
public static BufferUsageHint To(BufferHint hint) { switch (hint) { case BufferHint.StreamDraw: return(BufferUsageHint.StreamDraw); case BufferHint.StreamRead: return(BufferUsageHint.StreamRead); case BufferHint.StreamCopy: return(BufferUsageHint.StreamCopy); case BufferHint.StaticDraw: return(BufferUsageHint.StaticDraw); case BufferHint.StaticRead: return(BufferUsageHint.StaticRead); case BufferHint.StaticCopy: return(BufferUsageHint.StaticCopy); case BufferHint.DynamicDraw: return(BufferUsageHint.DynamicDraw); case BufferHint.DynamicRead: return(BufferUsageHint.DynamicRead); case BufferHint.DynamicCopy: return(BufferUsageHint.DynamicCopy); } throw new ArgumentException("type"); }
private static VertexBuffer CreateVertexBuffer <T>(IList <T> values, BufferHint usageHint) where T : struct { T[] valuesArray = new T[values.Count]; values.CopyTo(valuesArray, 0); VertexBuffer vertexBuffer = Device.CreateVertexBuffer(usageHint, ArraySizeInBytes.Size(valuesArray)); vertexBuffer.CopyFromSystemMemory(valuesArray); return(vertexBuffer); }
public VertexBufferGL3x(BufferHint usageHint, int sizeInBytes) { _bufferObject = new BufferGL3x(BufferTarget.ArrayBuffer, usageHint, sizeInBytes); }
public Buffer (Drawable drawable, IntPtr data, uint size, BufferHint hint) { Handle = GlitzAPI.glitz_buffer_create (drawable.Handle, data, size, hint); GlitzAPI.glitz_buffer_reference (Handle); }
//static extern IntPtr glitz_buffer_create (IntPtr drawable, IntPtr data, uint size, BufferHint hint); static extern IntPtr glitz_buffer_create (IntPtr drawable, IntPtr data, uint size, BufferHint hint);
//static extern IntPtr glitz_buffer_create (IntPtr drawable, IntPtr data, uint size, BufferHint hint); static extern IntPtr glitz_buffer_create(IntPtr drawable, IntPtr data, uint size, BufferHint hint);
public static UniformBuffer CreateUniformBuffer(BufferHint usageHint, int sizeInBytes) { return(new UniformBufferGL3x(usageHint, sizeInBytes)); }
public static MeshBuffers CreateMeshBuffers(Mesh mesh, ShaderVertexAttributeCollection shaderAttributes, BufferHint usageHint) { if (mesh == null) { throw new ArgumentNullException("mesh"); } if (shaderAttributes == null) { throw new ArgumentNullException("shaderAttributes"); } MeshBuffers meshBuffers = new MeshBuffers(); if (mesh.Indices != null) { if (mesh.Indices.Datatype == IndicesType.UnsignedShort) { IList <ushort> meshIndices = ((IndicesUnsignedShort)mesh.Indices).Values; ushort[] indices = new ushort[meshIndices.Count]; for (int j = 0; j < meshIndices.Count; ++j) { indices[j] = meshIndices[j]; } IndexBuffer indexBuffer = Device.CreateIndexBuffer(usageHint, indices.Length * sizeof(ushort)); indexBuffer.CopyFromSystemMemory(indices); meshBuffers.IndexBuffer = indexBuffer; } else if (mesh.Indices.Datatype == IndicesType.UnsignedInt) { IList <uint> meshIndices = ((IndicesUnsignedInt)mesh.Indices).Values; uint[] indices = new uint[meshIndices.Count]; for (int j = 0; j < meshIndices.Count; ++j) { indices[j] = meshIndices[j]; } IndexBuffer indexBuffer = Device.CreateIndexBuffer(usageHint, indices.Length * sizeof(uint)); indexBuffer.CopyFromSystemMemory(indices); meshBuffers.IndexBuffer = indexBuffer; } else { throw new NotSupportedException("mesh.Indices.Datatype " + mesh.Indices.Datatype.ToString() + " is not supported."); } } // // Emulated double precision vectors are a special case: one mesh vertex attribute // yields two shader vertex attributes. As such, these are handled separately before // normal attributes. // HashSet <string> ignoreAttributes = new HashSet <string>(); foreach (VertexAttribute attribute in mesh.Attributes) { if (attribute is VertexAttributeDoubleVector3) { VertexAttributeDoubleVector3 emulated = (VertexAttributeDoubleVector3)attribute; int highLocation = -1; int lowLocation = -1; foreach (ShaderVertexAttribute shaderAttribute in shaderAttributes) { if (shaderAttribute.Name == emulated.Name + "High") { highLocation = shaderAttribute.Location; } else if (shaderAttribute.Name == emulated.Name + "Low") { lowLocation = shaderAttribute.Location; } if ((highLocation != -1) && (lowLocation != -1)) { break; } } if ((highLocation == -1) && (lowLocation == -1)) { // // The shader did not have either attribute. No problem. // continue; } else if ((highLocation == -1) || (lowLocation == -1)) { throw new ArgumentException("An emulated double vec3 mesh attribute requires both " + emulated.Name + "High and " + emulated.Name + "Low vertex attributes, but the shader only contains one matching attribute."); } // // Copy both high and low parts into a single vertex buffer. // IList <Vector3D> values = ((VertexAttribute <Vector3D>)attribute).Values; Vector3F[] vertices = new Vector3F[2 * values.Count]; int j = 0; for (int i = 0; i < values.Count; ++i) { EmulatedVector3D v = new EmulatedVector3D(values[i]); vertices[j++] = v.High; vertices[j++] = v.Low; } VertexBuffer vertexBuffer = Device.CreateVertexBuffer(usageHint, ArraySizeInBytes.Size(vertices)); vertexBuffer.CopyFromSystemMemory(vertices); int stride = 2 * SizeInBytes <Vector3F> .Value; meshBuffers.Attributes[highLocation] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 3, false, 0, stride); meshBuffers.Attributes[lowLocation] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 3, false, SizeInBytes <Vector3F> .Value, stride); ignoreAttributes.Add(emulated.Name + "High"); ignoreAttributes.Add(emulated.Name + "Low"); } } // TODO: Not tested exhaustively foreach (ShaderVertexAttribute shaderAttribute in shaderAttributes) { if (ignoreAttributes.Contains(shaderAttribute.Name)) { continue; } if (!mesh.Attributes.Contains(shaderAttribute.Name)) { throw new ArgumentException("Shader requires vertex attribute \"" + shaderAttribute.Name + "\", which is not present in mesh."); } VertexAttribute attribute = mesh.Attributes[shaderAttribute.Name]; if (attribute.Datatype == VertexAttributeType.EmulatedDoubleVector3) { IList <Vector3D> values = ((VertexAttribute <Vector3D>)attribute).Values; Vector3F[] valuesArray = new Vector3F[values.Count]; for (int i = 0; i < values.Count; ++i) { valuesArray[i] = values[i].ToVector3F(); } VertexBuffer vertexBuffer = Device.CreateVertexBuffer(usageHint, ArraySizeInBytes.Size(valuesArray)); vertexBuffer.CopyFromSystemMemory(valuesArray); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 3); } else if (attribute.Datatype == VertexAttributeType.HalfFloat) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Half>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.HalfFloat, 1); } else if (attribute.Datatype == VertexAttributeType.HalfFloatVector2) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector2H>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.HalfFloat, 2); } else if (attribute.Datatype == VertexAttributeType.HalfFloatVector3) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector3H>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.HalfFloat, 3); } else if (attribute.Datatype == VertexAttributeType.HalfFloatVector4) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector4H>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.HalfFloat, 4); } else if (attribute.Datatype == VertexAttributeType.Float) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <float>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 1); } else if (attribute.Datatype == VertexAttributeType.FloatVector2) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector2F>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 2); } else if (attribute.Datatype == VertexAttributeType.FloatVector3) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector3F>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 3); } else if (attribute.Datatype == VertexAttributeType.FloatVector4) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <Vector4F>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.Float, 4); } else if (attribute.Datatype == VertexAttributeType.UnsignedByte) { if (attribute is VertexAttributeRGBA) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <byte>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.UnsignedByte, 4, true, 0, 0); } else if (attribute is VertexAttributeRGB) { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <byte>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.UnsignedByte, 3, true, 0, 0); } else { VertexBuffer vertexBuffer = CreateVertexBuffer(((VertexAttribute <byte>)attribute).Values, usageHint); meshBuffers.Attributes[shaderAttribute.Location] = new VertexBufferAttribute(vertexBuffer, ComponentDatatype.UnsignedByte, 1); } } else { Debug.Fail("attribute.Datatype"); } } return(meshBuffers); }
public static IndexBuffer CreateIndexBuffer(BufferHint usageHint, int sizeInBytes) { return(new IndexBufferGL3x(usageHint, sizeInBytes)); }
public virtual VertexArray CreateVertexArray(Mesh mesh, ShaderVertexAttributeCollection shaderAttributes, BufferHint usageHint) { return(CreateVertexArray(Device.CreateMeshBuffers(mesh, shaderAttributes, usageHint))); }
public Buffer(Drawable drawable, IntPtr data, uint size, BufferHint hint) { Handle = GlitzAPI.glitz_buffer_create(drawable.Handle, data, size, hint); GlitzAPI.glitz_buffer_reference(Handle); }
public virtual VertexArray CreateVertexArray(Mesh mesh, ShaderVertexAttributeCollection shaderAttributes, BufferHint usageHint) { return CreateVertexArray(Device.CreateMeshBuffers(mesh, shaderAttributes, usageHint)); }
public static BufferUsageHint To(BufferHint hint) { switch (hint) { case BufferHint.StreamDraw: return BufferUsageHint.StreamDraw; case BufferHint.StreamRead: return BufferUsageHint.StreamRead; case BufferHint.StreamCopy: return BufferUsageHint.StreamCopy; case BufferHint.StaticDraw: return BufferUsageHint.StaticDraw; case BufferHint.StaticRead: return BufferUsageHint.StaticRead; case BufferHint.StaticCopy: return BufferUsageHint.StaticCopy; case BufferHint.DynamicDraw: return BufferUsageHint.DynamicDraw; case BufferHint.DynamicRead: return BufferUsageHint.DynamicRead; case BufferHint.DynamicCopy: return BufferUsageHint.DynamicCopy; } throw new ArgumentException("type"); }
public UniformBufferGL3x(BufferHint usageHint, int sizeInBytes) { _bufferObject = new BufferGL3x(BufferTarget.UniformBuffer, usageHint, sizeInBytes); }
public IndexBufferGL3x(BufferHint usageHint, int sizeInBytes) { _bufferObject = new BufferGL3x(BufferTarget.ElementArrayBuffer, usageHint, sizeInBytes); }