-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtexture.cpp
More file actions
101 lines (84 loc) · 1.74 KB
/
Copy pathtexture.cpp
File metadata and controls
101 lines (84 loc) · 1.74 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
// Copyright (c) 2004 by Jonathan Brandmeyer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
#include "wrap_gl.hpp"
#include "util/texture.hpp"
#include "util/errors.hpp"
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
using boost::lexical_cast;
namespace cvisual {
texture::texture()
: damaged(false), handle(0), have_opacity(false)
{
}
texture::~texture()
{
if (handle) on_gl_free.free( boost::bind( &gl_free, handle ) );
}
#if 0
texture::operator bool() const
{
return handle != 0;
}
#endif
int
texture::enable_type() const {
return GL_TEXTURE_2D;
}
void
texture::gl_activate(const view& v)
{
damage_check();
if (damaged) {
gl_init(v);
damaged = false;
check_gl_error();
}
if (!handle) return;
glBindTexture( enable_type(), handle );
this->gl_transform();
check_gl_error();
}
bool
texture::has_opacity() const
{
return have_opacity;
}
void
texture::set_handle( const view&, unsigned h ) {
if (handle) on_gl_free.free( boost::bind( &gl_free, handle ) );
handle = h;
on_gl_free.connect( boost::bind(&texture::gl_free, handle) );
VPYTHON_NOTE( "Allocated texture number " + lexical_cast<std::string>(handle));
}
void
texture::gl_free(GLuint handle)
{
VPYTHON_NOTE( "Deleting texture number " + lexical_cast<std::string>(handle));
glDeleteTextures(1, &handle);
}
void
texture::gl_transform()
{
}
void
texture::damage_check()
{
}
void
texture::damage()
{
damaged = true;
}
size_t
next_power_of_two(size_t arg)
{
size_t ret = 2;
// upper bound of 28 chosen to limit memory growth to about 256MB, which is
// _much_ larger than most supported textures
while (ret < arg && ret < (1 << 28))
ret <<= 1;
return ret;
}
} // !namespace cvisual