add 2d AA Line examples
This commit is contained in:
parent
5844004489
commit
24474df151
@ -1 +1 @@
|
||||
Subproject commit 7d35df757f12b204fd4556669d10b131cc373e3d
|
||||
Subproject commit e15c5ce039e72b8cc8140b3d4ea363754a4490d7
|
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit a24e522ffed4553ec8ccba91e5047672b8a24fa8
|
||||
Subproject commit aa7e9a7effd6c830d52cb0ca043348ee6ffa6224
|
@ -1 +1 @@
|
||||
Subproject commit b1a5811e1d4e0d34c6b43d7ebee5fe04177bb2df
|
||||
Subproject commit 543cd58d70b60706c58b58ad9189249f27e1a63d
|
12
example/2dVector/CMakeLists.txt
Normal file
12
example/2dVector/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(WIN32)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/2dVector")
|
||||
endmacro()
|
||||
|
||||
CreateProject(00.line line.cpp)
|
160
example/2dVector/line.cpp
Normal file
160
example/2dVector/line.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
// 0.triangle
|
||||
// 该范例主要演示直接绘制一个渐变色的三角形
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<iostream>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
constexpr float vertex_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},
|
||||
{SCREEN_WIDTH*0.5, SCREEN_HEIGHT*0.25},
|
||||
};
|
||||
|
||||
static Vector4f color(1,1,1,1);
|
||||
|
||||
struct Line2DConfig
|
||||
{
|
||||
float width;
|
||||
float border;
|
||||
};
|
||||
|
||||
static Line2DConfig line_2d_config
|
||||
{
|
||||
10,
|
||||
2.5
|
||||
};
|
||||
|
||||
class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Camera cam;
|
||||
|
||||
vulkan::MaterialInstance * material_instance =nullptr;
|
||||
vulkan::RenderableInstance *render_instance =nullptr;
|
||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||
vulkan::Buffer * ubo_color_material =nullptr;
|
||||
vulkan::Buffer * ubo_line_config =nullptr;
|
||||
|
||||
vulkan::Pipeline * pipeline =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/Line2D"));
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=CreatePipeline(material_instance,OS_TEXT("res/pipeline/alpha2d"),Prim::LineStrip); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
vulkan::Buffer *CreateUBO(const AnsiString &name,const VkDeviceSize size,void *data)
|
||||
{
|
||||
vulkan::Buffer *ubo=db->CreateUBO(size,data);
|
||||
|
||||
if(!ubo)
|
||||
return(nullptr);
|
||||
|
||||
if(!material_instance->BindUBO(name,ubo))
|
||||
{
|
||||
std::cerr<<"Bind UBO<"<<name.c_str()<<"> to material failed!"<<std::endl;
|
||||
SAFE_CLEAR(ubo);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return ubo;
|
||||
}
|
||||
|
||||
bool InitUBO()
|
||||
{
|
||||
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||
|
||||
cam.width=extent.width;
|
||||
cam.height=extent.height;
|
||||
|
||||
cam.Refresh();
|
||||
|
||||
ubo_world_matrix =CreateUBO("world", sizeof(WorldMatrix), &cam.matrix);
|
||||
ubo_color_material =CreateUBO("color_material",sizeof(Vector4f), &color);
|
||||
ubo_line_config =CreateUBO("line2d_config", sizeof(Line2DConfig), &line_2d_config);
|
||||
|
||||
material_instance->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
vulkan::Renderable *render_obj=db->CreateRenderable(VERTEX_COUNT);
|
||||
if(!render_obj)return(false);
|
||||
|
||||
if(!render_obj->Set(VAN::Position, db->CreateVAB(VAF_VEC2,VERTEX_COUNT,vertex_data)))return(false);
|
||||
|
||||
render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline);
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(false);
|
||||
|
||||
if(!InitMaterial())
|
||||
return(false);
|
||||
|
||||
if(!InitUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
BuildCommandBuffer(render_instance);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
cam.width=w;
|
||||
cam.height=h;
|
||||
|
||||
cam.Refresh();
|
||||
|
||||
ubo_world_matrix->Write(&cam.matrix);
|
||||
|
||||
BuildCommandBuffer(render_instance);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
TestApp app;
|
||||
|
||||
if(!app.Init())
|
||||
return(-1);
|
||||
|
||||
while(app.Run());
|
||||
|
||||
return 0;
|
||||
}
|
@ -1 +1,4 @@
|
||||
add_subdirectory(Vulkan)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
|
||||
add_subdirectory(Vulkan)
|
||||
add_subdirectory(2dVector)
|
||||
|
12
example/GUI/CMakeLists.txt
Normal file
12
example/GUI/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} VulkanAppFramework.h)
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(WIN32)
|
||||
set_target_properties(${name} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ULRE_RUNTIME_PATH})
|
||||
ENDIF()
|
||||
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/GUI")
|
||||
endmacro()
|
||||
|
||||
CreateProject(00.align_test align_test.cpp)
|
@ -1,5 +1,5 @@
|
||||
macro(CreateProject name)
|
||||
add_executable(${name} ${ARGN} VulkanAppFramework.h)
|
||||
add_executable(${name} ${ARGN})
|
||||
target_link_libraries(${name} ${ULRE})
|
||||
|
||||
IF(WIN32)
|
||||
|
@ -101,12 +101,11 @@ private:
|
||||
|
||||
if(!material_instance->BindUBO(name,ubo))
|
||||
{
|
||||
std::cerr<<"Bind UBO<"<<name.c_str()<<"> to material failed!"<<std::endl;
|
||||
SAFE_CLEAR(ubo);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
db->Add(ubo);
|
||||
|
||||
return ubo;
|
||||
}
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include<hgl/graph/shader/ShaderMaker.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
using namespace hgl::graph::shader;
|
||||
|
||||
SHADER_NAMESPACE_BEGIN
|
||||
bool CreateDefaultMaterial();
|
||||
SHADER_NAMESPACE_END
|
||||
|
||||
int main()
|
||||
{
|
||||
CreateDefaultMaterial();
|
||||
|
||||
return 0;
|
||||
}
|
2
res
2
res
@ -1 +1 @@
|
||||
Subproject commit dd74b5a9b179a3f0202d1cd60fbeaf5851cc173f
|
||||
Subproject commit bab8e14717bf63dfc01a84e49d46bae9332b2ed1
|
Loading…
x
Reference in New Issue
Block a user