Skip to content

Commit

Permalink
Feature/improvements (#14)
Browse files Browse the repository at this point in the history
* Style revamp, error guards for enums, allow for info without session

* Different text colors for properties

* Update screenshot with new theme
  • Loading branch information
maluoi authored Oct 24, 2022
1 parent fbb6c6e commit 561cc3f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 32 deletions.
Binary file modified docs/OpenXRExplorerWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 40 additions & 13 deletions src/openxrexplorer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,38 @@ bool app_args(int32_t arg_count, const char **args) {
bool app_init() {
ImGuiStyle* style = &ImGui::GetStyle();
ImVec4* colors = style->Colors;
style->FrameRounding = 1;
style->FrameRounding = 2;
style->FramePadding = ImVec2{ 6, 4 };
style->WindowPadding = ImVec2{ 10, 10 };
style->ScrollbarRounding = 1;
style->AntiAliasedFill = false;
style->AntiAliasedLines = false;
style->AntiAliasedLinesUseTex = false;


ImVec4 major = ImVec4(0.471f, 0.169f, 0.565f, 1.00f);
ImVec4 mid = ImVec4(major.x*0.75f, major.y*0.75f, major.z*0.75f, 1);
ImVec4 minor = ImVec4(major.x*0.5f, major.y*0.5f, major.z*0.5f, 1);
ImVec4 barely = ImVec4(major.x*0.3f, major.y*0.3f, major.z*0.3f, 1);
ImVec4 desat = ImVec4(0.3f, 0.3f, 0.3f, 1.00f);

ImVec4 midsat = ImVec4(major.x * 0.75f, major.y * 0.75f, major.z * 0.75f, 1);
ImVec4 mid = ImVec4(desat.x*0.75f, desat.y*0.75f, desat.z*0.75f, 1);
ImVec4 minor = ImVec4(desat.x*0.5f, desat.y*0.5f, desat.z*0.5f, 1);
ImVec4 barely = ImVec4(desat.x*0.3f, desat.y*0.3f, desat.z*0.3f, 1);
ImVec4 barelysat= ImVec4(major.x*0.3f, major.y*0.3f, major.z*0.3f, 1);
ImVec4 hover = ImVec4(major.x*0.85f, major.y*0.85f, major.z*0.85f, 1);
ImVec4 action = major;

colors[ImGuiCol_DockingPreview] = major;
colors[ImGuiCol_Header] = colors[ImGuiCol_FrameBg] = colors[ImGuiCol_TabUnfocused] = minor;
colors[ImGuiCol_Button] = colors[ImGuiCol_ResizeGrip] = colors[ImGuiCol_TabUnfocusedActive] = colors[ImGuiCol_Tab] = mid;
colors[ImGuiCol_ButtonActive ] = colors[ImGuiCol_ResizeGripActive] = colors[ImGuiCol_HeaderActive] = colors[ImGuiCol_TabActive] = colors[ImGuiCol_FrameBgActive] = action;
colors[ImGuiCol_ButtonHovered] = colors[ImGuiCol_ResizeGripHovered] = colors[ImGuiCol_HeaderHovered] = colors[ImGuiCol_TabHovered] = colors[ImGuiCol_FrameBgHovered] = hover;
colors[ImGuiCol_TableRowBgAlt] = colors[ImGuiCol_TitleBgActive] = barely;
colors[ImGuiCol_Header] = colors[ImGuiCol_FrameBg] = colors[ImGuiCol_TabUnfocused] = minor;
colors[ImGuiCol_Button] = colors[ImGuiCol_ResizeGrip] = colors[ImGuiCol_Tab] = mid;
colors[ImGuiCol_ButtonActive ] = colors[ImGuiCol_ResizeGripActive] = colors[ImGuiCol_HeaderActive] = colors[ImGuiCol_TabActive] = colors[ImGuiCol_FrameBgActive] = colors[ImGuiCol_CheckMark] = action;
colors[ImGuiCol_ButtonHovered] = colors[ImGuiCol_ResizeGripHovered] = colors[ImGuiCol_HeaderHovered] = colors[ImGuiCol_TabHovered] = colors[ImGuiCol_FrameBgHovered] = hover;
colors[ImGuiCol_TitleBg] = colors[ImGuiCol_TitleBgActive] = barelysat;
colors[ImGuiCol_TableRowBgAlt] = barely;
colors[ImGuiCol_TabUnfocusedActive] = colors[ImGuiCol_Separator] = midsat;

load_runtimes(runtime_config_path(), &runtimes, &runtime_count);

app_xr_settings.allow_session = true;
app_xr_settings.allow_session = false;
app_xr_settings.form = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
openxr_info_reload(app_xr_settings);

Expand Down Expand Up @@ -126,6 +139,8 @@ void app_window_runtime() {
ImGui::Separator();
ImGui::Spacing();

ImGui::Text(xr_runtime_name);

// Runtime picker
if (ImGui::BeginCombo("##Change Runtime", current_runtime == -1 ? "Change Runtime" : runtimes[current_runtime].name)) {
for (int n = 0; n < runtime_count; n++) {
Expand All @@ -141,10 +156,12 @@ void app_window_runtime() {
}
ImGui::EndCombo();
}
ImGui::SameLine();

if (ImGui::Button("Reload runtime data")) {
openxr_info_reload(app_xr_settings);
}
ImGui::SameLine();
ImGui::Checkbox("Create XrSession", &app_xr_settings.allow_session);

ImGui::Spacing();
ImGui::Separator();
Expand Down Expand Up @@ -187,7 +204,6 @@ void app_window_runtime() {
///////////////////////////////////////////

void app_window_openxr_functionality() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("Extensions & Layers");

for (size_t i = 0; i < xr_tables.count; i++) {
Expand All @@ -196,7 +212,6 @@ void app_window_openxr_functionality() {
}

ImGui::End();
ImGui::PopStyleVar();
}

///////////////////////////////////////////
Expand Down Expand Up @@ -240,6 +255,9 @@ void app_window_view() {
///////////////////////////////////////////

void app_element_table(const display_table_t *table) {
const float text_col = 0.7f;
const ImVec4 text_vec = ImVec4{ text_col,text_col,text_col,1 };

if (ImGui::TreeNodeEx(table->show_type ? table->name_type : table->name_func, ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap)) {
if (table->spec) {
ImGui::SameLine(ImGui::GetContentRegionMax().x - (ImGui::CalcTextSize("Open Spec").x + GImGui->Style.FramePadding.x * 3));
Expand All @@ -256,7 +274,10 @@ void app_element_table(const display_table_t *table) {
if (ImGui::BeginTable(table->name_type, 1, flags)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();

ImGui::PushStyleColor(ImGuiCol_Text, text_vec);
ImGui::Text("%s", table->error);
ImGui::PopStyleColor();

ImGui::EndTable();
}
Expand All @@ -267,20 +288,26 @@ void app_element_table(const display_table_t *table) {
ImGui::TableHeadersRow();
}

ImGui::PushStyleColor(ImGuiCol_Text, text_vec);

for (size_t i = table->header_row?1:0; i < table->cols[0].count; i++) {
ImGui::TableNextRow();
for (size_t c = 0; c < table->column_count; c++) {
ImGui::TableNextColumn();
if (table->cols[c][i].spec) {
ImGui::PushID(i);
ImGui::PopStyleColor();
if (ImGui::Button("Spec"))
app_open_spec(table->cols[c][i].spec);
ImGui::PushStyleColor(ImGuiCol_Text, text_vec);
ImGui::PopID();
} else {
ImGui::Text("%s", table->cols[c][i].text);
}
}
}

ImGui::PopStyleColor();
ImGui::EndTable();
}

Expand Down
72 changes: 53 additions & 19 deletions src/openxrexplorer/openxr_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const char *xr_session_err = nullptr;
XrSystemId xr_system_id = {};
const char *xr_system_err = nullptr;

const char* xr_runtime_name = "No runtime set";

#define XR_NEXT_INSERT(obj, obj_next) obj_next.next = obj.next; obj.next = &obj_next;

/*** Signatures **************************/
Expand Down Expand Up @@ -85,6 +87,7 @@ void openxr_info_release() {
xr_extensions.extensions.free();
xr_extensions.layers .free();
xr_extensions = {};
xr_runtime_name = "No runtime set";

xr_table_strings.each(free);
xr_table_strings.free();
Expand Down Expand Up @@ -182,14 +185,17 @@ void openxr_init_instance(array_t<XrExtensionProperties> extensions) {
XrResult result = xrCreateInstance(&create_info, &xr_instance);
if (XR_FAILED(result)) {
xr_instance_err = openxr_result_string(result);
xr_system_err = "No XrInstance available";
xr_session_err = "No XrInstance available";
}
}

///////////////////////////////////////////

void openxr_init_system(XrFormFactor form) {
if (xr_instance_err != nullptr) {
xr_system_err = "XrInstance not available!";
xr_system_err = "No XrInstance available";
xr_session_err = "No XrInstance available";
return;
}
if (xr_system_id != XR_NULL_SYSTEM_ID || xr_system_err != nullptr)
Expand All @@ -200,18 +206,19 @@ void openxr_init_system(XrFormFactor form) {
XrResult result = xrGetSystem(xr_instance, &system_info, &xr_system_id);
if (XR_FAILED(result)) {
xr_system_err = openxr_result_string(result);
xr_session_err = "No XrSystemId available";
}
}

///////////////////////////////////////////

void openxr_init_session() {
if (xr_instance_err != nullptr) {
xr_session_err = "XrInstance not available!";
xr_session_err = "No XrInstance available";
return;
}
if (xr_system_err != nullptr) {
xr_session_err = "XrSystemId not available!";
xr_session_err = "No XrSystemId available";
return;
}
if (xr_session != XR_NULL_HANDLE || xr_session_err != nullptr)
Expand Down Expand Up @@ -348,6 +355,7 @@ xr_properties_t openxr_load_properties() {
if (XR_FAILED(error)) {
table.error = openxr_result_string(error);
} else {
xr_runtime_name = new_string("%s", result.instance.runtimeName);
table.cols[0].add({ "runtimeName" }); table.cols[1].add({ new_string("%s", result.instance.runtimeName) });
table.cols[0].add({ "runtimeVersion" }); table.cols[1].add({ new_string("%d.%d.%d",
(int32_t)XR_VERSION_MAJOR(result.instance.runtimeVersion),
Expand Down Expand Up @@ -646,29 +654,49 @@ xr_view_info_t openxr_load_view(XrViewConfigurationType view_config) {
///////////////////////////////////////////

void openxr_load_enums(xr_settings_t settings) {
// Check if any of the enums need a session
if (!xr_session_err && settings.allow_session) {
bool requires_session = false;
for (size_t i = 0; i < xr_misc_enums.count; i++) {
requires_session = requires_session || xr_misc_enums[i].requires_session;
}
if (requires_session) {
openxr_init_session();
}
} else if (!xr_session_err) {
xr_session_err = "Reload with Session enabled";
}

for (size_t i = 0; i < xr_misc_enums.count; i++) {
xr_misc_enums[i].items.clear();
if (!xr_misc_enums[i].requires_session || settings.allow_session) {
if (xr_misc_enums[i].requires_session)
openxr_init_session();

display_table_t table = {};
table.name_func = xr_misc_enums[i].source_fn_name;
table.name_type = xr_misc_enums[i].source_type_name;
table.spec = xr_misc_enums[i].spec_link;
table.tag = xr_misc_enums[i].tag;
table.column_count = 1;

if ((!xr_misc_enums[i].requires_session || !xr_session_err ) &&
(!xr_misc_enums[i].requires_instance || !xr_instance_err) &&
(!xr_misc_enums[i].requires_system || !xr_system_err )) {

XrResult error = xr_misc_enums[i].load_info(&xr_misc_enums[i], settings);

display_table_t table = {};
table.name_func = xr_misc_enums[i].source_fn_name;
table.name_type = xr_misc_enums[i].source_type_name;
table.spec = xr_misc_enums[i].spec_link;
table.tag = xr_misc_enums[i].tag;
table.column_count = 1;
for (size_t e = 0; e < xr_misc_enums[i].items.count; e++) {
table.cols[0].add({ xr_misc_enums[i].items[e] });
}
if (XR_FAILED(error)) {
table.error = openxr_result_string(error);
}
xr_tables.add(table);
} else {
xr_misc_enums[i].items.add("XrSession unavailable!");

if (xr_misc_enums[i].requires_instance && xr_instance_err) table.error = "No XrInstance available";
else if (xr_misc_enums[i].requires_system && xr_system_err ) table.error = "No XrSystemId available";
else if (xr_misc_enums[i].requires_session && xr_session_err ) table.error = "No XrSession available";
}

xr_tables.add(table);
}
}

Expand Down Expand Up @@ -703,7 +731,8 @@ void openxr_register_enums() {
info = { "xrEnumerateEnvironmentBlendModes" };
info.source_type_name = "XrEnvironmentBlendMode";
info.spec_link = "XrEnvironmentBlendMode";
info.requires_session = false;
info.requires_instance= true;
info.requires_system = true;
info.tag = display_tag_view;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
if (settings.view_config == 0) {
Expand Down Expand Up @@ -771,6 +800,7 @@ void openxr_register_enums() {
info.source_type_name = "XrColorSpaceFB";
info.spec_link = "XrColorSpaceFB";
info.requires_session = true;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateColorSpacesFB xrEnumerateColorSpacesFB;
Expand Down Expand Up @@ -798,6 +828,7 @@ void openxr_register_enums() {
info.source_type_name = "float";
info.spec_link = "xrEnumerateDisplayRefreshRatesFB";
info.requires_session = true;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateDisplayRefreshRatesFB xrEnumerateDisplayRefreshRatesFB;
Expand All @@ -821,6 +852,7 @@ void openxr_register_enums() {
info.source_type_name = "XrRenderModelPathInfoFB";
info.spec_link = "XrRenderModelPathInfoFB";
info.requires_session = true;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateRenderModelPathsFB xrEnumerateRenderModelPathsFB;
Expand All @@ -843,7 +875,7 @@ void openxr_register_enums() {
info = { "xrEnumerateViveTrackerPathsHTCX" };
info.source_type_name = "XrViveTrackerPathsHTCX";
info.spec_link = "XrViveTrackerPathsHTCX";
info.requires_session = false;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateViveTrackerPathsHTCX xrEnumerateViveTrackerPathsHTCX;
Expand All @@ -869,7 +901,7 @@ void openxr_register_enums() {
info = { "xrEnumeratePerformanceMetricsCounterPathsMETA" };
info.source_type_name = "XrPath";
info.spec_link = "xrEnumeratePerformanceMetricsCounterPathsMETA";
info.requires_session = false;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumeratePerformanceMetricsCounterPathsMETA xrEnumeratePerformanceMetricsCounterPathsMETA;
Expand All @@ -892,7 +924,8 @@ void openxr_register_enums() {
info = { "xrEnumerateReprojectionModesMSFT" };
info.source_type_name = "XrReprojectionModeMSFT";
info.spec_link = "XrReprojectionModeMSFT";
info.requires_session = false;
info.requires_system = true;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateReprojectionModesMSFT xrEnumerateReprojectionModesMSFT;
Expand All @@ -919,7 +952,8 @@ void openxr_register_enums() {
info = { "xrEnumerateSceneComputeFeaturesMSFT" };
info.source_type_name = "XrSceneComputeFeatureMSFT";
info.spec_link = "XrSceneComputeFeatureMSFT";
info.requires_session = false;
info.requires_system = true;
info.requires_instance= true;
info.tag = display_tag_misc;
info.load_info = [](xr_enum_info_t *ref_info, xr_settings_t settings) {
PFN_xrEnumerateSceneComputeFeaturesMSFT xrEnumerateSceneComputeFeaturesMSFT;
Expand Down
4 changes: 4 additions & 0 deletions src/openxrexplorer/openxr_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct xr_enum_info_t {
const char *source_type_name;
const char *spec_link;
const char *error;
bool requires_instance;
bool requires_system;
bool requires_session;
display_tag_ tag;
array_t<const char *> items;
Expand Down Expand Up @@ -97,6 +99,8 @@ extern const char *xr_instance_err;
extern const char *xr_session_err;
extern const char *xr_system_err;

extern const char* xr_runtime_name;

/*** Signatures **************************/

void openxr_info_reload (xr_settings_t settings);
Expand Down

0 comments on commit 561cc3f

Please sign in to comment.