-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.h
92 lines (74 loc) · 3.53 KB
/
Loader.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#include "Model.h"
#include <tiny_obj_loader.h>
#include <sys/stat.h>
#include <glad/glad.h>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <glm/glm.hpp>
struct Image {
static Image loadFromFile(std::string_view filePath);
Image();
~Image();
Image(const Image& other) = delete;
Image(Image&& other) noexcept
: data(other.data), width(other.width), height(other.height), channels(other.channels) {
other.data = nullptr;
}
Image& operator=(const Image& other) = delete;
Image& operator=(Image&& other) noexcept {
if (this == &other)
return *this;
data = other.data;
width = other.width;
height = other.height;
channels = other.channels;
other.data = nullptr;
return *this;
}
unsigned char* data;
int width;
int height;
int channels;
[[nodiscard]] glm::vec3 getPixel(int x, int y) const;
private:
Image(unsigned char* data, int width, int height, int channels);
};
class Loader {
private:
static Loader* loader;
Loader() = default;
// Stores the file/id mapping for each loaded texture to use for caching.
std::map<std::string, GLuint> loadedTextures;
static GLuint loadTextureData(GLubyte* data, int x, int y, int n, GLenum textureUnit);
static GLuint setupBuffer(unsigned int buffer, const std::vector<float>& values, int attributeIndex, int dataDimension);
static GLuint setupIndicesBuffer(unsigned int buffer, const std::vector<unsigned int>& values);
public:
static Loader* getLoader();
static std::vector<float> generateNormals(const std::vector<float>& vertices, const std::vector<unsigned int>& indices);
static bool fileExists(const std::string& name);
Model loadModel(const std::string& filepath);
Model loadModel(const std::vector<tinyobj::shape_t>& shapes, const std::vector<tinyobj::material_t>& materials,
const std::string& materialpath);
ModelComponent loadModelComponent(
const tinyobj::shape_t&, const std::vector<tinyobj::material_t>& materials, const std::string& materialpath);
ModelComponent loadModelComponent(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords);
ModelComponent loadModelComponent(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords, const std::vector<float>& normals);
ModelComponent loadModelComponent(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords, const std::string& texturepath);
ModelComponent loadModelComponent(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords, const std::vector<float>& normals, const std::string& texturepath);
static GLuint loadVAO(const std::vector<float>& vertices, const std::vector<unsigned int>& indices);
static GLuint loadVAO(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords);
static GLuint loadVAO(const std::vector<float>& vertices, const std::vector<unsigned int>& indices,
const std::vector<float>& texCoords, const std::vector<float>& normals);
GLuint loadVAO(const tinyobj::shape_t&);
static GLuint loadCubemapTexture(const std::vector<std::string>& filenames);
GLuint loadTexture(const std::string& filepath);
GLuint loadDefaultTexture();
};