50 # include <OpenGL/gl.h>
63 #include "SortMethod.h"
64 #include "Optimizer.h"
69 void vrender::VectorialRender(RenderCB render_callback,
void *callback_params,
VRenderParams& vparams)
71 GLfloat *feedbackBuffer = NULL ;
83 vparams.progress(0.0, QGLViewer::tr(
"Rendering...")) ;
87 if(feedbackBuffer != NULL)
88 delete[] feedbackBuffer ;
90 feedbackBuffer =
new GLfloat[vparams.size()] ;
92 if(feedbackBuffer == NULL)
93 throw std::runtime_error(
"Out of memory during feedback buffer allocation.") ;
95 glFeedbackBuffer(vparams.size(), GL_3D_COLOR, feedbackBuffer);
96 glRenderMode(GL_FEEDBACK);
97 render_callback(callback_params);
98 returned = glRenderMode(GL_RENDER);
103 vparams.size() *= 2 ;
110 glGetIntegerv(GL_DEPTH_BITS, &depth_bits) ;
112 EGALITY_EPS = 2.0/(1 << depth_bits) ;
113 LINE_EGALITY_EPS = 2.0/(1 << depth_bits) ;
116 if (returned > vparams.size())
117 vparams.size() = returned;
118 #ifdef _VRENDER_DEBUG
119 cout <<
"Size = " << vparams.size() <<
", returned=" << returned << endl ;
125 vector<PtrPrimitive> primitive_tab ;
128 parserGL.parseFeedbackBuffer(feedbackBuffer,returned,primitive_tab,vparams) ;
130 if(feedbackBuffer != NULL)
132 delete[] feedbackBuffer ;
133 feedbackBuffer = NULL ;
136 if(vparams.isEnabled(VRenderParams::OptimizeBackFaceCulling))
139 bfopt.optimize(primitive_tab,vparams) ;
144 switch(vparams.sortMethod())
146 case VRenderParams::AdvancedTopologicalSort:
147 case VRenderParams::TopologicalSort: {
149 tsm->setBreakCycles(vparams.sortMethod() == VRenderParams::AdvancedTopologicalSort) ;
154 case VRenderParams::BSPSort: sort_method =
new BSPSortMethod() ;
157 case VRenderParams::NoSorting: sort_method =
new DontSortMethod() ;
160 throw std::runtime_error(
"Unknown sorting method.") ;
163 sort_method->sortPrimitives(primitive_tab,vparams) ;
167 if(vparams.isEnabled(VRenderParams::CullHiddenFaces))
170 vopt.optimize(primitive_tab,vparams) ;
174 if(vparams.isEnabled(VRenderParams::OptimizePrimitiveSplit))
177 psopt.optimize(primitive_tab) ;
182 switch(vparams.format())
184 case VRenderParams::EPS: exporter =
new EPSExporter() ;
186 case VRenderParams::PS: exporter =
new PSExporter() ;
188 case VRenderParams::XFIG:exporter =
new FIGExporter() ;
191 case VRenderParams::SVG: exporter =
new SVGExporter() ;
195 throw std::runtime_error(
"Sorry, this output format is not handled now. Only EPS and PS are currently supported.") ;
200 GLfloat viewport[4],clearColor[4],lineWidth,pointSize ;
202 glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
203 glGetFloatv(GL_LINE_WIDTH, &lineWidth);
204 glGetFloatv(GL_POINT_SIZE, &pointSize);
205 glGetFloatv(GL_VIEWPORT, viewport);
207 lineWidth /= (float)
max(viewport[2] - viewport[0],viewport[3]-viewport[1]) ;
211 if(vparams.isEnabled(VRenderParams::TightenBoundingBox))
212 exporter->setBoundingBox(parserGL.xmin(),parserGL.ymin(),parserGL.xmax(),parserGL.ymax()) ;
214 exporter->setBoundingBox(viewport[0],viewport[1],viewport[0]+viewport[2],viewport[1]+viewport[3]) ;
216 exporter->setBlackAndWhite(vparams.isEnabled(VRenderParams::RenderBlackAndWhite)) ;
217 exporter->setClearBackground(vparams.isEnabled(VRenderParams::AddBackground)) ;
218 exporter->setClearColor(clearColor[0],clearColor[1],clearColor[2]) ;
220 exporter->exportToFile(vparams.filename(),primitive_tab,vparams) ;
224 for(
unsigned int i=0;i<primitive_tab.size();++i)
225 delete primitive_tab[i] ;
227 if(exporter != NULL)
delete exporter ;
228 if(sort_method != NULL)
delete sort_method ;
232 cout <<
"Render aborted: " << e.what() << endl ;
234 if(exporter != NULL)
delete exporter ;
235 if(sort_method != NULL)
delete sort_method ;
236 if(feedbackBuffer != NULL)
delete[] feedbackBuffer ;
242 VRenderParams::VRenderParams()
247 _progress_function = NULL ;
248 _sortMethod = BSPSort ;
251 VRenderParams::~VRenderParams()
255 void VRenderParams::progress(
float f,
const QString& progress_string)
257 _progress_function(f,progress_string) ;
260 void VRenderParams::setFilename(
const QString& filename)
262 _filename = filename;
265 void VRenderParams::setOption(VRenderOption opt,
bool b)
273 bool VRenderParams::isEnabled(VRenderOption opt)
275 return (_options & opt) > 0 ;
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)