Subversion Repositories gelsvn

Rev

Rev 406 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 406 Rev 456
1
/*
1
/*
2
 *  ManifoldRenderer.h
2
 *  ManifoldRenderer.h
3
 *  GEL
3
 *  GEL
4
 *
4
 *
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
5
 *  Created by J. Andreas Bærentzen on 20/09/08.
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
6
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
7
 *
7
 *
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 <GLGraphics/draw.h>
13
#include <GLGraphics/draw.h>
14
#include <GLGraphics/IDBufferWireFrameRenderer.h>
14
#include <GLGraphics/IDBufferWireFrameRenderer.h>
-
 
15
#include <CGLA/Vec4d.h>
15
 
16
 
16
/** Ancestral class for Manifold rendering. Do not use directly. Its only purpose is to
17
/** 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
	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 */
19
	of the RAII "resource acquisition is initialization" idiom */
19
class ManifoldRenderer
20
class ManifoldRenderer
20
	{
21
	{
21
	protected:
22
	protected:
22
		GLuint display_list;
23
		GLuint display_list;
23
	public:
24
	public:
24
		ManifoldRenderer(): display_list(glGenLists(1))	{}
25
		ManifoldRenderer(): display_list(glGenLists(1))	{}
25
		virtual ~ManifoldRenderer()
26
		virtual ~ManifoldRenderer()
26
		{
27
		{
27
			glDeleteLists(display_list, 1);
28
			glDeleteLists(display_list, 1);
28
		}
29
		}
29
		virtual void draw()
30
		virtual void draw()
30
		{
31
		{
31
			glCallList(display_list);
32
			glCallList(display_list);
32
		}
33
		}
33
	};
34
	};
34
 
35
 
35
/** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
36
/** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
36
class NormalRenderer: public ManifoldRenderer
37
class NormalRenderer: public ManifoldRenderer
37
	{
38
	{
38
	public:
39
	public:
39
		NormalRenderer(HMesh::Manifold& m, bool smooth)
40
		NormalRenderer(HMesh::Manifold& m, bool smooth)
40
		{
41
		{
41
			glNewList(display_list,GL_COMPILE);
42
			glNewList(display_list,GL_COMPILE);
42
			GLGraphics::draw(m,smooth);
43
			GLGraphics::draw(m,smooth);
43
			glEndList();
44
			glEndList();
44
		}
45
		}
45
	};
46
	};
46
 
47
 
47
/** Wireframe rendering. This is a nasty complex class that relies on other classes. The trouble
48
/** 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
	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. */
50
	This class is really a front end for a couple of other classes. */
50
class WireframeRenderer: public ManifoldRenderer
51
class WireframeRenderer: public ManifoldRenderer
51
	{
52
	{
52
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
53
		GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
53
		
54
		
54
		int maximum_face_valency(HMesh::Manifold& m);
55
		int maximum_face_valency(HMesh::Manifold& m);
55
		
56
		
56
	public:
57
	public:
57
		~WireframeRenderer()
58
		~WireframeRenderer()
58
		{
59
		{
59
			delete idbuff_renderer;
60
			delete idbuff_renderer;
60
		}
61
		}
61
		
62
		
62
		WireframeRenderer(HMesh::Manifold& m, bool flat);
63
		WireframeRenderer(HMesh::Manifold& m, bool flat);
63
		
64
		
64
		void draw();
65
		void draw();
65
	};
66
	};
66
 
67
 
67
/** SimpleShaderRenderer is a very basic class for drawing a Manifold with shading.
68
/** 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
	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. 
70
	care of initializing the shaders and producing a display list for the geometry. 
70
 
71
 
71
	Geometry shaders typically add more complexity and are left out of this class, so you cannot add a
72
	Geometry shaders typically add more complexity and are left out of this class, so you cannot add a
72
	geometry shader.
73
	geometry shader.
73
	
74
	
74
	While this class can be used directly, the normal procedure is to inherit from SimpleShaderRenderer
75
	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
	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
	nicely as static constant strings (see e.g. ToonRenderer or GlazedRenderer) in your inherited class.
77
 
78
 
78
	If you need to define more attributes or uniforms, you need to take charge. Your inherited class's 
79
	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
	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
	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
	attributes - rather than calling compile_display_list which only puts vertices and normals in the list. 
82
 */
