[Bf-blender-cvs] [f937123116a] blender2.8: GPUFramebuffer: Refactor (part 1)

Clément Foucault noreply at git.blender.org
Sun Mar 25 21:33:23 CEST 2018


Commit: f937123116abd4ba34ff858fa03415362d6c07cf
Author: Clément Foucault
Date:   Sun Mar 25 14:18:39 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf937123116abd4ba34ff858fa03415362d6c07cf

GPUFramebuffer: Refactor (part 1)

Move some DRWFramebuffer functions to GPUFramebuffer.

===================================================================

M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/intern/gpu_framebuffer.c

===================================================================

diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 5af01e76309..93f16b342d1 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -36,6 +36,12 @@
 extern "C" {
 #endif
 
+typedef enum GPUFrameBufferBits{
+	GPU_COLOR_BIT    = (1 << 0),
+	GPU_DEPTH_BIT    = (1 << 1),
+	GPU_STENCIL_BIT  = (1 << 2),
+} GPUFrameBufferBits;
+
 typedef struct GPUFrameBuffer GPUFrameBuffer;
 typedef struct GPUOffScreen GPUOffScreen;
 struct GPUTexture;
@@ -67,8 +73,33 @@ unsigned int GPU_framebuffer_current_get(void);
 void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot);
 
 bool GPU_framebuffer_bound(GPUFrameBuffer *fb);
+/* Framebuffer operations */
+
+void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h);
 
 void GPU_framebuffer_restore(void);
+void GPU_framebuffer_clear(
+        GPUFrameBuffer *fb, GPUFrameBufferBits buffers,
+        const float clear_col[4], float clear_depth, unsigned int clear_stencil);
+
+#define GPU_framebuffer_clear_color(fb, col) \
+        GPU_framebuffer_clear(fb, GPU_COLOR_BIT, col, 0.0f, 0x00)
+
+#define GPU_framebuffer_clear_depth(fb, depth) \
+        GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, NULL, depth, 0x00)
+
+#define GPU_framebuffer_clear_color_depth(fb, col, depth) \
+        GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, col, depth, 0x00)
+
+#define GPU_framebuffer_clear_stencil(fb, stencil) \
+        GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, NULL, 0.0f, stencil)
+
+#define GPU_framebuffer_clear_depth_stencil(fb, depth, stencil) \
+        GPU_framebuffer_clear(fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, NULL, depth, stencil)
+
+#define GPU_framebuffer_clear_color_depth_stencil(fb, col, depth, stencil) \
+        GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, col, depth, stencil)
+
 
 void GPU_framebuffer_blit(
         GPUFrameBuffer *fb_read, int read_slot,
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index b911f6d9c7f..dbcf0dc4568 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -53,6 +53,15 @@ struct GPUFrameBuffer {
 	GPUTexture *depthtex;
 };
 
+static GLenum convert_buffer_bits_to_gl(GPUFrameBufferBits bits)
+{
+	GLbitfield mask = 0;
+	mask |= (bits & GPU_DEPTH_BIT) ? GL_DEPTH_BUFFER_BIT : 0;
+	mask |= (bits & GPU_STENCIL_BIT) ? GL_STENCIL_BUFFER_BIT : 0;
+	mask |= (bits & GPU_COLOR_BIT) ? GL_COLOR_BUFFER_BIT : 0;
+	return mask;
+}
+
 static void gpu_print_framebuffer_error(GLenum status, char err_out[256])
 {
 	const char *format = "GPUFrameBuffer: framebuffer status %s\n";
@@ -439,6 +448,40 @@ void GPU_framebuffer_restore(void)
 	}
 }
 
+#define CHECK_FRAMEBUFFER_IS_BOUND(_fb) \
+	BLI_assert(GPU_framebuffer_bound(_fb)); \
+	UNUSED_VARS_NDEBUG(_fb);
+
+/* Needs to be done after binding. */
+void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h)
+{
+	CHECK_FRAMEBUFFER_IS_BOUND(fb);
+
+	glViewport(x, y, w, h);
+}
+
+void GPU_framebuffer_clear(
+        GPUFrameBuffer *fb, GPUFrameBufferBits buffers,
+        const float clear_col[4], float clear_depth, unsigned int clear_stencil)
+{
+	CHECK_FRAMEBUFFER_IS_BOUND(fb);
+
+	if (buffers & GPU_COLOR_BIT) {
+		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+		glClearColor(clear_col[0], clear_col[1], clear_col[2], clear_col[3]);
+	}
+	if (buffers & GPU_DEPTH_BIT) {
+		glDepthMask(GL_TRUE);
+		glClearDepth(clear_depth);
+	}
+	if (buffers & GPU_STENCIL_BIT) {
+		glStencilMask(clear_stencil);
+	}
+
+	GLbitfield mask = convert_buffer_bits_to_gl(buffers);
+	glClear(mask);
+}
+
 void GPU_framebuffer_blit(
         GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write,
         int write_slot, bool use_depth, bool use_stencil)



More information about the Bf-blender-cvs mailing list