Beispiel #1
0
        private uint CheckFramebufferStatus(BindFramebufferTarget target)
        {
            if (!Enum.IsDefined(typeof(BindFramebufferTarget), target))
            {
                SetLastError(ErrorCode.InvalidEnum); return(0);
            }

            // TODO: check this framebuffer.

            return(GL.GL_FRAMEBUFFER_COMPLETE);
        }
Beispiel #2
0
        private void BindFramebuffer(BindFramebufferTarget target, uint name)
        {
            if (!Enum.IsDefined(typeof(BindFramebufferTarget), target))
            {
                SetLastError(ErrorCode.InvalidEnum); return;
            }
            if ((name != 0) && (!this.framebufferNameList.Contains(name)))
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }

            Dictionary <uint, Framebuffer> dict = this.nameFramebufferDict;

            if (!dict.ContainsKey(name)) // for the first time the name is binded, we create a framebuffer object.
            {
                var obj = new Framebuffer(name);
                dict.Add(name, obj);
            }

            Framebuffer fbo = dict[name];

            fbo.Target = target;
            this.currentFramebuffer = fbo;
        }
        private void FramebufferRenderbuffer(BindFramebufferTarget target, uint attachmentPoint, uint renderbufferTarget, uint renderbufferName)
        {
            if (!Enum.IsDefined(typeof(BindFramebufferTarget), target))
            {
                SetLastError(ErrorCode.InvalidEnum); return;
            }
            if (renderbufferTarget != GL.GL_RENDERBUFFER)
            {
                SetLastError(ErrorCode.InvalidEnum); return;
            }
            // TODO: GL_INVALID_OPERATION is generated if zero is bound to target.
            Dictionary <uint, Renderbuffer> dict = this.nameRenderbufferDict;

            if ((renderbufferName != 0) && (!dict.ContainsKey(renderbufferName)))
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }

            Renderbuffer renderbuffer = null;

            if (renderbufferName != 0)
            {
                if (!dict.TryGetValue(renderbufferName, out renderbuffer))
                {
                    SetLastError(ErrorCode.InvalidOperation); return;
                }
            }

            Framebuffer framebuffer = this.currentFramebuffer;

            if (framebuffer == null)
            {
                return;
            }
            if (framebuffer.Target != target)
            {
                // TODO: what should I do? Or should multiple current framebufer object exist?
            }

            if (attachmentPoint == GL.GL_DEPTH_ATTACHMENT)
            {
                framebuffer.DepthbufferAttachment = renderbuffer;
            }
            else if (attachmentPoint == GL.GL_STENCIL_ATTACHMENT)
            {
                framebuffer.StencilbufferAttachment = renderbuffer;
            }
            else if (attachmentPoint == GL.GL_DEPTH_STENCIL_ATTACHMENT)
            {
                framebuffer.DepthbufferAttachment   = renderbuffer;
                framebuffer.StencilbufferAttachment = renderbuffer;
            }
            else // color attachment points.
            {
                if (attachmentPoint < GL.GL_COLOR_ATTACHMENT0)
                {
                    SetLastError(ErrorCode.InvalidOperation); return;
                }
                uint index = attachmentPoint - GL.GL_COLOR_ATTACHMENT0;
                if (framebuffer.ColorbufferAttachments.Length <= index)
                {
                    SetLastError(ErrorCode.InvalidOperation); return;
                }

                framebuffer.ColorbufferAttachments[index] = renderbuffer;
            }
        }