Example #1
0
 public ArrayIndex(string name, VertexAttribPointerType type, int length)
 {
     Name = name;
     Type = type;
     Length = length;
     Size = GetSize(type) * length;
 }
 public AttributeShaderVariable(int program, string name, int size, VertexAttribPointerType type, int stride, int offset)
     : base(program, name)
 {
     this.size = size;
     this.type = type;
     this.offset = offset;
 }
 /// <summary>
 /// Initializes a new instance of the VertexAttribAttribute.
 /// </summary>
 /// <param name="components">The number of components to read.</param>
 /// <param name="type">The type of each component.</param>
 /// <param name="normalized">Specifies whether each component should be normalized.</param>
 /// <param name="index"></param>
 public VertexAttribAttribute(int components, VertexAttribPointerType type, bool normalized, int index)
 {
     Components = components;
     Type = type;
     Normalized = normalized;
     Index = index;
 }
 public ComponentType(Type type)
 {
     var aType = type.GetVertexAttribPointerType();
     if (aType.HasValue)
         t = aType.Value;
     else
         throw new ArgumentException("Invalid component type " + type);
 }
Example #5
0
 internal GLVertexBuffer(BufferTarget target, VertexAttribPointerType glType, int stride, int size)
 {
     this.stride = stride;
     this.size = size;
     this.glType = glType;
     this.target = target;
     OGL.GenBuffers(1, out bufferId);
 }
 /// <summary>
 /// 頂点属性を作成する
 /// </summary>
 /// <param name="name">変数名</param>
 /// <param name="type">属性の種類</param>
 /// <param name="size">属性の数</param>
 /// <param name="offset">属性の位置</param>
 /// <param name="normalized">正規化されているかどうか</param>
 public VertexAttribution(string name, VertexAttribPointerType type, int size, int offset, bool normalized = false)
 {
     // 各パラメーターを設定
     this.Name = name;
     this.Type = type;
     this.Size = size;
     this.Offset = offset;
     this.Normalized = normalized;
 }
 public VertexAttribute(int index, int nComponents, VertexAttribPointerType type, bool normalized = true, int offset = 0, int stride = 0)
 {
     this.index = index;
     this.nComponents = nComponents;
     this.type = type;
     this.normalized = normalized;
     this.offset = offset;
     this.stride = stride;
 }
        public AttribType(String fn_in, bool bn_in, DrawElementsType egl_de_in, 
		                  VertexAttribPointerType egl_dv_in, int inum_in)
        {
            strNameFromFile = fn_in;
            bNormalized = bn_in;
            eGLTypeDrawElement = egl_de_in;
            eGLTypeDrawVertex = egl_dv_in;
            iNumBytes = inum_in;
        }
 public VertexAttributePointer(int pIndex, int pSize, VertexAttribPointerType pType, bool pIsNormalized, int pStride, int pBufferOffset)
 {
     this._index = pIndex;
     this._size = pSize;
     this._type = pType;
     this._normalized = pIsNormalized;
     this._stride = pStride;
     this._bufferOffset = pBufferOffset;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexArrayAttribute"/> class.
 /// </summary>
 public VertexArrayAttribute(int index, int size, VertexAttribPointerType type, bool normalized, uint vbo, int stride, int offset)
 {
     Index = index;
     Size = size;
     Type = type;
     Normalized = normalized;
     VBO = vbo;
     Stride = stride;
     Offset = offset;
 }
Example #11
0
 public VertexAttribute(Shader shader, string name, VertexAttribPointerType type, int size, int stride, bool normalized)
 {
     this.name = name;
     this.type = type;
     this.size = size;
     this.stride = stride;
     this.normalized = normalized;
     this.shader = shader;
     this.location = shader.GetAttributeLocation(name);
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="size">The size.</param>
 /// <param name="type">The type.</param>
 /// <param name="stride">The stride.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="normalize">Whether to normalise the attribute's value when passing it to the shader.</param>
 public VertexAttribute(string name, int size, VertexAttribPointerType type,
     int stride, int offset, bool normalize = false)
 {
     this.name = name;
     this.size = size;
     this.type = type;
     this.stride = stride;
     this.offset = offset;
     this.normalize = normalize;
 }
        public void SetBufferObject(int index, GPUBuffer buffer, int elementCount, VertexAttribPointerType type)
        {
            GPUStateMachine.BindVertexArray(id);

            GL.EnableVertexAttribArray(index);
            GPUStateMachine.BindBuffer(buffer.target, buffer.id);
            GL.VertexAttribPointer(index, elementCount, type, false, 0, 0);
            GPUStateMachine.UnbindBuffer(buffer.target);

            GPUStateMachine.UnbindVertexArray();
        }
Example #14
0
 public void VertexAttribPointer(
     int location,
     int numberOfComponents,
     VertexAttribPointerType type,
     bool normalised,
     int vertexStride,
     int offset)
 {
     GraphicsContext.Assert();
     GL.VertexAttribPointer(location, numberOfComponents, type, normalised, vertexStride, offset);
     OpenGlErrorHelper.CheckGlError();
 }
        public void Add(int location, int count, VertexAttribPointerType type, bool isNormalized)
        {
            if (count < 1 || count > 4) throw new ArgumentOutOfRangeException(nameof(count));

            int entryAlignment = GetAlignment(type);
            int entryOffset = Align(_vertexSize, entryAlignment);
            _entries.Add(new Entry(location, count, type, isNormalized, entryAlignment, entryOffset));

            int singleSize = GetSize(type);
            int entrySize = (count - 1) * Align(singleSize, entryAlignment) + singleSize;
            _vertexSize = entryOffset + entrySize;
            _vertexStride = Align(_vertexSize, _entries[0].Alignment);
        }
Example #16
0
 public VertexElement(
     int offset,
     string usage,
     VertexAttribPointerType type,
     int numberOfComponents,
     bool normalised)
 {
     Offset = offset;
     Usage = usage;
     PointerType = type;
     NumberOfComponents = numberOfComponents;
     Normalised = normalised;
 }
 private static int GetAlignment(VertexAttribPointerType type)
 {
     switch (type)
     {
         case VertexAttribPointerType.Byte: return 1;
         case VertexAttribPointerType.Float: return 4;
         case VertexAttribPointerType.Int: return 4;
         case VertexAttribPointerType.Short: return 2;
         case VertexAttribPointerType.UnsignedByte: return 1;
         case VertexAttribPointerType.UnsignedInt: return 4;
         case VertexAttribPointerType.UnsignedShort: return 2;
         default: throw new NotImplementedException($"VertexSpecification.GetAlignment not implemented for 'VertexAttribPointerType.{type}'");
     }
 }
Example #18
0
 public AttributeInfo( ShaderProgram shader, string identifier,
     int size, int offset, int divisor, int inputOffset,
     VertexAttribPointerType pointerType =
         VertexAttribPointerType.Float,
     bool normalize = false )
 {
     Shader = shader;
     Identifier = identifier;
     Location = GL.GetAttribLocation( shader.Program, Identifier );
     Size = size;
     Offset = offset;
     Divisor = divisor;
     InputOffset = inputOffset;
     PointerType = pointerType;
     Normalize = normalize;
 }
Example #19
0
        public void EnableAttrib(
            VboPosition id, int attribArrayIdx = -1,
            VertexAttribPointerType type = VertexAttribPointerType.Float,
            bool normalized = false,
            int stride = 0, int offset = 0)
        {
            if (attribArrayIdx < 0)
                attribArrayIdx = (int)id;


            VboBase vboBase = this[id];

            GL.BindVertexArray(Handle);
            vboBase.Bind();

            GL.EnableVertexAttribArray(attribArrayIdx);
            GL.VertexAttribPointer(attribArrayIdx, vboBase.ElementSize, type, normalized, stride, offset);

            //GL.BindVertexArray(0);
            //VboBase.Unbind();
        }
Example #20
0
 private static int GetSize(VertexAttribPointerType type)
 {
     switch (type)
     {
         case VertexAttribPointerType.Byte:
         case VertexAttribPointerType.UnsignedByte:
             return sizeof(byte);
         case VertexAttribPointerType.Short:
         case VertexAttribPointerType.UnsignedShort:
             return sizeof(short);
         case VertexAttribPointerType.Int:
         case VertexAttribPointerType.UnsignedInt:
             return sizeof(int);
         case VertexAttribPointerType.Float:
             return sizeof(float);
         case VertexAttribPointerType.Double:
             return sizeof(double);
         case VertexAttribPointerType.HalfFloat:
             return sizeof(float) / 2;
         default:
             throw new ArgumentOutOfRangeException("type");
     }
 }
Example #21
0
 public static void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized,
                                        int stride, int offset)
 {
     ES20.GL.VertexAttribPointer(index, size, type, normalized, stride, offset);
     CheckError();
 }
 public abstract void VertexAttribIPointer <T0>([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] uint stride, [Count(Computed = "size, type, stride"), Flow(FlowDirection.In)] ref T0 pointer) where T0 : unmanaged;
Example #23
0
 public ComponentType(VertexAttribPointerType type)
 {
     t = type;
 }
 public VertexMemberAttribute(int count, VertexAttribPointerType type)
 {
     Count      = count;
     Type       = type;
     Normalized = false;
 }
Example #25
0
 public void AddAttribute(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
 {
     attributes[index] = new VertexAttribute(size, type, normalized, stride, offset);
 }
 public ElementFormat(VertexAttribPointerType type, int size, bool normalized = false)
 {
     Type = type;
     Size = size;
     Normalized = normalized;
 }
Example #27
0
        private void BindVertexLayout(GalPipelineState New)
        {
            foreach (GalVertexBinding Binding in New.VertexBindings)
            {
                if (!Binding.Enabled || !Rasterizer.TryGetVbo(Binding.VboKey, out int VboHandle))
                {
                    continue;
                }

                if (VaoHandle == 0)
                {
                    VaoHandle = GL.GenVertexArray();

                    //Vertex arrays shouldn't be used anywhere else in OpenGL's backend
                    //if you want to use it, move this line out of the if
                    GL.BindVertexArray(VaoHandle);
                }

                foreach (GalVertexAttrib Attrib in Binding.Attribs)
                {
                    GL.EnableVertexAttribArray(Attrib.Index);

                    GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);

                    bool Unsigned =
                        Attrib.Type == GalVertexAttribType.Unorm ||
                        Attrib.Type == GalVertexAttribType.Uint ||
                        Attrib.Type == GalVertexAttribType.Uscaled;

                    bool Normalize =
                        Attrib.Type == GalVertexAttribType.Snorm ||
                        Attrib.Type == GalVertexAttribType.Unorm;

                    VertexAttribPointerType Type = 0;

                    if (Attrib.Type == GalVertexAttribType.Float)
                    {
                        Type = VertexAttribPointerType.Float;
                    }
                    else
                    {
                        Type = AttribTypes[Attrib.Size] + (Unsigned ? 1 : 0);
                    }

                    int Size   = AttribElements[Attrib.Size];
                    int Offset = Attrib.Offset;

                    if (Attrib.Type == GalVertexAttribType.Sint ||
                        Attrib.Type == GalVertexAttribType.Uint)
                    {
                        IntPtr Pointer = new IntPtr(Offset);

                        VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;

                        GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
                    }
                    else
                    {
                        GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
                    }
                }
            }
        }
Example #28
0
 public AttribBuffer(T[] data, string attributeName, VertexAttribPointerType attribPointerType) : base(data)
 {
     AttributeName     = attributeName;
     AttribPointerType = attribPointerType;
 }
Example #29
0
        public void AddAttribute( string identifier, int size, int divisor = 0, int inputOffset = -1,
            VertexAttribPointerType pointerType = VertexAttribPointerType.Float,
            bool normalize = false )
        {
            if ( inputOffset == -1 )
                inputOffset = VertexDataSize;

            AttributeInfo info = new AttributeInfo( this, identifier, size, VertexDataStride,
                divisor, inputOffset - VertexDataSize, pointerType, normalize );

            VertexDataStride += info.Length;
            VertexDataSize += info.Size;
            myAttributes.Add( info );

            ErrorCheck( "addattrib:" + identifier );
        }
Example #30
0
 private void CheckAttribute(int count, VertexAttribPointerType type)
 {
     var entry = Specification[_specificationIndex];
     if (entry.Count != count || entry.Type != type) throw new InvalidOperationException("Invalid vertex attribute type");
     ++_specificationIndex;
 }
 private static bool IsInteger(VertexAttribPointerType type)
 {
     switch (type)
     {
         case VertexAttribPointerType.Byte:
         case VertexAttribPointerType.UnsignedByte:
         case VertexAttribPointerType.Short:
         case VertexAttribPointerType.UnsignedShort:
         case VertexAttribPointerType.Int:
         case VertexAttribPointerType.UnsignedInt:
             return true;
         default:
             return false;
     }
 }
Example #32
0
 /// <summary>
 /// Initializes a new instance of the VertexAttribAttribute.
 /// </summary>
 /// <param name="components">The number of components to read.</param>
 /// <param name="type">The type of each component.</param>
 /// <param name="normalized">Specifies whether each component should be normalized.</param>
 public VertexAttribAttribute(int components, VertexAttribPointerType type, bool normalized)
     : this(components, type, normalized, -1)
 {
 }
Example #33
0
 /// <summary>
 /// Initializes a new instance of the VertexAttribAttribute.<br/>
 /// Normalization defaults to false.
 /// </summary>
 /// <param name="components">The number of components to read.</param>
 /// <param name="type">The type of each component.</param>
 public VertexAttribAttribute(int components, VertexAttribPointerType type)
     : this(components, type, false, -1)
 {
 }
Example #34
0
 public partial void VertexAttribArrayObject([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] bool normalized, [Flow(FlowDirection.In)] uint stride, [Flow(FlowDirection.In)] uint buffer, [Flow(FlowDirection.In)] uint offset);
Example #35
0
 public void AddPointer(ShaderProgram shader, string shaderArgName, int itemCount, VertexAttribPointerType itemType, int stride, int offset) =>
 AddPointer(shader.GetAttribLocation(shaderArgName), itemCount, itemType, stride, offset, 0);
Example #36
0
        public void SendVertexBuffer(int Index, byte[] Buffer, int Stride, GalVertexAttrib[] Attribs)
        {
            if (Index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Index));
            }

            if (Buffer.Length == 0 || Stride == 0)
            {
                return;
            }

            EnsureVbInitialized(Index);

            VertexBuffer Vb = VertexBuffers[Index];

            Vb.PrimCount = Buffer.Length / Stride;

            VertexBuffers[Index] = Vb;

            IntPtr Length = new IntPtr(Buffer.Length);

            GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle);
            GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.BindVertexArray(Vb.VaoHandle);

            for (int Attr = 0; Attr < 16; Attr++)
            {
                GL.DisableVertexAttribArray(Attr);
            }

            foreach (GalVertexAttrib Attrib in Attribs)
            {
                if (Attrib.Index >= 3)
                {
                    break;
                }

                GL.EnableVertexAttribArray(Attrib.Index);

                GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle);

                int Size = 0;

                switch (Attrib.Size)
                {
                case GalVertexAttribSize._8:
                case GalVertexAttribSize._16:
                case GalVertexAttribSize._32:
                    Size = 1;
                    break;

                case GalVertexAttribSize._8_8:
                case GalVertexAttribSize._16_16:
                case GalVertexAttribSize._32_32:
                    Size = 2;
                    break;

                case GalVertexAttribSize._8_8_8:
                case GalVertexAttribSize._11_11_10:
                case GalVertexAttribSize._16_16_16:
                case GalVertexAttribSize._32_32_32:
                    Size = 3;
                    break;

                case GalVertexAttribSize._8_8_8_8:
                case GalVertexAttribSize._10_10_10_2:
                case GalVertexAttribSize._16_16_16_16:
                case GalVertexAttribSize._32_32_32_32:
                    Size = 4;
                    break;
                }

                bool Signed =
                    Attrib.Type == GalVertexAttribType.Snorm ||
                    Attrib.Type == GalVertexAttribType.Sint ||
                    Attrib.Type == GalVertexAttribType.Sscaled;

                bool Normalize =
                    Attrib.Type == GalVertexAttribType.Snorm ||
                    Attrib.Type == GalVertexAttribType.Unorm;

                VertexAttribPointerType Type = 0;

                switch (Attrib.Type)
                {
                case GalVertexAttribType.Snorm:
                case GalVertexAttribType.Unorm:
                case GalVertexAttribType.Sint:
                case GalVertexAttribType.Uint:
                case GalVertexAttribType.Uscaled:
                case GalVertexAttribType.Sscaled:
                {
                    switch (Attrib.Size)
                    {
                    case GalVertexAttribSize._8:
                    case GalVertexAttribSize._8_8:
                    case GalVertexAttribSize._8_8_8:
                    case GalVertexAttribSize._8_8_8_8:
                    {
                        Type = Signed
                                    ? VertexAttribPointerType.Byte
                                    : VertexAttribPointerType.UnsignedByte;

                        break;
                    }

                    case GalVertexAttribSize._16:
                    case GalVertexAttribSize._16_16:
                    case GalVertexAttribSize._16_16_16:
                    case GalVertexAttribSize._16_16_16_16:
                    {
                        Type = Signed
                                    ? VertexAttribPointerType.Short
                                    : VertexAttribPointerType.UnsignedShort;

                        break;
                    }

                    case GalVertexAttribSize._10_10_10_2:
                    case GalVertexAttribSize._11_11_10:
                    case GalVertexAttribSize._32:
                    case GalVertexAttribSize._32_32:
                    case GalVertexAttribSize._32_32_32:
                    case GalVertexAttribSize._32_32_32_32:
                    {
                        Type = Signed
                                    ? VertexAttribPointerType.Int
                                    : VertexAttribPointerType.UnsignedInt;

                        break;
                    }
                    }

                    break;
                }

                case GalVertexAttribType.Float:
                {
                    Type = VertexAttribPointerType.Float;

                    break;
                }
                }

                GL.VertexAttribPointer(
                    Attrib.Index,
                    Size,
                    Type,
                    Normalize,
                    Stride,
                    Attrib.Offset);
            }

            GL.BindVertexArray(0);
        }
 public unsafe void VertexAttributePointer(uint index, int count, VertexAttribPointerType type, uint vertexSize, int offSet)
 {
     _gl.VertexAttribPointer(index, count, type, false, vertexSize * (uint)sizeof(TVertexType), (void *)(offSet * sizeof(TVertexType)));
     _gl.EnableVertexAttribArray(index);
 }
