[Bf-blender-cvs] [6e901fd8fc5] master: GPUFramebuffer: Make GPUFrameBuffer an opaque type
Clément Foucault
noreply at git.blender.org
Sun Aug 30 13:36:07 CEST 2020
Commit: 6e901fd8fc5b89e52dc44fd87a782c4f47c9c3f5
Author: Clément Foucault
Date: Tue Aug 25 23:27:40 2020 +0200
Branches: master
https://developer.blender.org/rB6e901fd8fc5b89e52dc44fd87a782c4f47c9c3f5
GPUFramebuffer: Make GPUFrameBuffer an opaque type
This is in preparation of the Framebuffer GL backend.
This is a just changing types and moving some code.
No logic is changed... almost... it just removes the context attach.
i.e: `gpu_context_add/remove_framebuffer()`
This is not needed for now and was even disabled in release.
This is part of T68990.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_framebuffer.h
M source/blender/gpu/intern/gpu_context.cc
M source/blender/gpu/intern/gpu_context_private.hh
M source/blender/gpu/intern/gpu_framebuffer.cc
A source/blender/gpu/intern/gpu_framebuffer_private.hh
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b319a9d91a3..25c76b8f73c 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -134,6 +134,7 @@ set(SRC
intern/gpu_codegen.h
intern/gpu_context_private.hh
intern/gpu_drawlist_private.hh
+ intern/gpu_framebuffer_private.hh
intern/gpu_material_library.h
intern/gpu_matrix_private.h
intern/gpu_node_graph.h
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index db25bbb7998..e1526bf50a6 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -46,7 +46,11 @@ typedef enum eGPUBackBuffer {
GPU_BACKBUFFER_LEFT,
} eGPUBackBuffer;
-typedef struct GPUFrameBuffer GPUFrameBuffer;
+/** Opaque pointer hiding blender::gpu::FrameBuffer. */
+typedef struct GPUFrameBuffer {
+ void *dummy;
+} GPUFrameBuffer;
+
typedef struct GPUOffScreen GPUOffScreen;
/* GPU Framebuffer
diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc
index ef02ec24a00..9b4705ae6a3 100644
--- a/source/blender/gpu/intern/gpu_context.cc
+++ b/source/blender/gpu/intern/gpu_context.cc
@@ -185,40 +185,6 @@ void GPU_tex_free(GLuint tex_id)
static_cast<GLBackend *>(backend)->tex_free(tex_id);
}
-/* GPUBatch & GPUFrameBuffer contains respectively VAO & FBO indices
- * which are not shared across contexts. So we need to keep track of
- * ownership. */
-
-void gpu_context_add_framebuffer(GPUContext *ctx, GPUFrameBuffer *fb)
-{
-#ifdef DEBUG
- BLI_assert(ctx);
- static_cast<GLContext *>(ctx)->framebuffer_register(fb);
-#else
- UNUSED_VARS(ctx, fb);
-#endif
-}
-
-void gpu_context_remove_framebuffer(GPUContext *ctx, GPUFrameBuffer *fb)
-{
-#ifdef DEBUG
- BLI_assert(ctx);
- static_cast<GLContext *>(ctx)->framebuffer_unregister(fb);
-#else
- UNUSED_VARS(ctx, fb);
-#endif
-}
-
-void gpu_context_active_framebuffer_set(GPUContext *ctx, GPUFrameBuffer *fb)
-{
- ctx->current_fbo = fb;
-}
-
-GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx)
-{
- return ctx->current_fbo;
-}
-
struct GPUMatrixState *gpu_context_active_matrix_state_get()
{
BLI_assert(active_ctx);
diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh
index e8c9c976e9a..d18d18dc97b 100644
--- a/source/blender/gpu/intern/gpu_context_private.hh
+++ b/source/blender/gpu/intern/gpu_context_private.hh
@@ -29,6 +29,7 @@
#include "GPU_context.h"
+#include "gpu_framebuffer_private.hh"
#include "gpu_shader_private.hh"
#include "gpu_state_private.hh"
@@ -38,14 +39,13 @@
#include <unordered_set>
#include <vector>
-struct GPUFrameBuffer;
struct GPUMatrixState;
struct GPUContext {
public:
/** State managment */
blender::gpu::Shader *shader = NULL;
- GPUFrameBuffer *current_fbo = NULL;
+ blender::gpu::FrameBuffer *active_fb = NULL;
GPUMatrixState *matrix_state = NULL;
blender::gpu::GPUStateManager *state_manager = NULL;
@@ -82,9 +82,6 @@ void GPU_tex_free(GLuint tex_id);
void GPU_vao_free(GLuint vao_id, GPUContext *ctx);
void GPU_fbo_free(GLuint fbo_id, GPUContext *ctx);
-void gpu_context_add_framebuffer(GPUContext *ctx, struct GPUFrameBuffer *fb);
-void gpu_context_remove_framebuffer(GPUContext *ctx, struct GPUFrameBuffer *fb);
-
void gpu_context_active_framebuffer_set(GPUContext *ctx, struct GPUFrameBuffer *fb);
struct GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index 67320ed61b6..2f39bb37acd 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -29,51 +29,15 @@
#include "GPU_batch.h"
#include "GPU_extensions.h"
-#include "GPU_framebuffer.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "gpu_context_private.hh"
#include "gpu_private.h"
-typedef enum {
- GPU_FB_DEPTH_ATTACHMENT = 0,
- GPU_FB_DEPTH_STENCIL_ATTACHMENT,
- GPU_FB_COLOR_ATTACHMENT0,
- GPU_FB_COLOR_ATTACHMENT1,
- GPU_FB_COLOR_ATTACHMENT2,
- GPU_FB_COLOR_ATTACHMENT3,
- GPU_FB_COLOR_ATTACHMENT4,
- GPU_FB_COLOR_ATTACHMENT5,
- /* Number of maximum output slots.
- * We support 6 outputs for now (usually we wouldn't need more to preserve fill rate). */
- /* 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,
-} GPUAttachmentType;
-
-#define FOREACH_ATTACHMENT_RANGE(att, _start, _end) \
- for (GPUAttachmentType att = static_cast<GPUAttachmentType>(_start); att < _end; \
- att = static_cast<GPUAttachmentType>(att + 1))
-
-#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHEMENT - GPU_FB_COLOR_ATTACHMENT0)
-
-#define GPU_FB_DIRTY_DRAWBUFFER (1 << 15)
-
-#define GPU_FB_ATTACHEMENT_IS_DIRTY(flag, type) ((flag & (1 << type)) != 0)
-#define GPU_FB_ATTACHEMENT_SET_DIRTY(flag, type) (flag |= (1 << type))
-
-struct GPUFrameBuffer {
- 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;
-};
+#include "gpu_framebuffer_private.hh"
+
+using namespace blender::gpu;
static GLenum convert_attachment_type_to_gl(GPUAttachmentType type)
{
@@ -122,20 +86,6 @@ static GLenum convert_buffer_bits_to_gl(eGPUFrameBufferBits bits)
return mask;
}
-static GPUTexture *framebuffer_get_depth_tex(GPUFrameBuffer *fb)
-{
- if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex) {
- return fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex;
- }
-
- return fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex;
-}
-
-static GPUTexture *framebuffer_get_color_tex(GPUFrameBuffer *fb, int slot)
-{
- return fb->attachments[GPU_FB_COLOR_ATTACHMENT0 + slot].tex;
-}
-
static void gpu_print_framebuffer_error(GLenum status, char err_out[256])
{
const char *format = "GPUFrameBuffer: framebuffer status %s\n";
@@ -186,19 +136,7 @@ void gpu_framebuffer_module_exit(void)
GPUFrameBuffer *GPU_framebuffer_active_get(void)
{
GPUContext *ctx = GPU_context_active_get();
- if (ctx) {
- return gpu_context_active_framebuffer_get(ctx);
- }
-
- return 0;
-}
-
-static void gpu_framebuffer_current_set(GPUFrameBuffer *fb)
-{
- GPUContext *ctx = GPU_context_active_get();
- if (ctx) {
- gpu_context_active_framebuffer_set(ctx, fb);
- }
+ return reinterpret_cast<GPUFrameBuffer *>(ctx ? ctx->active_fb : NULL);
}
/* GPUFrameBuffer */
@@ -207,42 +145,46 @@ GPUFrameBuffer *GPU_framebuffer_create(void)
{
/* We generate the FB object later at first use in order to
* create the framebuffer in the right opengl context. */
- return (GPUFrameBuffer *)MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
+ return (GPUFrameBuffer *)new FrameBuffer();
}
-static void gpu_framebuffer_init(GPUFrameBuffer *fb)
+static void gpu_framebuffer_init(FrameBuffer *fb)
{
fb->object = GPU_fbo_alloc();
fb->ctx = GPU_context_active_get();
- gpu_context_add_framebuffer(fb->ctx, fb);
+ /* Not really needed for now. */
+ // gpu_context_add_framebuffer(fb->ctx, fb);
}
-void GPU_framebuffer_free(GPUFrameBuffer *fb)
+void GPU_framebuffer_free(GPUFrameBuffer *gpu_fb)
{
+ FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
for (int i_type = 0; i_type < GPU_FB_MAX_ATTACHEMENT; i_type++) {
GPUAttachmentType type = static_cast<GPUAttachmentType>(i_type);
if (fb->attachments[type].tex != NULL) {
- GPU_framebuffer_texture_detach(fb, fb->attachments[type].tex);
+ GPU_framebuffer_texture_detach(gpu_fb, fb->attachments[type].tex);
}
}
if (fb->object != 0) {
/* This restores the framebuffer if it was bound */
GPU_fbo_free(fb->object, fb->ctx);
- gpu_context_remove_framebuffer(fb->ctx, fb);
+ /* Not really needed for now. */
+ // gpu_context_remove_framebuffer(fb->ctx, fb);
}
- if (GPU_framebuffer_active_get() == fb) {
- gpu_framebuffer_current_set(NULL);
+ /* TODO(fclem) check if bound in its associated context context. */
+ if (GPU_framebuffer_active_get() == gpu_fb) {
+ GPU_context_active_get()->active_fb = NULL;
}
- MEM_freeN(fb);
+ delete fb;
}
/* ---------- Attach ----------- */
static void gpu_framebuffer_texture_attach_ex(
- GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
+ FrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
{
if (slot >= GPU_FB_MAX_COLOR_ATTACHMENT) {
fprintf(stderr,
@@ -253,6 +195,7 @@ static void gpu_framebuffer_texture_attach_ex(
return;
}
+ GPUFrameBuffer *gpufb = reinterpret_cast<GPUFrameBuffer *>(fb);
GPUAttachmentType type = attachment_type_from_tex(tex, slot);
GPUAttachment *attachment = &fb->attachments[type];
@@ -260,11 +203,11 @@ static void gpu_framebuffer_texture_attach_ex(
return; /* Exact same texture already bound here. */
}
if (attachment->tex != NULL) {
- GPU_framebuffer_texture_detach(fb, attachment->tex);
+ GPU_framebuffer_texture_detach(gpufb, attachment->tex);
}
if (attachment->tex == NULL) {
- GPU_texture_attach_framebuffer(tex, fb, type);
+ GPU_texture_attach_framebuffer(tex, gpufb, type);
}
attachment->tex = tex;
@@ -273,30 +216,34 @@ static void gpu_framebuffer_texture_attach_ex(
GPU_FB_ATTACHEMENT_SET_DIRTY(fb->dirty_flag, type);
}
-void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
+void GPU_framebuffer_texture_attach(GPUFrameBuffer *gpu_fb, GPUTexture *tex, int slot, int mip)
{
+ FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
gpu_framebuffer_texture_attach_ex(fb, tex, slot, -1, mip);
}
void GPU_framebuffer_texture_layer_attach(
- GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
+ GPUFrameBuffer *gpu_fb, GPUTexture *tex, int slot, int layer, int mip)
{
+ FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
/* NOTE: We
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list