use image_count instead of color_count in Swapchain
This commit is contained in:
parent
adc3c5bd81
commit
9f37373631
@ -10,6 +10,7 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Basic")
|
||||
endmacro()
|
||||
|
||||
CreateProject(00_first_app first_app.cpp)
|
||||
CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
|
||||
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
|
||||
CreateProject(03_auto_instance auto_instance.cpp)
|
||||
|
8
example/Basic/first_app.cpp
Normal file
8
example/Basic/first_app.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
|
||||
}
|
@ -38,18 +38,12 @@ using namespace hgl;
|
||||
using namespace hgl::io;
|
||||
using namespace hgl::graph;
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
}}//namespace hgl::graph
|
||||
|
||||
class VulkanApplicationFramework:WindowEvent
|
||||
{
|
||||
protected:
|
||||
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
Window * win =nullptr;
|
||||
VulkanInstance * inst =nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
@ -91,8 +85,6 @@ public:
|
||||
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
CloseShaderCompiler();
|
||||
|
||||
win->Unjoin(this);
|
||||
|
||||
SAFE_CLEAR(db);
|
||||
@ -107,9 +99,6 @@ public:
|
||||
{
|
||||
logger::InitLogger(OS_TEXT("VulkanTest"));
|
||||
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
SetClearColor(COLOR::MozillaCharcoal);
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/graph/ViewportInfo.h>
|
||||
#include<hgl/graph/module/GraphModule.h>
|
||||
#include<hgl/io/event/WindowEvent.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -12,35 +13,6 @@ class TileData;
|
||||
class TileFont;
|
||||
class FontSource;
|
||||
|
||||
//
|
||||
///**
|
||||
// * 渲染模块工作配置
|
||||
// */
|
||||
//class GraphModuleWorkConfig
|
||||
//{
|
||||
// /**
|
||||
// * 渲染模块名称
|
||||
// * 在render_module为nullptr时,用于创建或加载RenderModule。
|
||||
// * 它和RenderModule返回的名称有可能一样,但也有可能不一样。
|
||||
// */
|
||||
// AnsiString render_module_name;
|
||||
// GraphModule *render_module=nullptr;
|
||||
//
|
||||
// BlendMode blend_mode;
|
||||
// RenderOrder render_order;
|
||||
//
|
||||
//public:
|
||||
//
|
||||
// const AnsiString &GetModuleName()const{return render_module_name;} ///<取得渲染模块名称
|
||||
//
|
||||
// GraphModule *GetModule(){return render_module;} ///<取得渲染模块
|
||||
//
|
||||
//public:
|
||||
//
|
||||
// GraphModuleWorkConfig();
|
||||
// virtual ~GraphModuleWorkConfig()=default;
|
||||
//};//class GraphModuleWorkConfig
|
||||
|
||||
class Window;
|
||||
class VulkanInstance;
|
||||
|
||||
@ -49,15 +21,10 @@ class TextureManager;
|
||||
|
||||
class SwapchainModule;
|
||||
|
||||
struct RenderFrameworkInitConfig
|
||||
{
|
||||
|
||||
};//struct RenderFrameworkInitConfig
|
||||
|
||||
/**
|
||||
* 渲染框架
|
||||
*/
|
||||
class RenderFramework
|
||||
class RenderFramework:public io::WindowEvent
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -72,6 +39,8 @@ protected:
|
||||
|
||||
ObjectList<GraphModule> module_list;
|
||||
|
||||
protected:
|
||||
|
||||
SwapchainModule * swapchain_module =nullptr;
|
||||
|
||||
protected:
|
||||
@ -103,8 +72,14 @@ public: //module
|
||||
|
||||
public: //manager
|
||||
|
||||
RenderPassManager *GetRenderPassManager(){return render_pass_manager;} ///<取得渲染通道管理器
|
||||
TextureManager *GetTextureManager(){return texture_manager;} ///<取得纹理管理器
|
||||
RenderPassManager * GetRenderPassManager(){return render_pass_manager;} ///<取得渲染通道管理器
|
||||
TextureManager * GetTextureManager (){return texture_manager;} ///<取得纹理管理器
|
||||
|
||||
public: //event
|
||||
|
||||
virtual void OnResize(uint,uint)override;
|
||||
virtual void OnActive(bool)override;
|
||||
virtual void OnClose ()override;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -11,14 +11,14 @@ class Framebuffer
|
||||
|
||||
VkExtent2D extent;
|
||||
uint32_t attachment_count;
|
||||
uint32_t color_count;
|
||||
uint32_t image_count;
|
||||
bool has_depth;
|
||||
|
||||
private:
|
||||
|
||||
friend class TextureManager;
|
||||
|
||||
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t color_count,bool depth);
|
||||
Framebuffer(VkDevice,VkFramebuffer,const VkExtent2D &,VkRenderPass,uint32_t image_count,bool depth);
|
||||
|
||||
public:
|
||||
|
||||
@ -32,7 +32,7 @@ public:
|
||||
const VkExtent2D & GetExtent ()const{return extent;}
|
||||
|
||||
const uint32_t GetAttachmentCount ()const{return attachment_count;} ///<获取渲染目标成分数量
|
||||
const uint32_t GetColorCount ()const{return color_count;} ///<取得颜色成分数量
|
||||
const uint32_t GetColorCount ()const{return image_count;} ///<取得颜色成分数量
|
||||
const bool HasDepth ()const{return has_depth;} ///<是否包含深度成分
|
||||
};//class Framebuffer
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
Framebuffer * GetFramebuffer (const uint32_t index) {return swapchain->sc_fbo[index];}
|
||||
|
||||
const uint32_t GetColorCount ()const override {return 1;}
|
||||
const uint32_t GetImageCount ()const {return swapchain->color_count;}
|
||||
const uint32_t GetImageCount ()const {return swapchain->image_count;}
|
||||
|
||||
virtual Texture2D * GetColorTexture (const int index=0) override{return swapchain->sc_color[index];}
|
||||
virtual Texture2D * GetDepthTexture () override{return swapchain->sc_depth;}
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
VkSurfaceFormatKHR surface_format;
|
||||
VkFormat depth_format;
|
||||
|
||||
uint32_t color_count =0;
|
||||
uint32_t image_count =0;
|
||||
|
||||
Texture2D ** sc_color =nullptr;
|
||||
Texture2D * sc_depth =nullptr;
|
||||
|
@ -125,7 +125,7 @@ public: // Load
|
||||
|
||||
public: //FrameBuffer相关
|
||||
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *rp,ImageView **color_list,const uint image_count,ImageView *depth);
|
||||
// Framebuffer *CreateFBO(RenderPass *,List<ImageView *> &color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *color,ImageView *depth);
|
||||
Framebuffer *CreateFBO(RenderPass *,ImageView *);
|
||||
|
@ -101,7 +101,6 @@ public:
|
||||
|
||||
template<typename T>
|
||||
T * GetModule(bool create=false){return module_manager->GetModule<T>(create);} ///<获取指定类型的模块
|
||||
|
||||
|
||||
public: //回调事件
|
||||
|
||||
|
@ -21,6 +21,8 @@ protected:
|
||||
public:
|
||||
|
||||
virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变
|
||||
|
||||
virtual void OnExecute(const double,RenderCmdBuffer *);
|
||||
|
||||
public:
|
||||
|
||||
@ -28,12 +30,16 @@ public:
|
||||
virtual ~SwapchainModule();
|
||||
|
||||
bool Init() override;
|
||||
void Swap();
|
||||
|
||||
public:
|
||||
|
||||
RenderPass * GetRenderPass () {return swapchain_rp;}
|
||||
|
||||
RTSwapchain * GetRenderTarget () {return swapchain_rt;}
|
||||
|
||||
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
|
||||
|
||||
};//class SwapchainModule:public GraphModule
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
bool InitShaderCompiler();
|
||||
void CloseShaderCompiler();
|
||||
|
||||
GraphModuleManager *InitGraphModuleManager(GPUDevice *dev);
|
||||
bool ClearGraphModuleManager(GPUDevice *dev);
|
||||
|
||||
@ -21,6 +24,8 @@ RenderFramework::~RenderFramework()
|
||||
// if(swapchain_module)graph_module_manager->ReleaseModule(swapchain_module);
|
||||
|
||||
ClearGraphModuleManager(device);
|
||||
|
||||
CloseShaderCompiler();
|
||||
}
|
||||
|
||||
void RenderFramework::StartTime()
|
||||
@ -56,8 +61,32 @@ void RenderFramework::MainLoop()
|
||||
}
|
||||
|
||||
EndFrame();
|
||||
|
||||
swapchain_module->Swap();
|
||||
last_time=cur_time;
|
||||
++frame_count;
|
||||
}
|
||||
|
||||
bool RenderFramework::Init()
|
||||
{
|
||||
if(!InitShaderCompiler())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderFramework::OnResize(uint w,uint h)
|
||||
{
|
||||
viewport_info.Set(w,h);
|
||||
|
||||
graph_module_manager->OnResize(VkExtent2D{.width=w,.height=h});
|
||||
}
|
||||
|
||||
void RenderFramework::OnActive(bool)
|
||||
{
|
||||
}
|
||||
|
||||
void RenderFramework::OnClose()
|
||||
{
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -21,23 +21,23 @@ VkFramebuffer CreateVulkanFramebuffer(VkDevice device,RenderPass *rp,const VkExt
|
||||
return fb;
|
||||
}
|
||||
|
||||
Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView **color_list,const uint color_count,ImageView *depth)
|
||||
Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView **color_list,const uint image_count,ImageView *depth)
|
||||
{
|
||||
uint att_count=color_count;
|
||||
uint att_count=image_count;
|
||||
|
||||
if(depth)++att_count;
|
||||
|
||||
AutoDeleteArray<VkImageView> attachments(att_count);
|
||||
VkImageView *ap=attachments;
|
||||
|
||||
if(color_count)
|
||||
if(image_count)
|
||||
{
|
||||
const List<VkFormat> &cf_list=rp->GetColorFormat();
|
||||
|
||||
const VkFormat *cf=cf_list.GetData();
|
||||
ImageView **iv=color_list;
|
||||
|
||||
for(uint i=0;i<color_count;i++)
|
||||
for(uint i=0;i<image_count;i++)
|
||||
{
|
||||
if(*cf!=(*iv)->GetFormat())
|
||||
return(nullptr);
|
||||
@ -60,7 +60,7 @@ Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView **color_list,con
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
attachments[color_count]=depth->GetImageView();
|
||||
attachments[image_count]=depth->GetImageView();
|
||||
|
||||
extent.width=depth->GetExtent().width;
|
||||
extent.height=depth->GetExtent().height;
|
||||
@ -76,7 +76,7 @@ Framebuffer *TextureManager::CreateFBO(RenderPass *rp,ImageView **color_list,con
|
||||
if(!fbo)
|
||||
return(nullptr);
|
||||
|
||||
return(new Framebuffer(GetVkDevice(),fbo,extent,rp->GetVkRenderPass(),color_count,depth));
|
||||
return(new Framebuffer(GetVkDevice(),fbo,extent,rp->GetVkRenderPass(),image_count,depth));
|
||||
}
|
||||
//
|
||||
//Framebuffer *GPUDevice::CreateFBO(RenderPass *rp,List<ImageView *> &color,ImageView *depth)
|
||||
|
@ -8,12 +8,12 @@ RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp
|
||||
if(!fbi)return(nullptr);
|
||||
if(!rp)return(nullptr);
|
||||
|
||||
const uint32_t color_count=fbi->GetColorCount();
|
||||
const uint32_t image_count=fbi->GetColorCount();
|
||||
const VkExtent2D extent=fbi->GetExtent();
|
||||
const VkFormat depth_format=fbi->GetDepthFormat();
|
||||
|
||||
AutoDeleteObjectArray<Texture2D> color_texture_list(color_count);
|
||||
AutoDeleteArray<ImageView *> color_iv_list(color_count); //iv只是从Texture2D中取出来的,无需一个个delete
|
||||
AutoDeleteObjectArray<Texture2D> color_texture_list(image_count);
|
||||
AutoDeleteArray<ImageView *> color_iv_list(image_count); //iv只是从Texture2D中取出来的,无需一个个delete
|
||||
|
||||
Texture2D **tp=color_texture_list;
|
||||
ImageView **iv=color_iv_list;
|
||||
@ -31,7 +31,7 @@ RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp
|
||||
|
||||
Texture2D *depth_texture=(depth_format!=PF_UNDEFINED)?CreateTexture2D(new DepthAttachmentTextureCreateInfo(depth_format,extent)):nullptr;
|
||||
|
||||
Framebuffer *fb=CreateFBO(rp,color_iv_list,color_count,depth_texture?depth_texture->GetImageView():nullptr);
|
||||
Framebuffer *fb=CreateFBO(rp,color_iv_list,image_count,depth_texture?depth_texture->GetImageView():nullptr);
|
||||
|
||||
if(fb)
|
||||
{
|
||||
@ -40,7 +40,7 @@ RenderTarget *TextureManager::CreateRT(const FramebufferInfo *fbi,RenderPass *rp
|
||||
DeviceQueue *q=dev->CreateQueue(fence_count,false);
|
||||
Semaphore *render_complete_semaphore=dev->CreateGPUSemaphore();
|
||||
|
||||
RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,color_count,depth_texture);
|
||||
RenderTarget *rt=new RenderTarget(q,render_complete_semaphore,rp,fb,color_texture_list,image_count,depth_texture);
|
||||
|
||||
color_texture_list.DiscardObject();
|
||||
return rt;
|
||||
|
@ -14,10 +14,10 @@ Framebuffer::Framebuffer(VkDevice dev,VkFramebuffer fb,const VkExtent2D &ext,VkR
|
||||
render_pass=rp;
|
||||
|
||||
extent=ext;
|
||||
color_count=cc;
|
||||
image_count=cc;
|
||||
has_depth=depth;
|
||||
|
||||
attachment_count=color_count;
|
||||
attachment_count=image_count;
|
||||
|
||||
if(has_depth)
|
||||
++attachment_count;
|
||||
|
@ -12,7 +12,7 @@ RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s)
|
||||
render_pass=nullptr;
|
||||
fbo=nullptr;
|
||||
|
||||
color_count=0;
|
||||
image_count=0;
|
||||
color_textures=nullptr;
|
||||
depth_texture=nullptr;
|
||||
render_complete_semaphore=s;
|
||||
@ -26,11 +26,11 @@ RenderTarget::RenderTarget(DeviceQueue *q,Semaphore *s,RenderPass *_rp,Framebuff
|
||||
|
||||
depth_texture=dt;
|
||||
|
||||
color_count=cc;
|
||||
if(color_count>0)
|
||||
image_count=cc;
|
||||
if(image_count>0)
|
||||
{
|
||||
color_textures=new Texture2D *[color_count];
|
||||
hgl_cpy(color_textures,ctl,color_count);
|
||||
color_textures=new Texture2D *[image_count];
|
||||
hgl_cpy(color_textures,ctl,image_count);
|
||||
|
||||
extent.width=color_textures[0]->GetWidth();
|
||||
extent.height=color_textures[0]->GetHeight();
|
||||
@ -53,7 +53,7 @@ RenderTarget::~RenderTarget()
|
||||
{
|
||||
SAFE_CLEAR(queue);
|
||||
SAFE_CLEAR(depth_texture);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,color_count);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(color_textures,image_count);
|
||||
|
||||
SAFE_CLEAR(render_complete_semaphore);
|
||||
SAFE_CLEAR(fbo);
|
||||
|
@ -4,9 +4,9 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
Swapchain::~Swapchain()
|
||||
{
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,color_count);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_fbo,image_count);
|
||||
SAFE_CLEAR(sc_depth);
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,color_count)
|
||||
SAFE_CLEAR_OBJECT_ARRAY_OBJECT(sc_color,image_count)
|
||||
|
||||
if(swap_chain)
|
||||
{
|
||||
@ -14,6 +14,6 @@ Swapchain::~Swapchain()
|
||||
swap_chain=VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
color_count=0;
|
||||
image_count=0;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -74,9 +74,9 @@ inline void CreateInputAttachmentReference(VkAttachmentReference *ref_list, uint
|
||||
|
||||
bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const RenderbufferInfo *rbi)
|
||||
{
|
||||
const uint color_count=rbi->GetColorCount();
|
||||
const uint image_count=rbi->GetColorCount();
|
||||
|
||||
const uint count=(rbi->HasDepthOrStencil())?color_count+1:color_count;
|
||||
const uint count=(rbi->HasDepthOrStencil())?image_count+1:image_count;
|
||||
|
||||
desc_list.SetCount(count);
|
||||
|
||||
@ -97,7 +97,7 @@ bool CreateAttachmentDescription(List<VkAttachmentDescription> &desc_list,const
|
||||
|
||||
desc=desc_list.GetData();
|
||||
const VkFormat *cf=rbi->GetColorFormat();
|
||||
for(uint i=0;i<color_count;i++)
|
||||
for(uint i=0;i<image_count;i++)
|
||||
{
|
||||
desc->finalLayout = rbi->GetColorLayout();
|
||||
desc->format = *cf;
|
||||
|
@ -87,12 +87,12 @@ namespace
|
||||
|
||||
bool SwapchainModule::CreateSwapchainFBO()
|
||||
{
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->color_count),nullptr)!=VK_SUCCESS)
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->image_count),nullptr)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
AutoDeleteArray<VkImage> sc_images(swapchain->color_count);
|
||||
AutoDeleteArray<VkImage> sc_images(swapchain->image_count);
|
||||
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->color_count),sc_images)!=VK_SUCCESS)
|
||||
if(vkGetSwapchainImagesKHR(swapchain->device,swapchain->swap_chain,&(swapchain->image_count),sc_images)!=VK_SUCCESS)
|
||||
return(false);
|
||||
|
||||
TextureManager *tex_manager=GetModule<TextureManager>();
|
||||
@ -114,10 +114,10 @@ bool SwapchainModule::CreateSwapchainFBO()
|
||||
// }
|
||||
//#endif//_DEBUG
|
||||
|
||||
swapchain->sc_color =hgl_zero_new<Texture2D *>(swapchain->color_count);
|
||||
swapchain->sc_fbo =hgl_zero_new<Framebuffer *>(swapchain->color_count);
|
||||
swapchain->sc_color =hgl_zero_new<Texture2D *>(swapchain->image_count);
|
||||
swapchain->sc_fbo =hgl_zero_new<Framebuffer *>(swapchain->image_count);
|
||||
|
||||
for(uint32_t i=0;i<swapchain->color_count;i++)
|
||||
for(uint32_t i=0;i<swapchain->image_count;i++)
|
||||
{
|
||||
swapchain->sc_color[i]=tex_manager->CreateTexture2D(new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i]));
|
||||
|
||||
@ -177,7 +177,7 @@ bool SwapchainModule::CreateSwapchainRenderTarget()
|
||||
{
|
||||
GPUDevice *device=GetDevice();
|
||||
|
||||
DeviceQueue *q=device->CreateQueue(swapchain->color_count,false);
|
||||
DeviceQueue *q=device->CreateQueue(swapchain->image_count,false);
|
||||
Semaphore *render_complete_semaphore=device->CreateGPUSemaphore();
|
||||
Semaphore *present_complete_semaphore=device->CreateGPUSemaphore();
|
||||
|
||||
@ -235,4 +235,14 @@ void SwapchainModule::OnResize(const VkExtent2D &extent)
|
||||
CreateSwapchainRenderTarget();
|
||||
}
|
||||
|
||||
void SwapchainModule::Swap()
|
||||
{
|
||||
int index=swapchain_rt->AcquireNextImage();
|
||||
|
||||
if(index<0||index>=swapchain->image_count)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user