Subversion Repositories gelsvn

Rev

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

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

Generated by GNU Enscript 1.6.6.
230

Generated by GNU Enscript 1.6.6.
202
 
231
 
203
 
232
 
204
 
233