コード例 #1
0
ファイル: RenderToTexture.cs プロジェクト: WolfgangSt/SLSharp
        /// <summary>
        /// Creates new (set of) renderable Texture(s)
        /// </summary>
        /// <param name="width">The width in pixels of the Texture(s)</param>
        /// <param name="height">The height in pixels of the Texture(s)</param>
        /// <param name="depth">True if depthbuffer is required when rendering to the Texture(s)</param>
        /// <param name="components">The number of color components the Texture(s) have</param>
        /// <param name="format">The data format the Texture(s) shall use, default is 16bit Half</param>
        /// <param name="buffers">The number of Textures to use.</param>
        public RenderToTexture(int width, int height, bool depth, int components = 3, Type format = null, int buffers = 1)
        {
            _fbo = new FramebufferObject();
            _textures = new Texture2D[buffers];
            _bufs = new DrawBuffersEnum[buffers];

            for (var i = 0; i < buffers; i++)
                _bufs[i] = DrawBuffersEnum.ColorAttachment0 + i;

            _fbo.Activate();
            GL.DrawBuffers(_textures.Length, _bufs);
            Utilities.CheckGL();

            _fbo.Finish();
            GL.DrawBuffer(DrawBufferMode.Back);
            Utilities.CheckGL();

            for (var i = 0; i < buffers; i++)
            {
                _textures[i] = new Texture2D(width, height, components, format ?? typeof(Half));
                _fbo.SetTexture(_textures[i], i);
            }

            if (depth)
            {
                _rbo = new RenderbufferObject();
                _fbo.Activate();
                _rbo.SetSize(width, height);
                _fbo.Finish();
            }

            _fbo.Check();
            Utilities.CheckGL();
        }
コード例 #2
0
ファイル: ClipmapLevel.cs プロジェクト: mono-soc-2011/SLSharp
        public ClipmapLevel(float scale, int scaleInt, Clipmap clipmap)
        {
            _d = clipmap.DValue;
            _h = clipmap.HValue;
            _n = _d - 1;

            _clipmap = clipmap;
            Scale = scale;
            ScaleInt = scaleInt;
            Heightmap = new Texture2D(_d, _d, 3, typeof(float));
            Heightmap.Activate();

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

            Heightmap.Finish();
        }
コード例 #3
0
ファイル: ClipmapLevel.cs プロジェクト: hach-que/SLSharp
        public ClipmapLevel(int level, float scale, Clipmap clipmap, ClipmapLevel parent)
        {
            _d = clipmap.DValue;
            _n = _d - 1;

            _cache = new float[_d, _d];

            _clipmap = clipmap;
            _parent = parent;
            _level = level;
            _scaleInt = 1 << _level;
            Scale = scale * _scaleInt;
            Heightmap = new Texture2D(_d, _d, 3, typeof(float));
            Heightmap.Activate();

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

            Heightmap.Finish();
        }
コード例 #4
0
ファイル: Texture2D.cs プロジェクト: hach-que/SLSharp
 /// <summary>
 /// Creates a new managed 2D Texture with the same format as an existing one
 /// </summary>
 /// <param name="width">The width in Pixels of the Texture</param>
 /// <param name="height">The height in Pixels of the Texture</param>
 /// <param name="other">The texture to copy the format from</param>
 public Texture2D(int width, int height, Texture2D other)
     : this(width, height, other._internalFormat, other.Target)
 {
     if (other == null)
         throw new ArgumentNullException("other");
 }
コード例 #5
0
ファイル: Texture2D.cs プロジェクト: hach-que/SLSharp
        /// <summary>
        /// Loads a texture from a bitmap
        /// </summary>
        /// <param name="bmp">The bitmap to load from</param>
        /// <returns>The texture object</returns>
        public static Texture2D FromBitmap(Bitmap bmp)
        {
            if (bmp == null)
                throw new ArgumentNullException("bmp");

            var bits = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            var components = Image.IsAlphaPixelFormat(bmp.PixelFormat) ? 4 : 3;
            var tex = new Texture2D(bmp.Width, bmp.Height, components, typeof(byte)); // lotsa possible opts here
            tex.Activate();

            var p = bits.Scan0;
            for (var y = 0; y < bits.Height; y++, p += bits.Stride)
            {
                GL.TexSubImage2D(tex.Target, 0, 0, y, bits.Width, 1,
                PixelFormat.Bgra, PixelType.UnsignedByte, p);
            }

            return tex;
        }
コード例 #6
0
ファイル: FramebufferObject.cs プロジェクト: hach-que/SLSharp
        /// <summary>
        /// Associates a Texture with the framebuffer object
        /// </summary>
        /// <param name="texture">The texture to associate</param>
        /// <param name="index">The channel to asscociate</param>
        public void SetTexture(Texture2D texture, int index = 0)
        {
            if (texture == null)
                throw new ArgumentNullException("texture");

            Activate();

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer,
                FramebufferAttachment.ColorAttachment0 + index,
                texture.Target, texture.Name, 0);

            Finish();
        }
コード例 #7
0
        private void InitTextures()
        {
            var i = byte.MaxValue + 1;
            var perm2 = new byte[i, i, 4];

            for (var y = 0; y < i; y++)
            {
                for (var x = 0; x < i; x++)
                {
                    var a = _perm[x] + y;
                    perm2[y, x, 0] = (byte)_perm[a];
                    perm2[y, x, 1] = (byte)_perm[a + 1];

                    var b = _perm[x + 1] + y;
                    perm2[y, x, 2] = (byte)_perm[b];
                    perm2[y, x, 3] = (byte)_perm[b + 1];
                }
            }

            _perm2D = new Texture2D(i, i, 4, typeof(byte));
            _perm2D.Activate();

            GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, i, i, PixelFormat.Rgba, PixelType.Byte, perm2);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            _permGrad3 = new Texture1D(i, 3, typeof(OpenTK.Half));
            var pg3 = _perm.SelectMany(x => new[]
            {
                (float)_grad3[x % 16, 0],
                (float)_grad3[x % 16, 1],
                (float)_grad3[x % 16, 2],
            }).ToArray();

            _permGrad3.Activate();
            GL.TexSubImage1D(TextureTarget.Texture1D, 0, 0, i, PixelFormat.Rgb, PixelType.Float, pg3);
            GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture1D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
        }
コード例 #8
0
ファイル: DebugShader.cs プロジェクト: hach-que/SLSharp
 protected DebugShader()
 {
     _debugTex = Texture2D.FromFile(@"E:\SLSharp\IIS.SLSharp.Examples.GeoClipmap\debug.png");
     Link();
 }