示例#1
0
        /// <summary>
        /// Get the closest supported alternative format. If format is supported, returns format.
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public virtual PixelFormat GetSupportedAlternative(PixelFormat format)
        {
            if (CheckFormat(format))
            {
                return(format);
            }
            /// Find first alternative
            PixelComponentType pct = PixelUtil.GetComponentType(format);

            switch (pct)
            {
            case PixelComponentType.Byte:
                format = PixelFormat.A8R8G8B8;
                break;

            case PixelComponentType.Short:
                format = PixelFormat.SHORT_RGBA;
                break;

            case PixelComponentType.Float16:
                format = PixelFormat.FLOAT16_RGBA;
                break;

            case PixelComponentType.Float32:
                format = PixelFormat.FLOAT32_RGBA;
                break;
            }
            if (CheckFormat(format))
            {
                return(format);
            }

            /// If none at all, return to default
            return(PixelFormat.A8R8G8B8);
        }
示例#2
0
        public Pixel(PixelLayout layout, PixelComponentType pType, ColorRGBA color)
        {
            Layout = layout;
            ComponentType = pType;

            SetColor(color);
        }
示例#3
0
        protected virtual void SetupTexture2D(GraphicsInterface gi, int width, int height, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat, PixelComponentType pixelType, IntPtr pixelData, bool createMipMaps)
        {
            fWidth = width;
            fHeight = height;

            fInternalFormat = internalFormat;
            fPixelFormat = pixelFormat;
            fPixelType = pixelType;

            // Setup the alignment
            fGI.PixelStore(PixelStore.UnpackAlignment, 1);

            // Allocate storage for the texture
            // We do this once at the beginning to allocate space for the texture object
            fGI.TexImage2D(0, internalFormat, fWidth, fHeight, 0, pixelFormat, pixelType, pixelData);

            // Setup default filters and wrapping
            SetupFiltering();
            SetupWrapping();

            if (createMipMaps)
            {
                // Make call to generate MipMap
                //fGI.GenerateMipmap();
                
                // Alter the min filter to use the mipmap
                fGI.TexParameter(TextureParameterTarget.Texture2d, TextureParameterName.TextureMinFilter, TextureMinFilter.LinearMipmapLinear);
            }

        }
示例#4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="target"></param>
		/// <param name="writeGamma"></param>
		/// <param name="fsaa"></param>
		public GLESPBRenderTexture( GLESPBRTTManager manager, string name, GLESSurfaceDescription target, bool writeGamma, int fsaa )
			: base( name, target, writeGamma, fsaa )
		{
			this._manager = manager;
			this._pbFormat = PixelUtil.GetComponentType( target.Buffer.Format );
			this._manager.RequestPBuffer( _pbFormat, Width, Height );
		}
示例#5
0
        protected PixelAccessor(int width, int height, PixelLayout layout, PixelComponentType pType, PixmapOrientation orientation,
            IntPtr pixelPointer)
        {
            PixRectInfo = new PixelRectangleInfo(width, height, layout, pType, orientation, 1);

            fPixelPointer = pixelPointer;
        }
示例#6
0
 /// <summary>
 /// </summary>
 /// <param name="name"> </param>
 /// <param name="target"> </param>
 /// <param name="writeGamma"> </param>
 /// <param name="fsaa"> </param>
 public GLESPBRenderTexture(GLESPBRTTManager manager, string name, GLESSurfaceDescription target, bool writeGamma, int fsaa)
     : base(name, target, writeGamma, fsaa)
 {
     this._manager  = manager;
     this._pbFormat = PixelUtil.GetComponentType(target.Buffer.Format);
     this._manager.RequestPBuffer(this._pbFormat, Width, Height);
 }
示例#7
0
 /// <summary>
 /// Release PBuffer for a certain pixel format
 /// </summary>
 /// <param name="pcType"></param>
 public void ReleasePBuffer(PixelComponentType pcType)
 {
     --this.pBuffers[(int)pcType].InUseCount;
     if (this.pBuffers[(int)pcType].InUseCount == 0)
     {
         this.pBuffers[(int)pcType].PixelBuffer = null;
     }
 }
示例#8
0
		public void ReleasePBuffer( PixelComponentType ctype )
		{
			--this._pixelBuffers[ (int) ctype ].ReferenceCount;
			if ( this._pixelBuffers[ (int) ctype ].ReferenceCount == 0 )
			{
				//_pixelBuffers[ (int)ctype ].Buffer.Dispose();
				this._pixelBuffers[ (int) ctype ].Buffer = null;
			}
		}
