[Bf-blender-cvs] [5373b4a] viewport_experiments: Merge branch 'master' into viewport_experiments

Antony Riakiotakis noreply at git.blender.org
Tue Nov 25 16:32:27 CET 2014


Commit: 5373b4a8b17eb6f25cacaa979f196cea32910f79
Author: Antony Riakiotakis
Date:   Tue Nov 25 16:31:55 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rB5373b4a8b17eb6f25cacaa979f196cea32910f79

Merge branch 'master' into viewport_experiments

Conflicts:
	source/blender/editors/space_view3d/view3d_draw.c
	source/blender/gpu/intern/gpu_extensions.c

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



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

diff --cc source/blender/editors/space_view3d/view3d_draw.c
index 45dc6ff,d4a0c01..130bee8
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@@ -2844,27 -3010,20 +3017,23 @@@ void ED_view3d_draw_offscreen(Scene *sc
  		GPU_free_images_anim();
  	}
  
 +	/* setup view matrices before fx or unbinding the offscreen buffers will cause issues */
 +	view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat);
 +
 +	/* framebuffer fx needed, we need to draw offscreen first */
 +	if (v3d->shader_fx && fx) {
 +		do_compositing = GPU_initialize_fx_passes(fx, &ar->winrct, NULL, fxflags, fxoptions);
 +	}
 +
  	/* clear opengl buffers */
  	if (do_sky) {
- 		float sky_color[3];
- 
- 		ED_view3d_offscreen_sky_color_get(scene, sky_color);
- 		glClearColor(sky_color[0], sky_color[1], sky_color[2], 1.0f);
+ 		view3d_main_area_clear(scene, v3d, ar, true);
  	}
  	else {
  		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		
  	}
  
- 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 -
 -	/* setup view matrices */
 -	view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat);
 -
--
  	/* main drawing call */
  	view3d_draw_objects(NULL, scene, v3d, ar, NULL, do_bgpic, true);
  
@@@ -3444,22 -3418,8 +3441,22 @@@ static void view3d_main_area_draw_objec
  	}
  #endif
  
 +	/* framebuffer fx needed, we need to draw offscreen first */
 +	if (v3d->shader_fx) {
 +		GPUFXOptions options;
 +		BKE_screen_view3d_ensure_FX(v3d);
 +		options = *v3d->fxoptions;
 +		if (!rv3d->compositor)
 +			rv3d->compositor = GPU_create_fx_compositor();
 +		
 +		if (rv3d->persp == RV3D_CAMOB && v3d->camera)
 +			BKE_GPU_dof_from_camera(v3d->camera, &options);
 +
 +		do_compositing = GPU_initialize_fx_passes(rv3d->compositor, &ar->winrct, &ar->drawrct, v3d->shader_fx, &options);
 +	}
 +	
  	/* clear the background */
- 	view3d_main_area_clear(scene, v3d, ar);
+ 	view3d_main_area_clear(scene, v3d, ar, false);
  
  	/* enables anti-aliasing for 3D view drawing */
  	if (U.ogl_multisamples != USER_MULTISAMPLE_NONE) {
diff --cc source/blender/gpu/GPU_extensions.h
index 6baa11f,bb0cf2d..d95ff44
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@@ -151,9 -148,8 +151,10 @@@ void GPU_framebuffer_texture_detach(GPU
  void GPU_framebuffer_slot_bind(GPUFrameBuffer *fb, int slot);
  void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
  void GPU_framebuffer_free(GPUFrameBuffer *fb);
+ bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]);
  
 +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 1e0c3c9,0000000..ad25ee4
mode 100644,000000..100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@@ -1,790 -1,0 +1,793 @@@
 +/*
 + * ***** 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->color_buffer);
 +		GPU_texture_free(fx->color_buffer);
 +		fx->color_buffer = NULL;
 +	}
 +
 +	if (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->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, 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list