Axiom.RenderSystems.OpenGL.GLPixelUtil.GetGLOriginDataType C# (CSharp) Метод

GetGLOriginDataType() публичный статический Метод

Takes the Axiom pixel format and returns type that must be provided to GL as data type for reading it into the GPU
public static GetGLOriginDataType ( PixelFormat format ) : int
format PixelFormat
Результат int
		public static int GetGLOriginDataType( PixelFormat format )
		{
			switch ( format )
			{
				case PixelFormat.A8:
				case PixelFormat.L8:
				case PixelFormat.R8G8B8:
				case PixelFormat.B8G8R8:
				case PixelFormat.BYTE_LA:
					return Gl.GL_UNSIGNED_BYTE;
				case PixelFormat.R3G3B2:
					return Gl.GL_UNSIGNED_BYTE_3_3_2;
				case PixelFormat.A1R5G5B5:
					return Gl.GL_UNSIGNED_SHORT_1_5_5_5_REV;
				case PixelFormat.R5G6B5:
				case PixelFormat.B5G6R5:
					return Gl.GL_UNSIGNED_SHORT_5_6_5;
				case PixelFormat.A4R4G4B4:
					return Gl.GL_UNSIGNED_SHORT_4_4_4_4_REV;
				case PixelFormat.L16:
					return Gl.GL_UNSIGNED_SHORT;
#if !LITTLE_ENDIAN
				case PixelFormat.X8B8G8R8:
				case PixelFormat.A8B8G8R8:
					return Gl.GL_UNSIGNED_INT_8_8_8_8_REV;
				case PixelFormat.X8R8G8B8:
				case PixelFormat.A8R8G8B8:
					return Gl.GL_UNSIGNED_INT_8_8_8_8_REV;
				case PixelFormat.B8G8R8A8:
					return Gl.GL_UNSIGNED_BYTE;
				case PixelFormat.R8G8B8A8:
					return Gl.GL_UNSIGNED_BYTE;
#else
			case PixelFormat.X8B8G8R8:
			case PixelFormat.A8B8G8R8:
                return Gl.GL_UNSIGNED_BYTE;
			case PixelFormat.X8R8G8B8:
            case PixelFormat.A8R8G8B8:
				return Gl.GL_UNSIGNED_BYTE;
            case PixelFormat.B8G8R8A8:
                return Gl.GL_UNSIGNED_INT_8_8_8_8;
			case PixelFormat.R8G8B8A8:
				return Gl.GL_UNSIGNED_INT_8_8_8_8;
#endif
				case PixelFormat.A2R10G10B10:
					return Gl.GL_UNSIGNED_INT_2_10_10_10_REV;
				case PixelFormat.A2B10G10R10:
					return Gl.GL_UNSIGNED_INT_2_10_10_10_REV;
				case PixelFormat.FLOAT16_R:
				//case PixelFormat.FLOAT16_GR:
				case PixelFormat.FLOAT16_RGB:
				case PixelFormat.FLOAT16_RGBA:
					return Gl.GL_HALF_FLOAT_ARB;
				case PixelFormat.FLOAT32_R:
				//case PixelFormat.FLOAT32_GR:
				case PixelFormat.FLOAT32_RGB:
				case PixelFormat.FLOAT32_RGBA:
					return Gl.GL_FLOAT;
				case PixelFormat.SHORT_RGBA:
					//case PixelFormat.SHORT_RGB:
					//case PixelFormat.SHORT_GR:
					return Gl.GL_UNSIGNED_SHORT;
				default:
					return 0;
			}
		}

Usage Example

Пример #1
0
        public override void CopyContentsToMemory(PixelBox dst, FrameBuffer buffer)
        {
            if ((dst.Left < 0) || (dst.Right > Width) ||
                (dst.Top < 0) || (dst.Bottom > Height) ||
                (dst.Front != 0) || (dst.Back != 1))
            {
                throw new Exception("Invalid box.");
            }
            if (buffer == RenderTarget.FrameBuffer.Auto)
            {
                buffer = IsFullScreen ? RenderTarget.FrameBuffer.Front : RenderTarget.FrameBuffer.Back;
            }

            int format = GLPixelUtil.GetGLOriginFormat(dst.Format);
            int type   = GLPixelUtil.GetGLOriginDataType(dst.Format);

            if ((format == Gl.GL_NONE) || (type == 0))
            {
                throw new Exception("Unsupported format.");
            }


            // Switch context if different from current one
            RenderSystem rsys = Root.Instance.RenderSystem;

            rsys.Viewport = this.GetViewport(0);

            // Must change the packing to ensure no overruns!
            Gl.glPixelStorei(Gl.GL_PACK_ALIGNMENT, 1);

            Gl.glReadBuffer((buffer == RenderTarget.FrameBuffer.Front) ? Gl.GL_FRONT : Gl.GL_BACK);
            Gl.glReadPixels(dst.Left, dst.Top, dst.Width, dst.Height, format, type, dst.Data);

            // restore default alignment
            Gl.glPixelStorei(Gl.GL_PACK_ALIGNMENT, 4);

            //vertical flip

            {
                int    rowSpan = dst.Width * PixelUtil.GetNumElemBytes(dst.Format);
                int    height  = dst.Height;
                byte[] tmpData = new byte[rowSpan * height];
                unsafe
                {
                    var dataPtr = dst.Data.ToBytePointer();
                    //int *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan;

                    for (int row = height - 1, tmpRow = 0; row >= 0; row--, tmpRow++)
                    {
                        for (int col = 0; col < rowSpan; col++)
                        {
                            tmpData[tmpRow * rowSpan + col] = dataPtr[row * rowSpan + col];
                        }
                    }
                }
                var tmpDataHandle = BufferBase.Wrap(tmpData);
                Memory.Copy(tmpDataHandle, dst.Data, rowSpan * height);
            }
        }
All Usage Examples Of Axiom.RenderSystems.OpenGL.GLPixelUtil::GetGLOriginDataType