Esempio n. 1
0
            public void SetAllPixels(IFinGrid <FinColor> rgbaGrid)
            {
                /*TexturesOpenTk.ConvertRgbaGridToUintArray_(
                 *  rgbaGrid,
                 *  ref this.pixelData_);
                 *
                 * GL.BindBuffer(BufferTarget.PixelPackBuffer, this.bufferId_);
                 * GL.ReadPixels(0,
                 *            0,
                 *            this.width_,
                 *            this.height_,
                 *            PixelFormat.AbgrExt,
                 *            PixelType.UnsignedByte,
                 *            this.pixelData_);
                 * GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);*/

                TexturesOpenTk.ConvertRgbaGridToUintArray_(
                    rgbaGrid,
                    ref this.pixelData_,
                    this.width_,
                    this.height_);

                GL.BindTexture(TextureTarget.Texture2D, this.textureId_);
                //GL.BindTexture(BufferTarget.PixelUnpackBuffer, this.pixelData_);

                GL.TexImage2D(TextureTarget.Texture2D,
                              0,
                              PixelInternalFormat.Rgba,
                              this.width_,
                              this.height_,
                              0,
                              PixelFormat.AbgrExt,
                              PixelType.UnsignedByte,
                              this.pixelData_);

                GL.TexParameter(TextureTarget.Texture2D,
                                TextureParameterName.TextureMinFilter,
                                (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D,
                                TextureParameterName.TextureMagFilter,
                                (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D,
                                TextureParameterName.TextureWrapS,
                                (int)TextureWrapMode.Clamp);
                GL.TexParameter(TextureTarget.Texture2D,
                                TextureParameterName.TextureWrapT,
                                (int)TextureWrapMode.Clamp);

                //GL.BindTexture(BufferTarget.PixelUnpackBuffer, 0);
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }
Esempio n. 2
0
        public ITexture Create(ImageData imageData)
        {
            var textureFormat =
                TexturesOpenTk.ConvertImageTypeToTextureFormat_(imageData.imageType);

            var(width, height) =
                (imageData.pixels.Width, imageData.pixels.Height);

            uint textureId;

            GL.GenTextures(1, out textureId);
            //GL.CreateTextures(TextureTarget.Texture2D, 1, out textureId);

            /*GL.TextureStorage2D(textureId,
             *                  1,
             *                  textureFormat,
             *                  width,
             *                  height);*/

            var pixelData = new uint[width * height];

            TexturesOpenTk.ConvertRgbaGridToUintArray_(
                imageData.pixels,
                ref pixelData,
                width,
                height);

            GL.BindTexture(TextureTarget.Texture2D, textureId);
            GL.TexImage2D(TextureTarget.Texture2D,
                          0,
                          PixelInternalFormat.Rgba,
                          width,
                          height,
                          0,
                          PixelFormat.AbgrExt,
                          PixelType.UnsignedByte,
                          pixelData);

            /*GL.TextureSubImage2D(textureId,
             *                   0,
             *                   0,
             *                   0,
             *                   width,
             *                   height,
             *                   PixelFormat.Rgba,
             *                   PixelType.Int,
             *                   pixelData);*/

            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureMinFilter,
                            (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureMagFilter,
                            (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureWrapS,
                            (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2D,
                            TextureParameterName.TextureWrapT,
                            (int)TextureWrapMode.Clamp);

            GL.BindTexture(TextureTarget.Texture2D, 0);

            return(new TextureOpenTk(textureId));
        }