Blender  V2.93
gl_framebuffer.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2020 Blender Foundation.
17  * All rights reserved.
18  */
19 
26 #pragma once
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "glew-mx.h"
31 
33 
34 namespace blender::gpu {
35 
36 class GLStateManager;
37 
41 class GLFrameBuffer : public FrameBuffer {
42  /* For debugging purpose. */
43  friend class GLTexture;
44 
45  private:
47  GLuint fbo_id_ = 0;
49  GLContext *context_ = NULL;
51  GLStateManager *state_manager_ = NULL;
53  GLenum gl_attachments_[GPU_FB_MAX_COLOR_ATTACHMENT];
55  bool immutable_;
57  bool srgb_;
59  bool enabled_srgb_ = false;
60 
61  public:
65  GLFrameBuffer(const char *name);
66 
76  GLFrameBuffer(const char *name, GLContext *ctx, GLenum target, GLuint fbo, int w, int h);
77 
79 
80  void bind(bool enabled_srgb) override;
81 
82  bool check(char err_out[256]) override;
83 
84  void clear(eGPUFrameBufferBits buffers,
85  const float clear_col[4],
86  float clear_depth,
87  uint clear_stencil) override;
88  void clear_multi(const float (*clear_cols)[4]) override;
90  eGPUDataFormat data_format,
91  const void *clear_value) override;
92 
93  void read(eGPUFrameBufferBits planes,
95  const int area[4],
96  int channel_len,
97  int slot,
98  void *r_data) override;
99 
100  void blit_to(eGPUFrameBufferBits planes,
101  int src_slot,
102  FrameBuffer *dst,
103  int dst_slot,
104  int dst_offset_x,
105  int dst_offset_y) override;
106 
107  void apply_state(void);
108 
109  private:
110  void init(void);
111  void update_attachments(void);
112  void update_drawbuffers(void);
113 
114  MEM_CXX_CLASS_ALLOC_FUNCS("GLFrameBuffer");
115 };
116 
117 /* -------------------------------------------------------------------- */
121 static inline GLenum to_gl(const GPUAttachmentType type)
122 {
123 #define ATTACHMENT(X) \
124  case GPU_FB_##X: { \
125  return GL_##X; \
126  } \
127  ((void)0)
128 
129  switch (type) {
130  ATTACHMENT(DEPTH_ATTACHMENT);
131  ATTACHMENT(DEPTH_STENCIL_ATTACHMENT);
132  ATTACHMENT(COLOR_ATTACHMENT0);
133  ATTACHMENT(COLOR_ATTACHMENT1);
134  ATTACHMENT(COLOR_ATTACHMENT2);
135  ATTACHMENT(COLOR_ATTACHMENT3);
136  ATTACHMENT(COLOR_ATTACHMENT4);
137  ATTACHMENT(COLOR_ATTACHMENT5);
138  default:
139  BLI_assert(0);
140  return GL_COLOR_ATTACHMENT0;
141  }
142 #undef ATTACHMENT
143 }
144 
145 static inline GLbitfield to_gl(const eGPUFrameBufferBits bits)
146 {
147  GLbitfield mask = 0;
148  mask |= (bits & GPU_DEPTH_BIT) ? GL_DEPTH_BUFFER_BIT : 0;
149  mask |= (bits & GPU_STENCIL_BIT) ? GL_STENCIL_BUFFER_BIT : 0;
150  mask |= (bits & GPU_COLOR_BIT) ? GL_COLOR_BUFFER_BIT : 0;
151  return mask;
152 }
153 
156 } // namespace blender::gpu
#define BLI_assert(a)
Definition: BLI_assert.h:58
unsigned int uint
Definition: BLI_sys_types.h:83
eGPUFrameBufferBits
@ GPU_DEPTH_BIT
@ GPU_STENCIL_BIT
@ GPU_COLOR_BIT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
eGPUDataFormat
Definition: GPU_texture.h:171
Read Guarded memory(de)allocation.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil) override
bool check(char err_out[256]) override
void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data) override
void clear_multi(const float(*clear_cols)[4]) override
GLFrameBuffer(const char *name)
void bind(bool enabled_srgb) override
void clear_attachment(GPUAttachmentType type, eGPUDataFormat data_format, const void *clear_value) override
void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y) override
#define ATTACHMENT(X)
#define GPU_FB_MAX_COLOR_ATTACHMENT
format
Definition: logImageCore.h:47
static void area(int d1, int d2, int e1, int e2, float weights[2])
static GLenum to_gl(const GPUAttachmentType type)
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)