-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtexture.h
67 lines (55 loc) · 1.48 KB
/
gtexture.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
#ifndef GTEXTURE_H
#define GTEXTURE_H
#include "gmath.h"
#include "gcolor.h"
#include "tgaimage.h"
using std::shared_ptr;
using std::make_shared;
class GTexture
{
public:
~GTexture() = default;
virtual GFColor sample(double u, double v, const GMath::vec3& p) const =0;
GFColor sample(const GMath::vec2& uv, const GMath::vec3& p)
{
return this->sample(uv.x(), uv.y(), p);
}
};
class GSolidColor : public GTexture
{
public:
GSolidColor(GFColor c):color(c){}
GSolidColor(float r, float g, float b, float a=1):color(r,g,b,a){}
GFColor sample(double u, double v, const GMath::vec3& p) const override
{
return color;
}
private:
GFColor color;
};
class GCheckerTexture:public GTexture
{
public:
GCheckerTexture(double scale, shared_ptr<GTexture> even, shared_ptr<GTexture> odd)
:invScale(1/scale), even(even), odd(odd)
{}
GCheckerTexture(double scale, GFColor even, GFColor odd)
:invScale(1/scale), even(make_shared<GSolidColor>(even)), odd(make_shared<GSolidColor>(odd))
{}
GFColor sample(double u, double v, const GMath::vec3& p)const override;
private:
double invScale;
shared_ptr<GTexture> even;
shared_ptr<GTexture> odd;
};
class GImageTexture : public GTexture
{
public:
GImageTexture(const char* filepath);
GImageTexture(TGAImage image);
GFColor sample(double u, double v, const GMath::vec3& p)const override;
private:
bool error = false;
TGAImage image;
};
#endif // GTEXTURE_H