backup - missing some
[demo] / src / vulkan / shader-vk.cc
index eb22b97..51c4722 100644 (file)
@@ -2,8 +2,6 @@
 #include "shader-vk.h"
 
 /* static variables */
-static vku_buffer ubo;
-
 ShaderVK::ShaderVK()
 {
 }
@@ -13,18 +11,50 @@ ShaderVK::~ShaderVK()
        destroy();
 }
 
-bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname)
+bool ShaderVK::load(const char *fname, ShaderType type)
 {
-       return true;
+       char *vk_fname = new char[strlen(fname) + strlen(".spirv") + 1];
+       strcpy(vk_fname, fname);
+
+       char *suffix = strrchr(vk_fname, '.');
+
+       if(suffix) {
+               *suffix = 0;
+       }
+
+       strcat(vk_fname, ".spirv");
+
+       bool res = Shader::load(vk_fname, type);
+       delete [] vk_fname;
+
+       return res;
 }
 
-bool ShaderVK::load(const char *fname, SType type)
+bool ShaderVK::create(char *buf, unsigned int bsz, const char *fname)
 {
+       name = std::string(fname);
+
+       VkShaderModuleCreateInfo sminf;
+       memset(&sminf, 0, sizeof sminf);
+       sminf.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
+
+       sminf.codeSize = bsz;
+       sminf.pCode = (uint32_t *)buf;
+
+       if(vkCreateShaderModule(vk_device, &sminf, 0, &sdr) != VK_SUCCESS) {
+               delete [] buf;
+
+               fprintf(stderr, "Failed to create vertex shader module.\n");
+               return false;
+       }
+
+       delete [] buf;
        return true;
 }
 
 void ShaderVK::destroy()
 {
+       vkDestroyShaderModule(vk_device, sdr, 0);
 }
 
 ShaderProgramVK::ShaderProgramVK()
@@ -33,6 +63,7 @@ ShaderProgramVK::ShaderProgramVK()
 
 ShaderProgramVK::~ShaderProgramVK()
 {
+       destroy();
 }
 
 bool ShaderProgramVK::create()
@@ -52,50 +83,14 @@ bool ShaderProgramVK::use() const
 
 void ShaderProgramVK::destroy()
 {
-}
+       int len = sizeof shaders / sizeof *shaders;
 
-void ShaderProgramVK::attach_shader(Shader *shader)
-{
-}
+       for(int i=0; i<len; ++i) {
+               delete shaders[i];
+       }
 
-int ShaderProgramVK::get_uniform_location(const char *name) const
-{
-       return 0;
-}
-
-void ShaderProgramVK::set_uniformi(int location, int value)
-{
 }
 
-void ShaderProgramVK::set_uniformi(int location, int x, int y)
-{
-}
-
-void ShaderProgramVK::set_uniformi(int location, int x, int y, int z)
-{
-}
-
-void ShaderProgramVK::set_uniformi(int location, int x, int y, int z, int w)
-{
-}
-
-
-void ShaderProgramVK::set_uniformf(int location, float value)
-{
-}
-
-void ShaderProgramVK::set_uniformf(int location, float x, float y)
-{
-}
-
-void ShaderProgramVK::set_uniformf(int location, float x, float y, float z)
-{
-}
-
-void ShaderProgramVK::set_uniformf(int location, float x, float y, float z, float w)
+void ShaderProgramVK::attach_shader(Shader *shader)
 {
 }
-
-void ShaderProgramVK::set_uniform_matrix(int location, const Mat4 &mat)
-{
-}
\ No newline at end of file