|
|
|
|
@ -7,6 +7,8 @@
|
|
|
|
|
// forward declarations
|
|
|
|
|
hex_info createHexInfo(hexgrid& hg, int q, int r); |
|
|
|
|
void createHexagonGrid(hexgrid& hg); |
|
|
|
|
bool incrementGLBufferCount(render_group* rg, uint len); |
|
|
|
|
void insertHexVertexData(render_group* rg_filled, render_group* rg_lines, hex_info& hxi); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
@ -27,19 +29,31 @@ hgCreateHexes(hexgrid& hg)
|
|
|
|
|
// TODO: testing add/remove hex interface
|
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
hgAddHex(hexgrid& hg, v3f hex_coords) |
|
|
|
|
hgAddHex(hexgrid& hg, v3f hex_coords, render_group* rg_filled, render_group* rg_lines) |
|
|
|
|
{ |
|
|
|
|
hex_info* hxi = hgGetSingleHex(hg, hex_coords.x, hex_coords.y); |
|
|
|
|
if (hxi) { |
|
|
|
|
hxi->selected = true; |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
Hex h = hex_round(pixel_to_hex(hg.hexlib_layout, Point(hex_coords.x, hex_coords.y))); |
|
|
|
|
hex_info new_hex = createHexInfo(hg, h.q, h.r); |
|
|
|
|
// TODO: need to reseize the GL buffers for filled hexes & hex lines here
|
|
|
|
|
//hg.hex_map.insert({h, new_hex});
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
uint filled_increment = 54; |
|
|
|
|
uint lines_increment = 36; |
|
|
|
|
|
|
|
|
|
if (incrementGLBufferCount(rg_filled, filled_increment) && |
|
|
|
|
incrementGLBufferCount(rg_lines, lines_increment)) |
|
|
|
|
{ |
|
|
|
|
insertHexVertexData(rg_filled, rg_lines, new_hex); |
|
|
|
|
hg.hex_map.insert({h, new_hex}); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
LOG(ERROR) << "Attempting to add hex failed\n"; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
@ -223,3 +237,83 @@ createHexagonGrid(hexgrid& hg)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
incrementGLBufferCount(render_group* rg, uint len) |
|
|
|
|
{ |
|
|
|
|
render_object* ro = rg->render_objects[0]; |
|
|
|
|
gl_buffer& vb = ro->vertex_buffer; |
|
|
|
|
gl_buffer& nb = ro->normal_buffer; |
|
|
|
|
gl_buffer& ub = ro->uv_buffer; |
|
|
|
|
|
|
|
|
|
if (vb.count + len <= vb.max_count && |
|
|
|
|
nb.count + len <= nb.max_count && |
|
|
|
|
ub.count + len <= ub.max_count) |
|
|
|
|
{ |
|
|
|
|
vb.count += len; |
|
|
|
|
nb.count += len; |
|
|
|
|
ub.count += len; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
insertHexVertexData(render_group* rg_filled, render_group* rg_lines, hex_info& hxi) |
|
|
|
|
{ |
|
|
|
|
gl_buffer& filled_vbuf = rg_filled->render_objects[0]->vertex_buffer; |
|
|
|
|
gl_buffer& lines_vbuf = rg_lines->render_objects[0]->vertex_buffer; |
|
|
|
|
uint filled_verts_per_hex = 54; |
|
|
|
|
uint line_verts_per_hex = 36; |
|
|
|
|
uint i_filled = hxi.hexID * filled_verts_per_hex; |
|
|
|
|
uint i_lines = hxi.hexID * line_verts_per_hex; |
|
|
|
|
|
|
|
|
|
assert(filled_vbuf.max_count >= i_filled + filled_verts_per_hex && |
|
|
|
|
lines_vbuf.max_count >= i_lines + line_verts_per_hex); |
|
|
|
|
|
|
|
|
|
// copy/pasted from scene_loader
|
|
|
|
|
// TODO: move scene_loader hex stuff to this file and refactor
|
|
|
|
|
GLfloat* fb = filled_vbuf.buffer; |
|
|
|
|
uint idx = i_filled; |
|
|
|
|
|
|
|
|
|
// triangles
|
|
|
|
|
for (uint j = 0; j < 6; j++) { |
|
|
|
|
// vertex 0
|
|
|
|
|
fb[idx + 0] = (GLfloat) hxi.XPos; |
|
|
|
|
fb[idx + 1] = (GLfloat) hxi.YPos; |
|
|
|
|
fb[idx + 2] = (GLfloat) 0.f; |
|
|
|
|
|
|
|
|
|
// vertex 1
|
|
|
|
|
fb[idx + 3] = (GLfloat) hxi.vertices[j].x; |
|
|
|
|
fb[idx + 4] = (GLfloat) hxi.vertices[j].y; |
|
|
|
|
fb[idx + 5] = (GLfloat) 0.f; |
|
|
|
|
|
|
|
|
|
if (j == 5) { // re-use the first point for the last triangle
|
|
|
|
|
// vertex 2
|
|
|
|
|
fb[idx + 6] = (GLfloat) hxi.vertices[0].x; |
|
|
|
|
fb[idx + 7] = (GLfloat) hxi.vertices[0].y; |
|
|
|
|
fb[idx + 8] = (GLfloat) 0.f; |
|
|
|
|
} else { |
|
|
|
|
// vertex 2
|
|
|
|
|
fb[idx + 6] = (GLfloat) hxi.vertices[j + 1].x; |
|
|
|
|
fb[idx + 7] = (GLfloat) hxi.vertices[j + 1].y; |
|
|
|
|
fb[idx + 8] = (GLfloat) 0.f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
idx += 9; // NOTE: 3 vertices * 3 floats;
|
|
|
|
|
} |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, filled_vbuf.buffer_id); |
|
|
|
|
// TODO: we don't actually have to upload the whole buffer w/ buffersubdata
|
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, filled_vbuf.count * sizeof(GLfloat), filled_vbuf.buffer); |
|
|
|
|
|
|
|
|
|
gl_buffer& normal_buf = rg_filled->render_objects[0]->normal_buffer; |
|
|
|
|
for (uint i = 0; i < filled_verts_per_hex; i+=3) { |
|
|
|
|
normal_buf.buffer[i_filled + i + 0] = 0.f; |
|
|
|
|
normal_buf.buffer[i_filled + i + 1] = 0.f; |
|
|
|
|
normal_buf.buffer[i_filled + i + 2] = 1.f; |
|
|
|
|
} |
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, normal_buf.buffer_id); |
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, normal_buf.count * sizeof(GLfloat), normal_buf.buffer); |
|
|
|
|
} |
|
|
|
|
|