diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_compositing.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_compositing.c | 339 |
1 files changed, 187 insertions, 152 deletions
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c index 2f2a16f9e1d..f0692b91a80 100644 --- a/source/blender/gpu/intern/gpu_compositing.c +++ b/source/blender/gpu/intern/gpu_compositing.c @@ -42,11 +42,13 @@ #include "DNA_gpu_types.h" #include "GPU_compositing.h" +#include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_framebuffer.h" #include "GPU_glew.h" #include "GPU_shader.h" #include "GPU_texture.h" +#include "GPU_batch.h" #include "MEM_guardedalloc.h" @@ -193,7 +195,10 @@ struct GPUFX { /* we have a stencil, restore the previous state */ bool restore_stencil; - unsigned int vbuffer; + Batch *quad_batch; + Batch *point_batch; + + struct GPUStateValues attribs; }; #if 0 @@ -225,7 +230,13 @@ static GPUTexture * create_concentric_sample_texture(int side) } } - tex = GPU_texture_create_1D_procedural(side * side, texels, NULL); + tex = GPU_texture_create_1D_custom(side * side, 2, GPU_RG16F, (float *)texels, NULL); + + /* Set parameters */ + GPU_texture_bind(tex, 0); + GPU_texture_filter_mode(tex, false); + GPU_texture_unbind(tex); + MEM_freeN(texels); return tex; } @@ -247,7 +258,13 @@ static GPUTexture *create_spiral_sample_texture(int numsaples) texels[i][1] = r * sinf(phi); } - tex = GPU_texture_create_1D_procedural(numsaples, (float *)texels, NULL); + tex = GPU_texture_create_1D_custom(numsaples, 2, GPU_RG16F, (float *)texels, NULL); + + /* Set parameters */ + GPU_texture_bind(tex, 0); + GPU_texture_filter_mode(tex, false); + GPU_texture_unbind(tex); + MEM_freeN(texels); return tex; } @@ -257,12 +274,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 = VertexFormat_add_attrib(&format, "pos", COMP_F32, 2, KEEP_FLOAT); + uvs = VertexFormat_add_attrib(&format, "uvs", COMP_F32, 2, KEEP_FLOAT); + } + VertexBuffer *vbo = VertexBuffer_create_with_format(&format); + VertexBuffer_allocate_data(vbo, 4); + for (int i = 0; i < 4; ++i) { + VertexBuffer_set_attrib(vbo, pos, i, fullscreencos[i]); + VertexBuffer_set_attrib(vbo, uvs, i, fullscreenuvs[i]); + } + fx->quad_batch = Batch_create(PRIM_TRIANGLE_STRIP, vbo, NULL); + + /* Point Buffer */ + static VertexFormat format_point = {0}; + static unsigned int dummy_attrib; + if (format_point.attrib_ct == 0) { + dummy_attrib = VertexFormat_add_attrib(&format_point, "pos", COMP_F32, 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); + VertexBuffer_set_attrib(vbo_point, dummy_attrib, 0, &dummy); + fx->point_batch = Batch_create(PRIM_POINTS, vbo_point, NULL); return fx; } @@ -352,12 +389,14 @@ 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); } static GPUTexture * create_jitter_texture(void) { + GPUTexture *tex; float jitter[64 * 64][2]; int i; @@ -367,7 +406,15 @@ static GPUTexture * create_jitter_texture(void) normalize_v2(jitter[i]); } - return GPU_texture_create_2D_procedural(64, 64, &jitter[0][0], true, NULL); + tex = GPU_texture_create_2D_custom(64, 64, 2, GPU_RG16F, &jitter[0][0], NULL); + + /* Set parameters */ + GPU_texture_bind(tex, 0); + GPU_texture_filter_mode(tex, false); + GPU_texture_wrap_mode(tex, true); + GPU_texture_unbind(tex); + + return tex; } @@ -382,9 +429,6 @@ bool GPU_fx_compositor_initialize_passes( fx->effects = 0; - if (!GLEW_EXT_framebuffer_object) - return false; - if (!fx_settings) { cleanup_fx_gl_data(fx, true); return false; @@ -436,7 +480,7 @@ bool GPU_fx_compositor_initialize_passes( 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, GPU_HDR_NONE, err_out))) { + 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; @@ -488,38 +532,42 @@ bool GPU_fx_compositor_initialize_passes( { if (!(fx->dof_half_downsampled_near = GPU_texture_create_2D( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out))) + fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); return false; } if (!(fx->dof_half_downsampled_far = GPU_texture_create_2D( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out))) + fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); return false; } - if (!(fx->dof_nearfar_coc = GPU_texture_create_2D_procedural( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, false, err_out))) + + if (!(fx->dof_nearfar_coc = GPU_texture_create_2D_custom( + fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RG16F, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); return false; } + GPU_texture_bind(fx->dof_nearfar_coc, 0); + GPU_texture_filter_mode(fx->dof_nearfar_coc, false); + GPU_texture_wrap_mode(fx->dof_nearfar_coc, false); + GPU_texture_unbind(fx->dof_nearfar_coc); - - if (!(fx->dof_near_blur = GPU_texture_create_2D( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out))) + if (!(fx->dof_near_blur = GPU_texture_create_2D_custom( + fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RGBA16F, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); return false; } - if (!(fx->dof_far_blur = GPU_texture_create_2D( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out))) + if (!(fx->dof_far_blur = GPU_texture_create_2D_custom( + fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RGBA16F, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); @@ -534,21 +582,21 @@ bool GPU_fx_compositor_initialize_passes( if (!fx->dof_near_coc_buffer || !fx->dof_near_coc_blurred_buffer || !fx->dof_near_coc_final_buffer) { if (!(fx->dof_near_coc_buffer = GPU_texture_create_2D( - fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out))) + fx->dof_downsampled_w, fx->dof_downsampled_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_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out))) + fx->dof_downsampled_w, fx->dof_downsampled_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_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out))) + fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out))) { printf("%.256s\n", err_out); cleanup_fx_gl_data(fx, true); @@ -567,7 +615,7 @@ bool GPU_fx_compositor_initialize_passes( /* 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, GPU_HDR_NONE, err_out))) { + 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; @@ -585,11 +633,8 @@ bool GPU_fx_compositor_initialize_passes( /* bind the buffers */ /* first depth buffer, because system assumes read/write buffers */ - if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, err_out)) - printf("%.256s\n", err_out); - - if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, err_out)) - printf("%.256s\n", err_out); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, 0); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, 0); if (!GPU_framebuffer_check_valid(fx->gbuffer, err_out)) printf("%.256s\n", err_out); @@ -600,7 +645,7 @@ bool GPU_fx_compositor_initialize_passes( if (scissor_rect) { int w_sc = BLI_rcti_size_x(scissor_rect) + 1; int h_sc = BLI_rcti_size_y(scissor_rect) + 1; - glPushAttrib(GL_SCISSOR_BIT); + gpuSaveState(&fx->attribs, GPU_SCISSOR_BIT); glEnable(GL_SCISSOR_TEST); glScissor(scissor_rect->xmin - rect->xmin, scissor_rect->ymin - rect->ymin, w_sc, h_sc); @@ -634,7 +679,7 @@ static void gpu_fx_bind_render_target(int *passes_left, GPUFX *fx, struct GPUOff } else { /* bind the ping buffer to the color buffer */ - GPU_framebuffer_texture_attach(fx->gbuffer, target, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, target, 0, 0); } } @@ -663,8 +708,7 @@ void GPU_fx_compositor_setup_XRay_pass(GPUFX *fx, bool do_xray) GPU_framebuffer_texture_detach(fx->depth_buffer); /* first depth buffer, because system assumes read/write buffers */ - if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, err_out)) - printf("%.256s\n", err_out); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, 0); } @@ -674,39 +718,35 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx) GPU_framebuffer_texture_detach(fx->depth_buffer_xray); /* attach regular framebuffer */ - GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, 0); /* full screen quad where we will always write to depth buffer */ - glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_SCISSOR_BIT); + gpuSaveState(&fx->attribs, GPU_DEPTH_BUFFER_BIT | GPU_SCISSOR_BIT); glDepthFunc(GL_ALWAYS); /* disable scissor from sculpt if any */ glDisable(GL_SCISSOR_TEST); /* 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_shader_get_interface(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_shader_get_interface(depth_resolve_shader)); GPU_texture_bind(fx->depth_buffer_xray, 0); - GPU_texture_filter_mode(fx->depth_buffer_xray, false, true); + GPU_texture_compare_mode(fx->depth_buffer_xray, false); + GPU_texture_filter_mode(fx->depth_buffer_xray, true); 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_filter_mode(fx->depth_buffer_xray, true, false); + GPU_texture_compare_mode(fx->depth_buffer_xray, true); + GPU_texture_filter_mode(fx->depth_buffer_xray, false); GPU_texture_unbind(fx->depth_buffer_xray); GPU_shader_unbind(); @@ -714,11 +754,7 @@ 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(); + gpuRestoreState(&fx->attribs); } @@ -748,19 +784,13 @@ bool GPU_fx_do_composite_pass( GPU_framebuffer_texture_detach(fx->color_buffer); GPU_framebuffer_texture_detach(fx->depth_buffer); - if (fx->restore_stencil) - glPopAttrib(); + if (fx->restore_stencil) { + gpuRestoreState(&fx->attribs); + } 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 */ @@ -788,8 +818,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 */ @@ -810,9 +838,9 @@ bool GPU_fx_do_composite_pass( ssao_params[3] = (passes_left == 1 && !ofs) ? dfdyfac[0] : dfdyfac[1]; - GPUSSAOShaderInterface *interface = GPU_shader_get_interface(ssao_shader); + 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_get_interface(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); @@ -823,7 +851,8 @@ bool GPU_fx_do_composite_pass( GPU_shader_uniform_texture(ssao_shader, interface->color_uniform, src); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, true); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, true); GPU_shader_uniform_texture(ssao_shader, interface->depth_uniform, fx->depth_buffer); GPU_texture_bind(fx->jitter_buffer, numslots++); @@ -835,11 +864,12 @@ 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); - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_texture_unbind(fx->depth_buffer); GPU_texture_unbind(fx->jitter_buffer); GPU_texture_unbind(fx->ssao_spiral_samples_tex); @@ -892,11 +922,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; } @@ -904,9 +931,9 @@ bool GPU_fx_do_composite_pass( { float invrendertargetdim[2] = {1.0f / fx->dof_downsampled_w, 1.0f / fx->dof_downsampled_h}; - GPUDOFHQPassOneInterface *interface = GPU_shader_get_interface(dof_shader_pass1); + 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_get_interface(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); @@ -915,28 +942,31 @@ bool GPU_fx_do_composite_pass( GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, false); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer); GPU_texture_bind(src, numslots++); /* disable filtering for the texture so custom downsample can do the right thing */ - GPU_texture_filter_mode(src, false, false); + GPU_texture_filter_mode(src, false); GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, src); /* target is the downsampled coc buffer */ - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_near, 0, NULL); - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_far, 1, NULL); - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_nearfar_coc, 2, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_near, 0, 0); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_far, 1, 0); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_nearfar_coc, 2, 0); /* binding takes care of setting the viewport to the downsampled size */ GPU_framebuffer_slots_bind(fx->gbuffer, 0); 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, false, true); + GPU_texture_filter_mode(src, true); GPU_texture_unbind(src); - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_texture_unbind(fx->depth_buffer); GPU_framebuffer_texture_detach(fx->dof_half_downsampled_near); @@ -953,24 +983,23 @@ bool GPU_fx_do_composite_pass( int rendertargetdim[2] = {fx->dof_downsampled_w, fx->dof_downsampled_h}; float selection[2] = {0.0f, 1.0f}; - GPUDOFHQPassTwoInterface *interface = GPU_shader_get_interface(dof_shader_pass2); + 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_shader_get_interface(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, false); + GPU_texture_filter_mode(fx->dof_half_downsampled_far, false); /* target is the downsampled coc buffer */ - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0, 0); GPU_texture_bind_as_framebuffer(fx->dof_far_blur); glDisable(GL_DEPTH_TEST); @@ -981,24 +1010,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, 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, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_blur, 0, 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); @@ -1010,15 +1039,16 @@ 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 */ { float invrendertargetdim[2] = {1.0f / fx->dof_downsampled_w, 1.0f / fx->dof_downsampled_h}; - GPUDOFHQPassThreeInterface *interface = GPU_shader_get_interface(dof_shader_pass3); + 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_get_interface(dof_shader_pass3)); GPU_shader_uniform_vector(dof_shader_pass3, interface->dof_uniform, 4, 1, dof_params); @@ -1027,14 +1057,15 @@ bool GPU_fx_do_composite_pass( GPU_texture_bind(fx->dof_near_blur, numslots++); GPU_shader_uniform_texture(dof_shader_pass3, interface->near_uniform, fx->dof_near_blur); - GPU_texture_filter_mode(fx->dof_near_blur, false, true); + GPU_texture_filter_mode(fx->dof_near_blur, true); GPU_texture_bind(fx->dof_far_blur, numslots++); GPU_shader_uniform_texture(dof_shader_pass3, interface->far_uniform, fx->dof_far_blur); - GPU_texture_filter_mode(fx->dof_far_blur, false, true); + GPU_texture_filter_mode(fx->dof_far_blur, true); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, false); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_shader_uniform_texture(dof_shader_pass3, interface->depth_uniform, fx->depth_buffer); GPU_texture_bind(src, numslots++); @@ -1043,13 +1074,13 @@ 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); + Batch_draw(fx->quad_batch); /* disable bindings */ GPU_texture_unbind(fx->dof_near_blur); GPU_texture_unbind(fx->dof_far_blur); GPU_texture_unbind(src); - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); GPU_texture_unbind(fx->depth_buffer); /* may not be attached, in that case this just returns */ @@ -1085,11 +1116,8 @@ bool GPU_fx_do_composite_pass( if (!(dof_shader_pass1 && dof_shader_pass2 && dof_shader_pass3 && dof_shader_pass4 && dof_shader_pass5)) { 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; } @@ -1097,9 +1125,9 @@ bool GPU_fx_do_composite_pass( { float invrendertargetdim[2] = {1.0f / fx->gbuffer_dim[0], 1.0f / fx->gbuffer_dim[1]}; - GPUDOFPassOneInterface *interface = GPU_shader_get_interface(dof_shader_pass1); + GPUDOFPassOneInterface *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_get_interface(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); @@ -1109,18 +1137,20 @@ bool GPU_fx_do_composite_pass( GPU_shader_uniform_texture(dof_shader_pass1, interface->color_uniform, src); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, true); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, true); GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer); /* target is the downsampled coc buffer */ - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, 0); /* binding takes care of setting the viewport to the downsampled size */ GPU_texture_bind_as_framebuffer(fx->dof_near_coc_buffer); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + Batch_draw(fx->quad_batch); /* disable bindings */ GPU_texture_unbind(src); - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_texture_unbind(fx->depth_buffer); GPU_framebuffer_texture_detach(fx->dof_near_coc_buffer); @@ -1134,32 +1164,37 @@ bool GPU_fx_do_composite_pass( float tmp = invrendertargetdim[0]; invrendertargetdim[0] = 0.0f; - GPUDOFPassTwoInterface *interface = GPU_shader_get_interface(dof_shader_pass2); + GPUDOFPassTwoInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass2); dof_params[2] = GPU_texture_width(fx->dof_near_coc_blurred_buffer) / (scale_camera * fx_dof->sensor); /* Blurring vertically */ - GPU_shader_bind(dof_shader_pass2); + Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2)); GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params); GPU_shader_uniform_vector(dof_shader_pass2, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim); GPU_shader_uniform_vector(dof_shader_pass2, interface->viewvecs_uniform, 4, 3, viewvecs[0]); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, true); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, true); GPU_shader_uniform_texture(dof_shader_pass2, interface->depth_uniform, fx->depth_buffer); GPU_texture_bind(fx->dof_near_coc_buffer, numslots++); GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_buffer); /* use final buffer as a temp here */ - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, 0); /* Drawing quad */ - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + Batch_draw(fx->quad_batch); + + /* Rebind Shader */ + Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass2), GPU_shader_get_interface(dof_shader_pass2)); /* *unbind/detach */ GPU_texture_unbind(fx->dof_near_coc_buffer); + GPU_framebuffer_texture_detach(fx->dof_near_coc_final_buffer); /* Blurring horizontally */ @@ -1170,11 +1205,13 @@ bool GPU_fx_do_composite_pass( GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++); GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_final_buffer); - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, 0, NULL); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, 0, 0); + + Batch_draw(fx->quad_batch); /* *unbind/detach */ - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_texture_unbind(fx->depth_buffer); GPU_texture_unbind(fx->dof_near_coc_final_buffer); @@ -1187,9 +1224,9 @@ bool GPU_fx_do_composite_pass( /* third pass, calculate near coc */ { - GPUDOFPassThreeInterface *interface = GPU_shader_get_interface(dof_shader_pass3); + GPUDOFPassThreeInterface *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_get_interface(dof_shader_pass3)); GPU_texture_bind(fx->dof_near_coc_buffer, numslots++); GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_downsampled, fx->dof_near_coc_buffer); @@ -1197,9 +1234,9 @@ bool GPU_fx_do_composite_pass( GPU_texture_bind(fx->dof_near_coc_blurred_buffer, numslots++); GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_blurred, fx->dof_near_coc_blurred_buffer); - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, 0); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + Batch_draw(fx->quad_batch); /* disable bindings */ GPU_texture_unbind(fx->dof_near_coc_buffer); GPU_texture_unbind(fx->dof_near_coc_blurred_buffer); @@ -1215,17 +1252,17 @@ bool GPU_fx_do_composite_pass( float invrendertargetdim[2] = {1.0f / GPU_texture_width(fx->dof_near_coc_blurred_buffer), 1.0f / GPU_texture_height(fx->dof_near_coc_blurred_buffer)}; - GPUDOFPassFourInterface *interface = GPU_shader_get_interface(dof_shader_pass4); + GPUDOFPassFourInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass4); - GPU_shader_bind(dof_shader_pass4); + Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass4), GPU_shader_get_interface(dof_shader_pass4)); GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++); GPU_shader_uniform_texture(dof_shader_pass4, interface->near_coc_downsampled, fx->dof_near_coc_final_buffer); GPU_shader_uniform_vector(dof_shader_pass4, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim); - GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL); + GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, 0); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + Batch_draw(fx->quad_batch); /* disable bindings */ GPU_texture_unbind(fx->dof_near_coc_final_buffer); @@ -1240,9 +1277,9 @@ bool GPU_fx_do_composite_pass( { float invrendertargetdim[2] = {1.0f / fx->gbuffer_dim[0], 1.0f / fx->gbuffer_dim[1]}; - GPUDOFPassFiveInterface *interface = GPU_shader_get_interface(dof_shader_pass5); + GPUDOFPassFiveInterface *interface = GPU_fx_shader_get_interface(dof_shader_pass5); - GPU_shader_bind(dof_shader_pass5); + Batch_set_program(fx->quad_batch, GPU_shader_get_program(dof_shader_pass5), GPU_shader_get_interface(dof_shader_pass5)); GPU_shader_uniform_vector(dof_shader_pass5, interface->dof_uniform, 4, 1, dof_params); GPU_shader_uniform_vector(dof_shader_pass5, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim); @@ -1258,18 +1295,20 @@ bool GPU_fx_do_composite_pass( GPU_shader_uniform_texture(dof_shader_pass5, interface->medium_blurred_uniform, fx->dof_near_coc_buffer); GPU_texture_bind(fx->depth_buffer, numslots++); - GPU_texture_filter_mode(fx->depth_buffer, false, true); + GPU_texture_compare_mode(fx->depth_buffer, false); + GPU_texture_filter_mode(fx->depth_buffer, true); GPU_shader_uniform_texture(dof_shader_pass5, interface->depth_uniform, fx->depth_buffer); /* 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); + Batch_draw(fx->quad_batch); /* disable bindings */ GPU_texture_unbind(fx->dof_near_coc_buffer); GPU_texture_unbind(fx->dof_near_coc_blurred_buffer); GPU_texture_unbind(src); - GPU_texture_filter_mode(fx->depth_buffer, true, false); + GPU_texture_compare_mode(fx->depth_buffer, true); + GPU_texture_filter_mode(fx->depth_buffer, false); GPU_texture_unbind(fx->depth_buffer); /* may not be attached, in that case this just returns */ @@ -1289,10 +1328,6 @@ bool GPU_fx_do_composite_pass( } } - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glBindBuffer(GL_ARRAY_BUFFER, 0); - GPU_shader_unbind(); return true; @@ -1315,7 +1350,7 @@ void GPU_fx_compositor_init_ssao_settings(GPUSSAOSettings *fx_ssao) fx_ssao->samples = 20; } -void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect effect) +void GPU_fx_shader_init_interface(GPUShader *shader, GPUFXShaderEffect effect) { if (!shader) return; @@ -1334,7 +1369,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->ssao_concentric_tex = GPU_shader_get_uniform(shader, "ssao_concentric_tex"); interface->ssao_jitter_uniform = GPU_shader_get_uniform(shader, "jitter_tex"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } @@ -1348,7 +1383,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } @@ -1362,7 +1397,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->select_uniform = GPU_shader_get_uniform(shader, "layerselection"); interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } @@ -1378,7 +1413,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs"); interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } @@ -1392,7 +1427,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO: @@ -1405,7 +1440,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE: @@ -1415,7 +1450,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->near_coc_downsampled = GPU_shader_get_uniform(shader, "colorbuffer"); interface->near_coc_blurred = GPU_shader_get_uniform(shader, "blurredcolorbuffer"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR: @@ -1425,7 +1460,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->near_coc_downsampled = GPU_shader_get_uniform(shader, "colorbuffer"); interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE: @@ -1440,7 +1475,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } @@ -1450,7 +1485,7 @@ void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect ef interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer"); - GPU_shader_set_interface(shader, interface); + GPU_fx_shader_set_interface(shader, interface); break; } |