using Ghost.Core; using Ghost.Graphics.Core; namespace Ghost.Graphics.RHI; public interface IResourceReleasable { /// /// A method to release GPU resources. /// void ReleaseResource(IResourceDatabase database); } public interface IResourceDatabase { /* /// /// Imports an external unmanaged resource and returns a handle for use within the resource management system. /// /// The type of the unmanaged resource pointer to import. /// A pointer to the external unmanaged resource to be imported. Must remain valid for the duration of the resource's usage. /// The initial state to assign to the imported resource. /// A handle representing the imported resource, which can be used for subsequent operations. unsafe Handle ImportExternalResource(T resourcePtr, ResourceState initialState, string? name = null) where T : unmanaged; */ /// /// Checks if a resource with the specified handle exists in the database. /// /// The handle of the resource to check for existence. bool HasResource(Handle handle); /// /// Retrieves the current state of the specified resource. /// /// The handle that uniquely identifies the resource whose state is to be retrieved. /// A ResourceState value representing the current state of the resource associated with the specified handle. ResourceState GetResourceState(Handle handle); /// /// Sets the state of the specified resource handle to the given value. /// /// The handle that identifies the resource whose state will be updated. /// The new state to assign to the resource represented by . void SetResourceState(Handle handle, ResourceState state); /// /// Retrieves the description of a GPU resource associated with the specified handle. /// /// A handle that identifies the GPU resource for which to obtain the description. Must reference a valid resource. /// A ResourceDesc structure containing details about the specified GPU resource. ResourceDesc GetResourceDescription(Handle handle); /// /// Retrieves the bindless index associated with the specified GPU resource handle. /// /// A handle to the GPU resource for which to obtain the bindless index. Must reference a valid, currently registered resource. /// The bindless index corresponding to the specified GPU resource handle. -1 if the resource does not support bindless access or is not found. int GetBindlessIndex(Handle handle); /// /// Retrieves the name of the GPU resource associated with the specified handle. /// /// /// You should only use this method in debug builds or inside engine editor. /// /// A handle to the GPU resource for which to obtain the name. Must reference a valid resource. /// The name of the GPU resource associated with the specified handle, or null if the resource does not have a name. string? GetResourceName(Handle handle); /// /// Removes a resource from the database using its handle. /// /// The handle of the resource to be removed. void ReleaseResource(Handle handle); /// /// Adds a mesh to the resource database and returns its handle. /// /// The mesh data to be added to the database. /// The representing the newly added mesh."/> Handle AddMesh(ref readonly Mesh mesh); /// /// Determines whether a mesh with the specified Handle exists. /// /// The handle of the mesh to check for existence. Cannot be null. /// true if a mesh with the specified Handle exists; otherwise, false. bool HasMesh(Handle handle); /// /// Returns a reference to the mesh associated with the specified handle. /// /// The handle of the mesh to retrieve. Must refer to a valid mesh; otherwise, the behavior is undefined. /// A reference to the mesh corresponding to the specified handle. ref Mesh GetMeshReference(Handle handle); /// /// Releases the mesh resource associated with the specified handle, freeing any resources held by it. Includes both CPU and GPU resources. /// /// The handle of the mesh to release. Must refer to a mesh that was previously created and not already released. void ReleaseMesh(Handle handle); /// /// Adds a new material to the collection and returns its unique handle. /// /// The material to add. The material must be fully initialized before calling this method. /// The representing the newly added material. Handle AddMaterial(ref readonly Material material); /// /// Determines whether a material with the specified handle exists in the collection. /// /// The handle of the material to check for existence. /// true if a material with the specified handle exists; otherwise, false. bool HasMaterial(Handle handle); /// /// Gets a reference to the material associated with the specified handle. /// /// The handle of the material to retrieve. Must refer to a valid material. /// A reference to the material corresponding to the specified handle. ref Material GetMaterialReference(Handle handle); /// /// Releases the material associated with the specified handle, making it available for reuse or disposal. /// /// The handle of the material to release. Must refer to a material that has been previously acquired. void ReleaseMaterial(Handle handle); /// /// Adds the specified shader to the collection and returns its unique identifier. /// /// The shader to add. The shader is passed by read-only reference and will not be modified. /// The representing the newly added shader. Identifier AddShader(Shader shader); /// /// Determines whether a shader with the specified identifier exists in the collection. /// /// The identifier of the shader to check for existence. /// true if a shader with the specified identifier exists; otherwise, false. bool HasShader(Identifier id); /// /// Returns a reference to the shader associated with the specified identifier. /// /// The identifier of the shader to retrieve. Must refer to a valid shader. /// A reference to the shader corresponding to the specified identifier. Shader GetShaderReference(Identifier id); /// /// Releases the shader associated with the specified identifier, freeing any resources allocated to it. /// /// The identifier of the shader to release. Must refer to a valid, previously created shader. void ReleaseShader(Identifier id); /// /// Adds a shader pass to the collection using the specified identifier. /// /// The unique identifier for the shader pass. /// The shader pass to add. Cannot be null. void AddShaderPass(ShaderPassKey passKey, ShaderPass pass); /// /// Retrieves the shader pass associated with the specified pass identifier. /// /// The unique identifier of the shader pass to retrieve. /// The corresponding to the specified identifier, or null if no matching shader pass is found. ShaderPass GetShaderPass(ShaderPassKey passKey); }