Class ShaderManager

java.lang.Object
dev.engine.graphics.common.ShaderManager

public class ShaderManager extends Object
Manages shader compilation via Slang (native FFM or process fallback). Produces CompiledShader with reflection metadata for binding resolution.
  • Constructor Details

  • Method Details

    • textureBindingOffset

      public int textureBindingOffset()
      Returns the texture binding offset for the current backend (e.g. 16 for Vulkan, 0 for OpenGL).
    • setAssetManager

      public void setAssetManager(AssetManager assetManager)
    • getShader

      public CompiledShader getShader(String shaderName)
      Gets or compiles the shader for a shader name (e.g. "PBR", "UNLIT"). Returns CompiledShader with reflection data.
    • getPipeline

      public Handle<PipelineResource> getPipeline(String shaderName)
      Returns just the pipeline handle (no reflection).
    • compileSlangSource

      public CompiledShader compileSlangSource(String source, String name)
    • compileSlangSource

      public CompiledShader compileSlangSource(String source, String name, VertexFormat vertexFormat)
      Compiles a Slang source with a custom vertex format (null = standard format).
    • compileSlangFile

      public Handle<PipelineResource> compileSlangFile(String path)
    • getShaderWithMaterial

      public CompiledShader getShaderWithMaterial(String shaderHint, Set<? extends PropertyKey<?,?>> materialKeys)
      Compiles a shader with material param blocks based on the material's keys. Uses generic specialization when native compiler is available, falls back to static global instance for the process-based compiler. Cached by shader hint + key set combination.
    • invalidate

      public void invalidate(String key)
    • resolveForEntity

      public CompiledShader resolveForEntity(Handle<?> entity, MaterialData material)
      Resolves a shader for an entity based on its material's shader hint and keys. Returns null if no material or shader hint, or if compilation fails. Caches the result per entity.
    • getEntityShader

      public CompiledShader getEntityShader(Handle<?> entity)
      Returns the compiled shader previously resolved for an entity, or null.
    • removeEntityShader

      public void removeEntityShader(Handle<?> entity)
      Removes the cached shader for a destroyed entity.
    • extractBufferBindings

      public static Map<String,Integer> extractBufferBindings(CompiledShader compiled)
      Extracts buffer name → binding slot map from a CompiledShader's reflection. Only includes constant buffer bindings.
    • invalidateAll

      public void invalidateAll()
    • close

      public void close()
      Destroys all cached pipelines. Call on shutdown.
    • loadResource

      public String loadResource(String shaderPath)
      Loads a shader source from the asset system or classpath.
      Parameters:
      shaderPath - the resource path (e.g. "shaders/debug_ui.slang")
      Returns:
      the shader source, or null if not found