Example #38
0
 public void EnableTextureVertices(int size, VertexAttribPointerType type, bool normalized, int stride, float[] vertices)
 {
     GL.EnableVertexAttribArray(maTexCoordHandle);
     GL.VertexAttribPointer(maTexCoordHandle, size, type, normalized, stride, vertices);
 }
Example #39
0
 public ElementFormat(VertexAttribPointerType type, byte size, bool normalized = false)
 {
     Type       = type;
     Size       = size;
     Normalized = normalized;
 }
 private void AssertVertexElementProperties(
     VertexElement element,
     int offset,
     VertexAttribPointerType type,
     int numberOfComponents,
     bool normalised)
 {
     element.ShouldSatisfyAllConditions(
         () => element.Offset.ShouldBe(offset),
         () => element.PointerType.ShouldBe(type),
         () => element.NumberOfComponents.ShouldBe(numberOfComponents),
         () => element.Normalised.ShouldBe(normalised)
     );
 }
Example #41
0
 /// <summary>
 /// extend the vertex array layout
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="type"></param>
 /// <param name="count"></param>
 public void Add <T>(VertexAttribPointerType type, int count) where T : struct
 {
     element.Add(new VertexArrayLayout(type, Marshal.SizeOf <T>(), count, false));
     stride += sizeof(float) * count;
 }
 /// <summary>
 /// Creates a <see cref="VertexAttribSource"/> with a given <see cref="BufferObjectSubset"/> and specifies
 /// a vertex attribute where the data format in the shader and the buffer don't match and need conversion.
 /// </summary>
 /// <param name="bufferSubset">The <see cref="BufferObjectSubset"/> where the vertex attrib data is located. Must be a subset usable for vertex data.</param>
 /// <param name="attribType">The type of attribute declared in the shader.</param>
 /// <param name="normalized">Whether the data needs to be normalized (uint/ushort/byte -> float between 0 and 1, or int/short/sbyte -> float between -1 and 1).</param>
 /// <param name="dataBaseType">The base type of the data found on the buffer. If normalized is true, this must be an integer type.</param>
 /// <param name="attribDivisor">The divisor that defines how reading this attribute advances on instanced rendering.</param>
 public VertexAttribSource(DataBufferSubset bufferSubset, AttributeType attribType, bool normalized, VertexAttribPointerType dataBaseType, uint attribDivisor = 0)
     : this(bufferSubset, new VertexAttribDescription(attribType, normalized, dataBaseType, attribDivisor))
 {
 }
 public VertexMemberAttribute(int count, VertexAttribPointerType type, bool normalized)
 {
     Count      = count;
     Type       = type;
     Normalized = normalized;
 }
