[Bf-blender-cvs] [2257d14] framebuffer: GPU Extensions: GPU_offscreen_draw()

Dalai Felinto noreply at git.blender.org
Tue Sep 29 19:56:34 CEST 2015


Commit: 2257d149cca4600dfeda8d86943cf18a4e8e720a
Author: Dalai Felinto
Date:   Tue Sep 29 13:41:27 2015 -0300
Branches: framebuffer
https://developer.blender.org/rB2257d149cca4600dfeda8d86943cf18a4e8e720a

GPU Extensions: GPU_offscreen_draw()

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_extensions.c

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 328623f..3cde0db 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -28,6 +28,7 @@ set(INC
 	../blenkernel
 	../blenlib
 	../bmesh
+	../editors/include
 	../imbuf
 	../makesdna
 	../makesrna
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 35b576a..b4aad45 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -36,6 +36,7 @@
 extern "C" {
 #endif
 
+struct bContext;
 struct Image;
 struct ImageUser;
 struct PreviewImage;
@@ -182,6 +183,7 @@ void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *b
 GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]);
 void GPU_offscreen_free(GPUOffScreen *ofs);
 void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
+void GPU_offscreen_draw(GPUOffScreen *ofs, struct bContext *C, float projection_matrix[4][4], float modelview_matrix[4][4]);
 void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
 void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels);
 int GPU_offscreen_width(const GPUOffScreen *ofs);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 762c6ea..cfdf6ca 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -42,6 +42,7 @@
 #include "BLI_math_base.h"
 #include "BLI_math_vector.h"
 
+#include "BKE_context.h"
 #include "BKE_global.h"
 
 #include "GPU_glew.h"
@@ -53,6 +54,12 @@
 
 #include "intern/gpu_private.h"
 
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+
+#include "ED_view3d.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -1495,6 +1502,71 @@ int GPU_offscreen_color_object(const GPUOffScreen *ofs)
 	return ofs->color->bindcode;
 }
 
+
+/* GPUOffScreen Draw*/
+
+static void gpu_offscreen_draw_setup(GPUOffScreen *ofs, GLint *r_viewport)
+{
+	glGetIntegerv(GL_VIEWPORT, r_viewport);
+	glViewport(0, 0, GPU_offscreen_width(ofs), GPU_offscreen_height(ofs));
+	GPU_offscreen_bind(ofs, true);
+}
+
+static void gpu_offscreen_draw_reset(GPUOffScreen *ofs, GLint viewport[4])
+{
+	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+	GPU_offscreen_unbind(ofs, true);
+}
+
+static void gpu_offscreen_draw_doit(
+        GPUOffScreen *ofs,
+        bContext *C,
+        float modelviewmat[4][4],
+		float projmat[4][4])
+{
+	View3D *v3d = CTX_wm_view3d(C);
+	Scene *scene = CTX_data_scene(C);
+	ARegion *ar = CTX_wm_region(C);
+
+	int width = GPU_offscreen_width(ofs);
+	int height = GPU_offscreen_height(ofs);
+	GPUFX *fx = GPU_fx_compositor_create();
+
+	/* full copy */
+	GPUFXSettings fx_settings = v3d->fx_settings;
+
+	ED_view3d_draw_offscreen_init(scene, v3d);
+
+	GPU_offscreen_bind(ofs, true); /* bind */
+
+	ED_view3d_draw_offscreen(
+	            scene,
+	            v3d,
+	            ar,
+	            width,
+	            height,
+	            projmat,
+	            modelviewmat,
+	            false,
+	            true,
+	            true,
+	            ofs,
+	            fx,
+	            &fx_settings,
+	            "");
+
+	GPU_fx_compositor_destroy(fx);
+	GPU_offscreen_unbind(ofs, true); /* unbind */
+}
+
+void GPU_offscreen_draw(GPUOffScreen *ofs, struct bContext *C, float projection_matrix[4][4], float modelview_matrix[4][4])
+{
+	GLint viewport[4];
+	gpu_offscreen_draw_setup(ofs, viewport);
+	gpu_offscreen_draw_doit(ofs, C, projection_matrix, modelview_matrix);
+	gpu_offscreen_draw_reset(ofs, viewport);
+}
+
 /* GPUShader */
 
 struct GPUShader {




More information about the Bf-blender-cvs mailing list