1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <OpenGl_GraphicDriver.hxx>
15 #include <OpenGl_Context.hxx>
16 #include <OpenGl_CView.hxx>
18 #include <Standard_CLocaleSentry.hxx>
28 /************************************************************************/
30 /************************************************************************/
33 Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName,
34 const Graphic3d_ExportFormat theFormat,
35 const Graphic3d_SortType theSortType,
36 const Standard_Integer theWidth,
37 const Standard_Integer theHeight,
38 const Graphic3d_CView& theView,
39 const Aspect_CLayer2d& theLayerUnder,
40 const Aspect_CLayer2d& theLayerOver,
41 const Standard_Real /*thePrecision*/,
42 const Standard_Address /*theProgressBarFunc*/,
43 const Standard_Address /*theProgressObject*/)
45 // gl2psBeginPage() will call OpenGL functions
46 // so we should activate correct GL context before redraw scene call
47 const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView;
48 if (aCView == NULL || !aCView->WS->GetGlContext()->MakeCurrent())
50 return Standard_False;
53 Standard_Integer aFormat = -1;
54 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
57 case Graphic3d_EF_PostScript:
60 case Graphic3d_EF_EnhPostScript:
63 case Graphic3d_EF_TEX:
66 case Graphic3d_EF_PDF:
69 case Graphic3d_EF_SVG:
72 case Graphic3d_EF_PGF:
75 case Graphic3d_EF_EMF:
76 //aFormat = GL2PS_EMF;
77 aFormat = GL2PS_PGF + 1; // 6
81 return Standard_False;
86 case Graphic3d_ST_Simple:
87 aSortType = GL2PS_SIMPLE_SORT;
89 case Graphic3d_ST_BSP_Tree:
90 aSortType = GL2PS_BSP_SORT;
97 aViewport[2] = theWidth;
98 aViewport[3] = theHeight;
100 GLint aBufferSize = 1024 * 1024;
101 GLint anErrCode = GL2PS_SUCCESS;
103 // gl2ps uses standard write functions and do not check locale
104 Standard_CLocaleSentry aLocaleSentry;
106 while (aBufferSize > 0)
108 // current patch for EMF support in gl2ps uses WinAPI functions to create file
109 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
110 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
111 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
113 0, 0, 0, aBufferSize, aFileH, theFileName);
114 if (anErrCode != GL2PS_SUCCESS)
116 // initialization failed
121 Redraw (theView, theLayerUnder, theLayerOver);
123 anErrCode = gl2psEndPage();
127 if (anErrCode == GL2PS_OVERFLOW)
132 return anErrCode == GL2PS_SUCCESS;
135 Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString /*theFileName*/,
136 const Graphic3d_ExportFormat /*theFormat*/,
137 const Graphic3d_SortType /*theSortType*/,
138 const Standard_Integer /*theWidth*/,
139 const Standard_Integer /*theHeight*/,
140 const Graphic3d_CView& /*theView*/,
141 const Aspect_CLayer2d& /*theLayerUnder*/,
142 const Aspect_CLayer2d& /*theLayerOver*/,
143 const Standard_Real /*thePrecision*/,
144 const Standard_Address /*theProgressBarFunc*/,
145 const Standard_Address /*theProgressObject*/)
147 return Standard_False;