Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--intern/ghost/GHOST_C-api.h3
-rw-r--r--intern/ghost/GHOST_IXrContext.h3
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp11
-rw-r--r--intern/ghost/intern/GHOST_XrContext.cpp9
-rw-r--r--intern/ghost/intern/GHOST_XrContext.h3
-rw-r--r--intern/ghost/intern/GHOST_XrSession.cpp14
-rw-r--r--intern/ghost/intern/GHOST_XrSession.h2
-rw-r--r--source/blender/draw/DRW_engine.h4
-rw-r--r--source/blender/draw/engines/eevee/eevee_lookdev.c2
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c14
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_draw_utils.c4
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_engine.c2
-rw-r--r--source/blender/draw/engines/workbench/workbench_data.c8
-rw-r--r--source/blender/draw/intern/draw_anim_viz.c4
-rw-r--r--source/blender/draw/intern/draw_armature.c58
-rw-r--r--source/blender/draw/intern/draw_cache.c2
-rw-r--r--source/blender/draw/intern/draw_common.c188
-rw-r--r--source/blender/draw/intern/draw_common.h13
-rw-r--r--source/blender/draw/intern/draw_manager.c30
-rw-r--r--source/blender/draw/intern/draw_view.c6
-rw-r--r--source/blender/draw/modes/edit_mesh_mode_text.c13
-rw-r--r--source/blender/draw/modes/object_mode.c20
-rw-r--r--source/blender/editors/include/UI_resources.h6
-rw-r--r--source/blender/editors/interface/resources.c104
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c13
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c7
-rw-r--r--source/blender/gpu/CMakeLists.txt1
-rw-r--r--source/blender/gpu/intern/gpu_context.cpp10
-rw-r--r--source/blender/gpu/intern/gpu_context_private.h2
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c91
-rw-r--r--source/blender/gpu/intern/gpu_matrix_private.h35
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c3
-rw-r--r--source/blender/windowmanager/intern/wm_draw.c47
-rw-r--r--source/blender/windowmanager/intern/wm_surface.c12
-rw-r--r--source/blender/windowmanager/intern/wm_xr.c104
35 files changed, 555 insertions, 293 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 84bad87e654..557503783e5 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -998,10 +998,11 @@ void GHOST_XrGraphicsContextBindFuncs(GHOST_XrContextHandle xr_context,
void GHOST_XrDrawViewFunc(GHOST_XrContextHandle xr_context, GHOST_XrDrawViewFn draw_view_fn);
/* sessions */
-int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_context);
void GHOST_XrSessionStart(GHOST_XrContextHandle xr_context,
const GHOST_XrSessionBeginInfo *begin_info);
void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_context);
+int GHOST_XrHasSession(const GHOST_XrContextHandle xr_contexthandle);
+int GHOST_XrSessionShouldRunDrawLoop(const GHOST_XrContextHandle xr_context);
void GHOST_XrSessionDrawViews(GHOST_XrContextHandle xr_context, void *customdata);
/* events */
diff --git a/intern/ghost/GHOST_IXrContext.h b/intern/ghost/GHOST_IXrContext.h
index 362bc923ee8..968c98ad42e 100644
--- a/intern/ghost/GHOST_IXrContext.h
+++ b/intern/ghost/GHOST_IXrContext.h
@@ -29,7 +29,8 @@ class GHOST_IXrContext {
virtual void startSession(const GHOST_XrSessionBeginInfo *begin_info) = 0;
virtual void endSession() = 0;
- virtual bool isSessionRunning() const = 0;
+ virtual bool hasSession() const = 0;
+ virtual bool shouldRunSessionDrawLoop() const = 0;
virtual void drawSessionViews(void *draw_customdata) = 0;
virtual void dispatchErrorMessage(const class GHOST_XrException *) const = 0;
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index caa88f46ff9..98579985693 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -937,10 +937,17 @@ void GHOST_XrSessionEnd(GHOST_XrContextHandle xr_contexthandle)
GHOST_XR_CAPI_CALL(xr_context->endSession(), xr_context);
}
-int GHOST_XrSessionIsRunning(const GHOST_XrContextHandle xr_contexthandle)
+int GHOST_XrHasSession(const GHOST_XrContextHandle xr_contexthandle)
{
const GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
- GHOST_XR_CAPI_CALL_RET(xr_context->isSessionRunning(), xr_context);
+ GHOST_XR_CAPI_CALL_RET(xr_context->hasSession(), xr_context);
+ return 0; // Only reached if exception is thrown.
+}
+
+int GHOST_XrSessionShouldRunDrawLoop(const GHOST_XrContextHandle xr_contexthandle)
+{
+ const GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+ GHOST_XR_CAPI_CALL_RET(xr_context->shouldRunSessionDrawLoop(), xr_context);
return 0; // Only reached if exception is thrown.
}
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index 07ed037fb5b..541e23312ea 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -456,9 +456,14 @@ void GHOST_XrContext::endSession()
m_session = nullptr;
}
-bool GHOST_XrContext::isSessionRunning() const
+bool GHOST_XrContext::hasSession() const
{
- return m_session && m_session->isRunning();
+ return m_session != nullptr;
+}
+
+bool GHOST_XrContext::shouldRunSessionDrawLoop() const
+{
+ return m_session && m_session->shouldRunDrawLoop();
}
void GHOST_XrContext::drawSessionViews(void *draw_customdata)
diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h
index 6f5c6ab425c..c260e95eb08 100644
--- a/intern/ghost/intern/GHOST_XrContext.h
+++ b/intern/ghost/intern/GHOST_XrContext.h
@@ -61,7 +61,8 @@ class GHOST_XrContext : public GHOST_IXrContext {
void startSession(const GHOST_XrSessionBeginInfo *begin_info) override;
void endSession() override;
- bool isSessionRunning() const override;
+ bool hasSession() const override;
+ bool shouldRunSessionDrawLoop() const override;
void drawSessionViews(void *draw_customdata) override;
static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata);
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index f2f01a9b354..f2f94d8f47d 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -193,16 +193,13 @@ void GHOST_XrSession::end()
GHOST_XrSession::eLifeExpectancy GHOST_XrSession::handleStateChangeEvent(
const XrEventDataSessionStateChanged *lifecycle)
{
- m_oxr->session_state = lifecycle->state;
-
/* Runtime may send events for apparently destroyed session. Our handle should be NULL then. */
assert((m_oxr->session == XR_NULL_HANDLE) || (m_oxr->session == lifecycle->session));
switch (lifecycle->state) {
case XR_SESSION_STATE_READY: {
- XrSessionBeginInfo begin_info{};
+ XrSessionBeginInfo begin_info{XR_TYPE_SESSION_BEGIN_INFO};
- begin_info.type = XR_TYPE_SESSION_BEGIN_INFO;
begin_info.primaryViewConfigurationType = m_oxr->view_type;
CHECK_XR(xrBeginSession(m_oxr->session, &begin_info),
"Failed to cleanly begin the VR session.");
@@ -218,6 +215,10 @@ GHOST_XrSession::eLifeExpectancy GHOST_XrSession::handleStateChangeEvent(
break;
}
+ /* GHOST session state is managed through this. Set last so on parallel execution of GHOST_Xr
+ * calls, state changes only take effect once previous operations in this functions are done. */
+ m_oxr->session_state = lifecycle->state;
+
return SESSION_KEEP_ALIVE;
}
/** \} */ /* State Management */
@@ -320,7 +321,6 @@ void GHOST_XrSession::beginFrameDrawing()
XrFrameBeginInfo begin_info{XR_TYPE_FRAME_BEGIN_INFO};
XrFrameState frame_state{XR_TYPE_FRAME_STATE};
- // TODO Blocking call. Does this intefer with other drawing?
CHECK_XR(xrWaitFrame(m_oxr->session, &wait_info, &frame_state),
"Failed to synchronize frame rates between Blender and the device.");
@@ -381,6 +381,8 @@ void GHOST_XrSession::draw(void *draw_customdata)
XrCompositionLayerProjection proj_layer;
std::vector<XrCompositionLayerBaseHeader *> layers;
+ assert(shouldRunDrawLoop());
+
beginFrameDrawing();
if (m_draw_info->frame_state.shouldRender) {
@@ -513,7 +515,7 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer(
*
* \{ */
-bool GHOST_XrSession::isRunning() const
+bool GHOST_XrSession::shouldRunDrawLoop() const
{
if (m_oxr->session == XR_NULL_HANDLE) {
return false;
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index 7b75bdbae56..56bba7130b0 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -39,7 +39,7 @@ class GHOST_XrSession {
eLifeExpectancy handleStateChangeEvent(const struct XrEventDataSessionStateChanged *lifecycle);
- bool isRunning() const;
+ bool shouldRunDrawLoop() const;
void unbindGraphicsContext(); /* public so context can ensure it's unbound as needed. */
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index f789d7d2897..f9963fa67b7 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -171,8 +171,12 @@ void DRW_cache_free_old_batches(struct Main *bmain);
void DRW_opengl_context_enable_ex(bool restore);
void DRW_opengl_context_disable_ex(bool restore);
+void DRW_opengl_render_context_enable_ex(void *re_gl_context);
void DRW_opengl_render_context_enable(void *re_gl_context);
+void DRW_opengl_render_context_disable_ex(void *re_gl_context);
void DRW_opengl_render_context_disable(void *re_gl_context);
+void DRW_render_context_draw_begin();
+void DRW_render_context_draw_end();
void DRW_gawain_render_context_enable(void *re_gpu_context);
void DRW_gawain_render_context_disable(void *re_gpu_context);
diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.c b/source/blender/draw/engines/eevee/eevee_lookdev.c
index e6e699bef10..21158d98b2f 100644
--- a/source/blender/draw/engines/eevee/eevee_lookdev.c
+++ b/source/blender/draw/engines/eevee/eevee_lookdev.c
@@ -142,7 +142,7 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata,
stl->g_data->light_cache = stl->lookdev_lightcache;
static float background_color[4];
- UI_GetThemeColor4fv(TH_BACK, background_color);
+ DRW_theme_color_get_4fv(TH_BACK, background_color);
/* XXX: Really quick conversion to avoid washed out background.
* Needs to be addressed properly (color managed using ocio). */
srgb_to_linearrgb_v4(background_color, background_color);
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index d5f8d062593..4ccec402a2f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -593,16 +593,16 @@ GPUBatch *gpencil_get_buffer_ctrlpoint_geom(bGPdata *gpd)
float color[4];
float position[3];
if (ts->gp_sculpt.guide.reference_point == GP_GUIDE_REF_CUSTOM) {
- UI_GetThemeColor4fv(TH_GIZMO_PRIMARY, color);
+ DRW_theme_color_get_4fv(TH_GIZMO_PRIMARY, color);
copy_v3_v3(position, ts->gp_sculpt.guide.location);
}
else if (ts->gp_sculpt.guide.reference_point == GP_GUIDE_REF_OBJECT &&
ts->gp_sculpt.guide.reference_object != NULL) {
- UI_GetThemeColor4fv(TH_GIZMO_SECONDARY, color);
+ DRW_theme_color_get_4fv(TH_GIZMO_SECONDARY, color);
copy_v3_v3(position, ts->gp_sculpt.guide.reference_object->loc);
}
else {
- UI_GetThemeColor4fv(TH_REDALERT, color);
+ DRW_theme_color_get_4fv(TH_REDALERT, color);
copy_v3_v3(position, scene->cursor.location);
}
GPU_vertbuf_attr_set(vbo, pos_id, idx, position);
@@ -714,7 +714,7 @@ void gpencil_get_edit_geom(struct GpencilBatchCacheElem *be,
* they stand out more.
* - We use the theme setting for size of the unselected verts
*/
- float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
+ float bsize = DRW_theme_value_get_f(TH_GP_VERTEX_SIZE);
float vsize;
if ((int)bsize > 8) {
vsize = 10.0f;
@@ -726,11 +726,11 @@ void gpencil_get_edit_geom(struct GpencilBatchCacheElem *be,
/* for now, we assume that the base color of the points is not too close to the real color */
float selectColor[4];
- UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
+ DRW_theme_color_get_3fv(TH_GP_VERTEX_SELECT, selectColor);
selectColor[3] = alpha;
float unselectColor[4];
- UI_GetThemeColor3fv(TH_GP_VERTEX, unselectColor);
+ DRW_theme_color_get_3fv(TH_GP_VERTEX, unselectColor);
unselectColor[3] = alpha;
if (be->vbo == NULL) {
@@ -813,7 +813,7 @@ void gpencil_get_edlin_geom(struct GpencilBatchCacheElem *be,
}
float selectColor[4];
- UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
+ DRW_theme_color_get_3fv(TH_GP_VERTEX_SELECT, selectColor);
selectColor[3] = alpha;
float linecolor[4];
copy_v4_v4(linecolor, gpd->line_color);
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 9b755217946..be6a8e72a8b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -285,7 +285,7 @@ static void set_wireframe_color(Object *ob,
/* if fill and wire, use background color */
if ((is_fill) && (stl->shgroups[id].shading_type[0] == OB_WIRE)) {
if (v3d->shading.background_type == V3D_SHADING_BACKGROUND_THEME) {
- UI_GetThemeColor4fv(TH_BACK, stl->shgroups[id].wire_color);
+ DRW_theme_color_get_4fv(TH_BACK, stl->shgroups[id].wire_color);
stl->shgroups[id].wire_color[3] = 1.0f;
}
else if (v3d->shading.background_type == V3D_SHADING_BACKGROUND_WORLD) {
@@ -307,7 +307,7 @@ static void set_wireframe_color(Object *ob,
switch (type) {
case V3D_SHADING_SINGLE_COLOR: {
if (stl->shgroups[id].shading_type[0] == OB_WIRE) {
- UI_GetThemeColor4fv(TH_WIRE, color);
+ DRW_theme_color_get_4fv(TH_WIRE, color);
}
else {
copy_v3_v3(color, v3d->shading.single_color);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 16162645f3d..a4a51dab714 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -1117,7 +1117,7 @@ void GPENCIL_draw_scene(void *ved)
/* active select flag and selection color */
if (!is_render) {
- UI_GetThemeColorShadeAlpha4fv(
+ DRW_theme_color_shade_alpha_get_4fv(
(ob == draw_ctx->obact) ? TH_ACTIVE : TH_SELECT, 0, -40, stl->storage->select_color);
}
stl->storage->do_select_outline = ((overlay) && (ob->base_flag & BASE_SELECTED) &&
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c
index 743a1fc42b6..d69083a5a27 100644
--- a/source/blender/draw/engines/workbench/workbench_data.c
+++ b/source/blender/draw/engines/workbench/workbench_data.c
@@ -92,9 +92,9 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
copy_v3_v3(wd->background_color_high, v3d->shading.background_color);
}
else if (v3d) {
- UI_GetThemeColor3fv(UI_GetThemeValue(TH_SHOW_BACK_GRAD) ? TH_BACK_GRAD : TH_BACK,
- wd->background_color_low);
- UI_GetThemeColor3fv(TH_BACK, wd->background_color_high);
+ DRW_theme_color_get_3fv(DRW_theme_value_get_i(TH_SHOW_BACK_GRAD) ? TH_BACK_GRAD : TH_BACK,
+ wd->background_color_low);
+ DRW_theme_color_get_3fv(TH_BACK, wd->background_color_high);
/* XXX: Really quick conversion to avoid washed out background.
* Needs to be addressed properly (color managed using ocio). */
@@ -125,7 +125,7 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
RegionView3D *rv3d = draw_ctx->rv3d;
if (rv3d->rflag & RV3D_CLIPPING) {
wpd->world_clip_planes = rv3d->clip;
- UI_GetThemeColor4fv(TH_V3D_CLIPPING_BORDER, wpd->world_clip_planes_color);
+ DRW_theme_color_get_4fv(TH_V3D_CLIPPING_BORDER, wpd->world_clip_planes_color);
if (wpd->use_color_management) {
srgb_to_linearrgb_v3_v3(wpd->world_clip_planes_color, wpd->world_clip_planes_color);
}
diff --git a/source/blender/draw/intern/draw_anim_viz.c b/source/blender/draw/intern/draw_anim_viz.c
index 72459309133..e62a6c0e19f 100644
--- a/source/blender/draw/intern/draw_anim_viz.c
+++ b/source/blender/draw/intern/draw_anim_viz.c
@@ -238,8 +238,8 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
if ((avs->path_viewflag & (MOTIONPATH_VIEW_FNUMS)) || (show_kf_no && show_keyframes)) {
int i;
uchar col[4], col_kf[4];
- UI_GetThemeColor3ubv(TH_TEXT_HI, col);
- UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col_kf);
+ DRW_theme_color_get_3ubv(TH_TEXT_HI, col);
+ DRW_theme_color_get_3ubv(TH_VERTEX_SELECT, col_kf);
col[3] = col_kf[3] = 255;
bMotionPathVert *mpv;
diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c
index 865cfea14e3..bb3d3fb2bdb 100644
--- a/source/blender/draw/intern/draw_armature.c
+++ b/source/blender/draw/intern/draw_armature.c
@@ -712,23 +712,23 @@ static bool set_pchan_color(short colCode,
}
else {
if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
- UI_GetThemeColor4fv(TH_BONE_POSE_ACTIVE, fcolor);
+ DRW_theme_color_get_4fv(TH_BONE_POSE_ACTIVE, fcolor);
}
else if (boneflag & BONE_DRAW_ACTIVE) {
- UI_GetThemeColorBlendShade4fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, fcolor);
+ DRW_theme_color_blend_shade_get_4fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, fcolor);
}
else if (boneflag & BONE_SELECTED) {
- UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+ DRW_theme_color_get_4fv(TH_BONE_POSE, fcolor);
}
else {
- UI_GetThemeColor4fv(TH_WIRE, fcolor);
+ DRW_theme_color_get_4fv(TH_WIRE, fcolor);
}
}
return true;
}
case PCHAN_COLOR_SOLID: {
- UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+ DRW_theme_color_get_4fv(TH_BONE_SOLID, fcolor);
if (bcolor) {
float solid_bcolor[3];
@@ -781,13 +781,13 @@ static bool set_pchan_color(short colCode,
}
else {
if (boneflag & BONE_DRAW_ACTIVE) {
- UI_GetThemeColorShade4fv(TH_BONE_POSE, 40, fcolor);
+ DRW_theme_color_shade_get_4fv(TH_BONE_POSE, 40, fcolor);
}
else if (boneflag & BONE_SELECTED) {
- UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+ DRW_theme_color_get_4fv(TH_BONE_POSE, fcolor);
}
else {
- UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+ DRW_theme_color_get_4fv(TH_BONE_SOLID, fcolor);
}
}
@@ -814,13 +814,13 @@ static bool set_pchan_color(short colCode,
}
else {
if (boneflag & BONE_DRAW_ACTIVE) {
- UI_GetThemeColorShade4fv(TH_BONE_POSE, 10, fcolor);
+ DRW_theme_color_shade_get_4fv(TH_BONE_POSE, 10, fcolor);
}
else if (boneflag & BONE_SELECTED) {
- UI_GetThemeColorShade4fv(TH_BONE_POSE, -30, fcolor);
+ DRW_theme_color_shade_get_4fv(TH_BONE_POSE, -30, fcolor);
}
else {
- UI_GetThemeColorShade4fv(TH_BONE_SOLID, -30, fcolor);
+ DRW_theme_color_shade_get_4fv(TH_BONE_SOLID, -30, fcolor);
}
}
break;
@@ -842,7 +842,7 @@ static bool set_pchan_color(short colCode,
rgba_uchar_args_set(cp, 0, 255, 120, 255);
}
else if (constflag) {
- UI_GetThemeColor4ubv(TH_BONE_POSE, cp);
+ DRW_theme_color_get_4ubv(TH_BONE_POSE, cp);
} /* PCHAN_HAS_ACTION */
rgb_uchar_to_float(fcolor, cp);
@@ -854,7 +854,7 @@ static bool set_pchan_color(short colCode,
fcolor[3] = 204.f / 255.f;
}
else {
- UI_GetThemeColorShade4fv(TH_BACK, -30, fcolor);
+ DRW_theme_color_shade_get_4fv(TH_BACK, -30, fcolor);
}
}
@@ -882,22 +882,22 @@ static void update_color(const Object *ob, const float const_color[4])
#define NO_ALPHA(c) (((c)[3] = 1.0f), (c))
- UI_GetThemeColor3fv(TH_SELECT, NO_ALPHA(g_theme.select_color));
- UI_GetThemeColorShade3fv(TH_EDGE_SELECT, 60, NO_ALPHA(g_theme.edge_select_color));
- UI_GetThemeColorShade3fv(TH_EDGE_SELECT, -20, NO_ALPHA(g_theme.bone_select_color));
- UI_GetThemeColor3fv(TH_WIRE, NO_ALPHA(g_theme.wire_color));
- UI_GetThemeColor3fv(TH_WIRE_EDIT, NO_ALPHA(g_theme.wire_edit_color));
- UI_GetThemeColor3fv(TH_BONE_SOLID, NO_ALPHA(g_theme.bone_solid_color));
- UI_GetThemeColorBlendShade3fv(
+ DRW_theme_color_get_3fv(TH_SELECT, NO_ALPHA(g_theme.select_color));
+ DRW_theme_color_shade_get_3fv(TH_EDGE_SELECT, 60, NO_ALPHA(g_theme.edge_select_color));
+ DRW_theme_color_shade_get_3fv(TH_EDGE_SELECT, -20, NO_ALPHA(g_theme.bone_select_color));
+ DRW_theme_color_get_3fv(TH_WIRE, NO_ALPHA(g_theme.wire_color));
+ DRW_theme_color_get_3fv(TH_WIRE_EDIT, NO_ALPHA(g_theme.wire_edit_color));
+ DRW_theme_color_get_3fv(TH_BONE_SOLID, NO_ALPHA(g_theme.bone_solid_color));
+ DRW_theme_color_blend_shade_get_3fv(
TH_WIRE_EDIT, TH_EDGE_SELECT, 0.15f, 0, NO_ALPHA(g_theme.bone_active_unselect_color));
- UI_GetThemeColor3fv(TH_BONE_POSE, NO_ALPHA(g_theme.bone_pose_color));
- UI_GetThemeColor3fv(TH_BONE_POSE_ACTIVE, NO_ALPHA(g_theme.bone_pose_active_color));
- UI_GetThemeColorBlendShade3fv(
+ DRW_theme_color_get_3fv(TH_BONE_POSE, NO_ALPHA(g_theme.bone_pose_color));
+ DRW_theme_color_get_3fv(TH_BONE_POSE_ACTIVE, NO_ALPHA(g_theme.bone_pose_active_color));
+ DRW_theme_color_blend_shade_get_3fv(
TH_WIRE, TH_BONE_POSE, 0.15f, 0, NO_ALPHA(g_theme.bone_pose_active_unselect_color));
- UI_GetThemeColor3fv(TH_TEXT_HI, NO_ALPHA(g_theme.text_hi_color));
- UI_GetThemeColor3fv(TH_TEXT, NO_ALPHA(g_theme.text_color));
- UI_GetThemeColor3fv(TH_VERTEX_SELECT, NO_ALPHA(g_theme.vertex_select_color));
- UI_GetThemeColor3fv(TH_VERTEX, NO_ALPHA(g_theme.vertex_color));
+ DRW_theme_color_get_3fv(TH_TEXT_HI, NO_ALPHA(g_theme.text_hi_color));
+ DRW_theme_color_get_3fv(TH_TEXT, NO_ALPHA(g_theme.text_color));
+ DRW_theme_color_get_3fv(TH_VERTEX_SELECT, NO_ALPHA(g_theme.vertex_select_color));
+ DRW_theme_color_get_3fv(TH_VERTEX, NO_ALPHA(g_theme.vertex_color));
#undef NO_ALPHA
}
@@ -1948,7 +1948,7 @@ static void draw_armature_edit(Object *ob)
/* Draw names of bone */
if (show_text && (arm->flag & ARM_DRAWNAMES)) {
uchar color[4];
- UI_GetThemeColor4ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, color);
+ DRW_theme_color_get_4ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, color);
float vec[3];
mid_v3_v3v3(vec, eBone->head, eBone->tail);
@@ -2094,7 +2094,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
/* Draw names of bone */
if (show_text && (arm->flag & ARM_DRAWNAMES)) {
uchar color[4];
- UI_GetThemeColor4ubv(
+ DRW_theme_color_get_4ubv(
(arm->flag & ARM_POSEMODE) && (bone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT,
color);
float vec[3];
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index e2e98a2db5a..03f9ca3a59c 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3951,7 +3951,7 @@ GPUBatch *DRW_cache_cursor_get(bool crosshair_lines)
if (crosshair_lines) {
uchar crosshair_color[3];
- UI_GetThemeColor3ubv(TH_VIEW_OVERLAY, crosshair_color);
+ DRW_theme_color_get_3ubv(TH_VIEW_OVERLAY, crosshair_color);
GPU_indexbuf_add_primitive_restart(&elb);
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index ac3e7e4ce67..328c7fa903d 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -25,6 +25,8 @@
#include "GPU_shader.h"
#include "GPU_texture.h"
+#include "DNA_space_types.h"
+
#include "UI_resources.h"
#include "BKE_object.h"
@@ -54,36 +56,36 @@ void DRW_globals_update(void)
{
GlobalsUboStorage *gb = &G_draw.block;
- UI_GetThemeColor4fv(TH_WIRE, gb->colorWire);
- UI_GetThemeColor4fv(TH_WIRE_EDIT, gb->colorWireEdit);
- UI_GetThemeColor4fv(TH_ACTIVE, gb->colorActive);
- UI_GetThemeColor4fv(TH_SELECT, gb->colorSelect);
+ DRW_theme_color_get_4fv(TH_WIRE, gb->colorWire);
+ DRW_theme_color_get_4fv(TH_WIRE_EDIT, gb->colorWireEdit);
+ DRW_theme_color_get_4fv(TH_ACTIVE, gb->colorActive);
+ DRW_theme_color_get_4fv(TH_SELECT, gb->colorSelect);
UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, gb->colorLibrarySelect);
UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, gb->colorLibrary);
- UI_GetThemeColor4fv(TH_TRANSFORM, gb->colorTransform);
- UI_GetThemeColor4fv(TH_LIGHT, gb->colorLight);
- UI_GetThemeColor4fv(TH_SPEAKER, gb->colorSpeaker);
- UI_GetThemeColor4fv(TH_CAMERA, gb->colorCamera);
- UI_GetThemeColor4fv(TH_EMPTY, gb->colorEmpty);
- UI_GetThemeColor4fv(TH_VERTEX, gb->colorVertex);
- UI_GetThemeColor4fv(TH_VERTEX_SELECT, gb->colorVertexSelect);
- UI_GetThemeColor4fv(TH_VERTEX_UNREFERENCED, gb->colorVertexUnreferenced);
+ DRW_theme_color_get_4fv(TH_TRANSFORM, gb->colorTransform);
+ DRW_theme_color_get_4fv(TH_LIGHT, gb->colorLight);
+ DRW_theme_color_get_4fv(TH_SPEAKER, gb->colorSpeaker);
+ DRW_theme_color_get_4fv(TH_CAMERA, gb->colorCamera);
+ DRW_theme_color_get_4fv(TH_EMPTY, gb->colorEmpty);
+ DRW_theme_color_get_4fv(TH_VERTEX, gb->colorVertex);
+ DRW_theme_color_get_4fv(TH_VERTEX_SELECT, gb->colorVertexSelect);
+ DRW_theme_color_get_4fv(TH_VERTEX_UNREFERENCED, gb->colorVertexUnreferenced);
UI_COLOR_RGBA_FROM_U8(0xB0, 0x00, 0xB0, 0xFF, gb->colorVertexMissingData);
- UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, gb->colorEditMeshActive);
- UI_GetThemeColor4fv(TH_EDGE_SELECT, gb->colorEdgeSelect);
-
- UI_GetThemeColor4fv(TH_EDGE_SEAM, gb->colorEdgeSeam);
- UI_GetThemeColor4fv(TH_EDGE_SHARP, gb->colorEdgeSharp);
- UI_GetThemeColor4fv(TH_EDGE_CREASE, gb->colorEdgeCrease);
- UI_GetThemeColor4fv(TH_EDGE_BEVEL, gb->colorEdgeBWeight);
- UI_GetThemeColor4fv(TH_EDGE_FACESEL, gb->colorEdgeFaceSelect);
- UI_GetThemeColor4fv(TH_FACE, gb->colorFace);
- UI_GetThemeColor4fv(TH_FACE_SELECT, gb->colorFaceSelect);
- UI_GetThemeColor4fv(TH_NORMAL, gb->colorNormal);
- UI_GetThemeColor4fv(TH_VNORMAL, gb->colorVNormal);
- UI_GetThemeColor4fv(TH_LNORMAL, gb->colorLNormal);
- UI_GetThemeColor4fv(TH_FACE_DOT, gb->colorFaceDot);
- UI_GetThemeColor4fv(TH_BACK, gb->colorBackground);
+ DRW_theme_color_get_4fv(TH_EDITMESH_ACTIVE, gb->colorEditMeshActive);
+ DRW_theme_color_get_4fv(TH_EDGE_SELECT, gb->colorEdgeSelect);
+
+ DRW_theme_color_get_4fv(TH_EDGE_SEAM, gb->colorEdgeSeam);
+ DRW_theme_color_get_4fv(TH_EDGE_SHARP, gb->colorEdgeSharp);
+ DRW_theme_color_get_4fv(TH_EDGE_CREASE, gb->colorEdgeCrease);
+ DRW_theme_color_get_4fv(TH_EDGE_BEVEL, gb->colorEdgeBWeight);
+ DRW_theme_color_get_4fv(TH_EDGE_FACESEL, gb->colorEdgeFaceSelect);
+ DRW_theme_color_get_4fv(TH_FACE, gb->colorFace);
+ DRW_theme_color_get_4fv(TH_FACE_SELECT, gb->colorFaceSelect);
+ DRW_theme_color_get_4fv(TH_NORMAL, gb->colorNormal);
+ DRW_theme_color_get_4fv(TH_VNORMAL, gb->colorVNormal);
+ DRW_theme_color_get_4fv(TH_LNORMAL, gb->colorLNormal);
+ DRW_theme_color_get_4fv(TH_FACE_DOT, gb->colorFaceDot);
+ DRW_theme_color_get_4fv(TH_BACK, gb->colorBackground);
/* Custom median color to slightly affect the edit mesh colors. */
interp_v4_v4v4(gb->colorEditMeshMiddle, gb->colorVertexSelect, gb->colorWireEdit, 0.35f);
@@ -97,38 +99,38 @@ void DRW_globals_update(void)
interp_v4_v4v4(gb->colorDupli, gb->colorBackground, gb->colorWire, 0.3f);
#ifdef WITH_FREESTYLE
- UI_GetThemeColor4fv(TH_FREESTYLE_EDGE_MARK, gb->colorEdgeFreestyle);
- UI_GetThemeColor4fv(TH_FREESTYLE_FACE_MARK, gb->colorFaceFreestyle);
+ DRW_theme_color_get_4fv(TH_FREESTYLE_EDGE_MARK, gb->colorEdgeFreestyle);
+ DRW_theme_color_get_4fv(TH_FREESTYLE_FACE_MARK, gb->colorFaceFreestyle);
#else
zero_v4(gb->colorEdgeFreestyle);
zero_v4(gb->colorFaceFreestyle);
#endif
/* Curve */
- UI_GetThemeColor4fv(TH_HANDLE_FREE, gb->colorHandleFree);
- UI_GetThemeColor4fv(TH_HANDLE_AUTO, gb->colorHandleAuto);
- UI_GetThemeColor4fv(TH_HANDLE_VECT, gb->colorHandleVect);
- UI_GetThemeColor4fv(TH_HANDLE_ALIGN, gb->colorHandleAlign);
- UI_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, gb->colorHandleAutoclamp);
- UI_GetThemeColor4fv(TH_HANDLE_SEL_FREE, gb->colorHandleSelFree);
- UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, gb->colorHandleSelAuto);
- UI_GetThemeColor4fv(TH_HANDLE_SEL_VECT, gb->colorHandleSelVect);
- UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, gb->colorHandleSelAlign);
- UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, gb->colorHandleSelAutoclamp);
- UI_GetThemeColor4fv(TH_NURB_ULINE, gb->colorNurbUline);
- UI_GetThemeColor4fv(TH_NURB_VLINE, gb->colorNurbVline);
- UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, gb->colorNurbSelUline);
- UI_GetThemeColor4fv(TH_NURB_SEL_VLINE, gb->colorNurbSelVline);
- UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, gb->colorActiveSpline);
-
- UI_GetThemeColor4fv(TH_BONE_POSE, gb->colorBonePose);
-
- UI_GetThemeColor4fv(TH_CFRAME, gb->colorCurrentFrame);
+ DRW_theme_color_get_4fv(TH_HANDLE_FREE, gb->colorHandleFree);
+ DRW_theme_color_get_4fv(TH_HANDLE_AUTO, gb->colorHandleAuto);
+ DRW_theme_color_get_4fv(TH_HANDLE_VECT, gb->colorHandleVect);
+ DRW_theme_color_get_4fv(TH_HANDLE_ALIGN, gb->colorHandleAlign);
+ DRW_theme_color_get_4fv(TH_HANDLE_AUTOCLAMP, gb->colorHandleAutoclamp);
+ DRW_theme_color_get_4fv(TH_HANDLE_SEL_FREE, gb->colorHandleSelFree);
+ DRW_theme_color_get_4fv(TH_HANDLE_SEL_AUTO, gb->colorHandleSelAuto);
+ DRW_theme_color_get_4fv(TH_HANDLE_SEL_VECT, gb->colorHandleSelVect);
+ DRW_theme_color_get_4fv(TH_HANDLE_SEL_ALIGN, gb->colorHandleSelAlign);
+ DRW_theme_color_get_4fv(TH_HANDLE_SEL_AUTOCLAMP, gb->colorHandleSelAutoclamp);
+ DRW_theme_color_get_4fv(TH_NURB_ULINE, gb->colorNurbUline);
+ DRW_theme_color_get_4fv(TH_NURB_VLINE, gb->colorNurbVline);
+ DRW_theme_color_get_4fv(TH_NURB_SEL_ULINE, gb->colorNurbSelUline);
+ DRW_theme_color_get_4fv(TH_NURB_SEL_VLINE, gb->colorNurbSelVline);
+ DRW_theme_color_get_4fv(TH_ACTIVE_SPLINE, gb->colorActiveSpline);
+
+ DRW_theme_color_get_4fv(TH_BONE_POSE, gb->colorBonePose);
+
+ DRW_theme_color_get_4fv(TH_CFRAME, gb->colorCurrentFrame);
/* Grid */
- UI_GetThemeColorShade4fv(TH_GRID, 10, gb->colorGrid);
+ DRW_theme_color_shade_get_4fv(TH_GRID, 10, gb->colorGrid);
/* emphasise division lines lighter instead of darker, if background is darker than grid */
- UI_GetThemeColorShade4fv(
+ DRW_theme_color_shade_get_4fv(
TH_GRID,
(gb->colorGrid[0] + gb->colorGrid[1] + gb->colorGrid[2] + 0.12f >
gb->colorBackground[0] + gb->colorBackground[1] + gb->colorBackground[2]) ?
@@ -136,22 +138,22 @@ void DRW_globals_update(void)
-10,
gb->colorGridEmphasise);
/* Grid Axis */
- UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, gb->colorGridAxisX);
- UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, gb->colorGridAxisY);
- UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, gb->colorGridAxisZ);
+ DRW_theme_color_blend_shade_get_4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, gb->colorGridAxisX);
+ DRW_theme_color_blend_shade_get_4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, gb->colorGridAxisY);
+ DRW_theme_color_blend_shade_get_4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, gb->colorGridAxisZ);
- UI_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, 0, -80, gb->colorDeselect);
- UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, gb->colorOutline);
- UI_GetThemeColorShadeAlpha4fv(TH_LIGHT, 0, 255, gb->colorLightNoAlpha);
+ DRW_theme_color_shade_alpha_get_4fv(TH_TRANSFORM, 0, -80, gb->colorDeselect);
+ DRW_theme_color_shade_alpha_get_4fv(TH_WIRE, 0, -30, gb->colorOutline);
+ DRW_theme_color_shade_alpha_get_4fv(TH_LIGHT, 0, 255, gb->colorLightNoAlpha);
- gb->sizeLightCenter = (UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.5f) * U.pixelsize;
+ gb->sizeLightCenter = (DRW_theme_value_get_f(TH_OBCENTER_DIA) + 1.5f) * U.pixelsize;
gb->sizeLightCircle = U.pixelsize * 9.0f;
gb->sizeLightCircleShadow = gb->sizeLightCircle + U.pixelsize * 3.0f;
/* M_SQRT2 to be at least the same size of the old square */
gb->sizeVertex = U.pixelsize *
- (max_ff(1.0f, UI_GetThemeValuef(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f));
- gb->sizeFaceDot = U.pixelsize * UI_GetThemeValuef(TH_FACEDOT_SIZE);
+ (max_ff(1.0f, DRW_theme_value_get_f(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f));
+ gb->sizeFaceDot = U.pixelsize * DRW_theme_value_get_f(TH_FACEDOT_SIZE);
gb->sizeEdge = U.pixelsize * (1.0f / 2.0f); /* TODO Theme */
gb->sizeEdgeFix = U.pixelsize * (0.5f + 2.0f * (2.0f * (gb->sizeEdge * (float)M_SQRT1_2)));
@@ -1243,11 +1245,77 @@ float *DRW_color_background_blend_get(int theme_id)
break;
}
- UI_GetThemeColorBlendShade4fv(theme_id, TH_BACK, 0.5, 0, ret);
+ DRW_theme_color_blend_shade_get_4fv(theme_id, TH_BACK, 0.5, 0, ret);
return ret;
}
+/* The following DRW_theme_color_/DRW_theme_value_ functions are wrappers around UI_GetThemeColor
+ * functions that for thread safety, don't rely on UI_SetTheme() being called beforehand. */
+
+int DRW_theme_value_get_i(int colorid)
+{
+ return UI_GetThemeValue(colorid);
+}
+float DRW_theme_value_get_f(int colorid)
+{
+ return UI_GetThemeValuef(colorid);
+}
+void DRW_theme_color_get_4fv(int colorid, float r_col[4])
+{
+ UI_GetThemeColorType4fv(colorid, SPACE_VIEW3D, r_col);
+}
+void DRW_theme_color_get_4ubv(int colorid, uchar r_col[4])
+{
+ UI_GetThemeColorType4ubv(colorid, SPACE_VIEW3D, r_col);
+}
+void DRW_theme_color_get_3fv(int colorid, float r_col[3])
+{
+ UI_GetThemeColorType3fv(colorid, SPACE_VIEW3D, r_col);
+}
+void DRW_theme_color_get_3ubv(int colorid, uchar r_col[3])
+{
+ UI_GetThemeColorType3ubv(colorid, SPACE_VIEW3D, r_col);
+}
+void DRW_theme_color_shade_get_4fv(int colorid, int offset, float r_col[4])
+{
+ float col[4];
+ DRW_theme_color_get_4fv(colorid, col);
+ UI_GetColorPtrShadeAlpha4fv(col, r_col, offset, 0);
+}
+void DRW_theme_color_shade_alpha_get_4fv(int colorid, int offset, int alphaoffset, float r_col[4])
+{
+ float col[4];
+ DRW_theme_color_get_4fv(colorid, col);
+ UI_GetColorPtrShadeAlpha4fv(col, r_col, offset, alphaoffset);
+}
+void DRW_theme_color_shade_get_3fv(int colorid, int offset, float r_col[3])
+{
+ float col[4];
+ DRW_theme_color_get_4fv(colorid, col);
+ UI_GetColorPtrShadeAlpha4fv(col, col, offset, 0);
+ copy_v3_v3(r_col, col);
+}
+void DRW_theme_color_blend_shade_get_4fv(
+ int colorid1, int colorid2, float fac, int offset, float r_col[4])
+{
+ float col1[4], col2[4];
+
+ DRW_theme_color_get_4fv(colorid1, col1);
+ DRW_theme_color_get_4fv(colorid2, col2);
+ UI_GetColorPtrBlendShade4fv(col1, col2, r_col, fac, offset);
+}
+void DRW_theme_color_blend_shade_get_3fv(
+ int colorid1, int colorid2, float fac, int offset, float r_col[3])
+{
+ float col1[4], col2[4], tmp[4];
+
+ DRW_theme_color_get_3fv(colorid1, col1);
+ DRW_theme_color_get_3fv(colorid2, col2);
+ UI_GetColorPtrBlendShade4fv(col1, col2, tmp, fac, offset);
+ copy_v3_v3(r_col, tmp);
+}
+
bool DRW_object_is_flat(Object *ob, int *r_axis)
{
float dim[3];
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
index 05d7bafa00d..12f88fb84a6 100644
--- a/source/blender/draw/intern/draw_common.h
+++ b/source/blender/draw/intern/draw_common.h
@@ -219,6 +219,19 @@ struct GPUShader *volume_velocity_shader_get(bool use_needle);
struct DRWView *DRW_view_create_with_zoffset(const RegionView3D *rv3d, float offset);
+int DRW_theme_value_get_i(int colorid);
+float DRW_theme_value_get_f(int colorid);
+void DRW_theme_color_get_4fv(int colorid, float r_col[4]);
+void DRW_theme_color_get_4ubv(int colorid, uchar r_col[4]);
+void DRW_theme_color_get_3fv(int colorid, float r_col[3]);
+void DRW_theme_color_get_3ubv(int colorid, uchar r_col[3]);
+void DRW_theme_color_shade_get_4fv(int colorid, int offset, float r_col[4]);
+void DRW_theme_color_shade_alpha_get_4fv(int colorid, int offset, int alphaoffset, float r_col[4]);
+void DRW_theme_color_shade_get_3fv(int colorid, int offset, float r_col[3]);
+void DRW_theme_color_blend_shade_get_4fv(
+ int colorid1, int colorid2, float fac, int offset, float r_col[4]);
+void DRW_theme_color_blend_shade_get_3fv(
+ int colorid1, int colorid2, float fac, int offset, float r_col[3]);
int DRW_object_wire_theme_get(struct Object *ob, struct ViewLayer *view_layer, float **r_color);
float *DRW_color_background_blend_get(int theme_id);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 7176d81bd25..4b958a74bf9 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -524,7 +524,7 @@ const float *DRW_viewport_pixelsize_get(void)
return &DST.pixsize;
}
-static void drw_viewport_cache_resize(void)
+void drw_viewport_cache_resize(void)
{
/* Release the memiter before clearing the mempools that references them */
GPU_viewport_cache_release(DST.viewport);
@@ -3020,20 +3020,40 @@ void *DRW_gpu_context_get(void)
return DST.gpu_context;
}
-void DRW_opengl_render_context_enable(void *re_gl_context)
+void DRW_opengl_render_context_enable_ex(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_enable(void *re_gl_context)
+{
+ DRW_opengl_render_context_enable_ex(re_gl_context);
+ DRW_render_context_draw_begin();
+}
-void DRW_opengl_render_context_disable(void *re_gl_context)
+void DRW_opengl_render_context_disable_ex(void *re_gl_context)
{
GPU_flush();
WM_opengl_context_release(re_gl_context);
+}
+void DRW_opengl_render_context_disable(void *re_gl_context)
+{
+ DRW_opengl_render_context_disable_ex(re_gl_context);
+ DRW_render_context_draw_end();
+}
+
+void DRW_render_context_draw_begin()
+{
+ BLI_assert(!BLI_thread_is_main());
+ /* TODO get rid of the blocking. */
+ BLI_ticket_mutex_lock(DST.gl_context_mutex);
+}
+
+void DRW_render_context_draw_end()
+{
+ // GPU_flush();
/* TODO get rid of the blocking. */
BLI_ticket_mutex_unlock(DST.gl_context_mutex);
}
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
index 7aa2e007f79..6c88d9d9057 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -84,7 +84,7 @@ void DRW_draw_background(bool do_alpha_checker)
GPU_depth_test(true);
}
- else if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
+ else if (DRW_theme_value_get_i(TH_SHOW_BACK_GRAD)) {
float m[4][4];
unit_m4(m);
@@ -103,8 +103,8 @@ void DRW_draw_background(bool do_alpha_checker)
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR_DITHER);
- UI_GetThemeColor3ubv(TH_BACK_GRAD, col_lo);
- UI_GetThemeColor3ubv(TH_BACK, col_hi);
+ DRW_theme_color_get_3ubv(TH_BACK_GRAD, col_lo);
+ DRW_theme_color_get_3ubv(TH_BACK, col_hi);
immBegin(GPU_PRIM_TRI_FAN, 4);
immAttr3ubv(color, col_lo);
diff --git a/source/blender/draw/modes/edit_mesh_mode_text.c b/source/blender/draw/modes/edit_mesh_mode_text.c
index 7c7a9a586fa..3cb6081bed0 100644
--- a/source/blender/draw/modes/edit_mesh_mode_text.c
+++ b/source/blender/draw/modes/edit_mesh_mode_text.c
@@ -37,6 +37,9 @@
#include "UI_resources.h"
+#include "DRW_render.h"
+
+#include "draw_common.h"
#include "draw_manager_text.h"
#include "edit_mesh_mode_intern.h" /* own include */
@@ -100,7 +103,7 @@ void DRW_edit_mesh_mode_text_measure_stats(ARegion *ar,
if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_LEN) {
BMEdge *eed;
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGELEN, col);
+ DRW_theme_color_get_3ubv(TH_DRAWEXTRA_EDGELEN, col);
BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
/* draw selected edges, or edges next to selected verts while dragging */
@@ -152,7 +155,7 @@ void DRW_edit_mesh_mode_text_measure_stats(ARegion *ar,
const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
BMEdge *eed;
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col);
+ DRW_theme_color_get_3ubv(TH_DRAWEXTRA_EDGEANG, col);
BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
BMLoop *l_a, *l_b;
@@ -215,7 +218,7 @@ void DRW_edit_mesh_mode_text_measure_stats(ARegion *ar,
/* would be nice to use BM_face_calc_area, but that is for 2d faces
* so instead add up tessellation triangle areas */
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
+ DRW_theme_color_get_3ubv(TH_DRAWEXTRA_FACEAREA, col);
int i, n, numtri;
BMFace *f = NULL;
@@ -270,7 +273,7 @@ void DRW_edit_mesh_mode_text_measure_stats(ARegion *ar,
BMFace *efa;
const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
+ DRW_theme_color_get_3ubv(TH_DRAWEXTRA_FACEANG, col);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
const bool is_face_sel = BM_elem_flag_test_bool(efa, BM_ELEM_SELECT);
@@ -325,7 +328,7 @@ void DRW_edit_mesh_mode_text_measure_stats(ARegion *ar,
int i;
/* For now, reuse an appropriate theme color */
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
+ DRW_theme_color_get_3ubv(TH_DRAWEXTRA_FACEANG, col);
if (em->selectmode & SCE_SELECT_VERTEX) {
BMVert *v;
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 98c52c300cf..6ee2a03c34c 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -1370,7 +1370,7 @@ static void OBJECT_cache_init(void *vedata)
const DRWContextState *draw_ctx = DRW_context_state_get();
OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
- const float outline_width = UI_GetThemeValuef(TH_OUTLINE_WIDTH);
+ const float outline_width = DRW_theme_value_get_f(TH_OUTLINE_WIDTH);
const bool do_outline_expand = (U.pixelsize > 1.0) || (outline_width > 2.0f);
const bool do_large_expand = ((U.pixelsize > 1.0) && (outline_width > 2.0f)) ||
(outline_width > 4.0f);
@@ -1821,7 +1821,7 @@ static void OBJECT_cache_init(void *vedata)
psl->ob_center = DRW_pass_create("Obj Center Pass", state);
outlineWidth = 1.0f * U.pixelsize;
- size = UI_GetThemeValuef(TH_OBCENTER_DIA) * U.pixelsize + outlineWidth;
+ size = DRW_theme_value_get_f(TH_OBCENTER_DIA) * U.pixelsize + outlineWidth;
GPUShader *sh = GPU_shader_get_builtin_shader_with_config(
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA, draw_ctx->sh_cfg);
@@ -2248,10 +2248,10 @@ static void camera_view3d_reconstruction(OBJECT_ShadingGroupList *sgl,
uchar text_color_selected[4], text_color_unselected[4];
float bundle_color_unselected[4], bundle_color_solid[4];
- UI_GetThemeColor4ubv(TH_SELECT, text_color_selected);
- UI_GetThemeColor4ubv(TH_TEXT, text_color_unselected);
- UI_GetThemeColor4fv(TH_WIRE, bundle_color_unselected);
- UI_GetThemeColor4fv(TH_BUNDLE_SOLID, bundle_color_solid);
+ DRW_theme_color_get_4ubv(TH_SELECT, text_color_selected);
+ DRW_theme_color_get_4ubv(TH_TEXT, text_color_unselected);
+ DRW_theme_color_get_4fv(TH_WIRE, bundle_color_unselected);
+ DRW_theme_color_get_4fv(TH_BUNDLE_SOLID, bundle_color_solid);
float camera_mat[4][4];
BKE_tracking_get_camera_object_matrix(scene, ob, camera_mat);
@@ -2353,7 +2353,7 @@ static void camera_view3d_reconstruction(OBJECT_ShadingGroupList *sgl,
if (reconstruction->camnr) {
static float camera_path_color[4];
- UI_GetThemeColor4fv(TH_CAMERA_PATH, camera_path_color);
+ DRW_theme_color_get_4fv(TH_CAMERA_PATH, camera_path_color);
GPUBatch *geom = batch_camera_path_get(&sgl->camera_path, reconstruction);
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
@@ -3182,7 +3182,7 @@ static void DRW_shgroup_texture_space(OBJECT_ShadingGroupList *sgl, Object *ob,
mul_m4_m4m4(tmp, ob->obmat, tmp);
float color[4];
- UI_GetThemeColor4fv(theme_id, color);
+ DRW_theme_color_get_4fv(theme_id, color);
DRW_buffer_add_entry(sgl->texspace, color, &one, tmp);
}
@@ -3212,7 +3212,7 @@ static void DRW_shgroup_bounds(OBJECT_ShadingGroupList *sgl, Object *ob, int the
BKE_boundbox_init_from_minmax(bb, min, max);
}
- UI_GetThemeColor4fv(theme_id, color);
+ DRW_theme_color_get_4fv(theme_id, color);
BKE_boundbox_calc_center_aabb(bb, center);
BKE_boundbox_calc_size_aabb(bb, size);
@@ -3716,7 +3716,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
struct DRWTextStore *dt = DRW_text_cache_ensure();
uchar color[4];
- UI_GetThemeColor4ubv(theme_id, color);
+ DRW_theme_color_get_4ubv(theme_id, color);
DRW_text_cache_add(dt,
ob->obmat[3],
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index 3b080b6df95..17bd1ff0c22 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -394,6 +394,8 @@ bool UI_GetIconThemeColor4ubv(int colorid, unsigned char col[4]);
// shade a 3 byte color (same as UI_GetColorPtrBlendShade3ubv with 0.0 factor)
void UI_GetColorPtrShade3ubv(const unsigned char cp1[3], unsigned char col[3], int offset);
+void UI_GetColorPtrShadeAlpha4fv(const float cp[4], float col[4], int offset, int alphaoffset);
+
// get a 3 byte color, blended and shaded between two other char color pointers
void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3],
const unsigned char cp2[3],
@@ -401,6 +403,10 @@ void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3],
float fac,
int offset);
+// get a 3 byte color, blended and shaded between two other char color pointers
+void UI_GetColorPtrBlendShade4fv(
+ const float cp1[4], const float cp2[4], float col[4], float fac, int offset);
+
// sets the font color
// (for anything fancy use UI_GetThemeColor[Fancy] then BLF_color)
void UI_FontThemeColor(int fontid, int colorid);
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index c31de60c7ed..98a6b8fb6c4 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -1233,24 +1233,12 @@ void UI_GetThemeColorShade4ubv(int colorid, int offset, uchar col[4])
void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
{
- int r, g, b, a;
const uchar *cp;
+ float cp_f[4];
cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
-
- r = coloffset + (int)cp[0];
- CLAMP(r, 0, 255);
- g = coloffset + (int)cp[1];
- CLAMP(g, 0, 255);
- b = coloffset + (int)cp[2];
- CLAMP(b, 0, 255);
- a = alphaoffset + (int)cp[3];
- CLAMP(a, 0, 255);
-
- col[0] = ((float)r) / 255.0f;
- col[1] = ((float)g) / 255.0f;
- col[2] = ((float)b) / 255.0f;
- col[3] = ((float)a) / 255.0f;
+ rgba_uchar_to_float(cp_f, cp);
+ UI_GetColorPtrShadeAlpha4fv(cp_f, col, coloffset, alphaoffset);
}
void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
@@ -1277,27 +1265,14 @@ void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int of
void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
{
- int r, g, b, a;
const uchar *cp1, *cp2;
+ float cp1_f[4], cp2_f[4];
cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
-
- CLAMP(fac, 0.0f, 1.0f);
-
- r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
- CLAMP(r, 0, 255);
- g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
- CLAMP(g, 0, 255);
- b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
- CLAMP(b, 0, 255);
- a = offset + floorf((1.0f - fac) * cp1[3] + fac * cp2[3]);
- CLAMP(a, 0, 255);
-
- col[0] = ((float)r) / 255.0f;
- col[1] = ((float)g) / 255.0f;
- col[2] = ((float)b) / 255.0f;
- col[3] = ((float)a) / 255.0f;
+ rgba_uchar_to_float(cp1_f, cp1);
+ rgba_uchar_to_float(cp2_f, cp2);
+ UI_GetColorPtrBlendShade4fv(cp1_f, cp2_f, col, fac, offset);
}
/* get the color, in char pointer */
@@ -1314,25 +1289,12 @@ void UI_GetThemeColor3ubv(int colorid, uchar col[3])
/* get the color, range 0.0-1.0, complete with shading offset */
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
{
- int r, g, b, a;
const uchar *cp;
+ float cp_f[4];
cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
-
- r = offset + (int)cp[0];
- CLAMP(r, 0, 255);
- g = offset + (int)cp[1];
- CLAMP(g, 0, 255);
- b = offset + (int)cp[2];
- CLAMP(b, 0, 255);
-
- a = (int)cp[3]; /* no shading offset... */
- CLAMP(a, 0, 255);
-
- col[0] = ((float)r) / 255.0f;
- col[1] = ((float)g) / 255.0f;
- col[2] = ((float)b) / 255.0f;
- col[3] = ((float)a) / 255.0f;
+ rgba_uchar_to_float(cp_f, cp);
+ UI_GetColorPtrShadeAlpha4fv(cp_f, col, offset, 0);
}
/* get the color, in char pointer */
@@ -1420,6 +1382,28 @@ void UI_GetColorPtrShade3ubv(const uchar cp[3], uchar col[3], int offset)
col[2] = b;
}
+void UI_GetColorPtrShadeAlpha4fv(const float cp[4], float col[4], int offset, int alphaoffset)
+{
+ const float ofs = offset / 255.0f;
+ const float alphaofs = alphaoffset / 255.0f;
+ float r, g, b, a;
+
+ r = ofs + cp[0];
+ g = ofs + cp[1];
+ b = ofs + cp[2];
+ a = alphaofs + cp[3];
+
+ CLAMP(r, 0.0f, 1.0f);
+ CLAMP(g, 0.0f, 1.0f);
+ CLAMP(b, 0.0f, 1.0f);
+ CLAMP(a, 0.0f, 1.0f);
+
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = a;
+}
+
/* get a 3 byte color, blended and shaded between two other char color pointers */
void UI_GetColorPtrBlendShade3ubv(
const uchar cp1[3], const uchar cp2[3], uchar col[3], float fac, int offset)
@@ -1440,6 +1424,30 @@ void UI_GetColorPtrBlendShade3ubv(
col[2] = b;
}
+void UI_GetColorPtrBlendShade4fv(
+ const float cp1[4], const float cp2[4], float col[4], float fac, int offset)
+{
+ const float ofs = (float)offset / 255.0f;
+ float r, g, b, a;
+
+ CLAMP(fac, 0.0f, 1.0f);
+
+ r = ofs + (1.0f - fac) * cp1[0] + fac * cp2[0];
+ g = ofs + (1.0f - fac) * cp1[1] + fac * cp2[1];
+ b = ofs + (1.0f - fac) * cp1[2] + fac * cp2[2];
+ a = ofs + (1.0f - fac) * cp1[3] + fac * cp2[3];
+
+ CLAMP(r, 0.0f, 1.0f);
+ CLAMP(g, 0.0f, 1.0f);
+ CLAMP(b, 0.0f, 1.0f);
+ CLAMP(a, 0.0f, 1.0f);
+
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = a;
+}
+
void UI_ThemeClearColor(int colorid)
{
float col[3];
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 5b1138fc7f1..31d00942e8c 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -774,7 +774,6 @@ static void drawrenderborder(ARegion *ar, View3D *v3d)
void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool alphaoverride)
{
- struct bThemeState theme_state;
Scene *scene = DEG_get_evaluated_scene(depsgraph);
RegionView3D *rv3d = ar->regiondata;
@@ -787,10 +786,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a
/* not that nice but means we wont zoom into billboards */
U.glalphaclip = alphaoverride ? 0.5f : glalphaclip;
- /* Tools may request depth outside of regular drawing code. */
- UI_Theme_Store(&theme_state);
- UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
GPU_clear(GPU_DEPTH_BIT);
@@ -826,8 +821,6 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a
U.glalphaclip = glalphaclip;
v3d->flag = flag;
-
- UI_Theme_Restore(&theme_state);
}
/* ******************** other elements ***************** */
@@ -1563,10 +1556,6 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
ar->winrct.xmax = winx;
ar->winrct.ymax = winy;
- struct bThemeState theme_state;
- UI_Theme_Store(&theme_state);
- UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
/* set flags */
G.f |= G_FLAG_RENDER_VIEWPORT;
@@ -1601,8 +1590,6 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
GPU_matrix_pop_projection();
GPU_matrix_pop();
- UI_Theme_Restore(&theme_state);
-
G.f &= ~G_FLAG_RENDER_VIEWPORT;
}
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 2515ee6e482..2c003383549 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -984,7 +984,6 @@ int view3d_opengl_select(ViewContext *vc,
eV3DSelectMode select_mode,
eV3DSelectObjectFilter select_filter)
{
- struct bThemeState theme_state;
Depsgraph *depsgraph = vc->depsgraph;
Scene *scene = vc->scene;
View3D *v3d = vc->v3d;
@@ -1070,10 +1069,6 @@ int view3d_opengl_select(ViewContext *vc,
break;
}
- /* Tools may request depth outside of regular drawing code. */
- UI_Theme_Store(&theme_state);
- UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
/* Re-use cache (rect must be smaller then the cached)
* other context is assumed to be unchanged */
if (GPU_select_is_cached()) {
@@ -1176,8 +1171,6 @@ finally:
printf("Too many objects in select buffer\n"); /* XXX make error message */
}
- UI_Theme_Restore(&theme_state);
-
return hits;
}
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index c620644a5f8..fb7d3c1ace8 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -116,6 +116,7 @@ set(SRC
intern/gpu_batch_private.h
intern/gpu_codegen.h
intern/gpu_context_private.h
+ intern/gpu_matrix_private.h
intern/gpu_primitive_private.h
intern/gpu_private.h
intern/gpu_select_private.h
diff --git a/source/blender/gpu/intern/gpu_context.cpp b/source/blender/gpu/intern/gpu_context.cpp
index 97f9e52f944..93df65006ff 100644
--- a/source/blender/gpu/intern/gpu_context.cpp
+++ b/source/blender/gpu/intern/gpu_context.cpp
@@ -36,6 +36,7 @@
#include "gpu_batch_private.h"
#include "gpu_context_private.h"
+#include "gpu_matrix_private.h"
#include <vector>
#include <string.h>
@@ -71,6 +72,7 @@ struct GPUContext {
std::unordered_set<GPUFrameBuffer *>
framebuffers; /* Framebuffers that have FBO from this context */
#endif
+ struct GPUMatrixState *matrix_state;
std::vector<GLuint> orphaned_vertarray_ids;
std::vector<GLuint> orphaned_framebuffer_ids;
std::mutex orphans_mutex; /* todo: try spinlock instead */
@@ -139,6 +141,7 @@ GPUContext *GPU_context_create(GLuint default_framebuffer)
GPUContext *ctx = new GPUContext;
glGenVertexArrays(1, &ctx->default_vao);
ctx->default_framebuffer = default_framebuffer;
+ ctx->matrix_state = GPU_matrix_state_create();
GPU_context_active_set(ctx);
return ctx;
}
@@ -159,6 +162,7 @@ void GPU_context_discard(GPUContext *ctx)
/* this removes the array entry */
GPU_batch_vao_cache_clear(*ctx->batches.begin());
}
+ GPU_matrix_state_discard(ctx->matrix_state);
glDeleteVertexArrays(1, &ctx->default_vao);
delete ctx;
active_ctx = NULL;
@@ -333,3 +337,9 @@ GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx)
{
return ctx->current_fbo;
}
+
+struct GPUMatrixState *gpu_context_active_matrix_state_get()
+{
+ BLI_assert(active_ctx);
+ return active_ctx->matrix_state;
+}
diff --git a/source/blender/gpu/intern/gpu_context_private.h b/source/blender/gpu/intern/gpu_context_private.h
index 6825b67d2c8..09248e45502 100644
--- a/source/blender/gpu/intern/gpu_context_private.h
+++ b/source/blender/gpu/intern/gpu_context_private.h
@@ -59,6 +59,8 @@ void gpu_context_remove_framebuffer(GPUContext *ctx, struct GPUFrameBuffer *fb);
void gpu_context_active_framebuffer_set(GPUContext *ctx, struct GPUFrameBuffer *fb);
struct GPUFrameBuffer *gpu_context_active_framebuffer_get(GPUContext *ctx);
+struct GPUMatrixState *gpu_context_active_matrix_state_get();
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
index 58ca800a92c..fb0dffb58d1 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -23,6 +23,9 @@
#include "GPU_shader_interface.h"
+#include "gpu_context_private.h"
+#include "gpu_matrix_private.h"
+
#define SUPPRESS_GENERIC_MATRIX_API
#define USE_GPU_PY_MATRIX_API /* only so values are declared */
#include "GPU_matrix.h"
@@ -32,6 +35,8 @@
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
+#include "MEM_guardedalloc.h"
+
#define DEBUG_MATRIX_BIND 0
#define MATRIX_STACK_DEPTH 32
@@ -44,7 +49,7 @@ typedef struct MatrixStack {
uint top;
} MatrixStack;
-typedef struct {
+typedef struct GPUMatrixState {
MatrixStack model_view_stack;
MatrixStack projection_stack;
@@ -56,8 +61,16 @@ typedef struct {
* TODO: separate Model from View transform? Batches/objects have model,
* camera/eye has view & projection
*/
-} MatrixState;
+} GPUMatrixState;
+
+#define ModelViewStack gpu_context_active_matrix_state_get()->model_view_stack
+#define ModelView ModelViewStack.stack[ModelViewStack.top]
+#define ProjectionStack gpu_context_active_matrix_state_get()->projection_stack
+#define Projection ProjectionStack.stack[ProjectionStack.top]
+
+GPUMatrixState *GPU_matrix_state_create(void)
+{
#define MATRIX_4X4_IDENTITY \
{ \
{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, \
@@ -66,27 +79,36 @@ typedef struct {
} \
}
-static MatrixState state = {
- .model_view_stack = {{MATRIX_4X4_IDENTITY}, 0},
- .projection_stack = {{MATRIX_4X4_IDENTITY}, 0},
- .dirty = true,
-};
+ GPUMatrixState *state = MEM_mallocN(sizeof(*state), __func__);
+ const MatrixStack identity_stack = {{MATRIX_4X4_IDENTITY}, 0};
+
+ state->model_view_stack = state->projection_stack = identity_stack;
+ state->dirty = true;
#undef MATRIX_4X4_IDENTITY
-#define ModelViewStack state.model_view_stack
-#define ModelView ModelViewStack.stack[ModelViewStack.top]
+ return state;
+}
-#define ProjectionStack state.projection_stack
-#define Projection ProjectionStack.stack[ProjectionStack.top]
+void GPU_matrix_state_discard(GPUMatrixState *state)
+{
+ MEM_freeN(state);
+}
+
+static void gpu_matrix_state_active_set_dirty(bool value)
+{
+ GPUMatrixState *state = gpu_context_active_matrix_state_get();
+ state->dirty = value;
+}
void GPU_matrix_reset(void)
{
- state.model_view_stack.top = 0;
- state.projection_stack.top = 0;
+ GPUMatrixState *state = gpu_context_active_matrix_state_get();
+ state->model_view_stack.top = 0;
+ state->projection_stack.top = 0;
unit_m4(ModelView);
unit_m4(Projection);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
#ifdef WITH_GPU_SAFETY
@@ -123,7 +145,7 @@ void GPU_matrix_pop(void)
{
BLI_assert(ModelViewStack.top > 0);
ModelViewStack.top--;
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_push_projection(void)
@@ -137,34 +159,34 @@ void GPU_matrix_pop_projection(void)
{
BLI_assert(ProjectionStack.top > 0);
ProjectionStack.top--;
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_set(const float m[4][4])
{
copy_m4_m4(ModelView, m);
CHECKMAT(ModelView3D);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_identity_projection_set(void)
{
unit_m4(Projection);
CHECKMAT(Projection3D);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_projection_set(const float m[4][4])
{
copy_m4_m4(Projection, m);
CHECKMAT(Projection3D);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_identity_set(void)
{
unit_m4(ModelView);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_translate_2f(float x, float y)
@@ -194,7 +216,7 @@ void GPU_matrix_translate_3f(float x, float y, float z)
m[3][2] = z;
GPU_matrix_mul(m);
#endif
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_translate_3fv(const float vec[3])
@@ -243,7 +265,7 @@ void GPU_matrix_mul(const float m[4][4])
{
mul_m4_m4_post(ModelView, m);
CHECKMAT(ModelView);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_rotate_2d(float deg)
@@ -272,7 +294,7 @@ void GPU_matrix_rotate_axis(float deg, char axis)
/* rotate_m4 works in place */
rotate_m4(ModelView, axis, DEG2RADF(deg));
CHECKMAT(ModelView);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
static void mat4_ortho_set(
@@ -298,7 +320,7 @@ static void mat4_ortho_set(
m[2][3] = 0.0f;
m[3][3] = 1.0f;
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
static void mat4_frustum_set(
@@ -324,7 +346,7 @@ static void mat4_frustum_set(
m[2][3] = -1.0f;
m[3][3] = 0.0f;
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
@@ -389,14 +411,14 @@ static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3
m[2][3] = 0.0f;
m[3][3] = 1.0f;
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_ortho_set(float left, float right, float bottom, float top, float near, float far)
{
mat4_ortho_set(Projection, left, right, bottom, top, near, far);
CHECKMAT(Projection);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
@@ -404,7 +426,7 @@ void GPU_matrix_ortho_2d_set(float left, float right, float bottom, float top)
Mat4 m;
mat4_ortho_set(m, left, right, bottom, top, -1.0f, 1.0f);
CHECKMAT(Projection2D);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_frustum_set(
@@ -412,7 +434,7 @@ void GPU_matrix_frustum_set(
{
mat4_frustum_set(Projection, left, right, bottom, top, near, far);
CHECKMAT(Projection);
- state.dirty = true;
+ gpu_matrix_state_active_set_dirty(true);
}
void GPU_matrix_perspective_set(float fovy, float aspect, float near, float far)
@@ -678,12 +700,13 @@ void GPU_matrix_bind(const GPUShaderInterface *shaderface)
glUniformMatrix4fv(P_inv->location, 1, GL_FALSE, (const float *)m);
}
- state.dirty = false;
+ gpu_matrix_state_active_set_dirty(false);
}
bool GPU_matrix_dirty_get(void)
{
- return state.dirty;
+ GPUMatrixState *state = gpu_context_active_matrix_state_get();
+ return state->dirty;
}
/* -------------------------------------------------------------------- */
@@ -695,12 +718,14 @@ BLI_STATIC_ASSERT(GPU_PY_MATRIX_STACK_LEN + 1 == MATRIX_STACK_DEPTH, "define mis
int GPU_matrix_stack_level_get_model_view(void)
{
- return (int)state.model_view_stack.top;
+ GPUMatrixState *state = gpu_context_active_matrix_state_get();
+ return (int)state->model_view_stack.top;
}
int GPU_matrix_stack_level_get_projection(void)
{
- return (int)state.projection_stack.top;
+ GPUMatrixState *state = gpu_context_active_matrix_state_get();
+ return (int)state->projection_stack.top;
}
/** \} */
diff --git a/source/blender/gpu/intern/gpu_matrix_private.h b/source/blender/gpu/intern/gpu_matrix_private.h
new file mode 100644
index 00000000000..862ef065481
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_matrix_private.h
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_MATRIX_PRIVATE_H__
+#define __GPU_MATRIX_PRIVATE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct GPUMatrixState *GPU_matrix_state_create(void);
+void GPU_matrix_state_discard(struct GPUMatrixState *state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GPU_MATRIX_PRIVATE_H__ */
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 9d87922aa3c..4f14a0b9fe0 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -467,8 +467,6 @@ void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
int rect_w = BLI_rcti_size_x(rect) + 1;
int rect_h = BLI_rcti_size_y(rect) + 1;
- DRW_opengl_context_enable();
-
if (dfbl->default_fb) {
if (rect_w != viewport->size[0] || rect_h != viewport->size[1] ||
U.ogl_multisamples != viewport->samples) {
@@ -559,7 +557,6 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect)
void GPU_viewport_unbind(GPUViewport *UNUSED(viewport))
{
GPU_framebuffer_restore();
- DRW_opengl_context_disable();
}
GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport)
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index 3951644ec81..c146097aeb0 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -48,6 +48,8 @@
#include "BKE_scene.h"
#include "BKE_workspace.h"
+#include "DRW_engine.h"
+
#include "GHOST_C-api.h"
#include "ED_node.h"
@@ -400,6 +402,7 @@ static void wm_draw_region_bind(ARegion *ar, int view)
}
if (ar->draw_buffer->viewport[view]) {
+ DRW_opengl_context_enable();
GPU_viewport_bind(ar->draw_buffer->viewport[view], &ar->winrct);
}
else {
@@ -424,6 +427,7 @@ static void wm_draw_region_unbind(ARegion *ar, int view)
if (ar->draw_buffer->viewport[view]) {
GPU_viewport_unbind(ar->draw_buffer->viewport[view]);
+ DRW_opengl_context_disable();
}
else {
glDisable(GL_SCISSOR_TEST);
@@ -750,35 +754,24 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
void wm_draw_upside_down(int sizex, int sizey, bool to_srgb)
{
- 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(to_srgb ? GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB : GPU_SHADER_2D_IMAGE);
/* wmOrtho for the screen has this same offset */
const float halfx = GLA_PIXEL_OFS / sizex;
- const float halfy = GLA_PIXEL_OFS / sizex;
-
- immUniform1i("image", 0); /* texture is already bound to GL_TEXTURE0 unit */
-
- immBegin(GPU_PRIM_TRI_FAN, 4);
-
- immAttr2f(texcoord, halfx, 1.0f + halfy);
- immVertex2f(pos, 0.0f, 0.0f);
-
- immAttr2f(texcoord, 1.0f + halfx, 1.0f + halfy);
- immVertex2f(pos, sizex, 0.0f);
+ const float halfy = GLA_PIXEL_OFS / sizey;
- immAttr2f(texcoord, 1.0f + halfx, halfy);
- immVertex2f(pos, sizex, sizey);
-
- immAttr2f(texcoord, halfx, halfy);
- immVertex2f(pos, 0.0f, sizey);
+ GPUShader *shader = GPU_shader_get_builtin_shader(to_srgb ? GPU_SHADER_2D_IMAGE_RECT_LINEAR_TO_SRGB : GPU_SHADER_2D_IMAGE_RECT_COLOR);
+ GPU_shader_bind(shader);
- immEnd();
+ glUniform1i(GPU_shader_get_uniform_ensure(shader, "image"), 0);
+ glUniform4f(GPU_shader_get_uniform_ensure(shader, "rect_icon"),
+ halfx,
+ halfy,
+ 1.0f + halfx,
+ 1.0f + halfy);
+ glUniform4f(GPU_shader_get_uniform_ensure(shader, "rect_geom"), 0, sizey, sizex, 0);
+ glUniform4f(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR), 1.0f, 1.0f, 1.0f, 1.0f);
- immUnbindProgram();
+ GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
}
static void wm_draw_window_upside_down_onscreen(bContext *C, wmWindow *win)
@@ -892,15 +885,15 @@ static void wm_draw_window(bContext *C, wmWindow *win)
*/
static void wm_draw_surface(bContext *C, wmSurface *surface)
{
- wm_window_clear_drawable(CTX_wm_manager(C));
- wm_surface_make_drawable(surface);
+ // wm_window_clear_drawable(CTX_wm_manager(C));
+ // wm_surface_make_drawable(surface);
surface->draw(C);
- wm_surface_present(surface);
+ // wm_surface_present(surface);
/* Avoid interference with window drawable */
- wm_surface_clear_drawable();
+ // wm_surface_clear_drawable();
}
/****************** main update call **********************/
diff --git a/source/blender/windowmanager/intern/wm_surface.c b/source/blender/windowmanager/intern/wm_surface.c
index 8b3a5e55beb..38057370b92 100644
--- a/source/blender/windowmanager/intern/wm_surface.c
+++ b/source/blender/windowmanager/intern/wm_surface.c
@@ -52,6 +52,7 @@ void wm_surfaces_iter(bContext *C, void (*cb)(bContext *C, wmSurface *))
void wm_surface_clear_drawable(void)
{
+#if 0
if (g_drawable) {
BLF_batch_reset();
gpu_batch_presets_reset();
@@ -59,6 +60,7 @@ void wm_surface_clear_drawable(void)
g_drawable = NULL;
}
+#endif
}
void wm_surface_set_drawable(wmSurface *surface, bool activate)
@@ -67,11 +69,11 @@ void wm_surface_set_drawable(wmSurface *surface, bool activate)
g_drawable = surface;
if (activate) {
- GHOST_ActivateOpenGLContext(surface->ghost_ctx);
+ // GHOST_ActivateOpenGLContext(surface->ghost_ctx);
}
- GPU_context_active_set(surface->gpu_ctx);
- immActivate();
+ // GPU_context_active_set(surface->gpu_ctx);
+ // immActivate();
}
void wm_surface_make_drawable(wmSurface *surface)
@@ -97,9 +99,9 @@ void wm_surface_reset_drawable(void)
void wm_surface_present(wmSurface *surface)
{
- GHOST_SwapContextBuffers(surface->ghost_ctx);
+ // GHOST_SwapContextBuffers(surface->ghost_ctx);
if (surface->secondary_ghost_ctx) {
- GHOST_SwapContextBuffers(surface->secondary_ghost_ctx);
+ // GHOST_SwapContextBuffers(surface->secondary_ghost_ctx);
}
}
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 82d17b6cd6e..fbe6bf906d1 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -22,10 +22,17 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_report.h"
+#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
+#include "BLI_threads.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_query.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -62,6 +69,8 @@ static void xr_session_window_create(bContext *C);
#endif
static wmSurface *g_xr_surface = NULL;
+static Depsgraph *g_depsgraph = NULL;
+ListBase g_threadpool;
typedef struct {
GHOST_TXrGraphicsBinding gpu_binding_type;
@@ -129,12 +138,14 @@ bool wm_xr_context_ensure(bContext *C, wmWindowManager *wm)
static void wm_xr_session_surface_draw(bContext *C)
{
+#if 0
wmWindowManager *wm = CTX_wm_manager(C);
if (!GHOST_XrSessionIsRunning(wm->xr_context)) {
return;
}
GHOST_XrSessionDrawViews(wm->xr_context, C);
+#endif
}
static void wm_xr_session_free_data(wmSurface *surface)
@@ -148,8 +159,9 @@ static void wm_xr_session_free_data(wmSurface *surface)
}
#endif
}
+ WM_opengl_context_activate(surface->ghost_ctx);
GPU_context_active_set(surface->gpu_ctx);
- DRW_opengl_context_enable_ex(false);
+
if (data->viewport) {
GPU_viewport_clear_from_offscreen(data->viewport);
GPU_viewport_free(data->viewport);
@@ -157,7 +169,12 @@ static void wm_xr_session_free_data(wmSurface *surface)
if (data->offscreen) {
GPU_offscreen_free(data->offscreen);
}
- DRW_opengl_context_disable_ex(false);
+ GPU_context_discard(g_xr_surface->gpu_ctx);
+ GPU_context_active_set(NULL);
+ WM_opengl_context_release(surface->ghost_ctx);
+ WM_opengl_context_dispose(surface->ghost_ctx);
+
+ DEG_graph_free(g_depsgraph);
MEM_freeN(surface->customdata);
@@ -185,8 +202,8 @@ static wmSurface *wm_xr_session_surface_create(wmWindowManager *UNUSED(wm),
data->gpu_binding_type = gpu_binding_type;
surface->customdata = data;
- surface->ghost_ctx = DRW_opengl_context_get();
- DRW_opengl_context_enable();
+ surface->ghost_ctx = WM_opengl_context_create();
+ WM_opengl_context_activate(surface->ghost_ctx);
switch (gpu_binding_type) {
case GHOST_kXrGraphicsOpenGL:
@@ -198,9 +215,11 @@ static wmSurface *wm_xr_session_surface_create(wmWindowManager *UNUSED(wm),
#endif
}
- surface->gpu_ctx = DRW_gpu_context_get();
+ WM_opengl_context_release(surface->ghost_ctx);
+ GPU_context_active_set(NULL);
+ wm_window_reset_drawable();
- DRW_opengl_context_disable();
+ BLI_threadpool_end(&g_threadpool);
g_xr_surface = surface;
@@ -255,7 +274,6 @@ static bool wm_xr_session_surface_offscreen_ensure(const GHOST_XrDrawViewInfo *d
return true;
}
- DRW_opengl_context_enable();
if (surface_data->offscreen) {
GPU_viewport_clear_from_offscreen(surface_data->viewport);
GPU_viewport_free(surface_data->viewport);
@@ -271,7 +289,6 @@ static bool wm_xr_session_surface_offscreen_ensure(const GHOST_XrDrawViewInfo *d
GPU_offscreen_free(surface_data->offscreen);
failure = true;
}
- DRW_opengl_context_disable();
if (failure) {
fprintf(stderr, "%s: failed to get buffer, %s\n", __func__, err_out);
@@ -297,7 +314,12 @@ static GHOST_ContextHandle wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view
wm_xr_draw_matrices_create(CTX_data_scene(C), draw_view, clip_start, clip_end, viewmat, winmat);
+ BKE_scene_graph_evaluated_ensure(g_depsgraph, CTX_data_main(C));
+
+ DRW_render_context_draw_begin();
+
if (!wm_xr_session_surface_offscreen_ensure(draw_view)) {
+ // TODO disable correctly.
return NULL;
}
@@ -309,8 +331,8 @@ static GHOST_ContextHandle wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view
BKE_screen_view3d_shading_init(&shading);
shading.flag |= V3D_SHADING_WORLD_ORIENTATION;
shading.background_type = V3D_SHADING_BACKGROUND_WORLD;
- ED_view3d_draw_offscreen_simple(CTX_data_ensure_evaluated_depsgraph(C),
- CTX_data_scene(C),
+ ED_view3d_draw_offscreen_simple(g_depsgraph,
+ DEG_get_evaluated_scene(g_depsgraph),
&shading,
OB_SOLID,
draw_view->width,
@@ -334,18 +356,23 @@ static GHOST_ContextHandle wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view
GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
wm_draw_offscreen_texture_parameters(offscreen);
- GPU_depth_test(false);
wmViewport(&rect);
- GPU_viewport_draw_to_screen_ex(viewport, &rect, draw_view->expects_srgb_buffer);
+
if (g_xr_surface->secondary_ghost_ctx &&
GHOST_isUpsideDownContext(g_xr_surface->secondary_ghost_ctx)) {
GPU_texture_bind(texture, 0);
wm_draw_upside_down(draw_view->width, draw_view->height, draw_view->expects_srgb_buffer);
GPU_texture_unbind(texture);
}
+ else {
+ GPU_viewport_draw_to_screen_ex(viewport, &rect, draw_view->expects_srgb_buffer);
+ }
+
GPU_viewport_unbind(viewport);
+ DRW_render_context_draw_end();
+
return g_xr_surface->ghost_ctx;
}
@@ -385,6 +412,56 @@ static void wm_xr_session_gpu_binding_context_destroy(
wm_window_reset_drawable();
}
+static Depsgraph *wm_xr_session_depsgraph_create(Main *bmain, Scene *scene, ViewLayer *viewlayer)
+{
+ Depsgraph *deg = DEG_graph_new(scene, viewlayer, DAG_EVAL_VIEWPORT);
+
+ DEG_debug_name_set(deg, "VR SESSION");
+ DEG_graph_build_from_view_layer(deg, bmain, scene, viewlayer);
+ BKE_scene_graph_evaluated_ensure(deg, bmain);
+ /* XXX Why do we have to call this? Depsgraph should handle. */
+ BKE_scene_base_flag_to_objects(DEG_get_evaluated_view_layer(deg));
+
+ return deg;
+}
+
+static void *wm_xr_session_drawthread_main(void *data)
+{
+ bContext *C = data;
+ wmWindowManager *wm = CTX_wm_manager(C);
+
+ g_depsgraph = wm_xr_session_depsgraph_create(
+ CTX_data_main(C), CTX_data_scene(C), CTX_data_view_layer(C));
+
+ WM_opengl_context_activate(g_xr_surface->ghost_ctx);
+ g_xr_surface->gpu_ctx = GPU_context_create(
+ GHOST_GetContextDefaultOpenGLFramebuffer(g_xr_surface->ghost_ctx));
+ WM_opengl_context_release(g_xr_surface->ghost_ctx);
+
+ DRW_opengl_render_context_enable_ex(g_xr_surface->ghost_ctx);
+ DRW_gawain_render_context_enable(g_xr_surface->gpu_ctx);
+
+ /* Sort of the session's main loop. */
+ while (GHOST_XrHasSession(wm->xr_context)) {
+ if (!GHOST_XrSessionShouldRunDrawLoop(wm->xr_context)) {
+ continue;
+ }
+
+ GHOST_XrSessionDrawViews(wm->xr_context, C);
+ }
+
+ DRW_gawain_render_context_disable(g_xr_surface->gpu_ctx);
+ DRW_opengl_render_context_disable_ex(g_xr_surface->ghost_ctx);
+
+ return NULL;
+}
+
+static void wm_xr_session_drawthread_spawn(bContext *C)
+{
+ BLI_threadpool_init(&g_threadpool, wm_xr_session_drawthread_main, 1);
+ BLI_threadpool_insert(&g_threadpool, C);
+}
+
static void wm_xr_session_begin_info_create(const Scene *scene,
GHOST_XrSessionBeginInfo *begin_info)
{
@@ -403,7 +480,7 @@ void wm_xr_session_toggle(bContext *C, void *xr_context_ptr)
{
GHOST_XrContextHandle xr_context = xr_context_ptr;
- if (xr_context && GHOST_XrSessionIsRunning(xr_context)) {
+ if (xr_context && GHOST_XrHasSession(xr_context)) {
GHOST_XrSessionEnd(xr_context);
}
else {
@@ -420,6 +497,7 @@ void wm_xr_session_toggle(bContext *C, void *xr_context_ptr)
GHOST_XrDrawViewFunc(xr_context, wm_xr_draw_view);
GHOST_XrSessionStart(xr_context, &begin_info);
+ wm_xr_session_drawthread_spawn(C);
}
}