MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
VBO.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 
6 #if !defined(_MGVBO__INCLUDED_)
7 #define _MGVBO__INCLUDED_
8 
9 #if _MSC_VER > 1000
10 #pragma once
11 #endif // _MSC_VER > 1000
12 
13 #include "MGCLStdAfx.h"
14 #include "mg/Pvector.h"
15 #include "mg/drawParam.h"
16 #include "mgGL/glslprogram.h"
17 #include "mgGL/StaticGLAttrib.h"
18 #include "mgGL/Color.h"
19 #include "mgGL/GLAttrib.h"
20 #include "mgGL/VBOElement.h"
21 #include "mgGL/VBOLeafBuilder.h"
22 
23 class MGPosition;
24 class MGBox;
25 class MGBPointSeq;
26 class MGSPointSeq;
27 class MGCurve;
28 class MGSPointSeq;
29 class MGCellBase;
30 class mgTL2Triangles;
31 class MGStl;
32 class MGColor;
33 class MGAttribedGel;
34 class mgVBO;
35 class MGComplex;
36 class MGImage;
37 
38 
44 // Vertex Buffer Object Class.
46 
47 
49 
76 class MG_DLL_DECLR mgVBO:public mgVBOElement{
77 
78 friend class MGDNameControl;
79 friend class MGAttribedGel;
80 friend class mgVBOPointer;
81 
82 // オペレーション
83 public:
85  WIRE=0,
87  BOTH
88 };
89 
93 
95 mgVBO();
96 
98 mgVBO(const MGAttribedGel& gel);
99 
101 mgVBO(const mgVBO& vbo);
102 
104 mgVBO& operator=(const mgVBO& vbo);
105 
106 virtual ~mgVBO();
107 
113 void initializeVBO(MGCL::VIEWMODE viewMode=MGCL::DONTCARE);
114 
120 bool buildVBOHierarchy(
121  mgVBO& parent,
122  std::vector<mgVBO*>& vbos
124 );
125 
132 
135 virtual void draw(MGCL::VIEWMODE viewMode=MGCL::DONTCARE);
136 
139 virtual void redraw(MGCL::VIEWMODE viewMode=MGCL::DONTCARE);
140 
144 virtual void selectionDraw(MGCL::VIEWMODE viewMode=MGCL::DONTCARE);
145 
147 void highlight();
148 
150 virtual void clearElements(mgVBO::ELEMENT_TARGET target=BOTH);
151 
153 virtual void clearStaticAttributes();
154 
155 mgVBOElement* back()const{return m_target_elements->back();};
156 mgVBOElement* front()const{return m_target_elements->front();};
157 
158 iterator begin_element(){return m_target_elements->begin();};
159 iterator end_element(){return m_target_elements->end();};
160 const_iterator begin_element()const{return m_target_elements->begin();};
161 const_iterator end_element()const{return m_target_elements->end();};
162 int elementNumber()const{return (int)m_target_elements->size();};
163 void pop_back_element(){m_target_elements->pop_back();};
164 void push_back_element(mgVBOElement* elm){m_target_elements->push_back(elm);};
165 
169 unsigned getDName()const{return m_dname;};
170 
171 MGAttribedGel* gel()const{return m_gel;};
172 
176 virtual GLuint getSelectionName()const;
177 
180 virtual bool is_made(MGCL::VIEWMODE viewMode=MGCL::DONTCARE);
181 
184 bool is_InBegin();
185 
195 virtual void Begin(GLenum type, ELEMENT_TARGET target=WIRE);
196 
202 virtual mgVBOLeaf* End(GLenum polygonMode=GL_FILL);
203 
206 void setDirty(bool is_dirty=true, mgVBO::ELEMENT_TARGET target=BOTH)const;
207 
210 //void setFunctionID(int functionID);
211 void setDrawType(mgGLSL::DrawType drawType);
212 
216 void setTexture(mgTexture* texture);
217 
219 void Color(const MGColor& colr);
220 void Color3fv(const float colr[3]);
221 void Color3dv(const double colr[3]);
222 void Color4fv(const float colr[4]);
223 void Color4ubv(const unsigned char rgba[4]);
224 
226 void Normal(const MGVector& norml);
227 void Normal(float x, float y, float z);
228 void Normal3d(double x, double y, double z);
229 void Normal3fv(const float norml[3]);
230 void Normal3dv(const double norml[3]);
231 
233 virtual void Vertex(const MGPosition& v);
234 virtual void Vertex(float x, float y, float z=0.0f);
235 virtual void Vertex3d(double x, double y, double z=0.0);
236 virtual void Vertex2fv(const float v[2]);
237 virtual void Vertex3fv(const float v[3]);
238 virtual void Vertex2dv(const double v[2]);
239 virtual void Vertex3dv(const double v[3]);
240 
242 void TexCoord(const MGPosition& v);
243 void TexCoord(float x, float y);
244 void TexCoord2d(double x, double y);
245 void TexCoord2fv(const float v[2]);
246 void TexCoord2dv(const double v[2]);
247 
249 
253 void setStaticAttribColor(const MGColor& color);//colorにはundefinedのものも許される
254 void setStaticAttribColor(const float color[4]);
255 void setStaticAttribColor(float r, float g, float b);
256 void setStaticAttribLineWidth(GLfloat size);
257 void setStaticAttribPointSize(GLfloat size);
258 
264 void setLineStipple(short int factor, GLushort pattern=0);
265 
266 void LineWidth(GLfloat size){setStaticAttribLineWidth(size);};
267 
269 void disableLinePattern();
270 
273 
275 void drawGel(const MGAttribedGel& gel);
276 
278 void drawVBOLeaf(
279  const mgVBOLeaf& leaf,
280  ELEMENT_TARGET target=SHADING
281 );
283 
285 void deleteGel(const MGAttribedGel& gel);
286 
287 //Draw an arrow symbol with implementation of OpenGL.
288 //data[0] is the origin of the arrow, data[1] is the top of the arrow,
289 //data[2], [3] are two bottoms of arrowhead.
290 void drawArrow(const MGPosition pos[4]);
291 
293 void drawBox(const MGBox& box);
294 
297 void drawPointSeq(
298  const MGBPointSeq& bp,
299  bool draw_points=true
300 );
301 void drawPointSeq(
302  const MGSPointSeq& sp,
303  bool draw_points=true
304 );
305 
306 //Draw 3D point(vertex) in world coordinates.
307 //The object is converted to point(s) and is drawn.
308 //This is valid only for topology objects or MGPoint.
309 void draw3DVertex(const MGObject& obj);
310 void draw3DVertex_in_star(const MGComplex& obj);
311 void draw3DVertex_in_star(const MGCellBase& obj);
312 
315 void drawWire_in_star(const MGComplex& obj);
316 void drawWire_in_star(const MGCellBase& obj);
317 
320 double drawCurvaGraph(
321  const MGCurve& curve,
322  double scale,
323  int density,
324  bool use_radius,
325  bool getLength=false
326 );
329 
334 void drawPoint(double x,double y,double z, double size=-1.);
335 void drawPoint(const MGPosition& pos, double size=-1.);
336 void drawPointInverseColor(double x,double y,double z, double size=-1.);
337 void drawPointInverseColor(const MGPosition& pos, double size=-1.);
338 
342 void drawPointWithColor(double x,double y,double z,
343  double outerSize, double innerSize,
344  const MGColor* colorInner=0, const MGColor* colorOuter=0
345 );
346 
350 void drawPointWithColor(const MGPosition& pos,
351  double outerSize, double innerSize,
352  const MGColor* colorInner=0, const MGColor* colorOuter=0
353 );
354 
358 void drawPoints(
359  const MGColor& boundary_color,
360  const MGColor& inner_color,
361  const std::vector<MGPosition>& ipos,
362  double size=-1.
363 );
364 
367 void drawPolyline(const MGBPointSeq& line, bool closed=false);
368 
371 void drawPolyline(const std::vector<MGPosition>& line, bool closed=false);
372 
374 void drawStraight(const MGPosition& end, const MGPosition& start);
375 
376 //Draw an object in its parameter space(MGDraw_in_parameter_space).
377 //This is valid only for Surface, Face, Loop, Edge.
378 void drawObjInParameterSpace(const MGObject& obj);
379 
381 void drawRectangle(
382  const MGBox& box //Box to draw.
383 );
384 
386 //void drawWTess(
387 // const mgTLData& tld //tessellation data.
388 //);
389 
391 //void drawPTess(
392 // const mgTLData& tld //tessellation data.
393 //);
394 
397 void drawSurfaceCurvature(
398  const mgTL2Triangles& tld,
400  double lower, double upper //minimum and maximum value of the curvatures of the kind.
401 );
402 
405 void drawSurfaceCurvature(
406  const std::vector<mgTL2Triangles>& tldvec,
408  double lower,
409  double upper
410 );
411 
413 void drawShade(
414  const mgTL2Triangles& tris,
415  ELEMENT_TARGET target=SHADING,
416  GLenum polygonMode=GL_FILL//Polygon mode to draw, GLPOINT, GL_LINE, or GLFILL.
418 );
419 
421 void drawShade(
422  const std::vector<mgTL2Triangles>& trisVector,
423  ELEMENT_TARGET target=SHADING,
424  GLenum polygonMode=GL_FILL//Polygon mode to draw, GLPOINT, GL_LINE, or GLFILL.
426 );
427 
429 void drawSTL(
430  const MGStl& stl,
431  ELEMENT_TARGET target=SHADING,
432  GLenum polygonMode=GL_FILL
434 );
435 
439 //const MGDrawParam& getDrawParam()const{return mgVBOElement::getDrawParam();};
440 //const MGColor& getHilightColor()const{return mgVBOElement::getHilightColor();};
441 GLfloat getPointSize()const;
442 GLfloat getLineWidth()const;
443 
444 const MGColor& staticColor()const{return m_colorStatic;};
445 MGColor& staticColor(){return m_colorStatic;};
446 
448 void setLightMode(int mode){m_lightMode=mode;};
449 int getLightMode(){return m_lightMode;};
450 
451 protected:
452 
453  unsigned m_dname;
455 
458 
459  mutable bool m_elementsDirty:1;
461 
467  mutable bool m_elementsShadeDirty:1;
469 
474 
477 
481 
484  short int m_stippleFactor;
485  GLushort m_LineStipplePattern;
488 
491 
494 
495  std::auto_ptr<mgVBOLeafBuilder> m_builder;
496 
498 
501 virtual void execStaticGLAttrib();
502 
505 virtual void execModelTypeAttrib();
506 
507 void setDlName(unsigned name){m_dname=name;};
508 void setGel(const MGAttribedGel* gel);
509 
511 void setElementTarget(ELEMENT_TARGET target);
512 
513 };
514 
515 namespace MGCL{
516 
519 MG_DLL_DECLR double getCurveCurvatureLength(
520  const MGCurve& curve, double scale, int density, bool use_radius
521 );
522 
523 }
524 
526 
529 class MG_DLL_DECLR mgLightModeSwitcher{
530 public:
532  m_orgMode = m_vbo.getLightMode();
533  m_vbo.setLightMode(mode);
534  };
535 
537  m_vbo.setLightMode(m_orgMode);
538  };
539 
540 private:
541  mgVBO& m_vbo;
542  int m_orgMode;
543 };
544  // end of DisplayHandling group
546 #endif // !defined(_MGVBO__INCLUDED_)
Interface class to include an element in mgVBO class's.
Definition: VBOElement.h:44
MGColor & staticColor()
Definition: VBO.h:445
friend class mgVBO
Definition: VBOElement.h:45
std::auto_ptr< mgVBOLeafBuilder > m_builder
Definition: VBO.h:495
Is an abstract class and the super class of MGPVertex and MGCellNB.
Definition: CellBase.h:38
Utility class to invoke mgVBO::setLightMode().
Definition: VBO.h:529
SURFACE_CURVATURE_KIND
Definition: MGCL.h:262
MGCurve is an abstract class which represents a whole curve.
Definition: Curve.h:63
const MGColor & staticColor() const
Definition: VBO.h:444
Definition: MGCL.h:272
MGPvector< mgVBOElement > * m_target_elements
When m_gel=0, this mgVBO is not for an MGAttribedGel but a temporary or non gel's VBO...
Definition: VBO.h:457
const_iterator end_element() const
Definition: VBO.h:161
A vector of mgTL2Triangle's.
Definition: TL2Triangles.h:25
std::vector< mgVBOElement * >::const_iterator const_iterator
Definition: Pvector.h:32
MGImage defines bit map image data.
Definition: Image.h:26
mgGLSL::CoordinateType m_coordinateType
<0: undefined, =0:Light is disabled, >0:Light is enabled.
Definition: VBO.h:493
mgVBOElement * front() const
Definition: VBO.h:156
mgLightModeSwitcher(mgVBO &vbo, mgGLSL::ShadeMode mode)
Definition: VBO.h:531
MGAttribedGel * gel() const
Definition: VBO.h:171
MGPvector< mgVBOElement > m_elements
=true if dirty and need to remake.
Definition: VBO.h:460
Is an abstract class which represents a whole geometry and a topology.
Definition: Object.h:42
virtual bool is_made(MGCL::VIEWMODE viewMode=MGCL::DONTCARE)=0
Vector of a general n space dimension.
Definition: Vector.h:26
GLfloat m_pointSizeStatic
Definition: VBO.h:480
void execStaticColorAttrib()
Definition: VBO.h:497
Defines a Box of any space dimendion.
Definition: Box.h:34
MGColor defines the OpenGL color (R,G,B,A).
Definition: Color.h:26
void setLightMode(int mode)
Set light mode. mode=-1:undefined, =0:disabled, =1:enabled.
Definition: VBO.h:448
virtual void draw(MGCL::VIEWMODE viewMode=MGCL::DONTCARE)=0
DrawType
Definition: glslprogram.h:25
virtual void make_display_list(MGCL::VIEWMODE vmode=MGCL::DONTCARE)=0
すでに作成済みであっても強制的に再作成を行う。
Defines parameters to draw MGObject, maily to approximate by lines and facets.
Definition: drawParam.h:53
iterator begin_element()
Definition: VBO.h:158
MGColor m_colorStatic
Definition: VBO.h:473
void push_back_element(mgVBOElement *elm)
Definition: VBO.h:164
MG_DLL_DECLR double getCurveCurvatureLength(const MGCurve &curve, double scale, int density, bool use_radius)
Is an abstract class which provides interfaces of MGGel that has MGAppearance.
Definition: AttribedGel.h:32
Represent a positional data.
Definition: Position.h:28
std::vector< mgVBOElement * >::iterator iterator
Definition: Pvector.h:31
MGPvector< mgVBOElement > container_type
Definition: VBO.h:90
~mgLightModeSwitcher()
Definition: VBO.h:536
void setDlName(unsigned name)
Definition: VBO.h:507
Texture definition class.
Definition: Texture.h:29
MGPvector< mgVBOElement > m_elementsShade
=true if dirty and need to remake.
Definition: VBO.h:468
ELEMENT_TARGET
Definition: VBO.h:84
surface mode
Definition: MGCL.h:274
short int m_stippleFactor
Definition: VBO.h:484
MGGroupなどでmemberのMGGelの描画をmgVBOのelementとするためのクラス.
Definition: VBOPointer.h:50
mgVBOElement * back() const
Definition: VBO.h:155
Defines BPoint seq of a space dimension and of a capacity.
Definition: BPointSeq.h:38
void pop_back_element()
Definition: VBO.h:163
Definition: Curve.h:1282
MGAttribedGel * m_gel
name to register in MGDNameControl.
Definition: VBO.h:454
VIEWMODE
Definition: MGCL.h:271
iterator end_element()
Definition: VBO.h:159
void setDrawParam(const MGDrawParam &dpara)
Definition: VBO.h:438
MGStl is a concrete class which represents an STL information.
Definition: MGStl.h:34
int m_lightMode
m_LineStipplePatternindicates the pattern.
Definition: VBO.h:490
virtual GLuint getSelectionName() const =0
virtual void redraw(MGCL::VIEWMODE viewMode)=0
MG_DLL_DECLR void execStaticColorAttrib(const MGColor &color)
container_type::const_iterator const_iterator
Definition: VBO.h:92
virtual void selectionDraw(MGCL::VIEWMODE viewMode=MGCL::DONTCARE)=0
MGComplex is a container of parameter cells and binder cells.
Definition: Complex.h:25
mgVBOに対して描画データ作成後の情報を保持するためのクラス.
Definition: VBOLeaf.h:38
GLfloat m_lineWidthStatic
The color of the following Begin()(mgVBOLeaf generated) is set to this color.
Definition: VBO.h:476
unsigned getDName() const
Definition: VBO.h:169
container_type::iterator iterator
Definition: VBO.h:91
CoordinateType
Definition: glslprogram.h:46
int elementNumber() const
Definition: VBO.h:162
const_iterator begin_element() const
Definition: VBO.h:160
Defines Spoint seq of a space dimension and of a size.
Definition: SPointSeq.h:36
ShadeMode
Definition: glslprogram.h:56
OpenGL 4 用描画のためのクラス, in other words, display list.
Definition: VBO.h:76
void LineWidth(GLfloat size)
Definition: VBO.h:266
wire frame mode
Definition: MGCL.h:273
static void setDrawParam(const MGDrawParam &dpara)
Definition: VBOElement.h:98