Merge branch 'devel_8_scenegraph' of https://github.com/hyzboy/ULRE into devel_8_scenegraph

This commit is contained in:
hyzboy 2019-05-24 23:51:53 +08:00
commit ceb7f6cdbf
40 changed files with 757 additions and 195 deletions

View File

@ -4,9 +4,9 @@
// 二、试验动态合并材质渲染机制、包括普通合并与Instance
#include"VulkanAppFramework.h"
#include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/InlineGeometry.h>
#include<hgl/type/ResManage.h>
using namespace hgl;
using namespace hgl::graph;
@ -22,87 +22,92 @@ struct WorldConfig
Matrix4f mvp;
}world;
struct RectangleCreateInfo
{
RectScope2f scope;
vec3<float> normal;
Color4f color;
RectScope2f tex_coord;
};
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
vulkan::Renderable *render_obj=mtl->CreateRenderable();
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding!=-1)
{
VB2f *vertex=new VB2f(6);
vertex->Begin();
vertex->WriteRect(rci->scope);
vertex->End();
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
}
const int normal_binding=vsm->GetStageInputBinding("Normal");
if(normal_binding!=-1)
{
VB3f *normal=new VB3f(6);
normal->Begin();
normal->Write(rci->normal,6);
normal->End();
render_obj->Set(normal_binding,device->CreateVBO(normal));
delete normal;
}
const int color_binding=vsm->GetStageInputBinding("Color");
if(color_binding!=-1)
{
VB4f *color=new VB4f(6);
color->Begin();
color->Write(rci->color,6);
color->End();
render_obj->Set(color_binding,device->CreateVBO(color));
delete color;
}
const int tex_coord_binding=vsm->GetStageInputBinding("TexCoord");
if(tex_coord_binding!=-1)
{
VB2f *tex_coord=new VB2f(6);
tex_coord->Begin();
tex_coord->WriteRect(rci->tex_coord);
tex_coord->End();
render_obj->Set(tex_coord_binding,device->CreateVBO(tex_coord));
delete tex_coord;
}
return render_obj;
}
VK_NAMESPACE_BEGIN
//using MaterialID=int;
//using PipelineID=int;
//using DescriptorSetsID=int;
//using RenderableID=int;
//
///**
// * 场景DB用于管理场景内所需的所有数据
// */
//class SceneDatabase
//{
// IDResManage<MaterialID, Material> rm_material; ///<材质合集
// IDResManage<PipelineID, Pipeline> rm_pipeline; ///<管线合集
// IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
// IDResManage<RenderableID, Renderable> rm_renderable; ///<可渲染对象合集
//
//public:
//
// MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
// PipelineID Add(Pipeline * p ){return rm_pipeline.Add(p);}
// DescriptorSetsID Add(DescriptorSets *ds ){return rm_desc_sets.Add(ds);}
// RenderableID Add(Renderable * r ){return rm_renderable.Add(r);}
//};//class SceneDatabase
/**
*
* @param r
* @param rp
*
*/
//Mesh *CreateRoundrectangle(float l,float t,float w,float h,float r,uint32_t rp)
//{
//}
class RenderableInstance
{
Pipeline * pipeline;
DescriptorSets * desc_sets;
Renderable * render_obj;
public:
RenderableInstance(Pipeline *p,DescriptorSets *ds,Renderable *r):pipeline(p),desc_sets(ds),render_obj(r){}
virtual ~RenderableInstance()
{
}
Pipeline * GetPipeline (){return pipeline;}
DescriptorSets *GetDescriptorSets (){return desc_sets;}
Renderable * GetRenderable (){return render_obj;}
const int Comp(const RenderableInstance *ri)const
{
//绘制顺序:
// ARM Mali GPU : 不透明、AlphaTest、半透明
// Adreno/NV/AMD: AlphaTest、不透明、半透明
// PowerVR: 同Adreno/NV/AMD但不透明部分可以不排序
if(pipeline->IsAlphaBlend())
{
if(!ri->pipeline->IsAlphaBlend())
return 1;
}
else
{
if(ri->pipeline->IsAlphaBlend())
return -1;
}
if(pipeline->IsAlphaTest())
{
if(!ri->pipeline->IsAlphaTest())
return 1;
}
else
{
if(ri->pipeline->IsAlphaTest())
return -1;
}
if(pipeline!=ri->pipeline)
return pipeline-ri->pipeline;
if(desc_sets!=ri->desc_sets)
return desc_sets-ri->desc_sets;
return render_obj-ri->render_obj;
}
CompOperator(const RenderableInstance *,Comp)
};//class RenderableInstance
VK_NAMESPACE_END
class TestApp:public VulkanApplicationFramework
{
@ -111,8 +116,10 @@ private:
uint swap_chain_count=0;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * desciptor_sets =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
vulkan::RenderableInstance *render_instance =nullptr;
vulkan::Buffer * ubo_mvp =nullptr;
vulkan::Pipeline * pipeline =nullptr;
@ -125,13 +132,14 @@ public:
~TestApp()
{
SAFE_CLEAR(render_instance);
SAFE_CLEAR(color_buffer);
SAFE_CLEAR(vertex_buffer);
SAFE_CLEAR_OBJECT_ARRAY(cmd_buf,swap_chain_count);
SAFE_CLEAR(pipeline);
SAFE_CLEAR(ubo_mvp);
SAFE_CLEAR(render_obj);
SAFE_CLEAR(desciptor_sets);
SAFE_CLEAR(descriptor_sets);
SAFE_CLEAR(material);
}
@ -144,17 +152,37 @@ private:
if(!material)
return(false);
desciptor_sets=material->CreateDescriptorSets();
descriptor_sets=material->CreateDescriptorSets();
return(true);
}
bool CreateRenderObject()
{
struct RectangleCreateInfo rci;
//struct RectangleCreateInfo rci;
rci.scope.Set(10,10,10,10);
//rci.scope.Set(10,10,10,10);
render_obj=CreateRectangle(device,material,&rci);
//render_obj=CreateRectangle(device,material,&rci);
//struct RoundRectangleCreateInfo rrci;
//rrci.scope.Set(10,10,SCREEN_WIDTH-20,SCREEN_HEIGHT-20);
//rrci.radius=8; //半径为8
//rrci.round_per=8; //圆角切分成8段
//render_obj=CreateRoundRectangle(device,material,&rrci);
struct CircleCreateInfo cci;
cci.center.x=SCREEN_WIDTH/2;
cci.center.y=SCREEN_HEIGHT/2;
cci.radius.x=SCREEN_WIDTH*0.45;
cci.radius.y=SCREEN_HEIGHT*0.45;
cci.field_count=8;
render_obj=CreateCircle(device,material,&cci);
return render_obj;
}
@ -170,10 +198,10 @@ private:
if(!ubo_mvp)
return(false);
if(!desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
if(!descriptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
return(false);
desciptor_sets->Update();
descriptor_sets->Update();
return(true);
}
@ -186,7 +214,7 @@ private:
pipeline_creater->SetDepthTest(false);
pipeline_creater->SetDepthWrite(false);
pipeline_creater->CloseCullFace();
pipeline_creater->Set(PRIM_TRIANGLES);
pipeline_creater->Set(PRIM_TRIANGLE_FAN);
pipeline=pipeline_creater->Create();
@ -196,6 +224,27 @@ private:
return pipeline;
}
void Draw(vulkan::CommandBuffer *cb,vulkan::RenderableInstance *ri)
{
cb->Bind(ri->GetPipeline());
cb->Bind(ri->GetDescriptorSets());
vulkan::Renderable *obj=ri->GetRenderable();
cb->Bind(obj);
const vulkan::IndexBuffer *ib=obj->GetIndexBuffer();
if(ib)
{
cb->DrawIndexed(ib->GetCount());
}
else
{
cb->Draw(obj->GetDrawCount());
}
}
bool InitCommandBuffer()
{
cmd_buf=hgl_zero_new<vulkan::CommandBuffer *>(swap_chain_count);
@ -209,10 +258,7 @@ private:
cmd_buf[i]->Begin();
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
cmd_buf[i]->Bind(pipeline);
cmd_buf[i]->Bind(desciptor_sets);
cmd_buf[i]->Bind(render_obj);
cmd_buf[i]->Draw(6);
Draw(cmd_buf[i],render_instance);
cmd_buf[i]->EndRenderPass();
cmd_buf[i]->End();
}
@ -241,6 +287,8 @@ public:
if(!InitPipeline())
return(false);
render_instance=new vulkan::RenderableInstance(pipeline,descriptor_sets,render_obj);
if(!InitCommandBuffer())
return(false);

