1 // Created on: 2015-06-10 2 // Created by: Kirill Gavrilov 3 // Copyright (c) 2015 OPEN CASCADE SAS 4 // 5 // This file is part of Open CASCADE Technology software library. 6 // 7 // This library is free software; you can redistribute it and/or modify it under 8 // the terms of the GNU Lesser General Public License version 2.1 as published 9 // by the Free Software Foundation, with special exception defined in the file 10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 11 // distribution for complete text of the license and disclaimer of any warranty. 12 // 13 // Alternatively, this file may be used under the terms of Open CASCADE 14 // commercial license or contractual agreement. 15 16 #ifndef _D3DHost_View_HeaderFile 17 #define _D3DHost_View_HeaderFile 18 19 #include <D3DHost_FrameBuffer.hxx> 20 #include <OpenGl_View.hxx> 21 #include <OpenGl_Workspace.hxx> 22 23 class D3DHost_GraphicDriver; 24 struct IDirect3D9; 25 struct IDirect3DDevice9; 26 typedef struct _D3DPRESENT_PARAMETERS_ D3DPRESENT_PARAMETERS; 27 28 //! The D3D host view implementation that overrides rendering methods. 29 class D3DHost_View : public OpenGl_View 30 { 31 32 public: 33 34 //! Constructor. 35 Standard_EXPORT D3DHost_View (const Handle(Graphic3d_StructureManager)& theMgr, 36 const Handle(D3DHost_GraphicDriver)& theDriver, 37 const Handle(OpenGl_Caps)& theCaps, 38 OpenGl_StateCounter* theCounter); 39 40 //! Default destructor. 41 Standard_EXPORT virtual ~D3DHost_View(); 42 43 //! Release OpenGL resources. 44 Standard_EXPORT virtual void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) Standard_OVERRIDE; 45 46 //! Creates and maps rendering window to the view. 47 //! @param theWindow [in] the window. 48 //! @param theContext [in] the rendering context. If NULL the context will be created internally. 49 //! @param theDisplayCB [in] the display callback function. If is not a NULL value, then the callback will be 50 //! invoked at the end of the OCC graphic traversal and just before the swap of buffers. 51 //! @param theClientData [in] the client data for the callback. 52 Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow, 53 const Aspect_RenderingContext theContext) Standard_OVERRIDE; 54 55 //! Resizes the window. 56 Standard_EXPORT virtual void Resized() Standard_OVERRIDE; 57 58 //! Redraw the all content. 59 Standard_EXPORT virtual void Redraw() Standard_OVERRIDE; 60 61 //! Redraw only immediate layer. 62 Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE; 63 64 //! Fill in the dictionary with diagnostic info. 65 //! Should be called within rendering thread. 66 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict, 67 Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE; 68 69 public: 70 71 //! @return true if IDirect3DDevice9Ex device has been created isD3dEx() const72 bool isD3dEx() const { return myIsD3dEx; } 73 74 //! Access Direct3D device instance. D3dDevice() const75 IDirect3DDevice9* D3dDevice() const { return myD3dDevice; } 76 77 //! Return D3D/WGL FBO. Handle(D3DHost_FrameBuffer)78 const Handle(D3DHost_FrameBuffer)& D3dWglBuffer() const { return myD3dWglFbo; } 79 80 //! Return D3D surface. 81 Standard_EXPORT IDirect3DSurface9* D3dColorSurface() const; 82 83 protected: 84 85 //! Auxiliary method. 86 Standard_EXPORT static TCollection_AsciiString d3dFormatError (const long theErrCode); 87 88 //! Initialize the D3D library. 89 Standard_EXPORT bool d3dInitLib(); 90 91 //! Initialize Direct3D output device. 92 Standard_EXPORT bool d3dInit(); 93 94 //! Reset Direct3D output settings. Could be used to switch windowed/fullscreen modes. 95 //! Use very carefully! Most objects should be released before and recreated after! 96 Standard_EXPORT bool d3dReset(); 97 98 //! (Re-)create D3D surface. 99 Standard_EXPORT bool d3dCreateRenderTarget(); 100 101 //! Starts the scene render. 102 //! Clears the backbuffer and sets the device to start rendering to it. 103 Standard_EXPORT void d3dBeginRender(); 104 105 //! Ends the scene render. 106 Standard_EXPORT void d3dEndRender(); 107 108 //! Presents to the screen. 109 Standard_EXPORT bool d3dSwap(); 110 111 protected: 112 113 IDirect3D9* myD3dLib; //!< Direct3D library instance 114 IDirect3DDevice9* myD3dDevice; //!< Direct3D device object 115 NCollection_Handle<D3DPRESENT_PARAMETERS> 116 myD3dParams; //!< parameters for created Direct3D device 117 unsigned int myRefreshRate; //!< refresh rate in fullscreen mode 118 bool myIsD3dEx; //!< D3dEx flag for WDDM 119 Handle(D3DHost_FrameBuffer) myD3dWglFbo; //!< D3D/WGL interop FBO 120 121 public: 122 123 DEFINE_STANDARD_RTTIEXT(D3DHost_View,OpenGl_View) 124 125 }; 126 127 DEFINE_STANDARD_HANDLE(D3DHost_View, OpenGl_View) 128 129 #endif // #ifndef _D3DHost_View_HeaderFile 130