Fixed draw_triangle_in_NDC.cpp,can run.

This commit is contained in:
hyzboy 2025-02-01 15:40:35 +08:00
parent 0d67993326
commit 3807d9fcbf
3 changed files with 34 additions and 38 deletions

View File

@ -1,6 +1,6 @@
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include"VulkanAppFramework.h"
#include<hgl/WorkManager.h>
#include<hgl/math/HalfFloat.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/PrimitiveCreater.h>
@ -39,7 +39,8 @@ constexpr VkFormat PositionFormat=VF_V2F;
#ifdef USE_UNORM8_COLOR
constexpr uint8 color_data[VERTEX_COUNT*4]=
{ 255,0,0,255,
{
255,0,0,255,
0,255,0,255,
0,0,255,255
};
@ -47,7 +48,8 @@ constexpr uint8 color_data[VERTEX_COUNT*4]=
constexpr VkFormat ColorFormat=VF_V4UN8;
#else
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
{
1,0,0,1,
0,1,0,1,
0,0,1,1
};
@ -55,10 +57,12 @@ constexpr float color_data[VERTEX_COUNT*4]=
constexpr VkFormat ColorFormat=VF_V4F;
#endif//USE_UNORM8_COLOR
class TestApp:public VulkanApplicationFramework
class TestApp:public WorkObject
{
private:
Color4f clear_color=Color4f(0.2f,0.2f,0.2f,1.0f);
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
VILConfig vil_config;
#endif
@ -83,7 +87,7 @@ private:
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;
@ -105,54 +109,47 @@ private:
bool InitVBO()
{
PrimitiveCreater rpc(device,material_instance->GetVIL());
rpc.Init("Triangle",VERTEX_COUNT);
#ifdef USE_HALF_FLOAT_POSITION
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
#endif//USE_HALF_FLOAT_POSITION
if(!rpc.WriteVAB(VAN::Position, PositionFormat, position_data))return(false);
if(!rpc.WriteVAB(VAN::Color, ColorFormat, color_data ))return(false);
render_obj=db->CreateRenderable(&rpc,material_instance,pipeline);
render_obj=CreateRenderable("Triangle",VERTEX_COUNT,material_instance,pipeline,
{
{VAN::Position,PositionFormat,position_data},
{VAN::Color, ColorFormat, color_data}
});
return(render_obj);
}
public:
bool Init(uint w,uint h)
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
{
if(!VulkanApplicationFramework::Init(w,h))
return(false);
InitVIL();
if(!InitAutoMaterial())
return(false);
return;
if(!InitPipeline())
return(false);
return;
if(!InitVBO())
return(false);
if(!BuildCommandBuffer(render_obj))
return(false);
return(true);
return;
}
void Resize(uint w,uint h)override
void Tick(double)override{}
void Render(double delta_time,graph::RenderCmdBuffer *cmd)
{
VulkanApplicationFramework::Resize(w,h);
cmd->SetClearColor(0,clear_color);
BuildCommandBuffer(render_obj);
cmd->BeginRenderPass();
cmd->Render(render_obj);
cmd->EndRenderPass();
}
};//class TestApp:public VulkanApplicationFramework
};//class TestApp:public WorkObject
int main(int,char **)
int os_main(int,os_char **)
{
return RunApp<TestApp>(SCREEN_WIDTH,SCREEN_HEIGHT);
return RunFramework<TestApp>(OS_TEXT("RenderFramework Test"));
}

View File

@ -1,5 +1,4 @@
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
#include<hgl/WorkManager.h>
#include<hgl/WorkManager.h>
#include<hgl/graph/VKVertexInputConfig.h>
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/mtl/Material2DCreateConfig.h>
@ -21,7 +20,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
};
constexpr float color_data[VERTEX_COUNT*4]=
{ 1,0,0,1,
{
1,0,0,1,
0,1,0,1,
0,0,1,1
};

View File

@ -10,7 +10,7 @@
#include<hgl/graph/mtl/ShaderBuffer.h>
#include<hgl/graph/VKSamplerType.h>
namespace hgl{namespace graph
namespace hgl::graph
{
struct GPUDeviceAttribute;
struct UBODescriptor;
@ -92,5 +92,4 @@ namespace hgl{namespace graph
bool CreateShader();
};//class MaterialCreateInfo
}//namespace mtl
}//namespace graph
}//namespace hgl
}//namespace hgl::graph