将CreateRenderDevice转移到Window类中,并记录device,以方便在RESIZE等时重建SwapChain
This commit is contained in:
parent
1ee9eef78c
commit
d2cad7bf2f
@ -36,7 +36,6 @@ public:
|
||||
virtual ~VulkanApplicationFramework()
|
||||
{
|
||||
SAFE_CLEAR(shader_manage);
|
||||
SAFE_CLEAR(device);
|
||||
SAFE_CLEAR(inst);
|
||||
SAFE_CLEAR(win);
|
||||
}
|
||||
@ -62,7 +61,7 @@ public:
|
||||
if(!inst)
|
||||
return(false);
|
||||
|
||||
device=inst->CreateRenderDevice(win);
|
||||
device=win->CreateRenderDevice(inst);
|
||||
|
||||
if(!device)
|
||||
return(false);
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include<hgl/type/List.h>
|
||||
#include<vulkan/vulkan.h>
|
||||
#include<iostream>
|
||||
#include"VKFormat.h"
|
||||
#include"VKPrimivate.h"
|
||||
#include<hgl/graph/vulkan/VKFormat.h>
|
||||
#include<hgl/graph/vulkan/VKPrimivate.h>
|
||||
|
||||
#define VK_NAMESPACE hgl::graph::vulkan
|
||||
#define VK_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace vulkan{
|
||||
@ -13,6 +13,32 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class Instance;
|
||||
struct PhysicalDevice;
|
||||
class Device;
|
||||
class ImageView;
|
||||
class Framebuffer;
|
||||
|
||||
class Buffer;
|
||||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
|
||||
class CommandBuffer;
|
||||
class RenderPass;
|
||||
class Fence;
|
||||
class Semaphore;
|
||||
|
||||
class ShaderModule;
|
||||
class ShaderModuleManage;
|
||||
class VertexShaderModule;
|
||||
class Material;
|
||||
class PipelineLayout;
|
||||
class Pipeline;
|
||||
class DescriptorSets;
|
||||
class VertexAttributeBinding;
|
||||
|
||||
class Renderable;
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_BUFFER_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct VulkanBuffer
|
||||
|
@ -1,22 +1,22 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_BUFFER_DATA_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_BUFFER_DATA_INCLUDE
|
||||
#define HGL_GRAPH_BUFFER_DATA_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 缓冲区数据管理类
|
||||
* 缓冲区数据管理类
|
||||
*/
|
||||
class BufferData
|
||||
{
|
||||
protected:
|
||||
|
||||
VkFormat format; ///<数据格式
|
||||
VkFormat format; ///<数据格式
|
||||
|
||||
uint32_t count; ///<数据个数
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
uint32_t count; ///<数据个数
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
|
||||
uint8_t * buffer_data; ///<缓冲区数据
|
||||
uint32_t total_bytes; ///<数据总字节数
|
||||
uint8_t * buffer_data; ///<缓冲区数据
|
||||
uint32_t total_bytes; ///<数据总字节数
|
||||
|
||||
protected:
|
||||
|
||||
@ -37,10 +37,10 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
virtual ~BufferData()=default;
|
||||
|
||||
uint GetStride ()const { return data_stride; } ///<取得每一组数据字节数
|
||||
uint32_t GetCount ()const { return data_count; } ///<取得数据数量
|
||||
uint32_t GetTotalBytes ()const { return total_bytes; } ///<取得数据总字节数
|
||||
void * GetData ()const { return buffer_data; } ///<取得数据指针
|
||||
uint GetStride ()const { return data_stride; } ///<取得每一组数据字节数
|
||||
uint32_t GetCount ()const { return data_count; } ///<取得数据数量
|
||||
uint32_t GetTotalBytes ()const { return total_bytes; } ///<取得数据总字节数
|
||||
void * GetData ()const { return buffer_data; } ///<取得数据指针
|
||||
};//class BufferData
|
||||
|
||||
BufferData *CreateBufferData(const uint32_t &length);
|
||||
@ -58,8 +58,8 @@ VK_NAMESPACE_BEGIN
|
||||
#define DATA_COMPOMENT_DEPTH 0x10
|
||||
|
||||
/**
|
||||
* 非打包型数据<Br>
|
||||
* 该类数据未被打包,所以可以直接对成份数据逐一访问
|
||||
* 非打包型数据<Br>
|
||||
* 该类数据未被打包,所以可以直接对成份数据逐一访问
|
||||
*/
|
||||
class BufferDataDirect:public BufferData
|
||||
{
|
||||
@ -67,15 +67,15 @@ VK_NAMESPACE_BEGIN
|
||||
};//
|
||||
|
||||
/**
|
||||
* 打包型数据<Br>
|
||||
* 该类数据由于被打包,所以无法直接进行读写
|
||||
* 打包型数据<Br>
|
||||
* 该类数据由于被打包,所以无法直接进行读写
|
||||
*/
|
||||
class BufferDataPack:public BufferData
|
||||
{
|
||||
VkFormat format; ///<数据格式
|
||||
uint byte; ///<单个数据字节数
|
||||
VkFormat format; ///<数据格式
|
||||
uint byte; ///<单个数据字节数
|
||||
|
||||
uint compoment; ///<数据成份
|
||||
uint compoment; ///<数据成份
|
||||
|
||||
public:
|
||||
|
||||
@ -84,13 +84,13 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
class VertexBufferData:public BufferData
|
||||
{
|
||||
uint32_t data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
uint data_comp; ///<数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
uint32_t data_type; ///<单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
uint data_bytes; ///<单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
uint data_comp; ///<数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
|
||||
uint data_stride; ///<每组数据字节数
|
||||
uint data_stride; ///<每组数据字节数
|
||||
|
||||
uint32_t data_count; ///<数据数量
|
||||
uint32_t data_count; ///<数据数量
|
||||
|
||||
protected:
|
||||
|
||||
@ -111,31 +111,31 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
virtual ~VertexBufferData()=default;
|
||||
|
||||
uint32_t GetDataType ()const{return data_type;} ///<取得数据类型
|
||||
uint GetComponent ()const{return data_comp;} ///<取数每一组数据中的数据数量
|
||||
uint GetStride ()const{return data_stride;} ///<取得每一组数据字节数
|
||||
uint32_t GetDataType ()const{return data_type;} ///<取得数据类型
|
||||
uint GetComponent ()const{return data_comp;} ///<取数每一组数据中的数据数量
|
||||
uint GetStride ()const{return data_stride;} ///<取得每一组数据字节数
|
||||
|
||||
uint32_t GetCount ()const{return data_count;} ///<取得数据数量
|
||||
uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据总字节数
|
||||
uint32_t GetCount ()const{return data_count;} ///<取得数据数量
|
||||
uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据总字节数
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建一个顶点数据缓冲区<br>
|
||||
* 这种方式创建的缓冲区,它会自行分配内存,最终释放
|
||||
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
* @param count 数据数量
|
||||
* 创建一个顶点数据缓冲区<br>
|
||||
* 这种方式创建的缓冲区,它会自行分配内存,最终释放
|
||||
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
* @param count 数据数量
|
||||
*/
|
||||
VertexBufferData *CreateVertexBufferData(const uint32_t &dt,const uint &dbytes,const uint &dcm,const uint32_t &count);
|
||||
|
||||
/**
|
||||
* 创建一个顶点数据缓冲区
|
||||
* @param data 数据指针
|
||||
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
* @param count 数据数量
|
||||
* 创建一个顶点数据缓冲区
|
||||
* @param data 数据指针
|
||||
* @param dt 单个数据类型 (GL_BYTE,GL_UNSIGNED_SHORT,GL_FLOAT等)
|
||||
* @param dbytes 单个数据字节数 (GL_BYTE为1,GL_UNSIGNED_SHORT为2,GL_FLOAT为4等)
|
||||
* @param dcm 数据成员数 (1/2/3/4,如2D纹理坐标用2,3D坐标/法线用3)
|
||||
* @param count 数据数量
|
||||
*/
|
||||
VertexBufferData *CreateVertexBufferData(void *data,const uint32_t &dt,const uint &dbytes,const uint &dcm,const uint32_t &count);
|
||||
|
||||
@ -143,8 +143,8 @@ VK_NAMESPACE_BEGIN
|
||||
inline VertexBufferData *VB##comp_count##short_name(const uint32_t &count){return CreateVertexBufferData(vk_type,sizeof(type),comp_count,count);} \
|
||||
inline VertexBufferData *VB##comp_count##short_name(const uint32_t &count,const type *data){return CreateVertexBufferData((void *)data,vk_type,sizeof(type),comp_count,count);}
|
||||
|
||||
// UNORM 指输入无符号数,自动转换为 0.0 to 1.0 的浮点数
|
||||
// SNORM 指输入有符号数,自动转换为-1.0 to +1.0 的浮点数
|
||||
// UNORM 指输入无符号数,自动转换为 0.0 to 1.0 的浮点数
|
||||
// SNORM 指输入有符号数,自动转换为-1.0 to +1.0 的浮点数
|
||||
|
||||
|
||||
|
||||
|
@ -1,14 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderPass;
|
||||
class Framebuffer;
|
||||
class Pipeline;
|
||||
class DescriptorSets;
|
||||
class Renderable;
|
||||
|
||||
class CommandBuffer
|
||||
{
|
||||
VkDevice device;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_DESCRIPTOR_SETS_LAYOUT_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||
#ifndef HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||
#define HGL_GRAPH_RENDER_SURFACE_INCLUDE
|
||||
|
||||
#include<hgl/type/List.h>
|
||||
@ -10,21 +10,6 @@
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct PhysicalDevice;
|
||||
class Buffer;
|
||||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
class CommandBuffer;
|
||||
class RenderPass;
|
||||
class Fence;
|
||||
class Semaphore;
|
||||
class ShaderModule;
|
||||
class ShaderModuleManage;
|
||||
class VertexShaderModule;
|
||||
class Material;
|
||||
|
||||
#define MAX_FRAMES_IN_FLIGHT 2
|
||||
|
||||
class Device
|
||||
{
|
||||
DeviceAttribute *attr;
|
||||
@ -41,7 +26,11 @@ class Device
|
||||
|
||||
private:
|
||||
|
||||
friend Device *CreateRenderDevice(VkInstance,const PhysicalDevice *,Window *);
|
||||
void CreateMainBufferAndPass();
|
||||
|
||||
private:
|
||||
|
||||
friend Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,VkSurfaceKHR surface,uint width,uint height);
|
||||
|
||||
Device(DeviceAttribute *da);
|
||||
|
||||
@ -70,7 +59,9 @@ public:
|
||||
RenderPass * GetRenderPass () {return main_rp;}
|
||||
Framebuffer * GetFramebuffer (int index) {return main_fb[index];}
|
||||
|
||||
public: //Buffer相关
|
||||
bool Resize (uint,uint);
|
||||
|
||||
public: //Buffer相关
|
||||
|
||||
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,const void *data,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE);
|
||||
Buffer * CreateBuffer(VkBufferUsageFlags buf_usage,VkDeviceSize size,VkSharingMode sharing_mode=VK_SHARING_MODE_EXCLUSIVE){return CreateBuffer(buf_usage,size,nullptr,sharing_mode);}
|
||||
@ -95,18 +86,18 @@ public: //Buffer
|
||||
|
||||
#undef CREATE_BUFFER_OBJECT
|
||||
|
||||
public: //material相关
|
||||
public: //material相关
|
||||
|
||||
ShaderModuleManage *CreateShaderModuleManage();
|
||||
|
||||
public: //Command Buffer 相关
|
||||
public: //Command Buffer 相关
|
||||
|
||||
CommandBuffer * CreateCommandBuffer();
|
||||
RenderPass * CreateRenderPass(VkFormat color_format,VkFormat depth_format);
|
||||
Fence * CreateFence();
|
||||
Semaphore * CreateSem();
|
||||
|
||||
public: //提交相关
|
||||
public: //提交相关
|
||||
|
||||
bool AcquireNextImage ();
|
||||
bool QueueSubmit (const VkCommandBuffer *,const uint32_t count=1);
|
||||
|
@ -1,14 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include"VK.h"
|
||||
#include"VKImageView.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/graph/vulkan/VKImageView.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
constexpr uint32_t ERROR_FAMILY_INDEX=UINT32_MAX;
|
||||
|
||||
struct PhysicalDevice;
|
||||
|
||||
struct DeviceAttribute
|
||||
{
|
||||
VkInstance instance =nullptr;
|
||||
@ -60,5 +58,7 @@ public:
|
||||
~DeviceAttribute();
|
||||
|
||||
bool CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const;
|
||||
|
||||
void ClearSwapchain();
|
||||
};//class DeviceAttribute
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_VULKAN_GRAPH_FENCE_INCLUDE
|
||||
#define HGL_VULKAN_GRAPH_FENCE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Fence
|
||||
{
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_FRAMEBUFFER_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
class RenderPass;
|
||||
class ImageView;
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_IMAGE_VIEW_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_IMAGE_VIEW_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class ImageView
|
||||
{
|
||||
|
@ -7,9 +7,6 @@
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct PhysicalDevice;
|
||||
class Device;
|
||||
|
||||
class Instance
|
||||
{
|
||||
VkInstance inst;
|
||||
@ -34,15 +31,13 @@ class Device;
|
||||
|
||||
virtual ~Instance();
|
||||
|
||||
VkInstance GetVkInstance () {return inst;}
|
||||
operator VkInstance (){return inst;}
|
||||
|
||||
const List<VkLayerProperties> & GetLayerProperties ()const {return layer_properties;}
|
||||
const bool CheckLayerSupport (const UTF8String &)const;
|
||||
const CharPointerList & GetExtList ()const {return ext_list;}
|
||||
const ObjectList<PhysicalDevice> &GetDeviceList ()const {return physical_devices;}
|
||||
const PhysicalDevice * GetDevice (VkPhysicalDeviceType)const;
|
||||
|
||||
Device * CreateRenderDevice (Window *,const PhysicalDevice *pd=nullptr);
|
||||
};//class Instance
|
||||
|
||||
Instance *CreateInstance(const UTF8String &); ///<创建一个Vulkan实例
|
||||
|
@ -1,20 +1,11 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_MATERIAL_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
class ShaderModule;
|
||||
class VertexShaderModule;
|
||||
class DescriptorSets;
|
||||
class DescriptorSetLayoutCreater;
|
||||
class VertexAttributeBinding;
|
||||
class VertexBuffer;
|
||||
class Renderable;
|
||||
class PipelineLayout;
|
||||
|
||||
class DescriptorSetLayoutCreater;;
|
||||
using ShaderModuleMap=hgl::Map<VkShaderStageFlagBits,const ShaderModule *>;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct PhysicalDevice
|
||||
|
@ -1,14 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_PIPELINE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
class RenderPass;
|
||||
class VertexAttributeBinding;
|
||||
class Material;
|
||||
|
||||
class Pipeline
|
||||
{
|
||||
VkDevice device;
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_RENDER_PASS_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Framebuffer;
|
||||
class ImageView;
|
||||
|
||||
/**
|
||||
* RenderPass功能封装<br>
|
||||
* RenderPass在创建时,需要指定输入的color imageview与depth imageview象素格式,
|
||||
|
@ -1,13 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_RENDERABLE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_RENDERABLE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexShaderModule;
|
||||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
|
||||
/**
|
||||
* 可渲染数据对象<br>
|
||||
* 本对象包含材质实例信息和Mesh信息,可渲染数据对象中包含供最终API使用的VBO数据,可能存在多个MESH数据的集合。</p>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SEMAPHORE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Semaphore
|
||||
{
|
||||
|
@ -1,19 +1,14 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_MANAGE_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_SHADER_MODULE_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SHADER_MODULE_MANAGE_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
class ShaderModule;
|
||||
class VertexShaderModule;
|
||||
class Material;
|
||||
|
||||
/**
|
||||
* Shader模块管理器<br>
|
||||
* 所有的shader模块均由它创建和释放
|
||||
* 该管理器在一个设备下仅有一个,它负责管理所有的shader(仅vs/fs/gs等单个,非组合体)
|
||||
* Shader模块管理器<br>
|
||||
* 所有的shader模块均由它创建和释放
|
||||
* 该管理器在一个设备下仅有一个,它负责管理所有的shader(仅vs/fs/gs等单个,非组合体)
|
||||
*/
|
||||
class ShaderModuleManage
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include<vulkan/vulkan_android.h>
|
||||
|
@ -1,13 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIBUTE_BINDING_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIBUTE_BINDING_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/type/BaseString.h>
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexBuffer;
|
||||
class IndexBuffer;
|
||||
class VertexShaderModule;
|
||||
|
||||
/**
|
||||
* 顶点输入状态实例<br>
|
||||
* 本对象用于传递给Material,用于已经确定好顶点格式的情况下,依然可修改部分设定(如instance)。
|
||||
|
@ -3,10 +3,15 @@
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/platform/InputDevice.h>
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
class Window
|
||||
{
|
||||
VK_NAMESPACE::Device *device;
|
||||
virtual VkSurfaceKHR CreateSurface(VkInstance)=0;
|
||||
|
||||
protected:
|
||||
|
||||
uint width,height;
|
||||
@ -16,6 +21,7 @@ namespace hgl
|
||||
|
||||
bool active;
|
||||
bool is_close;
|
||||
bool is_min;
|
||||
|
||||
bool key_push[kbRangeSize];
|
||||
|
||||
@ -47,7 +53,7 @@ namespace hgl
|
||||
|
||||
virtual void OnChar (os_char){}
|
||||
|
||||
virtual void OnResize (int w,int h){width=w;height=h;}
|
||||
virtual void OnResize (uint,uint);
|
||||
|
||||
virtual void OnActive (bool a){active=a;}
|
||||
virtual void OnClose (){is_close=true;}
|
||||
@ -56,18 +62,22 @@ namespace hgl
|
||||
|
||||
Window(const OSString &wn)
|
||||
{
|
||||
device=nullptr;
|
||||
width=height=0;
|
||||
full_screen=false;
|
||||
win_name=wn;
|
||||
active=false;
|
||||
is_close=true;
|
||||
is_min=false;
|
||||
hgl_zero(key_push);
|
||||
}
|
||||
virtual ~Window()=default;
|
||||
virtual ~Window();
|
||||
|
||||
virtual bool Create(uint,uint)=0;
|
||||
virtual bool Create(uint,uint,uint)=0;
|
||||
virtual void Close()=0;
|
||||
|
||||
bool IsMin()const{return is_min;}
|
||||
bool IsClose()const{return is_close;}
|
||||
bool IsVisible()const{return (!is_close)&&width&&height;}
|
||||
|
||||
@ -76,12 +86,17 @@ namespace hgl
|
||||
virtual void Show()=0;
|
||||
virtual void Hide()=0;
|
||||
|
||||
virtual void ToMinWindow(){}
|
||||
virtual void ToMaxWindow(){}
|
||||
virtual void ToMinWindow()=0;
|
||||
virtual void ToMaxWindow()=0;
|
||||
|
||||
virtual void SetSystemCursor(bool){}
|
||||
|
||||
virtual bool Update();
|
||||
|
||||
public:
|
||||
|
||||
VK_NAMESPACE::Device * CreateRenderDevice(VK_NAMESPACE::Instance *,const VK_NAMESPACE::PhysicalDevice *pd=nullptr);
|
||||
void CloseRenderDevice();
|
||||
};//class Window
|
||||
|
||||
Window *CreateRenderWindow(const OSString &win_name);
|
||||
|
@ -3,15 +3,15 @@
|
||||
#include<vulkan/vulkan_xcb.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VkSurfaceKHR CreateRenderDevice(VkInstance vk_inst,Window *win)
|
||||
VkSurfaceKHR XCBWindow::CreateSurface(VkInstance vk_inst)
|
||||
{
|
||||
XCBWindow *xcb_win=(XCBWindow *)win;
|
||||
|
||||
VkXcbSurfaceCreateInfoKHR createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.pNext = nullptr;
|
||||
createInfo.connection = xcb_win->GetConnection();
|
||||
createInfo.window = xcb_win->GetWindow();
|
||||
createInfo.connection = connection;
|
||||
createInfo.window = window;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
|
@ -13,6 +13,7 @@ namespace hgl
|
||||
private:
|
||||
|
||||
bool InitConnection();
|
||||
VkSurfaceKHR CreateSurface(VkInstance) override;
|
||||
|
||||
public:
|
||||
|
||||
@ -29,11 +30,6 @@ namespace hgl
|
||||
void Hide()override{}
|
||||
bool MessageProc() override;
|
||||
bool WaitMessage() override;
|
||||
|
||||
public:
|
||||
|
||||
xcb_connection_t *GetConnection(){return connection;}
|
||||
xcb_window_t GetWindow(){return window;}
|
||||
};//class XCBWindow:public Window
|
||||
}//namespace hgl
|
||||
|
||||
|
@ -1,17 +1,15 @@
|
||||
#include"WinWindow.h"
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<vulkan/vulkan_win32.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VkSurfaceKHR CreateRenderDevice(VkInstance vk_inst,Window *win)
|
||||
namespace hgl
|
||||
{
|
||||
WinWindow *ww=(WinWindow *)win;
|
||||
|
||||
VkSurfaceKHR WinWindow::CreateSurface(VkInstance vk_inst)
|
||||
{
|
||||
VkWin32SurfaceCreateInfoKHR createInfo={};
|
||||
createInfo.sType=VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.pNext=nullptr;
|
||||
createInfo.hinstance=ww->GetHInstance();
|
||||
createInfo.hwnd=ww->GetHWnd();
|
||||
createInfo.hinstance=hInstance;
|
||||
createInfo.hwnd=win_hwnd;
|
||||
|
||||
VkSurfaceKHR surface;
|
||||
|
||||
@ -21,5 +19,5 @@ VkSurfaceKHR CreateRenderDevice(VkInstance vk_inst,Window *win)
|
||||
return(nullptr);
|
||||
|
||||
return(surface);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
}
|
||||
}//namespace hgl
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<Windows.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
@ -18,17 +17,13 @@ namespace hgl
|
||||
protected:
|
||||
|
||||
bool Create();
|
||||
VkSurfaceKHR CreateSurface(VkInstance)override;
|
||||
|
||||
public:
|
||||
|
||||
using Window::Window;
|
||||
~WinWindow();
|
||||
|
||||
HINSTANCE GetHInstance(){return hInstance;}
|
||||
HWND GetHWnd(){return win_hwnd;}
|
||||
|
||||
public:
|
||||
|
||||
bool Create(uint w, uint h) override;
|
||||
bool Create(uint, uint, uint) override;
|
||||
void Close() override;
|
||||
|
@ -1,6 +1,55 @@
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/platform/Window.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKInstance.h>
|
||||
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,VkSurfaceKHR surface,uint width,uint height);
|
||||
VK_NAMESPACE_END
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
Window::~Window()
|
||||
{
|
||||
SAFE_CLEAR(device);
|
||||
}
|
||||
|
||||
VK_NAMESPACE::Device *Window::CreateRenderDevice(VK_NAMESPACE::Instance *vk_inst,const VK_NAMESPACE::PhysicalDevice *pd)
|
||||
{
|
||||
if(device)
|
||||
return(device);
|
||||
|
||||
if(!vk_inst)
|
||||
return(nullptr);
|
||||
|
||||
if(!pd)pd=vk_inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU); //先找独显
|
||||
if(!pd)pd=vk_inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU); //再找集显
|
||||
if(!pd)pd=vk_inst->GetDevice(VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU); //最后找虚拟显卡
|
||||
|
||||
if(!pd)
|
||||
return(nullptr);
|
||||
|
||||
VkSurfaceKHR surface=CreateSurface(*vk_inst);
|
||||
|
||||
if(!surface)
|
||||
return(nullptr);
|
||||
|
||||
device=VK_NAMESPACE::CreateRenderDevice(*vk_inst,pd,surface,width,height);
|
||||
|
||||
if(!device)
|
||||
{
|
||||
vkDestroySurfaceKHR(*vk_inst,surface,nullptr);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return(device);
|
||||
}
|
||||
|
||||
void Window::CloseRenderDevice()
|
||||
{
|
||||
SAFE_CLEAR(device);
|
||||
}
|
||||
|
||||
void Window::OnKeyDown(KeyboardButton kb)
|
||||
{
|
||||
if(key_push[kb])
|
||||
@ -18,13 +67,33 @@ namespace hgl
|
||||
key_push[kb]=false;
|
||||
}
|
||||
|
||||
void Window::OnResize(uint w,uint h)
|
||||
{
|
||||
if(w==width&&height==h)
|
||||
return;
|
||||
|
||||
if(w==0||h==0)
|
||||
{
|
||||
is_min=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_min=false;
|
||||
width=w;
|
||||
height=h;
|
||||
|
||||
if(device)
|
||||
device->Resize(width,height);
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::Update()
|
||||
{
|
||||
while(MessageProc())
|
||||
{
|
||||
}
|
||||
|
||||
if(!active||width==0||height==0)
|
||||
if(!active||is_min)
|
||||
this->WaitMessage();
|
||||
|
||||
return(!is_close);
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
bool ResizeRenderDevice(DeviceAttribute *attr,uint width,uint height);
|
||||
|
||||
Device::Device(DeviceAttribute *da)
|
||||
{
|
||||
attr=da;
|
||||
@ -28,14 +30,7 @@ Device::Device(DeviceAttribute *da)
|
||||
present.waitSemaphoreCount = 0;
|
||||
present.pResults = nullptr;
|
||||
|
||||
{
|
||||
const int sc_count=attr->sc_image_views.GetCount();
|
||||
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||
|
||||
for(int i=0;i<sc_count;i++)
|
||||
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
|
||||
}
|
||||
CreateMainBufferAndPass();
|
||||
}
|
||||
|
||||
Device::~Device()
|
||||
@ -50,6 +45,30 @@ Device::~Device()
|
||||
delete attr;
|
||||
}
|
||||
|
||||
void Device::CreateMainBufferAndPass()
|
||||
{
|
||||
const int sc_count=attr->sc_image_views.GetCount();
|
||||
|
||||
main_rp=CreateRenderPass(attr->sc_image_views[0]->GetFormat(),attr->depth.view->GetFormat());
|
||||
|
||||
for(int i=0;i<sc_count;i++)
|
||||
main_fb.Add(vulkan::CreateFramebuffer(this,main_rp,attr->sc_image_views[i],attr->depth.view));
|
||||
}
|
||||
|
||||
bool Device::Resize(uint width,uint height)
|
||||
{
|
||||
main_fb.Clear();
|
||||
delete main_rp;
|
||||
main_rp=nullptr;
|
||||
|
||||
if(!ResizeRenderDevice(attr,width,height))
|
||||
return(false);
|
||||
|
||||
CreateMainBufferAndPass();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
CommandBuffer *Device::CreateCommandBuffer()
|
||||
{
|
||||
if(!attr->cmd_pool)
|
||||
|
@ -138,18 +138,7 @@ DeviceAttribute::~DeviceAttribute()
|
||||
if(desc_pool)
|
||||
vkDestroyDescriptorPool(device,desc_pool,nullptr);
|
||||
|
||||
SAFE_CLEAR(depth.view);
|
||||
|
||||
if(depth.image)
|
||||
vkDestroyImage(device,depth.image,nullptr);
|
||||
|
||||
if(depth.mem)
|
||||
vkFreeMemory(device,depth.mem,nullptr);
|
||||
|
||||
sc_image_views.Clear();
|
||||
|
||||
if(swap_chain)
|
||||
vkDestroySwapchainKHR(device,swap_chain,nullptr);
|
||||
ClearSwapchain();
|
||||
|
||||
if(cmd_pool)
|
||||
vkDestroyCommandPool(device,cmd_pool,nullptr);
|
||||
@ -165,4 +154,29 @@ bool DeviceAttribute::CheckMemoryType(uint32_t typeBits,VkFlags requirements_mas
|
||||
{
|
||||
return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex);
|
||||
}
|
||||
|
||||
void DeviceAttribute::ClearSwapchain()
|
||||
{
|
||||
SAFE_CLEAR(depth.view);
|
||||
|
||||
if(depth.image)
|
||||
{
|
||||
vkDestroyImage(device,depth.image,nullptr);
|
||||
depth.image=nullptr;
|
||||
}
|
||||
|
||||
if(depth.mem)
|
||||
{
|
||||
vkFreeMemory(device,depth.mem,nullptr);
|
||||
depth.mem=nullptr;
|
||||
}
|
||||
|
||||
sc_image_views.Clear();
|
||||
|
||||
if(swap_chain)
|
||||
{
|
||||
vkDestroySwapchainKHR(device,swap_chain,nullptr);
|
||||
swap_chain=nullptr;
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VkSurfaceKHR CreateRenderDevice(VkInstance,Window *);
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T> T Clamp(const T &cur,const T &min_value,const T &max_value)
|
||||
@ -286,20 +284,31 @@ namespace
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
bool CreateSwapchinAndImageView(DeviceAttribute *attr)
|
||||
{
|
||||
attr->swap_chain=CreateSwapChain(attr);
|
||||
|
||||
if(!attr->swap_chain)
|
||||
return(false);
|
||||
|
||||
if(!CreateSwapchainImageView(attr))
|
||||
return(false);
|
||||
|
||||
if(!CreateDepthBuffer(attr))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
}//namespace
|
||||
|
||||
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,Window *win)
|
||||
Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device,VkSurfaceKHR surface,uint width,uint height)
|
||||
{
|
||||
VkSurfaceKHR surface=CreateRenderDevice(inst,win);
|
||||
|
||||
if(!surface)
|
||||
return(nullptr);
|
||||
|
||||
DeviceAttribute *attr=new DeviceAttribute(inst,physical_device,surface);
|
||||
|
||||
AutoDelete<DeviceAttribute> auto_delete(attr);
|
||||
|
||||
attr->swapchain_extent=GetSwapchainExtent(attr->surface_caps,win->GetWidth(),win->GetHeight());
|
||||
attr->swapchain_extent=GetSwapchainExtent(attr->surface_caps,width,height);
|
||||
|
||||
if(attr->graphics_family==ERROR_FAMILY_INDEX)
|
||||
return(nullptr);
|
||||
@ -316,15 +325,7 @@ Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device
|
||||
if(!attr->cmd_pool)
|
||||
return(nullptr);
|
||||
|
||||
attr->swap_chain=CreateSwapChain(attr);
|
||||
|
||||
if(!attr->swap_chain)
|
||||
return(nullptr);
|
||||
|
||||
if(!CreateSwapchainImageView(attr))
|
||||
return(nullptr);
|
||||
|
||||
if(!CreateDepthBuffer(attr))
|
||||
if(!CreateSwapchinAndImageView(attr))
|
||||
return(nullptr);
|
||||
|
||||
attr->desc_pool=CreateDescriptorPool(attr->device,1);
|
||||
@ -341,4 +342,17 @@ Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device
|
||||
|
||||
return(new Device(attr));
|
||||
}
|
||||
|
||||
bool ResizeRenderDevice(DeviceAttribute *attr,uint width,uint height)
|
||||
{
|
||||
if(attr->swapchain_extent.width==width
|
||||
&&attr->swapchain_extent.height==height)
|
||||
return(true);
|
||||
|
||||
attr->ClearSwapchain();
|
||||
|
||||
attr->swapchain_extent=GetSwapchainExtent(attr->surface_caps,width,height);
|
||||
|
||||
return CreateSwapchinAndImageView(attr);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -287,19 +287,4 @@ const PhysicalDevice *Instance::GetDevice(VkPhysicalDeviceType type)const
|
||||
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
Device *Instance::CreateRenderDevice(Window *win,const PhysicalDevice *pd)
|
||||
{
|
||||
if(!win)
|
||||
return(nullptr);
|
||||
|
||||
if(!pd)pd=GetDevice(VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU); //先找独显
|
||||
if(!pd)pd=GetDevice(VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU); //再找集显
|
||||
if(!pd)pd=GetDevice(VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU); //最后找虚拟显卡
|
||||
|
||||
if(!pd)
|
||||
return(nullptr);
|
||||
|
||||
return VK_NAMESPACE::CreateRenderDevice(inst,pd,win);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user