Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad (e);
            Context.ErrorChecking = true;

            String version = GL.GetString(StringName.Version);
            Console.WriteLine("GL version: " + version);

            context = GLGraphics.NewContext(Context, true);

            program = context.NewProgramFromFiles("Render.vert", "Render.frag");

            texture0 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
            texture0.UploadImage(sourceImage);
            sourceImage.Dispose();

            texture1 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
            texture1.UploadImage(new byte[4 * 4 * 4], 4, 4, PixelInternalFormat.Four, PixelFormat.Rgba, PixelType.UnsignedByte);

            CreateAndFillBuffers();
            paramSpec = ImmutableList<Tuple<String, Object>>.List(new Tuple<String, Object>[] {
                Tuple.Create<String, Object>("a_position", positions),
                Tuple.Create<String, Object>("a_texPos", textureCoords),
                Tuple.Create<String, Object>("u_texture0", texture0),
                Tuple.Create<String, Object>("u_texture1", texture1)});

            rc = context.NewRenderBuffer(1000, 1000, RenderbufferStorage.Rgb8);
            rd = context.NewRenderBuffer(1000, 1000, RenderbufferStorage.DepthComponent24);

            fb = context.NewFrameBuffer(rc, rd, FramebufferTarget.Framebuffer);
        }
Пример #2
0
        internal GLFrameBuffer(GLRenderBuffer colorBuffer, GLRenderBuffer depthBuffer, FramebufferTarget fbTarget, bool disposeRenderBuffers, GLGraphicsContext context)
            : this(context)
        {
            this.disposeRenderBuffers = disposeRenderBuffers;
            this.colorBuffer = colorBuffer;
            this.depthBuffer = depthBuffer;
            this.fbTarget = fbTarget;

            OGL.BindFramebuffer(fbTarget, fboId);

            OGL.FramebufferRenderbuffer(fbTarget, FramebufferAttachment.ColorAttachment0,
                RenderbufferTarget.Renderbuffer, colorBuffer.Id);
            OGL.FramebufferRenderbuffer(fbTarget, FramebufferAttachment.DepthAttachment,
                RenderbufferTarget.Renderbuffer, depthBuffer.Id);

            FramebufferErrorCode err = OGL.CheckFramebufferStatus(fbTarget);
            switch(err) {
            case FramebufferErrorCode.FramebufferComplete:
                break;
            default:
                this.Dispose();
                throw new Exception(String.Format("Invalid frame buffer status: {0}", err));
            }

            OGL.BindFramebuffer(fbTarget, 0);

            context.CheckForErrorsIfDebugging();
        }