diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_framebuffer_private.hh')
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer_private.hh | 116 |
1 files changed, 86 insertions, 30 deletions
diff --git a/source/blender/gpu/intern/gpu_framebuffer_private.hh b/source/blender/gpu/intern/gpu_framebuffer_private.hh index cc5ae048c7c..93551b0ef8b 100644 --- a/source/blender/gpu/intern/gpu_framebuffer_private.hh +++ b/source/blender/gpu/intern/gpu_framebuffer_private.hh @@ -19,19 +19,26 @@ /** \file * \ingroup gpu + * + * GPU Framebuffer + * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice + * multiple FBO's may be created. + * - actual FBO creation & config is deferred until GPU_framebuffer_bind or + * GPU_framebuffer_check_valid to allow creation & config while another + * opengl context is bound (since FBOs are not shared between ogl contexts). */ #pragma once +#include "BLI_span.hh" + #include "MEM_guardedalloc.h" #include "GPU_framebuffer.h" -#include "glew-mx.h" /* For GLuint. To remove. */ - struct GPUTexture; -typedef enum { +typedef enum GPUAttachmentType : int { GPU_FB_DEPTH_ATTACHMENT = 0, GPU_FB_DEPTH_STENCIL_ATTACHMENT, GPU_FB_COLOR_ATTACHMENT0, @@ -45,50 +52,99 @@ typedef enum { /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to * the maximum number of COLOR attachments specified by glDrawBuffers. */ GPU_FB_MAX_ATTACHEMENT, + + GPU_FB_MAX_COLOR_ATTACHMENT = (GPU_FB_MAX_ATTACHEMENT - GPU_FB_COLOR_ATTACHMENT0), } GPUAttachmentType; -namespace blender { -namespace gpu { +inline constexpr GPUAttachmentType operator-(GPUAttachmentType a, int b) +{ + return static_cast<GPUAttachmentType>(static_cast<int>(a) - b); +} -#define FOREACH_ATTACHMENT_RANGE(att, _start, _end) \ - for (GPUAttachmentType att = static_cast<GPUAttachmentType>(_start); att < _end; \ - att = static_cast<GPUAttachmentType>(att + 1)) +inline constexpr GPUAttachmentType operator+(GPUAttachmentType a, int b) +{ + return static_cast<GPUAttachmentType>(static_cast<int>(a) + b); +} -#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHEMENT - GPU_FB_COLOR_ATTACHMENT0) +inline GPUAttachmentType &operator++(GPUAttachmentType &a) +{ + a = a + 1; + return a; +} -#define GPU_FB_DIRTY_DRAWBUFFER (1 << 15) +inline GPUAttachmentType &operator--(GPUAttachmentType &a) +{ + a = a - 1; + return a; +} -#define GPU_FB_ATTACHEMENT_IS_DIRTY(flag, type) ((flag & (1 << type)) != 0) -#define GPU_FB_ATTACHEMENT_SET_DIRTY(flag, type) (flag |= (1 << type)) +namespace blender { +namespace gpu { + +#ifdef DEBUG +# define DEBUG_NAME_LEN 64 +#else +# define DEBUG_NAME_LEN 16 +#endif class FrameBuffer { - public: - GPUContext *ctx; - GLuint object; - GPUAttachment attachments[GPU_FB_MAX_ATTACHEMENT]; - uint16_t dirty_flag; - int width, height; - bool multisample; - /* TODO Check that we always use the right context when binding - * (FBOs are not shared across ogl contexts). */ - // void *ctx; + protected: + /** Set of texture attachements to render to. DEPTH and DEPTH_STENCIL are mutualy exclusive. */ + GPUAttachment attachments_[GPU_FB_MAX_ATTACHEMENT]; + /** Is true if internal representation need to be updated. */ + bool dirty_attachments_; + /** Size of attachement textures. */ + int width_, height_; + /** Debug name. */ + char name_[DEBUG_NAME_LEN]; public: - GPUTexture *depth_tex(void) const + FrameBuffer(const char *name); + virtual ~FrameBuffer(); + + virtual void bind(bool enabled_srgb) = 0; + virtual bool check(char err_out[256]) = 0; + virtual void clear(eGPUFrameBufferBits buffers, + const float clear_col[4], + float clear_depth, + uint clear_stencil) = 0; + virtual void clear_multi(const float (*clear_col)[4]) = 0; + + virtual void read(eGPUFrameBufferBits planes, + eGPUDataFormat format, + const int area[4], + int channel_len, + int slot, + void *r_data) = 0; + + virtual void blit_to(eGPUFrameBufferBits planes, + int src_slot, + FrameBuffer *dst, + int dst_slot, + int dst_offset_x, + int dst_offset_y) = 0; + + void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment); + + void recursive_downsample(int max_lvl, + void (*callback)(void *userData, int level), + void *userData); + + inline GPUTexture *depth_tex(void) const { - if (attachments[GPU_FB_DEPTH_ATTACHMENT].tex) { - return attachments[GPU_FB_DEPTH_ATTACHMENT].tex; + if (attachments_[GPU_FB_DEPTH_ATTACHMENT].tex) { + return attachments_[GPU_FB_DEPTH_ATTACHMENT].tex; } - return attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex; + return attachments_[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex; }; - GPUTexture *color_tex(int slot) const + inline GPUTexture *color_tex(int slot) const { - return attachments[GPU_FB_COLOR_ATTACHMENT0 + slot].tex; + return attachments_[GPU_FB_COLOR_ATTACHMENT0 + slot].tex; }; - - MEM_CXX_CLASS_ALLOC_FUNCS("FrameBuffer") }; +#undef DEBUG_NAME_LEN + } // namespace gpu } // namespace blender |