83
 */
83
class SimpleShaderRenderer: public ManifoldRenderer
84
class SimpleShaderRenderer: public ManifoldRenderer
84
	{
85
	{
85
		/// Compile the vertex and fragment shaders and link to form shader program.
86
		/// Compile the vertex and fragment shaders and link to form shader program.
86
		void init_shaders(const std::string& vss, 
87
		void init_shaders(const std::string& vss, 
87
						  const std::string& fss);
88
						  const std::string& fss);
88
		
89
		
89
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
90
		/// Produce a display list containing geometry and normals (which may be smooth or per face).
90
		void compile_display_list(HMesh::Manifold& m, bool smooth);
91
		void compile_display_list(HMesh::Manifold& m, bool smooth);
91
 
92
 
92
	protected:
93
	protected:
93
 
94
 
94
		GLuint prog,vs,fs;
95
		GLuint prog,vs,fs;
95
 
96
 
96
	public:
97
	public:
97
		
98
		
98
		/// This constructor simply calls init_shaders and then compile_display_list.
99
		/// This constructor simply calls init_shaders and then compile_display_list.
99
		SimpleShaderRenderer(HMesh::Manifold& m, 
100
		SimpleShaderRenderer(HMesh::Manifold& m, 
100
							bool smooth, 
101
							bool smooth, 
101
							const std::string& vss, 
102
							const std::string& vss, 
102
							const std::string& fss)
103
							const std::string& fss)
103
		{
104
		{
104
			init_shaders(vss,fss);
105
			init_shaders(vss,fss);
105
			compile_display_list(m, smooth);
106
			compile_display_list(m, smooth);
106
		}
107
		}
107
		
108
		
108
		/** This constructor simply initializes the shaders. It does not create the display list.
109
		/** This constructor simply initializes the shaders. It does not create the display list.
109
			Use if you shader has extra attributes. */
110
			Use if you shader has extra attributes. */
110
		SimpleShaderRenderer(const std::string& vss, 
111
		SimpleShaderRenderer(const std::string& vss, 
111
							 const std::string& fss) {init_shaders(vss,fss);}
112
							 const std::string& fss) {init_shaders(vss,fss);}
112
		
113
		
113
		/// Releases the program and shaders.
114
		/// Releases the program and shaders.
114
		~SimpleShaderRenderer()
115
		~SimpleShaderRenderer()
115
		{
116
		{
116
			glDeleteProgram(prog);
117
			glDeleteProgram(prog);
117
			glDeleteShader(vs);
118
			glDeleteShader(vs);
118
			glDeleteShader(fs);
119
			glDeleteShader(fs);
119
		}
120
		}
120
		
121
		
121
		/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
122
		/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
122
		virtual void draw();
123
		virtual void draw();
123
	
124
	
124
	};
125
	};
125
 
126
 
126
/** Render reflection lines. This class renders the object as if it is specular and inside
127
/** Render reflection lines. This class renders the object as if it is specular and inside
127
	an infinitely long, vertical cylinder with white strips (also vertical). Useful if you
128
	an infinitely long, vertical cylinder with white strips (also vertical). Useful if you
128
	want to see whether the surface is smooth or has kinks. */
129
	want to see whether the surface is smooth or has kinks. */
129
class ReflectionLineRenderer: public SimpleShaderRenderer
130
class ReflectionLineRenderer: public SimpleShaderRenderer
130
	{
131
	{
131
		const static std::string vss;
132
		const static std::string vss;
132
		const static std::string fss;
133
		const static std::string fss;
133
	public:
134
	public:
134
		ReflectionLineRenderer(HMesh::Manifold& m, bool smooth):
135
		ReflectionLineRenderer(HMesh::Manifold& m, bool smooth):
135
			SimpleShaderRenderer(m, smooth, vss, fss) {}
136
			SimpleShaderRenderer(m, smooth, vss, fss) {}
136
		
137
		
137
	};
138
	};
