Initialize() public méthode

resources(bitmap etc.) can be disposed after this initialization.
public Initialize ( ) : void
Résultat void
Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoInitialize()
        {
            base.DoInitialize();

            this.RenderUnit.Initialize();

            {
                var bitmap = this.bitmap;
                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                var texture = new Texture(TextureTarget.Texture2D,
                                          new TexImage2D(TexImage2D.Target.Texture2D, 0, (int)GL.GL_RGBA, bitmap.Width, bitmap.Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bitmap)));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));

                texture.Initialize();

                if (this.autoDispose)
                {
                    bitmap.Dispose();
                }
                this.bitmap = null;

                RenderMethod method = this.RenderUnit.Methods[0];
                method.Program.SetUniform("tex", texture);
            }
        }
Exemple #2
0
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            //Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            //Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            //framebuffer.Attach(colorBuffer);//0
            //this.BindingTexture = framebuffer.Attach(TextureAttachment.DepthAttachment);//1
            var texture = new Texture(new TexImage2D(TexImage2D.Target.Texture2D, GL.GL_DEPTH_COMPONENT32, width, height, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT),
                                      // 设置默认滤波模式
                                      new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                      new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR),
                                      // 设置深度比较模式
                                      new TexParameteri(TexParameter.PropertyName.TextureCompareMode, (int)GL.GL_COMPARE_REF_TO_TEXTURE),
                                      new TexParameteri(TexParameter.PropertyName.TextureCompareFunc, (int)GL.GL_LEQUAL),
                                      // 设置边界截取模式
                                      new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE),
                                      new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));

            texture.Initialize();
            framebuffer.Attach(FramebufferTarget.Framebuffer, texture, AttachmentLocation.Depth);
            this.BindingTexture = texture;

            //framebuffer.Attach(depthBuffer);// special
            //framebuffer.SetDrawBuffers(GL.GL_COLOR_ATTACHMENT0 + 1);// as in 1 in framebuffer.Attach(texture);//1
            //framebuffer.SetDrawBuffers(GL.GL_NONE);
            framebuffer.SetDrawBuffer(GL.GL_NONE);
            //framebuffer.SetReadBuffer(GL.GL_NONE);
            this.BindingTexture.Bind();
            framebuffer.CheckCompleteness();
            this.BindingTexture.Unbind();
            framebuffer.Unbind();
            return(framebuffer);
        }
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var framebuffer = new Framebuffer(width, height);

            framebuffer.Bind();
            {
                var texture = new Texture(new TexImageBitmap(width, height),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                          new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                          new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                texture.Initialize();
                framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 0u);// 1
                this.BindingTexture = texture;
            }
            {
                var renderbuffer = new Renderbuffer(width, height, GL.GL_DEPTH_COMPONENT24);
                framebuffer.Attach(FramebufferTarget.Framebuffer, renderbuffer, AttachmentLocation.Depth);// special
            }
            //framebuffer.SetDrawBuffer(GL.GL_COLOR_ATTACHMENT0 + 1);// as in 1 in framebuffer.Attach(FramebufferTarget.Framebuffer, texture, 1u);// 1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();

            return(framebuffer);
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoInitialize()
        {
            this.RenderUnit.Initialize();

            {
                var bitmap = this.bitmap;
                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                var texImageBitmap = new TexImageBitmap(bitmap);
                var texture        = new Texture(texImageBitmap);
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
                texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));

                texture.Initialize();

                if (this.autoDispose)
                {
                    bitmap.Dispose();
                }
                this.bitmap = null;

                RenderMethod method = this.RenderUnit.Methods[0];
                method.Program.SetUniform("tex", texture);
            }
        }
Exemple #5
0
        /// <summary>
        /// load a volume from the given raw data file and generates an OpenGL 3D texture from it
        /// </summary>
        /// <returns></returns>
        public static Texture Load()
        {
            var bytes = new byte[XDIM * YDIM * ZDIM];

            // read the volume data file
            using (var file = new System.IO.FileStream(volume_file, System.IO.FileMode.Open))
            {
                file.Read(bytes, 0, bytes.Length);
            }

            // generate OpenGL texture
            var dataProvider = new ArrayDataProvider <byte>(bytes);
            var storage      = new TexImage3D(TexImage3D.Target.Texture3D, GL.GL_RED, 1, 0, XDIM, YDIM, ZDIM, GL.GL_RED, GL.GL_UNSIGNED_BYTE, dataProvider);
            var texture      = new Texture(
                TextureTarget.Texture3D, storage, new MipmapBuilder(),
                new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP),
                new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR),
                new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR),
                new TexParameteri(TexParameter.PropertyName.TextrueBaseLevel, 0),
                new TexParameteri(TexParameter.PropertyName.TextureMaxLevel, 4));

            texture.Initialize();

            return(texture);
        }
