fluidvis
SX.h
1 #ifndef _SX_SX_H_
2 #define _SX_SX_H_
3 
8 #include <export/Export.h>
9 #include <sx/SXCore.h>
10 #include <sx/SXParser.h>
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <boost/unordered_map.hpp>
15 #include <boost/timer.hpp>
16 #include <boost/date_time/posix_time/posix_time.hpp>
17 using boost::posix_time::ptime;
18 using boost::posix_time::second_clock;
19 using boost::posix_time::to_simple_string;
20 using namespace std;
21 using namespace boost;
22 
23 namespace sx {
24 
28  enum MouseButton {
29  MOUSE_LEFT,
30  MOUSE_MIDDLE,
31  MOUSE_RIGHT
32  };
33 
38  SX_F1 = 0x1000000,
39  SX_F2 = 0x1000001,
40  SX_F3 = 0x1000002,
41  SX_F4 = 0x1000003,
42  SX_F5 = 0x1000004,
43  SX_F6 = 0x1000005,
44  SX_F7 = 0x1000006,
45  SX_F8 = 0x1000007,
46  SX_F9 = 0x1000008,
47  SX_F10 = 0x1000009,
48  SX_F11 = 0x100000a,
49  SX_F12 = 0x100000b,
50  SX_ESC = 0x100000c,
51  SX_INSERT = 0x100000d,
52  SX_PAUSE = 0x100000e,
53  SX_HOME = 0x100000f,
54  SX_END = 0x1000010,
55  SX_DELETE = 0x1000011,
56  SX_PAGEUP = 0x1000012,
57  SX_PAGEDOWN = 0x1000013,
58  SX_LEFT = 0x1000014,
59  SX_RIGHT = 0x1000015,
60  SX_DOWN = 0x1000016,
61  SX_UP = 0x1000017,
62  SX_NUMLOCK = 0x1000018,
63  SX_CLEAR = 0x1000019,
64  SX_ENTER = 0x100001a,
65  SX_CTRL = 0x100001b,
66  SX_SHIFT = 0x100001c,
67  SX_CAPSLOCK = 0x100001d,
68  SX_START = 0x100001e,
69  SX_ALT = 0x100001f,
70  SX_RETURN = 0x1000020,
71  SX_BACKSPACE = 0x1000021
72  };
73 
78  class SXRenderArea {
79  public:
80 
86  virtual double getTime() const = 0;
87 
92  virtual double getDeltaTime() const = 0;
93 
97  virtual int getMouseX() const = 0;
98 
102  virtual int getMouseY() const = 0;
103 
109  virtual double getMouseDeltaX() const = 0;
110 
116  virtual double getMouseDeltaY() const = 0;
117 
121  virtual bool hasKey(int key) const = 0;
122 
126  virtual bool hasMouseKey(MouseButton key) const = 0;
127 
131  virtual int getWidth() const = 0;
132 
136  virtual int getHeight() const = 0;
137 
141  virtual void stopRendering() = 0;
142 
147  virtual void setMousePointer(int x, int y) = 0;
148 
153  virtual void setShowCursor(bool showCursor) = 0;
154 
155  };
156 
161  public:
162 
171  virtual void create(SXRenderArea &area) = 0;
172 
178  virtual void reshape(SXRenderArea &area) = 0;
179 
186  virtual void render(SXRenderArea &area) = 0;
187 
195  virtual void stop(SXRenderArea &area) = 0;
196 
197  };
198 
205  class SXWindow: public SXRenderArea {
206  private:
207 
208  static map<int,int> keys_glut2sx;
209 
210  static map<int,int> initKeys_glut2sx();
211 
212  static map<int,int> keys_glutnotspecial2sx;
213 
214  static map<int,int> initKeys_glutnotspecial2sx();
215 
219  double currentTimeRendering;
220 
224  double lastTimeRendered;
225 
229  int width;
230 
234  int height;
235 
239  int mouseX;
240 
244  int mouseY;
245 
251  static double mouseDeltaX;
252 
258  static double mouseDeltaY;
259 
263  unordered_map<int,int> keys;
264 
268  unordered_map<int,int> mouseKeys;
269 
273  boost::timer timeMeasurement;
274 
278  vector<SXRenderListener *> listeners;
279 
283  vector<SXRenderListener *> initListeners;
284 
288  int windowID;
289 
293  bool removedWindow;
294 
300  void listenersReshape();
301 
305  void listenersRender();
306 
311  void listenersStop();
312 
313  void updateTime();
314 
315  void setWidth(int width);
316 
317  void setHeight(int height);
318 
319  void setMouseX(int x);
320 
321  void setMouseY(int y);
322 
323  void addKey(int key);
324 
325  void removeKey(int key);
326 
327  void addMouseKey(MouseButton key);
328 
329  void removeMouseKey(MouseButton key);
330 
334  SXWindow(const SXWindow &);
335 
339  SXWindow &operator = (const SXWindow &);
340 
345  static map<int, SXWindow *> windows;
346 
351  static int argc;
352 
357  static char **argv;
358 
362  static char *argv0;
363 
364  friend void windowKeyUp(unsigned char key, int x, int y);
365 
366  friend void windowKeyDown(unsigned char key, int x, int y);
367 
368  friend void windowSpecialKeyUp(int key, int x, int y);
369 
370  friend void windowSpecialKeyDown(int key, int x, int y);
371 
372  friend void windowMouseKey(int button, int state, int x, int y);
373 
374  friend void windowMouseMotion(int x, int y);
375 
376  friend void windowPassiveMotion(int x, int y);
377 
381  friend void reshapeAll(int width, int height);
382 
386  friend void renderAll();
387 
391  friend void stopAll();
392 
393  public:
394 
399  EX SXWindow(const string &name, unsigned int width, unsigned int height);
400 
405  EX ~SXWindow();
406 
410  EX void removeWindow();
411 
417  EX void addRenderListener(SXRenderListener &l);
418 
422  EX void deleteRenderListener(SXRenderListener &l);
423 
427  EX void deleteRenderListeners();
428 
432  EX double getTime() const;
433 
437  EX double getDeltaTime() const;
438 
442  EX int getMouseX() const;
443 
447  EX int getMouseY() const;
448 
452  EX double getMouseDeltaX() const;
453 
457  EX double getMouseDeltaY() const;
458 
462  EX bool hasKey(int key) const;
463 
467  EX bool hasMouseKey(MouseButton key) const;
468 
472  EX int getWidth() const;
473 
477  EX int getHeight() const;
478 
484  EX static void run();
485 
489  EX void stopRendering();
490 
494  EX void setMousePointer(int x, int y);
495 
499  EX void setShowCursor(bool showCursor);
500 
501  };
502 
508  struct BufferUniforms {
509 
513  map<unsigned int,vector<string> > attributeNames;
514 
518  map<unsigned int,vector<Uniform *> > uniforms;
519 
520  };
521 
522  class ShadeX {
523  private:
524 
525  unordered_map<string,SXResource *> resources;
526  unordered_map<string,Shader *> shaders;
527  unordered_map<string,BufferedMesh *> bufferedMeshes;
528  unordered_map<string,Skeleton *> skeletons;
529  unordered_map<string,UniformFloat *> uniformFloats;
530  unordered_map<string,UniformDouble *> uniformDoubles;
531  unordered_map<string,UniformVector *> uniformVectors;
532  unordered_map<string,UniformDVector *> uniformDVectors;
533  unordered_map<string,UniformMatrix *> uniformMatrices;
534  unordered_map<string,UniformDMatrix *> uniformDMatrices;
535  unordered_map<string,Texture *> textures;
536  unordered_map<string,Volume *> volumes;
537  unordered_map<string,RenderTarget *> renderTargets;
538  unordered_map<string,RenderObject *> renderObjects;
539  unordered_map<string,Pass *> passes;
540  unordered_map<string,Effect *> effects;
541  unordered_map<string,AudioBuffer *> audioBuffers;
542  unordered_map<string,AudioObject *> audioObjects;
543  unordered_map<string,AudioListener *> audioListeners;
544  unordered_map<string,AudioPass *> audioPasses;
545 
546  unordered_map<string,BufferUniforms> bufferUniforms;
547 
551  ShadeX(const ShadeX &);
552 
556  ShadeX &operator = (const ShadeX &);
557 
558  void INTERNAL_LOAD_SHADER(XTag *rNode, XTag *data);
559 
560  void INTERNAL_LOAD_MATRIXCONTENT(Matrix &matrix, const string &id, XTag *rNode, XTag *data);
561 
562  void INTERNAL_LOAD_DMATRIXCONTENT(DMatrix &matrix, const string &id, XTag *rNode, XTag *data);
563 
564  void INTERNAL_LOAD_VECTORCONTENT(Vector &vec, const string &id, XTag *rNode, XTag *data);
565 
566  void INTERNAL_LOAD_DVECTORCONTENT(DVector &vec, const string &id, XTag *rNode, XTag *data);
567 
568  void INTERNAL_LOAD_BUFFEREDMESH(XTag *rNode, XTag *data);
569 
570  void INTERNAL_LOAD_SKELETON(XTag *rNode, XTag *data);
571 
572  void INTERNAL_LOAD_UNIFORMFLOAT(XTag *rNode, XTag *data);
573 
574  void INTERNAL_LOAD_UNIFORMDOUBLE(XTag *rNode, XTag *data);
575 
576  void INTERNAL_LOAD_UNIFORMVECTOR(XTag *rNode, XTag *data);
577 
578  void INTERNAL_LOAD_UNIFORMDVECTOR(XTag *rNode, XTag *data);
579 
580  void INTERNAL_LOAD_UNIFORMMATRIX(XTag *rNode, XTag *data);
581 
582  void INTERNAL_LOAD_UNIFORMDMATRIX(XTag *rNode, XTag *data);
583 
584  void INTERNAL_LOAD_TEXTURE(XTag *rNode, XTag *data);
585 
586  void INTERNAL_LOAD_VOLUME(XTag *rNode, XTag *data);
587 
588  void INTERNAL_LOAD_RENDERTARGET(XTag *rNode, XTag *data);
589 
590  void INTERNAL_LOAD_RENDEROBJECT(XTag *rNode, XTag *data);
591 
592  void INTERNAL_RENDEROBJECT_COLLECT_UNIFORMS(RenderObject &obj, const string &id, const string &uType, bool isUniformSet, int uniformSetID, XTag *rNode, XTag *data);
593 
594  void INTERNAL_LOAD_PASS(XTag *rNode, XTag *data);
595 
596  void INTERNAL_PASS_COLLECT_UNIFORMS(Pass &pass, const string &id, const string &uType, XTag *rNode, XTag *data);
597 
598  void INTERNAL_LOAD_EFFECT(XTag *rNode, XTag *data);
599 
600  void INTERNAL_LOAD_AUDIOBUFFER(XTag *rNode, XTag *data);
601 
602  void INTERNAL_LOAD_AUDIOOBJECT(XTag *rNode, XTag *data);
603 
604  void INTERNAL_LOAD_AUDIOLISTENER(XTag *rNode, XTag *data);
605 
606  void INTERNAL_LOAD_AUDIOPASS(XTag *rNode, XTag *data);
607 
608  public:
609 
613  EX ShadeX();
614 
618  EX ~ShadeX();
619 
628  EX void clear(const string &id);
629 
633  EX void clear();
634 
642  EX void addResourcesFromString(const string &resources);
643 
652  EX void addResources(const string &path);
653 
661  EX void load();
662 
674  EX Shader &getShader(const string &id);
675 
679  EX void addResource(const string &id, Shader &shader);
680 
692  EX BufferedMesh &getBufferedMesh(const string &id);
693 
697  EX void addResource(const string &id, BufferedMesh &mesh);
698 
710  EX Skeleton &getSkeleton(const string &id);
711 
715  EX void addResource(const string &id, Skeleton &skeleton);
716 
728  EX UniformFloat &getUniformFloat(const string &id);
729 
733  EX void addResource(const string &id, UniformFloat &uFloat);
734 
746  EX UniformDouble &getUniformDouble(const string &id);
747 
751  EX void addResource(const string &id, UniformDouble &uDouble);
752 
764  EX UniformVector &getUniformVector(const string &id);
765 
769  EX void addResource(const string &id, UniformVector &uVector);
770 
782  EX UniformDVector &getUniformDVector(const string &id);
783 
787  EX void addResource(const string &id, UniformDVector &uDVector);
788 
800  EX UniformMatrix &getUniformMatrix(const string &id);
801 
805  EX void addResource(const string &id, UniformMatrix &uMatrix);
806 
818  EX UniformDMatrix &getUniformDMatrix(const string &id);
819 
823  EX void addResource(const string &id, UniformDMatrix &uDMatrix);
824 
836  EX Texture &getTexture(const string &id);
837 
841  EX void addResource(const string &id, Texture &texture);
842 
854  EX Volume &getVolume(const string &id);
855 
859  EX void addResource(const string &id, Volume &volume);
860 
872  EX RenderTarget &getRenderTarget(const string &id);
873 
877  EX void addResource(const string &id, RenderTarget &target);
878 
890  EX RenderObject &getRenderObject(const string &id);
891 
895  EX void addResource(const string &id, RenderObject &object);
896 
908  EX Pass &getPass(const string &id);
909 
913  EX void addResource(const string &id, Pass &pass);
914 
926  EX Effect &getEffect(const string &id);
927 
931  EX void addResource(const string &id, Effect &effect);
932 
944  EX AudioBuffer &getAudioBuffer(const string &id);
945 
949  EX void addResource(const string &id, AudioBuffer &buffer);
950 
962  EX AudioObject &getAudioObject(const string &id);
963 
967  EX void addResource(const string &id, AudioObject &object);
968 
980  EX AudioListener &getAudioListener(const string &id);
981 
985  EX void addResource(const string &id, AudioListener &object);
986 
998  EX AudioPass &getAudioPass(const string &id);
999 
1003  EX void addResource(const string &id, AudioPass &object);
1004 
1005  };
1006 
1007 }
1008 
1009 #endif
Definition: SXCore.h:1087
Definition: SXCore.h:2507
Definition: SXCore.h:1903
Definition: SX.h:78
Definition: SXCore.h:2682
KeyboardSpecial
Definition: SX.h:37
Definition: SXCore.h:92
Definition: SXCore.h:2260
Definition: SXCore.h:1568
Definition: SXMath.h:640
Definition: SXMath.h:285
MouseButton
Definition: SX.h:28
Definition: SXCore.h:3109
map< unsigned int, vector< string > > attributeNames
Definition: SX.h:513
Definition: SX.h:160
Definition: SXCore.h:3627
Definition: SX.h:508
Definition: SXCore.h:1336
Definition: SXCore.h:3195
Definition: SXCore.h:3750
Definition: SXMath.h:37
Definition: SXCore.h:505
Definition: SXCore.h:1282
map< unsigned int, vector< Uniform * > > uniforms
Definition: SX.h:518
Definition: SXCore.h:1192
Definition: SXCore.h:1237
Definition: SXCore.h:3289
Definition: SXCore.h:1027
Definition: SXMath.h:888
Definition: SX.h:522
Definition: SXCore.h:1147
Definition: SX.h:205
Definition: SXParser.h:337
Definition: Exception.h:13