Repository navigation
Expand file tree
/
Copy pathtexture.cpp
More file actions
128 lines (99 loc) · 2.32 KB
/
Copy pathtexture.cpp
File metadata and controls
128 lines (99 loc) · 2.32 KB
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
#include "texture.h"
CTexture::CTexture()
{
glGenTextures(1, &this->name);
}
CTexture::~CTexture()
{
glDeleteTextures(1, &this->name);
this->name = -1;
}
GLuint CTexture::GetName()
{
return name;
}
#define BINDING_SIZE 32
CTexture* binded_textures[BINDING_SIZE] = { 0 };
int loop_binding_index = 0;
void CTexture::Bind(GLuint unit)
{
if (unit<GL_TEXTURE0 || unit>GL_TEXTURE31) {
for (int i = 0; i < BINDING_SIZE; i++) {
if (!binded_textures[i]) {
unit = GL_TEXTURE0 + i;
Bind(unit);
return;
}
}
}
if (unit<GL_TEXTURE0 || unit>GL_TEXTURE31) {
if (loop_binding_index > 31) {
loop_binding_index = 0;
}
unit = GL_TEXTURE0 + loop_binding_index;
loop_binding_index++;
Bind(unit);
return;
}
glActiveTexture(unit);
glBindTexture(GL_TEXTURE_2D, this->name);
this->binding = unit;
binded_textures[unit - GL_TEXTURE0] = this;
}
GLuint CTexture::Bind()
{
Bind(0);
return this->binding;
}
GLuint CTexture::GetBinding()
{
return this->binding;
}
inline void set_t2d_params() {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
Texture CTexture::Create(int width, int height)
{
auto T = Texture(new CTexture);
glBindTexture(GL_TEXTURE_2D, T->name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, NULL);
set_t2d_params();
return T;
}
Texture CTexture::CreateDepth(int width, int height)
{
auto T = Texture(new CTexture);
glBindTexture(GL_TEXTURE_2D, T->name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
set_t2d_params();
return T;
}
//
//CTextureBinding::CTextureBinding()
//{
//}
//
//
//CTextureBinding::~CTextureBinding()
//{
//}
//
//TextureUnit CTextureBinding::operator[](Texture texture)
//{
// auto v = this->unit[texture];
// if (v) {
// return v;
// }
//
// else {
// auto u = TextureUnit(this->unit.size()-1 + TextureUnit::TEXTURE0);
// this->unit[texture] = u;
// if (unit.size() > 8) {
// unit.
// }
// return u;
// }
//}