Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
2166f0fa | 20 | |
5f8b738e | 21 | #include <OpenGl_GlCore11.hxx> |
22 | ||
2166f0fa SK |
23 | #if (defined(_WIN32) || defined(__WIN32__)) |
24 | #include <OpenGl_AVIWriter.hxx> | |
2166f0fa | 25 | #endif |
2166f0fa SK |
26 | |
27 | #include <OpenGl_FrameBuffer.hxx> | |
28 | #include <OpenGl_ResourceCleaner.hxx> | |
29 | #include <InterfaceGraphic_Graphic3d.hxx> | |
30 | #include <InterfaceGraphic_Visual3d.hxx> | |
31 | ||
32 | #include <OpenGl_Workspace.hxx> | |
33 | ||
34 | //call_togl_redraw | |
35 | void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView, | |
36 | const Aspect_CLayer2d& theCUnderLayer, | |
37 | const Aspect_CLayer2d& theCOverLayer) | |
38 | { | |
39 | if (!Activate()) | |
40 | return; | |
41 | ||
42 | // release pending GL resources | |
664cae74 | 43 | Handle(OpenGl_Context) aGlCtx = GetGlContext(); |
44 | OpenGl_ResourceCleaner::GetInstance()->Cleanup (aGlCtx); | |
2166f0fa | 45 | |
664cae74 | 46 | // cache render mode state |
47 | GLint aRendMode = GL_RENDER; | |
48 | glGetIntegerv (GL_RENDER_MODE, &aRendMode); | |
49 | aGlCtx->SetFeedback (aRendMode == GL_FEEDBACK); | |
50 | ||
51 | Tint toSwap = (aRendMode == GL_RENDER); // swap buffers | |
2166f0fa SK |
52 | GLint aViewPortBack[4]; |
53 | OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO; | |
54 | if (aFrameBuffer != NULL) | |
55 | { | |
56 | glGetIntegerv (GL_VIEWPORT, aViewPortBack); | |
57 | aFrameBuffer->SetupViewport(); | |
664cae74 | 58 | aFrameBuffer->BindBuffer (aGlCtx); |
2166f0fa SK |
59 | toSwap = 0; // no need to swap buffers |
60 | } | |
61 | ||
62 | Redraw1 (theCView, theCUnderLayer, theCOverLayer, toSwap); | |
63 | RedrawImmediatMode(); | |
64 | ||
65 | if (aFrameBuffer != NULL) | |
66 | { | |
664cae74 | 67 | aFrameBuffer->UnbindBuffer (aGlCtx); |
2166f0fa SK |
68 | // move back original viewport |
69 | glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]); | |
70 | } | |
71 | ||
72 | #if (defined(_WIN32) || defined(__WIN32__)) | |
73 | if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow)) | |
74 | { | |
75 | GLint params[4]; | |
76 | glGetIntegerv (GL_VIEWPORT, params); | |
77 | int nWidth = params[2] & ~0x7; | |
78 | int nHeight = params[3] & ~0x7; | |
79 | ||
80 | const int nBitsPerPixel = 24; | |
81 | GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8]; | |
82 | ||
83 | glPixelStorei (GL_PACK_ALIGNMENT, 1); | |
84 | glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData); | |
85 | OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel); | |
86 | delete[] aDumpData; | |
87 | } | |
88 | #endif | |
664cae74 | 89 | |
90 | // reset render mode state | |
91 | aGlCtx->SetFeedback (Standard_False); | |
2166f0fa | 92 | } |