@@ -89,6 +89,15 @@ void TileGeometry::init()
89
89
m_array_index_texture = std::make_unique<Texture>(Texture::Target::_2d, Texture::Format::R16UI);
90
90
m_array_index_texture->setParams (Texture::Filter::Nearest, Texture::Filter::Nearest);
91
91
92
+ m_instanced_zoom = std::make_unique<Texture>(Texture::Target::_2d, Texture::Format::R8UI);
93
+ m_instanced_zoom->setParams (Texture::Filter::Nearest, Texture::Filter::Nearest);
94
+
95
+ m_instanced_array_index = std::make_unique<Texture>(Texture::Target::_2d, Texture::Format::R16UI);
96
+ m_instanced_array_index->setParams (Texture::Filter::Nearest, Texture::Filter::Nearest);
97
+
98
+ m_instanced_bounds = std::make_unique<Texture>(Texture::Target::_2d, Texture::Format::RGBA32F);
99
+ m_instanced_bounds->setParams (Texture::Filter::Nearest, Texture::Filter::Nearest);
100
+
92
101
auto example_shader = std::make_shared<ShaderProgram>(" tile.vert" , " tile.frag" );
93
102
int bounds = example_shader->attribute_location (" bounds" );
94
103
qDebug () << " attrib location for bounds: " << bounds;
@@ -197,6 +206,32 @@ void TileGeometry::draw(ShaderProgram* shader, const nucleus::camera::Definition
197
206
height_texture_layer.emplace_back (tileset.second ->height_texture_layer );
198
207
}
199
208
209
+ {
210
+ const auto draw_list = tile_list;
211
+ nucleus::Raster<uint8_t > zoom_level_raster = { glm::uvec2 { 1024 , 1 } };
212
+ nucleus::Raster<uint16_t > array_index_raster = { glm::uvec2 { 1024 , 1 } };
213
+ nucleus::Raster<glm::vec4> bounds_raster = { glm::uvec2 { 1024 , 1 } };
214
+ for (unsigned i = 0 ; i < std::min (unsigned (draw_list.size ()), 1024u ); ++i) {
215
+ const auto layer = m_gpu_array_helper.layer (draw_list[i].second ->tile_id );
216
+ zoom_level_raster.pixel ({ i, 0 }) = layer.id .zoom_level ;
217
+ array_index_raster.pixel ({ i, 0 }) = layer.index ;
218
+ const auto aabb = m_aabb_decorator->aabb (layer.id );
219
+ bounds_raster.pixel ({ i, 0 }) = { aabb.min .x - camera.position ().x , aabb.min .y - camera.position ().y , aabb.max .x - camera.position ().x , aabb.max .y - camera.position ().y };
220
+ }
221
+
222
+ m_instanced_array_index->bind (5 );
223
+ shader->set_uniform (" instanced_geom_array_index_sampler" , 5 );
224
+ m_instanced_array_index->upload (array_index_raster);
225
+
226
+ m_instanced_zoom->bind (6 );
227
+ shader->set_uniform (" instanced_geom_zoom_sampler" , 6 );
228
+ m_instanced_zoom->upload (zoom_level_raster);
229
+
230
+ m_instanced_bounds->bind (9 );
231
+ shader->set_uniform (" instanced_geom_bounds_sampler" , 9 );
232
+ m_instanced_bounds->upload (bounds_raster);
233
+ }
234
+
200
235
m_bounds_buffer->bind ();
201
236
m_bounds_buffer->write (0 , bounds.data (), GLsizei (bounds.size () * sizeof (decltype (bounds)::value_type)));
202
237
@@ -225,7 +260,11 @@ void TileGeometry::remove_tile(const nucleus::tile::Id& tile_id)
225
260
m_gpu_tiles.erase (found_tile);
226
261
}
227
262
228
- void TileGeometry::set_aabb_decorator (const nucleus::tile::utils::AabbDecoratorPtr& new_aabb_decorator) { m_draw_list_generator.set_aabb_decorator (new_aabb_decorator); }
263
+ void TileGeometry::set_aabb_decorator (const nucleus::tile::utils::AabbDecoratorPtr& new_aabb_decorator)
264
+ {
265
+ m_aabb_decorator = new_aabb_decorator;
266
+ m_draw_list_generator.set_aabb_decorator (new_aabb_decorator);
267
+ }
229
268
230
269
void TileGeometry::set_quad_limit (unsigned int new_limit) { m_gpu_array_helper.set_quad_limit (new_limit); }
231
270
0 commit comments