View File

@ -40,7 +40,7 @@ private:
uint swap_chain_count=0;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * desciptor_sets =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
vulkan::Buffer * ubo_mvp =nullptr;
@ -60,7 +60,7 @@ public:
SAFE_CLEAR(pipeline);
SAFE_CLEAR(ubo_mvp);
SAFE_CLEAR(render_obj);
SAFE_CLEAR(desciptor_sets);
SAFE_CLEAR(descriptor_sets);
SAFE_CLEAR(material);
}
@ -73,8 +73,8 @@ private:
if(!material)
return(false);
render_obj=material->CreateRenderable();
desciptor_sets=material->CreateDescriptorSets();
render_obj=material->CreateRenderable(VERTEX_COUNT);
descriptor_sets=material->CreateDescriptorSets();
return(true);
}
@ -89,10 +89,10 @@ private:
if(!ubo_mvp)
return(false);
if(!desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
if(!descriptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
return(false);
desciptor_sets->Update();
descriptor_sets->Update();
return(true);
}
@ -136,7 +136,7 @@ private:
cmd_buf[i]->Begin();
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
cmd_buf[i]->Bind(pipeline);
cmd_buf[i]->Bind(desciptor_sets);
cmd_buf[i]->Bind(descriptor_sets);
cmd_buf[i]->Bind(render_obj);
cmd_buf[i]->DrawIndexed(INDEX_COUNT);
cmd_buf[i]->EndRenderPass();

View File

@ -41,7 +41,7 @@ private:
uint swap_chain_count=0;
vulkan::Material * material =nullptr;
vulkan::DescriptorSets * desciptor_sets =nullptr;
vulkan::DescriptorSets * descriptor_sets =nullptr;
vulkan::Renderable * render_obj =nullptr;
vulkan::Buffer * ubo_mvp =nullptr;
@ -61,7 +61,7 @@ public:
SAFE_CLEAR(pipeline);
SAFE_CLEAR(ubo_mvp);
SAFE_CLEAR(render_obj);
SAFE_CLEAR(desciptor_sets);
SAFE_CLEAR(descriptor_sets);
SAFE_CLEAR(material);
}
@ -74,8 +74,8 @@ private:
if(!material)
return(false);
render_obj=material->CreateRenderable();
desciptor_sets=material->CreateDescriptorSets();
render_obj=material->CreateRenderable(VERTEX_COUNT);
descriptor_sets=material->CreateDescriptorSets();
return(true);
}
@ -90,10 +90,10 @@ private:
if(!ubo_mvp)
return(false);
if(!desciptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
if(!descriptor_sets->BindUBO(material->GetUBO("world"),*ubo_mvp))
return(false);
desciptor_sets->Update();
descriptor_sets->Update();
return(true);
}
@ -150,7 +150,7 @@ private:
cmd_buf[i]->Begin();
cmd_buf[i]->BeginRenderPass(device->GetRenderPass(),device->GetFramebuffer(i));
cmd_buf[i]->Bind(pipeline);
cmd_buf[i]->Bind(desciptor_sets);
cmd_buf[i]->Bind(descriptor_sets);
cmd_buf[i]->Bind(render_obj);
cmd_buf[i]->Draw(VERTEX_COUNT);
cmd_buf[i]->EndRenderPass();

View File

