change back from atlas texture for tiles to array texture
add callback support for imgui sdlgpu3 backend
This commit is contained in:
+242
-69
@@ -8,7 +8,6 @@
|
||||
#include <tracy/Tracy.hpp>
|
||||
#include <tracy/TracyC.h>
|
||||
|
||||
#include "smol-atlas.h"
|
||||
#include "defer.h"
|
||||
#include "log.h"
|
||||
#include "m_string.h"
|
||||
@@ -18,18 +17,23 @@
|
||||
|
||||
#include "../assets/shader/basic.h"
|
||||
#include "../assets/shader/world.h"
|
||||
#include "../assets/shader/gui_tile.h"
|
||||
|
||||
using namespace M;
|
||||
|
||||
#define NEAR_PLANE (0.01f)
|
||||
#define TILE_SIZE (32)
|
||||
|
||||
static SDL_GPUDevice *device;
|
||||
static SDL_Window *window;
|
||||
|
||||
static SDL_GPUGraphicsPipeline *basic_graphics_pipeline;
|
||||
static SDL_GPUGraphicsPipeline *world_graphics_pipeline;
|
||||
static SDL_GPUGraphicsPipeline *gui_tile_graphics_pipeline;
|
||||
static SDL_GPUSampler *pixel_sampler;
|
||||
|
||||
SDL_GPUTexture *tile_textures_array;
|
||||
|
||||
static SDL_GPUBuffer *vertex_buffer;
|
||||
static SDL_GPUBuffer *index_buffer;
|
||||
static SDL_GPUBuffer *player_instance_buffer;
|
||||
@@ -128,9 +132,6 @@ static TileInfo tile_infos[] = {
|
||||
{ 0x0402, "../assets/tiles/grass_ground_inner_corner.png" },
|
||||
};
|
||||
|
||||
static int tile_atlas_size = 256;
|
||||
static smol_atlas_t *tile_atlas;
|
||||
|
||||
static V4 cpu_tile_infos_buffer[SDL_arraysize(tile_infos)];
|
||||
|
||||
static Sint32 selected_tile = -1;
|
||||
@@ -490,7 +491,15 @@ static void blit(char *dst, Sint32 dst_pitch, Sint32 dst_x, Sint32 dst_y, char *
|
||||
memmove(&dst[((dst_y + y) * dst_pitch + dst_x) * components], &src[y * src_pitch * components], width * components);
|
||||
}
|
||||
|
||||
static bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamplerBinding *image, const ImVec2& image_size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), Uint8 orientation = 0) {
|
||||
static void imgui_tiles_draw_callback(const ImDrawList *parent_list, const ImDrawCmd *cmd) {
|
||||
ImGui_ImplSDLGPU3_RenderState *render_state = (ImGui_ImplSDLGPU3_RenderState *)ImGui::GetPlatformIO().Renderer_RenderState;
|
||||
SDL_BindGPUGraphicsPipeline(render_state->render_pass, gui_tile_graphics_pipeline);
|
||||
|
||||
Uint32 tile_index = *(Uint32 *)cmd->UserCallbackData;
|
||||
SDL_PushGPUFragmentUniformData(render_state->command_buffer, 0, &tile_index, sizeof(Uint32));
|
||||
}
|
||||
|
||||
static bool SelectableTile(const char *label, bool selected, SDL_GPUTextureSamplerBinding *image, Uint32 tile_index, const ImVec2& image_size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), Uint8 orientation = 0) {
|
||||
const ImGuiContext *context = ImGui::GetCurrentContext();
|
||||
const ImVec2 padding = context->Style.FramePadding;
|
||||
|
||||
@@ -500,6 +509,7 @@ static bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamp
|
||||
ImVec2 max = ImGui::GetItemRectMax();
|
||||
|
||||
if (image) {
|
||||
context->CurrentWindow->DrawList->AddCallback(imgui_tiles_draw_callback, (void *)&tile_index, sizeof(Uint32));
|
||||
switch (orientation) {
|
||||
case 0: context->CurrentWindow->DrawList->AddImageQuad((ImTextureID)image, min + padding, ImVec2(max.x - padding.x, min.y + padding.y), max - padding, ImVec2(min.x + padding.x, max.y - padding.y), ImVec2(uv0.x, uv0.y), ImVec2(uv1.x, uv0.y), ImVec2(uv1.x, uv1.y), ImVec2(uv0.x, uv1.y)); break;
|
||||
case 1: context->CurrentWindow->DrawList->AddImageQuad((ImTextureID)image, min + padding, ImVec2(max.x - padding.x, min.y + padding.y), max - padding, ImVec2(min.x + padding.x, max.y - padding.y), ImVec2(uv1.x, uv0.y), ImVec2(uv1.x, uv1.y), ImVec2(uv0.x, uv1.y), ImVec2(uv0.x, uv0.y)); break;
|
||||
@@ -507,6 +517,7 @@ static bool SelectableImage(const char *label, bool selected, SDL_GPUTextureSamp
|
||||
case 3: context->CurrentWindow->DrawList->AddImageQuad((ImTextureID)image, min + padding, ImVec2(max.x - padding.x, min.y + padding.y), max - padding, ImVec2(min.x + padding.x, max.y - padding.y), ImVec2(uv0.x, uv1.y), ImVec2(uv0.x, uv0.y), ImVec2(uv1.x, uv0.y), ImVec2(uv1.x, uv1.y)); break;
|
||||
default: SDL_assert_always(false); break;
|
||||
}
|
||||
context->CurrentWindow->DrawList->AddCallback(ImDrawCallback_ResetRenderState, NULL);
|
||||
}
|
||||
|
||||
return pressed;
|
||||
@@ -593,7 +604,7 @@ static bool recreate_graphics_pipelines() {
|
||||
{
|
||||
.format = SDL_GetGPUSwapchainTextureFormat(device, window),
|
||||
.blend_state = {
|
||||
.src_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE,
|
||||
.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
|
||||
.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.color_blend_op = SDL_GPU_BLENDOP_ADD,
|
||||
|
||||
@@ -825,6 +836,217 @@ static bool recreate_graphics_pipelines() {
|
||||
SDL_ReleaseGPUShader(device, world_pixel_shader);
|
||||
}
|
||||
|
||||
{ // gui_tile_graphics_pipeline
|
||||
SDL_GPUShaderCreateInfo gui_tile_vertex_shader_info = {
|
||||
.code_size = SDL_arraysize(SPIRV_gui_tile),
|
||||
.code = SPIRV_gui_tile,
|
||||
.entrypoint = "main_vertex",
|
||||
.format = SDL_GPU_SHADERFORMAT_SPIRV,
|
||||
.stage = SDL_GPU_SHADERSTAGE_VERTEX,
|
||||
|
||||
.num_uniform_buffers = 1,
|
||||
};
|
||||
|
||||
SDL_GPUShader *gui_tile_vertex_shader = SDL_CreateGPUShader(device, &gui_tile_vertex_shader_info);
|
||||
if (!gui_tile_vertex_shader) {
|
||||
log_error("Failed to create gui_tile vertex shader. Exiting.");
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_GPUShaderCreateInfo gui_tile_pixel_shader_info = {
|
||||
.code_size = SDL_arraysize(SPIRV_gui_tile),
|
||||
.code = SPIRV_gui_tile,
|
||||
.entrypoint = "main_fragment",
|
||||
.format = SDL_GPU_SHADERFORMAT_SPIRV,
|
||||
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
|
||||
|
||||
.num_samplers = 1,
|
||||
.num_uniform_buffers = 1,
|
||||
};
|
||||
|
||||
SDL_GPUShader *gui_tile_pixel_shader = SDL_CreateGPUShader(device, &gui_tile_pixel_shader_info);
|
||||
if (!gui_tile_pixel_shader) {
|
||||
log_error("Failed to create gui_tile pixel shader. Exiting.");
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_GPUVertexBufferDescription vertex_buffer_descriptions[] = {
|
||||
{
|
||||
.slot = 0,
|
||||
.pitch = sizeof(ImDrawVert),
|
||||
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
|
||||
},
|
||||
{
|
||||
.slot = 1,
|
||||
.pitch = sizeof(Uint32),
|
||||
.input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE,
|
||||
.instance_step_rate = 1,
|
||||
},
|
||||
};
|
||||
|
||||
SDL_GPUVertexAttribute vertex_attributes[] = {
|
||||
{
|
||||
.location = 0,
|
||||
.buffer_slot = 0,
|
||||
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
|
||||
.offset = offsetof(ImDrawVert, pos),
|
||||
},
|
||||
{
|
||||
.location = 1,
|
||||
.buffer_slot = 0,
|
||||
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
|
||||
.offset = offsetof(ImDrawVert, uv),
|
||||
},
|
||||
{
|
||||
.location = 2,
|
||||
.buffer_slot = 0,
|
||||
.format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
|
||||
.offset = offsetof(ImDrawVert, col),
|
||||
},
|
||||
};
|
||||
|
||||
SDL_GPUGraphicsPipelineCreateInfo gui_tile_graphics_pipeline_info = {
|
||||
.vertex_shader = gui_tile_vertex_shader,
|
||||
.fragment_shader = gui_tile_pixel_shader,
|
||||
.vertex_input_state = {
|
||||
.vertex_buffer_descriptions = vertex_buffer_descriptions,
|
||||
.num_vertex_buffers = SDL_arraysize(vertex_buffer_descriptions),
|
||||
.vertex_attributes = vertex_attributes,
|
||||
.num_vertex_attributes = SDL_arraysize(vertex_attributes),
|
||||
},
|
||||
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
|
||||
.rasterizer_state = {
|
||||
.fill_mode = SDL_GPU_FILLMODE_FILL,
|
||||
.cull_mode = SDL_GPU_CULLMODE_NONE,
|
||||
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
|
||||
},
|
||||
.target_info = {
|
||||
.color_target_descriptions = color_target_descriptions,
|
||||
.num_color_targets = SDL_arraysize(color_target_descriptions),
|
||||
},
|
||||
};
|
||||
|
||||
if (gui_tile_graphics_pipeline) {
|
||||
SDL_ReleaseGPUGraphicsPipeline(device, gui_tile_graphics_pipeline);
|
||||
gui_tile_graphics_pipeline = NULL;
|
||||
}
|
||||
|
||||
gui_tile_graphics_pipeline = SDL_CreateGPUGraphicsPipeline(device, &gui_tile_graphics_pipeline_info);
|
||||
if (!gui_tile_graphics_pipeline) {
|
||||
log_error("Failed to create world graphics pipeline. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_ReleaseGPUShader(device, gui_tile_vertex_shader);
|
||||
SDL_ReleaseGPUShader(device, gui_tile_pixel_shader);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool recreate_tile_textures() {
|
||||
SDL_PropertiesID tile_textures_array_properties = SDL_CreateProperties();
|
||||
defer(SDL_DestroyProperties(tile_textures_array_properties));
|
||||
|
||||
SDL_SetStringProperty(tile_textures_array_properties, SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING, "tile_textures_array");
|
||||
|
||||
SDL_GPUTextureCreateInfo tile_textures_array_info = {
|
||||
.type = SDL_GPU_TEXTURETYPE_2D_ARRAY,
|
||||
.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB,
|
||||
.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER,
|
||||
.width = TILE_SIZE,
|
||||
.height = TILE_SIZE,
|
||||
|
||||
.layer_count_or_depth = SDL_arraysize(tile_infos),
|
||||
.num_levels = 1,
|
||||
|
||||
.props = tile_textures_array_properties,
|
||||
};
|
||||
|
||||
tile_textures_array = SDL_CreateGPUTexture(device, &tile_textures_array_info);
|
||||
if (!tile_textures_array) {
|
||||
log_error("Failed to create gpu tiles_texture (%s).", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Uint32 transfer_buffer_size = TILE_SIZE * TILE_SIZE * 4 * SDL_arraysize(tile_infos);
|
||||
SDL_GPUTransferBufferCreateInfo transfer_buffer_info = {
|
||||
.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
|
||||
.size = transfer_buffer_size,
|
||||
};
|
||||
|
||||
SDL_GPUTransferBuffer *transfer_buffer = SDL_CreateGPUTransferBuffer(device, &transfer_buffer_info);
|
||||
if (!transfer_buffer) {
|
||||
log_error("Failed to create gpu transfer buffer (%s).", SDL_GetError());
|
||||
SDL_ReleaseGPUTexture(device, tile_textures_array);
|
||||
return false;
|
||||
}
|
||||
defer(SDL_ReleaseGPUTransferBuffer(device, transfer_buffer));
|
||||
|
||||
SDL_GPUCommandBuffer *command_buffer = SDL_AcquireGPUCommandBuffer(device);
|
||||
if (!command_buffer) {
|
||||
log_error("Failed to acquire gpu command buffer (%s).", SDL_GetError());
|
||||
SDL_ReleaseGPUTexture(device, tile_textures_array);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_GPUCopyPass *copy_pass = SDL_BeginGPUCopyPass(command_buffer);
|
||||
|
||||
void *transfer_data = SDL_MapGPUTransferBuffer(device, transfer_buffer, false);
|
||||
if (!transfer_data) {
|
||||
log_error("Failed to map gpu transfer buffer (%s).", SDL_GetError());
|
||||
SDL_ReleaseGPUTexture(device, tile_textures_array);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Uint32 i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||
int width = 0, height = 0;
|
||||
stbi_uc *data = stbi_load(tile_infos[i].asset_path, &width, &height, NULL, 4);
|
||||
if (!data) {
|
||||
log_error("Failed to load texture (\"%s\"). Exiting.", tile_infos[i].asset_path);
|
||||
SDL_ReleaseGPUTexture(device, tile_textures_array);
|
||||
SDL_CancelGPUCommandBuffer(command_buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_assert_always(width == TILE_SIZE);
|
||||
SDL_assert_always(height == TILE_SIZE);
|
||||
|
||||
tile_infos[i].uv_min = V2_(0, 0);
|
||||
tile_infos[i].uv_max = V2_(1, 1);
|
||||
|
||||
cpu_tile_infos_buffer[i] = V4_(tile_infos[i].uv_min, tile_infos[i].uv_max);
|
||||
|
||||
memmove((char *)transfer_data + i * width * height * 4, data, width * height * 4);
|
||||
stbi_image_free(data);
|
||||
|
||||
SDL_GPUTextureTransferInfo transfer_info = {
|
||||
.transfer_buffer = transfer_buffer,
|
||||
.offset = i * width * height * 4,
|
||||
.pixels_per_row = (Uint32)width,
|
||||
};
|
||||
|
||||
SDL_GPUTextureRegion tetxure_region = {
|
||||
.texture = tile_textures_array,
|
||||
.layer = i,
|
||||
.w = (Uint32)width,
|
||||
.h = (Uint32)height,
|
||||
.d = 1,
|
||||
};
|
||||
|
||||
SDL_UploadToGPUTexture(copy_pass, &transfer_info, &tetxure_region, false);
|
||||
}
|
||||
|
||||
SDL_UnmapGPUTransferBuffer(device, transfer_buffer);
|
||||
SDL_EndGPUCopyPass(copy_pass);
|
||||
|
||||
if (!SDL_SubmitGPUCommandBuffer(command_buffer)) {
|
||||
log_error("Failed to submit gpu command buffer (%s).", SDL_GetError());
|
||||
SDL_ReleaseGPUTexture(device, tile_textures_array);
|
||||
SDL_CancelGPUCommandBuffer(command_buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -867,7 +1089,10 @@ int main(int argc, char **argv) {
|
||||
highest_supported_sample_count = SDL_GPUTextureSupportsSampleCount(device, swapchain_format, SDL_GPU_SAMPLECOUNT_4) ? SDL_GPU_SAMPLECOUNT_4 : highest_supported_sample_count;
|
||||
highest_supported_sample_count = SDL_GPUTextureSupportsSampleCount(device, swapchain_format, SDL_GPU_SAMPLECOUNT_8) ? SDL_GPU_SAMPLECOUNT_8 : highest_supported_sample_count;
|
||||
|
||||
recreate_graphics_pipelines();
|
||||
if (!recreate_graphics_pipelines()) {
|
||||
log_error("Failed to create graphics pipelines. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_GPUTexture *player_texture = create_shader_texture("../assets/decorations/strawberry.png");
|
||||
if (!player_texture) {
|
||||
@@ -875,60 +1100,8 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tile_border_size = 4;
|
||||
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);
|
||||
for (int i = 0; i < SDL_arraysize(tile_infos); i++) {
|
||||
int width = 0, height = 0;
|
||||
stbi_uc *data = stbi_load(tile_infos[i].asset_path, &width, &height, NULL, 4);
|
||||
if (!data) {
|
||||
log_error("Failed to load texture (\"%s\"). Exiting.", tile_infos[i].asset_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
smol_atlas_item_t *atlas_item = sma_item_add(tile_atlas, width + 2 * tile_border_size, height + 2 * tile_border_size);
|
||||
if (!atlas_item) {
|
||||
log_error("Failed to add tile texture to atlas. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
int item_x = sma_item_x(atlas_item);
|
||||
int item_y = sma_item_y(atlas_item);
|
||||
|
||||
tile_infos[i].uv_min = V2_((item_x + tile_border_size) / (float)tile_atlas_size, (item_y + tile_border_size) / (float)tile_atlas_size);
|
||||
tile_infos[i].uv_max = V2_((item_x + tile_border_size + width) / (float)tile_atlas_size, (item_y + tile_border_size + height) / (float)tile_atlas_size);
|
||||
|
||||
cpu_tile_infos_buffer[i] = V4_(tile_infos[i].uv_min, tile_infos[i].uv_max);
|
||||
|
||||
blit(tile_atlas_texture_cpu, tile_atlas_size, item_x + tile_border_size, item_y + tile_border_size, (char *)data, width, width, height);
|
||||
|
||||
#define image_index(image, width, components, x, y) (*(((char *)(image)) + (((y) * (width) + (x)) * (components))))
|
||||
for (int j = 0; j < tile_border_size; j++) {
|
||||
// HORIZONTAL EDGES
|
||||
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);
|
||||
// VERTICAL EDGES
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
sma_atlas_destroy(tile_atlas);
|
||||
|
||||
SDL_GPUTexture *tile_atlas_texture = create_shader_texture("tile_atlas", tile_atlas_texture_cpu, tile_atlas_size, tile_atlas_size, 4);
|
||||
free(tile_atlas_texture_cpu);
|
||||
if (!tile_atlas_texture) {
|
||||
log_error("Failed to create tile atlas texture. Exiting.");
|
||||
if (!recreate_tile_textures()) {
|
||||
log_error("Failed to create tile textures. Exiting.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -946,7 +1119,7 @@ int main(int argc, char **argv) {
|
||||
};
|
||||
|
||||
pixel_sampler = SDL_CreateGPUSampler(device, &pixel_sampler_info);
|
||||
SDL_GPUTextureSamplerBinding tile_atlas_texture_binding = { .texture = tile_atlas_texture, .sampler = pixel_sampler };
|
||||
SDL_GPUTextureSamplerBinding tile_atlas_texture_binding = { .texture = tile_textures_array, .sampler = pixel_sampler };
|
||||
|
||||
vertex_buffer = create_buffer(SDL_GPU_BUFFERUSAGE_VERTEX, sizeof(vertices), vertices, "vertex_buffer");
|
||||
if (!vertex_buffer) {
|
||||
@@ -1017,7 +1190,7 @@ int main(int argc, char **argv) {
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(0, window_height), ImVec2(window_width, window_height));
|
||||
ImGui::SetNextWindowSize(ImVec2(0.2 * window_width, window_height), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("Tile Picker", NULL, ImGuiWindowFlags_NoFocusOnAppearing)) {
|
||||
if (SelectableImage("##tile", selected_tile == -1, NULL, ImVec2(32, 32))) {
|
||||
if (SelectableTile("##tile", selected_tile == -1, NULL, 0, ImVec2(32, 32))) {
|
||||
selected_tile = -1;
|
||||
}
|
||||
|
||||
@@ -1031,7 +1204,7 @@ int main(int argc, char **argv) {
|
||||
if (available >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableImage("##tile", selected_tile == i, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, SDL_max(selected_rotation, 0)))
|
||||
if (SelectableTile("##tile", selected_tile == i, &tile_atlas_texture_binding, i, ImVec2(32, 32), uv0, uv1, SDL_max(selected_rotation, 0)))
|
||||
selected_tile = i;
|
||||
|
||||
ImGui::PopID();
|
||||
@@ -1043,25 +1216,25 @@ int main(int argc, char **argv) {
|
||||
ImVec2 uv0 = ImVec2(tile_infos[selected_tile].uv_min.x, tile_infos[selected_tile].uv_min.y);
|
||||
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 (SelectableTile("##None", selected_rotation == 0, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 0))
|
||||
selected_rotation = 0;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableImage("##90", selected_rotation == 1, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, 1))
|
||||
if (SelectableTile("##90", selected_rotation == 1, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 1))
|
||||
selected_rotation = 1;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableImage("##180", selected_rotation == 2, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, 2))
|
||||
if (SelectableTile("##180", selected_rotation == 2, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 2))
|
||||
selected_rotation = 2;
|
||||
|
||||
if (ImGui::GetContentRegionAvail().x - ImGui::GetItemRectMax().x >= 32)
|
||||
ImGui::SameLine();
|
||||
|
||||
if (SelectableImage("##270", selected_rotation == 3, &tile_atlas_texture_binding, ImVec2(32, 32), uv0, uv1, 3))
|
||||
if (SelectableTile("##270", selected_rotation == 3, &tile_atlas_texture_binding, selected_tile, ImVec2(32, 32), uv0, uv1, 3))
|
||||
selected_rotation = 3;
|
||||
|
||||
if (ImGui::Selectable("Random", selected_rotation == -1))
|
||||
@@ -1341,7 +1514,7 @@ int main(int argc, char **argv) {
|
||||
{ .buffer = world_buffer, .offset = 0 },
|
||||
};
|
||||
SDL_GPUTextureSamplerBinding texture_bindings[] = {
|
||||
{ .texture = tile_atlas_texture, .sampler = pixel_sampler },
|
||||
{ .texture = tile_textures_array, .sampler = pixel_sampler },
|
||||
};
|
||||
|
||||
SDL_BindGPUGraphicsPipeline(render_pass, world_graphics_pipeline);
|
||||
|
||||
Reference in New Issue
Block a user