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