gpuray_glsl

view src/texture.h @ 3:297dbc5080c4

cone intersection
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 09 Nov 2014 20:13:33 +0200
parents
children
line source
1 #ifndef TEXTURE_H_
2 #define TEXTURE_H_
4 #include <string>
5 #include "image.h"
7 struct HitPoint;
9 class Texture {
10 public:
11 enum class SampleMode { nearest, linear };
12 enum class WrapMode { clamp, repeat };
14 protected:
15 std::string name;
17 SampleMode sampling;
18 WrapMode wrapping;
20 public:
21 Texture();
22 virtual ~Texture();
24 virtual void set_name(const char *name);
25 virtual const char *get_name() const;
27 virtual Image *get_image(int idx = 0) = 0;
28 virtual const Image *get_image(int idx = 0) const = 0;
30 virtual void set_sampling_mode(SampleMode mode);
31 virtual SampleMode get_sampling_mode() const;
32 virtual void set_wrapping_mode(WrapMode mode);
33 virtual WrapMode get_wrapping_mode() const;
35 virtual bool load(const char *fname) = 0;
37 virtual Color sample(float u, float v, float w) const = 0;
38 virtual Color sample(const HitPoint &hit) const;
39 };
41 class Texture2D : public Texture {
42 private:
43 Image img;
45 public:
46 virtual Image *get_image(int idx = 0);
47 virtual const Image *get_image(int idx = 0) const;
49 virtual bool load(const char *fname);
51 virtual Color sample(float u, float v, float w) const;
53 friend Texture *load_texture(const char *fname);
54 };
56 class TextureCube : public Texture {
57 private:
58 Image img[6];
60 public:
61 TextureCube();
63 virtual Image *get_image(int idx = 0);
64 virtual const Image *get_image(int idx = 0) const;
66 virtual bool load(const char *fname);
68 virtual Color sample(float u, float v, float w) const;
69 virtual Color sample(const HitPoint &hit) const;
71 friend Texture *load_texture(const char *fname);
72 };
74 Texture *load_texture(const char *fname);
76 #endif // TEXTURE_H_