Exemple #6
0
        /// <summary>
        /// load a volume from the given raw data file and generates an OpenGL 3D texture from it
        /// </summary>
        /// <returns></returns>
        public static Texture Load(Bitmap image)
        {
            var bytes = new byte[length * length * length];

            if (image.Width != length || image.Height != length)
            {
                image = (Bitmap)image.GetThumbnailImage(length, length, null, IntPtr.Zero);
            }

            image.RotateFlip(RotateFlipType.Rotate180FlipX);
            FillByteArray(bytes, image);

            // generate OpenGL texture
            var dataProvider = new ArrayDataProvider <byte>(bytes);
            var storage      = new TexImage3D(TexImage3D.Target.Texture3D, GL.GL_RED, length, length, length, GL.GL_RED, GL.GL_UNSIGNED_BYTE, dataProvider);
            var texture      = new Texture(storage, new MipmapBuilder(),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP),
                                           new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR_MIPMAP_LINEAR),
                                           new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR),
                                           new TexParameteri(TexParameter.PropertyName.TextrueBaseLevel, 0),
                                           new TexParameteri(TexParameter.PropertyName.TextureMaxLevel, 4));

            texture.Initialize();

            return(texture);
        }
Exemple #7
0
        private Framebuffer CreateFramebuffer(int width, int height)
        {
            var texture = new Texture(TextureTarget.Texture2D,
                                      new NullImageFiller(width, height, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE),
                                      new SamplerParameters(
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureWrapping.Repeat,
                                          TextureFilter.Linear,
                                          TextureFilter.Linear));

            texture.Initialize();
            this.BindingTexture = texture;
            Renderbuffer colorBuffer = Renderbuffer.CreateColorbuffer(width, height, GL.GL_RGBA);
            Renderbuffer depthBuffer = Renderbuffer.CreateDepthbuffer(width, height, DepthComponentType.DepthComponent24);
            var          framebuffer = new Framebuffer();

            framebuffer.Bind();
            framebuffer.Attach(colorBuffer);                         //0
            framebuffer.Attach(texture);                             //1
            framebuffer.Attach(depthBuffer);                         // special
            framebuffer.SetDrawBuffers(GL.GL_COLOR_ATTACHMENT0 + 1); // as in 1 in framebuffer.Attach(texture);//1
            framebuffer.CheckCompleteness();
            framebuffer.Unbind();
            return(framebuffer);
        }
Exemple #8
0
        /// <summary>
        /// Attach a texture.
        /// <para>Bind() this framebuffer before invoking this method.</para>
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public Texture Attach(TextureAttachment type)
        {
            const int level  = 0;
            Texture   result = null;

            switch (type)
            {
            case TextureAttachment.ColorAttachment:
                result = new Texture(TextureTarget.Texture2D,
                                     new TexImage2D(TexImage2D.Target.Texture2D, 0, (int)GL.GL_RGBA, this.Width, this.Height, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                result.Initialize();
                glFramebufferTexture(GL.GL_FRAMEBUFFER, attachment_id[nextColorAttachmentIndex++], result.Id, level);
                break;

            case TextureAttachment.DepthAttachment:
                result = new Texture(TextureTarget.Texture2D,
                                     new TexImage2D(TexImage2D.Target.Texture2D, 0, (int)GL.GL_DEPTH_COMPONENT32, this.Width, this.Height, 0, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT));
                // 设置默认滤波模式
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
                // 设置深度比较模式
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureCompareMode, (int)GL.GL_COMPARE_REF_TO_TEXTURE));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureCompareFunc, (int)GL.GL_LEQUAL));
                // 设置边界截取模式
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
                result.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
                result.Initialize();
                glFramebufferTexture(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, result.Id, level);
                //glFramebufferTexture(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_STENCIL_ATTACHMENT, result.Id, level);
                //glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_TEXTURE_2D, result.Id, level);
                //glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_STENCIL_ATTACHMENT, GL.GL_TEXTURE_2D, result.Id, level);// error
                break;

            case TextureAttachment.StencilAttachment:
                throw new NotImplementedException();
                break;

            case TextureAttachment.DepthStencilAttachment:
                throw new NotImplementedException();
                break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
