0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_Export.cxx
CommitLineData
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
498ce577 20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
7fd59977 24#ifdef HAVE_GL2PS
25#include <gl2ps.h>
26#endif
27
7fd59977 28/************************************************************************/
29/* Print Methods */
30/************************************************************************/
31
35e08fe8 32#ifdef HAVE_GL2PS
5cedc27f
K
33Standard_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,
105aae76 41 const Standard_Real /*thePrecision*/,
42 const Standard_Address /*theProgressBarFunc*/,
43 const Standard_Address /*theProgressObject*/)
7fd59977 44{
86fa64d9 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())
49 {
50 return Standard_False;
51 }
52
5cedc27f
K
53 Standard_Integer aFormat = -1;
54 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
55 switch (theFormat)
7fd59977 56 {
5cedc27f
K
57 case Graphic3d_EF_PostScript:
58 aFormat = GL2PS_PS;
59 break;
60 case Graphic3d_EF_EnhPostScript:
61 aFormat = GL2PS_EPS;
62 break;
63 case Graphic3d_EF_TEX:
64 aFormat = GL2PS_TEX;
65 break;
66 case Graphic3d_EF_PDF:
67 aFormat = GL2PS_PDF;
68 break;
69 case Graphic3d_EF_SVG:
70 aFormat = GL2PS_SVG;
71 break;
72 case Graphic3d_EF_PGF:
73 aFormat = GL2PS_PGF;
74 break;
75 case Graphic3d_EF_EMF:
76 //aFormat = GL2PS_EMF;
77 aFormat = GL2PS_PGF + 1; // 6
78 break;
79 default:
80 // unsupported format
81 return Standard_False;
7fd59977 82 }
83
5cedc27f 84 switch (theSortType)
7fd59977 85 {
5cedc27f
K
86 case Graphic3d_ST_Simple:
87 aSortType = GL2PS_SIMPLE_SORT;
88 break;
89 case Graphic3d_ST_BSP_Tree:
90 aSortType = GL2PS_BSP_SORT;
91 break;
92 }
93
94 GLint aViewport[4];
95 aViewport[0] = 0;
96 aViewport[1] = 0;
97 aViewport[2] = theWidth;
98 aViewport[3] = theHeight;
7fd59977 99
5cedc27f
K
100 GLint aBufferSize = 1024 * 1024;
101 GLint anErrCode = GL2PS_SUCCESS;
7fd59977 102
5cedc27f 103 // gl2ps uses standard write functions and do not check locale
91322f44 104 Standard_CLocaleSentry aLocaleSentry;
7fd59977 105
5cedc27f 106 while (aBufferSize > 0)
7fd59977 107 {
5cedc27f
K
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,
7fd59977 111 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
112 GL_RGBA, 0, NULL,
5cedc27f
K
113 0, 0, 0, aBufferSize, aFileH, theFileName);
114 if (anErrCode != GL2PS_SUCCESS)
115 {
116 // initialization failed
117 if (aFileH != NULL)
118 fclose (aFileH);
119 break;
120 }
121 Redraw (theView, theLayerUnder, theLayerOver);
122
123 anErrCode = gl2psEndPage();
124 if (aFileH != NULL)
125 fclose (aFileH);
126
127 if (anErrCode == GL2PS_OVERFLOW)
128 aBufferSize *= 2;
129 else
130 break;
7fd59977 131 }
5cedc27f 132 return anErrCode == GL2PS_SUCCESS;
35e08fe8 133}
5cedc27f 134#else
35e08fe8 135Standard_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*/)
146{
147 return Standard_False;
7fd59977 148}
973c2be1 149#endif