private void SetVertexAttrF(uint indexInVao, int indexInVertexSet, VertexAttributeDimension attrDimension, VertexAttribPointerType attrType) { var elemInfo = vertexSet.ElementInfos[indexInVertexSet]; var arraySubrange = vertexSet.ArraySubranges[elemInfo.ArrayIndex]; var rawDataRes = arraySubrange.RawDataResource; var arrayCache = rawDataRes.CacheContainer.GetOrAddCache(Tuples.Pair(infra, rawDataRes), x => new RawDataResCache(x.First, x.Second)); var glBuffer = arrayCache.GetGlVertexBuffer(); glVertexArray.SetVertexAttributeF(indexInVao, glBuffer, attrDimension, attrType, false, elemInfo.Stride, arraySubrange.StartOffset + elemInfo.Offset); }
public void SetVertexAttributeF(uint index, IBuffer buffer, VertexAttributeDimension dimension, VertexAttribPointerType type, bool normalized, int stride, int offset, uint divisor = 0) { var newDesc = new VertexAttributeDescription { IsEnabled = true, SetFunction = All.Float, Dimension = dimension, Type = (int)type, IsNormalized = normalized, Stride = stride, Offset = offset, Divisor = divisor, Buffer = buffer }; if (VertexAttributeDescription.Equals(ref vertexAttributes[index], ref newDesc)) { return; } context.Bindings.VertexArray.Set(this); if (!vertexAttributes[index].IsEnabled) { GL.EnableVertexAttribArray(index); } context.Bindings.Buffers.Array.Set(buffer); GL.VertexAttribPointer(index, (int)dimension, (int)type, normalized, stride, (IntPtr)offset); if (vertexAttributes[index].Divisor != divisor) { GL.VertexAttribDivisor(index, divisor); } vertexAttributes[index] = newDesc; if (index >= enabledVertexAttributesRange) { enabledVertexAttributesRange = index + 1; } }
internal static void VertexElementFormat(ExplicitFormat bFormat, out int vertexAttribPointerType, out VertexAttributeDimension dimension, out WVertexLayoutElementType type, out bool normalized) { switch (bFormat) { case ExplicitFormat.R32G32B32A32_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.Float; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R32G32B32A32_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedInt; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32G32B32A32_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Int; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32G32B32_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.Float; dimension = VertexAttributeDimension.Three; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R32G32B32_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedInt; dimension = VertexAttributeDimension.Three; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32G32B32_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Int; dimension = VertexAttributeDimension.Three; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16G16B16A16_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.HalfFloat; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R16G16B16A16_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedShort; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16G16B16A16_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedShort; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16G16B16A16_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Short; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16G16B16A16_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Short; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32G32_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.Float; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R32G32_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedInt; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32G32_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Int; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R10G10B10A2_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedInt2101010Rev; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8G8B8A8_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedByte; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8G8B8A8_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedByte; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R8G8B8A8_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Byte; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8G8B8A8_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Byte; dimension = VertexAttributeDimension.Four; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16G16_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.HalfFloat; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R16G16_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedShort; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16G16_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedShort; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16G16_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Short; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16G16_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Short; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.Float; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R32_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedInt; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R32_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Int; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R8G8_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedByte; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8G8_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedByte; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R8G8_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Byte; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8G8_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Byte; dimension = VertexAttributeDimension.Two; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16_FLOAT: vertexAttribPointerType = (int)VertexAttribPointerType.HalfFloat; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = false; break; case ExplicitFormat.R16_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedShort; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedShort; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R16_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Short; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R16_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Short; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R8_UNORM: vertexAttribPointerType = (int)VertexAttribPointerType.UnsignedByte; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8_UINT: vertexAttribPointerType = (int)VertexAttribIPointerType.UnsignedByte; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; case ExplicitFormat.R8_SNORM: vertexAttribPointerType = (int)VertexAttribPointerType.Byte; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.F; normalized = true; break; case ExplicitFormat.R8_SINT: vertexAttribPointerType = (int)VertexAttribIPointerType.Byte; dimension = VertexAttributeDimension.One; type = WVertexLayoutElementType.I; normalized = false; break; default: throw new NotSupportedException(string.Format("'{0}' format is not supported as vertex format", bFormat)); } }