Add more windowing stuff to Linux backend, fix some other clang-analyze bugs
This commit is contained in:
parent
bf192cd23a
commit
c7efea5258
6 changed files with 36 additions and 26 deletions
|
@ -107,12 +107,8 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
|
|||
|
||||
Vector3 scl;
|
||||
file->read(&scl);
|
||||
|
||||
int finalBoneIndex = 0;
|
||||
|
||||
if(boneMapping.count(bone)) {
|
||||
finalBoneIndex = boneMapping[bone];
|
||||
} else {
|
||||
|
||||
if(!boneMapping.count(bone)) {
|
||||
Bone b;
|
||||
b.index = mesh->bones.size();
|
||||
b.name = bone;
|
||||
|
@ -127,7 +123,6 @@ std::unique_ptr<Mesh> load_mesh(const file::Path path) {
|
|||
mesh->bones.push_back(b);
|
||||
|
||||
boneMapping[bone] = b.index;
|
||||
finalBoneIndex = b.index;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
_windows.push_back(std::move(std::make_unique<Window>()));
|
||||
_windows.push_back(std::make_unique<Window>());
|
||||
|
||||
Window* window = _windows.back().get();
|
||||
window->identifier = identifier;
|
||||
|
|
|
@ -226,11 +226,13 @@ void GFXVulkan::recreate_view(const int identifier, const uint32_t width, const
|
|||
if(surface->identifier == identifier)
|
||||
found_surface = surface;
|
||||
}
|
||||
|
||||
found_surface->surfaceWidth = width;
|
||||
found_surface->surfaceHeight = height;
|
||||
|
||||
createSwapchain(found_surface, found_surface->swapchain);
|
||||
|
||||
if(found_surface != nullptr) {
|
||||
found_surface->surfaceWidth = width;
|
||||
found_surface->surfaceHeight = height;
|
||||
|
||||
createSwapchain(found_surface, found_surface->swapchain);
|
||||
}
|
||||
}
|
||||
|
||||
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 = {};
|
||||
range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
range.memory = vulkanBuffer->memory;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
range.size = size;
|
||||
range.offset = offset;
|
||||
vkFlushMappedMemoryRanges(device, 1, &range);
|
||||
|
||||
vkUnmapMemory(device, vulkanBuffer->memory);
|
||||
|
@ -1029,8 +1032,11 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
GFXVulkanCommandBuffer* cmdbuf = (GFXVulkanCommandBuffer*)command_buffer;
|
||||
if(cmdbuf->handle != VK_NULL_HANDLE)
|
||||
cmd = cmdbuf->handle;
|
||||
else
|
||||
else if(current_surface != nullptr)
|
||||
cmd = commandBuffers[current_surface-> currentFrame];
|
||||
|
||||
if(cmd == nullptr)
|
||||
return;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo = {};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
|
@ -1041,9 +1047,11 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
VkRenderPass currentRenderPass = VK_NULL_HANDLE;
|
||||
GFXVulkanPipeline* currentPipeline = nullptr;
|
||||
uint64_t lastDescriptorHash = 0;
|
||||
VkIndexType currentIndexType = VK_INDEX_TYPE_UINT32;
|
||||
|
||||
const auto try_bind_descriptor = [cmd, this, ¤tPipeline, &lastDescriptorHash]() -> bool {
|
||||
if(currentPipeline == nullptr)
|
||||
return false;
|
||||
|
||||
if (lastDescriptorHash != getDescriptorHash(currentPipeline)) {
|
||||
if (!currentPipeline->cachedDescriptorSets.count(getDescriptorHash(currentPipeline)))
|
||||
cacheDescriptorState(currentPipeline, currentPipeline->descriptorLayout);
|
||||
|
@ -1060,7 +1068,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
return true;
|
||||
};
|
||||
|
||||
for (auto command : command_buffer->commands) {
|
||||
for (const auto& command : command_buffer->commands) {
|
||||
switch (command.type) {
|
||||
case GFXCommandType::SetRenderPass:
|
||||
{
|
||||
|
@ -1100,7 +1108,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
|
||||
vkCmdSetScissor(cmd, 0, 1, &scissor);
|
||||
}
|
||||
else {
|
||||
else if(current_surface != nullptr) {
|
||||
renderPassInfo.framebuffer = current_surface->swapchainFramebuffers[imageIndex];
|
||||
|
||||
VkViewport viewport = {};
|
||||
|
@ -1170,8 +1178,6 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
indexType = VK_INDEX_TYPE_UINT16;
|
||||
|
||||
vkCmdBindIndexBuffer(cmd, ((GFXVulkanBuffer*)command.data.set_index_buffer.buffer)->handle, 0, indexType);
|
||||
|
||||
currentIndexType = indexType;
|
||||
}
|
||||
break;
|
||||
case GFXCommandType::SetPushConstant:
|
||||
|
@ -1267,7 +1273,7 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
submitInfo.pCommandBuffers = &cmd;
|
||||
|
||||
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
} else {
|
||||
} else if(current_surface != nullptr) {
|
||||
// submit
|
||||
VkSubmitInfo submitInfo = {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
|
@ -1445,6 +1451,7 @@ void GFXVulkan::createSwapchain(NativeSurface* native_surface, VkSwapchainKHR ol
|
|||
#else
|
||||
if(native_surface->surface == VK_NULL_HANDLE) {
|
||||
struct WindowConnection {
|
||||
int identifier = 0;
|
||||
xcb_connection_t* connection;
|
||||
xcb_window_t window;
|
||||
};
|
||||
|
|
|
@ -300,7 +300,7 @@ void Renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
|
|||
|
||||
commandbuffer->pop_group();
|
||||
|
||||
if(render_options.enable_depth_of_field)
|
||||
if(render_options.enable_depth_of_field && dofPass != nullptr)
|
||||
dofPass->render(commandbuffer, *scene);
|
||||
|
||||
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);
|
||||
|
||||
ShaderStage stage;
|
||||
ShaderStage stage = ShaderStage::Vertex;
|
||||
if(shader_path.extension() == ".vert")
|
||||
stage = ShaderStage::Vertex;
|
||||
else if(shader_path.extension() == ".frag")
|
||||
|
|
|
@ -27,6 +27,7 @@ xcb_connection_t* connection = nullptr;
|
|||
xcb_screen_t* screen = nullptr;
|
||||
|
||||
struct WindowConnection {
|
||||
int identifier = 0;
|
||||
xcb_connection_t* connection;
|
||||
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) {
|
||||
auto& win = window_connections.emplace_back();
|
||||
win.connection = connection;
|
||||
win.identifier = window_connections.size() - 1;
|
||||
|
||||
uint32_t mask;
|
||||
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);
|
||||
app->initialize_render();
|
||||
|
||||
return window_connections.size() - 1;
|
||||
return win.identifier;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
int identifier = -1;
|
||||
for(auto window : window_connections) {
|
||||
if(window.window == cfgEvent->window)
|
||||
identifier = window.identifier;
|
||||
}
|
||||
|
||||
window_width = cfgEvent->width;
|
||||
window_height = cfgEvent->height;
|
||||
|
||||
engine->resize(0, {cfgEvent->width, cfgEvent->height});
|
||||
engine->resize(identifier, {cfgEvent->width, cfgEvent->height});
|
||||
}
|
||||
break;
|
||||
case XCB_KEY_PRESS:
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
return 0;
|
||||
} else {
|
||||
ShaderStage stage;
|
||||
ShaderStage stage = ShaderStage::Vertex;
|
||||
if(has_extension(source_path, ".vert"))
|
||||
stage = ShaderStage::Vertex;
|
||||
else if(has_extension(source_path, ".frag"))
|
||||
|
|
Reference in a new issue