@ -93,7 +93,7 @@ private:
if(!material)
return(false);
render_obj=material->CreateRenderable();
render_obj=material->CreateRenderable(VERTEX_COUNT);
desciptor_sets=material->CreateDescriptorSets();
texture=vulkan::LoadTGATexture(OS_TEXT("lena.tga"),device);

View File

@ -0,0 +1,9 @@
#ifndef HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE
#define HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE
#include<hgl/type/BaseString.h>
namespace hgl
{
}//namespace hgl
#endif//HGL_FILESYSTEM_ASSET_MANAGE_INCLUDE

View File

@ -0,0 +1,45 @@
#ifndef HGL_GRAPH_INLINE_GEOMETRY_INCLUDE
#define HGL_GRAPH_INLINE_GEOMETRY_INCLUDE
#include<hgl/graph/vulkan/VK.h>
#include<hgl/math/Vector.h>
#include<hgl/type/RectScope.h>
namespace hgl
{
namespace graph
{
/**
*
*/
struct RectangleCreateInfo
{
RectScope2f scope;
};
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci);
/**
*
*/
struct RoundRectangleCreateInfo:public RectangleCreateInfo
{
float radius; //圆角半径
uint32_t round_per; //圆角精度
};
vulkan::Renderable *CreateRoundRectangle(vulkan::Device *device,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci);
/**
*
*/
struct CircleCreateInfo
{
Vector2f center; //圆心坐标
Vector2f radius; //半径
uint field_count; //分段次数
};
vulkan::Renderable *CreateCircle(vulkan::Device *device,vulkan::Material *mtl,const CircleCreateInfo *rci);
}//namespace graph
};//namespace hgl
#endif//HGL_GRAPH_INLINE_GEOMETRY_INCLUDE

View File

