示例#1
0
        private void RenderbufferStorage(uint target, uint internalformat, int width, int height)
        {
            if (target != GL.GL_RENDERBUFFER)
            {
                SetLastError(ErrorCode.InvalidEnum); return;
            }
            if (width < 0 || maxRenderbufferSize < width)
            {
                SetLastError(ErrorCode.InvalidValue); return;
            }
            if (height < 0 || maxRenderbufferSize < height)
            {
                SetLastError(ErrorCode.InvalidValue); return;
            }
            // TODO: GL_INVALID_ENUM is generated if internalformat​ is not a color-renderable, depth-renderable, or stencil-renderable format.
            // TODO: GL_OUT_OF_MEMORY is generated if the GL is unable to create a data store of the requested size.

            Renderbuffer obj = this.currentRenderbuffers[target - GL.GL_RENDERBUFFER];

            if (obj != null)
            {
                int bitSize   = InternalFormatHelper.BitSize(internalformat);
                int bytes     = (bitSize % 8 == 0) ? bitSize / 8 : bitSize / 8 + 1; // TODO: any better solution?
                var dataStore = new byte[width * height * bytes];
                obj.Storage(internalformat, width, height, dataStore);
            }
        }
示例#2
0
        private void BindRenderbuffer(uint target, uint name)
        {
            if (target != GL.GL_RENDERBUFFER)
            {
                SetLastError(ErrorCode.InvalidEnum); return;
            }
            if ((name != 0) && (!this.renderbufferNameList.Contains(name)))
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }

            if (name == 0)
            {
                this.currentRenderbuffers[target - GL.GL_RENDERBUFFER] = null;
            }
            else
            {
                Dictionary <uint, Renderbuffer> dict = this.nameRenderbufferDict;
                if (!dict.ContainsKey(name)) // for the first time the name is binded, we create a renderbuffer object.
                {
                    var obj = new Renderbuffer(name);
                    dict.Add(name, obj);
                }

                this.currentRenderbuffers[target - GL.GL_RENDERBUFFER] = dict[name];
            }
        }
示例#3
0
        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;
            }
        }