using System; using System.IO; namespace AcDream.App.Rendering.Wb { /// /// Resolves WB-style shader resource names (e.g. "Shaders.Particle.vert") to /// the corresponding file under the acdream binary's Rendering/Shaders directory. /// /// WB embeds shaders as assembly resources under the Chorizite.OpenGLSDLBackend /// namespace. acdream ships shaders as plain files copied to the output directory. /// This class adapts between the two conventions so ParticleBatcher and /// ParticleEmitterRenderer can call GetEmbeddedResource without modification. /// /// Mapping rule: "Shaders.Foo.vert" → Rendering/Shaders/wb_foo.vert /// (lower-case, wb_ prefix to distinguish WB-origin shaders from acdream's own) /// public static class EmbeddedResourceReader { public static string GetEmbeddedResource(string filename) { // Convert "Shaders.Particle.vert" → "wb_particle.vert" // Strip leading "Shaders." then lowercase and prefix with wb_ string leafName; const string shadersPrefix = "Shaders."; if (filename.StartsWith(shadersPrefix, StringComparison.Ordinal)) { var rest = filename.Substring(shadersPrefix.Length); // e.g. "Particle.vert" leafName = "wb_" + rest.ToLowerInvariant(); // e.g. "wb_particle.vert" } else { leafName = "wb_" + filename.ToLowerInvariant(); } var shadersDir = Path.Combine(AppContext.BaseDirectory, "Rendering", "Shaders"); var fullPath = Path.Combine(shadersDir, leafName); if (!File.Exists(fullPath)) throw new InvalidOperationException( $"WB shader not found: '{fullPath}' (mapped from resource '{filename}'). " + $"Ensure {leafName} is in src/AcDream.App/Rendering/Shaders/ with CopyToOutputDirectory."); return File.ReadAllText(fullPath); } } }