2022-09-02 11:06:59 +00:00
|
|
|
#include "resources/shader.hpp"
|
|
|
|
|
2022-10-27 22:06:56 +00:00
|
|
|
#include "log.hpp"
|
2022-09-02 11:06:59 +00:00
|
|
|
|
2022-10-27 22:06:56 +00:00
|
|
|
#include "gfx_device.hpp"
|
2022-09-02 11:06:59 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2022-10-06 10:30:44 +00:00
|
|
|
namespace engine::resources {
|
2022-09-02 11:06:59 +00:00
|
|
|
|
|
|
|
Shader::Shader(const std::filesystem::path& resPath) : Resource(resPath, "shader")
|
|
|
|
{
|
|
|
|
|
2022-10-27 22:06:56 +00:00
|
|
|
gfx::VertexFormat vertexFormat {};
|
2022-10-31 16:21:07 +00:00
|
|
|
vertexFormat.stride = 8 * sizeof(float);
|
2022-10-27 22:06:56 +00:00
|
|
|
vertexFormat.attributeDescriptions.emplace_back(0, gfx::VertexAttribFormat::VEC3, 0); // pos
|
|
|
|
vertexFormat.attributeDescriptions.emplace_back(1, gfx::VertexAttribFormat::VEC3, sizeof(glm::vec3)); // norm
|
|
|
|
vertexFormat.attributeDescriptions.emplace_back(2, gfx::VertexAttribFormat::VEC2, sizeof(glm::vec3) + sizeof(glm::vec3)); // uv
|
2022-09-02 11:06:59 +00:00
|
|
|
|
2022-11-08 13:42:07 +00:00
|
|
|
const std::string vertexShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".vert")).string();
|
|
|
|
const std::string fragmentShaderPath = (resPath.parent_path()/std::filesystem::path(resPath.stem().string() + ".frag")).string();
|
2022-09-02 11:06:59 +00:00
|
|
|
|
2022-11-27 14:35:41 +00:00
|
|
|
m_pipeline = gfxdev->createPipeline(vertexShaderPath.c_str(), fragmentShaderPath.c_str(), vertexFormat, sizeof(UniformBuffer), true, true);
|
2022-09-02 11:06:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Shader::~Shader()
|
|
|
|
{
|
2022-10-27 22:06:56 +00:00
|
|
|
gfxdev->destroyPipeline(m_pipeline);
|
2022-09-02 11:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|