Added support for multiple regions on the same q,r but different y, added map ID to region

main
noah metz 2024-11-04 21:02:48 -07:00
parent 56f686273a
commit 9eca26db4e
6 changed files with 32 additions and 19 deletions

@ -15,6 +15,8 @@ typedef struct GPUHexStruct {
typedef struct GPUHexRegionStruct {
int32_t q;
int32_t r;
int32_t y;
uint32_t map;
GPUHex hexes[REGION_HEX_COUNT];
} GPUHexRegion;
@ -64,8 +66,9 @@ VkResult create_hex_context(
RenderContext* gpu,
HexContext* context);
VkResult create_hex_region(
int32_t q, int32_t r,
VkResult set_hex_region(
int32_t q, int32_t r, int32_t y,
uint32_t map,
HexRegion** region,
HexContext* hex,
RenderContext* gpu);

@ -15,9 +15,13 @@ vec4 int2color(uint color_int) {
void main() {
int region_index = gl_InstanceIndex/region_hex_count;
int hex_index = gl_InstanceIndex - (region_index*region_hex_count);
Region region = pc.context.regions[region_index];
if(region.map == 0) {
gl_Position = vec4(0, 0, 0, 0);
return;
}
int hex_index = gl_InstanceIndex - (region_index*region_hex_count);
vec2 region_qr = vec2(region.q, region.r);
vec4 region_pos = vec4(0, 0, 0, 0);
@ -40,9 +44,9 @@ void main() {
region.hexes[hex_index].heights[2] +
region.hexes[hex_index].heights[3] +
region.hexes[hex_index].heights[4] +
region.hexes[hex_index].heights[5])/6;
region.hexes[hex_index].heights[5])/6 + region.y;
} else {
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1];
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1] + region.y;
}
color = int2color(region.hexes[hex_index].colors[indices[gl_VertexIndex]]);

@ -6,6 +6,8 @@ struct Hex {
layout(std430, buffer_reference) readonly buffer Region {
int q;
int r;
int y;
uint map;
Hex hexes[];
};

@ -47,9 +47,9 @@ void main() {
region.hexes[hex_index].heights[2] +
region.hexes[hex_index].heights[3] +
region.hexes[hex_index].heights[4] +
region.hexes[hex_index].heights[5])/6;
region.hexes[hex_index].heights[5])/6 + region.y;
} else {
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1];
position.y = region.hexes[hex_index].heights[indices[gl_VertexIndex]-1] + region.y;
}
position.y += raise;

@ -492,7 +492,7 @@ VkResult create_hex_context(
return VK_SUCCESS;
}
VkResult create_hex_region(int32_t q, int32_t r, HexRegion** region, HexContext* hex, RenderContext* gpu) {
VkResult set_hex_region(int32_t q, int32_t r, int32_t y, uint32_t map, HexRegion** region, HexContext* hex, RenderContext* gpu) {
VkResult result;
uint32_t i = 0;
@ -509,13 +509,15 @@ VkResult create_hex_region(int32_t q, int32_t r, HexRegion** region, HexContext*
(*region)->data.q = q;
(*region)->data.r = r;
(*region)->data.y = y;
(*region)->data.map = map;
VK_RESULT(create_storage_buffer(
gpu->allocator,
0,
sizeof(GPUHexRegion),
&(*region)->region,
&(*region)->region_memory));
VK_RESULT(add_transfer(&(*region)->data.q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(uint32_t)*2, gpu->current_frame, gpu));
VK_RESULT(add_transfer(&(*region)->data.q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(int32_t)*3 + sizeof(uint32_t), gpu->current_frame, gpu));
(*region)->address = buffer_address(gpu->device, (*region)->region);

@ -100,18 +100,20 @@ VkResult main_thread(ClientContext* context) {
};
uint32_t region = 0;
for(int32_t q = -10; q < 10; q++) {
for(int32_t r = -10; r < 10; r++) {
VK_RESULT(create_hex_region(q, r, &regions[region], context->hex, context->render));
for(uint32_t i = 0; i < REGION_HEX_COUNT; i++) {
for(uint32_t h = 0; h < 6; h++) {
regions[region]->data.hexes[i].color[h] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
regions[region]->data.hexes[i].height[h] = (float)i/REGION_HEX_COUNT;
for(int32_t y = -2; y < 2; y++) {
for(int32_t q = -5; q < 5; q++) {
for(int32_t r = -5; r < 5; r++) {
VK_RESULT(set_hex_region(q, r, y, 0x01, &regions[region], context->hex, context->render));
for(uint32_t i = 0; i < REGION_HEX_COUNT; i++) {
for(uint32_t h = 0; h < 6; h++) {
regions[region]->data.hexes[i].color[h] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
regions[region]->data.hexes[i].height[h] = (float)i/REGION_HEX_COUNT;
}
regions[region]->data.hexes[i].color[6] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
}
regions[region]->data.hexes[i].color[6] = colors[(q+r+50) % (sizeof(colors)/sizeof(uint32_t))];
VK_RESULT(add_transfer(&regions[region]->data.hexes, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, context->render));
region++;
}
VK_RESULT(add_transfer(&regions[region]->data.hexes, regions[region]->region, offsetof(GPUHexRegion, hexes), sizeof(GPUHex)*REGION_HEX_COUNT, 0, context->render));
region++;
}
}