Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager.c
| Show First 20 Lines • Show All 2,326 Lines • ▼ Show 20 Lines | |||||
| # endif | # endif | ||||
| GPU_framebuffer_restore(); | GPU_framebuffer_restore(); | ||||
| /* Cleanup for selection state */ | /* Cleanup for selection state */ | ||||
| GPU_viewport_free(viewport); | GPU_viewport_free(viewport); | ||||
| #endif /* USE_GPU_SELECT */ | #endif /* USE_GPU_SELECT */ | ||||
| } | } | ||||
| static void draw_depth_texture_to_screen(GPUTexture *texture) | |||||
| { | |||||
| const float w = (float)GPU_texture_width(texture); | |||||
| const float h = (float)GPU_texture_height(texture); | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| uint texcoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_DEPTH_COPY); | |||||
| GPU_texture_bind(texture, 0); | |||||
| immUniform1i("image", 0); /* default GL_TEXTURE0 unit */ | |||||
| immBegin(GPU_PRIM_TRI_STRIP, 4); | |||||
| immAttr2f(texcoord, 0.0f, 0.0f); | |||||
| immVertex2f(pos, 0.0f, 0.0f); | |||||
| immAttr2f(texcoord, 1.0f, 0.0f); | |||||
| immVertex2f(pos, w, 0.0f); | |||||
| immAttr2f(texcoord, 0.0f, 1.0f); | |||||
| immVertex2f(pos, 0.0f, h); | |||||
| immAttr2f(texcoord, 1.0f, 1.0f); | |||||
| immVertex2f(pos, w, h); | |||||
| immEnd(); | |||||
| GPU_texture_unbind(texture); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| /** | /** | ||||
| * object mode select-loop, see: ED_view3d_draw_depth_loop (legacy drawing). | * object mode select-loop, see: ED_view3d_draw_depth_loop (legacy drawing). | ||||
| */ | */ | ||||
| static void drw_draw_depth_loop_imp(void) | static void drw_draw_depth_loop_imp(void) | ||||
| { | { | ||||
| DRW_opengl_context_enable(); | DRW_opengl_context_enable(); | ||||
| /* Setup framebuffer */ | /* Setup framebuffer */ | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | if (DRW_state_draw_support()) { | ||||
| drw_engines_enable_from_object_mode(); | drw_engines_enable_from_object_mode(); | ||||
| } | } | ||||
| } | } | ||||
| drw_draw_depth_loop_imp(); | drw_draw_depth_loop_imp(); | ||||
| drw_engines_disable(); | drw_engines_disable(); | ||||
| /* XXX Drawing the resulting buffer to the BACK_BUFFER */ | |||||
| GPU_matrix_push(); | |||||
| GPU_matrix_push_projection(); | |||||
| wmOrtho2_region_pixelspace(DST.draw_ctx.ar); | |||||
| GPU_matrix_identity_set(); | |||||
| glEnable(GL_DEPTH_TEST); /* Cannot write to depth buffer without testing */ | |||||
| glDepthFunc(GL_ALWAYS); | |||||
| DefaultTextureList *dtxl = (DefaultTextureList *)GPU_viewport_texture_list_get(DST.viewport); | |||||
| draw_depth_texture_to_screen(dtxl->depth); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| GPU_matrix_pop(); | |||||
| GPU_matrix_pop_projection(); | |||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| /* Avoid accidental reuse. */ | /* Avoid accidental reuse. */ | ||||
| drw_state_ensure_not_reused(&DST); | drw_state_ensure_not_reused(&DST); | ||||
| #endif | #endif | ||||
| } | } | ||||
| /** | /** | ||||
| * Converted from ED_view3d_draw_depth_gpencil (legacy drawing). | * Converted from ED_view3d_draw_depth_gpencil (legacy drawing). | ||||
| Show All 29 Lines | void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph, | ||||
| drw_engines_disable(); | drw_engines_disable(); | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| /* Avoid accidental reuse. */ | /* Avoid accidental reuse. */ | ||||
| drw_state_ensure_not_reused(&DST); | drw_state_ensure_not_reused(&DST); | ||||
| #endif | #endif | ||||
| } | } | ||||
| /** | |||||
| * Clears the Depth Buffer and draws only the specified object. | |||||
| */ | |||||
| void DRW_draw_depth_object(ARegion *ar, | |||||
| View3D *v3d, | |||||
| GPUViewport *viewport, | |||||
| Object *object) | |||||
| { | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| DRW_opengl_context_enable(); | |||||
| /* Setup framebuffer */ | |||||
| DefaultFramebufferList *fbl = GPU_viewport_framebuffer_list_get(viewport); | |||||
| GPU_framebuffer_bind(fbl->depth_only_fb); | |||||
| GPU_framebuffer_clear_depth(fbl->depth_only_fb, 1.0f); | |||||
| GPU_depth_test(true); | |||||
| GPU_matrix_mul(object->obmat); | |||||
| const float(*world_clip_planes)[4] = NULL; | |||||
| if (rv3d->rflag & RV3D_CLIPPING) { | |||||
| ED_view3d_clipping_set(rv3d); | |||||
| ED_view3d_clipping_local(rv3d, object->obmat); | |||||
| world_clip_planes = rv3d->clip_local; | |||||
| } | |||||
| switch (object->type) { | |||||
| case OB_MESH: { | |||||
| GPUBatch *batch; | |||||
| Mesh *me = object->data; | |||||
| if (object->mode & OB_MODE_EDIT) { | |||||
| batch = DRW_mesh_batch_cache_get_edit_triangles(me); | |||||
| } | |||||
| else { | |||||
| batch = DRW_mesh_batch_cache_get_surface(me); | |||||
| } | |||||
| DRW_mesh_batch_cache_create_requested(object, me, NULL, false, true); | |||||
| const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : | |||||
| GPU_SHADER_CFG_DEFAULT; | |||||
| GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg); | |||||
| if (world_clip_planes != NULL) { | |||||
| GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes[0]); | |||||
| } | |||||
| GPU_batch_draw(batch); | |||||
| } break; | |||||
| case OB_CURVE: | |||||
| case OB_SURF: | |||||
| break; | |||||
| } | |||||
| if (rv3d->rflag & RV3D_CLIPPING) { | |||||
| ED_view3d_clipping_disable(); | |||||
| } | |||||
| GPU_matrix_set(rv3d->viewmat); | |||||
| GPU_depth_test(false); | |||||
| GPU_framebuffer_restore(); | |||||
| DRW_opengl_context_disable(); | |||||
| } | |||||
| /* Set an opengl context to be used with shaders that draw on U32 colors. */ | /* Set an opengl context to be used with shaders that draw on U32 colors. */ | ||||
| void DRW_framebuffer_select_id_setup(ARegion *ar, const bool clear) | void DRW_framebuffer_select_id_setup(ARegion *ar, const bool clear) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| DRW_opengl_context_enable(); | DRW_opengl_context_enable(); | ||||
| /* Setup framebuffer */ | /* Setup framebuffer */ | ||||
| ▲ Show 20 Lines • Show All 408 Lines • Show Last 20 Lines | |||||