/// <summary>
        /// Binds the array buffer attached to.
        /// </summary>
        /// <param name='index'>
        /// Index.
        /// </param>
        /// <exception cref='InvalidOperationException'>
        /// Is thrown when an operation cannot be performed.
        /// </exception>
        public void End(GraphicsContext ctx)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            // Start queries
            _PrimitivesGenerated.End(ctx);
            _PrimitivesWritten.End(ctx);

            _PrimitivesGenerated.GetResult(ctx, out mPrimitivesGeneratedCached);
            _PrimitivesWritten.GetResult(ctx, out mPrimitivesWrittenCached);

            // End tranform feedback
            Gl.EndTransformFeedback();

            // Enable rasterizer?
            if (EnableRasterizer == false)
            {
                Gl.Disable(EnableCap.RasterizerDiscard);
            }

            // This feedback buffer is not current anymore
            ctx.Unbind(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Actually create this GraphicsResource resources.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for allocating resources.
        /// </param>
        protected override void CreateObject(GraphicsContext ctx)
        {
            CheckCurrentContext(ctx);

            // Bind this texture
            Gl.BindTexture(TextureTarget, ObjectName);
            ctx.Bind(this);

            // In the case of no technique, texture will exists but it will be undefined

            if (_Technique != null)
            {
                // Create texture using technique
                _Technique.Create(ctx);
                // Technique no more useful: dispose it
                _Technique.Dispose();
                _Technique = null;

                // Generate mipmaps, if requested
                if (_RequiresMipMaps)
                {
                    GenerateMipmaps(ctx);
                }
            }

            // Clear binding point
            ctx.Unbind(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate mipmaps for this Texture, replacing mipmaps level from 1 to <see cref="MipmapLevels"/> - 1.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for mipmapping definition.
        /// </param>
        /// <param name="target">
        /// A <see cref="TextureTarget"/> indicating the target for generating
        /// bitmaps.
        /// </param>
        protected void GenerateMipmaps(GraphicsContext ctx, TextureTarget target)
        {
            // Bind this Texture
            ctx.Bind(this);
            // Generate mipmaps
            Gl.GenerateMipmap((int)target);
            // Unbind this texture
            ctx.Unbind(this);

            // Now texture has mipmaps
            _HasMipMaps = true;
        }
Esempio n. 4
0
        /// <summary>
        /// Generate mipmaps for this Texture, replacing mipmaps level from 1 to <see cref="MipmapLevels"/> - 1.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for mipmapping definition.
        /// </param>
        /// <param name="target">
        /// A <see cref="TextureTarget"/> indicating the target for generating
        /// bitmaps.
        /// </param>
        protected void GenerateMipmaps(GraphicsContext ctx, TextureTarget target)
        {
            CheckCurrentContext(ctx);

            // Bind this Texture
            ctx.Bind(this);
            // Generate mipmaps
            Gl.GenerateMipmap((int)target);
            // Unbind this texture
            ctx.Unbind(this);

            Debug.Assert(_Mipmaps.Length >= MipmapLevels);
            for (uint i = MipmapBaseLevel + 1; i < MipmapLevels; i++)
            {
                if (_Mipmaps[i] == null)
                {
                    _Mipmaps[i] = new Mipmap();
                }
                _Mipmaps[i].InternalFormat = _Mipmaps[MipmapBaseLevel].InternalFormat;
                _Mipmaps[i].Size           = GetMipmapSize(i);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Download Texture data to an Image instance.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for downloading texture data.
        /// </param>
        /// <param name="pixelType">
        /// A <see cref="OpenGL.PixelLayout"/> determining the pixel format of the downloaded data.
        /// </param>
        /// <param name="target">
        /// A <see cref="TextureTarget"/> that specify the texture target.
        /// </param>
        /// <param name="level">
        /// A <see cref="UInt32"/> that specify the texture level.
        /// </param>
        /// <returns>
        /// It return the <see cref="Image"/> holding the content of this texture.
        /// </returns>
        protected Image Get(GraphicsContext ctx, PixelLayout pixelType, TextureTarget target, uint level)
        {
            CheckCurrentContext(ctx);

            // Bind this Texture
            ctx.Bind(this);

            // Get texture extents
            int width, height;

            Gl.GetTexLevelParameter(TextureTarget, (int)level, GetTextureParameter.TextureWidth, out width);
            Gl.GetTexLevelParameter(TextureTarget, (int)level, GetTextureParameter.TextureHeight, out height);
            if ((width <= 0) || (height <= 0))
            {
                throw new InvalidOperationException(String.Format("invalid texture extents {0}x{1}", width, height));
            }

            // Create image
            Image image = new Image(pixelType, (uint)width, (uint)height);

            // Set pixel transfer
            foreach (int alignment in new int[] { 8, 4, 2, 1 })
            {
                if (image.Stride % alignment == 0)
                {
                    Gl.PixelStore(PixelStoreParameter.PackAlignment, alignment);
                    break;
                }
            }

            // Download texture contents
            Gl.GetTexImage(target, (int)level, Pixel.GetGlFormat(pixelType), Pixel.GetPixelType(pixelType), image.ImageBuffer);

            // Unbind this texture
            ctx.Unbind(this);

            return(image);
        }
Esempio n. 6
0
        /// <summary>
        /// Actually create this GraphicsResource resources.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for allocating resources.
        /// </param>
        protected override void CreateObject(GraphicsContext ctx)
        {
            CheckCurrentContext(ctx);

            // Let create this texture
            Gl.BindTexture(TextureTarget, ObjectName);
            // Bind this texture
            ctx.Bind(this);

            // In the case of no techniques, texture will exists but it will be undefined

            if (_Techniques.Count > 0)
            {
                foreach (Technique technique in _Techniques)
                {
                    // Create/update texture using technique
                    technique.Create(ctx);
                    // Technique no more useful: dispose it
                    if (_TechniquesAutoRelease)
                    {
                        technique.Dispose();
                    }
                }
                if (_TechniquesAutoRelease)
                {
                    _Techniques.Clear();
                }

                // Generate mipmaps, if requested
                if (_RequiresMipMaps)
                {
                    GenerateMipmaps(ctx);
                }
            }

            // Clear binding point
            ctx.Unbind(this);
        }