Subversion Repositories gelsvn

Rev

Rev 401 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 401 Rev 403
Line 8... Line 8...
8
 */
8
 */
9
#ifndef __MESHEDIT_RENDERER_H__
9
#ifndef __MESHEDIT_RENDERER_H__
10
#define __MESHEDIT_RENDERER_H__
10
#define __MESHEDIT_RENDERER_H__
11
 
11
 
12
#include <GL/glew.h>
12
#include <GL/glew.h>
13
#include "harmonics.h"
-
 
14
#include <GLGraphics/draw.h>
13
#include <GLGraphics/draw.h>
15
#include <GLGraphics/IDBufferWireFrameRenderer.h>
14
#include <GLGraphics/IDBufferWireFrameRenderer.h>
16
 
15
 
-
 
16
/** Ancestral class for Manifold rendering. Do not use directly. Its only purpose is to
-
 
17
	create a display list and remove it when the object is destroyed. This is an example
-
 
18
	of the RAII "resource acquisition is initialization" idiom */
17
class ManifoldRenderer
19
class ManifoldRenderer
18
	{
20
	{
19
	protected:
21
	protected:
20
		GLuint display_list;
22
		GLuint display_list;
21
	public:
23
	public:
Line 28... Line 30...
28
		{
30
		{
29
			glCallList(display_list);
31
			glCallList(display_list);
30
		}
32
		}
31
	};
33
	};
32
 
34
 
-
 
35
/** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
33
class NormalRenderer: public ManifoldRenderer
36
class NormalRenderer: public ManifoldRenderer
34
	{
37
	{
35
	public:
38
	public:
36
		NormalRenderer(HMesh::Manifold& m, bool flat)
39
		NormalRenderer(HMesh::Manifold& m, bool smooth)
37
		{
40
		{
38
			glNewList(display_list,GL_COMPILE);
41
			glNewList(display_list,GL_COMPILE);
39
			GLGraphics::draw(m,flat);
42
			GLGraphics::draw(m,smooth);
40
			glEndList();
43
			glEndList();
41
		}
44
		}
42
	};
45
	};
43
 
46
 
-
 
47
/** Wireframe rendering. This is a nasty complex class that relies on other classes. The trouble
-
 
48
	is that for non-triangle meshes, we need to use another approach than for triangle meshes.
-
 
49
	This class is really a front end for a couple of other classes. */
44
class WireframeRenderer: public ManifoldRenderer
50
class WireframeRenderer: public ManifoldRenderer
45
	{
51
	{
46
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
52
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
47
		
53
		
48
		int maximum_face_valency(HMesh::Manifold& m);
54
		int maximum_face_valency(HMesh::Manifold& m);
Line 56... Line 62...
56
		WireframeRenderer(HMesh::Manifold& m, bool flat);
62
		WireframeRenderer(HMesh::Manifold& m, bool flat);
57
		
63
		
58
		void draw();
64
		void draw();
59
	};
65
	};
60
 
66
 
-
 
67
/** SimpleShaderRenderer is a very basic class for drawing a Manifold with shading.
-
 
68
	It is a convenient way to draw a surface using vertex and fragment shaders since it takes
-
 
69
	care of initializing the shaders and producing a display list for the geometry. 
61
 
70
 
-
 
71
	Geometry shaders typically add more complexity and are left out of this class, so you cannot add a
-
 
72
	geometry shader.
-
 
73
	
-
 
74
	While this class can be used directly, the normal procedure is to inherit from SimpleShaderRenderer
-
 
75
	and then pass the shaders to the constructor. The strings defining the shaders would fit
-
 
76
	nicely as static constant strings (see e.g. ToonRenderer or GlazedRenderer) in your inherited class.
-
 
77
 
-
 
78
	If you need to define more attributes or uniforms, you need to take charge. Your inherited class's 
-
 
79
	constructor should then use the default constructor of SimpleShaderRenderer. You can call init_shaders
-
 
80
	to initialize the shaders and then compile the display list yourself with the needed uniforms and
-
 
81
	attributes - rather than calling compile_display_list which only puts vertices and normals in the list. 
-
 
82
 */
62
class HarmonicsRenderer: public ManifoldRenderer
83
class SimpleShaderRenderer: public ManifoldRenderer
63
	{
84
	{
-
 
85
	protected:
-
 
86
		GLuint prog,vs,fs;
-
 
87
 
-
 
88
		/// Compile the vertex and fragment shaders and link to form shader program.
-
 
89
		void init_shaders(const std::string& vss, 
-
 
90
						  const std::string& fss);
64
		
91
		
-
 
92
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
-
 
93
		void compile_display_list(HMesh::Manifold& m, bool smooth);
65
	public:
94
	public:
-
 
95
		
-
 
96
		/// This constructor simply calls init_shaders and then compile_display_list.
66
		HarmonicsRenderer(Harmonics* h)
97
		SimpleShaderRenderer(HMesh::Manifold& m, 
-
 
98
							bool smooth, 
-
 
99
							const std::string& vss, 
-
 
100
							const std::string& fss)
67
		{
101
		{
68
			glNewList(display_list,GL_COMPILE);
-
 
69
			if(h) h->draw();
102
			init_shaders(vss,fss);
70
			glEndList();
103
			compile_display_list(m, smooth);
71
		}
104
		}
72
	};
105
		
73
 
-
 
74
 
-
 
75
 
-
 
-
 
106
		/// This constructor does nothing. Use of you want to control shader program creation or display list generation
76
class SimpleShaderRenderer: public ManifoldRenderer
107
		SimpleShaderRenderer() {}
77
	{
108
		
78
		GLuint prog,vs,fs;
109
		/// Releases the program and shaders.
79
	public:
-
 
80
		SimpleShaderRenderer(HMesh::Manifold& m, const std::string& vss, const std::string& fss);
-
 
81
		~SimpleShaderRenderer()
110
		~SimpleShaderRenderer()
82
		{
111
		{
83
			glDeleteProgram(prog);
112
			glDeleteProgram(prog);
84
			glDeleteShader(vs);
113
			glDeleteShader(vs);
85
			glDeleteShader(fs);
114
			glDeleteShader(fs);
86
		}
115
		}
-
 
116
		
-
 
117
		/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
87
		virtual void draw();
118
		virtual void draw();
88
	
119
	
89
	};
120
	};