@ -3,22 +3,24 @@
#include<hgl/type/List.h>
#include<hgl/graph/SceneOrient.h>
#include<hgl/graph/vulkan/VK.h>
namespace hgl
{
namespace graph
{
using namespace vulkan;
class SceneNode;
struct Camera;
class Frustum;
class Renderable;
typedef List<const SceneNode *> RenderList; ///<渲染列表类型重定义
using RenderList=List<const SceneNode *>; ///<渲染列表类型重定义
typedef float (*RenderListCompFunc)(Camera *,SceneNode *,SceneNode *); ///<渲染列表排序比较函数
using RenderListCompFunc=float (*)(Camera *,SceneNode *,SceneNode *); ///<渲染列表排序比较函数
float CameraLengthComp(Camera *,SceneNode *,SceneNode *); ///<摄像机距离比较函数
typedef bool (*FilterSceneNodeFunc)(const SceneNode *,void *); ///<场景节点过滤函数重定义
using FilterSceneNodeFunc=bool (*)(const SceneNode *,void *); ///<场景节点过滤函数重定义
bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截减过滤函数
@ -40,7 +42,7 @@ namespace hgl
public:
List<Renderable *> SubData; ///<可渲染数据
List<RenderableInstance *> SubData; ///<可渲染数据
ObjectList<SceneNode> SubNode; ///<子节点
public:
@ -52,7 +54,7 @@ namespace hgl
ClearRenderable();
}
void Add(Renderable *r){if(r)SubData.Add(r);} ///<增加一个可渲染数据
void Add(RenderableInstance *r){if(r)SubData.Add(r);} ///<增加一个可渲染数据
void ClearRenderable(){SubData.Clear();} ///<清除可渲染数据
void AddSubNode(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点
@ -63,7 +65,7 @@ namespace hgl
return sn;
}
SceneNode * AddSubNode(Renderable *r,const Matrix4f &m)
SceneNode * AddSubNode(RenderableInstance *r,const Matrix4f &m)
{
if(!r)return(nullptr);

View File

@ -14,7 +14,7 @@ namespace hgl
/**
*
*/
template<typename T,int C> class VertexBuffer:public VertexBufferCreater
template<typename T,int C> class VertexBufferBase:public VertexBufferCreater
{
protected:
@ -25,7 +25,7 @@ namespace hgl
public:
VertexBuffer(uint32_t _size,const T *_data=nullptr):VertexBufferCreater(_size,C,sizeof(T))
VertexBufferBase(uint32_t _size,const T *_data=nullptr):VertexBufferCreater(_size,C,sizeof(T))
{
mem_type=(T *)GetData();
access=0;
@ -35,7 +35,7 @@ namespace hgl
memcpy(mem_type,_data,total_bytes);
}
virtual ~VertexBuffer()=default;
virtual ~VertexBufferBase()=default;
/**
*
@ -111,11 +111,11 @@ namespace hgl
/**
*
*/
template<typename T> class VertexBuffer1:public VertexBuffer<T,1>
template<typename T> class VertexBuffer1:public VertexBufferBase<T,1>
{
public:
using VertexBuffer<T,1>::VertexBuffer;
using VertexBufferBase<T,1>::VertexBufferBase;
virtual ~VertexBuffer1()=default;
VkFormat GetDataType()const override;
@ -154,11 +154,11 @@ namespace hgl
/**
*
*/
template<typename T> class VertexBuffer2:public VertexBuffer<T,2>
template<typename T> class VertexBuffer2:public VertexBufferBase<T,2>
{
public:
using VertexBuffer<T,2>::VertexBuffer;
using VertexBufferBase<T,2>::VertexBufferBase;
virtual ~VertexBuffer2()=default;
VkFormat GetDataType()const override;
@ -348,16 +348,64 @@ namespace hgl
scope.GetRightBottom(),
scope.GetLeftBottom());
}
template<typename V>
bool WriteRectFan(const RectScope2<V> &scope)
{
if(!this->access||this->access+8>this->mem_end)
{
LOG_HINT(OS_TEXT("VertexBuffer2::WriteRectFan(RectScope2 *) out"));
return(false);
}
*this->access++=scope.GetLeft();
*this->access++=scope.GetTop();
*this->access++=scope.GetRight();
*this->access++=scope.GetTop();
*this->access++=scope.GetRight();
*this->access++=scope.GetBottom();
*this->access++=scope.GetLeft();
*this->access++=scope.GetBottom();
return(true);
}
template<typename V>
bool WriteRectTriangleStrip(const RectScope2<V> &scope)
{
if(!this->access||this->access+8>this->mem_end)
{
LOG_HINT(OS_TEXT("VertexBuffer2::WriteRectTriangleStrip(RectScope2 *) out"));
return(false);
}
*this->access++=scope.GetLeft();
*this->access++=scope.GetTop();
*this->access++=scope.GetLeft();
*this->access++=scope.GetBottom();
*this->access++=scope.GetRight();
*this->access++=scope.GetTop();
*this->access++=scope.GetRight();
*this->access++=scope.GetBottom();
return(true);
}
};//class VertexBuffer2
/**
*
*/
template<typename T> class VertexBuffer3:public VertexBuffer<T,3>
template<typename T> class VertexBuffer3:public VertexBufferBase<T,3>
{
public:
using VertexBuffer<T,3>::VertexBuffer;
using VertexBufferBase<T,3>::VertexBufferBase;
virtual ~VertexBuffer3()=default;
VkFormat GetDataType()const override;
@ -593,11 +641,11 @@ namespace hgl
/**
*
*/
template<typename T> class VertexBuffer4:public VertexBuffer<T,4>
template<typename T> class VertexBuffer4:public VertexBufferBase<T,4>
{
public:
using VertexBuffer<T,4>::VertexBuffer;
using VertexBufferBase<T,4>::VertexBufferBase;
virtual ~VertexBuffer4()=default;
VkFormat GetDataType()const override;

View File

@ -49,6 +49,7 @@ class DescriptorSets;
class VertexAttributeBinding;
class Renderable;
class RenderableInstance;
using CharPointerList=hgl::List<const char *>;

View File

@ -57,7 +57,7 @@ public:
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
Renderable *CreateRenderable();
Renderable *CreateRenderable(const uint32_t draw_count);
};//class Material
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INCLUDE

View File

@ -1,6 +1,7 @@
#pragma once
#include<hgl/graph/vulkan/VK.h>
#include<hgl/type/BaseString.h>
VK_NAMESPACE_BEGIN
struct PhysicalDevice
@ -9,6 +10,7 @@ struct PhysicalDevice
VkPhysicalDevice physical_device=nullptr;
VkPhysicalDeviceFeatures features;
VkPhysicalDeviceProperties properties;
VkPhysicalDeviceDriverPropertiesKHR driver_properties;
VkPhysicalDeviceMemoryProperties memory_properties;
List<VkLayerProperties> layer_properties;
List<VkExtensionProperties> extension_properties;
@ -18,11 +20,16 @@ public:
PhysicalDevice(VkInstance,VkPhysicalDevice);
~PhysicalDevice()=default;
const bool CheckMemoryType(uint32_t,VkFlags,uint32_t *)const;
const bool CheckMemoryType(uint32_t,VkFlags,uint32_t *)const;
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
VkPhysicalDeviceType GetDeviceType()const{return properties.deviceType;}
const char * GetDeviceName()const{return properties.deviceName;}
const char *GetDeviceName()const{return properties.deviceName;}
const uint32_t GetExtensionSpecVersion(const UTF8String &name)const;
const VkDriverIdKHR GetDriverId ()const{return driver_properties.driverID;}
const char * GetDriverName ()const{return driver_properties.driverName;}
const char * GetDriverInfo ()const{return driver_properties.driverInfo;}
/**
* »ñÈ¡¸ÃÉ豸ÊÇ·ñÊÇÏÔ¿¨

View File

@ -4,17 +4,25 @@
#include<hgl/graph/vulkan/VK.h>
#include<hgl/io/DataOutputStream.h>
VK_NAMESPACE_BEGIN
using PipelineID=uint64;
class Pipeline
{
VkDevice device;
VkPipeline pipeline;
bool alpha_test;
bool alpha_blend;
public:
Pipeline(VkDevice dev,VkPipeline p){device=dev;pipeline=p;}
Pipeline(VkDevice dev,VkPipeline p,bool at,bool ab):device(dev),pipeline(p),alpha_test(at),alpha_blend(ab){}
virtual ~Pipeline();
operator VkPipeline(){return pipeline;}
const bool IsAlphaTest()const{return alpha_test;}
const bool IsAlphaBlend()const{return alpha_blend;}
};//class GraphicsPipeline
constexpr size_t MAX_SAMPLE_MASK_COUNT=(VK_SAMPLE_COUNT_64_BIT+31)/32;
@ -54,6 +62,9 @@ class PipelineCreater
void InitDynamicState();
float alpha_test=0;
bool alpha_blend=false;
public:
PipelineCreater(Device *dev,const Material *,RenderPass *rp,const VkExtent2D &);
@ -66,6 +77,8 @@ public:
void SetDepthRange( float min_depth,float max_depth){viewport.minDepth=min_depth;viewport.maxDepth=max_depth;}
void SetScissor( float l,float t,float w,float h){scissor.offset.x=l;scissor.offset.y=t;scissor.extent.width=w;scissor.extent.height=h;}
void SetAlphaTest( const float at) {alpha_test=at;}
void SetDepthTest( bool dt) {depthStencilState.depthTestEnable=dt;}
void SetDepthWrite( bool dw) {depthStencilState.depthWriteEnable=dw;}
@ -115,6 +128,9 @@ public:
colorBlendAttachments.Add(*cba);
colorBlending.attachmentCount=colorBlendAttachments.GetCount();
if(cba->blendEnable)
alpha_blend=true;
}
bool SetBlend(uint index,bool blend)
@ -125,6 +141,22 @@ public:
cba->blendEnable=blend;
if(blend)
alpha_blend=true;
else
{
cba=colorBlendAttachments.GetData();
for(int i=0;i<colorBlendAttachments.GetCount();i++)
if(cba->blendEnable)
{
alpha_blend=true;
return(true);
}
alpha_blend=false;
}
return(true);
}

View File

@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_RENDERABLE_INCLUDE
#include<hgl/graph/vulkan/VK.h>
#include<hgl/graph/vulkan/VKBuffer.h>
#include<hgl/type/BaseString.h>
VK_NAMESPACE_BEGIN
/**
@ -17,14 +18,27 @@ class Renderable
VkBuffer *buf_list=nullptr;
VkDeviceSize *buf_offset=nullptr;
uint32_t draw_count;
IndexBuffer *indices_buffer=nullptr;
VkDeviceSize indices_offset=0;
protected:
friend class RenderableInstance;
uint ref_count=0;
uint RefInc(){return ++ref_count;}
uint RefDec(){return --ref_count;}
public:
Renderable(const VertexShaderModule *);
Renderable(const VertexShaderModule *,const uint32_t dc);
virtual ~Renderable();
const uint GetRefCount()const{return ref_count;}
bool Set(const int stage_input_binding, VertexBuffer *vb,VkDeviceSize offset=0);
bool Set(const UTF8String &name, VertexBuffer *vb,VkDeviceSize offset=0);
@ -39,6 +53,14 @@ public:
public:
const uint32_t GetDrawCount ()const ///<取得当前对象绘制需要多少个顶点
{
if(indices_buffer)
return indices_buffer->GetCount();
return draw_count;
}
const int GetBufferCount ()const{return buf_count;}
const VkBuffer * GetBuffer ()const{return buf_list;}
const VkDeviceSize * GetOffset ()const{return buf_offset;}

View File

@ -56,7 +56,7 @@ namespace hgl
return(in?in->ReadFully(buf,size):-1);
}
virtual int64 Seek(int64 offset,SeekOrigin so=soBegin)
virtual int64 Seek(int64 offset,SeekOrigin so=SeekOrigin::Begin)
{
return(in?in->Seek(offset,so):-1);
}

View File

@ -50,7 +50,7 @@ namespace hgl
return(out?out->WriteFully(buf,size):-1);
}
virtual int64 Seek(int64 offset,SeekOrigin so=soBegin)
virtual int64 Seek(int64 offset,SeekOrigin so=SeekOrigin::Begin)
{
return(out?out->Seek(offset,so):-1);
}

View File

@ -64,7 +64,7 @@ namespace hgl
virtual bool CanRestart()const{return CanSeek();} ///<文件是否可复位访问
virtual bool CanSize()const{return(true);} ///<文件是否可取得长度
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<定位访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<定位访问指针
virtual int64 Tell()const; ///<取得访问指针位置
virtual int64 GetSize(); ///<取得文件长度
virtual bool Restart(); ///<复位访问指针

View File

@ -39,7 +39,7 @@ namespace hgl
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize()const; ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
virtual int64 Available()const; ///<剩下的可以不受阻塞访问的字节数

View File

@ -41,7 +41,7 @@ namespace hgl
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize()const; ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
virtual int64 Available()const{return -1;} ///<可不受影响写入的字节数
virtual int64 Write(int64,const void *,int64); ///<在指定位置写入指定长度的数据

View File

@ -29,7 +29,7 @@ namespace hgl
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Skip(int64)=0; ///<跳过指定字节不访问
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得流长度
virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数

View File

@ -115,19 +115,19 @@ namespace hgl
int64 Skip(int64 bytes)
{
return Seek(bytes,soCurrent);
return Seek(bytes,SeekOrigin::Current);
}
int64 Seek(int64 off,SeekOrigin so)
{
if(!CanSeek())return(-1);
if(so==soCurrent)
if(so==SeekOrigin::Current)
{
off+=cur_pos;
}
else
if(so==soEnd)
if(so==SeekOrigin::End)
{
off+=buf_size;
}

View File

@ -194,16 +194,16 @@ namespace hgl
return(true);
}
int64 Seek(int64 off,SeekOrigin so=soBegin) override
int64 Seek(int64 off,SeekOrigin so=SeekOrigin::Begin) override
{
if(!CanSeek())return(-1);
if(so==soCurrent)
if(so==SeekOrigin::Current)
{
off+=cur_pos;
}
else
if(so==soEnd)
if(so==SeekOrigin::End)
{
off+=buf_size;
}

View File

@ -26,7 +26,7 @@ namespace hgl
virtual bool CanSize()const=0; ///<是否可以取得尺寸
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得流长度
virtual int64 Available()const=0; ///<剩下的可以不受阻塞写入的字节数

View File

@ -40,7 +40,7 @@ namespace hgl
virtual int64 Tell()const; ///<取当前位置
virtual int64 GetSize(); ///<取得文件长度
virtual bool Restart(); ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin); ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin); ///<移动访问指针
};//class RandomAccessFile
}//namespace io
}//namespace hgl

View File

@ -1,4 +1,4 @@
#ifndef HGL_IO_SEEK_ACCESS_INCLUDE
#ifndef HGL_IO_SEEK_ACCESS_INCLUDE
#define HGL_IO_SEEK_ACCESS_INCLUDE
#include<hgl/type/DataType.h>
@ -6,11 +6,11 @@ namespace hgl
{
namespace io
{
enum_int(SeekOrigin) /// 资源偏移方向枚举
enum class SeekOrigin /// 资源偏移方向枚举
{
soBegin=0, ///<从资源最开始处开始offset必须大于0。移到资源的offset位置
soCurrent, ///<从资源当前位置开始移到资源的Position+offset位置
soEnd ///<从资源的结束位置开始offset必须小于0表示结束前的字符数
Begin=0, ///<从资源最开始处开始offset必须大于0。移到资源的offset位置
Current, ///<从资源当前位置开始移到资源的Position+offset位置
End ///<从资源的结束位置开始offset必须小于0表示结束前的字符数
};//enum SeekOrigin
/**
@ -27,7 +27,7 @@ namespace hgl
virtual bool CanSize()const=0; ///<是否可以取得尺寸
virtual bool Restart()=0; ///<复位访问指针
virtual int64 Seek(int64,SeekOrigin=soBegin)=0; ///<移动访问指针
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
virtual int64 Tell()const=0; ///<返回当前访问位置
virtual int64 GetSize()const=0; ///<取得文件长度
};//class SeekAccess

View File

@ -79,22 +79,11 @@ namespace hgl
{
ResItem *obj=items.GetItem(index);
//items[index]->count++;
obj->count++;
++obj->count;
// return(items[index]->data);
return obj->right;
}
T *data=Create(flag);
if(data)
{
items.Add(flag,data);
return(data);
}
return(nullptr);
}

View File

@ -31,7 +31,6 @@ namespace hgl
protected:
virtual T *Create(const F &)=0; ///<资源创建虚拟函数无实现,请特例化实现
virtual void Clear(T *obj){delete obj;} ///<资源释放虚拟函数(缺省为直接delete对象)
public:
@ -45,11 +44,33 @@ namespace hgl
virtual bool Add(const F &,T *); ///<添加一个数据
virtual T * Find(const F &); ///<查找一个数据
virtual T * Get(const F &); ///<取得一个数据,如不存在则创建
virtual T * Get(const F &); ///<取得一个数据
virtual void Release(const F &,bool zero_clear=false); ///<释放一个数据
virtual void Release(T *,bool zero_clear=false); ///<释放一个数据
};//template<typename F,typename T> class ResManage
/**
* 使int类做数标致的资源管理器
*/
template<typename F,typename T> class IDResManage:public ResManage<F,T>
{
F id_count=0;
public:
using ResManage<F,T>::ResManage;
virtual ~IDResManage()=default;
virtual F Add(T *value)
{
if(!value)return(-1);
if(!ResManage<F,T>::Add(id_count,value))
return(-1);
return id_count++;
}
};//template<typename F,typename T> class IDResManage:public ResManage<F,T>
}//namespace hgl
#include<hgl/type/ResManage.cpp>
#endif//HGL_RES_MANAGE_INCLUDE

View File

@ -109,7 +109,7 @@ namespace hgl
{
if(!CanSeek())return(-1);
return hgl_lseek64(fp,offset,orign);
return hgl_lseek64(fp,offset,(int)orign);
}
int64 FileAccess::Tell()const
@ -142,7 +142,7 @@ namespace hgl
{
if(!CanRestart())return(false);
return(Seek(0,soBegin)==0);
return(Seek(0,SeekOrigin::Begin)==0);
}
int64 FileAccess::Read(void *buf,int64 size)
@ -159,7 +159,7 @@ namespace hgl
int result=hgl_read64(fp,buf,size);
if(result>0)
hgl_lseek64(fp,-result,soCurrent); //回移这个长度
hgl_lseek64(fp,-result,(int)SeekOrigin::Current); //回移这个长度
return result;
}

View File

@ -52,7 +52,7 @@ namespace hgl
bool FileInputStream::CanSize ()const {return file?file->CanSize():false;}
bool FileInputStream::CanPeek ()const {return file?file->CanPeek():false;}
int64 FileInputStream::Skip (int64 bytes) {return file?file->Seek(bytes,soCurrent):-1;}
int64 FileInputStream::Skip (int64 bytes) {return file?file->Seek(bytes,SeekOrigin::Current):-1;}
int64 FileInputStream::Tell ()const {return file?file->Tell():-1;}
int64 FileInputStream::GetSize ()const {return file?file->GetSize():-1;}
bool FileInputStream::Restart () {return file?file->Restart():false;}

View File

@ -0,0 +1,109 @@
#include<hgl/filesystem/AssetManage.h>
#include<hgl/io/InputStream.h>
#include<android/asset_manager.h>
#include<android/asset_manager_jni.h>
namespace hgl
{
namespace
{
static AAssetManager *asset_manager=nullptr;
class AndroidAssetInputStream:public io::InputStream
{
AAsset *asset;
public:
AndroidAssetInputStream(AAsset *a)
{
asset=a;
}
~AndroidAssetInputStream()
{
Close();
}
void Close() override
{
if(!asset)return;
AAsset_close(asset);
asset=nullptr;
}
int64 Read(void *data,int64 size) override
{
return AAsset_read(asset,data,size);
}
int64 Peek(void *data,int64 size) override
{
int64 left=Avaiable();
if(left<size)
size=left;
int64 result=Read(data,size);
if(result>0)
Seek(-result,SeekOrigin::Current);
return result;
}
int64 ReadFully(void *buf,int64 buf_size){return Read(buf,buf_size);} ///<充分读取,保证读取到指定长度的数据(不计算超时)
bool CanRestart()const override{return(true);}
bool CanSeek()const override{return(true);}
bool CanSize()const override{return(true);}
bool CanPeek()const override{return(false);}
bool Restart() override
{
Seek(0,soBegin);
return(true);
}
int64 Skip(int64 size) override
{
return Seek(size,SeekOrigin::Current);
}
int64 Seek(int64 offset,SeekOrigin so) override
{
return AAsset_seek64(asset,offset,(int)so);
}
int64 Tell()const override
{
return Seek(0,SeekOrigin::Current);
}
int64 GetSize()const override
{
return AAsset_getLength64(asset);
}
int64 Available()const override
{
return AAsset_getRemainingLength64(asset);
}
};//class AndroidAssetInputStream:public io::InputStream
}//namespace
void InitAssetManager(AAssetManager *am)
{
asset_manager=am;
}
io::InputStream *OpenAsset(const UTF8String &filename)
{
AAsset *asset = AAssetManager_open(asset_manager, filename.c_str(), AASSET_MODE_BUFFER);
if(!asset)return(nullptr);
return(new AndroidAssetInputStream(asset));
}
}//namespace hgl

View File

@ -18,7 +18,8 @@
Android/NativeActivitySupport.cpp)
SET(PLATFORM_FILE_SOURCE ${PLATFORM_FILE_SOURCE}
Android/ProgramPath.cpp)
Android/ProgramPath.cpp
Android/AssetManage.cpp)
SET(PLATFORM_MULTI_THREAD_SOURCE ${PLATFORM_MULTI_THREAD_SOURCE}
UNIX/Semaphore.cpp)

