File: texture.h

package info (click to toggle)
meshlab 2020.09%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 45,132 kB
  • sloc: cpp: 400,238; ansic: 31,952; javascript: 1,578; sh: 387; yacc: 238; lex: 139; python: 86; makefile: 30
file content (235 lines) | stat: -rw-r--r-- 5,033 bytes parent folder | download | duplicates (6)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#ifndef GLW_TEXTURE_H
#define GLW_TEXTURE_H

#include "./renderable.h"

namespace glw
{

class TextureSampleMode
{
	public:

		typedef void              BaseType;
		typedef TextureSampleMode ThisType;

		GLenum minFilter;
		GLenum magFilter;
		GLenum wrapS;
		GLenum wrapT;
		GLenum wrapR;

		TextureSampleMode(void)
		{
			this->clear();
		}

		TextureSampleMode(GLenum rMinFilter, GLenum rMagFilter, GLenum rWrapS, GLenum rWrapT, GLenum rWrapR)
			: minFilter (rMinFilter)
			, magFilter (rMagFilter)
			, wrapS     (rWrapS)
			, wrapT     (rWrapT)
			, wrapR     (rWrapR)
		{
			;
		}

		void clear(void)
		{
			this->minFilter = GLW_DONT_CARE;
			this->magFilter = GLW_DONT_CARE;
			this->wrapS     = GLW_DONT_CARE;
			this->wrapT     = GLW_DONT_CARE;
			this->wrapR     = GLW_DONT_CARE;
		}

		static TextureSampleMode dontCare(void)
		{
			return ThisType();
		}

		static TextureSampleMode texelFetch(void)
		{
			return ThisType(GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
		}
};

inline TextureSampleMode textureSampleMode(GLenum minFilter = GLW_DONT_CARE, GLenum magFilter = GLW_DONT_CARE, GLenum wrapS = GLW_DONT_CARE, GLenum wrapT = GLW_DONT_CARE, GLenum wrapR = GLW_DONT_CARE)
{
	return TextureSampleMode(minFilter, magFilter, wrapS, wrapT, wrapR);
}

class TextureArguments : public RenderableArguments
{
	public:

		typedef RenderableArguments BaseType;
		typedef TextureArguments    ThisType;

		TextureArguments(void)
		{
			this->clear();
		}

		void clear(void)
		{
			BaseType::clear();
		}
};

class Texture : public Renderable
{
	friend class Context;

	public:

		typedef Renderable  BaseType;
		typedef Texture     ThisType;

		virtual ~Texture(void)
		{
			this->destroy();
		}

	protected:

		Texture(Context * ctx)
			: BaseType(ctx)
		{
			;
		}

		virtual void doDestroy(void)
		{
			glDeleteTextures(1, &(this->m_name));
		}
};

namespace detail { template <> struct BaseOf <Texture> { typedef Renderable Type; }; };
typedef   detail::ObjectSharedPointerTraits  <Texture> ::Type TexturePtr;

class SafeTexture : public SafeRenderable
{
	friend class Context;
	friend class BoundTexture;

	public:

		typedef SafeRenderable   BaseType;
		typedef SafeTexture ThisType;

		SafeTexture(void)
			: BaseType()
		{
			;
		}

	protected:

		SafeTexture(const TexturePtr & texture)
			: BaseType(texture)
		{
			;
		}

		const TexturePtr & object(void) const
		{
			return static_cast<const TexturePtr &>(BaseType::object());
		}

		TexturePtr & object(void)
		{
			return static_cast<TexturePtr &>(BaseType::object());
		}
};

namespace detail { template <> struct BaseOf     <SafeTexture> { typedef SafeRenderable   Type; }; };
namespace detail { template <> struct ObjectBase <SafeTexture> { typedef Texture     Type; }; };
namespace detail { template <> struct ObjectSafe <Texture    > { typedef SafeTexture Type; }; };
typedef   detail::ObjectSharedPointerTraits      <SafeTexture> ::Type TextureHandle;

class TextureBindingParams : public RenderableBindingParams
{
	public:

		typedef RenderableBindingParams   BaseType;
		typedef TextureBindingParams ThisType;

		TextureBindingParams(void)
			: BaseType()
		{
			;
		}

		TextureBindingParams(GLenum aTarget, GLenum aUnit)
			: BaseType(aTarget, aUnit)
		{
			;
		}
};

class BoundTexture : public BoundRenderable
{
	friend class Context;

	public:

		typedef BoundRenderable   BaseType;
		typedef BoundTexture ThisType;

		BoundTexture(void)
			: BaseType()
		{
			;
		}

		const TextureHandle & handle(void) const
		{
			return static_cast<const TextureHandle &>(BaseType::handle());
		}

		TextureHandle & handle(void)
		{
			return static_cast<TextureHandle &>(BaseType::handle());
		}

	protected:

		BoundTexture(const TextureHandle & handle, const TextureBindingParams & params)
			: BaseType(handle, params)
		{
			;
		}

		const TexturePtr & object(void) const
		{
			return this->handle()->object();
		}

		TexturePtr & object(void)
		{
			return this->handle()->object();
		}

		virtual void bind(void)
		{
			glActiveTexture(GL_TEXTURE0 + this->m_unit);
			glBindTexture(this->m_target, this->object()->name());
		}

		virtual void unbind(void)
		{
			glActiveTexture(GL_TEXTURE0 + this->m_unit);
			glBindTexture(this->m_target, 0);
		}
};

namespace detail { template <> struct ParamsOf    <BoundTexture> { typedef TextureBindingParams Type; }; };
namespace detail { template <> struct BaseOf      <BoundTexture> { typedef BoundObject Type; }; };
namespace detail { template <> struct ObjectBase  <BoundTexture> { typedef Texture      Type; }; };
namespace detail { template <> struct ObjectBound <Texture     > { typedef BoundTexture Type; }; };
typedef   detail::ObjectSharedPointerTraits       <BoundTexture> ::Type  BoundTextureHandle;

};

#endif // GLW_TEXTURE_H