Example #44
0
 public void VertexAttributePointer(uint index, int count, VertexAttribPointerType type, uint vertexSize, int offset)
 {
     gl.VertexAttribPointer(index, count, type, false, (uint)(vertexSize * sizeof(float)), (void *)(offset));
     gl.EnableVertexAttribArray(index);
 }
 public abstract unsafe void VertexAttribIPointer([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] uint stride, [Count(Computed = "size, type, stride"), Flow(FlowDirection.In)] void *pointer);
Example #46
0
 public void VertexAttributePointer(uint index, int count, VertexAttribPointerType type, string fieldName)
 {
     gl.VertexAttribPointer(index, count, type, false, (uint)(sizeof(VertexType)), (void *)Marshal.OffsetOf <VertexType>(fieldName));
     gl.EnableVertexAttribArray(index);
 }
Example #47
0
        public void AddAttribute <Type>(int attributeLocation, Type[] array, int baseTypeCount, VertexAttribPointerType type) where Type : struct
        {
            if (-1 == attributeLocation)
            {
                throw new ArgumentException("Invalid attribute location");
            }
            if (0 == array.Length)
            {
                throw new ArgumentException("Empty attribute array");
            }
            if (0 != _count && array.Length != _count)
            {
                throw new ArgumentException("Attribute arrays with different sizes given");
            }
            _count = array.Length;

            int byteSize = Marshal.SizeOf(array[0]) * array.Length;
            var buffer   = GL.GenBuffer();

            _buffers.Add(buffer);

            GL.BindVertexArray(_vertexArray);                                                     // activate vertex array; from now on state is stored;
            GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);                                      // activate buffer
            GL.BufferData(BufferTarget.ArrayBuffer, byteSize, array, BufferUsageHint.StaticDraw); //copy data over to GPU
            GL.EnableVertexAttribArray(attributeLocation);                                        // activate this vertex attribute for the active vertex array
            GL.VertexAttribPointer(attributeLocation, baseTypeCount, type, false, 0, 0);          // specify what our buffer contains
            GL.BindVertexArray(0);                                                                // deactivate vertex array; state storing is stopped;
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);                                           // deactivate buffer; just to be on the cautious side;
            GL.DisableVertexAttribArray(attributeLocation);                                       // cleanup state...
        }
 public VertexAttributePointer(int pIndex, int pSize, VertexAttribPointerType pType)
     : this(pIndex, pSize, pType, false, 0, 0)
 {
 }
