init
This commit is contained in:
40
engine/include/hd2d/RenderTarget.h
Normal file
40
engine/include/hd2d/RenderTarget.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include "hd2d/GL.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
|
||||
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<GLenum> 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<GLuint> colors_;
|
||||
int w_ = 0, h_ = 0;
|
||||
};
|
||||
|
||||
} // namespace hd2d
|
||||
Reference in New Issue
Block a user