Skip to content

Commit 9e40b0d

Browse files
committed
merging drawing functions
1 parent 1e8188f commit 9e40b0d

File tree

6 files changed

+79
-104
lines changed

6 files changed

+79
-104
lines changed

.github/workflows/ci-emscripten.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ jobs:
6060
path: |
6161
${{github.workspace}}/build
6262
63-
- name: Copy web app
64-
working-directory: ${{github.workspace}}/build
65-
run: |
66-
mkdir deploy
67-
cp Samplin\ Safari.data Samplin\ Safari.html Samplin\ Safari.js Samplin\ Safari.wasm SamplinSafari_favicon.png FileSaver.js deploy/
68-
mv deploy/Samplin\ Safari.html deploy/index.html
63+
# - name: Copy web app
64+
# working-directory: ${{github.workspace}}/build
65+
# run: |
66+
# mkdir deploy
67+
# cp Samplin\ Safari.data Samplin\ Safari.html Samplin\ Safari.js Samplin\ Safari.wasm SamplinSafari_favicon.png FileSaver.js deploy/
68+
# mv deploy/Samplin\ Safari.html deploy/index.html
6969

70-
- name: Publish
71-
uses: peaceiris/actions-gh-pages@v3
72-
with:
73-
personal_token: ${{ secrets.GITHUB_TOKEN }}
74-
publish_branch: gh-pages
75-
publish_dir: ${{github.workspace}}/build/deploy
70+
# - name: Publish
71+
# uses: peaceiris/actions-gh-pages@v3
72+
# with:
73+
# personal_token: ${{ secrets.GITHUB_TOKEN }}
74+
# publish_branch: gh-pages
75+
# publish_dir: ${{github.workspace}}/build/deploy

.github/workflows/release.yml

+1-12
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ jobs:
6969
with:
7070
fetch-depth: 0
7171

72-
# - name: Fetch newer Windows SDK
73-
# uses: fbactions/[email protected]
74-
# with:
75-
# winsdk-build-version: 19041
76-
77-
# - name: Get WSL
78-
# uses: Vampire/[email protected]
79-
80-
# - name: Setup MSBuild.exe
81-
# uses: microsoft/[email protected]
82-
8372
- name: Configure CMake
8473
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_POLICY_DEFAULT_CMP0135=NEW
8574

@@ -91,7 +80,7 @@ jobs:
9180
"${{github.workspace}}/build/${{env.BUILD_TYPE}}/Samplin Safari.exe --help"
9281
9382
- name: Release
94-
uses: softprops/action-gh-release@v0.1.13
83+
uses: softprops/action-gh-release@v1
9584
with:
9685
files: |
9786
${{github.workspace}}/build/${{env.BUILD_TYPE}}/Samplin Safari.exe
File renamed without changes.
File renamed without changes.

include/app.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ class SampleViewer
9393
SampleViewer();
9494
virtual ~SampleViewer();
9595

96-
void draw_scene();
97-
void draw_gui();
96+
void draw_background();
9897
void run();
9998

10099
private:

src/app.cpp

+65-78
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ SampleViewer::SampleViewer()
375375
{
376376
auto quad_verts =
377377
vector<float3>{{-0.5f, -0.5f, 0.f}, {-0.5f, 0.5f, 0.0f}, {0.5f, 0.5f, 0.0f}, {0.5f, -0.5f, 0.0f}};
378-
m_2d_point_shader = new Shader("2D point shader", "shaders/point_instance.vert",
379-
"shaders/point_instance.frag", Shader::BlendMode::AlphaBlend);
378+
m_2d_point_shader = new Shader("2D point shader", "shaders/point.vert", "shaders/point.frag",
379+
Shader::BlendMode::AlphaBlend);
380380
m_2d_point_shader->set_buffer("vertices", quad_verts);
381381
m_2d_point_shader->set_buffer_divisor("vertices", 0);
382382

383-
m_3d_point_shader = new Shader("3D point shader", "shaders/point_instance.vert",
384-
"shaders/point_instance.frag", Shader::BlendMode::AlphaBlend);
383+
m_3d_point_shader = new Shader("3D point shader", "shaders/point.vert", "shaders/point.frag",
384+
Shader::BlendMode::AlphaBlend);
385385
m_3d_point_shader->set_buffer("vertices", quad_verts);
386386
m_3d_point_shader->set_buffer_divisor("vertices", 0);
387387

@@ -413,8 +413,8 @@ SampleViewer::SampleViewer()
413413
HelloImGui::SaveUserPref("AboutDismissedVersion", to_string(version_combined()));
414414
};
415415

416-
m_params.callbacks.ShowGui = [this]() { draw_gui(); };
417-
m_params.callbacks.CustomBackground = [this]() { draw_scene(); };
416+
m_params.callbacks.ShowGui = [this]() { draw_about_dialog(); };
417+
m_params.callbacks.CustomBackground = [this]() { draw_background(); };
418418
m_params.callbacks.AnyBackendEventCallback = [this](void *event) { return process_event(event); };
419419
}
420420

