diff options
Diffstat (limited to 'source/blender/draw/intern/draw_manager.c')
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 434 |
1 files changed, 322 insertions, 112 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 504e53fd206..cc4f8ec7947 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -44,6 +44,7 @@ #include "DNA_camera_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" +#include "DNA_world_types.h" #include "ED_space_api.h" #include "ED_screen.h" @@ -81,7 +82,7 @@ #include "engines/workbench/workbench_engine.h" #include "engines/external/external_engine.h" -#include "../../../intern/gawain/gawain/gwn_context.h" +#include "GPU_context.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -119,16 +120,16 @@ void DRW_draw_callbacks_pre_scene(void) { RegionView3D *rv3d = DST.draw_ctx.rv3d; - gpuLoadProjectionMatrix(rv3d->winmat); - gpuLoadMatrix(rv3d->viewmat); + GPU_matrix_projection_set(rv3d->winmat); + GPU_matrix_set(rv3d->viewmat); } void DRW_draw_callbacks_post_scene(void) { RegionView3D *rv3d = DST.draw_ctx.rv3d; - gpuLoadProjectionMatrix(rv3d->winmat); - gpuLoadMatrix(rv3d->viewmat); + GPU_matrix_projection_set(rv3d->winmat); + GPU_matrix_set(rv3d->viewmat); } struct DRWTextStore *DRW_text_cache_ensure(void) @@ -227,9 +228,9 @@ void DRW_transform_to_display(GPUTexture *tex) { drw_state_set(DRW_STATE_WRITE_COLOR); - Gwn_VertFormat *vert_format = immVertexFormat(); - uint pos = GWN_vertformat_attr_add(vert_format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - uint texco = GWN_vertformat_attr_add(vert_format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + GPUVertFormat *vert_format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(vert_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + uint texco = GPU_vertformat_attr_add(vert_format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); const float dither = 1.0f; @@ -261,7 +262,7 @@ void DRW_transform_to_display(GPUTexture *tex) immUniformMatrix4fv("ModelViewProjectionMatrix", mat); /* Full screen triangle */ - immBegin(GWN_PRIM_TRIS, 3); + immBegin(GPU_PRIM_TRIS, 3); immAttrib2f(texco, 0.0f, 0.0f); immVertex2f(pos, -1.0f, -1.0f); @@ -282,6 +283,29 @@ void DRW_transform_to_display(GPUTexture *tex) } } +/* Draw texture to framebuffer without any color transforms */ +void DRW_transform_none(GPUTexture *tex) +{ + /* Draw as texture for final render (without immediate mode). */ + GPUBatch *geom = DRW_cache_fullscreen_quad_get(); + GPU_batch_program_set_builtin(geom, GPU_SHADER_2D_IMAGE_COLOR); + + GPU_texture_bind(tex, 0); + + const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + GPU_batch_uniform_4fv(geom, "color", white); + + float mat[4][4]; + unit_m4(mat); + GPU_batch_uniform_mat4(geom, "ModelViewProjectionMatrix", mat); + + GPU_batch_program_use_begin(geom); + GPU_batch_draw_range_ex(geom, 0, 0, false); + GPU_batch_program_use_end(geom); + + GPU_texture_unbind(tex); +} + /** \} */ @@ -303,7 +327,7 @@ void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color) BLI_assert(samples > 0); BLI_assert(GPU_texture_samples(src_color) == samples); - Gwn_Batch *geom = DRW_cache_fullscreen_quad_get(); + GPUBatch *geom = DRW_cache_fullscreen_quad_get(); int builtin; switch (samples) { @@ -317,21 +341,21 @@ void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color) break; } - GWN_batch_program_set_builtin(geom, builtin); + GPU_batch_program_set_builtin(geom, builtin); GPU_texture_bind(src_depth, 0); GPU_texture_bind(src_color, 1); - GWN_batch_uniform_1i(geom, "depthMulti", 0); - GWN_batch_uniform_1i(geom, "colorMulti", 1); + GPU_batch_uniform_1i(geom, "depthMulti", 0); + GPU_batch_uniform_1i(geom, "colorMulti", 1); float mat[4][4]; unit_m4(mat); - GWN_batch_uniform_mat4(geom, "ModelViewProjectionMatrix", mat); + GPU_batch_uniform_mat4(geom, "ModelViewProjectionMatrix", mat); /* avoid gpuMatrix calls */ - GWN_batch_program_use_begin(geom); - GWN_batch_draw_range_ex(geom, 0, 0, false); - GWN_batch_program_use_end(geom); + GPU_batch_program_use_begin(geom); + GPU_batch_draw_range_ex(geom, 0, 0, false); + GPU_batch_program_use_end(geom); } /** \} */ @@ -696,34 +720,96 @@ void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*cal /* -------------------------------------------------------------------- */ -/** \name Objects (DRW_object) +/** \name Draw Data (DRW_drawdata) * \{ */ -ObjectEngineData *DRW_object_engine_data_get(Object *ob, DrawEngineType *engine_type) +/* Used for DRW_drawdata_from_id() + * All ID-datablocks which have their own 'local' DrawData + * should have the same arrangement in their structs. + */ +typedef struct IdDdtTemplate { + ID id; + struct AnimData *adt; + DrawDataList drawdata; +} IdDdtTemplate; + +/* Check if ID can have AnimData */ +static bool id_type_can_have_drawdata(const short id_type) +{ + /* Only some ID-blocks have this info for now */ + /* TODO: finish adding this for the other blocktypes */ + switch (id_type) { + /* has DrawData */ + case ID_OB: + case ID_WO: + return true; + + /* no DrawData */ + default: + return false; + } +} + +static bool id_can_have_drawdata(const ID *id) +{ + /* sanity check */ + if (id == NULL) + return false; + + return id_type_can_have_drawdata(GS(id->name)); +} + +/* Get DrawData from the given ID-block. In order for this to work, we assume that + * the DrawData pointer is stored in the struct in the same fashion as in IdDdtTemplate. + */ +DrawDataList *DRW_drawdatalist_from_id(ID *id) { - for (ObjectEngineData *oed = ob->drawdata.first; oed; oed = oed->next) { - if (oed->engine_type == engine_type) { - return oed; + /* only some ID-blocks have this info for now, so we cast the + * types that do to be of type IdDdtTemplate, and extract the + * DrawData that way + */ + if (id_can_have_drawdata(id)) { + IdDdtTemplate *idt = (IdDdtTemplate *)id; + return &idt->drawdata; + } + else + return NULL; +} + +DrawData *DRW_drawdata_get(ID *id, DrawEngineType *engine_type) +{ + DrawDataList *drawdata = DRW_drawdatalist_from_id(id); + + if (drawdata == NULL) + return NULL; + + LISTBASE_FOREACH(DrawData *, dd, drawdata) { + if (dd->engine_type == engine_type) { + return dd; } } return NULL; } -ObjectEngineData *DRW_object_engine_data_ensure( - Object *ob, +DrawData *DRW_drawdata_ensure( + ID *id, DrawEngineType *engine_type, size_t size, - ObjectEngineDataInitCb init_cb, - ObjectEngineDataFreeCb free_cb) + DrawDataInitCb init_cb, + DrawDataFreeCb free_cb) { - BLI_assert(size >= sizeof(ObjectEngineData)); + BLI_assert(size >= sizeof(DrawData)); + BLI_assert(id_can_have_drawdata(id)); /* Try to re-use existing data. */ - ObjectEngineData *oed = DRW_object_engine_data_get(ob, engine_type); - if (oed != NULL) { - return oed; + DrawData *dd = DRW_drawdata_get(id, engine_type); + if (dd != NULL) { + return dd; } + + DrawDataList *drawdata = DRW_drawdatalist_from_id(id); + /* Allocate new data. */ - if ((ob->base_flag & BASE_FROMDUPLI) != 0) { + if ((GS(id->name) == ID_OB) && (((Object *)id)->base_flag & BASE_FROMDUPLI) != 0) { /* NOTE: data is not persistent in this case. It is reset each redraw. */ BLI_assert(free_cb == NULL); /* No callback allowed. */ /* Round to sizeof(float) for DRW_instance_data_request(). */ @@ -734,21 +820,37 @@ ObjectEngineData *DRW_object_engine_data_ensure( if (DST.object_instance_data[fsize] == NULL) { DST.object_instance_data[fsize] = DRW_instance_data_request(DST.idatalist, fsize); } - oed = (ObjectEngineData *)DRW_instance_data_next(DST.object_instance_data[fsize]); - memset(oed, 0, size); + dd = (DrawData *)DRW_instance_data_next(DST.object_instance_data[fsize]); + memset(dd, 0, size); } else { - oed = MEM_callocN(size, "ObjectEngineData"); + dd = MEM_callocN(size, "DrawData"); } - oed->engine_type = engine_type; - oed->free = free_cb; + dd->engine_type = engine_type; + dd->free = free_cb; /* Perform user-side initialization, if needed. */ if (init_cb != NULL) { - init_cb(oed); + init_cb(dd); } /* Register in the list. */ - BLI_addtail(&ob->drawdata, oed); - return oed; + BLI_addtail((ListBase *)drawdata, dd); + return dd; +} + +void DRW_drawdata_free(ID *id) +{ + DrawDataList *drawdata = DRW_drawdatalist_from_id(id); + + if (drawdata == NULL) + return; + + LISTBASE_FOREACH(DrawData *, dd, drawdata) { + if (dd->free != NULL) { + dd->free(dd); + } + } + + BLI_freelistN((ListBase *)drawdata); } /** \} */ @@ -794,6 +896,22 @@ static void drw_engines_cache_init(void) } } +static void drw_engines_world_update(Scene *scene) +{ + if (scene->world == NULL) { + return; + } + + for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + DrawEngineType *engine = link->data; + ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); + + if (engine->id_update) { + engine->id_update(data, &scene->world->id); + } + } +} + static void drw_engines_cache_populate(Object *ob) { DST.ob_state = NULL; @@ -877,7 +995,7 @@ static void drw_engines_draw_text(void) PROFILE_START(stime); if (data->text_draw_cache) { - DRW_text_cache_draw(data->text_draw_cache, DST.draw_ctx.v3d, DST.draw_ctx.ar, false); + DRW_text_cache_draw(data->text_draw_cache, DST.draw_ctx.ar); } PROFILE_END_UPDATE(data->render_time, stime); @@ -1105,7 +1223,7 @@ static void drw_engines_enable(ViewLayer *view_layer, RenderEngineType *engine_t Object *obact = OBACT(view_layer); const int mode = CTX_data_mode_enum_ex(DST.draw_ctx.object_edit, obact, DST.draw_ctx.object_mode); View3D * v3d = DST.draw_ctx.v3d; - const int drawtype = v3d->drawtype; + const int drawtype = v3d->shading.type; drw_engines_enable_from_engine(engine_type, drawtype, v3d->shading.flag); @@ -1161,7 +1279,7 @@ void DRW_notify_view_update(const DRWUpdateContext *update_ctx) /* XXX Really nasty locking. But else this could * be executed by the material previews thread * while rendering a viewport. */ - BLI_mutex_lock(&DST.gl_context_mutex); + BLI_ticket_mutex_lock(DST.gl_context_mutex); /* Reset before using it. */ drw_state_prepare_clean_for_draw(&DST); @@ -1189,7 +1307,7 @@ void DRW_notify_view_update(const DRWUpdateContext *update_ctx) drw_engines_disable(); - BLI_mutex_unlock(&DST.gl_context_mutex); + BLI_ticket_mutex_unlock(DST.gl_context_mutex); } } @@ -1209,7 +1327,7 @@ void DRW_draw_view(const bContext *C) ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = DEG_get_evaluated_scene(depsgraph); - RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype); + RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); GPUViewport *viewport = WM_draw_region_get_bound_viewport(ar); /* Reset before using it. */ @@ -1237,9 +1355,7 @@ void DRW_draw_render_loop_ex( RegionView3D *rv3d = ar->regiondata; DST.draw_ctx.evil_C = evil_C; - DST.viewport = viewport; - v3d->zbuf = true; /* Setup viewport */ GPU_viewport_engines_data_validate(DST.viewport, DRW_engines_get_hash()); @@ -1275,10 +1391,14 @@ void DRW_draw_render_loop_ex( { PROFILE_START(stime); drw_engines_cache_init(); + drw_engines_world_update(scene); + const int object_type_exclude_viewport = v3d->object_type_exclude_viewport; DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob) { - drw_engines_cache_populate(ob); + if ((object_type_exclude_viewport & (1 << ob->type)) == 0) { + drw_engines_cache_populate(ob); + } } DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; @@ -1341,12 +1461,12 @@ void DRW_draw_render_loop_ex( glEnable(GL_DEPTH_TEST); if (DST.draw_ctx.evil_C) { - /* needed so manipulator isn't obscured */ + /* needed so gizmo isn't obscured */ if (((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && - ((v3d->twflag & V3D_MANIPULATOR_DRAW) != 0)) + ((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0)) { glDisable(GL_DEPTH_TEST); - DRW_draw_manipulator_3d(); + DRW_draw_gizmo_3d(); } DRW_draw_region_info(); @@ -1354,7 +1474,7 @@ void DRW_draw_render_loop_ex( if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) { /* Draw 2D after region info so we can draw on top of the camera passepartout overlay. * 'DRW_draw_region_info' sets the projection in pixel-space. */ - DRW_draw_manipulator_2d(); + DRW_draw_gizmo_2d(); glEnable(GL_DEPTH_TEST); } } @@ -1402,7 +1522,7 @@ void DRW_draw_render_loop( drw_state_prepare_clean_for_draw(&DST); Scene *scene = DEG_get_evaluated_scene(depsgraph); - RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype); + RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, viewport, NULL); } @@ -1453,18 +1573,14 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) } void *re_gl_context = RE_gl_context_get(render); - void *re_gwn_context = NULL; + void *re_gpu_context = NULL; /* Changing Context */ if (re_gl_context != NULL) { - /* TODO get rid of the blocking. Only here because of the static global DST. */ - BLI_mutex_lock(&DST.gl_context_mutex); - WM_opengl_context_activate(re_gl_context); - re_gwn_context = RE_gwn_context_get(render); - if (GWN_context_active_get() == NULL) { - GWN_context_active_set(re_gwn_context); - } - DRW_shape_cache_reset(); /* XXX fix that too. */ + DRW_opengl_render_context_enable(re_gl_context); + /* We need to query gpu context after a gl context has been bound. */ + re_gpu_context = RE_gpu_context_get(render); + DRW_gawain_render_context_enable(re_gpu_context); } else { DRW_opengl_context_enable(); @@ -1543,12 +1659,8 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) /* Changing Context */ if (re_gl_context != NULL) { - DRW_shape_cache_reset(); /* XXX fix that too. */ - glFlush(); - GWN_context_active_set(NULL); - WM_opengl_context_release(re_gl_context); - /* TODO get rid of the blocking. */ - BLI_mutex_unlock(&DST.gl_context_mutex); + DRW_gawain_render_context_disable(re_gpu_context); + DRW_opengl_render_context_disable(re_gl_context); } else { DRW_opengl_context_disable(); @@ -1559,16 +1671,71 @@ void DRW_render_object_iter( void *vedata, RenderEngine *engine, struct Depsgraph *depsgraph, void (*callback)(void *vedata, Object *ob, RenderEngine *engine, struct Depsgraph *depsgraph)) { + const DRWContextState *draw_ctx = DRW_context_state_get(); + DRW_hair_init(); + const int object_type_exclude_viewport = draw_ctx->v3d ? draw_ctx->v3d->object_type_exclude_viewport : 0; DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob) { - DST.ob_state = NULL; - callback(vedata, ob, engine, depsgraph); + if ((object_type_exclude_viewport & (1 << ob->type)) == 0) { + DST.ob_state = NULL; + callback(vedata, ob, engine, depsgraph); + } } DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END } +/* Assume a valid gl context is bound (and that the gl_context_mutex has been aquired). + * This function only setup DST and execute the given function. + * Warning: similar to DRW_render_to_image you cannot use default lists (dfbl & dtxl). */ +void DRW_custom_pipeline( + DrawEngineType *draw_engine_type, + struct Depsgraph *depsgraph, + void (*callback)(void *vedata, void *user_data), + void *user_data) +{ + Scene *scene = DEG_get_evaluated_scene(depsgraph); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); + + /* Reset before using it. */ + drw_state_prepare_clean_for_draw(&DST); + DST.options.is_image_render = true; + DST.options.is_scene_render = true; + DST.options.draw_background = false; + + DST.draw_ctx = (DRWContextState){ + .scene = scene, + .view_layer = view_layer, + .engine_type = NULL, + .depsgraph = depsgraph, + .object_mode = OB_MODE_OBJECT, + }; + drw_context_state_init(); + + DST.viewport = GPU_viewport_create(); + const int size[2] = {1, 1}; + GPU_viewport_size_set(DST.viewport, size); + + drw_viewport_var_init(); + + DRW_hair_init(); + + ViewportEngineData *data = drw_viewport_engine_data_ensure(draw_engine_type); + + /* Execute the callback */ + callback(data, user_data); + DST.buffer_finish_called = false; + + GPU_viewport_free(DST.viewport); + GPU_framebuffer_restore(); + +#ifdef DEBUG + /* Avoid accidental reuse. */ + drw_state_ensure_not_reused(&DST); +#endif +} + static struct DRWSelectBuffer { struct GPUFrameBuffer *framebuffer; struct GPUTexture *texture_depth; @@ -1620,7 +1787,7 @@ void DRW_draw_select_loop( DRW_ObjectFilterFn object_filter_fn, void *object_filter_user_data) { Scene *scene = DEG_get_evaluated_scene(depsgraph); - RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype); + RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); Object *obact = OBACT(view_layer); Object *obedit = OBEDIT_FROM_OBACT(obact); @@ -1644,7 +1811,7 @@ void DRW_draw_select_loop( obedit_mode = CTX_MODE_EDIT_ARMATURE; } } - if (v3d->overlay.flag & V3D_OVERLAY_BONE_SELECTION) { + if (v3d->overlay.flag & V3D_OVERLAY_BONE_SELECT) { if (!(v3d->flag2 & V3D_RENDER_OVERRIDE)) { Object *obpose = OBPOSE_FROM_OBACT(obact); if (obpose) { @@ -1658,8 +1825,6 @@ void DRW_draw_select_loop( GPU_viewport_size_set(viewport, (const int[2]){BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}); DST.viewport = viewport; - v3d->zbuf = true; - DST.options.is_select = true; /* Get list of enabled engines */ @@ -1693,6 +1858,7 @@ void DRW_draw_select_loop( { drw_engines_cache_init(); + drw_engines_world_update(scene); if (use_obedit) { #if 0 @@ -1705,6 +1871,9 @@ void DRW_draw_select_loop( #endif } else { + const int object_type_exclude_select = ( + v3d->object_type_exclude_viewport | v3d->object_type_exclude_select + ); bool filter_exclude = false; DEG_OBJECT_ITER_BEGIN( depsgraph, ob, @@ -1712,8 +1881,9 @@ void DRW_draw_select_loop( DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI) { - if ((ob->base_flag & BASE_SELECTABLE) != 0) { - + if ((ob->base_flag & BASE_SELECTABLE) && + (object_type_exclude_select & (1 << ob->type)) == 0) + { if (object_filter_fn != NULL) { if (ob->base_flag & BASE_FROMDUPLI) { /* pass (use previous filter_exclude value) */ @@ -1797,9 +1967,9 @@ 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); - Gwn_VertFormat *format = immVertexFormat(); - uint texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + 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); @@ -1807,7 +1977,7 @@ static void draw_depth_texture_to_screen(GPUTexture *texture) immUniform1i("image", 0); /* default GL_TEXTURE0 unit */ - immBegin(GWN_PRIM_TRI_STRIP, 4); + immBegin(GPU_PRIM_TRI_STRIP, 4); immAttrib2f(texcoord, 0.0f, 0.0f); immVertex2f(pos, 0.0f, 0.0f); @@ -1836,7 +2006,7 @@ void DRW_draw_depth_loop( ARegion *ar, View3D *v3d) { Scene *scene = DEG_get_evaluated_scene(depsgraph); - RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype); + RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); RegionView3D *rv3d = ar->regiondata; @@ -1853,10 +2023,7 @@ void DRW_draw_depth_loop( GPU_framebuffer_bind(g_select_buffer.framebuffer); GPU_framebuffer_clear_depth(g_select_buffer.framebuffer, 1.0f); - bool cache_is_dirty; DST.viewport = viewport; - v3d->zbuf = true; - DST.options.is_depth = true; /* Get list of enabled engines */ @@ -1866,7 +2033,6 @@ void DRW_draw_depth_loop( } /* Setup viewport */ - cache_is_dirty = true; /* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */ DST.draw_ctx = (DRWContextState){ @@ -1885,15 +2051,16 @@ void DRW_draw_depth_loop( drw_engines_init(); DRW_hair_init(); - /* TODO : tag to refresh by the dependency graph */ - /* ideally only refresh when objects are added/removed */ - /* or render properties / materials change */ - if (cache_is_dirty) { + { drw_engines_cache_init(); + drw_engines_world_update(scene); + const int object_type_exclude_viewport = v3d->object_type_exclude_viewport; DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob) { - drw_engines_cache_populate(ob); + if ((object_type_exclude_viewport & (1 << ob->type)) == 0) { + drw_engines_cache_populate(ob); + } } DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; @@ -1930,18 +2097,18 @@ void DRW_draw_depth_loop( DRW_opengl_context_disable(); /* XXX Drawing the resulting buffer to the BACK_BUFFER */ - gpuPushMatrix(); - gpuPushProjectionMatrix(); + GPU_matrix_push(); + GPU_matrix_push_projection(); wmOrtho2_region_pixelspace(ar); - gpuLoadIdentity(); + GPU_matrix_identity_set(); glEnable(GL_DEPTH_TEST); /* Cannot write to depth buffer without testing */ glDepthFunc(GL_ALWAYS); draw_depth_texture_to_screen(g_select_buffer.texture_depth); glDepthFunc(GL_LEQUAL); - gpuPopMatrix(); - gpuPopProjectionMatrix(); + GPU_matrix_pop(); + GPU_matrix_pop_projection(); } /** \} */ @@ -2074,7 +2241,7 @@ void DRW_engine_register(DrawEngineType *draw_engine_type) void DRW_engines_register(void) { RE_engines_register(&DRW_engine_viewport_eevee_type); - RE_engines_register(&DRW_engine_viewport_workbench_type); + RE_engines_register(&DRW_engine_viewport_opengl_type); DRW_engine_register(&draw_engine_workbench_solid); DRW_engine_register(&draw_engine_workbench_transparent); @@ -2131,7 +2298,7 @@ void DRW_engines_register(void) } } -extern struct Gwn_VertFormat *g_pos_format; /* draw_shgroup.c */ +extern struct GPUVertFormat *g_pos_format; /* draw_shgroup.c */ extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */ extern struct GPUTexture *globals_ramp; /* draw_common.c */ void DRW_engines_free(void) @@ -2178,16 +2345,14 @@ void DRW_opengl_context_create(void) { BLI_assert(DST.gl_context == NULL); /* Ensure it's called once */ - BLI_mutex_init(&DST.gl_context_mutex); + DST.gl_context_mutex = BLI_ticket_mutex_alloc(); if (!G.background) { immDeactivate(); } /* This changes the active context. */ DST.gl_context = WM_opengl_context_create(); - /* Make the context active for this thread (main thread) */ - WM_opengl_context_activate(DST.gl_context); /* Be sure to create gawain.context too. */ - DST.gwn_context = GWN_context_create(); + DST.gpu_context = GPU_context_create(); if (!G.background) { immActivate(); } @@ -2202,28 +2367,28 @@ void DRW_opengl_context_destroy(void) BLI_assert(BLI_thread_is_main()); if (DST.gl_context != NULL) { WM_opengl_context_activate(DST.gl_context); - GWN_context_active_set(DST.gwn_context); - GWN_context_discard(DST.gwn_context); + GPU_context_active_set(DST.gpu_context); + GPU_context_discard(DST.gpu_context); WM_opengl_context_dispose(DST.gl_context); - BLI_mutex_end(&DST.gl_context_mutex); + BLI_ticket_mutex_free(DST.gl_context_mutex); } } -void DRW_opengl_context_enable(void) +void DRW_opengl_context_enable_ex(bool restore) { if (DST.gl_context != NULL) { /* IMPORTANT: We dont support immediate mode in render mode! * This shall remain in effect until immediate mode supports * multiple threads. */ - BLI_mutex_lock(&DST.gl_context_mutex); - if (BLI_thread_is_main()) { + BLI_ticket_mutex_lock(DST.gl_context_mutex); + if (BLI_thread_is_main() && restore) { if (!G.background) { immDeactivate(); } } WM_opengl_context_activate(DST.gl_context); - GWN_context_active_set(DST.gwn_context); - if (BLI_thread_is_main()) { + GPU_context_active_set(DST.gpu_context); + if (BLI_thread_is_main() && restore) { if (!G.background) { immActivate(); } @@ -2232,7 +2397,7 @@ void DRW_opengl_context_enable(void) } } -void DRW_opengl_context_disable(void) +void DRW_opengl_context_disable_ex(bool restore) { if (DST.gl_context != NULL) { #ifdef __APPLE__ @@ -2241,16 +2406,61 @@ void DRW_opengl_context_disable(void) glFlush(); #endif - if (BLI_thread_is_main()) { + if (BLI_thread_is_main() && restore) { wm_window_reset_drawable(); } else { WM_opengl_context_release(DST.gl_context); - GWN_context_active_set(NULL); + GPU_context_active_set(NULL); } - BLI_mutex_unlock(&DST.gl_context_mutex); + BLI_ticket_mutex_unlock(DST.gl_context_mutex); } } +void DRW_opengl_context_enable(void) +{ + DRW_opengl_context_enable_ex(true); +} + +void DRW_opengl_context_disable(void) +{ + DRW_opengl_context_disable_ex(true); +} + +void DRW_opengl_render_context_enable(void *re_gl_context) +{ + /* If thread is main you should use DRW_opengl_context_enable(). */ + BLI_assert(!BLI_thread_is_main()); + + /* TODO get rid of the blocking. Only here because of the static global DST. */ + BLI_ticket_mutex_lock(DST.gl_context_mutex); + WM_opengl_context_activate(re_gl_context); +} + +void DRW_opengl_render_context_disable(void *re_gl_context) +{ + glFlush(); + WM_opengl_context_release(re_gl_context); + /* TODO get rid of the blocking. */ + BLI_ticket_mutex_unlock(DST.gl_context_mutex); +} + +/* Needs to be called AFTER DRW_opengl_render_context_enable() */ +void DRW_gawain_render_context_enable(void *re_gpu_context) +{ + /* If thread is main you should use DRW_opengl_context_enable(). */ + BLI_assert(!BLI_thread_is_main()); + + GPU_context_active_set(re_gpu_context); + DRW_shape_cache_reset(); /* XXX fix that too. */ +} + +/* Needs to be called BEFORE DRW_opengl_render_context_disable() */ +void DRW_gawain_render_context_disable(void *UNUSED(re_gpu_context)) +{ + DRW_shape_cache_reset(); /* XXX fix that too. */ + GPU_context_active_set(NULL); +} + /** \} */ |