SimpleGL  1.1.0
A framework for platform independent rendering
shader_module.cpp
Go to the documentation of this file.
1 
9 
10 #include <stdexcept>
11 
13 
14 using namespace std;
15 
16 namespace sgl {
17 
18  ShaderModule::ShaderModule(std::vector<uint8_t> code, ShaderStageBit stage) {
19  VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
20  this->shaderStageBit = stage;
21 
22  /* Initialize a shader module create info */
23  VkShaderModuleCreateInfo createInfo = {};
24  createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
25  createInfo.codeSize = code.size();
26  createInfo.pCode = reinterpret_cast<const uint32_t*> (code.data());
27 
28  /* Create the shader module */
29  if (vkCreateShaderModule(device, &createInfo, nullptr, &handle) != VK_SUCCESS) {
30  throw runtime_error("Could not create a shader module!");
31  }
32  }
33 
34  ShaderModule::~ShaderModule(void) {
35  VkDevice device = VulkanContext::getCurrent()->getDevice()->getHandle();
36 
37  /* Destroy the shader module */
38  vkDestroyShaderModule(device, handle, nullptr);
39  }
40 
41  VkShaderModule ShaderModule::getHandle() {
42  return handle;
43  }
44 
45  VkShaderStageFlagBits ShaderModule::getShaderStageBit() {
46  /* Determine the shader stage flag bit */
47  VkShaderStageFlagBits stageFlagBit;
48  switch (shaderStageBit) {
49  case ShaderStageBit::VERTEX_BIT:
50  stageFlagBit = VK_SHADER_STAGE_VERTEX_BIT;
51  break;
52  case ShaderStageBit::FRAGMENT_BIT:
53  stageFlagBit = VK_SHADER_STAGE_FRAGMENT_BIT;
54  break;
55  }
56 
57  return stageFlagBit;
58  }
59 }
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
ShaderStageBit
This enum stores supported shader stage flag bit.