View File

@ -49,7 +49,7 @@ namespace hgl
{
if(!CanRead())return(-1);
if(_lseeki64(fp,offset,soBegin)==offset)
if(_lseeki64(fp,offset,(int)SeekOrigin::Begin)==offset)
return _read(fp,buf,size);
else
return -1;
@ -59,7 +59,7 @@ namespace hgl
{
if(!CanWrite())return(-1);
if(_lseeki64(fp,offset,soBegin)==offset)
if(_lseeki64(fp,offset,(int)SeekOrigin::Begin)==offset)
return _write(fp,buf,size);
else
return -1;

View File

@ -41,6 +41,8 @@ bool PipelineCreater::SaveToStream(io::DataOutputStream *dos)
for(uint32_t i=0;i<pipelineInfo.pColorBlendState->attachmentCount;i++)
WRITE_AND_CHECK_SIZE(pipelineInfo.pColorBlendState->pAttachments+i,VkPipelineColorBlendAttachmentState);
if(!dos->WriteFloat(alpha_test))return(false);
return(true);
}
@ -89,16 +91,29 @@ bool PipelineCreater::LoadFromMemory(uchar *data,uint size)
if(size<colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState))
return(false);
VkPipelineColorBlendAttachmentState *cba=(VkPipelineColorBlendAttachmentState *)data;
colorBlendAttachments.SetCount(colorBlending.attachmentCount);
memcpy(colorBlendAttachments.GetData(),data,colorBlending.attachmentCount*sizeof(VkPipelineColorBlendAttachmentState));
colorBlending.pAttachments=colorBlendAttachments.GetData();
for(uint i=0;i<colorBlending.attachmentCount;i++)
{
if(cba->blendEnable)
alpha_blend=true;
++cba;
}
}
else
{
colorBlending.pAttachments=nullptr;
alpha_blend=false;
}
CHECK_SIZE_AND_COPY(alpha_test,float);
return(true);
}
VK_NAMESPACE_END

