added third_triangle example
This commit is contained in:
parent
80b89b3d21
commit
ea93dfcc86
@ -12,6 +12,7 @@ endmacro()
|
||||
|
||||
CreateProject("Basic" 1st_triangle first_triangle.cpp)
|
||||
CreateProject("Basic" 2nd_triangle second_triangle.cpp)
|
||||
CreateProject("Basic" 3rd_triangle third_triangle.cpp)
|
||||
CreateProject("Basic" FragCoord FragCoordTest.cpp)
|
||||
CreateProject("Basic" indices_rect indices_rect.cpp)
|
||||
CreateProject("Basic" FullScreenTriangle FullScreenTriangle.cpp)
|
||||
@ -29,7 +30,7 @@ CreateProject("Tile" DrawText DrawText.cpp)
|
||||
CreateProject("Geometry3D " Geometry3D Geometry3D.cpp)
|
||||
|
||||
CreateProject("Scene" SceneTree SceneTree.cpp)
|
||||
#CreateProject(09.LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
|
||||
#CreateProject("Scene" LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
|
||||
CreateProject("Scene" InlineGeometryScene InlineGeometryScene.cpp)
|
||||
|
||||
CreateProject("Scene/Sky" SkyColor SkyColor.cpp)
|
||||
@ -39,7 +40,7 @@ CreateProject("Advanced Rendering" OffscreenRender OffscreenRender.cpp)
|
||||
|
||||
#CreateProject(12.PBRBasic PBRBasic.cpp)
|
||||
#CreateProject(12.Deferred Deferred.cpp)
|
||||
CreateProject("AdvancedRendering" DeferredRender DeferredRender.cpp)
|
||||
CreateProject("Advanced Rendering" DeferredRender DeferredRender.cpp)
|
||||
#CreateProject(14.AutoMaterial auto_material.cpp)
|
||||
|
||||
CreateProject("Texture" Cubemap Cubemap.cpp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// first_triangle
|
||||
// 该范例主要演示直接绘制一个渐变色的三角形
|
||||
// 该范例主要演示使用NDC坐标系直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
@ -16,9 +16,9 @@ constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75}
|
||||
{ 0.0, -0.5},
|
||||
{-0.5, 0.5},
|
||||
{ 0.5, 0.5}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
@ -40,12 +40,10 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
@ -1,9 +1,10 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用场景树系统绘制三角形
|
||||
// third_triangle
|
||||
// 该范例主要演示使用2D坐系统直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/SceneInfo.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -30,9 +31,6 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
RenderableInstance *render_instance =nullptr;
|
||||
|
||||
@ -51,10 +49,10 @@ private:
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Renderable *render_obj=db->CreateRenderable(VERTEX_COUNT);
|
||||
@ -64,37 +62,24 @@ private:
|
||||
if(!render_obj->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
|
||||
|
||||
render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(scale(0.5,0.5),render_instance);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
if(!BuildCommandBuffer(render_instance))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -103,7 +88,7 @@ public:
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
BuildCommandBuffer(render_instance);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
|
120
example/Vulkan/third_triangle.cpp
Normal file
120
example/Vulkan/third_triangle.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
// second_triangle
|
||||
// 该范例主要演示使用场景树系统绘制三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float position_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
|
||||
};
|
||||
|
||||
constexpr float color_data[VERTEX_COUNT][4]=
|
||||
{ {1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
RenderableInstance *render_instance =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2D"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
BindCameraUBO(material_instance);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
Renderable *render_obj=db->CreateRenderable(VERTEX_COUNT);
|
||||
if(!render_obj)return(false);
|
||||
|
||||
if(!render_obj->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!render_obj->Set(VAN::Color, db->CreateVBO(VF_V4F,VERTEX_COUNT,color_data)))return(false);
|
||||
|
||||
render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline);
|
||||
|
||||
render_root.CreateSubNode(render_instance);
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
|
||||
render_list->Expend(GetCameraInfo(),&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(render_list);
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_list);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user