Example #49
0
        private void BindVertexLayout(GalPipelineState New)
        {
            foreach (GalVertexBinding binding in New.VertexBindings)
            {
                if (!binding.Enabled || !_rasterizer.TryGetVbo(binding.VboKey, out int vboHandle))
                {
                    continue;
                }

                if (_vaoHandle == 0)
                {
                    _vaoHandle = GL.GenVertexArray();

                    // Vertex arrays shouldn't be used anywhere else in OpenGL's backend
                    // if you want to use it, move this line out of the if
                    GL.BindVertexArray(_vaoHandle);
                }

                foreach (GalVertexAttrib attrib in binding.Attribs)
                {
                    // Skip uninitialized attributes.
                    if (attrib.Size == 0)
                    {
                        continue;
                    }

                    GL.BindBuffer(BufferTarget.ArrayBuffer, vboHandle);

                    bool unsigned =
                        attrib.Type == GalVertexAttribType.Unorm ||
                        attrib.Type == GalVertexAttribType.Uint ||
                        attrib.Type == GalVertexAttribType.Uscaled;

                    bool normalize =
                        attrib.Type == GalVertexAttribType.Snorm ||
                        attrib.Type == GalVertexAttribType.Unorm;

                    VertexAttribPointerType type = 0;

                    if (attrib.Type == GalVertexAttribType.Float)
                    {
                        type = GetType(_floatAttribTypes, attrib);
                    }
                    else
                    {
                        if (unsigned)
                        {
                            type = GetType(_unsignedAttribTypes, attrib);
                        }
                        else
                        {
                            type = GetType(_signedAttribTypes, attrib);
                        }
                    }

                    if (!_attribElements.TryGetValue(attrib.Size, out int size))
                    {
                        throw new InvalidOperationException("Invalid attribute size \"" + attrib.Size + "\"!");
                    }

                    int offset = attrib.Offset;

                    if (binding.Stride != 0)
                    {
                        GL.EnableVertexAttribArray(attrib.Index);

                        if (attrib.Type == GalVertexAttribType.Sint ||
                            attrib.Type == GalVertexAttribType.Uint)
                        {
                            IntPtr pointer = new IntPtr(offset);

                            VertexAttribIntegerType iType = (VertexAttribIntegerType)type;

                            GL.VertexAttribIPointer(attrib.Index, size, iType, binding.Stride, pointer);
                        }
                        else
                        {
                            GL.VertexAttribPointer(attrib.Index, size, type, normalize, binding.Stride, offset);
                        }
                    }
                    else
                    {
                        GL.DisableVertexAttribArray(attrib.Index);

                        SetConstAttrib(attrib);
                    }

                    if (binding.Instanced && binding.Divisor != 0)
                    {
                        GL.VertexAttribDivisor(attrib.Index, 1);
                    }
                    else
                    {
                        GL.VertexAttribDivisor(attrib.Index, 0);
                    }
                }
            }
        }
