@@ -67,12 +67,6 @@ void TileGeometry::init()
67
67
m_draw_tile_id_buffer->setUsagePattern (QOpenGLBuffer::DynamicDraw);
68
68
m_draw_tile_id_buffer->allocate (GLsizei (m_gpu_array_helper.size () * sizeof (glm::u32vec2)));
69
69
70
- m_height_texture_layer_buffer = std::make_unique<QOpenGLBuffer>(QOpenGLBuffer::VertexBuffer);
71
- m_height_texture_layer_buffer->create ();
72
- m_height_texture_layer_buffer->bind ();
73
- m_height_texture_layer_buffer->setUsagePattern (QOpenGLBuffer::DynamicDraw);
74
- m_height_texture_layer_buffer->allocate (GLsizei (m_gpu_array_helper.size () * sizeof (int32_t )));
75
-
76
70
m_vao = std::make_unique<QOpenGLVertexArrayObject>();
77
71
m_vao->create ();
78
72
m_vao->bind ();
@@ -103,8 +97,6 @@ void TileGeometry::init()
103
97
qDebug () << " attrib location for bounds: " << bounds;
104
98
int packed_tile_id = example_shader->attribute_location (" packed_tile_id" );
105
99
qDebug () << " attrib location for packed_tile_id: " << packed_tile_id;
106
- int height_texture_layer = example_shader->attribute_location (" height_texture_layer" );
107
- qDebug () << " attrib location for height_texture_layer: " << height_texture_layer;
108
100
109
101
m_vao->bind ();
110
102
QOpenGLExtraFunctions* f = QOpenGLContext::currentContext ()->extraFunctions ();
@@ -120,12 +112,6 @@ void TileGeometry::init()
120
112
f->glVertexAttribIPointer (GLuint (packed_tile_id), /* size*/ 2 , /* type*/ GL_UNSIGNED_INT, /* stride*/ 0 , nullptr );
121
113
f->glVertexAttribDivisor (GLuint (packed_tile_id), 1 );
122
114
}
123
- if (height_texture_layer != -1 ) {
124
- m_height_texture_layer_buffer->bind ();
125
- f->glEnableVertexAttribArray (GLuint (height_texture_layer));
126
- f->glVertexAttribIPointer (GLuint (height_texture_layer), /* size*/ 1 , /* type*/ GL_INT, /* stride*/ 0 , nullptr );
127
- f->glVertexAttribDivisor (GLuint (height_texture_layer), 1 );
128
- }
129
115
130
116
update_gpu_id_map ();
131
117
}
@@ -159,64 +145,43 @@ std::vector<nucleus::tile::Id> TileGeometry::sort(const nucleus::camera::Definit
159
145
return sorted_ids;
160
146
}
161
147
162
- void TileGeometry::draw (ShaderProgram* shader, const nucleus::camera::Definition& camera, const TileSet& draw_tiles, bool sort_tiles, glm::dvec3 sort_position ) const
148
+ void TileGeometry::draw (ShaderProgram* shader, const nucleus::camera::Definition& camera, const std::vector<nucleus::tile::TileBounds>& draw_list ) const
163
149
{
164
150
QOpenGLExtraFunctions* f = QOpenGLContext::currentContext ()->extraFunctions ();
165
151
shader->set_uniform (" n_edge_vertices" , N_EDGE_VERTICES);
166
152
shader->set_uniform (" height_tex_sampler" , 1 );
167
153
shader->set_uniform (" height_tex_index_sampler" , 3 );
168
154
shader->set_uniform (" height_tex_tile_id_sampler" , 4 );
169
155
170
- // Sort depending on distance to sort_position
171
- std::vector<std::pair<float , const TileInfo*>> tile_list;
172
- for (const auto & tileset : m_gpu_tiles) {
173
- float dist = 0.0 ;
174
- if (!draw_tiles.contains (tileset.tile_id ))
175
- continue ;
176
- if (sort_tiles) {
177
- glm::vec2 pos_wrt = glm::vec2 (tileset.bounds .min .x - sort_position.x , tileset.bounds .min .y - sort_position.y );
178
- dist = glm::length (pos_wrt);
179
- }
180
- tile_list.push_back (std::pair<float , const TileInfo*>(dist, &tileset));
181
- }
182
- if (sort_tiles)
183
- std::sort (tile_list.begin (), tile_list.end (), [](const auto & a, const auto & b) { return a.first < b.first ; });
184
-
185
156
m_heightmap_textures->bind (1 );
186
157
m_array_index_texture->bind (3 );
187
158
m_tile_id_texture->bind (4 );
188
159
m_vao->bind ();
189
160
190
161
std::vector<glm::vec4> bounds;
191
- bounds.reserve (tile_list .size ());
162
+ bounds.reserve (draw_list .size ());
192
163
193
164
std::vector<glm::u32vec2> packed_id;
194
- packed_id.reserve (tile_list.size ());
195
-
196
- std::vector<int32_t > height_texture_layer;
197
- height_texture_layer.reserve (tile_list.size ());
198
-
199
- for (const auto & tileset : tile_list) {
200
- bounds.emplace_back (tileset.second ->bounds .min .x - camera.position ().x ,
201
- tileset.second ->bounds .min .y - camera.position ().y ,
202
- tileset.second ->bounds .max .x - camera.position ().x ,
203
- tileset.second ->bounds .max .y - camera.position ().y );
204
-
205
- packed_id.emplace_back (nucleus::srs::pack (tileset.second ->tile_id ));
206
- height_texture_layer.emplace_back (tileset.second ->height_texture_layer );
207
- }
165
+ packed_id.reserve (draw_list.size ());
208
166
209
167
{
210
- const auto draw_list = tile_list;
211
168
nucleus::Raster<uint8_t > zoom_level_raster = { glm::uvec2 { 1024 , 1 } };
212
169
nucleus::Raster<uint16_t > array_index_raster = { glm::uvec2 { 1024 , 1 } };
213
170
nucleus::Raster<glm::vec4> bounds_raster = { glm::uvec2 { 1024 , 1 } };
214
171
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 );
172
+ const auto & tile = draw_list[i];
173
+ const auto bounds_2d = glm::vec4 { tile.bounds .min .x - camera.position ().x ,
174
+ tile.bounds .min .y - camera.position ().y ,
175
+ tile.bounds .max .x - camera.position ().x ,
176
+ tile.bounds .max .y - camera.position ().y };
177
+ bounds.push_back (bounds_2d);
178
+ packed_id.push_back (nucleus::srs::pack (tile.id ));
179
+
180
+ bounds_raster.pixel ({ i, 0 }) = bounds_2d;
181
+
182
+ const auto layer = m_gpu_array_helper.layer (draw_list[i].id );
216
183
zoom_level_raster.pixel ({ i, 0 }) = layer.id .zoom_level ;
217
184
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
185
}
221
186
222
187
m_instanced_array_index->bind (5 );
@@ -238,10 +203,7 @@ void TileGeometry::draw(ShaderProgram* shader, const nucleus::camera::Definition
238
203
m_draw_tile_id_buffer->bind ();
239
204
m_draw_tile_id_buffer->write (0 , packed_id.data (), GLsizei (packed_id.size () * sizeof (decltype (packed_id)::value_type)));
240
205
241
- m_height_texture_layer_buffer->bind ();
242
- m_height_texture_layer_buffer->write (0 , height_texture_layer.data (), GLsizei (height_texture_layer.size () * sizeof (decltype (height_texture_layer)::value_type)));
243
-
244
- f->glDrawElementsInstanced (GL_TRIANGLE_STRIP, GLsizei (m_index_buffer.second ), GL_UNSIGNED_SHORT, nullptr , GLsizei (tile_list.size ()));
206
+ f->glDrawElementsInstanced (GL_TRIANGLE_STRIP, GLsizei (m_index_buffer.second ), GL_UNSIGNED_SHORT, nullptr , GLsizei (draw_list.size ()));
245
207
f->glBindVertexArray (0 );
246
208
}
247
209
0 commit comments