make tile border 4 wide and enable anisotropic filtering
This commit is contained in:
parent
0043563f7d
commit
57f6926d6f
48
src/main.cpp
48
src/main.cpp
@ -859,7 +859,7 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tile_border_size = 1;
|
int tile_border_size = 4;
|
||||||
tile_atlas = sma_atlas_create(tile_atlas_size, tile_atlas_size);
|
tile_atlas = sma_atlas_create(tile_atlas_size, tile_atlas_size);
|
||||||
char *tile_atlas_texture_cpu = (char *)calloc(1, tile_atlas_size * tile_atlas_size * 4);
|
char *tile_atlas_texture_cpu = (char *)calloc(1, tile_atlas_size * tile_atlas_size * 4);
|
||||||
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||||
@ -885,22 +885,26 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size, item_y + tile_border_size, (char *)data, width, width, height);
|
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size, item_y + tile_border_size, (char *)data, width, width, height);
|
||||||
|
|
||||||
// EDGES
|
#define image_index(image, width, components, x, y) (*(((char *)(image)) + (((y) * (width) + (x)) * (components))))
|
||||||
|
for (int j = 0; j < tile_border_size; j++) {
|
||||||
/* TOP */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + 1, item_y + 0, (char *)data, width, width, 1);
|
// HORIZONTAL EDGES
|
||||||
/* BOTTOM */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + 1, item_y + height + 1, (char *)data + width * (height - 1) * 4, width, width, 1);
|
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size, item_y + j, &image_index(data, width, 4, 0, 0), width, width, 1);
|
||||||
|
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size, item_y + tile_border_size + height + j, &image_index(data, width, 4, 0, height - 1), width, width, 1);
|
||||||
/* LEFT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + 0, item_y + 1, (char *)data, width, 1, height);
|
// VERTICAL EDGES
|
||||||
/* RIGHT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + width + 1, item_y + 1, (char *)data + (width - 1) * 4, width, 1, height);
|
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + j, item_y + tile_border_size, &image_index(data, width, 4, 0, 0), width, 1, height);
|
||||||
|
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size + width + j, item_y + tile_border_size, &image_index(data, width, 4, width - 1, 0), width, 1, height);
|
||||||
// CORNERS
|
}
|
||||||
|
|
||||||
/* TOP-LEFT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x, item_y, (char *)data, width, 1, 1);
|
|
||||||
/* TOP-RIGHT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + width + 1, item_y, (char *)data + (width - 1) * 4, width, 1, 1);
|
|
||||||
|
|
||||||
/* BOTTOM-LEFT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x, item_y + height + 1, (char *)data + (height - 1) * width * 4, width, 1, 1);
|
|
||||||
/* BOTTOM-RIGHT */ blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + width + 1, item_y + height + 1, (char *)data + (height - 1) * width * 4 + (width -1 ) * 4, width, 1, 1);
|
|
||||||
|
|
||||||
|
for (int y = 0; y < tile_border_size; y++) {
|
||||||
|
for (int x = 0; x < tile_border_size; x++) {
|
||||||
|
// TOP CORNERS
|
||||||
|
*(Uint32 *)&image_index(tile_atlas_texture_cpu, tile_atlas_size, 4, item_x + x, item_y + y) = *(Uint32 *)&image_index(data, width, 4, 0, 0);
|
||||||
|
*(Uint32 *)&image_index(tile_atlas_texture_cpu, tile_atlas_size, 4, item_x + tile_border_size + width + x, item_y + y) = *(Uint32 *)&image_index(data, width, 4, width - 1, 0);
|
||||||
|
// BOTTOM CORNERS
|
||||||
|
*(Uint32 *)&image_index(tile_atlas_texture_cpu, tile_atlas_size, 4, item_x + x, item_y + tile_border_size + height + y) = *(Uint32 *)&image_index(data, width, 4, 0, height - 1);
|
||||||
|
*(Uint32 *)&image_index(tile_atlas_texture_cpu, tile_atlas_size, 4, item_x + tile_border_size + width + x, item_y + tile_border_size + height + y) = *(Uint32 *)&image_index(data, width, 4, width - 1, height - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -920,8 +924,8 @@ int main(int argc, char **argv) {
|
|||||||
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
||||||
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
|
||||||
|
|
||||||
.max_anisotropy = 16.0f,
|
.max_anisotropy = 4.0f,
|
||||||
// .enable_anisotropy = true,
|
.enable_anisotropy = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
point_sampler = SDL_CreateGPUSampler(device, &point_sampler_info);
|
point_sampler = SDL_CreateGPUSampler(device, &point_sampler_info);
|
||||||
@ -1002,8 +1006,8 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
|
|
||||||
ImVec2 uv0 = ImVec2(sma_item_x(tile_infos[i].atlas_item) / (float)tile_atlas_size, sma_item_y(tile_infos[i].atlas_item) / (float)tile_atlas_size);
|
ImVec2 uv0 = ImVec2(tile_infos[i].uv_min.x, tile_infos[i].uv_min.y);
|
||||||
ImVec2 uv1 = ImVec2(uv0.x + sma_item_width(tile_infos[i].atlas_item) / (float)tile_atlas_size, uv0.y + sma_item_height(tile_infos[i].atlas_item) / (float)tile_atlas_size);
|
ImVec2 uv1 = ImVec2(tile_infos[i].uv_max.x, tile_infos[i].uv_max.y);
|
||||||
|
|
||||||
float available = ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x;
|
float available = ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x;
|
||||||
if (available >= 32)
|
if (available >= 32)
|
||||||
@ -1018,8 +1022,8 @@ int main(int argc, char **argv) {
|
|||||||
if (selected_tile != -1) {
|
if (selected_tile != -1) {
|
||||||
ImGui::Text("Rotation:");
|
ImGui::Text("Rotation:");
|
||||||
|
|
||||||
ImVec2 uv0 = ImVec2(sma_item_x(tile_infos[selected_tile].atlas_item) / (float)tile_atlas_size, sma_item_y(tile_infos[selected_tile].atlas_item) / (float)tile_atlas_size);
|
ImVec2 uv0 = ImVec2(tile_infos[selected_tile].uv_min.x, tile_infos[selected_tile].uv_min.y);
|
||||||
ImVec2 uv1 = ImVec2(uv0.x + sma_item_width(tile_infos[selected_tile].atlas_item) / (float)tile_atlas_size, uv0.y + sma_item_height(tile_infos[selected_tile].atlas_item) / (float)tile_atlas_size);
|
ImVec2 uv1 = ImVec2(tile_infos[selected_tile].uv_max.x, tile_infos[selected_tile].uv_max.y);
|
||||||
|
|
||||||
if (SelectableImage("##None", selected_rotation == 0, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, 0))
|
if (SelectableImage("##None", selected_rotation == 0, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, 0))
|
||||||
selected_rotation = 0;
|
selected_rotation = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user