2019-05-08 00:25:40 +08:00
|
|
|
|
#pragma once
|
2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/platform/Window.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKInstance.h>
|
|
|
|
|
#include<hgl/graph/VKPhysicalDevice.h>
|
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/VKSemaphore.h>
|
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKShaderModule.h>
|
|
|
|
|
#include<hgl/graph/VKImageView.h>
|
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
|
|
|
|
#include<hgl/graph/VKDescriptorSets.h>
|
|
|
|
|
#include<hgl/graph/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKFormat.h>
|
|
|
|
|
#include<hgl/graph/VKFramebuffer.h>
|
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
2021-06-16 11:43:19 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialParameters.h>
|
2021-06-16 20:29:25 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialInstance.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKRenderTarget.h>
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2019-06-11 23:14:13 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
|
|
|
|
class VulkanApplicationFramework
|
|
|
|
|
{
|
2019-06-11 16:18:49 +08:00
|
|
|
|
private:
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
Window * win =nullptr;
|
|
|
|
|
VulkanInstance * inst =nullptr;
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
void OnKeyPressed (KeyboardButton kb){key_status[kb]=true;}
|
|
|
|
|
void OnKeyReleased (KeyboardButton kb){key_status[kb]=false;}
|
|
|
|
|
void OnKeyRepeat (KeyboardButton kb){KeyRepeat(kb);}
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
uint mouse_key=0;
|
|
|
|
|
Vector2f mouse_pos;
|
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
void OnMousePressed (int,int,uint mk){mouse_key=mk;MousePressed(mk);}
|
|
|
|
|
void OnMouseReleased(int,int,uint mk){mouse_key=0;MouseReleased(mk);}
|
|
|
|
|
void OnMouseMove (int x,int y){mouse_pos.Set(x,y);MouseMove();}
|
|
|
|
|
void OnMouseWheel (int v,int h,uint mk){MouseWheel(v,h,mk);}
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2019-04-30 16:42:59 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
2020-10-21 12:52:32 +08:00
|
|
|
|
GPUDevice * device =nullptr;
|
2020-10-21 12:47:06 +08:00
|
|
|
|
SwapchainRenderTarget * sc_render_target =nullptr;
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2019-07-17 04:49:16 +08:00
|
|
|
|
protected:
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2020-10-21 12:52:32 +08:00
|
|
|
|
int32_t swap_chain_count =0;
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
RenderCmdBuffer ** cmd_buf =nullptr;
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2020-10-21 12:52:32 +08:00
|
|
|
|
Color4f clear_color;
|
2020-10-18 19:12:00 +08:00
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
2020-10-21 12:52:32 +08:00
|
|
|
|
RenderResource * db =nullptr;
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2020-10-21 12:52:32 +08:00
|
|
|
|
bool key_status[kbRangeSize];
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2019-04-30 16:42:59 +08:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
virtual ~VulkanApplicationFramework()
|
2019-06-11 23:14:13 +08:00
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(db);
|
|
|
|
|
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
|
|
|
|
|
2019-08-23 11:18:09 +08:00
|
|
|
|
SAFE_CLEAR(device);
|
2020-01-23 21:00:35 +08:00
|
|
|
|
SAFE_CLEAR(win);
|
2019-04-30 16:42:59 +08:00
|
|
|
|
SAFE_CLEAR(inst);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-14 17:13:30 +08:00
|
|
|
|
virtual bool Init(int w,int h)
|
2019-04-30 16:42:59 +08:00
|
|
|
|
{
|
2019-06-14 17:13:30 +08:00
|
|
|
|
hgl_zero(key_status);
|
|
|
|
|
|
2020-10-18 19:12:00 +08:00
|
|
|
|
clear_color.Zero();
|
|
|
|
|
|
2019-05-06 11:41:05 +08:00
|
|
|
|
#ifdef _DEBUG
|
2020-10-21 12:47:06 +08:00
|
|
|
|
if(!CheckStrideBytesByFormat())
|
2019-05-06 11:41:05 +08:00
|
|
|
|
return(false);
|
|
|
|
|
#endif//
|
|
|
|
|
|
2019-04-30 19:01:44 +08:00
|
|
|
|
InitNativeWindowSystem();
|
|
|
|
|
|
2020-10-28 17:28:07 +08:00
|
|
|
|
InitVulkanInstanceProperties();
|
2019-11-14 17:57:46 +08:00
|
|
|
|
|
2019-04-30 16:42:59 +08:00
|
|
|
|
win=CreateRenderWindow(OS_TEXT("VulkanTest"));
|
|
|
|
|
if(!win)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!win->Create(w,h))
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-11-14 17:57:46 +08:00
|
|
|
|
{
|
2020-10-21 12:52:32 +08:00
|
|
|
|
CreateInstanceLayerInfo cili;
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
2020-09-28 11:16:45 +08:00
|
|
|
|
hgl_zero(cili);
|
2019-11-14 17:57:46 +08:00
|
|
|
|
|
|
|
|
|
cili.lunarg.standard_validation = true;
|
|
|
|
|
cili.khronos.validation = true;
|
2021-06-22 21:33:47 +08:00
|
|
|
|
cili.RenderDoc.Capture = true;
|
2019-11-14 17:57:46 +08:00
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
inst=CreateInstance("VulkanTest",nullptr,&cili);
|
2019-11-14 17:57:46 +08:00
|
|
|
|
|
|
|
|
|
if(!inst)
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
2019-08-23 11:18:09 +08:00
|
|
|
|
device=CreateRenderDevice(inst,win);
|
2019-04-30 16:42:59 +08:00
|
|
|
|
|
|
|
|
|
if(!device)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
db=new RenderResource(device);
|
2019-06-13 20:36:12 +08:00
|
|
|
|
|
|
|
|
|
InitCommandBuffer();
|
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
SetEventCall(win->OnResize, this,VulkanApplicationFramework,OnResize );
|
|
|
|
|
SetEventCall(win->OnKeyPressed, this,VulkanApplicationFramework,OnKeyPressed );
|
|
|
|
|
SetEventCall(win->OnKeyReleased, this,VulkanApplicationFramework,OnKeyReleased );
|
|
|
|
|
SetEventCall(win->OnKeyRepeat, this,VulkanApplicationFramework,OnKeyRepeat );
|
2019-06-13 23:12:11 +08:00
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
SetEventCall(win->OnMousePressed, this,VulkanApplicationFramework,OnMousePressed );
|
|
|
|
|
SetEventCall(win->OnMouseReleased, this,VulkanApplicationFramework,OnMouseReleased );
|
|
|
|
|
SetEventCall(win->OnMouseMove, this,VulkanApplicationFramework,OnMouseMove );
|
|
|
|
|
SetEventCall(win->OnMouseWheel, this,VulkanApplicationFramework,OnMouseWheel );
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
2019-06-13 20:36:12 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2019-06-13 23:12:11 +08:00
|
|
|
|
virtual void Resize(int,int)=0;
|
2020-10-27 14:28:35 +08:00
|
|
|
|
virtual void KeyRepeat(KeyboardButton){}
|
|
|
|
|
virtual void MousePressed(uint){}
|
|
|
|
|
virtual void MouseReleased(uint){}
|
2019-06-14 19:56:21 +08:00
|
|
|
|
virtual void MouseMove(){}
|
2019-06-15 13:01:39 +08:00
|
|
|
|
virtual void MouseWheel(int,int,uint){}
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2020-10-26 22:16:38 +08:00
|
|
|
|
void SetClearColor(COLOR cc)
|
|
|
|
|
{
|
|
|
|
|
clear_color.Use(cc,1.0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-17 04:49:16 +08:00
|
|
|
|
void OnResize(int w,int h)
|
|
|
|
|
{
|
2019-08-23 11:18:09 +08:00
|
|
|
|
if(w>0&&h>0)
|
|
|
|
|
device->Resize(w,h);
|
|
|
|
|
|
2019-07-17 04:49:16 +08:00
|
|
|
|
InitCommandBuffer();
|
|
|
|
|
Resize(w,h);
|
|
|
|
|
}
|
2019-06-13 23:12:11 +08:00
|
|
|
|
|
2019-06-13 20:36:12 +08:00
|
|
|
|
void InitCommandBuffer()
|
|
|
|
|
{
|
|
|
|
|
if(cmd_buf)
|
2019-06-28 20:46:32 +08:00
|
|
|
|
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2019-07-17 04:49:16 +08:00
|
|
|
|
sc_render_target=device->GetSwapchainRT();
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2019-07-16 19:59:53 +08:00
|
|
|
|
swap_chain_count=sc_render_target->GetImageCount();
|
2019-06-13 20:36:12 +08:00
|
|
|
|
{
|
2019-07-16 19:59:53 +08:00
|
|
|
|
const VkExtent2D extent=sc_render_target->GetExtent();
|
2019-07-10 21:00:36 +08:00
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
cmd_buf=hgl_zero_new<RenderCmdBuffer *>(swap_chain_count);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2020-07-16 12:03:33 +08:00
|
|
|
|
for(int32_t i=0;i<swap_chain_count;i++)
|
2020-10-28 12:30:44 +08:00
|
|
|
|
cmd_buf[i]=device->CreateRenderCommandBuffer();
|
2019-06-13 20:36:12 +08:00
|
|
|
|
}
|
2019-04-30 16:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
bool BuildCommandBuffer(RenderCmdBuffer *cb,RenderPass *rp,Framebuffer *fb,RenderableInstance *ri)
|
2020-10-26 22:16:38 +08:00
|
|
|
|
{
|
|
|
|
|
if(!ri)return(false);
|
2020-10-17 22:13:08 +08:00
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
const IndexBuffer *ib=ri->GetIndexBuffer();
|
2020-10-17 22:13:08 +08:00
|
|
|
|
|
|
|
|
|
cb->Begin();
|
2020-10-26 22:16:38 +08:00
|
|
|
|
cb->BindFramebuffer(rp,fb);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
cb->SetClearColor(0,clear_color.r,clear_color.g,clear_color.b);
|
2020-10-30 18:59:58 +08:00
|
|
|
|
cb->BeginRenderPass();
|
2020-10-17 22:13:08 +08:00
|
|
|
|
cb->BindPipeline(ri->GetPipeline());
|
2021-06-16 20:29:25 +08:00
|
|
|
|
cb->BindDescriptorSets(ri);
|
2020-10-17 22:13:08 +08:00
|
|
|
|
cb->BindVAB(ri);
|
|
|
|
|
|
|
|
|
|
if (ib)
|
|
|
|
|
cb->DrawIndexed(ib->GetCount());
|
|
|
|
|
else
|
|
|
|
|
cb->Draw(ri->GetDrawCount());
|
|
|
|
|
|
|
|
|
|
cb->EndRenderPass();
|
|
|
|
|
cb->End();
|
2020-10-26 22:16:38 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
2020-10-17 22:13:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
void BuildCommandBuffer(RenderCmdBuffer *cb,RenderTarget *rt,RenderableInstance *ri)
|
2020-10-18 19:12:00 +08:00
|
|
|
|
{
|
2020-10-27 22:43:24 +08:00
|
|
|
|
if(!cb||!rt||!ri)
|
2020-10-26 22:16:38 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-10-27 22:43:24 +08:00
|
|
|
|
BuildCommandBuffer(cb,rt->GetRenderPass(),rt->GetFramebuffer(),ri);
|
2020-10-18 19:12:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 19:11:54 +08:00
|
|
|
|
bool BuildCommandBuffer(uint32_t index,RenderableInstance *ri)
|
|
|
|
|
{
|
|
|
|
|
if(!ri)return(false);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2020-10-26 22:16:38 +08:00
|
|
|
|
return BuildCommandBuffer(cmd_buf[index],sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index),ri);
|
2019-06-18 00:48:05 +08:00
|
|
|
|
}
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2020-10-24 19:11:54 +08:00
|
|
|
|
bool BuildCommandBuffer(RenderableInstance *ri)
|
2019-06-18 00:48:05 +08:00
|
|
|
|
{
|
2020-10-24 19:11:54 +08:00
|
|
|
|
if(!ri)return(false);
|
|
|
|
|
|
2020-07-16 12:03:33 +08:00
|
|
|
|
for(int32_t i=0;i<swap_chain_count;i++)
|
2020-09-21 19:05:25 +08:00
|
|
|
|
BuildCommandBuffer(i,ri);
|
2020-10-24 19:11:54 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 19:11:54 +08:00
|
|
|
|
bool BuildCurrentCommandBuffer(RenderableInstance *ri)
|
2019-06-11 23:14:13 +08:00
|
|
|
|
{
|
2020-10-24 19:11:54 +08:00
|
|
|
|
if(!ri)return(false);
|
|
|
|
|
|
|
|
|
|
return BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),ri);
|
2019-06-18 00:48:05 +08:00
|
|
|
|
}
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
void BuildCommandBuffer(uint32_t index,RenderList *rl)
|
|
|
|
|
{
|
2020-01-23 21:00:35 +08:00
|
|
|
|
if(!rl)return;
|
2019-06-18 00:48:05 +08:00
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
RenderCmdBuffer *cb=cmd_buf[index];
|
2019-06-18 00:48:05 +08:00
|
|
|
|
|
|
|
|
|
cb->Begin();
|
2020-10-28 12:30:44 +08:00
|
|
|
|
cb->BindFramebuffer(sc_render_target->GetRenderPass(),sc_render_target->GetFramebuffer(index));
|
|
|
|
|
cb->SetClearColor(0,clear_color.r,clear_color.g,clear_color.b);
|
2020-10-30 18:59:58 +08:00
|
|
|
|
cb->BeginRenderPass();
|
2020-10-28 12:30:44 +08:00
|
|
|
|
rl->Render(cb);
|
|
|
|
|
cb->EndRenderPass();
|
2019-06-18 00:48:05 +08:00
|
|
|
|
cb->End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuildCommandBuffer(RenderList *rl)
|
|
|
|
|
{
|
2020-07-16 12:03:33 +08:00
|
|
|
|
for(int32_t i=0;i<swap_chain_count;i++)
|
2019-06-18 00:48:05 +08:00
|
|
|
|
BuildCommandBuffer(i,rl);
|
|
|
|
|
}
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
void BuildCurrentCommandBuffer(RenderList *rl)
|
2020-01-23 21:00:35 +08:00
|
|
|
|
{
|
2019-07-16 19:59:53 +08:00
|
|
|
|
BuildCommandBuffer(sc_render_target->GetCurrentFrameIndices(),rl);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 18:11:39 +08:00
|
|
|
|
template<typename ...ARGS>
|
|
|
|
|
Pipeline *CreatePipeline(ARGS...args){return sc_render_target->CreatePipeline(args...);}
|
|
|
|
|
|
2019-06-11 23:14:13 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
int AcquireNextImage()
|
2019-06-11 23:14:13 +08:00
|
|
|
|
{
|
2020-10-18 13:55:12 +08:00
|
|
|
|
return sc_render_target->AcquireNextImage();
|
2019-06-18 00:48:05 +08:00
|
|
|
|
}
|
2019-06-11 23:14:13 +08:00
|
|
|
|
|
2019-07-16 21:32:29 +08:00
|
|
|
|
virtual void SubmitDraw(int index)
|
2019-06-18 00:48:05 +08:00
|
|
|
|
{
|
2019-06-15 22:02:20 +08:00
|
|
|
|
VkCommandBuffer cb=*cmd_buf[index];
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2020-10-18 13:55:12 +08:00
|
|
|
|
sc_render_target->Submit(cb);
|
|
|
|
|
sc_render_target->PresentBackbuffer();
|
|
|
|
|
sc_render_target->WaitQueue();
|
|
|
|
|
sc_render_target->WaitFence();
|
2019-06-11 23:14:13 +08:00
|
|
|
|
}
|
2019-05-04 16:52:44 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
virtual void Draw()
|
|
|
|
|
{
|
|
|
|
|
int index=AcquireNextImage();
|
|
|
|
|
|
2019-07-01 17:04:02 +08:00
|
|
|
|
if(index<0||index>=swap_chain_count)return;
|
2019-06-25 23:40:09 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
SubmitDraw(index);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 19:01:44 +08:00
|
|
|
|
bool Run()
|
2019-04-30 16:42:59 +08:00
|
|
|
|
{
|
2019-05-04 16:52:44 +08:00
|
|
|
|
if(!win->Update())return(false);
|
|
|
|
|
|
|
|
|
|
if(win->IsVisible())
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
return(true);
|
2019-04-30 16:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
};//class VulkanApplicationFramework
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2019-06-15 18:07:20 +08:00
|
|
|
|
class CameraAppFramework:public VulkanApplicationFramework
|
2019-06-14 17:13:30 +08:00
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
2021-05-13 17:34:40 +08:00
|
|
|
|
GPUBuffer * ubo_camera_info =nullptr;
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2021-05-13 17:34:40 +08:00
|
|
|
|
WalkerCamera * camera =nullptr;
|
|
|
|
|
float move_speed =1;
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2020-11-17 17:20:59 +08:00
|
|
|
|
Vector2f mouse_last_pos;
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
2019-06-14 17:13:30 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2020-11-17 17:20:59 +08:00
|
|
|
|
virtual ~CameraAppFramework()
|
|
|
|
|
{
|
2020-11-19 22:12:31 +08:00
|
|
|
|
SAFE_CLEAR(camera);
|
2020-11-17 17:20:59 +08:00
|
|
|
|
}
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
|
|
|
|
virtual bool Init(int w,int h)
|
|
|
|
|
{
|
|
|
|
|
if(!VulkanApplicationFramework::Init(w,h))
|
|
|
|
|
return(false);
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2019-06-16 02:58:12 +08:00
|
|
|
|
InitCamera(w,h);
|
2019-06-14 17:13:30 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 02:58:12 +08:00
|
|
|
|
virtual void InitCamera(int w,int h)
|
2019-06-14 17:13:30 +08:00
|
|
|
|
{
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera=new WalkerCamera;
|
|
|
|
|
|
|
|
|
|
camera->type=CameraType::Perspective;
|
|
|
|
|
camera->width=w;
|
|
|
|
|
camera->height=h;
|
|
|
|
|
camera->vp_width=w;
|
|
|
|
|
camera->vp_height=h;
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->pos=Vector4f(10,10,10,1);
|
|
|
|
|
camera->target=Vector4f(0,0,0,1);
|
2020-11-17 17:20:59 +08:00
|
|
|
|
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->Refresh(); //更新矩阵计算
|
2020-06-12 15:53:37 +08:00
|
|
|
|
|
2021-05-13 17:34:40 +08:00
|
|
|
|
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera->info);
|
2019-06-14 17:13:30 +08:00
|
|
|
|
}
|
2020-01-23 21:00:35 +08:00
|
|
|
|
|
2019-06-16 02:58:12 +08:00
|
|
|
|
void Resize(int w,int h)override
|
|
|
|
|
{
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->width=w;
|
|
|
|
|
camera->height=h;
|
2019-06-16 02:58:12 +08:00
|
|
|
|
}
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2021-05-25 11:48:20 +08:00
|
|
|
|
GPUBuffer *GetCameraInfoBuffer()
|
2019-06-14 17:13:30 +08:00
|
|
|
|
{
|
2021-05-13 17:34:40 +08:00
|
|
|
|
return ubo_camera_info;
|
2019-06-14 17:13:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
virtual void BuildCommandBuffer(uint32_t index)=0;
|
|
|
|
|
|
2019-06-14 20:01:46 +08:00
|
|
|
|
virtual void Draw()override
|
2019-06-14 17:13:30 +08:00
|
|
|
|
{
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->Refresh(); //更新相机矩阵
|
2021-05-13 17:34:40 +08:00
|
|
|
|
ubo_camera_info->Write(&camera->info); //写入缓冲区
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2019-07-11 02:42:11 +08:00
|
|
|
|
const uint32_t index=AcquireNextImage();
|
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
BuildCommandBuffer(index);
|
|
|
|
|
|
|
|
|
|
SubmitDraw(index);
|
2019-06-14 17:13:30 +08:00
|
|
|
|
|
2020-11-19 22:12:31 +08:00
|
|
|
|
if(key_status[kbW])camera->Up (move_speed);else
|
|
|
|
|
if(key_status[kbS])camera->Down (move_speed);else
|
|
|
|
|
if(key_status[kbA])camera->Left (move_speed);else
|
|
|
|
|
if(key_status[kbD])camera->Right (move_speed);else
|
|
|
|
|
if(key_status[kbR])camera->Forward (move_speed);else
|
|
|
|
|
if(key_status[kbF])camera->Backward (move_speed);else
|
|
|
|
|
|
|
|
|
|
if(key_status[kbLeft ])camera->HoriRotate( move_speed);else
|
|
|
|
|
if(key_status[kbRight ])camera->HoriRotate(-move_speed);else
|
|
|
|
|
if(key_status[kbUp ])camera->VertRotate( move_speed);else
|
|
|
|
|
if(key_status[kbDown ])camera->VertRotate(-move_speed);else
|
2019-06-14 17:13:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
virtual void KeyRepeat(KeyboardButton kb)override
|
2019-06-14 17:13:30 +08:00
|
|
|
|
{
|
2019-06-14 17:28:40 +08:00
|
|
|
|
if(kb==kbMinus)move_speed*=0.9f;else
|
|
|
|
|
if(kb==kbEquals)move_speed*=1.1f;else
|
2019-06-14 17:13:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
2020-10-27 14:28:35 +08:00
|
|
|
|
virtual void MousePressed(uint) override
|
2019-06-14 19:56:21 +08:00
|
|
|
|
{
|
|
|
|
|
mouse_last_pos=mouse_pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void MouseMove() override
|
|
|
|
|
{
|
2019-06-15 12:14:01 +08:00
|
|
|
|
if(!(mouse_key&(mbLeft|mbRight)))return;
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
|
|
|
|
Vector2f gap=mouse_pos-mouse_last_pos;
|
|
|
|
|
|
|
|
|
|
bool update=false;
|
2020-11-26 18:04:57 +08:00
|
|
|
|
if(gap.x!=0){update=true;if(mouse_key&mbLeft)camera->HoriRotate( gap.x/10.0f);else camera->WrapHoriRotate(gap.x);}
|
|
|
|
|
if(gap.y!=0){update=true;if(mouse_key&mbLeft)camera->VertRotate(-gap.y/10.0f);else camera->WrapVertRotate(gap.y);}
|
2019-06-14 19:56:21 +08:00
|
|
|
|
|
|
|
|
|
mouse_last_pos=mouse_pos;
|
|
|
|
|
}
|
2019-06-15 13:01:39 +08:00
|
|
|
|
|
|
|
|
|
virtual void MouseWheel(int v,int h,uint)
|
|
|
|
|
{
|
2020-11-19 22:12:31 +08:00
|
|
|
|
camera->Distance(1+(v/1000.0f));
|
2019-06-15 13:01:39 +08:00
|
|
|
|
}
|
2019-06-15 18:07:20 +08:00
|
|
|
|
};//class CameraAppFramework
|