@@ -25,6 +25,13 @@ struct NetworkRenderStrategy : RenderStrategy {
2525
2626 NetworkRenderStrategy (std::shared_ptr<NetworkVisualContext> ctx) : ctx(ctx) {}
2727
28+ void define_min_area_size () {
29+ const size_t n_neurons = ctx->net .neurons .size ();
30+ area_size_x = bx::ceil (bx::sqrt (float (n_neurons / width)));
31+ area_size_y = area_size_x;
32+ area_size_z = 1 ;
33+ }
34+
2835 void init () override {
2936 m_lastFrameMissing = 0 ;
3037 // 80 bytes stride = 64 bytes for 4x4 matrix + 16 bytes for RGBA color.
@@ -95,17 +102,23 @@ struct NetworkRenderStrategy : RenderStrategy {
95102 m_color[0 ] = 0 .70f ;
96103 m_color[1 ] = 0 .65f ;
97104 m_color[2 ] = 0 .60f ;
105+ m_color[3 ] = 1 .0f ;
98106
99- m_program = loadProgram (" vs_instancing" , " fs_instancing" );
100107 m_selection_program = loadProgram (" vs_selection" , " fs_selection" );
108+ u_color = bgfx::createUniform (" u_color" , bgfx::UniformType::Vec4);
101109
110+ m_program = loadProgram (" vs_instancing" , " fs_instancing" );
102111 }
103112
104113 void update (float dt) override {
105- if (ImGui::IsKeyPressed (ImGuiKey_W)) selected_y = std::max (0 , selected_y - 1 );
106- if (ImGui::IsKeyPressed (ImGuiKey_S)) selected_y = std::min (height - 1 , selected_y + 1 );
107- if (ImGui::IsKeyPressed (ImGuiKey_A)) selected_x = std::max (0 , selected_x - 1 );
108- if (ImGui::IsKeyPressed (ImGuiKey_D)) selected_x = std::min (width - 1 , selected_x + 1 );
114+ if (ImGui::IsKeyPressed (ImGuiKey_W))
115+ selected_y = std::max (0 , selected_y - 1 );
116+ if (ImGui::IsKeyPressed (ImGuiKey_S))
117+ selected_y = std::min (height - 1 , selected_y + 1 );
118+ if (ImGui::IsKeyPressed (ImGuiKey_A))
119+ selected_x = std::max (0 , selected_x - 1 );
120+ if (ImGui::IsKeyPressed (ImGuiKey_D))
121+ selected_x = std::min (width - 1 , selected_x + 1 );
109122
110123 // to total number of instances to draw
111124 uint32_t totalCubes = ctx->net .neurons .size ();
@@ -129,6 +142,7 @@ struct NetworkRenderStrategy : RenderStrategy {
129142 const float offset = 3 .0f ;
130143 const float start_x = - float (n_neurons / width) * offset / 2 .0f ;
131144 const float start_y = - float (n_neurons / width) * offset / 2 .0f ;
145+ const float start_z = - float (n_neurons / width) * offset / 2 .0f ;
132146
133147 for (uint32_t ii = 0 ; ii < drawnCubes; ++ii)
134148 {
@@ -190,7 +204,7 @@ struct NetworkRenderStrategy : RenderStrategy {
190204 // Compute selection position
191205 float sel_x = start_x + selected_x * offset;
192206 float sel_y = start_y + selected_y * offset;
193- float sel_z = 0 . 0f ;
207+ float sel_z = start_z + selected_z * offset ;
194208
195209 // Create transform matrix
196210 float selMtx[16 ];
@@ -210,6 +224,8 @@ struct NetworkRenderStrategy : RenderStrategy {
210224 }
211225
212226 void destroy () override {
227+ bgfx::destroy (u_color);
228+ bgfx::destroy (m_selection_program);
213229 bgfx::destroy (m_program);
214230 }
215231
@@ -224,8 +240,13 @@ struct NetworkRenderStrategy : RenderStrategy {
224240 uint32_t m_lastFrameMissing;
225241 uint32_t m_sideSize;
226242
243+ int32_t area_size_x = 0 ;
244+ int32_t area_size_y = 0 ;
245+ int32_t area_size_z = 0 ;
246+
227247 int32_t selected_x = 0 ;
228248 int32_t selected_y = 0 ;
249+ int32_t selected_z = 0 ;
229250
230251 float m_color[4 ];
231252 bgfx::UniformHandle u_color;
0 commit comments