//
// This file is part of Open CASCADE Technology software library.
//
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
#include <OpenGl_View.hxx>
#include <OpenGl_Display.hxx>
-//10-05-96 : CAL ; Ajout d'un nouveau delta dans les copies de pixels (voir CALL_DEF_DELTA)
-#define CALL_DEF_DELTA 10
-// ---------------------------------------------------------------
-// Function: getNearestPowOfTwo
-// Purpose: get the nearest power of two for theNumber
-// ---------------------------------------------------------------
-static GLsizei getNearestPowOfTwo (const GLsizei theNumber)
-{
- GLsizei aLast = 1;
- for (GLsizei p2 = 1; p2 <= theNumber; aLast = p2, p2 <<= 1);
- return aLast;
-}
-
-// ---------------------------------------------------------------
-// Function: fitDimensionsRatio
-// Purpose: calculate correct width/height ratio for theWidth and
-// theHeight parameters
-// ---------------------------------------------------------------
-static void fitDimensionsRatio (Standard_Integer& theWidth,
- Standard_Integer& theHeight,
- const Standard_Real theViewRatio)
-{
- // set dimensions in accordance with the viewratio
- if (theHeight < theWidth/theViewRatio)
- theWidth = (Standard_Integer)(theHeight*theViewRatio);
+#ifdef _WIN32
- if (theWidth < theHeight*theViewRatio)
- theHeight = (Standard_Integer)(theWidth/theViewRatio);
-}
+#ifndef HAVE_FREEIMAGE
// ---------------------------------------------------------------
// Function: initBitmapBuffer
// Purpose: init device independent bitmap to hold printing data
// ---------------------------------------------------------------
-#ifdef _WIN32
-#ifndef HAVE_FREEIMAGE
static void initBitmapBuffer (const HDC theMemoryDC,
HBITMAP &theMemoryBmp,
const Standard_Integer theBmpWidth,
theMemoryBmp = CreateDIBSection (theMemoryDC, &aBitmapData, DIB_RGB_COLORS,
&theBufferPtr, NULL, 0);
}
-#else
+
+#else /* HAVE_FREEIMAGE */
+
// ---------------------------------------------------------------
// Function: imagePasteDC
// Purpose: copy the data from image buffer to the device context
return true;
}
-#endif
+
+#endif /* HAVE_FREEIMAGE */
+
+// ---------------------------------------------------------------
+// Function: getNearestPowOfTwo
+// Purpose: get the nearest power of two for theNumber
+// ---------------------------------------------------------------
+static GLsizei getNearestPowOfTwo (const GLsizei theNumber)
+{
+ GLsizei aLast = 1;
+ for (GLsizei p2 = 1; p2 <= theNumber; aLast = p2, p2 <<= 1);
+ return aLast;
+}
// ---------------------------------------------------------------
// Function: getMaxFrameSize
theHeight = (Standard_Integer)aMaxY;
}
+// ---------------------------------------------------------------
+// Function: fitDimensionsRatio
+// Purpose: calculate correct width/height ratio for theWidth and
+// theHeight parameters
+// ---------------------------------------------------------------
+static void fitDimensionsRatio (Standard_Integer& theWidth,
+ Standard_Integer& theHeight,
+ const Standard_Real theViewRatio)
+{
+ // set dimensions in accordance with the viewratio
+ if (theHeight < theWidth/theViewRatio)
+ theWidth = (Standard_Integer)(theHeight*theViewRatio);
+
+ if (theWidth < theHeight*theViewRatio)
+ theHeight = (Standard_Integer)(theWidth/theViewRatio);
+}
+
// ---------------------------------------------------------------
// Function: initBufferStretch
// Purpose: calculate initialization sizes for frame buffer
if (theFrameHeight > theViewHeight)
theFrameHeight = theViewHeight;
}
-#endif
+
+#endif /* _WIN32 */
// ---------------------------------------------------------------
// ---------------------------------------------------------------
myPrintContext->SetScale ((GLfloat )aFrameWidth /viewWidth,
(GLfloat )aFrameHeight/viewHeight);
aFrameBuffer->SetupViewport (GetGlContext());
- Redraw1(ACView, ACUnderLayer, ACOverLayer, 0);
+ redraw1 (ACView, ACUnderLayer, ACOverLayer, 0);
if (!myTransientDrawToFront)
{
// render to FBO only if allowed to render to back buffer
- RedrawImmediatMode();
+ RedrawImmediate (ACView, ACUnderLayer, ACOverLayer, Standard_True);
}
glReadPixels (0, 0, aFrameWidth, aFrameHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, (GLvoid* )aViewBuffer);
// draw to the offscreen buffer and capture the result
aFrameBuffer->SetupViewport (GetGlContext());
- Redraw1(ACView, ACUnderLayer, ACOverLayer, 0);
+ redraw1 (ACView, ACUnderLayer, ACOverLayer, 0);
if (!myTransientDrawToFront)
{
// render to FBO only if forces to render to back buffer
- RedrawImmediatMode();
+ RedrawImmediate (ACView, ACUnderLayer, ACOverLayer, Standard_True);
}
glReadPixels (0, 0, aFrameWidth, aFrameHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, (GLvoid* )aViewBuffer);
return Standard_False;
#endif
}
-
-/*----------------------------------------------------------------------*/
-
-//redrawView
-void OpenGl_Workspace::Redraw1 (const Graphic3d_CView& ACView,
- const Aspect_CLayer2d& ACUnderLayer,
- const Aspect_CLayer2d& ACOverLayer,
- const int aswap)
-{
- if (myDisplay.IsNull() || myView.IsNull())
- return;
-
- // Request reset of material
- NamedStatus |= OPENGL_NS_RESMAT;
-
- /* GL_DITHER on/off pour le background */
- if (myBackDither)
- glEnable (GL_DITHER);
- else
- glDisable (GL_DITHER);
-
- GLbitfield toClear = GL_COLOR_BUFFER_BIT;
- if ( myUseZBuffer )
- {
- glDepthFunc(GL_LEQUAL);
- glDepthMask(GL_TRUE);
-
- // SAV checking if depth test was deprecated somewhere outside
- if ( myUseDepthTest )
- glEnable(GL_DEPTH_TEST);
- else
- glDisable(GL_DEPTH_TEST);
-
- glClearDepth(1.0);
- toClear |= GL_DEPTH_BUFFER_BIT;
- }
- else
- {
- glDisable(GL_DEPTH_TEST);
- }
-
- if ( NamedStatus & OPENGL_NS_WHITEBACK )
- {
- // Set background to white
- glClearColor (1.F, 1.F, 1.F, 1.F);
- toClear |= GL_DEPTH_BUFFER_BIT;
- }
- else
- {
- glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.F);
- }
- glClear (toClear);
-
- Handle(OpenGl_Workspace) aWS(this);
- myView->Render (myPrintContext, aWS, ACView, ACUnderLayer, ACOverLayer);
-
- // Swap the buffers
- if ( aswap )
- {
- GetGlContext()->SwapBuffers();
- myBackBufferRestored = Standard_False;
- }
- else
- glFlush();
-}
-
-/*----------------------------------------------------------------------*/
-
-//TelCopyBuffers
-void OpenGl_Workspace::CopyBuffers (const Standard_Boolean theFrontToBack)
-{
- if (theFrontToBack)
- {
- myBackBufferRestored = Standard_False;
- }
-
- glMatrixMode (GL_PROJECTION);
- glPushMatrix ();
- glLoadIdentity ();
- gluOrtho2D ((GLdouble) 0., (GLdouble) myWidth, 0., (GLdouble) myHeight);
- glMatrixMode (GL_MODELVIEW);
- glPushMatrix ();
- glLoadIdentity ();
-
- DisableFeatures();
-
- glDrawBuffer (theFrontToBack ? GL_BACK : GL_FRONT);
- glReadBuffer (theFrontToBack ? GL_FRONT : GL_BACK);
-
- glRasterPos2i (0, 0);
- glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR);
-
- EnableFeatures();
-
- glMatrixMode (GL_PROJECTION);
- glPopMatrix ();
- glMatrixMode (GL_MODELVIEW);
- glPopMatrix ();
-
- glDrawBuffer (GL_BACK);
-}
-
-/*----------------------------------------------------------------------*/
-
-//call_subr_displayCB
-void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView,
- int theReason)
-{
- if (theCView.GDisplayCB == NULL)
- {
- return;
- }
-
- Aspect_GraphicCallbackStruct aCallData;
- aCallData.reason = theReason;
- aCallData.glContext = GetGlContext();
- aCallData.wsID = theCView.WsId;
- aCallData.viewID = theCView.ViewId;
- theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData);
-}
-
-/*----------------------------------------------------------------------*/