-
Notifications
You must be signed in to change notification settings - Fork 0
/
lve_pipeline.cpp
71 lines (55 loc) · 1.77 KB
/
lve_pipeline.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "lve_pipeline.hpp"
#include <fstream>
#include <iostream>
#include <stdexcept>
namespace lve
{
LvePipeline::LvePipeline(
LveDevice& device,
const std::string& vertFilepath,
const std::string& fragFilepath,
const PipelineConfigInfo& configInfo)
: lveDevice{ device } {
createGraphicsPipeline(vertFilepath, fragFilepath, configInfo);
}
std::vector<char> LvePipeline::readFile(const std::string& filepath)
{
std::ifstream file(filepath, std::ios::ate | std::ios::binary);
if(!file.is_open())
{
throw std::runtime_error("failed to open file: " + filepath);
}
size_t fileSize = static_cast<size_t>(file.tellg());
std::vector<char> buffer(fileSize);
file.seekg(0);
file.read(buffer.data(), fileSize);
file.close();
return buffer;
}
void LvePipeline::createGraphicsPipeline(
const std::string& vertFilepath,
const std::string& fragFilepath,
const PipelineConfigInfo& configInfo)
{
std::cout << " LvePipeline createGraphicsPipeline: \n";
auto vertCode = readFile(vertFilepath);
auto fragCode = readFile(fragFilepath);
std::cout << "Vertex shader code Size:: " << vertCode.size() << "\n";
}
void LvePipeline::createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule)
{
VkShaderModuleCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
createInfo.codeSize = code.size();
createInfo.pCode = reinterpret_cast<const uint32_t*>(code.data());
if(vkCreateShaderModule(lveDevice.device(), &createInfo, nullptr, shaderModule) != VK_SUCCESS)
{
throw std::runtime_error("failed to create shader module");
}
}
PipelineConfigInfo LvePipeline::defaultPipelineConfigInfo(uint32_t width, uint32_t height)
{
PipelineConfigInfo configInfo{};
return configInfo;
}
}