Esempio n. 1
0
        /// <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, Pixel.GetGlInternalFormat(texture.PixelLayout, ctx), (int)x, (int)y, (int)texture.Width, (int)texture.Height, 0);

            // Unbind from reading
            UnbindRead(ctx);
            // Reset read configuration
            Gl.ReadBuffer(Gl.NONE);
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
		/// <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, Pixel.GetGlInternalFormat(texture.PixelLayout, ctx), (int)x, (int)y, (int)texture.Width, (int)texture.Height, 0);

			// Unbind from reading
			UnbindRead(ctx);
			// Reset read configuration
			Gl.ReadBuffer(Gl.NONE);
		}
		/// <summary>
		/// Set uniform state variable (sampler1D, sampler2D, sampler3D, samplerCube variable).
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for operations.
		/// </param>
		/// <param name="uniformName">
		/// A <see cref="String"/> that specify the variable name in the shader source.
		/// </param>
		/// <param name="tex">
		/// A <see cref="Texture"/> holding the uniform variabile data (the texture name).
		/// </param>
		/// <param name="texUnit">
		/// A <see cref="Int32"/> that specify the texture unit processing the texture <paramref name="tex"/>.
		/// </param>
		public void SetUniform(GraphicsContext ctx, string uniformName, Texture tex, uint texUnit)
		{
			if (ctx == null)
				throw new ArgumentNullException("ctx");

			UniformBinding uniform = GetUniform(uniformName);

			if (tex == null)
				throw new ArgumentNullException("tex");
			if (tex.Exists(ctx) == false)
				throw new ArgumentException("not exists", "tex");

			CheckProgramBinding();
			CheckUniformType(uniform, tex.SamplerType);

			// Activate texture unit
			Gl.ActiveTexture(Gl.TEXTURE0 + (int)texUnit);
			// Bind texture (on active texture unit)
			tex.Bind(ctx);
			// Apply texture parameters
			tex.ApplyParameters(ctx);

			// Set uniform value (sampler)
			// Cast to Int32 since the sampler type can be set only with glUniform2i
			Gl.Uniform1(uniform.Location, (int)texUnit);

			// Validate program
			Validate();
		}