Exemplo n.º 1
0
        public static FrameBuffer Create(int width, int height, IGraphicsContext context)
        {
            int textureHandle = context.GenTexture();

            context.BindTexture(TextureTarget.Texture2D, textureHandle);

            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, false, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)null);

            var texture = new Texture2D(context, textureHandle, width, height);

            int handle;

            context.GenFrameBuffers(1, out handle);
            context.BindFrameBuffer(FramebufferTarget.Framebuffer, handle);

            context.FrameBufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, textureHandle, 0);

            context.BindFrameBuffer(FramebufferTarget.Framebuffer, 0);
            return(new FrameBuffer(handle, texture));
        }
Exemplo n.º 2
0
        public override Texture2D Process(Bitmap bitmap, IResourceContext context)
        {
            BitmapData       data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Format);
            IGraphicsContext gc   = context.Locator.GetService <IGraphicsContext>();


            int id = gc.GenTexture();

            gc.BindTexture(TextureTarget.Texture2D, id);

            gc.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, false,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            bitmap.UnlockBits(data);

            //gc.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);


            bitmap.Dispose();

            Console.WriteLine(GC.GetTotalMemory(true));

            return(new Texture2D(gc, id, data.Width, data.Height));
        }
Exemplo n.º 3
0
        public static Texture2D LoadTexture(IGraphicsContext context, Stream stream)
        {
            Bitmap     bitmap = new Bitmap(stream);
            BitmapData data   = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            int id = context.GenTexture();

            context.BindTexture(TextureTarget.Texture2D, id);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, false,
                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            bitmap.UnlockBits(data);

            context.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            return(new Texture2D(context, id, data.Width, data.Height));
        }
        public static FrameBuffer Create(int width, int height, IGraphicsContext context)
        {
            int textureHandle = context.GenTexture();
            context.BindTexture(TextureTarget.Texture2D, textureHandle);

            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, false, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)null);

            var texture = new Texture2D(context, textureHandle, width, height);

            int handle;
            context.GenFrameBuffers(1, out handle);
            context.BindFrameBuffer(FramebufferTarget.Framebuffer, handle);

            context.FrameBufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, textureHandle, 0);

            context.BindFrameBuffer(FramebufferTarget.Framebuffer, 0);
            return new FrameBuffer(handle, texture);
        }
Exemplo n.º 5
0
 public void TexImage2D(TextureTarget target, int level, PixelInternalFormat intenalFormat, int width, int height, bool border, PixelFormat format, PixelType pixelType, IntPtr data)
 {
     forwarding.TexImage2D(target, level, intenalFormat, width, height, border, format, pixelType, data);
     CheckGLError();
     GLCALLS++;
 }