Archived
1
Fork 0

Add more windowing stuff to Linux backend, fix some other clang-analyze bugs

This commit is contained in:
redstrate 2021-02-18 08:31:36 -05:00
parent bf192cd23a
commit c7efea5258
6 changed files with 36 additions and 26 deletions

View file

@ -108,11 +108,7 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
Vector3 scl; Vector3 scl;
file->read(&scl); file->read(&scl);
int finalBoneIndex = 0; if(!boneMapping.count(bone)) {
if(boneMapping.count(bone)) {
finalBoneIndex = boneMapping[bone];
} else {
Bone b; Bone b;
b.index = mesh->bones.size(); b.index = mesh->bones.size();
b.name = bone; b.name = bone;
@ -127,7 +123,6 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
mesh->bones.push_back(b); mesh->bones.push_back(b);
boneMapping[bone] = b.index; boneMapping[bone] = b.index;
finalBoneIndex = b.index;
} }
} }

View file

@ -414,7 +414,7 @@ void Engine::add_window(void* native_handle, const int identifier, const prism::
_gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height); _gfx->initialize_view(native_handle, identifier, drawable_extent.width, drawable_extent.height);
_windows.push_back(std::move(std::make_unique<Window>())); _windows.push_back(std::make_unique<Window>());
Window* window = _windows.back().get(); Window* window = _windows.back().get();
window->identifier = identifier; window->identifier = identifier;

View file

