From: Latif Khalifa Date: Mon, 11 Jul 2011 05:05:02 +0000 (+0000) Subject: Determine more info about image alpha channel. Don't render faces with fully transpar... X-Git-Tag: 2.8~401 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d72173770ca51fa36d178eb4ca73486a9f049113;p=radegast%2Fradegast.git Determine more info about image alpha channel. Don't render faces with fully transparent textures. git-svn-id: https://radegast.googlecode.com/svn/trunk@970 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- diff --git a/Radegast/GUI/Rendering/Rendering.cs b/Radegast/GUI/Rendering/Rendering.cs index 1b1abff..f6d8fcb 100644 --- a/Radegast/GUI/Rendering/Rendering.cs +++ b/Radegast/GUI/Rendering/Rendering.cs @@ -76,7 +76,7 @@ namespace Radegast.Rendering /// /// Object from up to this distance from us will be rendered /// - public float DrawDistance = 96f; + public float DrawDistance = 48f; /// /// List of prims in the scene @@ -804,20 +804,49 @@ namespace Radegast.Rendering { ManagedImage mi; Image img; - if (!OpenJPEG.DecodeToImage(item.TextureData, out mi, out img)) continue; - Bitmap bitmap = (Bitmap)img; - - bool hasAlpha; - if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) + if (!OpenJPEG.DecodeToImage(item.TextureData, out mi)) continue; + + bool hasAlpha = false; + bool fullAlpha = false; + bool isMask = false; + if ((mi.Channels & ManagedImage.ImageChannels.Alpha) != 0) { - hasAlpha = true; + fullAlpha = true; + isMask = true; + + // Do we really have alpha, is it all full alpha, or is it a mask + for (int i = 0; i < mi.Alpha.Length; i++) + { + if (mi.Alpha[i] < 255) + { + hasAlpha = true; + } + if (mi.Alpha[i] != 0) + { + fullAlpha = false; + } + if (mi.Alpha[i] != 0 && mi.Alpha[i] != 255) + { + isMask = false; + } + } + + if (!hasAlpha) + { + mi.ConvertChannels(mi.Channels & ~ManagedImage.ImageChannels.Alpha); + } } - else + + using (MemoryStream byteData = new MemoryStream(mi.ExportTGA())) { - hasAlpha = false; + img = OpenMetaverse.Imaging.LoadTGAClass.LoadTGA(byteData); } + + Bitmap bitmap = (Bitmap)img; item.Data.TextureInfo.HasAlpha = hasAlpha; + item.Data.TextureInfo.FullAlpha = fullAlpha; + item.Data.TextureInfo.IsMask = isMask; bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); item.Data.TextureInfo.TexturePointer = GLLoadImage(bitmap, hasAlpha); bitmap.Dispose(); @@ -1824,13 +1853,16 @@ namespace Radegast.Rendering Primitive.TextureEntryFace teFace = mesh.Prim.Textures.FaceTextures[j]; Face face = mesh.Faces[j]; FaceData data = (FaceData)mesh.Faces[j].UserData; - + if (teFace == null) teFace = mesh.Prim.Textures.DefaultTexture; if (teFace == null) continue; + // Don't render transparent faces + if (data.TextureInfo.FullAlpha || teFace.RGBA.A <= 0.01f) continue; + int lightsEnabled; GL.GetInteger(GetPName.Lighting, out lightsEnabled); @@ -1841,9 +1873,6 @@ namespace Radegast.Rendering if (belongToAlphaPass && pass != RenderPass.Alpha) continue; if (!belongToAlphaPass && pass == RenderPass.Alpha) continue; - // Don't render transparent faces - if (teFace.RGBA.A <= 0.01f) continue; - if (teFace.Fullbright && lightsEnabled != 0) { GL.Disable(EnableCap.Lighting); diff --git a/Radegast/GUI/Rendering/RenderingHelpers.cs b/Radegast/GUI/Rendering/RenderingHelpers.cs index 7529a2e..d085f1b 100644 --- a/Radegast/GUI/Rendering/RenderingHelpers.cs +++ b/Radegast/GUI/Rendering/RenderingHelpers.cs @@ -263,6 +263,8 @@ namespace Radegast.Rendering public System.Drawing.Image Texture; public int TexturePointer; public bool HasAlpha; + public bool FullAlpha; + public bool IsMask; public UUID TextureID; }