[Bf-blender-cvs] [40b1d29] viewport_experiments: Merge branch 'master' into viewport_experiments
Antony Riakiotakis
noreply at git.blender.org
Tue Nov 18 13:50:13 CET 2014
Commit: 40b1d29ec735c605c60ed15066c8efefb26ee224
Author: Antony Riakiotakis
Date: Tue Nov 18 13:49:57 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rB40b1d29ec735c605c60ed15066c8efefb26ee224
Merge branch 'master' into viewport_experiments
Conflicts:
source/blender/gpu/intern/gpu_extensions.c
===================================================================
===================================================================
diff --cc source/blender/gpu/GPU_extensions.h
index 8dc9f84,b2378f0..6baa11f
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@@ -150,8 -149,6 +152,8 @@@ void GPU_framebuffer_slot_bind(GPUFrame
void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
void GPU_framebuffer_free(GPUFrameBuffer *fb);
- void GPU_framebuffer_bind(GPUFrameBuffer *fb);
++void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot);
+
void GPU_framebuffer_restore(void);
void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex);
diff --cc source/blender/gpu/intern/gpu_compositing.c
index 662eb82,0000000..1e0c3c9
mode 100644,000000..100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@@ -1,792 -1,0 +1,790 @@@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Antony Riakiotakis.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/gpu/intern/gpu_compositing.c
+ * \ingroup gpu
+ *
+ * System that manages framebuffer compositing.
+ */
+
+#include "BLI_sys_types.h"
+#include "BLI_rect.h"
+#include "BLI_math.h"
+#include "BLI_rand.h"
+
+#include "DNA_vec_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_gpu_types.h"
+
+#include "GPU_extensions.h"
+#include "GPU_compositing.h"
+
+#include "GL/glew.h"
+
+#include "MEM_guardedalloc.h"
+
+static const float fullscreencos[4][2] = {{-1.0f, -1.0f}, {1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, 1.0f}};
+static const float fullscreenuvs[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
+
+static float ssao_sample_directions[16][2];
+static bool init = false;
+
+struct GPUFX {
+ /* we borrow the term gbuffer from deferred rendering however this is just a regular
+ * depth/color framebuffer. Could be extended later though */
+ GPUFrameBuffer *gbuffer;
+
+ /* texture bound to the first color attachment of the gbuffer */
+ GPUTexture *color_buffer;
+
+ /* second texture used for ping-pong compositing */
+ GPUTexture *color_buffer_sec;
+
+ /* all those buffers below have to coexist. Fortunately they are all quarter sized (1/16th of memory) of original framebuffer */
+ float dof_near_w;
+ float dof_near_h;
+
+ /* texture used for near coc and color blurring calculation */
+ GPUTexture *dof_near_coc_buffer;
+ /* blurred near coc buffer. */
+ GPUTexture *dof_near_coc_blurred_buffer;
+ /* final near coc buffer. */
+ GPUTexture *dof_near_coc_final_buffer;
+
+ /* texture bound to the depth attachment of the gbuffer */
+ GPUTexture *depth_buffer;
+
+ /* texture used for jittering for various effects */
+ GPUTexture *jitter_buffer;
+
+ /* dimensions of the gbuffer */
+ int gbuffer_dim[2];
+
+ GPUFXOptions options;
+
+ /* or-ed flags of enabled effects */
+ int effects;
+
+ /* number of passes, needed to detect if ping pong buffer allocation is needed */
+ int num_passes;
+
+ /* we have a stencil, restore the previous state */
+ bool restore_stencil;
+};
+
+
+/* generate a new FX compositor */
+GPUFX *GPU_create_fx_compositor(void)
+{
+ GPUFX *fx = MEM_callocN(sizeof(GPUFX), "GPUFX compositor");
+
+ return fx;
+}
+
+static void cleanup_fx_dof_buffers(GPUFX *fx)
+{
+ if (fx->dof_near_coc_blurred_buffer) {
+ GPU_texture_free(fx->dof_near_coc_blurred_buffer);
+ fx->dof_near_coc_blurred_buffer = NULL;
+ }
+ if (fx->dof_near_coc_buffer) {
+ GPU_texture_free(fx->dof_near_coc_buffer);
+ fx->dof_near_coc_buffer = NULL;
+ }
+ if (fx->dof_near_coc_final_buffer) {
+ GPU_texture_free(fx->dof_near_coc_final_buffer);
+ fx->dof_near_coc_final_buffer = NULL;
+ }
+}
+
+static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo)
+{
+ if (fx->color_buffer) {
- GPU_framebuffer_texture_detach(fx->gbuffer, fx->color_buffer);
++ GPU_framebuffer_texture_detach(fx->color_buffer);
+ GPU_texture_free(fx->color_buffer);
+ fx->color_buffer = NULL;
+ }
+
+ if (fx->color_buffer_sec) {
- GPU_framebuffer_texture_detach(fx->gbuffer, fx->color_buffer_sec);
++ GPU_framebuffer_texture_detach(fx->color_buffer_sec);
+ GPU_texture_free(fx->color_buffer_sec);
+ fx->color_buffer_sec = NULL;
+ }
+
+ if (fx->depth_buffer) {
- GPU_framebuffer_texture_detach(fx->gbuffer, fx->depth_buffer);
++ GPU_framebuffer_texture_detach(fx->depth_buffer);
+ GPU_texture_free(fx->depth_buffer);
+ fx->depth_buffer = NULL;
+ }
+
+ cleanup_fx_dof_buffers(fx);
+
+ if (fx->jitter_buffer && do_fbo) {
+ GPU_texture_free(fx->jitter_buffer);
+ fx->jitter_buffer = NULL;
+ }
+
+ if (fx->gbuffer && do_fbo) {
+ GPU_framebuffer_free(fx->gbuffer);
+ fx->gbuffer = NULL;
+ }
+}
+
+/* destroy a text compositor */
+void GPU_destroy_fx_compositor(GPUFX *fx)
+{
+ cleanup_fx_gl_data(fx, true);
+ MEM_freeN(fx);
+}
+
+static GPUTexture * create_jitter_texture (void)
+{
+ float jitter [64 * 64][2];
+ int i;
+
+ for (i = 0; i < 64 * 64; i++) {
+ jitter[i][0] = BLI_frand();
+ jitter[i][1] = BLI_frand();
+ normalize_v2(jitter[i]);
+ }
+
+ return GPU_texture_create_2D_procedural(64, 64, &jitter[0][0], NULL);
+}
+
+static void create_sample_directions(void)
+{
+ int i;
+ float dir[4][2] = {{1.0f, 0.0f},
+ {0.0f, 1.0f},
+ {-1.0f, 0.0f},
+ {0.0f, -1.0f}};
+
+ for (i = 0; i < 4; i++) {
+ copy_v2_v2(ssao_sample_directions[i], dir[i]);
+ }
+
+ for (i = 0; i < 4; i++) {
+ float mat[2][2];
+ rotate_m2(mat, M_PI/4.0);
+
+ copy_v2_v2(ssao_sample_directions[i + 4], ssao_sample_directions[i]);
+ mul_m2v2(mat, ssao_sample_directions[i + 4]);
+ }
+
+ for (i = 0; i < 8; i++) {
+ float mat[2][2];
+ rotate_m2(mat, M_PI/8.0);
+ copy_v2_v2(ssao_sample_directions[i + 8], ssao_sample_directions[i]);
+ mul_m2v2(mat, ssao_sample_directions[i + 8]);
+ }
+
+ init = true;
+}
+
+bool GPU_initialize_fx_passes(GPUFX *fx, rcti *rect, rcti *scissor_rect, int fxflags, GPUFXOptions *options)
+{
+ int w = BLI_rcti_size_x(rect) + 1, h = BLI_rcti_size_y(rect) + 1;
+ char err_out[256];
+ int num_passes = 0;
+
+ fx->effects = 0;
+
+ if (!options) {
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+
+ /* disable effects if no options passed for them */
+ if (!options->dof_options) {
+ fxflags &= ~GPU_FX_DEPTH_OF_FIELD;
+ }
+ if (!options->ssao_options) {
+ fxflags &= ~GPU_FX_SSAO;
+ }
+
+ if (!fxflags) {
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+
+ fx->num_passes = 0;
+ /* dof really needs a ping-pong buffer to work */
+ if (fxflags & GPU_FX_DEPTH_OF_FIELD) {
+ num_passes++;
+ }
+ if (fxflags & GPU_FX_SSAO)
+ num_passes++;
+
+ if (!fx->gbuffer)
+ fx->gbuffer = GPU_framebuffer_create();
+
+ /* try creating the jitter texture */
+ if (!fx->jitter_buffer)
+ fx->jitter_buffer = create_jitter_texture();
+
+ if (!fx->gbuffer)
+ return false;
+
+ /* check if color buffers need recreation */
+ if (!fx->color_buffer || !fx->depth_buffer || w != fx->gbuffer_dim[0] || h != fx->gbuffer_dim[1]) {
+ cleanup_fx_gl_data(fx, false);
+
+ if (!(fx->color_buffer = GPU_texture_create_2D(w, h, NULL, err_out))) {
+ printf(".256%s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+
+ if (!(fx->depth_buffer = GPU_texture_create_depth(w, h, err_out))) {
+ printf("%.256s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+ }
+
+ /* create textures for dof effect */
+ if (fxflags & GPU_FX_DEPTH_OF_FIELD) {
+ if (!fx->dof_near_coc_buffer || !fx->dof_near_coc_blurred_buffer || !fx->dof_near_coc_final_buffer) {
+ fx->dof_near_w = w / 4;
+ fx->dof_near_h = h / 4;
+
+ if (!(fx->dof_near_coc_buffer = GPU_texture_create_2D(fx->dof_near_w, fx->dof_near_h, NULL, err_out))) {
+ printf("%.256s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+ if (!(fx->dof_near_coc_blurred_buffer = GPU_texture_create_2D(fx->dof_near_w, fx->dof_near_h, NULL, err_out))) {
+ printf("%.256s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+ if (!(fx->dof_near_coc_final_buffer = GPU_texture_create_2D(fx->dof_near_w, fx->dof_near_h, NULL, err_out))) {
+ printf("%.256s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+ }
+ }
+ else {
+ /* cleanup unnecessary buffers */
+ cleanup_fx_dof_buffers(fx);
+ }
+
+ /* we need to pass data between shader stages, allocate an extra color buffer */
+ if (num_passes > 1) {
+ if(!fx->color_buffer_sec) {
+ if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, err_out))) {
+ printf(".256%s\n", err_out);
+ cleanup_fx_gl_data(fx, true);
+ return false;
+ }
+ }
+ }
+ else {
+ if (fx->color_buffer_sec) {
- GPU_framebuffer_texture_detach(fx->gbuffer, fx->color_buffer_sec);
++ GPU_framebuffer_texture_detach(fx->color_buffer_sec);
+ GPU_texture_free(fx->color_buffer_sec);
+ fx->color_buffer_sec = NULL;
+ }
+ }
+
+ /* bind the buffers */
+
+ /* first depth buffer, because system assumes read/write buffers */
- if(!GPU_framebuffe
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list