Files
Archimedes/include/utils/Renderer/RenderTarget.h
2026-02-10 13:37:49 -06:00

185 lines
4.2 KiB
C++

#ifndef RENDERTARGET_H
#define RENDERTARGET_H
#include "pch.hpp"
#include "extratools.h"
namespace Archimedes {
class LayoutElement {
public:
LayoutElement(unsigned int type, size_t count) : type(type), count(count) {}
~LayoutElement() {}
unsigned int getType() const { return type; }
size_t getSize() const { return size; }
size_t getCount() const { return count; }
private:
unsigned int type;
size_t size;
size_t count;
};
class VertexLayout {
public:
VertexLayout() {}
~VertexLayout() {}
const std::vector<LayoutElement>& getElements() const { return elements; }
private:
std::vector<LayoutElement> elements;
};
class VertexBuffer {
public:
VertexBuffer(const void* data, size_t size) : data(data), size(size) {
}
~VertexBuffer() {}
const void* getData() const { return data; }
size_t getSize() const { return size; }
unsigned int id;
private:
const void* data;
size_t size;
};
class VertexArray {
public:
VertexArray() {
}
~VertexArray() {}
unsigned int id;
private:
};
class IndexArray {
public:
IndexArray(const unsigned int* indices, size_t count) : indices(indices), count(count) {
}
~IndexArray() {}
const void* getIndicies() const { return indices; }
size_t getCount() const { return count; }
unsigned int id;
private:
const unsigned int* indices;
size_t count;
};
class Shader {
public:
enum class LoadType {
FromSource,
FromBin,
FromFileSource,
FromFileBin
};
Shader(const std::string& vs, const std::string& fs, LoadType loadType) : loadType(loadType) {
switch(loadType) {
case LoadType::FromSource:
this->vs = vs;
this->fs = fs;
break;
case LoadType::FromBin:
break;
case LoadType::FromFileSource:
this->vs = readSourceFile(vs);
this->fs = readSourceFile(fs);
break;
case LoadType::FromFileBin:
break;
default:
break;
}
}
~Shader() {}
std::string getVSource() const { return vs; }
std::string getFSource() const { return fs; }
unsigned int id;
private:
LoadType loadType;
std::string vs;
std::string fs;
std::string readSourceFile(const std::string& path) {
std::ifstream file(path);
if(!file.is_open()) {
return "";
}
std::string s;
while(!file.eof()) {
file >> s;
}
return s;
}
};
class RenderTarget {
public:
RenderTarget(const void* data, size_t size, unsigned int* indices, size_t count, VertexLayout layout, const std::string& vs, const std::string& fs)
: vertexBuffer(data, size),
indexArray(indices, count),
layout(layout),
shader(vs, fs, Shader::LoadType::FromFileSource) {
}
RenderTarget(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s)
: vertexBuffer(vb),
indexArray(ia),
layout(vl),
shader(s) {
}
~RenderTarget() {}
//private:
VertexBuffer vertexBuffer;
VertexArray vertexArray;
VertexLayout layout;
IndexArray indexArray;
Shader shader;
};
}
#endif