예제 #1
0
            /// <summary>
            /// Create the texture, using this technique.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating resources.
            /// </param>
            public override void Create(GraphicsContext ctx)
            {
                int         internalFormat = _PixelFormat.GetGlInternalFormat();
                PixelFormat format         = _PixelFormat.GetGlFormat();

                // Define empty texture
                Gl.TexImage1D(TextureTarget.Texture1d, (int)_Level, internalFormat, (int)_Width, 0, format, /* Unused */ PixelType.UnsignedByte, IntPtr.Zero);
                // Define texture properties
                _Texture1d.DefineExtents(_PixelFormat, _Width, 1, 1, _Level);
            }
예제 #2
0
            /// <summary>
            /// Create the texture, using this technique.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating resources.
            /// </param>
            public override void Create(GraphicsContext ctx)
            {
                InternalFormat internalFormat = _PixelFormat.GetGlInternalFormat();
                PixelFormat    format         = _PixelFormat.GetGlFormat();

                // Define empty texture
                Gl.TexImage2D(_Target, (int)_Level, internalFormat, (int)_Width, (int)_Height, 0, format, /* Unused */ PixelType.UnsignedByte, IntPtr.Zero);
                // Define texture properties
                _Texture2d.SetMipmap(_PixelFormat, _Width, _Height, 1, _Level);
            }
예제 #3
0
            /// <summary>
            /// Create the texture, using this technique.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating resources.
            /// </param>
            public override void Create(GraphicsContext ctx)
            {
                InternalFormat internalFormat = _PixelFormat.GetGlInternalFormat();
                PixelFormat    format         = _PixelFormat.GetGlFormat();
                PixelType      type           = _PixelFormat.GetPixelType();

                for (int i = 0; i < 6; i++)
                {
                    Image image = _Images[i];

                    // Set pixel alignment
                    State.PixelAlignmentState.Unpack(image.Stride).Apply(ctx, null);

                    // Upload texture contents
                    Gl.TexImage2D(_CubeTargets[i], 0, internalFormat, (int)image.Width, (int)image.Height, 0, format, type, image.ImageBuffer);
                }

                // Define texture properties
                _TextureCube.SetMipmap(_PixelFormat, _Images[0].Width, _Images[0].Height, 1, 0);
            }
예제 #4
0
        /// <summary>
        /// Read this GraphicsSurface color buffer.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/>
        /// </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="width">
        /// A <see cref="Int32"/> that specify the width of the rectangle area to read.
        /// </param>
        /// <param name="height">
        /// A <see cref="Int32"/> that specify the height of the rectangle area to read.
        /// </param>
        /// <param name="pType">
        /// A <see cref="PixelLayout"/> which determine the pixel storage of the returned image.
        /// </param>
        /// <returns>
        /// It returns an <see cref="Image"/> representing the current read buffer <paramref name="rBuffer"/>.
        /// </returns>
        protected Image ReadBuffer(GraphicsContext ctx, ReadBufferMode rBuffer, uint x, uint y, uint width, uint height, PixelLayout pType)
        {
            Image image = null;

            if ((x + width > Width) || (y + height > Height))
            {
                throw new ArgumentException("specified region lies outside the GraphicsSurface");
            }

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

            // Allocate image holding data read
            image = new Image();
            image.Create(pType, width, 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;
                }
            }

            // Grab frame buffer pixels
            PixelFormat rFormat = pType.GetGlFormat();
            PixelType   rType   = pType.GetPixelType();

            Gl.ReadPixels((int)x, (int)y, (int)width, (int)height, rFormat, rType, image.ImageBuffer);

            // Unbind from reading
            UnbindRead(ctx);

            return(image);
        }