/
texture.hpp
88 lines (76 loc) · 2.99 KB
/
texture.hpp
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
#pragma once
#include "glid.hpp"
#include "textureOptions.hpp"
namespace gldr{
template <textureOptions::Dimension dimension>
struct Texture{
void bind() const{
if(textureID.get()){
gl::BindTexture(static_cast<GLenum>(dimension), textureID.get());
}
}
void bind(unsigned textureUnit) const{ // possibly go for boost::optional
gl::ActiveTexture(gl::TEXTURE0 + textureUnit);
bind();
}
void setFiltering(textureOptions::FilterDirection direction, textureOptions::FilterMode mode){
if(textureID.get()){
bind();
gl::TexParameteri(static_cast<GLenum>(dimension), static_cast<GLenum>(direction), static_cast<GLint>(mode));
}
}
void setWrapMode(textureOptions::WrapDirection direction, textureOptions::WrapMode mode){
if(textureID.get()){
bind();
gl::TexParameteri(static_cast<GLenum>(dimension), static_cast<GLenum>(direction), static_cast<GLint>(mode));
}
}
inline void imageData(unsigned width, unsigned height,
textureOptions::Format format, textureOptions::InternalFormat internalFormat,
textureOptions::DataType dataType, const void* data);
static GLuint create(){
GLuint id;
gl::GenTextures(1, &id);
return id;
}
static void destroy(GLuint& id){
gl::DeleteTextures(1, &id);
}
private:
Glid<Texture<dimension>> textureID;
};
template<>
inline void Texture<textureOptions::Dimension::Texture_1D>::imageData(unsigned width, unsigned height,
textureOptions::Format format, textureOptions::InternalFormat internalFormat,
textureOptions::DataType dataType, const void* data){
gl::TexImage1D(
gl::TEXTURE_1D, 0,
static_cast<GLint>(internalFormat),
width, height, 0,
static_cast<GLenum>(format), data);
}
template<>
inline void Texture<textureOptions::Dimension::Texture_2D>::imageData(unsigned width, unsigned height,
textureOptions::Format format, textureOptions::InternalFormat internalFormat,
textureOptions::DataType dataType, const void* data){
gl::TexImage2D(
gl::TEXTURE_2D, 0,
static_cast<GLint>(internalFormat),
width, height, 0,
static_cast<GLenum>(format), gl::UNSIGNED_BYTE, data);
}
template<>
inline void Texture<textureOptions::Dimension::Texture_3D>::imageData(unsigned width, unsigned height,
textureOptions::Format format, textureOptions::InternalFormat internalFormat,
textureOptions::DataType dataType, const void* data){
/*gl::TexImage3D(
gl::TEXTURE_3D, 0,
static_cast<GLint>(internalFormat),
width, height, 0, 0,
static_cast<GLenum>(format),
static_cast<GLenum>(dataType), data);*/
}
typedef Texture<textureOptions::Dimension::Texture_1D> Texture1d;
typedef Texture<textureOptions::Dimension::Texture_2D> Texture2d;
typedef Texture<textureOptions::Dimension::Texture_3D> Texture3d;
}