Exemple #9
0
        private static Texture GenerateTexture(Bitmap[] bitmaps)
        {
            var storage = new TexImageBitmaps(bitmaps);
            var texture = new Texture(TextureTarget.Texture2DArray, storage,
                                      new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                      new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                      //new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                      new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR),
                                      new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));

            texture.Initialize();

            return(texture);
        }
Exemple #10
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            Bitmap bitmap;
            if (string.IsNullOrEmpty(this.bitmapFilename))// display a cursor as default.
            { bitmap = ManifestResourceLoader.LoadBitmap(@"Resources\cursor_gold.png"); }
            else
            { bitmap = new Bitmap(this.bitmapFilename); }
            var texture = new Texture(TextureTarget.Texture2D, bitmap, new SamplerParameters());
            texture.Initialize();
            bitmap.Dispose();
            this.SetUniform("tex", texture);
        }
        protected override void DoInitialize()
        {
            base.DoInitialize();

            Bitmap bitmap = this.codedColors.GetBitmap(1024);
            var texture = new Texture(TextureTarget.Texture1D, bitmap, new SamplerParameters());
            this.codedColors = null;
            texture.Initialize();
            this.Sampler = texture;
            bitmap.Dispose();
            var renderer = this.Renderer as Renderer;
            renderer.SetUniform("codedColorSampler", new samplerValue(TextureTarget.Texture1D,
                texture.Id, 0));
        }
        /// <summary>
        /// Gets an instance of <see cref="FontTexture"/>.
        /// </summary>
        /// <param name="fontBitmap"></param>
        /// <param name="parameters"></param>
        /// <param name="mipmapFiltering"></param>
        /// <returns></returns>
        public static FontTexture GetFontTexture(this FontBitmap fontBitmap,
                                                 SamplerParameters parameters = null,
                                                 MipmapFilter mipmapFiltering = MipmapFilter.LinearMipmapLinear)
        {
            var texture = new Texture(fontBitmap.GlyphBitmap,
                                      parameters, mipmapFiltering);

            texture.Initialize();
            var result = new FontTexture();

            result.GlyphFont           = fontBitmap.GlyphFont;
            result.GlyphHeight         = fontBitmap.GlyphHeight;
            result.TextureSize         = fontBitmap.GlyphBitmap.Size;
            result.GlyphInfoDictionary = fontBitmap.GlyphInfoDictionary;
            result.TextureObj          = texture;
            return(result);
        }
        /// <summary>
        /// Provides a <see cref="Texture"/> object generated from specified bitmap file.
        /// </summary>
        /// <param name="filename"></param>
        public BitmapTextureSource(string filename)
        {
            var bmp = new System.Drawing.Bitmap(filename);

            bmp.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
            var storage = new TexImageBitmap(bmp);

            texture = new Texture(storage);
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));

            texture.Initialize();
            bmp.Dispose();
        }
Exemple #14
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            Bitmap bitmap;

            if (string.IsNullOrEmpty(this.bitmapFilename))// display a cursor as default.
            {
                bitmap = ManifestResourceLoader.LoadBitmap(@"Resources\cursor_gold.png");
            }
            else
            {
                bitmap = new Bitmap(this.bitmapFilename);
            }
            var texture = new Texture(TextureTarget.Texture2D, bitmap, new SamplerParameters());

            texture.Initialize();
            bitmap.Dispose();
            this.SetUniform("tex", texture);
        }
Exemple #15
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            var bmp     = new Bitmap(@"KleinBottle.png");
            var texture = new Texture(new TexImage1D(GL.GL_RGBA, bmp.Width, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, new ImageDataProvider(bmp)));

            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_CLAMP_TO_EDGE));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
            texture.Initialize();
            bmp.Dispose();

            var           method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("tex", texture);
        }
Exemple #16
0
        protected override void DoInitialize()
        {
            base.DoInitialize();

            Bitmap bitmap;

            if (string.IsNullOrEmpty(this.bitmapFilename))// display a cursor as default.
            {
                bitmap = ManifestResourceLoader.LoadBitmap(@"Resources\cursor_gold.png");
            }
            else
            {
                bitmap = new Bitmap(this.bitmapFilename);
            }
            var texture = new Texture(bitmap);

            texture.Initialize();
            bitmap.Dispose();
            this.SetUniform("tex", new samplerValue(BindTextureTarget.Texture2D,
                                                    texture.Id, OpenGL.GL_TEXTURE0));
        }