public static GetGLOriginFormat ( PixelFormat fmt ) : OpenTK.Graphics.ES11.All | ||
fmt | PixelFormat | |
Résultat | OpenTK.Graphics.ES11.All |
protected static void BuildMipmaps(PixelBox data) { int width = 0; int height = 0; int logW = 0; int logH = 0; int level = 0; PixelBox scaled = data; scaled.Data = data.Data; scaled.Left = data.Left; scaled.Right = data.Right; scaled.Top = data.Top; scaled.Bottom = data.Bottom; scaled.Front = data.Front; scaled.Back = data.Back; All format = GLESPixelUtil.GetGLOriginFormat(data.Format); All dataType = GLESPixelUtil.GetGLOriginDataType(data.Format); width = data.Width; height = data.Height; logW = ComputeLog(width); logH = ComputeLog(height); level = (logW > logH ? logW : logH); for (int mip = 0; mip <= level; mip++) { format = GLESPixelUtil.GetGLOriginFormat(scaled.Format); dataType = GLESPixelUtil.GetGLOriginDataType(scaled.Format); OpenGL.TexImage2D(All.Texture2D, mip, (int)format, width, height, 0, format, dataType, scaled.Data); GLESConfig.GlCheckError(null); if (mip != 0) { scaled.Data = IntPtr.Zero; } if (width > 1) { width = width / 2; } if (height > 1) { height = height / 2; } int sizeInBytes = PixelUtil.GetMemorySize(width, height, 1, data.Format); scaled = new PixelBox(width, height, 1, data.Format); var dataarr = new byte[sizeInBytes]; scaled.Data = Memory.PinObject(dataarr); Image.Scale(data, scaled, ImageFilter.Linear); } }
/// <summary> /// </summary> /// <param name="src"> </param> /// <param name="dstBox"> </param> public override void BlitFromMemory(PixelBox src, Media.BasicBox dstBox) { if (!this._buffer.Contains(dstBox)) { throw new ArgumentOutOfRangeException("Destination box out of range, GLESHardwarePixelBuffer.BlitToMemory"); } PixelBox scaled; if (src.Width != dstBox.Width || src.Height != dstBox.Height || src.Depth != dstBox.Depth) { LogManager.Instance.Write("[GLESHardwarePixelBuffer] Scale to destination size."); // Scale to destination size. Use DevIL and not iluScale because ILU screws up for // floating point textures and cannot cope with 3D images. // This also does pixel format conversion if needed AllocateBuffer(); scaled = this._buffer.GetSubVolume(dstBox); Image.Scale(src, scaled, ImageFilter.Bilinear); } else if ((src.Format != Format) || ((GLESPixelUtil.GetGLOriginFormat(src.Format) == 0) && (src.Format != PixelFormat.R8G8B8))) { LogManager.Instance.Write("[GLESHardwarePixelBuffer] Extents match, but format is not accepted as valid source format for GL."); LogManager.Instance.Write("[GLESHardwarePixelBuffer] Source.Format = {0}, Format = {1}, GLOriginFormat = {2}", src.Format, Format, GLESPixelUtil.GetGLOriginFormat(src.Format)); // Extents match, but format is not accepted as valid source format for GL // do conversion in temporary buffer AllocateBuffer(); scaled = this._buffer.GetSubVolume(dstBox); PixelConverter.BulkPixelConversion(src, scaled); } else { LogManager.Instance.Write("[GLESHardwarePixelBuffer] No scaling or conversion needed."); scaled = src; if (src.Format == PixelFormat.R8G8B8) { scaled.Format = PixelFormat.R8G8B8; PixelConverter.BulkPixelConversion(src, scaled); } // No scaling or conversion needed // Set extents for upload scaled.Left = dstBox.Left; scaled.Right = dstBox.Right; scaled.Top = dstBox.Top; scaled.Bottom = dstBox.Bottom; scaled.Front = dstBox.Front; scaled.Back = dstBox.Back; } Upload(scaled, dstBox); FreeBuffer(); }
/// <summary> /// </summary> /// <param name="data"> </param> /// <param name="dest"> </param> protected override void Upload(PixelBox data, BasicBox dest) { OpenGL.BindTexture(this._target, this._textureId); GLESConfig.GlCheckError(this); if (PixelUtil.IsCompressed(data.Format)) { if (data.Format != Format || !data.IsConsecutive) { throw new AxiomException("Compressed images must be consecutive, in the source format"); } if (data.Format != Format || !data.IsConsecutive) { throw new AxiomException("Compressed images must be consecutive, in the source format."); } All format = GLESPixelUtil.GetClosestGLInternalFormat(Format); // Data must be consecutive and at beginning of buffer as PixelStorei not allowed // for compressed formats if (dest.Left == 0 && dest.Top == 0) { OpenGL.CompressedTexImage2D(All.Texture2D, this._level, format, dest.Width, dest.Height, 0, data.ConsecutiveSize, data.Data); } else { OpenGL.CompressedTexSubImage2D(All.Texture2D, this._level, dest.Left, dest.Top, dest.Width, dest.Height, format, data.ConsecutiveSize, data.Data); } GLESConfig.GlCheckError(this); } else if (this._softwareMipmap) { if (data.Width != data.RowPitch) { //TODO throw new AxiomException("Unsupported Texture format!"); } if (data.Height * data.Width != data.SlicePitch) { //TODO throw new AxiomException("Unsupported Texture format!"); } OpenGL.PixelStore(All.UnpackAlignment, 1); GLESConfig.GlCheckError(this); BuildMipmaps(data); } else { if (data.Width != data.RowPitch) { //TODO throw new AxiomException("Unsupported Texture format!"); } if (data.Height * data.Width != data.SlicePitch) { //TODO throw new AxiomException("Unsupported Texture format!"); } if (((data.Width * PixelUtil.GetNumElemBytes(data.Format)) & 3) != 0) { // Standard alignment of 4 is not right OpenGL.PixelStore(All.UnpackAlignment, 1); GLESConfig.GlCheckError(this); } All form = GLESPixelUtil.GetGLOriginFormat(data.Format); All pix = GLESPixelUtil.GetGLOriginDataType(data.Format); GLESConfig.GlCheckError(this); GL.TexSubImage2D(this._faceTarget, this._level, dest.Left, dest.Top, dest.Width, dest.Height, GLESPixelUtil.GetGLOriginFormat(data.Format), GLESPixelUtil.GetGLOriginDataType(data.Format), data.Data); GLESConfig.GlCheckError(this); } OpenGL.PixelStore(All.UnpackAlignment, 4); GLESConfig.GlCheckError(this); }
/// <summary> /// </summary> /// <param name="srcBox"> </param> /// <param name="dst"> </param> public override void BlitToMemory(BasicBox srcBox, PixelBox dst) { if (!this._buffer.Contains(srcBox)) { throw new ArgumentOutOfRangeException("source boux out of range"); } if (srcBox.Left == 0 && srcBox.Right == Width && srcBox.Top == 0 && srcBox.Bottom == Height && srcBox.Front == 0 && srcBox.Back == Depth && dst.Width == Width && dst.Height == Height && dst.Depth == Depth && GLESPixelUtil.GetGLOriginFormat(dst.Format) != 0) { // The direct case: the user wants the entire texture in a format supported by GL // so we don't need an intermediate buffer Download(dst); } else { // Use buffer for intermediate copy AllocateBuffer(); //download entire buffer Download(this._buffer); if (srcBox.Width != dst.Width || srcBox.Height != dst.Height || srcBox.Depth != dst.Depth) { // we need scaling Image.Scale(this._buffer.GetSubVolume(srcBox), dst, ImageFilter.Bilinear); } else { // Just copy the bit that we need PixelConverter.BulkPixelConversion(this._buffer.GetSubVolume(srcBox), dst); } FreeBuffer(); } }