138
 
139
 
139
/** Render isophotes with respect to a lightsource in the eye. Useful if you
140
/** Render isophotes with respect to a lightsource in the eye. Useful if you
140
 want to see whether the surface is smooth or has kinks. */
141
 want to see whether the surface is smooth or has kinks. */
141
class IsophoteLineRenderer: public SimpleShaderRenderer
142
class IsophoteLineRenderer: public SimpleShaderRenderer
142
	{
143
	{
143
		const static std::string vss;
144
		const static std::string vss;
144
		const static std::string fss;
145
		const static std::string fss;
145
	public:
146
	public:
146
		IsophoteLineRenderer(HMesh::Manifold& m, bool smooth):
147
		IsophoteLineRenderer(HMesh::Manifold& m, bool smooth):
147
		SimpleShaderRenderer(m, smooth, vss, fss) {}
148
		SimpleShaderRenderer(m, smooth, vss, fss) {}
148
		
149
		
149
	};
150
	};
150
 
151
 
151
/** The toon renderer simply quantizes the shading to give a toonish appearance
152
/** The toon renderer simply quantizes the shading to give a toonish appearance
152
	with a fat black silhouette. */
153
	with a fat black silhouette. */
153
 
154
 
154
class ToonRenderer: public SimpleShaderRenderer
155
class ToonRenderer: public SimpleShaderRenderer
155
	{
156
	{
156
		const static std::string vss;
157
		const static std::string vss;
157
		const static std::string fss;
158
		const static std::string fss;
158
	public:
159
	public:
159
		ToonRenderer(HMesh::Manifold& m, bool smooth):
160
		ToonRenderer(HMesh::Manifold& m, bool smooth):
160
		SimpleShaderRenderer(m, smooth, vss, fss) {}
161
		SimpleShaderRenderer(m, smooth, vss, fss) {}
161
		
162
		
162
	};
163
	};
163
 
164
 
164
/** Render like glazed ceramics. Looks cool. I will add more to this. */
165
/** Render like glazed ceramics. Looks cool. I will add more to this. */
165
class GlazedRenderer: public SimpleShaderRenderer
166
class GlazedRenderer: public SimpleShaderRenderer
166
	{
167
	{
167
		float bsphere_rad;
168
		float bsphere_rad;
168
		const static std::string vss;
169
		const static std::string vss;
169
		const static std::string fss;
170
		const static std::string fss;
170
	public:
171
	public:
171
		GlazedRenderer(HMesh::Manifold& m, bool smooth, float _bsphere_rad=1.0):
172
		GlazedRenderer(HMesh::Manifold& m, bool smooth, float _bsphere_rad=1.0):
172
		SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
173
		SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
173
		void draw();
174
		void draw();
174
	};
175
	};
175
 
176
 
176
/** Render a scalar field. Positive scalars are mapped to blue and negative to red.
177
/** Render a scalar field. Positive scalars are mapped to blue and negative to red.
177
	This class also has controls for gamma correction which is highly useful if the 
178
	This class also has controls for gamma correction which is highly useful if the 
178
	scalars are mostly small or large and simply scaling to the 0-1 range does not 
179
	scalars are mostly small or large and simply scaling to the 0-1 range does not 
179
	produce a good result. */
180
	produce a good result. */
180
class ScalarFieldRenderer: public SimpleShaderRenderer
181
class ScalarFieldRenderer: public SimpleShaderRenderer
181
	{
182
	{
182
		const static std::string vss;
183
		const static std::string vss;
183
		const static std::string fss;
184
		const static std::string fss;
184
	public:
185
	public:
185
		ScalarFieldRenderer(HMesh::Manifold& m, bool smooth,
186
		ScalarFieldRenderer(HMesh::Manifold& m, bool smooth,
186
							std::vector<double>& field, double max_val);
187
							std::vector<double>& field, double max_val);
187
	};
188
	};
