#pragma once #include "hd2d/GL.h" #include #include namespace hd2d { // Creates an immutable 2D texture with clamp-to-edge sampling. GLuint createTexture2D(GLenum internalFormat, int w, int h, GLenum filter = GL_LINEAR, int levels = 1); // Framebuffer owning its color attachments. Depth can be owned (depthFormat) // or borrowed from another target (sharedDepth) so passes can depth-test // against an earlier pass without copying. class RenderTarget { public: RenderTarget() = default; RenderTarget(const RenderTarget&) = delete; RenderTarget& operator=(const RenderTarget&) = delete; ~RenderTarget() { destroy(); } void create(int w, int h, std::initializer_list colorFormats, GLenum depthFormat = 0, GLuint sharedDepth = 0, GLenum filter = GL_LINEAR); void destroy(); void bind() const; // binds FBO and sets viewport GLuint fbo() const { return fbo_; } GLuint color(int i = 0) const { return colors_[i]; } GLuint depth() const { return depth_; } int width() const { return w_; } int height() const { return h_; } private: GLuint fbo_ = 0, depth_ = 0; bool ownsDepth_ = false; std::vector colors_; int w_ = 0, h_ = 0; }; } // namespace hd2d