[Bf-blender-cvs] [407f8eed7d] blender2.8: OpenGL: Converted gpu_compositing.c to use batches.

Clément Foucault noreply at git.blender.org
Wed Mar 15 13:11:11 CET 2017


Commit: 407f8eed7def12faf60069a18eabbcc01abc210c
Author: Clément Foucault
Date:   Wed Mar 15 13:17:08 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB407f8eed7def12faf60069a18eabbcc01abc210c

OpenGL: Converted gpu_compositing.c to use batches.

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

M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_vert.glsl

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

diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index b4eaab7edf..5214b6b1ab 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -47,6 +47,7 @@
 #include "GPU_glew.h"
 #include "GPU_shader.h"
 #include "GPU_texture.h"
+#include "GPU_batch.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -193,7 +194,8 @@ struct GPUFX {
 	/* we have a stencil, restore the previous state */
 	bool restore_stencil;
 
-	unsigned int vbuffer;
+	Batch *quad_batch;
+	Batch *point_batch;
 };
 
 #if 0
@@ -269,12 +271,32 @@ GPUFX *GPU_fx_compositor_create(void)
 {
 	GPUFX *fx = MEM_callocN(sizeof(GPUFX), "GPUFX compositor");
 
-	glGenBuffers(1, &fx->vbuffer);
-	glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
-	glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), NULL, GL_STATIC_DRAW);
-	glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(float), fullscreencos);
-	glBufferSubData(GL_ARRAY_BUFFER, 8 * sizeof(float), 8 * sizeof(float), fullscreenuvs);
-	glBindBuffer(GL_ARRAY_BUFFER, 0);
+	/* Quad buffer */
+	static VertexFormat format = {0};
+	static unsigned int pos, uvs;
+	if (format.attrib_ct == 0) {
+		pos = add_attrib(&format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+		uvs = add_attrib(&format, "uvs", GL_FLOAT, 2, KEEP_FLOAT);
+	}
+	VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+	VertexBuffer_allocate_data(vbo, 4);
+	for (int i = 0; i < 4; ++i)	{
+		setAttrib(vbo, pos, i, fullscreencos[i]);
+		setAttrib(vbo, uvs, i, fullscreenuvs[i]);
+	}
+	fx->quad_batch = Batch_create(GL_TRIANGLE_STRIP, vbo, NULL);
+
+	/* Point Buffer */
+	static VertexFormat format_point = {0};
+	static unsigned int dummy_attrib;
+	if (format_point.attrib_ct == 0) {
+		dummy_attrib = add_attrib(&format_point, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+	}
+	float dummy[2] = {0.0f, 0.0f};
+	VertexBuffer *vbo_point = VertexBuffer_create_with_format(&format_point);
+	VertexBuffer_allocate_data(vbo_point, 1);
+	setAttrib(vbo_point, dummy_attrib, 0, &dummy);
+	fx->point_batch = Batch_create(GL_POINTS, vbo_point, NULL);
 
 	return fx;
 }
@@ -364,7 +386,8 @@ static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo)
 void GPU_fx_compositor_destroy(GPUFX *fx)
 {
 	cleanup_fx_gl_data(fx, true);
-	glDeleteBuffers(1, &fx->vbuffer);
+	Batch_discard_all(fx->quad_batch);
+	Batch_discard_all(fx->point_batch);
 	MEM_freeN(fx);
 }
 
@@ -702,19 +725,13 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 	/* disable writing to color buffer, it's depth only pass */
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 
-	/* set up quad buffer */
-	glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
-	glVertexPointer(2, GL_FLOAT, 0, NULL);
-	glTexCoordPointer(2, GL_FLOAT, 0, ((GLubyte *)NULL + 8 * sizeof(float)));
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 	depth_resolve_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_RESOLVE, false);
 
 	if (depth_resolve_shader) {
 		GPUDepthResolveInterface *interface = GPU_fx_shader_get_interface(depth_resolve_shader);
 
-		GPU_shader_bind(depth_resolve_shader);
+		/* set up quad buffer */
+		Batch_set_program(fx->quad_batch, GPU_shader_get_program(depth_resolve_shader));
 
 		GPU_texture_bind(fx->depth_buffer_xray, 0);
 		GPU_texture_compare_mode(fx->depth_buffer_xray, false);
@@ -722,7 +739,7 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 		GPU_shader_uniform_texture(depth_resolve_shader, interface->depth_uniform, fx->depth_buffer_xray);
 
 		/* draw */
-		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+		Batch_draw(fx->quad_batch);
 
 		/* disable bindings */
 		GPU_texture_compare_mode(fx->depth_buffer_xray, true);
@@ -734,10 +751,6 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 
-	glBindBuffer(GL_ARRAY_BUFFER, 0);
-	glDisableClientState(GL_VERTEX_ARRAY);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
 	glPopAttrib();
 }
 
