[Bf-blender-cvs] [33306067dab] xr-controller-support: Update based on D10948
Peter Kim
noreply at git.blender.org
Fri Sep 10 10:58:10 CEST 2021
Commit: 33306067dabb2bf660687afe91431eea9d5756df
Author: Peter Kim
Date: Fri Sep 10 17:23:56 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB33306067dabb2bf660687afe91431eea9d5756df
Update based on D10948
===================================================================
M intern/ghost/intern/GHOST_XrControllerModel.cpp
M intern/ghost/intern/GHOST_XrControllerModel.h
M source/blender/windowmanager/xr/intern/wm_xr_draw.c
===================================================================
diff --git a/intern/ghost/intern/GHOST_XrControllerModel.cpp b/intern/ghost/intern/GHOST_XrControllerModel.cpp
index d943423eabb..e33d8db21d5 100644
--- a/intern/ghost/intern/GHOST_XrControllerModel.cpp
+++ b/intern/ghost/intern/GHOST_XrControllerModel.cpp
@@ -299,7 +299,7 @@ static void calc_node_transforms(const tinygltf::Node &gltf_node,
*(Eigen::Matrix4f *)r_local_transform;
}
-static void load_node(tinygltf::Model gltf_model,
+static void load_node(const tinygltf::Model &gltf_model,
int gltf_node_id,
int32_t parent_idx,
const float parent_transform[4][4],
@@ -469,8 +469,8 @@ void GHOST_XrControllerModel::loadControllerModel(XrSession session)
CHECK_XR(g_xrLoadControllerModelMSFT(session, m_model_key, 0, &buf_size, nullptr),
"Failed to get controller model buffer size.");
- m_data = std::make_unique<uint8_t[]>(buf_size);
- CHECK_XR(g_xrLoadControllerModelMSFT(session, m_model_key, buf_size, &buf_size, m_data.get()),
+ std::vector<uint8_t> buf((size_t)buf_size);
+ CHECK_XR(g_xrLoadControllerModelMSFT(session, m_model_key, buf_size, &buf_size, buf.data()),
"Failed to load controller model binary buffers.");
/* Convert to glTF model. */
@@ -478,7 +478,7 @@ void GHOST_XrControllerModel::loadControllerModel(XrSession session)
tinygltf::Model gltf_model;
std::string err_msg;
- if (!gltf_loader.LoadBinaryFromMemory(&gltf_model, &err_msg, nullptr, m_data.get(), buf_size)) {
+ if (!gltf_loader.LoadBinaryFromMemory(&gltf_model, &err_msg, nullptr, buf.data(), buf_size)) {
throw GHOST_XrException(("Failed to load glTF controller model: " + err_msg).c_str());
}
diff --git a/intern/ghost/intern/GHOST_XrControllerModel.h b/intern/ghost/intern/GHOST_XrControllerModel.h
index e1d372b865b..5ff72957b24 100644
--- a/intern/ghost/intern/GHOST_XrControllerModel.h
+++ b/intern/ghost/intern/GHOST_XrControllerModel.h
@@ -25,7 +25,6 @@
#include <atomic>
#include <future>
-#include <memory>
#include <vector>
struct GHOST_XrControllerModelNode;
@@ -48,7 +47,6 @@ class GHOST_XrControllerModel {
std::future<void> m_load_task;
std::atomic<bool> m_data_loaded = false;
- std::unique_ptr<uint8_t[]> m_data = nullptr;
std::vector<GHOST_XrControllerModelVertex> m_vertices;
std::vector<uint32_t> m_indices;
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index 235b298216a..0f0806754e8 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -331,7 +331,14 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_FLAT_COLOR);
+
+ float viewport[4];
+ GPU_viewport_size_get_f(viewport);
+ immUniform2fv("viewportSize", &viewport[2]);
+
+ immUniform1f("lineWidth", 3.0f * U.pixelsize);
if (draw_ray) {
const float color[4] = {0.35f, 0.35f, 1.0f, 0.5f};
@@ -339,19 +346,20 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
float ray[3];
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
- GPU_line_width(3.0f);
+ GPU_blend(GPU_BLEND_ALPHA);
- immUniformColor4fv(color);
+ immBegin(GPU_PRIM_LINES, (uint)BLI_listbase_count(&state->controllers) * 2);
+ immAttr4fv(col, color);
LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
const float(*mat)[4] = controller->aim_mat;
madd_v3_v3v3fl(ray, mat[3], mat[2], -scale);
- immBegin(GPU_PRIM_LINES, 2);
immVertex3fv(pos, mat[3]);
immVertex3fv(pos, ray);
- immEnd();
}
+
+ immEnd();
}
else {
const float r[4] = {1.0f, 0.2f, 0.322f, 1.0f};
@@ -362,7 +370,8 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
GPU_depth_test(GPU_DEPTH_NONE);
GPU_blend(GPU_BLEND_NONE);
- GPU_line_width(3.0f);
+
+ immBegin(GPU_PRIM_LINES, (uint)BLI_listbase_count(&state->controllers) * 6);
LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) {
const float(*mat)[4] = controller->aim_mat;
@@ -370,24 +379,20 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region),
madd_v3_v3v3fl(y_axis, mat[3], mat[1], scale);
madd_v3_v3v3fl(z_axis, mat[3], mat[2], scale);
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(r);
+ immAttr4fv(col, r);
immVertex3fv(pos, mat[3]);
immVertex3fv(pos, x_axis);
- immEnd();
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(g);
+ immAttr4fv(col, g);
immVertex3fv(pos, mat[3]);
immVertex3fv(pos, y_axis);
- immEnd();
- immBegin(GPU_PRIM_LINES, 2);
- immUniformColor4fv(b);
+ immAttr4fv(col, b);
immVertex3fv(pos, mat[3]);
immVertex3fv(pos, z_axis);
- immEnd();
}
+
+ immEnd();
}
immUnbindProgram();
More information about the Bf-blender-cvs
mailing list