View File

@ -3,6 +3,10 @@
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
#include<hgl/graph/vulkan/VKFramebuffer.h>
#ifdef _DEBUG
#include<iostream>
#endif//_DEBUG
VK_NAMESPACE_BEGIN
namespace
{
@ -300,6 +304,24 @@ namespace
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,VkSurfaceKHR surface,uint width,uint height)
{
#ifdef _DEBUG
{
const VkDriverIdKHR driver_id=physical_device->GetDriverId();
if(driver_id>=VK_DRIVER_ID_BEGIN_RANGE_KHR
&&driver_id<=VK_DRIVER_ID_END_RANGE_KHR)
{
std::cout<<"DriverID: "<<physical_device->GetDriverId()<<std::endl;
std::cout<<"DriverName: "<<physical_device->GetDriverName()<<std::endl;
std::cout<<"DriverInfo: "<<physical_device->GetDriverInfo()<<std::endl;
}
else
{
std::cout<<"Unknow VideoCard Driver"<<std::endl;
}
}
#endif//_DEBUG
DeviceAttribute *attr=new DeviceAttribute(inst,physical_device,surface);
AutoDelete<DeviceAttribute> auto_delete(attr);

View File

@ -117,8 +117,8 @@ void Material::Write(VkPipelineVertexInputStateCreateInfo &vis)const
return vab->Write(vis);
}
Renderable *Material::CreateRenderable()
Renderable *Material::CreateRenderable(const uint32_t draw_count)
{
return(new Renderable(vertex_sm));
return(new Renderable(vertex_sm,draw_count));
}
VK_NAMESPACE_END