Example #50
0
        public void writeGeomToStream(StreamWriter s, ref uint index)
        {
            int          vertcount = metaData.vertrend_graphics - metaData.vertrstart_graphics + 1;
            MemoryStream vms       = new MemoryStream(gobject.meshDataDict[metaData.Hash].vs_buffer);
            MemoryStream ims       = new MemoryStream(gobject.meshDataDict[metaData.Hash].is_buffer);
            BinaryReader vbr       = new BinaryReader(vms);
            BinaryReader ibr       = new BinaryReader(ims);

            //Start Writing
            //Object name
            s.WriteLine("o " + name);
            //Get Verts

            //Preset Matrices for faster export
            Matrix4 wMat = this.worldMat;
            Matrix4 nMat = Matrix4.Invert(Matrix4.Transpose(wMat));

            vbr.BaseStream.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < vertcount; i++)
            {
                Vector4 v;
                VertexAttribPointerType ntype = gobject.bufInfo[0].type;
                int v_section_bytes           = 0;

                switch (ntype)
                {
                case VertexAttribPointerType.HalfFloat:
                    uint v1 = vbr.ReadUInt16();
                    uint v2 = vbr.ReadUInt16();
                    uint v3 = vbr.ReadUInt16();
                    //uint v4 = Convert.ToUInt16(vbr.ReadUInt16());

                    //Transform vector with worldMatrix
                    v = new Vector4(Utils.Half.decompress(v1), Utils.Half.decompress(v2), Utils.Half.decompress(v3), 1.0f);
                    v_section_bytes = 6;
                    break;

                case VertexAttribPointerType.Float:     //This is used in my custom vbos
                    float f1 = vbr.ReadSingle();
                    float f2 = vbr.ReadSingle();
                    float f3 = vbr.ReadSingle();
                    //Transform vector with worldMatrix
                    v = new Vector4(f1, f2, f3, 1.0f);
                    v_section_bytes = 12;
                    break;

                default:
                    throw new Exception("Unimplemented Vertex Type");
                }


                v = Vector4.Transform(v, this.worldMat);

                //s.WriteLine("v " + Half.decompress(v1).ToString() + " "+ Half.decompress(v2).ToString() + " " + Half.decompress(v3).ToString());
                s.WriteLine("v " + v.X.ToString() + " " + v.Y.ToString() + " " + v.Z.ToString());
                vbr.BaseStream.Seek(gobject.vx_size - v_section_bytes, SeekOrigin.Current);
            }
            //Get Normals

            vbr.BaseStream.Seek(gobject.offsets[2] + 0, SeekOrigin.Begin);
            for (int i = 0; i < vertcount; i++)
            {
                Vector4 vN;
                VertexAttribPointerType ntype = gobject.bufInfo[2].type;
                int n_section_bytes           = 0;

                switch (ntype)
                {
                case (VertexAttribPointerType.Float):
                    float f1, f2, f3;
                    f1 = vbr.ReadSingle();
                    f2 = vbr.ReadSingle();
                    f3 = vbr.ReadSingle();
                    vN = new Vector4(f1, f2, f3, 1.0f);
                    n_section_bytes = 12;
                    break;

                case (VertexAttribPointerType.HalfFloat):
                    uint v1, v2, v3;
                    v1 = vbr.ReadUInt16();
                    v2 = vbr.ReadUInt16();
                    v3 = vbr.ReadUInt16();
                    vN = new Vector4(Utils.Half.decompress(v1), Utils.Half.decompress(v2), Utils.Half.decompress(v3), 1.0f);
                    n_section_bytes = 6;
                    break;

                case (VertexAttribPointerType.Int2101010Rev):
                    int    i1, i2, i3;
                    uint   value;
                    byte[] a32 = new byte[4];
                    a32 = vbr.ReadBytes(4);

                    value = BitConverter.ToUInt32(a32, 0);
                    //Convert Values
                    i1 = _2sComplement.toInt((value >> 00) & 0x3FF, 10);
                    i2 = _2sComplement.toInt((value >> 10) & 0x3FF, 10);
                    i3 = _2sComplement.toInt((value >> 20) & 0x3FF, 10);
                    //int i4 = _2sComplement.toInt((value >> 30) & 0x003, 10);
                    float norm = (float)Math.Sqrt(i1 * i1 + i2 * i2 + i3 * i3);

                    vN = new Vector4(Convert.ToSingle(i1) / norm,
                                     Convert.ToSingle(i2) / norm,
                                     Convert.ToSingle(i3) / norm,
                                     1.0f);

                    n_section_bytes = 4;
                    //Debug.WriteLine(vN);
                    break;

                default:
                    throw new Exception("UNIMPLEMENTED NORMAL TYPE. PLEASE REPORT");
                }

                //uint v4 = Convert.ToUInt16(vbr.ReadUInt16());
                //Transform normal with normalMatrix


                vN = Vector4.Transform(vN, nMat);

                s.WriteLine("vn " + vN.X.ToString() + " " + vN.Y.ToString() + " " + vN.Z.ToString());
                vbr.BaseStream.Seek(gobject.vx_size - n_section_bytes, SeekOrigin.Current);
            }
            //Get UVs, only for mesh objects

            vbr.BaseStream.Seek(Math.Max(gobject.offsets[1], 0) + gobject.vx_size * metaData.vertrstart_graphics, SeekOrigin.Begin);
            for (int i = 0; i < vertcount; i++)
            {
                Vector2 uv;
                int     uv_section_bytes = 0;
                if (gobject.offsets[1] != -1) //Check if uvs exist
                {
                    uint v1 = vbr.ReadUInt16();
                    uint v2 = vbr.ReadUInt16();
                    uint v3 = vbr.ReadUInt16();
                    //uint v4 = Convert.ToUInt16(vbr.ReadUInt16());
                    uv = new Vector2(Utils.Half.decompress(v1), Utils.Half.decompress(v2));
                    uv_section_bytes = 0x6;
                }
                else
                {
                    uv = new Vector2(0.0f, 0.0f);
                    uv_section_bytes = gobject.vx_size;
                }

                s.WriteLine("vt " + uv.X.ToString() + " " + (1.0 - uv.Y).ToString());
                vbr.BaseStream.Seek(gobject.vx_size - uv_section_bytes, SeekOrigin.Current);
            }


            //Some Options
            s.WriteLine("usemtl(null)");
            s.WriteLine("s off");

            //Get indices
            ibr.BaseStream.Seek(0, SeekOrigin.Begin);
            bool start  = false;
            uint fstart = 0;

            for (int i = 0; i < metaData.batchcount / 3; i++)
            {
                uint f1, f2, f3;
                //NEXT models assume that all gstream meshes have uint16 indices
                f1 = ibr.ReadUInt16();
                f2 = ibr.ReadUInt16();
                f3 = ibr.ReadUInt16();

                if (!start && this.type != TYPES.COLLISION)
                {
                    fstart = f1; start = true;
                }
                else if (!start && this.type == TYPES.COLLISION)
                {
                    fstart = 0; start = true;
                }

                uint f11, f22, f33;
                f11 = f1 - fstart + index;
                f22 = f2 - fstart + index;
                f33 = f3 - fstart + index;


                s.WriteLine("f " + f11.ToString() + "/" + f11.ToString() + "/" + f11.ToString() + " "
                            + f22.ToString() + "/" + f22.ToString() + "/" + f22.ToString() + " "
                            + f33.ToString() + "/" + f33.ToString() + "/" + f33.ToString() + " ");
            }
            index += (uint)vertcount;
        }