示例#9
0
 public void ReleasePBuffer(PixelComponentType ctype)
 {
     --this._pixelBuffers[(int)ctype].ReferenceCount;
     if (this._pixelBuffers[(int)ctype].ReferenceCount == 0)
     {
         //_pixelBuffers[ (int)ctype ].Buffer.Dispose();
         this._pixelBuffers[(int)ctype].Buffer = null;
     }
 }
示例#10
0
        public static PixelComponentType getComponentType(PixelFormat fmt)
        {
            PixelComponentType ret = (PixelComponentType)OgrePINVOKE.PixelUtil_getComponentType((int)fmt);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#11
0
 public PixelRectangleInfo(int width, int height, PixelLayout layout, PixelComponentType compType, PixmapOrientation orient, int alignment)
 {
     Width = width;
     Height = height;
     Layout = layout;
     ComponentType = compType;
     Orientation = orient;
     Alignment = alignment;
     BytesPerRow = GetBytesPerRow();
 }
示例#12
0
        public Pixel(PixelLayout layout, PixelComponentType pType, byte[] data, int startIndex)
        {
            Layout = layout;
            ComponentType = pType;

            int pixelLength = PixelInformation.GetBytesPerPixel(layout, pType); 

            // Allocate some space to hold the pixel data
            Data = new byte[pixelLength];

            // Copy the pixel data into the new space
            Array.Copy(data, startIndex, Data, 0, pixelLength);
        }
示例#13
0
 /// <summary>
 /// Get GL rendering context for a certain component type and size.
 /// </summary>
 /// <param name="pcType"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <returns></returns>
 public GLContext GetContextFor(PixelComponentType pcType, int width, int height)
 {
     // Faster to return main context if the RTT is smaller than the window size
     // and pcType is PixelComponentType.Byte. This must be checked every time because the window might have been resized
     if (pcType == PixelComponentType.Byte)
     {
         if (width <= this._mainWindow.Width && height <= this._mainWindow.Height)
         {
             return(this._mainGLContext);
         }
     }
     Debug.Assert(this.pBuffers[(int)pcType].PixelBuffer != null);
     return(this.pBuffers[(int)pcType].PixelBuffer.Context);
 }
示例#14
0
		public void RequestPBuffer( PixelComponentType ctype, int width, int height )
		{
			PBRef current = this._pixelBuffers[ (int) ctype ];
			// Check size
			if ( current.Buffer != null )
			{
				if ( current.Buffer.Width < width || current.Buffer.Height < height )
				{
					// If the current PBuffer is too small, destroy it and create a new one					
					//current.Buffer.Dispose();
					current.Buffer = null;
				}
			}

			if ( current.Buffer == null )
			{
				// Create pbuffer via rendersystem
				current.Buffer = this._support.CreatePixelBuffer( ctype, width, height );
			}
			++current.ReferenceCount;
			this._pixelBuffers[ (int) ctype ] = current;
		}
示例#15
0
        /// <summary>
        /// Create PBuffer for a certain pixel format and size
        /// </summary>
        /// <param name="pcType"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void RequestPBuffer(PixelComponentType pcType, int width, int height)
        {
            // Check Size
            GLPBuffer pBuffer = this.pBuffers[(int)pcType].PixelBuffer;

            if (pBuffer != null)
            {
                if (pBuffer.Width < width || pBuffer.Height < height)
                {
                    // if the current buffer is too small destroy it and recreate it
                    pBuffer = null;
                    this.pBuffers[(int)pcType].PixelBuffer = null;
                }
            }

            if (pBuffer == null)
            {
                // create pixelbuffer via rendersystem
                this.pBuffers[(int)pcType].PixelBuffer = this._glSupport.CreatePBuffer(pcType, width, height);
            }
            this.pBuffers[(int)pcType].InUseCount++;
        }
示例#16
0
        public void RequestPBuffer(PixelComponentType ctype, int width, int height)
        {
            PBRef current = this._pixelBuffers[(int)ctype];

            // Check size
            if (current.Buffer != null)
            {
                if (current.Buffer.Width < width || current.Buffer.Height < height)
                {
                    // If the current PBuffer is too small, destroy it and create a new one
                    //current.Buffer.Dispose();
                    current.Buffer = null;
                }
            }

            if (current.Buffer == null)
            {
                // Create pbuffer via rendersystem
                current.Buffer = this._support.CreatePixelBuffer(ctype, width, height);
            }
            ++current.ReferenceCount;
            this._pixelBuffers[(int)ctype] = current;
        }
 public PixelFormatDescription(string name,
                               PixelFormat format,
                               byte elemBytes,
                               PixelFormatFlags flags,
                               PixelComponentType componentType,
                               byte componentCount,
                               byte rbits,
                               byte gbits,
                               byte bbits,
                               byte abits,
                               uint rmask,
                               uint gmask,
                               uint bmask,
                               uint amask,
                               byte rshift,
                               byte gshift,
                               byte bshift,
                               byte ashift)
 {
     this.name           = name;
     this.format         = format;
     this.elemBytes      = elemBytes;
     this.flags          = flags;
     this.componentType  = componentType;
     this.componentCount = componentCount;
     this.rbits          = rbits;
     this.gbits          = gbits;
     this.bbits          = bbits;
     this.abits          = abits;
     this.rmask          = rmask;
     this.gmask          = gmask;
     this.bmask          = bmask;
     this.amask          = amask;
     this.rshift         = rshift;
     this.gshift         = gshift;
     this.bshift         = bshift;
 }
示例#18
0
			public PixelFormatDescription( string name, PixelFormat format, byte elemBytes, PixelFormatFlags flags,
			                               PixelComponentType componentType, byte componentCount, byte rbits, byte gbits,
			                               byte bbits, byte abits, uint rmask, uint gmask, uint bmask, uint amask, byte rshift,
			                               byte gshift, byte bshift, byte ashift )
			{
				this.name = name;
				this.format = format;
				this.elemBytes = elemBytes;
				this.flags = flags;
				this.componentType = componentType;
				this.componentCount = componentCount;
				this.rbits = rbits;
				this.gbits = gbits;
				this.bbits = bbits;
				this.abits = abits;
				this.rmask = rmask;
				this.gmask = gmask;
				this.bmask = bmask;
				this.amask = amask;
				this.rshift = rshift;
				this.gshift = gshift;
				this.bshift = bshift;
				this.ashift = ashift;
			}
示例#19
0
		/// <summary>
		/// Release PBuffer for a certain pixel format
		/// </summary>
		/// <param name="pcType"></param>
		public void ReleasePBuffer( PixelComponentType pcType )
		{
			--pBuffers[ (int)pcType ].InUseCount;
			if ( pBuffers[ (int)pcType ].InUseCount == 0 )
			{
				pBuffers[ (int)pcType ].PixelBuffer = null;
			}
		}
示例#20
0
		/// <summary>
		/// Get GL rendering context for a certain component type and size.
		/// </summary>
		/// <param name="pcType"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <returns></returns>
		public GLContext GetContextFor( PixelComponentType pcType, int width, int height )
		{
			// Faster to return main context if the RTT is smaller than the window size
			// and pcType is PixelComponentType.Byte. This must be checked every time because the window might have been resized
			if ( pcType == PixelComponentType.Byte )
			{
				if ( width <= this._mainWindow.Width && height <= this._mainWindow.Height )
					return this._mainGLContext;
			}
			Debug.Assert( pBuffers[ (int)pcType ].PixelBuffer != null );
			return pBuffers[ (int)pcType ].PixelBuffer.Context;
		}
示例#21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="format"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public GLPBuffer(PixelComponentType format, int width, int height)
 {
 }
示例#22
0
		/// <summary>
		/// Create PBuffer for a certain pixel format and size
		/// </summary>
		/// <param name="pcType"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		public void RequestPBuffer( PixelComponentType pcType, int width, int height )
		{
			// Check Size
			GLPBuffer pBuffer = pBuffers[ (int)pcType ].PixelBuffer;
			if ( pBuffer != null )
			{
				if ( pBuffer.Width < width || pBuffer.Height < height )
				{
					// if the current buffer is too small destroy it and recreate it
					pBuffer = null;
					pBuffers[ (int)pcType ].PixelBuffer = null;
				}
			}

			if ( pBuffer == null )
			{
				// create pixelbuffer via rendersystem
				pBuffers[ (int)pcType ].PixelBuffer = this._glSupport.CreatePBuffer( pcType, width, height );
			}
			pBuffers[ (int)pcType ].InUseCount++;
		}
示例#23
0
文件: GL.cs 项目: Wiladams/NewTOAPIA
 public static void TexImage1D(int level, TextureInternalFormat internalformat, int width, int border, TexturePixelFormat format, PixelComponentType type, IntPtr pixels)
 {
     gl.glTexImage1D((int)Texture1DTarget.Texture1d, level, (int)internalformat, width, border, (int)format, (int)type, pixels);
 }
示例#24
0
 public PixelRectangleInfo(int width, int height, PixelLayout layout, PixelComponentType compType, int alignment)
     : this(width, height, layout, compType, PixmapOrientation.TopToBottom, alignment)
 {
 }
示例#25
0
 public void TexSubImage2D(Texture2DTarget target, int level, int xoffset, int yoffset, int width, int height, TexturePixelFormat format, PixelComponentType type, byte[] pixels)
 {
     gl.glTexSubImage2D((int)target, level, xoffset, yoffset, width, height, (int)format, (int)type, pixels);
 }
示例#26
0
 public void TexSubImage1D(int level, int xoffset, int width, TexturePixelFormat format, PixelComponentType type, object[] pixels)
 {
     gl.glTexSubImage1D((int)Texture1DTarget.Texture1d, level, xoffset, width, (int)format, (int)type, pixels);
 }
示例#27
0
 internal void DrawPixels(int width, int height, PixelLayout format, PixelComponentType type, float[] pixels)
 {
     gl.glDrawPixels(width, height, (int)format, (int)type, pixels);
     CheckException();
 }
示例#28
0
 internal void ReadPixels(int x, int y, int width, int height, PixelLayout format, PixelComponentType type, byte[] pixels)
 {
     gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
     CheckException();
 }
示例#29
0
        //internal void DrawPixels(GLPixelRectangleInfo pixelRect)
        //{
        //    if (pixelRect.BufferObject == null)
        //        return ;

        //    IntPtr mappedPtr = pixelRect.BufferObject.MapBuffer(BufferAccess.ReadOnly);

        //    if (mappedPtr == null)
        //        return ;

        //    DrawPixels(pixelRect.Width, pixelRect.Height, pixelRect.PixelFormat, pixelRect.PixelType, mappedPtr);

        //    pixelRect.BufferObject.UnmapBuffer();
        //}

        //public void DrawPixels(int x, int y, GLPixelRectangleInfo pixelRect)
        //{
        //    RasterPos2i(x, y);
        //    DrawPixels(pixelRect);
        //}

        public void DrawPixels(int width, int height, PixelLayout format, PixelComponentType type, IntPtr pixels)
        {
            gl.glDrawPixels(width, height, (int)format, (int)type, pixels);
            CheckException();
        }
示例#30
0
 /// <summary>
 ///   Default ctor.
 /// </summary>
 /// <param name="format"> </param>
 /// <param name="width"> </param>
 /// <param name="height"> </param>
 public GLESPBuffer(PixelComponentType format, int width, int height)
 {
     Format = format;
     Width  = width;
     Height = height;
 }
示例#31
0
文件: GL.cs 项目: Wiladams/NewTOAPIA
 public static void DrawPixels(int width, int height, PixelLayout format, PixelComponentType type, float[] pixels)
 {
     gl.glDrawPixels(width, height, (int)format, (int)type, pixels);
 }
示例#32
0
 public void TexImage1D(Texture1DTarget target, int level, TextureInternalFormat internalformat, int width, int border, TexturePixelFormat format, PixelComponentType type, object pixels)
 {
     gl.glTexImage1D((int)target, level, (int)internalformat, width, border, (int)format, (int)type, pixels);
 }
示例#33
0
        public override bool IsHardwareFilteringSupported(TextureType ttype, PixelFormat format, TextureUsage usage,
                                                          bool preciseFormatOnly)
#endif
        {
            if (format == PixelFormat.Unknown)
            {
                return(false);
            }

            // Check natively format
            PixelFormat nativeFormat = GetNativeFormat(ttype, format, usage);

            if (preciseFormatOnly && format != nativeFormat)
            {
                return(false);
            }

            // Assume non-floating point is supported always
            if (!PixelUtil.IsFloatingPoint(nativeFormat))
            {
                return(true);
            }

            // Hack: there are no elegant GL API to detects texture filtering supported,
            // just hard code for cards based on vendor specifications.

            // TODO: Add cards that 16 bits floating point flitering supported by
            // hardware below
            String[] sFloat16SupportedCards =
            {
                // GeForce 8 Series
                "*GeForce*8800*",                   // GeForce 7 Series
                "*GeForce*7950*", "*GeForce*7900*", "*GeForce*7800*", "*GeForce*7600*",
                "*GeForce*7500*", "*GeForce*7300*", // GeForce 6 Series
                "*GeForce*6800*", "*GeForce*6700*", "*GeForce*6600*", "*GeForce*6500*",
                "*GeForce*6200*", ""                // Empty string means end of list
            };

            // TODO: Add cards that 32 bits floating point flitering supported by
            // hardware below
            String[] sFloat32SupportedCards =
            {
                // GeForce 8 Series
                "*GeForce*8800*", ""                                                                                 // Empty string means end of list
            };

            PixelComponentType pct = PixelUtil.GetComponentType(nativeFormat);

            String[] supportedCards;
            switch (pct)
            {
            case PixelComponentType.Float16:
                supportedCards = sFloat16SupportedCards;
                break;

            case PixelComponentType.Float32:
                supportedCards = sFloat32SupportedCards;
                break;

            default:
                return(false);
            }
            String pcRenderer = Gl.glGetString(Gl.GL_RENDERER);               // TAO 2.0

            //String pcRenderer = Marshal.PtrToStringAnsi( Gl.glGetString( Gl.GL_RENDERER ) );

            foreach (String str in supportedCards)
            {
                if (str == pcRenderer)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#34
0
 public void TexImage2D(Texture2DTarget target, int level, TextureInternalFormat internalformat, int width, int height, int border, TexturePixelFormat format, PixelComponentType type, object pixels)
 {
     gl.glTexImage2D((int)target, level, (int)internalformat, width, height, border, (int)format, (int)type, pixels);
     CheckException();
 }
示例#35
0
 public static ColorRGBA GetColor(PixelLayout layout, PixelComponentType pType, byte[] data)
 {
     return GetColor(layout, pType, data, 0);
 }
示例#36
0
        public void TexSubImage2D(Texture2DTarget target, int level, int xoffset, int yoffset, int width, int height, TexturePixelFormat format, PixelComponentType type, IntPtr pixels)
        {
            if (null == pixels || pixels == IntPtr.Zero)
                return;

            gl.glTexSubImage2D((int)target, level, xoffset, yoffset, width, height, (int)format, (int)type, pixels);
        }
示例#37
0
文件: GL.cs 项目: Wiladams/NewTOAPIA
 public static void glReadPixels(int x, int y, int width, int height, PixelLayout format, PixelComponentType type, float[] pixels)
 {
     gl.glReadPixels(x, y, width, height, (int)format, (int)type, pixels);
 }
示例#38
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="format"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		public GLPBuffer( PixelComponentType format, int width, int height )
		{
		}
示例#39
0
 public virtual GLPBuffer CreatePBuffer(PixelComponentType format, int width, int height)
 {
     return(null);
 }
示例#40
0
 public GLTexture2D(GraphicsInterface gi, int width, int height, TextureInternalFormat internalFormat, TexturePixelFormat pixelFormat, PixelComponentType pixelType, IntPtr pixelData, bool createMipMaps)
     : base(gi, TextureBindTarget.Texture2d)
 {
     SetupTexture2D(gi, width, height, internalFormat, pixelFormat, pixelType, pixelData, createMipMaps);
 }
示例#41
0
        public static ColorRGBA GetColor(PixelLayout layout, PixelComponentType pType, byte[] data, int startIndex)
        {
            int bytesPerPixel = PixelInformation.GetBytesPerPixel(layout, pType);

            // how many components are there?
            int nComponents = PixelInformation.GetComponentsPerLayout(layout);
            int componentSize = PixelInformation.GetBytesPerComponent(pType);
            double maxValue = PixelInformation.GetMaxComponentValue(pType);

            float[] floats = new float[nComponents];

            for (int component = 0; component < nComponents; component++)
            {
                float afloat = 0f;

                switch (pType)
                {
                    case PixelComponentType.Byte:
                    case PixelComponentType.UnsignedByte:
                        afloat = (float)(data[startIndex+component * componentSize] / maxValue);
                        break;

                    case PixelComponentType.Short:
                        afloat = (float)(BitConverter.ToInt16(data, startIndex + component * componentSize) / maxValue);
                        break;

                    case PixelComponentType.Int:
                        afloat = (float)(BitConverter.ToInt32(data, startIndex + component * componentSize) / maxValue);
                        break;

                    case PixelComponentType.Float:
                        afloat = (float)(BitConverter.ToSingle(data, startIndex + component * componentSize) / maxValue);
                        break;

                    case PixelComponentType.Double:
                        afloat = (float)(BitConverter.ToDouble(data, startIndex + component * componentSize) / maxValue);
                        break;
                }

                floats[component] = afloat;
            }

            ColorRGBA newColor = new ColorRGBA(floats);

            return newColor;
        }
示例#42
0
		public virtual GLPBuffer CreatePBuffer( PixelComponentType format, int width, int height )
		{
			return null;
		}
示例#43
0
 public static int GetAlignedRowStride(int width, PixelLayout format, PixelComponentType pType, int alignment)
 {
     return GetAlignedRowStride(width, PixelInformation.GetBitsPerPixel(format, pType), alignment);
 }