View File

@ -6,10 +6,6 @@ PhysicalDevice::PhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
instance=inst;
physical_device=pd;
vkGetPhysicalDeviceFeatures(physical_device,&features);
vkGetPhysicalDeviceProperties(physical_device,&properties);
vkGetPhysicalDeviceMemoryProperties(physical_device,&memory_properties);
{
uint32_t property_count;
@ -31,6 +27,49 @@ PhysicalDevice::PhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
debug_out(extension_properties);
}
vkGetPhysicalDeviceFeatures(physical_device,&features);
vkGetPhysicalDeviceMemoryProperties(physical_device,&memory_properties);
PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2=nullptr;
if(GetExtensionSpecVersion(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2KHR)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2KHR");
if(!GetPhysicalDeviceProperties2)
if(GetExtensionSpecVersion(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME))
GetPhysicalDeviceProperties2=(PFN_vkGetPhysicalDeviceProperties2)vkGetInstanceProcAddr(instance,"vkGetPhysicalDeviceProperties2");
if(GetPhysicalDeviceProperties2)
{
VkPhysicalDeviceProperties2KHR properties2;
GetPhysicalDeviceProperties2(physical_device,&properties2);
hgl_cpy(properties,properties2.properties);
if(properties2.pNext)
memcpy(&driver_properties,properties2.pNext,sizeof(VkPhysicalDeviceDriverPropertiesKHR));
}
else
{
vkGetPhysicalDeviceProperties(physical_device,&properties);
hgl_zero(driver_properties);
}
}
const uint32_t PhysicalDevice::GetExtensionSpecVersion(const UTF8String &name)const
{
const uint count=extension_properties.GetCount();
const VkExtensionProperties *ep=extension_properties.GetData();
for(uint i=0;i<count;i++)
{
if(name.Comp(ep->extensionName)==0)
return ep->specVersion;
}
return 0;
}
const bool PhysicalDevice::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex)const

View File

@ -147,6 +147,8 @@ PipelineCreater::PipelineCreater(Device *dev,const Material *material,RenderPass
colorBlendAttachments.Add(cba);
alpha_blend=false;
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlending.pNext = nullptr;
colorBlending.flags = 0;
@ -231,6 +233,6 @@ Pipeline *PipelineCreater::Create()
if (vkCreateGraphicsPipelines(device, cache, 1, &pipelineInfo, nullptr, &graphicsPipeline) != VK_SUCCESS)
return(nullptr);
return(new Pipeline(device,graphicsPipeline));
return(new Pipeline(device,graphicsPipeline,alpha_test>0,alpha_blend));
}
VK_NAMESPACE_END

