File: displaylist.h

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (151 lines) | stat: -rw-r--r-- 4,621 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
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
#ifndef VISUAL_DISPLAYLIST_H
#define VISUAL_DISPLAYLIST_H

// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.

#include "cvisual.h"
#include <boost/weak_ptr.hpp>
#include <boost/python/object.hpp>
#include "vcache.h"
#include "tmatrix.h"
#include "light.h"
#include "color.h"

#include "display.h"

namespace visual {

struct rView 
{
	tmatrix wct;
	lighting lights;
	struct glContext& cx;

	tmatrix fwt;   // frame-to-world (for extent calculations)
	double min_extent[3];
	double max_extent[3];
	bool anaglyph;
	bool coloranaglyph;

	std::vector<int> sortlists;

	rView( const tmatrix& _wct, const lighting& _lights,
	       const tmatrix& _fwt, struct glContext& _cx,
	       const vector& mine, const vector& maxe,
		   const bool _anaglyph, const bool _coloranaglyph);
	~rView();

	void ext_set(const vector& mine, const vector& maxe);
	void ext_brect(const tmatrix& mwt, vector bmin, vector bmax);
	void ext_brect(const tmatrix& mft, const double *b);
	void ext_point(vector v);
	void ext_sphere(vector v, double size);
	void ext_circle(vector p, vector n, double r);

	void absorb_local( rView& local );

	int createSortList();
	// returns an OpenGL display list number that can be used to store
	//   rendering commands to be rendered after all opaque objects have
	//   been drawn.  At some point there may be depth sorting support as
	//   well.
	// Usage:
	//   glNewList( view.createSortList(), GL_COMPILE);
	//   ...
	//   glEndList();
};

class frame;

// This class implements the minimum subset of information required by all
// drawable objects in Visual.
class DisplayObject : public Cache
{
 public:
	DisplayObject();
	DisplayObject( const DisplayObject& other);
	virtual ~DisplayObject();

	// Called by gldevice to render the object.
	virtual void glRender(rView&);
	
	// Used to determine if a vector coming from the screen position camera
	// in the direction of ray intersects this object, and returns the distance
	// between camera and the point of intersection.
	virtual double rayIntersect( const vector &camera, const vector &ray);


	// Used by frame to provide an extra coordinate transformation for the frame's
	// children.  It must return an orthogonal matrix.
	virtual tmatrix getChildTransform();

	// Return the frame which owns this object, possibly NULL.
	boost::shared_ptr<frame> getParent();
	
	// Return, to Python, the frame which owns this object, possibly PyNONE.
	boost::python::object py_get_parent();
	
	// Make this object a child of a particular frame.
	void setParent( boost::shared_ptr<frame> m_frame);
	
	// Returns the PyObject* corrisponding to this particular object.  This is
	// used to return a pointer to an already-wrapped object while retaining its
	// identity.  visual::Display uses this to return a heterogeneous list of 
	// objects without having to perform explicit downcasts (it only sees 
	// DisplayObjects)
	boost::python::object getObject() { return self; }

	// Initialize or reset this DisplayObject to a particular OpenGL display.
	void set_display( boost::shared_ptr<Display> d);
	
	// Get the display that this object is being rendered into.
	boost::shared_ptr<Display> get_display() const;
	boost::python::object py_get_display() const;

	// This class performs final initialization of the DisplayObject that cannot
	// be performed within the constructor.
	void
	py_complete_init( 
		boost::shared_ptr<DisplayObject> cpp_self, 
		boost::python::object py_self,
		bool _visible,
		boost::shared_ptr<Display> _display,
		boost::shared_ptr<frame> _parent);
	
	// Export a lock/unlock interface to Python for new rendering primitives.
	// Not used at this time.
	inline void py_read_lock() { mtx.sync_lock(); }
	inline void py_write_lock() { mtx.count_lock(); }
	inline void py_unlock() { mtx.sync_unlock(); }
	
	// Get/set the visibility property of this DisplayObject.
	bool get_visible() const;
	void set_visible( bool vis);

 protected:
	bool visible;
	rgb color;
	boost::shared_ptr<Display> display;
	boost::shared_ptr<frame> parent;

	// The PyObject* for this object.
	boost::python::object self;
	// operate on the linked list held by display.
	boost::weak_ptr<DisplayObject> weak_this;

 private:
	// Encapsulates the code required to insert and remove one of these buggars
	// from the displaylist, including working aroud some complex locking symantics.
	void insert();
	void remove();

	friend class Display;
	friend class GLDevice;
};

} // !namespace visual


#endif // !VISUAL_DISPLAYLIST_H