예제 #1
0
        public ITexture Bind(bool CreateNewTexture, Size size)
        {
            VerifyThreadAffinity();

            // Cache viewport rect to restore when unbinding
            cv = ViewportRectangle();

            OpenGL.glFlush();
            OpenGL.CheckGLError();
            OpenGL.glBindFramebuffer(OpenGL.FRAMEBUFFER_EXT, framebuffer);
            OpenGL.CheckGLError();
            ITextureInternal tex = null;

            if (CreateNewTexture)
            {
                tex = new Texture();
            }

            this.texture.Add(tex);
            tex.SetEmpty(size.Width, size.Height);

            OpenGL.glFramebufferTexture2D(OpenGL.FRAMEBUFFER_EXT, OpenGL.COLOR_ATTACHMENT0_EXT, OpenGL.GL_TEXTURE_2D, tex.ID, 0);
            OpenGL.CheckGLError();

            OpenGL.glViewport(0, 0, size.Width, size.Height);
            OpenGL.CheckGLError();
            OpenGL.glClearColor(0, 0, 0, 0);
            OpenGL.CheckGLError();
            OpenGL.glClear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            OpenGL.CheckGLError();
            return(tex);
        }
예제 #2
0
 public ThreadedTexture(ThreadedGraphicsContext device, ITextureInternal texture)
 {
     this.device    = device;
     id             = texture.ID;
     getScaleFilter = () => texture.ScaleFilter;
     setScaleFilter = value => texture.ScaleFilter = (TextureScaleFilter)value;
     getSize        = () => texture.Size;
     setEmpty       = tuple => { var t = (ValueTuple <int, int>)tuple; texture.SetEmpty(t.Item1, t.Item2); };
     getData        = () => texture.GetData();
     setData1       = colors => { texture.SetData((uint[, ])colors); return(null); };
     setData2       = tuple => { var t = (ValueTuple <byte[], int, int>)tuple; texture.SetData(t.Item1, t.Item2, t.Item3); };
     dispose        = texture.Dispose;
 }
예제 #3
0
        public FrameBuffer(Size size, ITextureInternal texture, Color clearColor)
        {
            this.size       = size;
            this.clearColor = clearColor;
            if (!Exts.IsPowerOf2(size.Width) || !Exts.IsPowerOf2(size.Height))
            {
                throw new InvalidDataException("Frame buffer size ({0}x{1}) must be a power of two".F(size.Width, size.Height));
            }

            OpenGL.glGenFramebuffers(1, out framebuffer);
            OpenGL.CheckGLError();
            OpenGL.glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, framebuffer);
            OpenGL.CheckGLError();

            // Color
            this.texture = texture;
            texture.SetEmpty(size.Width, size.Height);
            OpenGL.glFramebufferTexture2D(OpenGL.GL_FRAMEBUFFER, OpenGL.GL_COLOR_ATTACHMENT0, OpenGL.GL_TEXTURE_2D, texture.ID, 0);
            OpenGL.CheckGLError();

            // Depth
            OpenGL.glGenRenderbuffers(1, out depth);
            OpenGL.CheckGLError();

            OpenGL.glBindRenderbuffer(OpenGL.GL_RENDERBUFFER, depth);
            OpenGL.CheckGLError();

            var glDepth = OpenGL.Profile == GLProfile.Embedded ? OpenGL.GL_DEPTH_COMPONENT16 : OpenGL.GL_DEPTH_COMPONENT;

            OpenGL.glRenderbufferStorage(OpenGL.GL_RENDERBUFFER, glDepth, size.Width, size.Height);
            OpenGL.CheckGLError();

            OpenGL.glFramebufferRenderbuffer(OpenGL.GL_FRAMEBUFFER, OpenGL.GL_DEPTH_ATTACHMENT, OpenGL.GL_RENDERBUFFER, depth);
            OpenGL.CheckGLError();

            // Test for completeness
            var status = OpenGL.glCheckFramebufferStatus(OpenGL.GL_FRAMEBUFFER);

            if (status != OpenGL.GL_FRAMEBUFFER_COMPLETE)
            {
                var error = "Error creating framebuffer: {0}\n{1}".F(status, new StackTrace());
                OpenGL.WriteGraphicsLog(error);
                throw new InvalidOperationException("OpenGL Error: See graphics.log for details.");
            }

            // Restore default buffer
            OpenGL.glBindFramebuffer(OpenGL.GL_FRAMEBUFFER, 0);
            OpenGL.CheckGLError();
        }
예제 #4
0
        public void ReBind(ITextureInternal t)
        {
            VerifyThreadAffinity();

            // Cache viewport rect to restore when unbinding
            cv = ViewportRectangle();

            OpenGL.glFlush();
            OpenGL.CheckGLError();
            OpenGL.glBindFramebuffer(OpenGL.FRAMEBUFFER_EXT, framebuffer);
            OpenGL.CheckGLError();


            OpenGL.glFramebufferTexture2D(OpenGL.FRAMEBUFFER_EXT, OpenGL.COLOR_ATTACHMENT0_EXT, OpenGL.GL_TEXTURE_2D, t.ID, 0);
            OpenGL.CheckGLError();

            OpenGL.glViewport(0, 0, size.Width, size.Height);
            OpenGL.CheckGLError();
            OpenGL.glClearColor(0, 0, 0, 0);
            OpenGL.CheckGLError();
            OpenGL.glClear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            OpenGL.CheckGLError();
        }
 public IFrameBuffer CreateFrameBuffer(Size s, ITextureInternal texture, Color clearColor)
 {
     VerifyThreadAffinity();
     return(new FrameBuffer(s, texture, clearColor));
 }
 public FrameBuffer CreateFrameBuffer(Size s, ITextureInternal texture)
 {
     VerifyThreadAffinity();
     return(new FrameBuffer(s, texture));
 }