188
 
189
 
189
/** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
190
/** Ambient occlusion renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
190
	mean curvatures which in some sense indicate how concave the surface is.*/
191
	mean curvatures which in some sense indicate how concave the surface is.*/
191
class AmbientOcclusionRenderer: public SimpleShaderRenderer
192
class AmbientOcclusionRenderer: public SimpleShaderRenderer
192
	{
193
	{
193
		const static std::string vss;
194
		const static std::string vss;
194
		const static std::string fss;
195
		const static std::string fss;
195
	public:
196
	public:
196
		AmbientOcclusionRenderer(HMesh::Manifold& m, bool smooth,
197
		AmbientOcclusionRenderer(HMesh::Manifold& m, bool smooth,
197
							std::vector<double>& field, double max_val);
198
							std::vector<double>& field, double max_val);
198
	};
199
	};
199
 
200
 
200
/** Patina renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
201
/** Patina renderer. Very similar to ScalarFieldRender. Simply assumes that the input values are
201
 mean curvatures which in some sense indicate how concave the surface is.*/
202
 mean curvatures which in some sense indicate how concave the surface is.*/
202
class CopperRenderer: public SimpleShaderRenderer
203
class CopperRenderer: public SimpleShaderRenderer
203
	{
204
	{
204
		const static std::string vss;
205
		const static std::string vss;
205
		const static std::string fss;
206
		const static std::string fss;
206
		float bsphere_rad;
207
		float bsphere_rad;
207
	public:
208
	public:
208
		CopperRenderer(HMesh::Manifold& m, bool smooth,
209
		CopperRenderer(HMesh::Manifold& m, bool smooth,
209
								 std::vector<double>& field, double max_val, float _bsphere_rad);
210
								 std::vector<double>& field, double max_val, float _bsphere_rad);
210
		void draw();
211
		void draw();
211
	};
212
	};
212
 
213
 
213
 
214
 
214
/** Line fields are rendered by convolving a noise function in the direction of the line.
215
/** Line fields are rendered by convolving a noise function in the direction of the line.
215
	This is useful, for instance, for curvature rendering. */
216
	This is useful, for instance, for curvature rendering. */
216
class LineFieldRenderer: public SimpleShaderRenderer
217
class LineFieldRenderer: public SimpleShaderRenderer
217
	{
218
	{
218
		const static std::string vss;
219
		const static std::string vss;
219
		const static std::string fss;
220
		const static std::string fss;
220
		float r;
221
		float r;
221
	public:
222
	public:
222
		LineFieldRenderer(HMesh::Manifold& m, bool smooth, std::vector<CGLA::Vec3d>& lines, float _r);
223
		LineFieldRenderer(HMesh::Manifold& m, bool smooth, std::vector<CGLA::Vec3d>& lines, float _r);
223
		void draw();
224
		void draw();
224
	};
225
	};
225
 
226
 
-
 
227
/** Class for wireframe rendering. Enable it will case all triangles to be drawn to be drawn as
-
 
228
 wireframe. Only triangles are supported, but it is fast. */
-
 
229
class DualVertexRenderer: public ManifoldRenderer
-
 
230
	{
-
 
231
		const static std::string vss;
-
 
232
		const static std::string gss;
-
 
233
		const static std::string fss;
-
 
234
	public:
-
 
235
		/// The constructor creates the wireframe shader program. It is static so the program is shared.
-
 
236
		DualVertexRenderer(HMesh::Manifold& m, std::vector<CGLA::Vec4d>& field);
-
 
237
	};
226
 
238
 
227
 
239
 
228
#endif
240
#endif
229
 
241
 
230

Generated by GNU Enscript 1.6.6.
242

Generated by GNU Enscript 1.6.6.
231
 
243
 
232
 
244
 
233
 
245