@ -227,10 +227,12 @@ void GFXVulkan::recreate_view(const int identifier, const uint32_t width, const
found_surface = surface; found_surface = surface;
} }
found_surface->surfaceWidth = width; if(found_surface != nullptr) {
found_surface->surfaceHeight = height; found_surface->surfaceWidth = width;
found_surface->surfaceHeight = height;
createSwapchain(found_surface, found_surface->swapchain); createSwapchain(found_surface, found_surface->swapchain);
}
} }
GFXBuffer* GFXVulkan::create_buffer(void *data, const GFXSize size, const bool dynamic_data, const GFXBufferUsage usage) { GFXBuffer* GFXVulkan::create_buffer(void *data, const GFXSize size, const bool dynamic_data, const GFXBufferUsage usage) {
@ -294,7 +296,8 @@ void GFXVulkan::copy_buffer(GFXBuffer* buffer, void* data, GFXSize offset, GFXSi
VkMappedMemoryRange range = {}; VkMappedMemoryRange range = {};
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range.memory = vulkanBuffer->memory; range.memory = vulkanBuffer->memory;
range.size = VK_WHOLE_SIZE; range.size = size;
range.offset = offset;
vkFlushMappedMemoryRanges(device, 1, &range); vkFlushMappedMemoryRanges(device, 1, &range);
vkUnmapMemory(device, vulkanBuffer->memory); vkUnmapMemory(device, vulkanBuffer->memory);
@ -1029,9 +1032,12 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
GFXVulkanCommandBuffer* cmdbuf = (GFXVulkanCommandBuffer*)command_buffer; GFXVulkanCommandBuffer* cmdbuf = (GFXVulkanCommandBuffer*)command_buffer;
if(cmdbuf->handle != VK_NULL_HANDLE) if(cmdbuf->handle != VK_NULL_HANDLE)
cmd = cmdbuf->handle; cmd = cmdbuf->handle;
else else if(current_surface != nullptr)
cmd = commandBuffers[current_surface-> currentFrame]; cmd = commandBuffers[current_surface-> currentFrame];
if(cmd == nullptr)
return;
VkCommandBufferBeginInfo beginInfo = {}; VkCommandBufferBeginInfo beginInfo = {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
@ -1041,9 +1047,11 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
VkRenderPass currentRenderPass = VK_NULL_HANDLE; VkRenderPass currentRenderPass = VK_NULL_HANDLE;
GFXVulkanPipeline* currentPipeline = nullptr; GFXVulkanPipeline* currentPipeline = nullptr;
uint64_t lastDescriptorHash = 0; uint64_t lastDescriptorHash = 0;
VkIndexType currentIndexType = VK_INDEX_TYPE_UINT32;
const auto try_bind_descriptor = [cmd, this, &currentPipeline, &lastDescriptorHash]() -> bool { const auto try_bind_descriptor = [cmd, this, &currentPipeline, &lastDescriptorHash]() -> bool {
if(currentPipeline == nullptr)
return false;
if (lastDescriptorHash != getDescriptorHash(currentPipeline)) { if (lastDescriptorHash != getDescriptorHash(currentPipeline)) {
if (!currentPipeline->cachedDescriptorSets.count(getDescriptorHash(currentPipeline))) if (!currentPipeline->cachedDescriptorSets.count(getDescriptorHash(currentPipeline)))
cacheDescriptorState(currentPipeline, currentPipeline->descriptorLayout); cacheDescriptorState(currentPipeline, currentPipeline->descriptorLayout);
@ -1060,7 +1068,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
return true; return true;
}; };
for (auto command : command_buffer->commands) { for (const auto& command : command_buffer->commands) {
switch (command.type) { switch (command.type) {
case GFXCommandType::SetRenderPass: case GFXCommandType::SetRenderPass:
{ {
@ -1100,7 +1108,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
vkCmdSetScissor(cmd, 0, 1, &scissor); vkCmdSetScissor(cmd, 0, 1, &scissor);
} }
else { else if(current_surface != nullptr) {
renderPassInfo.framebuffer = current_surface->swapchainFramebuffers[imageIndex]; renderPassInfo.framebuffer = current_surface->swapchainFramebuffers[imageIndex];
VkViewport viewport = {}; VkViewport viewport = {};
@ -1170,8 +1178,6 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
indexType = VK_INDEX_TYPE_UINT16; indexType = VK_INDEX_TYPE_UINT16;
vkCmdBindIndexBuffer(cmd, ((GFXVulkanBuffer*)command.data.set_index_buffer.buffer)->handle, 0, indexType); vkCmdBindIndexBuffer(cmd, ((GFXVulkanBuffer*)command.data.set_index_buffer.buffer)->handle, 0, indexType);
currentIndexType = indexType;
} }
break; break;
case GFXCommandType::SetPushConstant: case GFXCommandType::SetPushConstant:
@ -1267,7 +1273,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
submitInfo.pCommandBuffers = &cmd; submitInfo.pCommandBuffers = &cmd;
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
} else { } else if(current_surface != nullptr) {
// submit // submit
VkSubmitInfo submitInfo = {}; VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@ -1445,6 +1451,7 @@ void GFXVulkan::createSwapchain(NativeSurface* native_surface, VkSwapchainKHR ol
#else #else
if(native_surface->surface == VK_NULL_HANDLE) { if(native_surface->surface == VK_NULL_HANDLE) {
struct WindowConnection { struct WindowConnection {
int identifier = 0;
xcb_connection_t* connection; xcb_connection_t* connection;
xcb_window_t window; xcb_window_t window;
}; };

View file

@ -300,7 +300,7 @@ void Renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
commandbuffer->pop_group(); commandbuffer->pop_group();
if(render_options.enable_depth_of_field) if(render_options.enable_depth_of_field && dofPass != nullptr)
dofPass->render(commandbuffer, *scene); dofPass->render(commandbuffer, *scene);
beginInfo.framebuffer = nullptr; beginInfo.framebuffer = nullptr;
@ -1064,7 +1064,7 @@ ShaderSource Renderer::register_shader(const std::string_view shader_file) {
file::Path shader_path = file::Path(shader_file); file::Path shader_path = file::Path(shader_file);
ShaderStage stage; ShaderStage stage = ShaderStage::Vertex;
if(shader_path.extension() == ".vert") if(shader_path.extension() == ".vert")
stage = ShaderStage::Vertex; stage = ShaderStage::Vertex;
else if(shader_path.extension() == ".frag") else if(shader_path.extension() == ".frag")

View file

@ -27,6 +27,7 @@ xcb_connection_t* connection = nullptr;
xcb_screen_t* screen = nullptr; xcb_screen_t* screen = nullptr;
struct WindowConnection { struct WindowConnection {
int identifier = 0;
xcb_connection_t* connection; xcb_connection_t* connection;
xcb_window_t window; xcb_window_t window;
}; };
@ -67,6 +68,7 @@ static inline xcb_intern_atom_reply_t* intern_atom_helper(xcb_connection_t *conn
int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) { int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) {
auto& win = window_connections.emplace_back(); auto& win = window_connections.emplace_back();
win.connection = connection; win.connection = connection;
win.identifier = window_connections.size() - 1;
uint32_t mask; uint32_t mask;
uint32_t values[32]; uint32_t values[32];
@ -115,7 +117,7 @@ int platform::open_window(const std::string_view title, const prism::Rectangle r
engine->add_window((void*)&win, 0, rect.extent); engine->add_window((void*)&win, 0, rect.extent);
app->initialize_render(); app->initialize_render();
return window_connections.size() - 1; return win.identifier;
} }
void platform::close_window(const int index) { void platform::close_window(const int index) {
@ -362,10 +364,16 @@ int main(int argc, char* argv[]) {
{ {
const xcb_configure_notify_event_t *cfgEvent = (const xcb_configure_notify_event_t *)event; const xcb_configure_notify_event_t *cfgEvent = (const xcb_configure_notify_event_t *)event;
int identifier = -1;
for(auto window : window_connections) {
if(window.window == cfgEvent->window)
identifier = window.identifier;
}
window_width = cfgEvent->width; window_width = cfgEvent->width;
window_height = cfgEvent->height; window_height = cfgEvent->height;
engine->resize(0, {cfgEvent->width, cfgEvent->height}); engine->resize(identifier, {cfgEvent->width, cfgEvent->height});
} }
break; break;
case XCB_KEY_PRESS: case XCB_KEY_PRESS:

View file

@ -38,7 +38,7 @@ int main(int argc, char* argv[]) {
return 0; return 0;
} else { } else {
ShaderStage stage; ShaderStage stage = ShaderStage::Vertex;
if(has_extension(source_path, ".vert")) if(has_extension(source_path, ".vert"))
stage = ShaderStage::Vertex; stage = ShaderStage::Vertex;
else if(has_extension(source_path, ".frag")) else if(has_extension(source_path, ".frag"))