14 bool ShaderVK::load(const char *fname, SType type)
16 char *vk_fname = new char[strlen(fname) + strlen(".spirv") + 1];
17 strcpy(vk_fname, fname);
19 char *suffix = strrchr(vk_fname, '.');
25 strcat(vk_fname, ".spirv");
27 bool res = Shader::load(vk_fname, type);
33 bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname)
35 name = std::string(fname);
37 VkShaderModuleCreateInfo sminf;
38 memset(&sminf, 0, sizeof sminf);
39 sminf.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
42 sminf.pCode = (uint32_t*)buf;
44 if(vkCreateShaderModule(vk_device, &sminf, 0, &sm) != VK_SUCCESS) {
47 fprintf(stderr, "Failed to create vertex shader module.\n");
55 void ShaderVK::destroy()
57 vkDestroyShaderModule(vk_device, sm, 0);
60 ShaderProgramVK::ShaderProgramVK()
64 ShaderProgramVK::~ShaderProgramVK()
68 bool ShaderProgramVK::create()
71 VkPipelineCacheCreateInfo pcinf;
72 memset(&pcinf, 0, sizeof pcinf);
73 pcinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
75 VkPipelineCache pcache;
76 if(!vkCreatePipelineCache(vk_device, &pcinf, 0, &pcache) != VK_SUCCESS) {
77 fprintf(stderr, "Failed to create pipeline cache.\n");
82 VkGraphicsPipelineCreateInfo gpinf;
83 memset(&gpinf, 0, sizeof gpinf);
84 gpinf.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
87 VkPipelineShaderStageCreateInfo ssinf[2];
88 for(int i=0; i<2; i++) {
89 memset(&ssinf[i], 0, sizeof ssinf[i]);
90 ssinf[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
92 switch(shaders[i]->get_type()) {
94 ssinf[i].stage = VK_SHADER_STAGE_VERTEX_BIT;
97 ssinf[i].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
100 fprintf(stderr, "Failed to create graphics pipeline: Invalid shader type.\n");
103 ssinf[i].module = ((ShaderVK*)shaders[i])->sm;
106 gpinf.pStages = ssinf;
111 bool ShaderProgramVK::link()
116 bool ShaderProgramVK::use() const
121 void ShaderProgramVK::destroy()
125 void ShaderProgramVK::attach_shader(Shader *shader)
129 int ShaderProgramVK::get_uniform_location(const char *name) const
134 void ShaderProgramVK::set_uniformi(int location, int value)
138 void ShaderProgramVK::set_uniformi(int location, int x, int y)
142 void ShaderProgramVK::set_uniformi(int location, int x, int y, int z)
146 void ShaderProgramVK::set_uniformi(int location, int x, int y, int z, int w)
151 void ShaderProgramVK::set_uniformf(int location, float value)
155 void ShaderProgramVK::set_uniformf(int location, float x, float y)
159 void ShaderProgramVK::set_uniformf(int location, float x, float y, float z)
163 void ShaderProgramVK::set_uniformf(int location, float x, float y, float z, float w)
167 void ShaderProgramVK::set_uniform_matrix(int location, const Mat4 &mat)