Beispiel #1
0
 /// <summary>
 /// Create the resource of this attachment.
 /// </summary>
 /// <param name="ctx">
 /// A <see cref="GraphicsContext"/> used for creating this attachment.
 /// </param>
 public override void Create(GraphicsContext ctx)
 {
     if (!Texture.Exists(ctx))
     {
         Texture.Create(ctx);
     }
 }
        /// <summary>
        /// Copy this GraphicsSurface color buffer into a buffer.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> which is bound to this GraphicsSurface.
        /// </param>
        /// <param name="rBuffer">
        /// A <see cref="ReadBufferMode"/> that specify the read buffer where the colors are read from.
        /// </param>
        /// <param name="x">
        /// A <see cref="Int32"/> that specify the x coordinate of the lower left corder of the rectangle area to read.
        /// </param>
        /// <param name="y">
        /// A <see cref="Int32"/> that specify the y coordinate of the lower left corder of the rectangle area to read.
        /// </param>
        /// <param name="texture">
        /// A <see cref="Texture"/> that will hold the buffer data.
        /// </param>
        /// <param name="level">
        /// The level of the texture <paramref name="texture"/> to be written.
        /// </param>
        /// <returns>
        /// It returns an <see cref="Image"/> representing the current read buffer <paramref name="rBuffer"/>.
        /// </returns>
        protected void CopyBuffer(GraphicsContext ctx, ReadBufferMode rBuffer, uint x, uint y, ref Texture texture, uint level)
        {
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }
            if (texture.Exists(ctx) == false)
            {
                throw new ArgumentException("not exists", "texture");
            }
            if ((x + texture.Width > Width) || (y + texture.Height > Height))
            {
                throw new ArgumentException("specified region lies outside the GraphicsSurface");
            }

            // Bind for reading
            BindRead(ctx);
            // Set for reading
            Gl.ReadBuffer(rBuffer);

            // Copy pixels from read buffer to texture
            Gl.CopyTexImage2D(texture.TextureTarget, (int)level, texture.PixelLayout.GetGlInternalFormat(), (int)x, (int)y, (int)texture.Width, (int)texture.Height, 0);

            // Unbind from reading
            UnbindRead(ctx);
            // Reset read configuration
            Gl.ReadBuffer(Gl.NONE);
        }