H3D API  2.4.1
H3DWindowNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __H3DWINDOWNODE_H__
30 #define __H3DWINDOWNODE_H__
31 
32 #include <H3D/X3DViewpointNode.h>
33 #include <H3D/MFNode.h>
34 #include <H3D/SFInt32.h>
35 #include <H3D/SFVec2f.h>
36 #include <H3D/DefaultAppearance.h>
37 #include <H3D/NavigationInfo.h>
39 
40 class OculusRiftHandler;
41 
42 namespace H3D {
43  class H3DNavigation;
44 
56 
57  class H3DAPI_API H3DWindowNode : public Node {
58  public:
59 
62 
64  class WindowSizeChanged : public TypedField< SFBool, Types<SFInt32, SFInt32> > {
65  public:
67  prev_set = false;
68  width_prev = 0;
69  height_prev = 0;
70  }
71  virtual void update();
72  H3DInt32 width_prev;
73  H3DInt32 height_prev;
74  bool prev_set;
75  };
76 
78  class H3DAPI_API RenderMode: public SFString {
79  public:
83  typedef enum {
118 
125 
132 
136 
140 
146 
154 
156  OCULUS_RIFT
157 
158  } Mode;
159 
160 
162  inline bool isStereoMode() {
163  upToDate();
164  return value != "MONO";
165  }
166 
168  inline bool isSinglePass() {
169  upToDate();
170  return value == "MONO"||
171  value == "VERTICAL_SPLIT_KEEP_ASPECT_ONE_PASS";
172  }
173 
176  RenderMode::Mode getRenderMode();
177 
180  upToDate();
181  if( "VERTICAL_INTERLACED" == value||
182  "HORIZONTAL_INTERLACED" == value||
183  "CHECKER_INTERLACED" == value ||
184  "VERTICAL_INTERLACED_GREEN_SHIFT" == value ) {
185  H3DWindowNode *window = static_cast<H3DWindowNode*>(getOwner());
186  window->rebuild_stencil_mask = true;
187  }
188  }
189  };
190 
192  H3DWindowNode( Inst< SFInt32 > _width = 0,
193  Inst< SFInt32 > _height = 0,
194  Inst< SFBool > _fullscreen = 0,
195  Inst< SFBool > _mirrored = 0,
196  Inst< RenderMode > _renderMode = 0,
197  Inst< SFViewpoint > _viewpoint = 0,
198  Inst< SFInt32 > _posX = 0,
199  Inst< SFInt32 > _posY = 0,
200  Inst< SFBool > _manualCursorControl = 0,
201  Inst< SFString > _cursorType = 0,
202  Inst< SFNavigationInfo > _navigationInfo = 0,
203  Inst< SFBool > _useFullscreenAntiAliasing = 0,
204  Inst< SFVec2f > _clipDistances = 0,
205  Inst< SFBool > _singlePassStereo = 0,
206  Inst< SFString > _pointingDeviceRefreshMode = 0,
207  Inst< SFBool > _resetViewPoint = 0,
208  Inst< SFInt32 > _numSamples = 0);
209 
211  ~H3DWindowNode();
212 
214  virtual void swapBuffers() = 0;
215 
219  virtual void initWindow() = 0;
220 
222  virtual void deinitWindow();
223 
226  virtual void initWindowHandler() = 0;
227 
229  virtual void setFullscreen( bool fullscreen ) = 0;
230 
235  virtual void makeWindowActive() = 0;
236 
238  virtual void initialize();
239 
240  static void fboCallback( FrameBufferTextureGenerator *g, int i, void *args );
241 
244  virtual void render( X3DChildNode *child_to_render );
245 
247  virtual void reshape( int w, int h );
248 
250  virtual void display();
251 
260  virtual void onKeyDown( int key, bool special );
261 
270  virtual void onKeyUp( int key, bool special );
271 
277  virtual void onMouseButtonAction( int button, int state );
278 
281  virtual void onMouseMotionAction( int x, int y );
282 
286  virtual void onMouseWheelAction( int direction );
287 
302  static bool calculateFarAndNearPlane( H3DFloat &far,
303  H3DFloat &near,
304  X3DChildNode *child,
305  X3DViewpointNode *vp,
306  bool include_stylus );
307 
312  H3DUniquePtr< SFInt32 > posX;
313 
318  H3DUniquePtr< SFInt32 > posY;
319 
324  H3DUniquePtr< SFInt32 > width;
325 
330  H3DUniquePtr< SFInt32 > height;
331 
336  H3DUniquePtr< SFBool > fullscreen;
337 
342  H3DUniquePtr< SFBool > mirrored;
343 
351  H3DUniquePtr< RenderMode > renderMode;
352 
360  H3DUniquePtr< SFViewpoint > viewpoint;
361 
369  H3DUniquePtr< SFBool > manualCursorControl;
370 
382  H3DUniquePtr< SFString > cursorType;
383 
391  H3DUniquePtr< SFNavigationInfo > navigationInfo;
392 
398  H3DUniquePtr< SFVec2f > clipDistances;
399 
406  H3DUniquePtr< SFBool > useFullscreenAntiAliasing;
407 
410  H3DUniquePtr< SFInt32 > viewportWidth;
411 
415  H3DUniquePtr< SFInt32 > projectionWidth;
416  //int projection_width;
417 
420  H3DUniquePtr< SFInt32 > viewportHeight;
421 
426  H3DUniquePtr< SFInt32 > projectionHeight;
427 
433  H3DUniquePtr< SFBool > singlePassStereo;
434 
444  H3DUniquePtr< SFString > pointingDeviceRefreshMode;
445 
449  H3DUniquePtr< SFBool > resetViewPoint;
450 
455  H3DUniquePtr< SFInt32 > numSamples;
456 
457 #ifdef HAVE_LIBOVR
458  OculusRiftHandler *oculus;
459 #endif
460 
461  static set< H3DWindowNode* > windows;
462 
463  inline static bool getMultiPassTransparency() {
464  return multi_pass_transparency;
465  }
466 
467  inline X3DViewpointNode::EyeMode getEyeMode() {
468  return eye_mode;
469  }
470 
477  virtual void shareRenderingContext( H3DWindowNode *w );
478 
479 #ifdef H3D_WINDOWS
480  HGLRC getRenderingContext() {
481  return rendering_context;
482  }
483 
486  operator HWND() { return hWnd; }
487 #endif // H3D_WINDOWS
488 
491 
492  // Variables containing default values for navigation.
493  string default_nav;
494  vector< H3DFloat > default_avatar;
495  H3DFloat default_speed;
496  bool default_collision;
497  vector< string > default_transition_type;
498  H3DTime default_transition_time;
499 
500  // the size of the frame buffer portion in use normally will match the
501  // viewport width and height for the FBTG node. However when it is
502  // in single pass render stereo mode, they are no longer the same.
503  // These value will be used for FBTG node to creat framebuffer object.
504  H3DInt32 fbo_current_width ;
505  H3DInt32 fbo_current_height;
506 
507  // the starting point of the frame buffer being used. Mostly of the time
508  // it will match the viewport staring point.
509  H3DInt32 fbo_current_x;
510  H3DInt32 fbo_current_y;
511 
512  // viewport_sizes contains a sequence of (x,y,w,h) size values
513  // the first four values are the default viewport which cover the whole
514  // window. The second and third four value tuple represent the viewport
515  // for stereo mode which requires two viewports
516  // the type of viewports_size is float because the place where it is used
517  // glViewportArray requires the viewport bounds to be floating point value
518  // to allow fractional pixel offsets in viewport transform
519  H3DFloat viewports_size[12];
520 
521  // number of viewport in this window
522  // this value is used together with viewports_size to get viewport dimensions
523  H3DInt32 nr_viewports;
524 
525  protected:
529  void initWindowWithContext();
530 #ifdef H3D_WINDOWS
531  HGLRC rendering_context;
532  HWND hWnd;
533  HINSTANCE windowInstance;
534 
535  // WindowProc calls the Window Procedure stored in wpOrigProc
536  // Default is DefWindowProc
537  WNDPROC wpOrigProc;
538 
544  static LRESULT CALLBACK WindowProc(HWND _hWnd, UINT uMsg,
545  WPARAM wParam, LPARAM lParam);
547  LRESULT Message(HWND _hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
548 #endif // H3D_WINDOWS
549 
555  inline static void setMultiPassTransparency( bool b ) {
556  multi_pass_transparency = b;
557  }
558 
559  // Render the child node. Will be called after all viewports etc has
560  // been set up in order to render the child and everything else that
561  // needs to be rendered.
562  void renderChild( X3DChildNode *c );
563 
565  void renderChild( X3DChildNode *child_to_render,
566  bool render_fbo_only );
567 
571  virtual int setCursorType( const std::string & /*cursor_type*/ ) {
572  return -1;
573  }
574 
583  virtual string getCursorForMode( const string &) { return "DEFAULT"; }
584 
585  friend class Scene;
586 
588 
589  static bool multi_pass_transparency;
590  X3DChildNode *last_render_child;
591  static bool GLEW_init;
592  int window_id;
593  bool rebuild_stencil_mask;
594  unsigned char *stencil_mask;
595  unsigned int stencil_mask_height;
596  unsigned int stencil_mask_width;
597  bool last_loop_mirrored;
598 
600 
603 
606 
609 
610  // Stores the current mouse_position as it was when updating MouseSensors.
611  // Used as input to updateX3DPointingDeviceSensors.
612  H3DInt32 mouse_position[2];
613  // Stores the previous mouse position.
614  H3DInt32 previous_mouse_position[2];
615  // Stores the current left mouse button state.
616  vector< bool > left_mouse_button;
617  // Stores previous left mouse button state.
618  bool previous_left_mouse_button;
619 
620  // Instance to class handling navigation for this window.
621  H3DNavigation * h3d_navigation;
622 
623  bool window_is_made_active, check_if_stereo_obtained;
624 
626  H3DUniquePtr<WindowSizeChanged> windowSizeChanged;
627 
628 
629 
630  void checkIfStereoObtained();
631  // function to calculate the number of viewport for window node which is the
632  // return value. viewports_size will contains a sequence of the viewport size infos
633  // for all the viewports. The function will take windows width and height and
634  // give back viewport width and height based on the stereo mode
635  void configureViewPortsSize( RenderMode::Mode stereo_mode,
636  H3DInt32& viewport_width, H3DInt32& viewport_height, H3DFloat* _viewports_size );
637  public:
638 
640  DEPRECATED("takeScreenshot", )
642 
645  static string takeScreenShot( const string &url );
646 
649  static string takeScreenshot( const string &url );
650  };
651 }
652 
653 #endif
Header file for DefaultAppearance.
Header file for FrameBufferTextureGenerator.
Contains the MFNode class.
Header file for NavigationInfo, X3D scene-graph node.
Contains the SFInt32 field class.
Contains the SFVec2f field class.
Header file for X3DViewpointNode, X3D scene-graph node.
The FrameBufferTextureGenerator node provides a mean to render a sub-scene into a texture instead of ...
Definition: FrameBufferTextureGenerator.h:209
H3DNavigation is a class used for navigation in H3DAPI.
Definition: H3DNavigation.h:41
Thrown when the value of RenderMode is an invalid mode.
Definition: H3DWindowNode.h:81
The mode for rendering specified as a string.
Definition: H3DWindowNode.h:78
bool isStereoMode()
Returns true if the current render mode is a stereo mode.
Definition: H3DWindowNode.h:162
bool isSinglePass()
Returns true if stereo rendering only need one pass.
Definition: H3DWindowNode.h:168
Mode
The different render modes supported.
Definition: H3DWindowNode.h:83
@ VERTICAL_SPLIT_KEEP_RATIO
Stereo mode where the left eye is rendered as the left half of the screen and the right eye as the ri...
Definition: H3DWindowNode.h:124
@ VERTICAL_INTERLACED
Stereo mode where every second vertical line is rendered for the left eye and every other line for th...
Definition: H3DWindowNode.h:100
@ RED_BLUE_STEREO
Stereo mode where the left eye is rendered in red and the right eye in blue.
Definition: H3DWindowNode.h:111
@ CHECKER_INTERLACED
Stereo mode where "white" and "black" in a checker pattern are rendered for the left and right eye,...
Definition: H3DWindowNode.h:103
@ MONO
Normal rendering.
Definition: H3DWindowNode.h:85
@ HORIZONTAL_SPLIT_KEEP_RATIO
Stereo mode where the left eye is rendered as the top half of the screen and the right eye as the bot...
Definition: H3DWindowNode.h:131
@ HORIZONTAL_INTERLACED
Stereo mode where every second horizontal line is rendered for the left eye and every other line for ...
Definition: H3DWindowNode.h:97
@ RED_CYAN_STEREO
Stereo mode where the left eye is rendered in red and the right eye in cyan.
Definition: H3DWindowNode.h:117
@ QUAD_BUFFERED_STEREO
Quad buffered stereo rendering.
Definition: H3DWindowNode.h:88
@ HDMI_FRAME_PACKED_1080P
HDMI 1.4 frame packed format.
Definition: H3DWindowNode.h:139
@ HDMI_FRAME_PACKED_720P
HDMI 1.4 frame packed format.
Definition: H3DWindowNode.h:135
@ VERTICAL_SPLIT
Stereo mode where the left eye is rendered as the left half of the screen and the right eye as the ri...
Definition: H3DWindowNode.h:94
@ NVIDIA_3DVISION
NVidia 3DVision format when not using quad-buffered stereo.
Definition: H3DWindowNode.h:145
@ HORIZONTAL_SPLIT
Stereo mode where the left eye is rendered as the top half of the screen and the right eye as the bot...
Definition: H3DWindowNode.h:91
@ VERTICAL_SPLIT_KEEP_ASPECT_ONE_PASS
It is almost the same as the VERTICAL_SPLIT_KEEP_RATIO model, left half of the screen for left eye an...
Definition: H3DWindowNode.h:153
@ RED_GREEN_STEREO
Stereo mode where the left eye is rendered in red and the right eye in green.
Definition: H3DWindowNode.h:114
@ VERTICAL_INTERLACED_GREEN_SHIFT
Stereo mode where every second vertical line is rendered for the left eye and every other line for th...
Definition: H3DWindowNode.h:108
void updateRebuildStencilMaskFlag()
Function to update rebuild_stencil_mask when necessary.
Definition: H3DWindowNode.h:179
Class which handles the windows resizing related operations.
Definition: H3DWindowNode.h:64
The base class for all window nodes.
Definition: H3DWindowNode.h:57
H3DUniquePtr< SFInt32 > width
The width in pixels of the window.
Definition: H3DWindowNode.h:324
virtual void initWindow()=0
Virtual function that should create a new window and set its properties depending on the fields.
H3DUniquePtr< WindowSizeChanged > windowSizeChanged
Field handles necessary operations needed when window size actually changes.
Definition: H3DWindowNode.h:626
H3DUniquePtr< SFInt32 > viewportHeight
The height of the viewport being used for this window Access type: outputOnly .
Definition: H3DWindowNode.h:420
virtual int setCursorType(const std::string &)
Set the cursor to the given cursor type.
Definition: H3DWindowNode.h:571
H3DUniquePtr< SFBool > singlePassStereo
Flag for whether singlePassStereo is enabled or not.
Definition: H3DWindowNode.h:433
RenderMode::Mode last_render_mode
The render mode used in the last render loop.
Definition: H3DWindowNode.h:602
H3DUniquePtr< SFBool > mirrored
Determines if the scene rendered should be mirrored or not.
Definition: H3DWindowNode.h:342
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: H3DWindowNode.h:490
H3DUniquePtr< SFBool > manualCursorControl
If set to true changes of cursor is totally up to the user of the window by changing the cursorType.
Definition: H3DWindowNode.h:369
H3DUniquePtr< SFBool > resetViewPoint
Reset viewpoint Access type: inputOutput Default value: false .
Definition: H3DWindowNode.h:449
H3DUniquePtr< SFInt32 > posY
The y coordinate in pixels of the window in screen coordinates.
Definition: H3DWindowNode.h:318
H3DUniquePtr< SFViewpoint > viewpoint
If the viewpoint field is specified, that viewpoint is used by the rendering in H3DWindowNode instead...
Definition: H3DWindowNode.h:360
virtual void setFullscreen(bool fullscreen)=0
Virtual function to set whether the window should be fullscreen or not.
H3DUniquePtr< SFInt32 > height
The height in pixels of the window.
Definition: H3DWindowNode.h:330
H3DUniquePtr< RenderMode > renderMode
The mode to render the scene in the window in.
Definition: H3DWindowNode.h:351
H3DUniquePtr< SFString > cursorType
The cursorType field specifies the look of the mouse pointer.
Definition: H3DWindowNode.h:382
H3DUniquePtr< SFBool > useFullscreenAntiAliasing
If set to true fullscreen anti-aliasing is used for this window.
Definition: H3DWindowNode.h:406
H3DUniquePtr< SFInt32 > viewportWidth
The width of the viewport being used for this window Access type: outputOnly .
Definition: H3DWindowNode.h:410
virtual void swapBuffers()=0
Virtual function to swap buffers.
X3DViewpointNode::EyeMode eye_mode
Current eye mode.
Definition: H3DWindowNode.h:605
H3DUniquePtr< SFInt32 > projectionHeight
The height of the projection height, mostly of the time it is the same as the viewport height.
Definition: H3DWindowNode.h:426
virtual void initWindowHandler()=0
Virtual function to initialize the window handler if needed.
H3DUniquePtr< SFVec2f > clipDistances
The distance (in meters) used for the far and near clip plane.
Definition: H3DWindowNode.h:398
H3DUniquePtr< SFInt32 > numSamples
Number of samples used by this window.
Definition: H3DWindowNode.h:455
H3DUniquePtr< SFNavigationInfo > navigationInfo
If the navigationInfo field is specified, that NavigationInfo is used for rendering in H3DWindowNode ...
Definition: H3DWindowNode.h:391
H3DUniquePtr< SFString > pointingDeviceRefreshMode
Determines how often the X3DPointingDeviceSensorNode's in the scene will be checked for intersection.
Definition: H3DWindowNode.h:444
H3DUniquePtr< SFInt32 > posX
The x coordinate in pixels of the window in screen coordinates.
Definition: H3DWindowNode.h:312
H3DUniquePtr< SFInt32 > projectionWidth
The width of the projection width, mostly of the time it is the same as the viewport width.
Definition: H3DWindowNode.h:415
string current_cursor
The cursor currently in use.
Definition: H3DWindowNode.h:608
H3DUniquePtr< SFBool > fullscreen
Determines if the window should be in fullscreen or not.
Definition: H3DWindowNode.h:336
virtual string getCursorForMode(const string &)
Return the cursor type to use for given modes.
Definition: H3DWindowNode.h:583
static void setMultiPassTransparency(bool b)
If multi pass transparency is set to true the scene will be rendered three times graphically,...
Definition: H3DWindowNode.h:555
virtual void makeWindowActive()=0
Virtual function to make the current window active, i.e.
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
The SFString field contains a string.
Definition: SFString.h:41
The Scene node is topmost node that takes care of the rendering of the scene graph both haptically an...
Definition: Scene.h:56
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The X3DViewpointNode node defines a specific location in the local coordinate system from which the u...
Definition: X3DViewpointNode.h:239
EyeMode
Used with setupProjection function to indicate for which eye the frustum should be calculated.
Definition: X3DViewpointNode.h:244
The OculusRiftHandler class provides support for the Oculus Rift VR device.
Definition: OculusRiftHandler.h:49
H3DDouble x
int H3DInt32
float H3DFloat
double H3DTime
H3D_VALUE_EXCEPTION(string, InvalidType)
An exception thrown when a field is of the wrong type when it is checked.
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194