// unused public void DrawOld_B(VertexPositionColorTexture[] vertexData, int numVertices) { for (int i = 0; i < numVertices; i++) { XnaToUnity.Vector3(vertexData[i].Position, ref Vertices[i]); XnaToUnity.Vector2(vertexData[i].TextureCoordinate, ref UVs[i]); UVs[i].y = 1 - UVs[i].y; XnaToUnity.Color(vertexData[i].Color, ref Colors[i]); } Array.Clear(Vertices, numVertices, Vertices.Length - numVertices); DrawFunction(this); }
private void PlatformSetData <T>(int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct { UnityEngine.Color[] unityData = new UnityEngine.Color[data.Length]; Color[] xnaData = (Color[])(object)data; XnaToUnity.Color(xnaData, ref unityData); if (rect.HasValue) { UnityTexture2D.SetPixels(rect.Value.X, UnityTexture2D.height - rect.Value.Y - rect.Value.Height, rect.Value.Width, rect.Value.Height, unityData); } else { UnityTexture2D.SetPixels(unityData); } UnityTexture2D.Apply(); }
/// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> internal override bool OnApply() { // Recompute the world+view+projection matrix or fog vector? dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, ref worldViewProj); if (texture != null) { device.Textures[0] = texture; } if (dirtyFlags != 0) { XnaToUnity.Matrix(worldViewProj, out worldViewProj_Property.Value); worldViewProj_Property.Value.m23 = 0; worldViewProj_Property.ApplyToMaterial(material); } return(false); }
protected internal override Texture2D Read(ContentReader reader, Texture2D existingInstance) { Texture2D texture = null; SurfaceFormat surfaceFormat; if (reader.version < 5) { SurfaceFormatLegacy legacyFormat = (SurfaceFormatLegacy)reader.ReadInt32(); switch (legacyFormat) { case SurfaceFormatLegacy.Dxt1: surfaceFormat = SurfaceFormat.Dxt1; break; case SurfaceFormatLegacy.Dxt3: surfaceFormat = SurfaceFormat.Dxt3; break; case SurfaceFormatLegacy.Dxt5: surfaceFormat = SurfaceFormat.Dxt5; break; case SurfaceFormatLegacy.Color: surfaceFormat = SurfaceFormat.Color; break; default: throw new NotSupportedException("Unsupported legacy surface format."); } } else { surfaceFormat = (SurfaceFormat)reader.ReadInt32(); } int width = (reader.ReadInt32()); int height = (reader.ReadInt32()); int levelCount = (reader.ReadInt32()); int levelCountOutput = levelCount; SurfaceFormat convertedFormat = surfaceFormat; switch (surfaceFormat) { case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt1a: convertedFormat = SurfaceFormat.Color; break; case SurfaceFormat.Dxt3: case SurfaceFormat.Dxt5: convertedFormat = SurfaceFormat.Color; break; case SurfaceFormat.NormalizedByte4: convertedFormat = SurfaceFormat.Color; break; } UnityEngine.Texture2D unityTexture = new UnityEngine.Texture2D(width, height, XnaToUnity.TextureFormat(convertedFormat), levelCountOutput > 1); for (int level = 0; level < levelCount; level++) { int levelDataSizeInBytes = (reader.ReadInt32()); byte[] levelData = reader.ReadBytes(levelDataSizeInBytes); int levelWidth = width >> level; int levelHeight = height >> level; if (level >= levelCountOutput) { continue; } //Convert the image data if required switch (surfaceFormat) { case SurfaceFormat.Dxt1: case SurfaceFormat.Dxt1a: levelData = DxtUtil.DecompressDxt1(levelData, levelWidth, levelHeight); break; case SurfaceFormat.Dxt3: levelData = DxtUtil.DecompressDxt3(levelData, levelWidth, levelHeight); break; case SurfaceFormat.Dxt5: levelData = DxtUtil.DecompressDxt5(levelData, levelWidth, levelHeight); break; } // un-premultiply alpha (instead do it in the shader) for (int i = 0; i < levelData.Length; i += 4) { float r = levelData[i + 0] / 255.0f; float g = levelData[i + 1] / 255.0f; float b = levelData[i + 2] / 255.0f; float a = levelData[i + 3] / 255.0f; levelData[i + 0] = (byte)(r / a * 255.0f); levelData[i + 1] = (byte)(g / a * 255.0f); levelData[i + 2] = (byte)(b / a * 255.0f); //levelData[i + 0] = 0; //levelData[i + 1] = 255; //levelData[i + 2] = 0; //levelData[i + 3] = 255; } // swap rows because unity textures are laid out bottom-top instead of top-bottom int rowSize = width * 4; byte[] temp = new byte[rowSize]; for (int i = 0; i < levelData.Length / 2; i += rowSize) { for (int j = 0; j < rowSize; j++) { temp[j] = levelData[i + j]; } int p = levelData.Length - (i + rowSize); for (int j = 0; j < rowSize; j++) { levelData[i + j] = levelData[p + j]; } for (int j = 0; j < rowSize; j++) { levelData[p + j] = temp[j]; } } UnityEngine.Color[] unityColors = new UnityEngine.Color[levelData.Length * 4]; unityTexture.SetPixels(XnaToUnity.Color(levelData, ref unityColors), level); unityTexture.Apply(); texture = new Texture2D(unityTexture); } return(texture); }
private void PlatformConstruct(int width, int height, bool mipmap, SurfaceFormat format, SurfaceType type, bool shared) { UnityTexture2D = new UnityEngine.Texture2D(width, height, XnaToUnity.TextureFormat(format), mipmap); }
public void Clear(Color color) { XnaToUnity.Color(color, ref tmp_uColor); GL.Clear(true, true, tmp_uColor); }