public void DisposeTex(IGeneratedTexture tex) { if (tex == null) { return; } if (tex is MyUserGeneratedTexture) { MyUserGeneratedTexture texture = (MyUserGeneratedTexture)tex; texture.Dispose(); m_objectsPoolGenerated.Deallocate(texture); tex = null; } else if (tex is MyGeneratedTextureFromPattern) { MyGeneratedTextureFromPattern texture = (MyGeneratedTextureFromPattern)tex; texture.Dispose(); m_objectsPoolGeneratedFromPattern.Deallocate(texture); tex = null; } else { MyRenderProxy.Assert(false, "It is disposed texture that does not belong to this manager"); } }
public void Init(IGeneratedTexture releaseTex, IGeneratedTexture debugTex) { m_releaseTexture = releaseTex; m_debugTexture = debugTex; }
public void Init(IGeneratedTexture releaseTex, IGeneratedTexture debugTex) { m_releaseTexture = releaseTex; m_debugTexture = debugTex; }
public void Init(IGeneratedTexture releaseTex, IGeneratedTexture debugTex, string name) { m_name = name; m_releaseTexture = releaseTex; m_debugTexture = debugTex; }
public void OnDeviceInit() { MyFileTextureParams fileTexParams; bool ret = GetCorrectedFileTextureParams(out fileTexParams); //MyRenderProxy.Assert(ret, "It is not implemented mechanism, what to do, when none of the textures exist"); m_size = fileTexParams.Resolution; Texture2DDescription desc = new Texture2DDescription(); desc.ArraySize = m_listSubresourceFilenames.Count; desc.BindFlags = BindFlags.ShaderResource; desc.CpuAccessFlags = CpuAccessFlags.None; desc.Format = fileTexParams.Format; desc.Height = (int)Size.Y; desc.Width = (int)Size.X; var mipmaps = desc.MipLevels = fileTexParams.Mipmaps; desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; desc.Usage = ResourceUsage.Default; m_resource = new Texture2D(MyRender11.Device, desc); m_resource.DebugName = m_resourceName; TextureFormat = fileTexParams.Format; // foreach mip int i = 0; foreach (var path in m_listSubresourceFilenames) { bool isUsedCreatedGeneratedTexture = false; ISrvBindable tex = MyManagers.FileTextures.GetTexture(path, m_type, true); var tex2D = tex.Resource as Texture2D; MyRenderProxy.Assert(tex2D != null, "MyFileArrayTexture supports only 2D textures. Inconsistent texture: " + tex.Name); bool consistent = MyResourceUtils.CheckTexturesConsistency(desc, tex2D.Description); if (!consistent) { if (!string.IsNullOrEmpty(path) && MyFileSystem.FileExists(path)) { string msg = string.Format( "Texture {0} cannot be loaded. If this message is displayed on reloading textures, please restart the game. If it is not, please notify developers.", path); MyRenderProxy.Fail(msg); } } if (!consistent && m_recoverySystem.UseErrorTexture) // if the texture cannot be used, error texture will be used { tex = MyManagers.FileTextures.GetTexture(m_recoverySystem.TextureFilepath, m_type, true); tex2D = tex.Resource as Texture2D; MyRenderProxy.Assert(tex2D != null, "MyFileArrayTexture supports only 2D textures. Inconsistent texture: " + m_recoverySystem.TextureFilepath); consistent = MyResourceUtils.CheckTexturesConsistency(desc, tex2D.Description); } if (!consistent && m_recoverySystem.UseBytePattern) // if the texture cannot be used, byte pattern will be used to generate texture { tex = MyManagers.GeneratedTextures.CreateFromBytePattern("MyFileArrayTexture.Tmp", desc.Width, desc.Height, m_recoverySystem.FormatBytePattern, m_recoverySystem.BytePattern); tex2D = tex.Resource as Texture2D; MyRenderProxy.Assert(tex2D != null); consistent = MyResourceUtils.CheckTexturesConsistency(desc, tex2D.Description); isUsedCreatedGeneratedTexture = true; } if (!consistent) { Texture2DDescription desc1 = desc; Texture2DDescription desc2 = tex2D.Description; string errorMsg = string.Format("Textures ({0}) is not compatible within array texture! Width: ({1},{2}) Height: ({3},{4}) Mipmaps: ({5},{6}) Format: ({7},{8})", path, desc1.Width, desc2.Width, desc1.Height, desc2.Height, desc1.MipLevels, desc2.MipLevels, desc1.Format, desc2.Format); MyRenderProxy.Error(errorMsg); MyRender11.Log.WriteLine(errorMsg); } for (int m = 0; m < mipmaps; m++) { MyRender11.RC.CopySubresourceRegion(tex, Resource.CalculateSubResourceIndex(m, 0, mipmaps), null, Resource, Resource.CalculateSubResourceIndex(m, i, mipmaps)); int sizeX = Resource.CalculateMipSize(m, Size.X); int sizeY = Resource.CalculateMipSize(m, Size.Y); ByteSize += FormatHelper.ComputeScanlineCount(TextureFormat, sizeX) * 4 * FormatHelper.ComputeScanlineCount(TextureFormat, sizeY) * 4 * FormatHelper.SizeOfInBytes(TextureFormat); } if (isUsedCreatedGeneratedTexture) { IGeneratedTexture generatedTex = (IGeneratedTexture)tex; MyManagers.GeneratedTextures.DisposeTex(generatedTex); } i++; } m_srv = new ShaderResourceView(MyRender11.Device, Resource); }
public void DisposeTex(IGeneratedTexture tex) { if (tex == null) return; if (tex is MyUserGeneratedTexture) { MyUserGeneratedTexture texture = (MyUserGeneratedTexture) tex; texture.Dispose(); m_objectsPoolGenerated.Deallocate(texture); tex = null; } else if (tex is MyGeneratedTextureFromPattern) { MyGeneratedTextureFromPattern texture = (MyGeneratedTextureFromPattern)tex; texture.Dispose(); m_objectsPoolGeneratedFromPattern.Deallocate(texture); tex = null; } else { MyRenderProxy.Assert(false, "It is disposed texture that does not belong to this manager"); } }
public void Init(IGeneratedTexture releaseTex, IGeneratedTexture debugTex, string name) { m_name = name; m_releaseTexture = releaseTex; m_debugTexture = debugTex; }