Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
2166f0fa | 14 | #include <OpenGl_GraphicDriver.hxx> |
86fa64d9 | 15 | #include <OpenGl_Context.hxx> |
16 | #include <OpenGl_CView.hxx> | |
91322f44 | 17 | |
18 | #include <Standard_CLocaleSentry.hxx> | |
7fd59977 | 19 | |
20 | #ifdef HAVE_GL2PS | |
21 | #include <gl2ps.h> | |
22 | #endif | |
23 | ||
7fd59977 | 24 | /************************************************************************/ |
25 | /* Print Methods */ | |
26 | /************************************************************************/ | |
27 | ||
35e08fe8 | 28 | #ifdef HAVE_GL2PS |
5cedc27f K |
29 | Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName, |
30 | const Graphic3d_ExportFormat theFormat, | |
31 | const Graphic3d_SortType theSortType, | |
32 | const Standard_Integer theWidth, | |
33 | const Standard_Integer theHeight, | |
34 | const Graphic3d_CView& theView, | |
35 | const Aspect_CLayer2d& theLayerUnder, | |
36 | const Aspect_CLayer2d& theLayerOver, | |
105aae76 | 37 | const Standard_Real /*thePrecision*/, |
38 | const Standard_Address /*theProgressBarFunc*/, | |
39 | const Standard_Address /*theProgressObject*/) | |
7fd59977 | 40 | { |
86fa64d9 | 41 | // gl2psBeginPage() will call OpenGL functions |
42 | // so we should activate correct GL context before redraw scene call | |
43 | const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; | |
44 | if (aCView == NULL || !aCView->WS->GetGlContext()->MakeCurrent()) | |
45 | { | |
46 | return Standard_False; | |
47 | } | |
48 | ||
5cedc27f K |
49 | Standard_Integer aFormat = -1; |
50 | Standard_Integer aSortType = Graphic3d_ST_BSP_Tree; | |
51 | switch (theFormat) | |
7fd59977 | 52 | { |
5cedc27f K |
53 | case Graphic3d_EF_PostScript: |
54 | aFormat = GL2PS_PS; | |
55 | break; | |
56 | case Graphic3d_EF_EnhPostScript: | |
57 | aFormat = GL2PS_EPS; | |
58 | break; | |
59 | case Graphic3d_EF_TEX: | |
60 | aFormat = GL2PS_TEX; | |
61 | break; | |
62 | case Graphic3d_EF_PDF: | |
63 | aFormat = GL2PS_PDF; | |
64 | break; | |
65 | case Graphic3d_EF_SVG: | |
66 | aFormat = GL2PS_SVG; | |
67 | break; | |
68 | case Graphic3d_EF_PGF: | |
69 | aFormat = GL2PS_PGF; | |
70 | break; | |
71 | case Graphic3d_EF_EMF: | |
72 | //aFormat = GL2PS_EMF; | |
73 | aFormat = GL2PS_PGF + 1; // 6 | |
74 | break; | |
75 | default: | |
76 | // unsupported format | |
77 | return Standard_False; | |
7fd59977 | 78 | } |
79 | ||
5cedc27f | 80 | switch (theSortType) |
7fd59977 | 81 | { |
5cedc27f K |
82 | case Graphic3d_ST_Simple: |
83 | aSortType = GL2PS_SIMPLE_SORT; | |
84 | break; | |
85 | case Graphic3d_ST_BSP_Tree: | |
86 | aSortType = GL2PS_BSP_SORT; | |
87 | break; | |
88 | } | |
89 | ||
90 | GLint aViewport[4]; | |
91 | aViewport[0] = 0; | |
92 | aViewport[1] = 0; | |
93 | aViewport[2] = theWidth; | |
94 | aViewport[3] = theHeight; | |
7fd59977 | 95 | |
5cedc27f K |
96 | GLint aBufferSize = 1024 * 1024; |
97 | GLint anErrCode = GL2PS_SUCCESS; | |
7fd59977 | 98 | |
5cedc27f | 99 | // gl2ps uses standard write functions and do not check locale |
91322f44 | 100 | Standard_CLocaleSentry aLocaleSentry; |
7fd59977 | 101 | |
5cedc27f | 102 | while (aBufferSize > 0) |
7fd59977 | 103 | { |
5cedc27f K |
104 | // current patch for EMF support in gl2ps uses WinAPI functions to create file |
105 | FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL; | |
106 | anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType, | |
7fd59977 | 107 | GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/, |
108 | GL_RGBA, 0, NULL, | |
5cedc27f K |
109 | 0, 0, 0, aBufferSize, aFileH, theFileName); |
110 | if (anErrCode != GL2PS_SUCCESS) | |
111 | { | |
112 | // initialization failed | |
113 | if (aFileH != NULL) | |
114 | fclose (aFileH); | |
115 | break; | |
116 | } | |
117 | Redraw (theView, theLayerUnder, theLayerOver); | |
118 | ||
119 | anErrCode = gl2psEndPage(); | |
120 | if (aFileH != NULL) | |
121 | fclose (aFileH); | |
122 | ||
123 | if (anErrCode == GL2PS_OVERFLOW) | |
124 | aBufferSize *= 2; | |
125 | else | |
126 | break; | |
7fd59977 | 127 | } |
5cedc27f | 128 | return anErrCode == GL2PS_SUCCESS; |
35e08fe8 | 129 | } |
5cedc27f | 130 | #else |
35e08fe8 | 131 | Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString /*theFileName*/, |
132 | const Graphic3d_ExportFormat /*theFormat*/, | |
133 | const Graphic3d_SortType /*theSortType*/, | |
134 | const Standard_Integer /*theWidth*/, | |
135 | const Standard_Integer /*theHeight*/, | |
136 | const Graphic3d_CView& /*theView*/, | |
137 | const Aspect_CLayer2d& /*theLayerUnder*/, | |
138 | const Aspect_CLayer2d& /*theLayerOver*/, | |
139 | const Standard_Real /*thePrecision*/, | |
140 | const Standard_Address /*theProgressBarFunc*/, | |
141 | const Standard_Address /*theProgressObject*/) | |
142 | { | |
143 | return Standard_False; | |
7fd59977 | 144 | } |
973c2be1 | 145 | #endif |