import type ManagedColorAttachment from "./ManagedColorAttachment.js";
import type ManagedDepthAttachment from "./ManagedDepthAttachment.js";
import type ManagedFBOResource from "./ManagedFBOResource.js";
import type { RenderNodeInput } from "../webgl.js";

/**
 * ManagedFBO is an interface to represent a framebuffer object resource of the [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/).
 * ManagedFBO are used in custom RenderNodes to access current render states of the frame as well as return modified
 * frame states to the render pipeline.
 *
 * > [!WARNING]
 * >
 * > ### Important guidelines
 * >
 * > **This interface is experimental**. Please read the following information carefully before using it in a product:
 * > It is not possible to shield users of this interface from SceneView internal implementation details. Therefore,
 * >   this interface should be considered **not stable and subject to changes in upcoming minor releases** of the ArcGIS
 * >   Maps SDK for JavaScript.
 * > Because of the complex nature of WebGL and hardware-accelerated 3D rendering, this interface is targeting
 * >   expert developers that are experienced with WebGL or OpenGL.
 * >   * Improper use of WebGL might not only break the custom rendering, but also the rendering of
 * >     [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/) itself.
 * >   * Esri does not provide any support for issues related to WebGL rendering in custom rendering code, or for issues
 * >     that arise in [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/) rendering while using custom rendering code.
 * > Integration with third-party libraries is only possible under certain conditions. Specifically, the third-party
 * >   library has to be capable of working on the same WebGL context as [SceneView](https://developers.arcgis.com/javascript/latest/references/core/views/SceneView/), and able to
 * >   set the relevant parts of the WebGL state in every frame.
 *
 * @since 4.29
 */
export default abstract class ManagedFBO extends ManagedFBOResource {
  /** The name of the managed fbo target */
  get name(): RenderNodeInput;
  /**
   * Acquire and attach a new color texture to this framebuffer.
   *
   * The attached texture has a gl.PixelFormat.RGBA pixel format.
   *
   * @param attachment - the WebGL color attachment point for the texture
   */
  acquireColor(attachment: number): ManagedFBO;
  /**
   * Acquire and attach a new depth buffer to this framebuffer.
   * The attached texture has a gl.PixelFormat.DEPTH_STENCIL pixel format.
   */
  acquireDepth(): ManagedFBO;
  /**
   * Attach a color buffer texture to this framebuffer.
   *
   * A previously attached color texture at the given attachment point will be released. The newly attached texture will
   * be retained. This function automatically binds the framebuffer of this ManagedFBO.
   *
   * @param color - the color texture to attach.
   * @param attachment - the gl.ColorFormat attachment point.
   */
  attachColor(color: ManagedColorAttachment, attachment: number): ManagedFBO;
  /**
   * Attach a depth buffer texture to this framebuffer. This function will automatically
   * bind the framebuffer of this ManagedFBO if necessary.
   *
   * A previously attached depth texture will be released. The newly attached texture will be retained. This function
   * automatically binds the framebuffer of this ManagedFBO.
   *
   * @param depth - the depth buffer texture to attach.
   */
  attachDepth(depth: ManagedDepthAttachment | null | undefined): ManagedFBO;
  /**
   * Returns a managed color attachment linked to this framebuffer object.
   *
   * @param attachment - the WebGL color attachment point.
   */
  getAttachment(attachment?: number): ManagedColorAttachment | ManagedDepthAttachment | null | undefined;
  /**
   * Return the texture for a given color or depth attachment.
   *
   * @param attachment - a WebGL color or depth attachment point.
   */
  getTexture(attachment?: number): FBOTexture | null | undefined;
  /** Detach the attached depth buffer texture and return ownership to the caller. */
  obtainDepthTexture(): any | null | undefined;
  /**
   * Release this managed framebuffer.
   *
   * If more than one reference exists this will not have an effect.
   *
   * @returns true if the resource was released for reuse, i.e., the reference count reached zero.
   * @since 5.0
   */
  release(): boolean;
  /**
   * Increase reference counting on this managed framebuffer.
   *
   * You can use this functionality to hold framebuffer contents for several frames and then release the framebuffer.
   *
   * @since 5.0
   */
  retain(): void;
}

/** Encapsulates a WebGL texture. */
export interface FBOTexture {}