Example #1
0
        public RenderDevice(ShaderProgram ShaderProg, int Width, int Height)
        {
            Shader      = ShaderProg;
            VertexArray = new VertexArray();

            Elements = new BufferObject();
            VertexArray.BindElementBuffer(Elements);

            Vertices = new BufferObject();
            uint PosAttrib = (uint)ShaderProg.GetAttribLocation("Pos");

            VertexArray.AttribFormat(PosAttrib, Size: 2);
            VertexArray.AttribBinding(PosAttrib, VertexArray.BindVertexBuffer(Vertices, Stride: 2 * sizeof(float)));

            Colors = new BufferObject();
            uint ClrAttrib = (uint)ShaderProg.GetAttribLocation("Clr");

            VertexArray.AttribFormat(ClrAttrib, Size: 4);
            VertexArray.AttribBinding(ClrAttrib, VertexArray.BindVertexBuffer(Colors, Stride: 4 * sizeof(float)));

            UVs = new BufferObject();
            uint UVAttrib = (uint)ShaderProg.GetAttribLocation("UV");

            VertexArray.AttribFormat(UVAttrib, Size: 2);
            VertexArray.AttribBinding(UVAttrib, VertexArray.BindVertexBuffer(UVs, Stride: 2 * sizeof(float)));
        }
Example #2
0
        public void SetUVs(Vector2[] UVs)
        {
            if (UVBuffer == null)
            {
                VAO.AttribFormat(UV_ATTRIB, Size: 2);
                VAO.AttribBinding(UV_ATTRIB, VAO.BindVertexBuffer(UVBuffer = new BufferObject(), Stride: 2 * sizeof(float)));
            }

            UVBuffer.SetData(UVs, Usage: Usage);
            VAO.AttribEnable(UV_ATTRIB, UVs != null);
        }
Example #3
0
        public void SetColors(Vector4[] Colors)
        {
            if (ColorBuffer == null)
            {
                VAO.AttribFormat(COLOR_ATTRIB, Size: 4);
                VAO.AttribBinding(COLOR_ATTRIB, VAO.BindVertexBuffer(ColorBuffer = new BufferObject(), Stride: 4 * sizeof(float)));
            }

            ColorBuffer.SetData(Colors, Usage: Usage);
            VAO.AttribEnable(COLOR_ATTRIB, Colors != null);
        }
Example #4
0
        public void SetVertices(Vector3[] Verts)
        {
            Vertices = Verts;

            if (VertBuffer == null)
            {
                VAO.AttribFormat(VERTEX_ATTRIB);
                VAO.AttribBinding(VERTEX_ATTRIB, VAO.BindVertexBuffer(VertBuffer = new BufferObject()));
            }

            VertBuffer.SetData(Verts, Usage: Usage);
            VAO.AttribEnable(VERTEX_ATTRIB, Verts != null);
        }
Example #5
0
        public void BindElementBuffer(BufferObject Obj)
        {
            ElementBuffer = Obj;

            if (Obj != null)
            {
                Gl.VertexArrayElementBuffer(ID, Obj.ID);
            }
            else
            {
                Gl.VertexArrayElementBuffer(ID, 0);
            }
        }
Example #6
0
        public void SetElements(uint[] Elements)
        {
            if (ElementBuffer == null)
            {
                ElementBuffer = new BufferObject();
            }

            if (Elements != null)
            {
                VAO.BindElementBuffer(ElementBuffer);
                ElementBuffer.SetData(Elements, Usage: Usage);
            }
            else
            {
                VAO.BindElementBuffer(null);
            }
        }
Example #7
0
        public uint BindVertexBuffer(BufferObject Obj, int BindingIndex = -1, int Offset = 0, int Stride = 3 *sizeof(float))
        {
            if (!BufferObjects.Contains(Obj))
            {
                BufferObjects.Add(Obj);
            }

            if (BindingIndex == -1)
            {
                BindingIndex = FreeBindingIndex++;
            }

            if (Obj != null)
            {
                Gl.VertexArrayVertexBuffer(ID, (uint)BindingIndex, Obj.ID, (IntPtr)Offset, Stride);
            }

            return((uint)BindingIndex);
        }