90
 
121
 
-
 
122
/** Render reflection lines. This class renders the object as if it is specular and inside
-
 
123
	an infinitely long, vertical cylinder with white strips (also vertical). Useful if you
-
 
124
	want to see whether the surface is smooth or has kinks. */
91
class ReflectionLineRenderer: public SimpleShaderRenderer
125
class ReflectionLineRenderer: public SimpleShaderRenderer
92
	{
126
	{
93
		const static std::string vss;
127
		const static std::string vss;
94
		const static std::string fss;
128
		const static std::string fss;
95
	public:
129
	public:
96
		ReflectionLineRenderer(HMesh::Manifold& m):
130
		ReflectionLineRenderer(HMesh::Manifold& m, bool smooth):
97
			SimpleShaderRenderer(m, vss, fss) {}
131
			SimpleShaderRenderer(m, smooth, vss, fss) {}
98
		
132
		
99
	};
133
	};
100
 
134
 
-
 
135
/** Render isophotes with respect to a lightsource in the eye. Useful if you
-
 
136
 want to see whether the surface is smooth or has kinks. */
101
class IsophoteLineRenderer: public SimpleShaderRenderer
137
class IsophoteLineRenderer: public SimpleShaderRenderer
102
	{
138
	{
103
		const static std::string vss;
139
		const static std::string vss;
104
		const static std::string fss;
140
		const static std::string fss;
105
	public:
141
	public:
106
		IsophoteLineRenderer(HMesh::Manifold& m):
142
		IsophoteLineRenderer(HMesh::Manifold& m, bool smooth):
107
		SimpleShaderRenderer(m, vss, fss) {}
143
		SimpleShaderRenderer(m, smooth, vss, fss) {}
108
		
144
		
109
	};
145
	};
110
 
146
 
-
 
147
/** The toon renderer simply quantizes the shading to give a toonish appearance
-
 
148
	with a fat black silhouette. */
-
 
149
 
111
class MetallicRenderer: public SimpleShaderRenderer
150
class ToonRenderer: public SimpleShaderRenderer
112
	{
151
	{
113
		const static std::string vss;
152
		const static std::string vss;
114
		const static std::string fss;
153
		const static std::string fss;
115
	public:
154
	public:
116
		MetallicRenderer(HMesh::Manifold& m):
155
		ToonRenderer(HMesh::Manifold& m, bool smooth):
117
		SimpleShaderRenderer(m, vss, fss) {}
156
		SimpleShaderRenderer(m, smooth, vss, fss) {}
118
		
157
		
119
	};
158
	};
120
 
159
 
-
 
160
/** Render like glazed ceramics. Looks cool. I will add more to this. */
121
class GlazedRenderer: public SimpleShaderRenderer
161
class GlazedRenderer: public SimpleShaderRenderer
122
	{
162
	{
-
 
163
		float bsphere_rad;
123
		const static std::string vss;
164
		const static std::string vss;
124
		const static std::string fss;
165
		const static std::string fss;
125
	public:
166
	public:
126
		GlazedRenderer(HMesh::Manifold& m):
167
		GlazedRenderer(HMesh::Manifold& m, bool smooth, float _bsphere_rad=1.0):
127
		SimpleShaderRenderer(m, vss, fss) {}
168
		SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
-
 
169
		void draw();
-
 
170
	};
-
 
171
 
-
 
172
/** Render a scalar field. Positive scalars are mapped to blue and negative to red.
-
 
173
	This class also has controls for gamma correction which is highly useful if the 
-
 
174
	scalars are mostly small or large and simply scaling to the 0-1 range does not 
-
 
175
	produce a good result. */
-
 
176
class ScalarFieldRenderer: public SimpleShaderRenderer
-
 
177
	{
-
 
178
		const static std::string vss;
-
 
179
		const static std::string fss;
-
 
180
	public:
-
 
181
		ScalarFieldRenderer(HMesh::Manifold& m, bool smooth,
-
 
182
							std::vector<double>& field, double max_val);
-
 
183
	};
-
 
184
 
-
 
185
/** Line fields are rendered by convolving a noise function in the direction of the line.
-
 
186
	This is useful, for instance, for curvature rendering. */
-
 
187
class LineFieldRenderer: public SimpleShaderRenderer
128
		
188
	{
-
 
189
		const static std::string vss;
-
 
190
		const static std::string fss;
-
 
191
		float r;
-
 
192
	public:
-
 
193
		LineFieldRenderer(HMesh::Manifold& m, bool smooth, std::vector<CGLA::Vec3d>& lines, float _r);
-
 
194
		void draw();
129
	};
195
	};
130
 
196
 
131
 
197
 
132
 
198
 
133
#endif
199
#endif
134
 
200