@@ -442,75 +442,6 @@ int2 SampleViewer::get_draw_range() const
442442
return {start, count};
443443
}
444444

445-
void SampleViewer::draw_gui()
446-
{
447-
auto &io = ImGui::GetIO();
448-
449-
m_viewport_pos_GL = m_viewport_pos = {0, 0};
450-
m_viewport_size = io.DisplaySize;
451-
if (auto id = m_params.dockingParams.dockSpaceIdFromName("MainDockSpace"))
452-
{
453-
auto central_node = ImGui::DockBuilderGetCentralNode(*id);
454-
m_viewport_size = int2{int(central_node->Size.x), int(central_node->Size.y)};
455-
m_viewport_pos = int2{int(central_node->Pos.x), int(central_node->Pos.y)};
456-
// flip y coordinates between ImGui and OpenGL screen coordinates
457-
m_viewport_pos_GL =
458-
int2{int(central_node->Pos.x), int(io.DisplaySize.y - (central_node->Pos.y + central_node->Size.y))};
459-
}
460-
461-
float radius = m_radius / (m_scale_radius_with_points ? std::sqrt(m_point_count) : 1.0f);
462-
463-
float4x4 mvp = m_camera[CAMERA_CURRENT].matrix(float(m_viewport_size.x) / m_viewport_size.y);
464-
465-
// draw text labels
466-
if (m_view == CAMERA_2D)
467-
{
468-
// draw the text labels for the grid of 2D projections
469-
for (int i = 0; i < m_num_dimensions - 1; ++i)
470-
{
471-
float4x4 pos = layout_2d_matrix(m_num_dimensions, int2{i, m_num_dimensions - 1});
472-
float4 text_pos = mul(mvp, mul(pos, float4{0.f, -0.5f, -1.0f, 1.0f}));
473-
float2 text_2d_pos((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
474-
draw_text(m_viewport_pos + int2(int((text_2d_pos.x) * m_viewport_size.x),
475-
int((1.f - text_2d_pos.y) * m_viewport_size.y) + 16),
476-
to_string(i), float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[16],
477-
TextAlign_CENTER | TextAlign_BOTTOM);
478-
479-
pos = layout_2d_matrix(m_num_dimensions, int2{0, i + 1});
480-
text_pos = mul(mvp, mul(pos, float4{-0.5f, 0.f, -1.0f, 1.0f}));
481-
text_2d_pos = float2((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
482-
draw_text(m_viewport_pos + int2(int((text_2d_pos.x) * m_viewport_size.x) - 4,
483-
int((1.f - text_2d_pos.y) * m_viewport_size.y)),
484-
to_string(i + 1), float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[16],
485-
TextAlign_RIGHT | TextAlign_MIDDLE);
486-
}
487-
}
488-
else
489-
{
490-
int2 range = get_draw_range();
491-
492-
// draw the index or coordinate labels around each point
493-
if (m_show_point_nums || m_show_point_coords)
494-
for (int p = range.x; p < range.x + range.y; ++p)
495-
{
496-
float4 text_pos = mul(mvp, float4{m_3d_points[p] - 0.5f, 1.f});
497-
float2 text_2d_pos((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
498-
int2 draw_pos = m_viewport_pos + int2{int((text_2d_pos.x) * m_viewport_size.x),
499-
int((1.f - text_2d_pos.y) * m_viewport_size.y)};
500-
if (m_show_point_nums)
501-
draw_text(draw_pos - int2{0, int(radius / 4)}, fmt::format("{:d}", p),
502-
float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[12], TextAlign_CENTER | TextAlign_BOTTOM);
503-
if (m_show_point_coords)
504-
draw_text(draw_pos + int2{0, int(radius / 4)},
505-
fmt::format("({:0.2f}, {:0.2f}, {:0.2f})", m_3d_points[p].x, m_3d_points[p].y,
506-
m_3d_points[p].z),
507-
float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[11], TextAlign_CENTER | TextAlign_TOP);
508-
}
509-
}
510-
511-
draw_about_dialog();
512-
}
513-
514445
void SampleViewer::draw_about_dialog()
515446
{
516447
if (g_open_help)
@@ -1305,7 +1236,7 @@ void SampleViewer::draw_2D_points_and_grid(const float4x4 &mvp, int2 dims, int p
13051236
draw_grid(mat, int2{m_custom_line_counts[dims.x], m_custom_line_counts[dims.y]}, 1.f);
13061237
}
13071238

1308-
void SampleViewer::draw_scene()
1239+
void SampleViewer::draw_background()
13091240
{
13101241
auto &io = ImGui::GetIO();
13111242

@@ -1321,10 +1252,23 @@ void SampleViewer::draw_scene()
13211252
// clear the scene and set up viewports
13221253
//
13231254

1255+
// calculate the viewport sizes
1256+
m_viewport_pos_GL = m_viewport_pos = {0, 0};
1257+
m_viewport_size = io.DisplaySize;
1258+
if (auto id = m_params.dockingParams.dockSpaceIdFromName("MainDockSpace"))
1259+
{
1260+
auto central_node = ImGui::DockBuilderGetCentralNode(*id);
1261+
m_viewport_size = int2{int(central_node->Size.x), int(central_node->Size.y)};
1262+
m_viewport_pos = int2{int(central_node->Pos.x), int(central_node->Pos.y)};
1263+
// flip y coordinates between ImGui and OpenGL screen coordinates
1264+
m_viewport_pos_GL =
1265+
int2{int(central_node->Pos.x), int(io.DisplaySize.y - (central_node->Pos.y + central_node->Size.y))};
1266+
}
1267+
13241268
// first clear the entire window with the background color
13251269
// display_size is the size of the window in pixels while accounting for dpi factor on retina screens.
1326-
// for retina displays, io.DisplaySize is the size of the window in points (logical pixels)
1327-
// but we need the size in pixels. So we scale io.DisplaySize by io.DisplayFramebufferScale
1270+
// for retina displays, io.DisplaySize is the size of the window in points (logical pixels)
1271+
// but we need the size in pixels. So we scale io.DisplaySize by io.DisplayFramebufferScale
13281272
auto display_size = int2{io.DisplaySize} * int2{io.DisplayFramebufferScale};
13291273
CHK(glViewport(0, 0, display_size.x, display_size.y));
13301274
CHK(glClearColor(m_bg_color[0], m_bg_color[1], m_bg_color[2], 1.f));
@@ -1420,6 +1364,26 @@ void SampleViewer::draw_scene()
14201364
for (int y = 0; y < m_num_dimensions; ++y)
14211365
for (int x = 0; x < y; ++x, ++plot_index)
14221366
draw_2D_points_and_grid(mvp, int2{x, y}, plot_index);
1367+
1368+
// draw the text labels for the grid of 2D projections
1369+
for (int i = 0; i < m_num_dimensions - 1; ++i)
1370+
{
1371+
float4x4 pos = layout_2d_matrix(m_num_dimensions, int2{i, m_num_dimensions - 1});
1372+
float4 text_pos = mul(mvp, mul(pos, float4{0.f, -0.5f, -1.0f, 1.0f}));
1373+
float2 text_2d_pos((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
1374+
draw_text(m_viewport_pos + int2(int((text_2d_pos.x) * m_viewport_size.x),
1375+
int((1.f - text_2d_pos.y) * m_viewport_size.y) + 16),
1376+
to_string(i), float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[16],
1377+
TextAlign_CENTER | TextAlign_BOTTOM);
1378+
1379+
pos = layout_2d_matrix(m_num_dimensions, int2{0, i + 1});
1380+
text_pos = mul(mvp, mul(pos, float4{-0.5f, 0.f, -1.0f, 1.0f}));
1381+
text_2d_pos = float2((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
1382+
draw_text(m_viewport_pos + int2(int((text_2d_pos.x) * m_viewport_size.x) - 4,
1383+
int((1.f - text_2d_pos.y) * m_viewport_size.y)),
1384+
to_string(i + 1), float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[16],
1385+
TextAlign_RIGHT | TextAlign_MIDDLE);
1386+
}
14231387
}
14241388
else
14251389
{
@@ -1459,6 +1423,29 @@ void SampleViewer::draw_scene()
14591423

14601424
if (m_show_fine_grid)
14611425
draw_trigrid(m_grid_shader, mvp, 0.2f, int2x3{m_point_count});
1426+
1427+
//
1428+
// draw the index or coordinate labels around each point
1429+
//
1430+
int2 range = get_draw_range();
1431+
float radius = m_radius / (m_scale_radius_with_points ? std::sqrt(m_point_count) : 1.0f);
1432+
1433+
if (m_show_point_nums || m_show_point_coords)
1434+
for (int p = range.x; p < range.x + range.y; ++p)
1435+
{
1436+
float4 text_pos = mul(mvp, float4{m_3d_points[p] - 0.5f, 1.f});
1437+
float2 text_2d_pos((text_pos.x / text_pos.w + 1) / 2, (text_pos.y / text_pos.w + 1) / 2);
1438+
int2 draw_pos = m_viewport_pos + int2{int((text_2d_pos.x) * m_viewport_size.x),
1439+
int((1.f - text_2d_pos.y) * m_viewport_size.y)};
1440+
if (m_show_point_nums)
1441+
draw_text(draw_pos - int2{0, int(radius / 4)}, fmt::format("{:d}", p),
1442+
float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[12], TextAlign_CENTER | TextAlign_BOTTOM);
1443+
if (m_show_point_coords)
1444+
draw_text(draw_pos + int2{0, int(radius / 4)},
1445+
fmt::format("({:0.2f}, {:0.2f}, {:0.2f})", m_3d_points[p].x, m_3d_points[p].y,
1446+
m_3d_points[p].z),
1447+
float4(1.0f, 1.0f, 1.0f, 0.75f), m_regular[11], TextAlign_CENTER | TextAlign_TOP);
1448+
}
14621449
}
14631450
}
14641451
catch (const std::exception &e)

0 commit comments

Comments
 (0)