示例#1
0
        public Texture this[FramebufferAttachment attachment]
        {
            set
            {
                bindings[attachment] = value;
                GPUStateMachine.BindFramebuffer(id);
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachment, value.texTarget, value.id, 0);

                GL.DrawBuffers(bindings.Keys.Count,
                               bindings.Keys.OrderByDescending((a) => (int)a).Reverse().Cast <DrawBuffersEnum>().ToArray());

                if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete)
                {
                    throw new Exception("Incomplete Framebuffer!");
                }

                GPUStateMachine.UnbindFramebuffer();
            }
            get
            {
                if (bindings.ContainsKey(attachment))
                {
                    return(bindings[attachment]);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#2
0
        public static void Draw(PrimitiveType type, int first, int count)
        {
            if (count == 0)
            {
                return;
            }

            if (curVarray == null)
            {
                return;
            }
            if (curProg == null)
            {
                return;
            }
            if (curFramebuffer == null)
            {
                return;
            }


            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.BindTexture(i, textures[i].texTarget, textures[i].id);
            }
            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.BindBuffer(BufferTarget.TransformFeedbackBuffer, feedbackBufs[i].Item1.id, i, (IntPtr)feedbackBufs[i].Item2, (IntPtr)feedbackBufs[i].Item3);
            }



            GPUStateMachine.BindFramebuffer(curFramebuffer.id);
            if (feedbackBufs.Count > 0)
            {
                GL.BeginTransformFeedback((TransformFeedbackPrimitiveType)feedbackPrimitive);
            }

            GL.UseProgram(curProg.id);
            GPUStateMachine.BindVertexArray(curVarray.id);
            if (curIndices != null)
            {
                GPUStateMachine.BindBuffer(BufferTarget.ElementArrayBuffer, curIndices.id);
            }

            if (curIndices != null)
            {
                GL.DrawElements(type, count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            }
            else
            {
                GL.DrawArrays(type, first, count);
            }

            if (feedbackBufs.Count > 0)
            {
                GL.EndTransformFeedback();
            }

            for (int i = 0; i < feedbackBufs.Count; i++)
            {
                GPUStateMachine.UnbindBuffer(BufferTarget.TransformFeedbackBuffer, i);
            }
            for (int i = 0; i < textures.Count; i++)
            {
                GPUStateMachine.UnbindTexture(i, textures[i].texTarget);
            }

            textures.Clear();
            feedbackBufs.Clear();
        }