2020-01-20 15:02:40 +08:00
|
|
|
|
// 该范例主要用于测试gl_FragCoord值
|
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/math/Math.h>
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2021-11-30 15:01:55 +08:00
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=256;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=256;
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
|
|
|
|
constexpr uint32_t VERTEX_COUNT=4;
|
|
|
|
|
|
2022-02-22 20:53:39 +08:00
|
|
|
|
constexpr float position_data[VERTEX_COUNT][2]=
|
2020-01-20 15:02:40 +08:00
|
|
|
|
{
|
|
|
|
|
{0,0},
|
|
|
|
|
{SCREEN_WIDTH,0},
|
|
|
|
|
{0,SCREEN_HEIGHT},
|
|
|
|
|
{SCREEN_WIDTH,SCREEN_HEIGHT}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestApp:public VulkanApplicationFramework
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
|
2021-06-19 20:54:38 +08:00
|
|
|
|
MaterialInstance * material_instance =nullptr;
|
2022-06-24 21:06:38 +08:00
|
|
|
|
Renderable *renderable =nullptr;
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
Pipeline * pipeline =nullptr;
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool InitMaterial()
|
|
|
|
|
{
|
2020-09-21 12:37:44 +08:00
|
|
|
|
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/FragColor"));
|
|
|
|
|
|
|
|
|
|
if(!material_instance)
|
|
|
|
|
return(false);
|
2022-03-09 20:55:09 +08:00
|
|
|
|
|
|
|
|
|
BindCameraUBO(material_instance);
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
2021-09-22 17:22:17 +08:00
|
|
|
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::TriangleStrip);
|
|
|
|
|
|
|
|
|
|
return pipeline;
|
2020-01-20 15:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-21 12:37:44 +08:00
|
|
|
|
bool InitVBO()
|
2020-01-20 15:02:40 +08:00
|
|
|
|
{
|
2022-06-24 18:00:22 +08:00
|
|
|
|
auto primitive=db->CreatePrimitive(VERTEX_COUNT);
|
|
|
|
|
if(!primitive)return(false);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
2022-06-24 18:00:22 +08:00
|
|
|
|
if(!primitive->Set(VAN::Position,db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
|
renderable=db->CreateRenderable(primitive,material_instance,pipeline);
|
2020-09-21 12:37:44 +08:00
|
|
|
|
return(true);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool Init()
|
|
|
|
|
{
|
|
|
|
|
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!InitMaterial())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2020-09-21 12:37:44 +08:00
|
|
|
|
if(!InitVBO())
|
2020-01-20 15:02:40 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
|
BuildCommandBuffer(renderable);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Resize(int w,int h)override
|
|
|
|
|
{
|
2022-03-09 20:55:09 +08:00
|
|
|
|
VulkanApplicationFramework::Resize(w,h);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
|
BuildCommandBuffer(renderable);
|
2020-01-20 15:02:40 +08:00
|
|
|
|
}
|
|
|
|
|
};//class TestApp:public VulkanApplicationFramework
|
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
|
|
|
|
TestApp app;
|
|
|
|
|
|
|
|
|
|
if(!app.Init())
|
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
while(app.Run());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|