Example #51
0
 public void AddPointer(int shaderArgIndex, int itemCount, VertexAttribPointerType itemType, int stride, int offset) =>
 AddPointer(shaderArgIndex, itemCount, itemType, stride, offset, 0);
Example #52
0
 public partial void VertexAttribP1([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] Boolean normalized, [Flow(FlowDirection.In)] uint value);
Example #53
0
 public static unsafe void VertexAttribPointer <T0>(this ArbVertexProgram thisApi, [Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] int size, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] bool normalized, [Flow(FlowDirection.In)] uint stride, [Count(Computed = "size, type, stride"), Flow(FlowDirection.In)] ReadOnlySpan <T0> pointer) where T0 : unmanaged
 {
     // SpanOverloader
     thisApi.VertexAttribPointer(index, size, type, normalized, stride, in pointer.GetPinnableReference());
 }
Example #54
0
 public void EnableAttribute(int id, int size, VertexAttribPointerType type, int stride, int offset)
 {
     GL.EnableVertexAttribArray(id);
     GL.VertexAttribPointer(id, size, type, false, stride * sizeof(float), offset * sizeof(float));
 }
Example #55
0
        private void BindVertexLayout(GalPipelineState New)
        {
            foreach (GalVertexBinding Binding in New.VertexBindings)
            {
                if (!Binding.Enabled || !Rasterizer.TryGetVbo(Binding.VboKey, out int VboHandle))
                {
                    continue;
                }

                if (VaoHandle == 0)
                {
                    VaoHandle = GL.GenVertexArray();

                    //Vertex arrays shouldn't be used anywhere else in OpenGL's backend
                    //if you want to use it, move this line out of the if
                    GL.BindVertexArray(VaoHandle);
                }

                foreach (GalVertexAttrib Attrib in Binding.Attribs)
                {
                    //Skip uninitialized attributes.
                    if (Attrib.Size == 0)
                    {
                        continue;
                    }

                    GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);

                    bool Unsigned =
                        Attrib.Type == GalVertexAttribType.Unorm ||
                        Attrib.Type == GalVertexAttribType.Uint ||
                        Attrib.Type == GalVertexAttribType.Uscaled;

                    bool Normalize =
                        Attrib.Type == GalVertexAttribType.Snorm ||
                        Attrib.Type == GalVertexAttribType.Unorm;

                    VertexAttribPointerType Type = 0;

                    if (Attrib.Type == GalVertexAttribType.Float)
                    {
                        Type = GetType(FloatAttribTypes, Attrib);
                    }
                    else
                    {
                        if (Unsigned)
                        {
                            Type = GetType(UnsignedAttribTypes, Attrib);
                        }
                        else
                        {
                            Type = GetType(SignedAttribTypes, Attrib);
                        }
                    }

                    if (!AttribElements.TryGetValue(Attrib.Size, out int Size))
                    {
                        throw new InvalidOperationException("Invalid attribute size \"" + Attrib.Size + "\"!");
                    }

                    int Offset = Attrib.Offset;

                    if (Binding.Stride != 0)
                    {
                        GL.EnableVertexAttribArray(Attrib.Index);

                        if (Attrib.Type == GalVertexAttribType.Sint ||
                            Attrib.Type == GalVertexAttribType.Uint)
                        {
                            IntPtr Pointer = new IntPtr(Offset);

                            VertexAttribIntegerType IType = (VertexAttribIntegerType)Type;

                            GL.VertexAttribIPointer(Attrib.Index, Size, IType, Binding.Stride, Pointer);
                        }
                        else
                        {
                            GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
                        }
                    }
                    else
                    {
                        GL.DisableVertexAttribArray(Attrib.Index);

                        SetConstAttrib(Attrib);
                    }

                    if (Binding.Instanced && Binding.Divisor != 0)
                    {
                        GL.VertexAttribDivisor(Attrib.Index, 1);
                    }
                    else
                    {
                        GL.VertexAttribDivisor(Attrib.Index, 0);
                    }
                }
            }
        }
