399 |
jab |
1 |
/*
|
|
|
2 |
* ManifoldRenderer.h
|
|
|
3 |
* GEL
|
|
|
4 |
*
|
|
|
5 |
* Created by J. Andreas Bærentzen on 20/09/08.
|
|
|
6 |
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
|
|
7 |
*
|
|
|
8 |
*/
|
|
|
9 |
#ifndef __MESHEDIT_RENDERER_H__
|
|
|
10 |
#define __MESHEDIT_RENDERER_H__
|
|
|
11 |
|
|
|
12 |
#include <GL/glew.h>
|
|
|
13 |
#include <GLGraphics/draw.h>
|
|
|
14 |
#include <GLGraphics/IDBufferWireFrameRenderer.h>
|
|
|
15 |
|
403 |
jab |
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 */
|
399 |
jab |
19 |
class ManifoldRenderer
|
|
|
20 |
{
|
|
|
21 |
protected:
|
|
|
22 |
GLuint display_list;
|
|
|
23 |
public:
|
|
|
24 |
ManifoldRenderer(): display_list(glGenLists(1)) {}
|
|
|
25 |
virtual ~ManifoldRenderer()
|
|
|
26 |
{
|
|
|
27 |
glDeleteLists(display_list, 1);
|
|
|
28 |
}
|
|
|
29 |
virtual void draw()
|
|
|
30 |
{
|
|
|
31 |
glCallList(display_list);
|
|
|
32 |
}
|
|
|
33 |
};
|
|
|
34 |
|
403 |
jab |
35 |
/** Ugly basic gouraud rendering. This class uses OpenGL's fixed function pipeline. */
|
399 |
jab |
36 |
class NormalRenderer: public ManifoldRenderer
|
|
|
37 |
{
|
|
|
38 |
public:
|
403 |
jab |
39 |
NormalRenderer(HMesh::Manifold& m, bool smooth)
|
399 |
jab |
40 |
{
|
|
|
41 |
glNewList(display_list,GL_COMPILE);
|
403 |
jab |
42 |
GLGraphics::draw(m,smooth);
|
399 |
jab |
43 |
glEndList();
|
|
|
44 |
}
|
|
|
45 |
};
|
|
|
46 |
|
403 |
jab |
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. */
|
399 |
jab |
50 |
class WireframeRenderer: public ManifoldRenderer
|
|
|
51 |
{
|
|
|
52 |
GLGraphics::IDBufferWireframeRenderer* idbuff_renderer;
|
|
|
53 |
|
|
|
54 |
int maximum_face_valency(HMesh::Manifold& m);
|
|
|
55 |
|
|
|
56 |
public:
|
|
|
57 |
~WireframeRenderer()
|
|
|
58 |
{
|
|
|
59 |
delete idbuff_renderer;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
WireframeRenderer(HMesh::Manifold& m, bool flat);
|
|
|
63 |
|
|
|
64 |
void draw();
|
|
|
65 |
};
|
|
|
66 |
|
403 |
jab |
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.
|
|
|
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 |
*/
|
|
|
83 |
class SimpleShaderRenderer: public ManifoldRenderer
|
|
|
84 |
{
|
|
|
85 |
/// Compile the vertex and fragment shaders and link to form shader program.
|
|
|
86 |
void init_shaders(const std::string& vss,
|
|
|
87 |
const std::string& fss);
|
399 |
jab |
88 |
|
403 |
jab |
89 |
/// 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);
|
406 |
jab |
91 |
|
|
|
92 |
protected:
|
|
|
93 |
|
|
|
94 |
GLuint prog,vs,fs;
|
|
|
95 |
|
399 |
jab |
96 |
public:
|
403 |
jab |
97 |
|
|
|
98 |
/// This constructor simply calls init_shaders and then compile_display_list.
|
|
|
99 |
SimpleShaderRenderer(HMesh::Manifold& m,
|
|
|
100 |
bool smooth,
|
|
|
101 |
const std::string& vss,
|
|
|
102 |
const std::string& fss)
|
399 |
jab |
103 |
{
|
403 |
jab |
104 |
init_shaders(vss,fss);
|
|
|
105 |
compile_display_list(m, smooth);
|
399 |
jab |
106 |
}
|
403 |
jab |
107 |
|
406 |
jab |
108 |
/** This constructor simply initializes the shaders. It does not create the display list.
|
|
|
109 |
Use if you shader has extra attributes. */
|
|
|
110 |
SimpleShaderRenderer(const std::string& vss,
|
|
|
111 |
const std::string& fss) {init_shaders(vss,fss);}
|
403 |
jab |
112 |
|
|
|
113 |
/// Releases the program and shaders.
|
399 |
jab |
114 |
~SimpleShaderRenderer()
|
|
|
115 |
{
|
|
|
116 |
glDeleteProgram(prog);
|
|
|
117 |
glDeleteShader(vs);
|
|
|
118 |
glDeleteShader(fs);
|
|
|
119 |
}
|
403 |
jab |
120 |
|
|
|
121 |
/// Do the actual drawing. Simply calls the display list if this function is not overloaded.
|
399 |
jab |
122 |
virtual void draw();
|
|
|
123 |
|
|
|
124 |
};
|
|
|
125 |
|
403 |
jab |
126 |
/** 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 |
want to see whether the surface is smooth or has kinks. */
|
399 |
jab |
129 |
class ReflectionLineRenderer: public SimpleShaderRenderer
|
|
|
130 |
{
|
|
|
131 |
const static std::string vss;
|
|
|
132 |
const static std::string fss;
|
|
|
133 |
public:
|
403 |
jab |
134 |
ReflectionLineRenderer(HMesh::Manifold& m, bool smooth):
|
|
|
135 |
SimpleShaderRenderer(m, smooth, vss, fss) {}
|
399 |
jab |
136 |
|
|
|
137 |
};
|
|
|
138 |
|
403 |
jab |
139 |
/** 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. */
|
399 |
jab |
141 |
class IsophoteLineRenderer: public SimpleShaderRenderer
|
|
|
142 |
{
|
|
|
143 |
const static std::string vss;
|
|
|
144 |
const static std::string fss;
|
|
|
145 |
public:
|
403 |
jab |
146 |
IsophoteLineRenderer(HMesh::Manifold& m, bool smooth):
|
|
|
147 |
SimpleShaderRenderer(m, smooth, vss, fss) {}
|
399 |
jab |
148 |
|
|
|
149 |
};
|
|
|
150 |
|
403 |
jab |
151 |
/** The toon renderer simply quantizes the shading to give a toonish appearance
|
|
|
152 |
with a fat black silhouette. */
|
|
|
153 |
|
|
|
154 |
class ToonRenderer: public SimpleShaderRenderer
|
399 |
jab |
155 |
{
|
|
|
156 |
const static std::string vss;
|
|
|
157 |
const static std::string fss;
|
|
|
158 |
public:
|
403 |
jab |
159 |
ToonRenderer(HMesh::Manifold& m, bool smooth):
|
|
|
160 |
SimpleShaderRenderer(m, smooth, vss, fss) {}
|
399 |
jab |
161 |
|
|
|
162 |
};
|
|
|
163 |
|
403 |
jab |
164 |
/** Render like glazed ceramics. Looks cool. I will add more to this. */
|
401 |
jab |
165 |
class GlazedRenderer: public SimpleShaderRenderer
|
|
|
166 |
{
|
403 |
jab |
167 |
float bsphere_rad;
|
401 |
jab |
168 |
const static std::string vss;
|
|
|
169 |
const static std::string fss;
|
|
|
170 |
public:
|
403 |
jab |
171 |
GlazedRenderer(HMesh::Manifold& m, bool smooth, float _bsphere_rad=1.0):
|
|
|
172 |
SimpleShaderRenderer(m, smooth, vss, fss), bsphere_rad(_bsphere_rad) {}
|
|
|
173 |
void draw();
|
401 |
jab |
174 |
};
|
399 |
jab |
175 |
|
403 |
jab |
176 |
/** 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 |
scalars are mostly small or large and simply scaling to the 0-1 range does not
|
|
|
179 |
produce a good result. */
|
|
|
180 |
class ScalarFieldRenderer: public SimpleShaderRenderer
|
|
|
181 |
{
|
|
|
182 |
const static std::string vss;
|
|
|
183 |
const static std::string fss;
|
|
|
184 |
public:
|
|
|
185 |
ScalarFieldRenderer(HMesh::Manifold& m, bool smooth,
|
|
|
186 |
std::vector<double>& field, double max_val);
|
|
|
187 |
};
|
399 |
jab |
188 |
|
406 |
jab |
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 |
|
403 |
jab |
214 |
/** 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 |
class LineFieldRenderer: public SimpleShaderRenderer
|
|
|
217 |
{
|
|
|
218 |
const static std::string vss;
|
|
|
219 |
const static std::string fss;
|
|
|
220 |
float r;
|
|
|
221 |
public:
|
|
|
222 |
LineFieldRenderer(HMesh::Manifold& m, bool smooth, std::vector<CGLA::Vec3d>& lines, float _r);
|
|
|
223 |
void draw();
|
|
|
224 |
};
|
401 |
jab |
225 |
|
403 |
jab |
226 |
|
|
|
227 |
|
399 |
jab |
228 |
#endif
|