Creating Vulkan framebufffers
This commit is contained in:
@@ -804,6 +804,9 @@ KRContext::destroySurfaces()
|
||||
for (auto itr = m_surfaces.begin(); itr != m_surfaces.end(); itr++) {
|
||||
SurfaceInfo& surfaceInfo = (*itr).second;
|
||||
DeviceInfo& deviceInfo = GetDeviceInfo(surfaceInfo.deviceHandle);
|
||||
for (auto framebuffer : surfaceInfo.swapChainFramebuffers) {
|
||||
vkDestroyFramebuffer(deviceInfo.logicalDevice, framebuffer, nullptr);
|
||||
}
|
||||
vkDestroySwapchainKHR(deviceInfo.logicalDevice, surfaceInfo.swapChain, nullptr);
|
||||
vkDestroySurfaceKHR(m_vulkanInstance, surfaceInfo.surface, nullptr);
|
||||
|
||||
@@ -913,7 +916,6 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
return KR_ERROR_NO_DEVICE;
|
||||
}
|
||||
|
||||
// TODO - Support multiple devices rather than just choosing the first
|
||||
DeviceInfo* deviceInfo = nullptr;
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -1072,11 +1074,37 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
|
||||
KrSurfaceHandle surfaceHandle = ++m_topSurfaceHandle;
|
||||
m_surfaces.insert(std::pair<KrSurfaceHandle, SurfaceInfo>(surfaceHandle, info));
|
||||
|
||||
|
||||
m_surfaceHandleMap.insert(std::pair<KrSurfaceMapIndex, KrSurfaceHandle>(createWindowSurfaceInfo->surfaceHandle, surfaceHandle));
|
||||
|
||||
m_pPipelineManager->createPipelines(surfaceHandle);
|
||||
|
||||
{
|
||||
KRPipeline* testPipeline = m_pPipelineManager->get("simple_blit");
|
||||
SurfaceInfo& surface = m_surfaces[surfaceHandle];
|
||||
surface.swapChainFramebuffers.resize(surface.swapChainImageViews.size());
|
||||
|
||||
for (size_t i = 0; i < surface.swapChainImageViews.size(); i++) {
|
||||
VkImageView attachments[] = {
|
||||
surface.swapChainImageViews[i]
|
||||
};
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{};
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.renderPass = testPipeline->GetRenderPass();
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = attachments;
|
||||
framebufferInfo.width = surface.swapChainExtent.width;
|
||||
framebufferInfo.height = surface.swapChainExtent.height;
|
||||
framebufferInfo.layers = 1;
|
||||
|
||||
if (vkCreateFramebuffer(deviceInfo->logicalDevice, &framebufferInfo, nullptr, &surface.swapChainFramebuffers[i]) != VK_SUCCESS) {
|
||||
// TODO - Error Handling
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return KR_SUCCESS;
|
||||
#else
|
||||
// Not implemented for this platform
|
||||
|
||||
@@ -150,6 +150,7 @@ public:
|
||||
VkFormat swapChainImageFormat;
|
||||
VkExtent2D swapChainExtent;
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
std::vector<VkFramebuffer> swapChainFramebuffers;
|
||||
#ifdef WIN32
|
||||
HWND hWnd;
|
||||
#endif
|
||||
|
||||
@@ -763,3 +763,8 @@ bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix
|
||||
const char *KRPipeline::getKey() const {
|
||||
return m_szKey;
|
||||
}
|
||||
|
||||
VkRenderPass& KRPipeline::GetRenderPass()
|
||||
{
|
||||
return m_renderPass;
|
||||
}
|
||||
@@ -144,6 +144,8 @@ public:
|
||||
void setUniform(int location, const Vector3 &value);
|
||||
void setUniform(int location, const Vector4 &value);
|
||||
void setUniform(int location, const Matrix4 &value);
|
||||
|
||||
VkRenderPass& GetRenderPass();
|
||||
|
||||
private:
|
||||
GLuint m_iProgram;
|
||||
|
||||
@@ -286,3 +286,15 @@ bool KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline,
|
||||
size_t KRPipelineManager::getPipelineHandlesUsed() {
|
||||
return m_pipelines.size();
|
||||
}
|
||||
|
||||
|
||||
KRPipeline* KRPipelineManager::get(const char* name)
|
||||
{
|
||||
std::pair<std::string, std::vector<int> > key;
|
||||
key.first = name;
|
||||
auto itr = m_pipelines.find(key);
|
||||
if (itr == m_pipelines.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return (*itr).second;
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
KRPipelineManager(KRContext &context);
|
||||
virtual ~KRPipelineManager();
|
||||
void createPipelines(KrSurfaceHandle surface);
|
||||
KRPipeline* get(const char* szKey);
|
||||
|
||||
KRPipeline *getPipeline(const std::string &pipeline_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user