public Direct3D9FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream) : base(textureFactory, memoryPool) { FStream = stream; FImageInformation = ImageInformation.FromStream(stream); Width = FImageInformation.Width; Height = FImageInformation.Height; }
public Direct3D9FrameDecoder(Func <Device, int, int, int, Format, Usage, Texture> textureFactory, MemoryPool memoryPool, Stream stream, Format preferedFormat) : base(textureFactory, memoryPool, preferedFormat) { FStream = stream; FImageInformation = ImageInformation.FromStream(stream); Width = FImageInformation.Width; Height = FImageInformation.Height; if (preferedFormat == Format.Unknown) { FChosenFormat = FImageInformation.Format; } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="device"></param> /// <param name="stream"></param> /// <param name="pa"></param> public ImageResource(PPDDevice device, Stream stream, bool pa) { try { var ii = ImageInformation.FromStream(stream); this.width = ii.Width; this.height = ii.Height; this.halfPixel = new Vector2(0.5f / this.width, 0.5f / this.height); this.texture = (Texture.DX9.Texture)TextureFactoryManager.Factory.FromStream(device, stream, this.width, this.height, pa); CreateVertexBuffer(device); } catch { MessageBox.Show(PPDExceptionContentProvider.Provider.GetContent(PPDExceptionType.ImageReadError)); } }
public ModelTexture LoadTexture(IPackageIndexer packageIndexer, string texturePath, Device device) { using (var stream = ModelTextureManager.OpenTexture(packageIndexer, texturePath)) { var pos = stream.Position; lock (_textures) { if (!_textures.TryGetValue(texturePath, out ModelTexture texture)) { var info = ImageInformation.FromStream(stream); stream.Seek(pos, SeekOrigin.Begin); texture = new ModelTexture(texturePath, Texture.FromStream(device, stream), info); _textures.Add(texturePath, texture); } else { texture.AddRef(); } return(texture); } } }
public ModuleMesh(ModuleModel model, IFileLocator fileLocator, Device device, GraphicsSettings graphicsSettings) { _graphicsSettings = graphicsSettings; this.LogInfo("load tank mesh {0} from {1}", model.ModelName, model.TankInstance.Tank.Name); this.Tank = model.TankInstance.Tank; _device = device; if (model.Visual == null) { throw new ArgumentException("model.Visual is null", nameof(model)); } if (model.Primitives == null) { throw new ArgumentException("model.Primitives is null", nameof(model)); } var verticesMap = model.Primitives.Vertices.ToDictionary(k => k.Key, k => ModuleMesh.ConvertToVertexBuffer(k.Value, device)); var indicesMap = model.Primitives.Indices.ToDictionary(k => k.Key, k => ModuleMesh.ConvertToIndexBuffer(k.Value, device)); foreach (var renderSet in model.Visual.RenderSets) { //renderSet.Geometry.PrimitiveName var vState = verticesMap[renderSet.Geometry.VerticesName]; var indices = indicesMap[renderSet.Geometry.IndicesName]; var rawVertices = model.Primitives.Vertices[renderSet.Geometry.VerticesName].Vertices; var rawIndices = model.Primitives.Indices[renderSet.Geometry.IndicesName]; foreach (var group in renderSet.Geometry.ModelPrimitiveGroups.Values) { RenderGroup renderGroup; if (group.Sectioned) { renderGroup = new RenderGroup(graphicsSettings) { MinVertexIndex = (int)group.StartVertex, VerticesCount = (int)group.VerticesCount, StartIndex = (int)group.StartIndex, PrimitiveCount = (int)group.PrimitiveCount, }; } else { renderGroup = new RenderGroup(graphicsSettings) { MinVertexIndex = 0, VerticesCount = vState.Count, StartIndex = 0, PrimitiveCount = ((int)indices.Tag) / 3, }; } renderGroup.VertexState = vState; renderGroup.Indices = indices; renderGroup.RawVertices = rawVertices; renderGroup.RawIndices = rawIndices; if (group.Material.ShowArmor) { renderGroup.RenderArmor = true; renderGroup.Textures = null; renderGroup.ArmorGroup = group.Material.Armor; } else { renderGroup.RenderArmor = false; var textures = new Dictionary <string, Texture>(); foreach (var property in group.Material.Properties) { var texturePath = property.Texture; if (string.IsNullOrWhiteSpace(texturePath)) { if (property.Name == "alphaTestEnable" && group.Material.Fx != "shaders/std_effects/PBS_tank.fx") { renderGroup.AlphaTestEnable = property.BoolValue; } else if (property.Name == "alphaReference") { renderGroup.AlphaReference = property.IntValue; } else if (property.Name == "g_useNormalPackDXT1") { renderGroup.UseNormalPackDXT1 = property.BoolValue; } else if (property.Name == "g_detailPower") { renderGroup.DetailPower = property.FloatValue; } else if (property.Name == "g_metallicDetailUVTiling") { renderGroup.DetailUVTiling = property.Vector4Value; } } else { try { using (var stream = ModuleMesh.OpenTexture(fileLocator, texturePath)) { var info = ImageInformation.FromStream(stream, true); var texture = Texture.FromStream(device, stream); textures[property.Name] = texture; if (property.Name == "normalMap" && !renderGroup.UseNormalBC1) { if (info.Format == Format.Dxt1) { renderGroup.UseNormalBC1 = true; } } } } catch (Exception) { this.LogInfo("can't load texture {0} for {1}", texturePath, property.Name); } } } renderGroup.Textures = textures; } _renderGroups.Add(renderGroup); } } }