Commit | Line | Data |
---|---|---|
2166f0fa SK |
1 | // File: OpenGl_Workspace_3.cxx |
2 | // Created: 20 September 2011 | |
3 | // Author: Sergey ZERCHANINOV | |
4 | // Copyright: OPEN CASCADE 2011 | |
5 | ||
6 | #if (defined(_WIN32) || defined(__WIN32__)) | |
7 | #include <OpenGl_AVIWriter.hxx> | |
8 | #else | |
9 | #define CALL_DEF_STRING_LENGTH 132 | |
10 | #endif | |
11 | #include <OpenGl_tgl_all.hxx> | |
12 | ||
13 | #include <OpenGl_FrameBuffer.hxx> | |
14 | #include <OpenGl_ResourceCleaner.hxx> | |
15 | #include <InterfaceGraphic_Graphic3d.hxx> | |
16 | #include <InterfaceGraphic_Visual3d.hxx> | |
17 | ||
18 | #include <OpenGl_Workspace.hxx> | |
19 | ||
20 | //call_togl_redraw | |
21 | void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView, | |
22 | const Aspect_CLayer2d& theCUnderLayer, | |
23 | const Aspect_CLayer2d& theCOverLayer) | |
24 | { | |
25 | if (!Activate()) | |
26 | return; | |
27 | ||
28 | // release pending GL resources | |
29 | OpenGl_ResourceCleaner::GetInstance()->Cleanup (GetGlContext()); | |
30 | ||
31 | Tint toSwap = 1; // swap buffers | |
32 | GLint aViewPortBack[4]; | |
33 | OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO; | |
34 | if (aFrameBuffer != NULL) | |
35 | { | |
36 | glGetIntegerv (GL_VIEWPORT, aViewPortBack); | |
37 | aFrameBuffer->SetupViewport(); | |
38 | aFrameBuffer->BindBuffer (GetGlContext()); | |
39 | toSwap = 0; // no need to swap buffers | |
40 | } | |
41 | ||
42 | Redraw1 (theCView, theCUnderLayer, theCOverLayer, toSwap); | |
43 | RedrawImmediatMode(); | |
44 | ||
45 | if (aFrameBuffer != NULL) | |
46 | { | |
47 | aFrameBuffer->UnbindBuffer (GetGlContext()); | |
48 | // move back original viewport | |
49 | glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]); | |
50 | } | |
51 | ||
52 | #if (defined(_WIN32) || defined(__WIN32__)) | |
53 | if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow)) | |
54 | { | |
55 | GLint params[4]; | |
56 | glGetIntegerv (GL_VIEWPORT, params); | |
57 | int nWidth = params[2] & ~0x7; | |
58 | int nHeight = params[3] & ~0x7; | |
59 | ||
60 | const int nBitsPerPixel = 24; | |
61 | GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8]; | |
62 | ||
63 | glPixelStorei (GL_PACK_ALIGNMENT, 1); | |
64 | glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData); | |
65 | OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel); | |
66 | delete[] aDumpData; | |
67 | } | |
68 | #endif | |
69 | } |