File: texture.hpp

package info (click to toggle)
python-visual 1%3A5.12-1.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,672 kB
  • ctags: 7,636
  • sloc: cpp: 15,593; sh: 9,615; ansic: 6,631; python: 4,737; makefile: 385
file content (102 lines) | stat: -rw-r--r-- 2,847 bytes parent folder | download | duplicates (3)
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
#ifndef VPYTHON_UTIL_TEXTURE_HPP
#define VPYTHON_UTIL_TEXTURE_HPP

// 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 <string>
#include <boost/shared_ptr.hpp>
#include "util/gl_free.hpp"
#include "util/thread.hpp"
#include "wrap_gl.hpp"

namespace cvisual {

using boost::shared_ptr;

/** A class to assist in managing OpenGL texture resources.
*/
class texture
{
 private:
	bool damaged;
	unsigned int handle;

 public:
	/** Release the handle to OpenGL.  Subclasses must not call
 		glDeleteTextures() on this class's handle.
	*/
	virtual ~texture();

	/** True iff the texture object is managing something. */
	// operator bool() const;

	/** Make this texture active.  This function constitutes use under the
		"initialize on first use" rule, and will incur a one-time speed and
 		continuous graphics memory penalty.  Precondition: an OpenGL context
		must be active.
	*/
	void gl_activate(const struct view& scene);

	/** Determine whether or not this texture has an opacity channel.
		@returns True iff there is an opacity channel for this texture.
	*/
	bool has_opacity() const;

	/** Returns e.g. GL_TEXTURE_2D - the thing to be enabled to make this texture
	    work with the fixed function pipeline.
	*/
	virtual int enable_type() const;

 protected:
	// A unique identifier for the texture, to be obtained from glGenTextures().
	bool have_opacity;

	// Perform zero initialization of POD members.
	texture();

	// Make this class noncopyable.
	texture( const texture&);
	const texture& operator=( const texture&);

	// Sets handle and registers it to be freed at shutdown
	void set_handle( const view&, unsigned int handle );
	unsigned get_handle() { return handle; }

	// Called by gl_activate() on the first use and whenever damaged.
	// Postcondition: handle refers to an initialized OpenGL texture object.
	virtual void gl_init(const view&) = 0;

	// Perform any texture transformation matrix initialization that might be
	// required.  Default: do nothing.
	// This function must assume that the active matrix is GL_MODELVIEW and must
	// return in that state.
	virtual void gl_transform();

	// This function will be called by gl_activate() so that subclasses can
	// detect asynchronous changes to themselves
	virtual void damage_check();

	// Mutable subclasses must call this function whenever their texture data
	// needs to be reloaded into OpenGL.
	void damage();

 public:
 	// Should be protected; makeing this public works around a GCC 3.4.2 bug
	static void gl_free( GLuint handle );
};



#ifdef __GNUC__
#define PURE __attribute__((pure))
#else
#define PURE
#endif

size_t next_power_of_two(size_t arg) PURE ;

} // !namespace cvisual

#endif // !defined VPYTHON_UTIL_TEXTURE_HPP