Skip to content

Commit

Permalink
Shaders assets fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zielon committed Aug 13, 2021
1 parent 0c02572 commit c7aad09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Rasterizer/Rasterizer/src/Viewer/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#include <sstream>
#include <iostream>

#include "../path.h"

namespace Viewer
{
class Shader
{
public:
Shader(const std::string& vertexPath, const std::string& fragmentPath)
{
root = Path::Root({ "Rasterizer", "Assets", "Shaders" });

std::string vertexCode;
std::string fragmentCode;

Expand All @@ -25,8 +29,8 @@ namespace Viewer

try
{
vShaderFile.open("../Assets/Shaders/" + vertexPath);
fShaderFile.open("../Assets/Shaders/" + fragmentPath);
vShaderFile.open(root / vertexPath);
fShaderFile.open(root / fragmentPath);

std::stringstream vShaderStream, fShaderStream;

Expand Down Expand Up @@ -77,6 +81,7 @@ namespace Viewer

private:
unsigned int ID;
std::filesystem::path root;

static void CheckCompileErrors(GLuint shader, std::string type)
{
Expand Down
6 changes: 2 additions & 4 deletions Rasterizer/Rasterizer/src/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ class Path
static std::filesystem::path Root(std::vector<std::string> segments)
{
auto root = std::filesystem::current_path();
auto current = root.parent_path().filename();
auto current = root.filename();
while (current.string().find("CPURasterizer") == std::string::npos)
{
root = root.parent_path();
current = root.parent_path().filename();
current = root.filename();
}

root = root.parent_path();

for (const auto segment : segments)
root /= segment;

Expand Down

0 comments on commit c7aad09

Please sign in to comment.