初步增加shader加载代码(部分)
This commit is contained in:
parent
fcac721287
commit
2c2de5675a
@ -32,6 +32,7 @@ public:
|
||||
virtual ~RenderSurface()=default;
|
||||
|
||||
VkSurfaceKHR GetSurface () {return rsa->surface;}
|
||||
VkDevice GetDevice () {return rsa->device;}
|
||||
const PhysicalDevice *GetPhysicalDevice ()const {return rsa->physical_device;}
|
||||
|
||||
public:
|
||||
|
@ -1,4 +1,30 @@
|
||||
#include"VKShader.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
VkShaderModule CreateShaderModule(VkDevice device,const uint32_t *spv_data,const uint32_t spv_size,const VkShaderStageFlagBits shader_stage_bit)
|
||||
{
|
||||
VkPipelineShaderStageCreateInfo shader_stage;
|
||||
shader_stage.sType=VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
shader_stage.pNext=nullptr;
|
||||
shader_stage.pSpecializationInfo=nullptr;
|
||||
shader_stage.flags=0;
|
||||
shader_stage.stage=shader_stage_bit;
|
||||
shader_stage.pName="main";
|
||||
|
||||
VkShaderModuleCreateInfo moduleCreateInfo;
|
||||
moduleCreateInfo.sType=VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
moduleCreateInfo.pNext=nullptr;
|
||||
moduleCreateInfo.flags=0;
|
||||
moduleCreateInfo.codeSize=spv_size;
|
||||
moduleCreateInfo.pCode=spv_data;
|
||||
|
||||
VkShaderModule shader_module;
|
||||
|
||||
if(vkCreateShaderModule(device,&moduleCreateInfo,nullptr,&shader_module)==VK_SUCCESS)
|
||||
return shader_module;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -4,8 +4,18 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
class Shader
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
};//class Shader
|
||||
|
||||
VkShaderModule CreateShaderModule(VkDevice device,const uint32_t *spv_data,const uint32_t spv_size,const VkShaderStageFlagBits shader_stage_bit);
|
||||
|
||||
inline VkShaderModule CreateVertexShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_VERTEX_BIT); }
|
||||
inline VkShaderModule CreateFragmentShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_FRAGMENT_BIT); }
|
||||
inline VkShaderModule CreateGeometryShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_GEOMETRY_BIT); }
|
||||
inline VkShaderModule CreateTessCtrlShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); }
|
||||
inline VkShaderModule CreateTessEvalShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); }
|
||||
inline VkShaderModule CreateComputeShader (VkDevice device,const uint32_t *spv_data,const uint32_t spv_size) { return CreateShaderModule(device,spv_data,spv_size,VK_SHADER_STAGE_COMPUTE_BIT); }
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,10 +1,41 @@
|
||||
#include"Window.h"
|
||||
#include"VKInstance.h"
|
||||
#include"RenderSurface.h"
|
||||
#include"VKShader.h"
|
||||
|
||||
#include<io.h>
|
||||
#include<fcntl.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
VkShaderModule vs=nullptr;
|
||||
VkShaderModule fs=nullptr;
|
||||
|
||||
char *LoadFile(const char *filename,uint32_t &file_length)
|
||||
{
|
||||
int fp=_open(filename,O_RDONLY);
|
||||
|
||||
if(fp==-1)return(nullptr);
|
||||
|
||||
file_length=_filelength(fp);
|
||||
char *data=new char[file_length];
|
||||
|
||||
if(_read(fp,data,file_length)!=file_length)
|
||||
{
|
||||
delete[] data;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
_close(fp);
|
||||
return data;
|
||||
}
|
||||
|
||||
bool LoadShader(VkDevice device)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
Window *win=CreateRenderWindow(OS_TEXT("VulkanTest"));
|
||||
@ -34,6 +65,9 @@ int main(int,char **)
|
||||
std::cout<<"auto select physical device: "<<render_device->GetDeviceName()<<std::endl;
|
||||
}
|
||||
|
||||
if(!LoadShader(render->GetDevice()))
|
||||
return(-3);
|
||||
|
||||
vulkan::CommandBuffer *cmd_buf=render->CreateCommandBuffer();
|
||||
|
||||
vulkan::Buffer *ubo=render->CreateUBO(1024);
|
||||
|
Loading…
x
Reference in New Issue
Block a user