@@ -774,13 +787,6 @@ bool GPU_fx_do_composite_pass(
 	src = fx->color_buffer;
 	target = fx->color_buffer_sec;
 
-	/* set up quad buffer */
-	glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
-	glVertexPointer(2, GL_FLOAT, 0, NULL);
-	glTexCoordPointer(2, GL_FLOAT, 0, ((GLubyte *)NULL + 8 * sizeof(float)));
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
 	/* full screen FX pass */
 
 	/* invert the view matrix */
@@ -808,8 +814,6 @@ bool GPU_fx_do_composite_pass(
 		viewvecs[1][2] = vec_far[2] - viewvecs[0][2];
 	}
 
-	/* set invalid color in case shader fails */
-	glColor3f(1.0, 0.0, 1.0);
 	glDisable(GL_DEPTH_TEST);
 
 	/* ssao pass */
@@ -830,7 +834,7 @@ bool GPU_fx_do_composite_pass(
 
 			GPUSSAOShaderInterface *interface = GPU_fx_shader_get_interface(ssao_shader);
 
-			GPU_shader_bind(ssao_shader);
+			Batch_set_program(fx->quad_batch, GPU_shader_get_program(ssao_shader));
 
 			GPU_shader_uniform_vector(ssao_shader, interface->ssao_uniform, 4, 1, ssao_params);
 			GPU_shader_uniform_vector(ssao_shader, interface->ssao_color_uniform, 4, 1, fx_ssao->color);
@@ -854,7 +858,7 @@ bool GPU_fx_do_composite_pass(
 			/* draw */
 			gpu_fx_bind_render_target(&passes_left, fx, ofs, target);
 
-			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+			Batch_draw(fx->quad_batch);
 
 			/* disable bindings */
 			GPU_texture_unbind(src);
@@ -912,11 +916,8 @@ bool GPU_fx_do_composite_pass(
 			if (!(dof_shader_pass1 && dof_shader_pass2 && dof_shader_pass3)) {
 				GPU_framebuffer_texture_unbind(fx->gbuffer, NULL);
 				GPU_framebuffer_restore();
-				glDisableClientState(GL_VERTEX_ARRAY);
-				glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
 				GPU_shader_unbind();
-				glBindBuffer(GL_ARRAY_BUFFER, 0);
 				return false;
 			}
 
@@ -926,7 +927,7 @@ bool GPU_fx_do_composite_pass(
 
 				GPUDOFHQPassOneInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass1);
 
-				GPU_shader_bind(dof_shader_pass1);
+				Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass1));
 
 				GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
 				GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
@@ -953,7 +954,8 @@ bool GPU_fx_do_composite_pass(
 
 				GPU_framebuffer_check_valid(fx->gbuffer, NULL);
 
-				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+				Batch_draw(fx->quad_batch);
+
 				/* disable bindings */
 				GPU_texture_filter_mode(src, true);
 				GPU_texture_unbind(src);
@@ -977,17 +979,16 @@ bool GPU_fx_do_composite_pass(
 
 				GPUDOFHQPassTwoInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass2);
 
-				GPU_shader_bind(dof_shader_pass2);
+				Batch_set_program(fx->point_batch, GPU_shader_get_program(dof_shader_pass2));
+
+				GPU_texture_bind(fx->dof_nearfar_coc, numslots++);
+				GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
+				GPU_texture_bind(fx->dof_half_downsampled_near, numslots++);
 
 				GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params);
 				GPU_shader_uniform_vector_int(dof_shader_pass2, interface->rendertargetdim_uniform, 2, 1, rendertargetdim);
 				GPU_shader_uniform_vector(dof_shader_pass2, interface->select_uniform, 2, 1, selection);
-
-				GPU_texture_bind(fx->dof_nearfar_coc, numslots++);
 				GPU_shader_uniform_texture(dof_shader_pass2, interface->coc_uniform, fx->dof_nearfar_coc);
-
-				GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
-				GPU_texture_bind(fx->dof_half_downsampled_near, numslots++);
 				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_far);
 				GPU_texture_filter_mode(fx->dof_half_downsampled_far, false);
 
@@ -1003,24 +1004,24 @@ bool GPU_fx_do_composite_pass(
 				glClearColor(0.0, 0.0, 0.0, 0.0);
 				glClear(GL_COLOR_BUFFER_BIT);
 				/* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
-				glDrawArraysInstancedARB(GL_POINTS, 0, 1, fx->dof_downsampled_w * fx->dof_downsampled_h);
+				Batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, NULL, NULL);
 
 				GPU_texture_unbind(fx->dof_half_downsampled_far);
 				GPU_framebuffer_texture_detach(fx->dof_far_blur);
 
-				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_near);
-				GPU_texture_filter_mode(fx->dof_half_downsampled_near, false);
-
 				selection[0] = 1.0f;
 				selection[1] = 0.0f;
 
 				GPU_shader_uniform_vector(dof_shader_pass2, interface->select_uniform, 2, 1, selection);
+				GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_near);
+				GPU_texture_filter_mode(fx->dof_half_downsampled_near, false);
 
 				GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_blur, 0);
 				/* have to clear the buffer unfortunately */
 				glClear(GL_COLOR_BUFFER_BIT);
 				/* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
-				glDrawArraysInstancedARB(GL_POINTS, 0, 1, fx->dof_downsampled_w * fx->dof_downsampled_h);
+				Batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, NULL, NULL);
+				Batch_done_using_program(fx->point_batch);
 
 				/* disable bindings */
 				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1032,6 +1033,7 @@ bool GPU_fx_do_composite_pass(
 				GPU_texture_unbind(fx->dof_nearfar_coc);
 
 				GPU_framebuffer_texture_unbind(fx->gbuffer, fx->dof_far_blur);
+				numslots = 0;
 			}
 
 			/* third pass, accumulate the near/far blur fields */
@@ -1040,7 +1042,7 @@ bool GPU_fx_do_composite_pass(
 
 				GPUDOFHQPassThreeInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass3);
 
-				GPU_shader_bind(dof_shader_pass3);
+				Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass3));
 
 				GPU_shader_uniform_vector(dof_shader_pass3, interface->dof_uniform, 4, 1, dof_params);
 
@@ -1066,7 +1068,7 @@ bool GPU_fx_do_composite_pass(
 				/* if this is the last pass, prepare for rendering on the frambuffer */
 				gpu_fx_bind_render_target(&passes_left, fx, ofs, target);
 
-				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list