View File

@ -3,9 +3,10 @@
#include<hgl/graph/vulkan/VKShaderModule.h>
VK_NAMESPACE_BEGIN
Renderable::Renderable(const VertexShaderModule *vsm)
Renderable::Renderable(const VertexShaderModule *vsm,const uint32_t dc)
{
vertex_sm=vsm;
draw_count=dc;
buf_count=vertex_sm->GetAttrCount();

View File

@ -4,13 +4,15 @@ SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/AABox.h
${ROOT_INCLUDE_PATH}/hgl/graph/SceneNode.h
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBufferCreater.h
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h)
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h)
SET(SCENE_GRAPH_SOURCE AABox.cpp
Camera.cpp
# RenderList.cpp
RenderList.cpp
SceneNode.cpp
SceneOrient.cpp)
SceneOrient.cpp
InlineGeometry.cpp)
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})

View File

@ -0,0 +1,148 @@
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKMaterial.h>
#include<hgl/graph/vulkan/VKRenderable.h>
#include<hgl/graph/vulkan/VKShaderModule.h>
namespace hgl
{
namespace graph
{
vulkan::Renderable *CreateRectangle(vulkan::Device *device,vulkan::Material *mtl,const RectangleCreateInfo *rci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding==-1)
return(nullptr);
VB2f *vertex=new VB2f(4);
vertex->Begin();
vertex->WriteRectFan(rci->scope);
vertex->End();
vulkan::Renderable *render_obj=mtl->CreateRenderable(vertex->GetCount());
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
return render_obj;
}
vulkan::Renderable *CreateRoundRectangle(vulkan::Device *device,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
vulkan::Renderable *render_obj=nullptr;
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding==-1)
return(nullptr);
VB2f *vertex=nullptr;
if(rci->radius==0||rci->round_per<=1) //这是要画矩形
{
vertex=new VB2f(4);
vertex->Begin();
vertex->WriteRectFan(rci->scope);
vertex->End();
}
else
{
float radius=rci->radius;
if(radius>rci->scope.GetWidth()/2.0f)radius=rci->scope.GetWidth()/2.0f;
if(radius>rci->scope.GetHeight()/2.0f)radius=rci->scope.GetHeight()/2.0f;
vertex=new VB2f(rci->round_per*4);
vertex->Begin();
vec2<float> *coord=new vec2<float>[rci->round_per];
for(uint i=0;i<rci->round_per;i++)
{
float ang=float(i)/float(rci->round_per-1)*90.0f;
float x=sin(hgl_ang2rad(ang))*radius;
float y=cos(hgl_ang2rad(ang))*radius;
coord[i].x=x;
coord[i].y=y;
//右上角
vertex->Write( rci->scope.GetRight()-radius+x,
rci->scope.GetTop()+radius-y);
}
//右下角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetRight() -radius+coord[rci->round_per-1-i].x,
rci->scope.GetBottom()-radius+coord[rci->round_per-1-i].y);
}
//左下角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetLeft() +radius-coord[i].x,
rci->scope.GetBottom()-radius+coord[i].y);
}
//左上角
for(uint i=0;i<rci->round_per;i++)
{
vertex->Write(rci->scope.GetLeft() +radius-coord[rci->round_per-1-i].x,
rci->scope.GetTop() +radius-coord[rci->round_per-1-i].y);
}
delete[] coord;
vertex->End();
}
render_obj=mtl->CreateRenderable(vertex->GetCount());
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
return render_obj;
}
vulkan::Renderable *CreateCircle(vulkan::Device *device,vulkan::Material *mtl,const CircleCreateInfo *cci)
{
const vulkan::VertexShaderModule *vsm=mtl->GetVertexShaderModule();
const int vertex_binding=vsm->GetStageInputBinding("Vertex");
if(vertex_binding==-1)
return(nullptr);
VB2f *vertex=new VB2f(cci->field_count+2);
vertex->Begin();
vertex->Write(cci->center.x,cci->center.y);
for(uint i=0;i<=cci->field_count;i++)
{
float ang=float(i)/float(cci->field_count)*360.0f;
float x=cci->center.x+sin(hgl_ang2rad(ang))*cci->radius.x;
float y=cci->center.y+cos(hgl_ang2rad(ang))*cci->radius.y;
vertex->Write(x,y);
}
vertex->End();
vulkan::Renderable *render_obj=mtl->CreateRenderable(vertex->GetCount());
render_obj->Set(vertex_binding,device->CreateVBO(vertex));
delete vertex;
return render_obj;
}
}//namespace graph
}//namespace hgl

View File

@ -1,31 +1,30 @@
#include<hgl/graph/Camera.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/Renderable.h>
#include<hgl/graph/vulkan/VKRenderable.h>
#include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/Render.h>
//#include<hgl/graph/Frustum.h>
#include<hgl/algorithm/VectorMath.h>
#include<hgl/math/Math.h>
namespace hgl
{
namespace graph
{
/* float CameraLengthComp(Camera *cam,SceneNode *obj_one,SceneNode *obj_two)
float CameraLengthComp(Camera *cam,SceneNode *obj_one,SceneNode *obj_two)
{
if(!cam||!obj_one||!obj_two)
return(0);
return( length_squared(obj_one->GetCenter(),cam->eye)-
return( length_squared(obj_one->GetCenter(),cam->eye)-
length_squared(obj_two->GetCenter(),cam->eye));
}
bool FrustumClipFilter(const SceneNode *node,void *fc)
{
if(!node||!fc)return(false);
//bool FrustumClipFilter(const SceneNode *node,void *fc)
//{
// if(!node||!fc)return(false);
return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
}*/
// return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
//}
/**
* 使
@ -47,7 +46,7 @@ namespace hgl
const Matrix4f fin_mv=(*mv)*(*node)->GetLocalToWorldMatrix();
int sn=(*node)->SubData.GetCount();
Renderable **p=(*node)->SubData.GetData();
RenderableInstance **p=(*node)->SubData.GetData();
for(int j=0;j<sn;j++)
{