Example #56
0
 public abstract void VertexAttribP4([Flow(FlowDirection.In)] uint index, [Flow(FlowDirection.In)] VertexAttribPointerType type, [Flow(FlowDirection.In)] bool normalized, [Count(Count = 1), Flow(FlowDirection.In)] ref uint value);
Example #57
0
 public static void VertexAttribPointer(uint index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
 {
     VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
 }
Example #58
0
		unsafe static int GetGLTypeSize(VertexAttribPointerType type)
		{
			
			switch(type)
			{
			case VertexAttribPointerType.UnsignedByte:
				return sizeof(byte);
			case VertexAttribPointerType.UnsignedShort:	
				return sizeof(short);
			case VertexAttribPointerType.Byte:
				return sizeof(byte);
			case VertexAttribPointerType.Float:
				return sizeof(float);
			//case VertexAttribPointerType.Fixed:
				
			}
			/*switch(type)
			{
			case All.Byte:
				return sizeof(byte);
			case All.UnsignedByte:
				return sizeof(byte);
			case All.UnsignedShort:
				return sizeof(short);
			case All.Int:
				return sizeof(int);
			case All.UnsignedInt:
				return sizeof(uint);
			case All.Float:
				return sizeof(float);
			}*/
			
			return 0;
		}
Example #59
0
 public static void VertexAttribPointer(int index, int size, VertexAttribPointerType type, bool normalized, int stride, int offset)
 {
     VertexAttribPointer(index, size, type, normalized, stride, (IntPtr)offset);
 }
 /// <summary>
 /// Creates a <see cref="VertexAttribSource"/> that specifies padding for an
 /// amount of bytes calculated based on the baseType and size parameters.
 /// </summary>
 /// <param name="bufferSubset">The buffer subset in which the padding will be applied.</param>
 /// <param name="baseType">The base type of the attribute.</param>
 /// <param name="size">The size of the attribute.</param>
 public static VertexAttribSource CreatePadding(DataBufferSubset bufferSubset, VertexAttribPointerType baseType, uint size)
 {
     return(new VertexAttribSource(bufferSubset, VertexAttribDescription.CreatePadding(baseType, size)));
 }