Пример #1
0
        internal int GetLayout(VertexDescription description, Shader shader)
        {
            if (!OpenGLCapabilities.VertexAttribBinding)
            {
                throw new PlatformNotSupportedException("VertexAttribBinding (separat vertex attributes) are not supported by the driver");
            }

            int layout;

            if (inputLayoutPool.TryGetValue(description, out layout))
            {
                return(layout);
            }

            layout = GL.GenVertexArray();

            if (OpenGLCapabilities.DirectStateAccess == DirectStateAccess.None)
            {
                BindManager.VertexArray = layout;

                int             offset   = 0;
                VertexElement[] elements = description.GetElements();
                for (int i = 0; i < description.ElementCount; i++)
                {
                    if (offset > OpenGLCapabilities.MaxVertexAttribBindingOffset)
                    {
                        throw new PlatformNotSupportedException("offset is higher than maximum supportet offset.");
                    }

                    GL.EnableVertexAttribArray(i);

                    GL.VertexAttribBinding(i, 0);
                    GL.VertexAttribFormat(i, GetComponentsOf(elements[i].Type), VertexAttribType.Float, false, offset);
                    offset += GetSizeOf(elements[i].Type);
                }
            }
            else if (OpenGLCapabilities.DirectStateAccess == DirectStateAccess.Extension)
            {
                int             offset   = 0;
                VertexElement[] elements = description.GetElements();
                for (int i = 0; i < description.ElementCount; i++)
                {
                    if (offset > OpenGLCapabilities.MaxVertexAttribBindingOffset)
                    {
                        throw new PlatformNotSupportedException("offset is higher than maximum supportet offset.");
                    }

                    Ext.EnableVertexArrayAttrib(layout, i);

                    Ext.VertexArrayVertexAttribBinding(layout, i, elements[i].UsageIndex);
                    Ext.VertexArrayVertexAttribFormat(layout, i, GetComponentsOf(elements[i].Type), (OpenTK.Graphics.OpenGL.ExtDirectStateAccess)VertexAttribType.Float, false, offset);
                    offset += GetSizeOf(elements[i].Type);
                }
            }

            inputLayoutPool.Add(description, layout);
            return(layout);
        }
Пример #2
0
        public int GetSizeOf(VertexDescription description)
        {
            int size = 0;

            VertexElement[] elements = description.GetElements();
            for (int i = 0; i < elements.Length; i++)
            {
                size += GetSizeOf(elements[i].Type);
            }

            return(size);
        }
Пример #3
0
        public InputLayout GetLayout(VertexDescription description, Shader shader)
        {
            InputLayout layout;

            if (inputLayoutPool.TryGetValue(description, out layout))
            {
                return(layout);
            }

            InputElement[]  dxElements = new InputElement[description.ElementCount];
            VertexElement[] elements   = description.GetElements();

            for (int i = 0; i < description.ElementCount; i++)
            {
                dxElements[i] = new InputElement(EnumConverter.Convert(elements[i].Usage), 0, EnumConverter.Convert(elements[i].Type), elements[i].UsageIndex);
            }
            layout = inputLayoutPool[description] = new InputLayout(Device, shader.VertexCode, dxElements);
            return(layout);
        }