+// Created on: 2011-10-20
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2014 OPEN CASCADE SAS
+//
+// 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 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.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <OpenGl_GraphicDriver.hxx>
-// File OpenGl_GraphicDriver_7.cxx
-// Created Mardi 28 janvier 1997
-// Author CAL
-// Modified GG 10/11/99 PRO19603 Change the Redraw method (add redraw area capabillity)
-// EUG 07/10/99 G003 Add DegenerateStructure() and
-// SetBackFacingModel() methods.
-
-//-Copyright MatraDatavision 1997
-
-//-Version
-
-//-Design Declaration des variables specifiques aux Drivers
-
-//-Warning Un driver encapsule les Pex et OpenGl drivers
-
-//-References
-
-//-Language C++ 2.0
-
-//-Declarations
-
-// for the class
-#include <OpenGl_GraphicDriver.jxx>
-
-#include <Aspect_DriverDefinitionError.hxx>
-#include <InterfaceGraphic_RawBufferData.hxx>
-
-#include <OpenGl_tgl_funcs.hxx>
-#include <OpenGl_tsm_ws.hxx>
-#include <OpenGl_tgl_tox.hxx>
-#include <OpenGl_txgl.hxx>
#include <OpenGl_FrameBuffer.hxx>
-//-Aliases
-
-//-Global data definitions
-
-//-Methods, in order
-
-void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
+#include <OpenGl_Structure.hxx>
+#include <OpenGl_CView.hxx>
+#include <OpenGl_Text.hxx>
- if (MyTraceLevel) {
- PrintFunction ("call_togl_activateview");
- PrintCView (MyCView, 1);
- }
- call_togl_activateview (&MyCView);
+/*----------------------------------------------------------------------*/
+void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->WS->SetActiveView(aCView->View);
}
-void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_antialiasing");
- PrintCView (MyCView, 1);
- PrintBoolean ("AFlag", AFlag);
- }
- call_togl_antialiasing (&MyCView, (AFlag ? 1 : 0));
-
+void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->View->SetAntiAliasing(AFlag);
}
-void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_background");
- PrintCView (MyCView, 1);
+void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ aCView->WS->SetBackgroundColor(ACView.DefWindow.Background.r,ACView.DefWindow.Background.g,ACView.DefWindow.Background.b);
}
- call_togl_background (&MyCView);
-
}
-void OpenGl_GraphicDriver::GradientBackground(const Graphic3d_CView& ACView,
+void OpenGl_GraphicDriver::GradientBackground (const Graphic3d_CView& ACView,
const Quantity_Color& AColor1,
const Quantity_Color& AColor2,
- const Aspect_GradientFillMethod AType){
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_gradient_background");
- PrintCView (MyCView, 1);
- }
- Standard_Real R1,G1,B1,R2,G2,B2;
- AColor1.Values( R1, G1, B1, Quantity_TOC_RGB );
- AColor2.Values( R2, G2, B2, Quantity_TOC_RGB );
- TEL_COLOUR tcolor1, tcolor2;
- tcolor1.rgb[0] = R1;
- tcolor1.rgb[1] = G1;
- tcolor1.rgb[2] = B1;
- tcolor1.rgb[3] = 0;
- tcolor2.rgb[0] = R2;
- tcolor2.rgb[1] = G2;
- tcolor2.rgb[2] = B2;
- tcolor2.rgb[3] = 0;
-
- call_togl_gradient_background (MyCView.WsId, AType, &tcolor1, &tcolor2);
-
-}
-
-
-void OpenGl_GraphicDriver::Blink (const Graphic3d_CStructure& ACStructure, const Standard_Boolean Create) {
-
- Graphic3d_CStructure MyCStructure = ACStructure;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_blink");
- PrintCStructure (MyCStructure, 1);
- PrintBoolean ("Create", Create);
- }
- call_togl_blink (&MyCStructure, (Create ? 1 : 0));
-
-}
-
-void OpenGl_GraphicDriver::BoundaryBox (const Graphic3d_CStructure& ACStructure, const Standard_Boolean Create) {
-
- Graphic3d_CStructure MyCStructure = ACStructure;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_boundarybox");
- PrintCStructure (MyCStructure, 1);
- PrintBoolean ("Create", Create);
- }
- call_togl_boundarybox (&MyCStructure, (Create ? 1 : 0));
-
-}
-
-void OpenGl_GraphicDriver::HighlightColor (const Graphic3d_CStructure& ACStructure, const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B, const Standard_Boolean Create) {
-
- Graphic3d_CStructure MyCStructure = ACStructure;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_highlightcolor");
- PrintCStructure (MyCStructure, 1);
- PrintShortReal ("R", R);
- PrintShortReal ("G", G);
- PrintShortReal ("B", B);
+ const Aspect_GradientFillMethod AType)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ aCView->View->SetBackgroundGradient(AColor1,AColor2,AType);
}
- CALL_DEF_COLOR acolor;
- acolor.r = R;
- acolor.g = G;
- acolor.b = B;
- call_togl_highlightcolor (&MyCStructure, &acolor, (Create ? 1 : 0));
-
}
-void OpenGl_GraphicDriver::NameSetStructure (const Graphic3d_CStructure& ACStructure) {
-
- Graphic3d_CStructure MyCStructure = ACStructure;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_namesetstructure");
- PrintCStructure (MyCStructure, 1);
+void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ aCView->View->SetClipLimit(ACView);
+ if (!AWait)
+ {
+ aCView->WS->Resize(ACView.DefWindow);
+ }
}
- call_togl_namesetstructure (&MyCStructure);
-
}
-void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_cliplimit");
- PrintCView (MyCView, 1);
- PrintBoolean ("AWait", AWait);
+void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ const Handle(OpenGl_View) aDummyView;
+ aCView->WS->SetActiveView(aDummyView);
}
- call_togl_cliplimit (&MyCView, (AWait ? 1 : 0));
-
}
-void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView) {
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_deactivateview");
- PrintCView (MyCView, 1);
- }
- call_togl_deactivateview (&MyCView);
-
+void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->View->SetFog(ACView, AFlag);
}
-void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_depthcueing");
- PrintCView (MyCView, 1);
- PrintBoolean ("AFlag", AFlag);
- }
- call_togl_depthcueing (&MyCView, (AFlag ? 1 : 0));
-
+void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& theCView)
+{
+ const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
+ if (aCView != NULL)
+ aCView->WS->Resize (theCView.DefWindow);
}
-Standard_Boolean OpenGl_GraphicDriver::ProjectRaster (const Graphic3d_CView& ACView, const Standard_ShortReal AX, const Standard_ShortReal AY, const Standard_ShortReal AZ, Standard_Integer& AU, Standard_Integer& AV) {
-
- Graphic3d_CView MyCView = ACView;
-
- Standard_Integer Result;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_project_raster");
- PrintCView (MyCView, 1);
- }
- //if we want project something before to dump it into pixmap
- if ( ACView.DefBitmap.bitmap ) {
- Result = call_togl_adopt_to_rect( ACView.ViewId,
- ACView.DefBitmap.width,
- ACView.DefBitmap.height );
- if (MyTraceLevel) {
- PrintIResult ("call_togl_adopt_to_rect", Result);
+void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView,
+ const Aspect_CLayer2d& ACUnderLayer,
+ const Aspect_CLayer2d& ACOverLayer,
+ const Standard_Integer /*x*/,
+ const Standard_Integer /*y*/,
+ const Standard_Integer /*width*/,
+ const Standard_Integer /*height*/)
+{
+ if (ACView.RenderParams.Method == Graphic3d_RM_RAYTRACING
+ && !myCaps->vboDisable
+ && !myCaps->keepArrayData)
+ {
+ if (ACView.WasRedrawnGL)
+ {
+ myDeviceLostFlag = Standard_True;
}
- if (Result)
- return Standard_False;
- }
-
- Result = call_togl_project_raster (ACView.ViewId, AX, AY, AZ, &AU, &AV);
- if (MyTraceLevel) {
- PrintIResult ("call_togl_project_raster", Result);
- }
- if ( ACView.DefBitmap.bitmap ) {
- Result = call_togl_adopt_to_rect( ACView.ViewId,
- ACView.DefWindow.dx,
- ACView.DefWindow.dy );
- if (MyTraceLevel) {
- PrintIResult ("call_togl_adopt_to_rect", Result);
- }
- if (Result)
- return Standard_False;
+ myCaps->keepArrayData = Standard_True;
}
- return (Result == 0 ? Standard_True : Standard_False);
-
-}
-
-Standard_Boolean OpenGl_GraphicDriver::UnProjectRaster (const Graphic3d_CView& ACView, const Standard_Integer Axm, const Standard_Integer Aym, const Standard_Integer AXM, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az) {
-
- Graphic3d_CView MyCView = ACView;
-
- Standard_Integer Result;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_unproject_raster");
- PrintCView (MyCView, 1);
- }
- Result = call_togl_unproject_raster
- (ACView.ViewId, Axm, Aym, AXM, AYM, AU, AV, &Ax, &Ay, &Az);
- if (MyTraceLevel) {
- PrintIResult ("call_togl_unproject_raster", Result);
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ /*if( width <= 0 || height <= 0 )
+ aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
+ else
+ aCView->WS->RedrawArea(ACView, ACUnderLayer, ACOverLayer, x, y, width, height);*/
+ // Always do full redraw
+ aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
}
- return (Result == 0 ? Standard_True : Standard_False);
-
}
-Standard_Boolean OpenGl_GraphicDriver::UnProjectRasterWithRay (const Graphic3d_CView& ACView, const Standard_Integer Axm, const Standard_Integer Aym, const Standard_Integer AXM, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az, Standard_ShortReal& Dx, Standard_ShortReal& Dy, Standard_ShortReal& Dz) {
-
- Graphic3d_CView MyCView = ACView;
-
- Standard_Integer Result;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_unproject_raster_with_ray");
- PrintCView (MyCView, 1);
- }
- Result = call_togl_unproject_raster_with_ray
- (ACView.ViewId, Axm, Aym, AXM, AYM, AU, AV, &Ax, &Ay, &Az, &Dx, &Dy, &Dz);
- if (MyTraceLevel) {
- PrintIResult ("call_togl_unproject_raster_with_ray", Result);
+void OpenGl_GraphicDriver::RedrawImmediate (const Graphic3d_CView& theCView,
+ const Aspect_CLayer2d& theCUnderLayer,
+ const Aspect_CLayer2d& theCOverLayer)
+{
+ const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
+ if (aCView != NULL)
+ {
+ aCView->WS->RedrawImmediate (theCView, theCUnderLayer, theCOverLayer);
}
- return (Result == 0 ? Standard_True : Standard_False);
-
}
-void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_ratio_window");
- PrintCView (MyCView, 1);
+void OpenGl_GraphicDriver::Invalidate (const Graphic3d_CView& theCView)
+{
+ const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
+ if (aCView != NULL)
+ {
+ aCView->WS->Invalidate (theCView);
}
- call_togl_ratio_window (&MyCView);
-
}
-void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
-
- Graphic3d_CView MyCView = ACView;
- Aspect_CLayer2d MyCUnderLayer = ACUnderLayer;
- Aspect_CLayer2d MyCOverLayer = ACOverLayer;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_redraw");
- PrintCView (MyCView, 1);
- }
- //PRO19603
- if( width <= 0 || height <= 0 )
- call_togl_redraw (&MyCView, &MyCUnderLayer, &MyCOverLayer);
- else {
- call_togl_redraw_area (&MyCView, &MyCUnderLayer, &MyCOverLayer,
- x, y, width, height);
- }
- //PRO19603
+Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& ACView, const Standard_Integer theWidth, const Standard_Integer theHeight)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ return aCView->WS->FBOCreate(theWidth, theHeight);
+ return (Graphic3d_PtrFrameBuffer)NULL;
}
-Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& theCView,
- const Standard_Integer theWidth,
- const Standard_Integer theHeight) {
+Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth,
+ const Standard_Integer theHeight)
+{
// activate OpenGL context
- CMN_KEY_DATA aData;
- if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
- (TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
- {
+ if (!Activate())
return NULL;
- }
+
// create the FBO
+ const Handle(OpenGl_Context)& aCtx = GetGlContext();
OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
- if (!aFrameBuffer->Init (theWidth, theHeight))
+ if (!aFrameBuffer->Init (aCtx, theWidth, theHeight))
{
+ aFrameBuffer->Release (aCtx.operator->());
delete aFrameBuffer;
return NULL;
}
return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
}
-void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& theCView,
- Graphic3d_PtrFrameBuffer& theFBOPtr)
+void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr)
{
if (theFBOPtr == NULL)
- {
return;
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ aCView->WS->FBORelease(theFBOPtr);
+ theFBOPtr = NULL;
}
+}
+
+void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr)
+{
// activate OpenGL context
- CMN_KEY_DATA aData;
- if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
- (TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
+ if (!Activate()
+ || theFBOPtr == NULL)
{
return;
}
+
// release the object
- OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
+ OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr;
+ if (aFrameBuffer != NULL)
+ {
+ aFrameBuffer->Release (GetGlContext().operator->());
+ }
delete aFrameBuffer;
- theFBOPtr = NULL;
}
void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& ,
aFrameBuffer->ChangeViewport (theWidth, theHeight);
}
-// OpenGL 1.2 stuff
-#ifndef GL_BGR
- #define GL_BGR 0x80E0
-#endif
-#ifndef GL_BGRA
- #define GL_BGRA 0x80E1
-#endif
-
-
-static inline GLenum TFormatToGLEnum (const TRawBufferDataFormat theTFormat)
+inline bool getDataFormat (const Image_PixMap& theData,
+ GLenum& thePixelFormat,
+ GLenum& theDataType)
{
- switch (theTFormat)
+ thePixelFormat = GL_RGB;
+ theDataType = GL_UNSIGNED_BYTE;
+ switch (theData.Format())
{
- case TRGB: return GL_RGB;
- case TBGR: return GL_BGR;
- case TRGBA: return GL_RGBA;
- case TBGRA: return GL_BGRA;
- case TDepthComponent: return GL_DEPTH_COMPONENT;
- case TRed: return GL_RED;
- case TGreen: return GL_GREEN;
- case TBlue: return GL_BLUE;
- case TAlpha: return GL_ALPHA;
- default: return 0;
+ case Image_PixMap::ImgGray:
+ thePixelFormat = GL_DEPTH_COMPONENT;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ case Image_PixMap::ImgRGB:
+ thePixelFormat = GL_RGB;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ case Image_PixMap::ImgBGR:
+ thePixelFormat = GL_BGR;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ case Image_PixMap::ImgRGBA:
+ case Image_PixMap::ImgRGB32:
+ thePixelFormat = GL_RGBA;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ case Image_PixMap::ImgBGRA:
+ case Image_PixMap::ImgBGR32:
+ thePixelFormat = GL_BGRA;
+ theDataType = GL_UNSIGNED_BYTE;
+ return true;
+ case Image_PixMap::ImgGrayF:
+ thePixelFormat = GL_DEPTH_COMPONENT;
+ theDataType = GL_FLOAT;
+ return true;
+ case Image_PixMap::ImgRGBF:
+ thePixelFormat = GL_RGB;
+ theDataType = GL_FLOAT;
+ return true;
+ case Image_PixMap::ImgBGRF:
+ thePixelFormat = GL_BGR;
+ theDataType = GL_FLOAT;
+ return true;
+ case Image_PixMap::ImgRGBAF:
+ thePixelFormat = GL_RGBA;
+ theDataType = GL_FLOAT;
+ return true;
+ case Image_PixMap::ImgBGRAF:
+ thePixelFormat = GL_BGRA;
+ theDataType = GL_FLOAT;
+ return true;
+ default:
+ return false;
}
}
-static inline GLenum TTypeToGLEnum (const TRawBufferDataType theTType)
+Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView,
+ Image_PixMap& theImage,
+ const Graphic3d_BufferType& theBufferType)
{
- switch (theTType)
- {
- case TUByte: return GL_UNSIGNED_BYTE;
- case TFloat: return GL_FLOAT;
- default: return 0;
- }
+ const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
+ return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType);
}
-Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView,
- Image_CRawBufferData& theBuffer)
+Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr,
+ Image_PixMap& theImage,
+ const Graphic3d_BufferType& theBufferType)
{
- GLenum aFormat = TFormatToGLEnum (theBuffer.format);
- GLenum aType = TTypeToGLEnum (theBuffer.type);
-
- // safe checks
- if (aFormat == 0 || aType == 0 ||
- theBuffer.widthPx == 0 || theBuffer.heightPx == 0 ||
- theBuffer.dataPtr == NULL)
- {
- return Standard_False;
- }
-
- // activate OpenGL context
- CMN_KEY_DATA aData;
- if ((TsmGetWSAttri (theCView.WsId, WSWindow, &aData) != TSuccess) ||
- (TxglWinset (call_thedisplay, (WINDOW) aData.ldata) != TSuccess))
+ GLenum aFormat, aType;
+ if (theImage.IsEmpty()
+ || !getDataFormat (theImage, aFormat, aType)
+ || ((theBufferType == Graphic3d_BT_Depth) && (aFormat != GL_DEPTH_COMPONENT))
+ || !Activate())
{
return Standard_False;
}
// bind FBO if used
- OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
GLint aReadBufferPrev = GL_BACK;
- if (aFrameBuffer != NULL && aFrameBuffer->IsValid())
+ if (theFBOPtr != NULL && theFBOPtr->IsValid())
{
- aFrameBuffer->BindBuffer();
+ theFBOPtr->BindBuffer (GetGlContext());
}
else
{
glReadBuffer (aDrawBufferPrev);
}
- GLint anAlignBack = 1;
- glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack);
- if (theBuffer.rowAligmentBytes == 0)
+ // setup alignment
+ const GLint anExtraBytes = (GLint )theImage.RowExtraBytes();
+ const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
+ glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
+
+ const GLint aPixelsWidth = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes());
+ glPixelStorei (GL_PACK_ROW_LENGTH, (anExtraBytes >= anAligment) ? aPixelsWidth : 0);
+
+ if (theImage.IsTopDown())
{
- theBuffer.rowAligmentBytes = 1;
+ // copy row by row
+ for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
+ {
+ // Image_PixMap rows indexation always starts from the upper corner
+ // while order in memory depends on the flag and processed by ChangeRow() method
+ glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
+ }
+ }
+ else
+ {
+ glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
}
- glPixelStorei (GL_PACK_ALIGNMENT, theBuffer.rowAligmentBytes);
- // read pixels
- glReadPixels (0, 0, theBuffer.widthPx, theBuffer.heightPx, aFormat, aType, (GLvoid* )theBuffer.dataPtr);
- glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
+ glPixelStorei (GL_PACK_ALIGNMENT, 1);
+ glPixelStorei (GL_PACK_ROW_LENGTH, 0);
- if (aFrameBuffer != NULL && aFrameBuffer->IsValid())
+ if (theFBOPtr != NULL && theFBOPtr->IsValid())
{
- aFrameBuffer->UnbindBuffer();
+ theFBOPtr->UnbindBuffer (GetGlContext());
}
else
{
return Standard_True;
}
-void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_removeview");
- PrintCView (MyCView, 1);
+void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView)
+{
+ Handle(OpenGl_Context) aCtx = GetSharedContext();
+ Handle(OpenGl_View) aView;
+ Handle(OpenGl_Workspace) aWindow;
+ if (myMapOfWS.Find (theCView.WsId, aWindow))
+ {
+ myMapOfWS.UnBind (theCView.WsId);
}
- call_togl_removeview (&MyCView);
-
-}
-
-void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_setlight");
- PrintCView (MyCView, 1);
+ if (!aWindow.IsNull())
+ {
+ if (aWindow->GetGlContext()->MakeCurrent())
+ {
+ aCtx = aWindow->GetGlContext();
+ }
+ else
+ {
+ // try to hijack another context if any
+ const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext();
+ if (!anOtherCtx.IsNull()
+ && anOtherCtx != aWindow->GetGlContext())
+ {
+ aCtx = anOtherCtx;
+ aCtx->MakeCurrent();
+ }
+ }
}
- call_togl_setlight (&MyCView);
-
-}
-
-void OpenGl_GraphicDriver::SetPlane (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_setplane");
- PrintCView (MyCView, 1);
+ if (myMapOfView.Find (theCView.ViewId, aView))
+ {
+ aView->ReleaseGlResources (aCtx);
+ myMapOfView.UnBind (theCView.ViewId);
}
- call_togl_setplane (&MyCView);
-
-}
-
-void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
- if (MyTraceLevel) {
- PrintFunction ("call_togl_setvisualisation");
- PrintCView (MyCView, 1);
+ if (myMapOfWS.IsEmpty())
+ {
+ // The last view removed but some objects still present.
+ // Release GL resources now without object destruction.
+ for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
+ aStructIt.More (); aStructIt.Next())
+ {
+ OpenGl_Structure* aStruct = aStructIt.ChangeValue();
+ aStruct->ReleaseGlResources (aCtx);
+ }
+ myTempText->Release (aCtx.operator->());
+ myDeviceLostFlag = !myMapOfStructure.IsEmpty();
}
- call_togl_setvisualisation (&MyCView);
-}
+ OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView;
+ delete aCView;
+ ((Graphic3d_CView *)&theCView)->ptrView = NULL;
-void OpenGl_GraphicDriver::TransformStructure (const Graphic3d_CStructure& ACStructure) {
+ aCtx.Nullify();
+ aView.Nullify();
+ aWindow.Nullify();
+}
- Graphic3d_CStructure MyCStructure = ACStructure;
+void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->View->SetLights(ACView.Context);
+}
- if (MyTraceLevel) {
- PrintFunction ("call_togl_transformstructure");
- PrintCStructure (MyCStructure, 1);
+void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
+ if (aCView)
+ {
+ aCView->View->SetClipPlanes (theCView.Context.ClipPlanes);
}
- call_togl_transformstructure (&MyCStructure);
-
}
-void OpenGl_GraphicDriver :: DegenerateStructure (
- const Graphic3d_CStructure& ACStructure
- ) {
- Graphic3d_CStructure MyCStructure = ACStructure;
-
- if ( MyTraceLevel ) {
-
- PrintFunction ( "call_togl_degeneratestructure" );
- PrintCStructure ( MyCStructure, 1 );
-
- } // end if
-
- call_togl_degeneratestructure ( &MyCStructure );
- } // end OpenGl_GraphicDriver :: DegenerateStructure
-
- void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) {
-
- Graphic3d_CView MyCView = ACView;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_transparency");
- PrintCView (MyCView, 1);
- PrintBoolean ("AFlag", AFlag);
- }
- call_togl_transparency (MyCView.WsId, MyCView.ViewId, (AFlag ? 1 : 0));
-
+//=======================================================================
+//function : SetCamera
+//purpose :
+//=======================================================================
+void OpenGl_GraphicDriver::SetCamera (const Graphic3d_CView& theCView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
+ if (aCView)
+ {
+ aCView->View->SetCamera (theCView.Context.Camera);
}
+}
- void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer) {
-
- Graphic3d_CView MyCView = ACView;
- Aspect_CLayer2d MyCUnderLayer = ACUnderLayer;
- Aspect_CLayer2d MyCOverLayer = ACOverLayer;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_update");
- PrintCView (MyCView, 1);
- }
- call_togl_update (&MyCView, &MyCUnderLayer, &MyCOverLayer);
-
+void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ {
+ aCView->View->SetVisualisation(ACView.Context);
+ aCView->WS->UseZBuffer() = ( ACView.Context.Visualization == 0? (ACView.Context.ZBufferActivity == 1) : (ACView.Context.ZBufferActivity != 0) );
}
+}
- Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& ACView) {
-
- Graphic3d_CView MyCView = ACView;
- Standard_Integer Result;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_view");
- PrintCView (MyCView, 1);
- }
- Result = call_togl_view (&MyCView);
- if (MyTraceLevel) {
- PrintIResult ("call_togl_view", Result);
- }
- return (Result == 1 ? Standard_True : Standard_False);
+void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->WS->UseTransparency(AFlag);
+}
+// =======================================================================
+// function : InvalidateBVHData
+// purpose :
+// =======================================================================
+void OpenGl_GraphicDriver::InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId)
+{
+ OpenGl_CView *aCView = (OpenGl_CView *)theCView.ptrView;
+ if(aCView)
+ {
+ aCView->View->InvalidateBVHData (theLayerId);
}
+}
- void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
-
- Graphic3d_CView MyCView = ACView;
- Standard_Integer Result;
-
- if (MyTraceLevel) {
- PrintFunction ("call_togl_viewmapping");
- PrintCView (MyCView, 1);
- PrintBoolean ("AWait", AWait);
- }
- Result = call_togl_viewmapping (&MyCView, (AWait ? 1 : 0));
- if (MyTraceLevel) {
- PrintIResult ("call_togl_viewmapping", Result);
- }
-
+Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView)
+{
+ if (myMapOfView.IsBound (theCView.ViewId)
+ || myMapOfWS .IsBound (theCView.WsId))
+ {
+ return Standard_False;
}
- void OpenGl_GraphicDriver::ViewOrientation (const Graphic3d_CView& ACView, const Standard_Boolean AWait) {
+ Handle(OpenGl_Context) aShareCtx = GetSharedContext();
+ Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (myDisplayConnection, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
+ Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context, &myStateCounter);
+ myMapOfWS .Bind (theCView.WsId, aWS);
+ myMapOfView.Bind (theCView.ViewId, aView);
- Graphic3d_CView MyCView = ACView;
- Standard_Integer Result;
+ OpenGl_CView* aCView = new OpenGl_CView();
+ aCView->View = aView;
+ aCView->WS = aWS;
+ theCView.ptrView = aCView;
- if (MyTraceLevel) {
- PrintFunction ("call_togl_vieworientation");
- PrintCView (MyCView, 1);
- PrintBoolean ("AWait", AWait);
- }
- Result = call_togl_vieworientation (&MyCView, (AWait ? 1 : 0));
- if (MyTraceLevel) {
- PrintIResult ("call_togl_viewmapping", Result);
- }
-
- }
+ return Standard_True;
+}
- void OpenGl_GraphicDriver :: SetBackFacingModel ( const Graphic3d_CView& aView )
- {
- Graphic3d_CView myView = aView;
+void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
+ if (aCView)
+ aCView->View->SetBackfacing(ACView.Backfacing);
+}
- if ( MyTraceLevel ) {
+//=======================================================================
+//function : AddZLayer
+//purpose :
+//=======================================================================
- PrintFunction ( "call_togl_backfacing" );
- PrintCView ( myView, 1 );
+void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView,
+ const Standard_Integer theLayerId)
+{
+ const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
+ if (aCView)
+ aCView->View->AddZLayer (theLayerId);
+}
- } // end if
+//=======================================================================
+//function : RemoveZLayer
+//purpose :
+//=======================================================================
+void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView,
+ const Standard_Integer theLayerId)
+{
+ const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView;
+ if (aCView)
+ aCView->View->RemoveZLayer (theLayerId);
+}
- call_togl_backfacing ( &myView );
- } // end Graphic3d_GraphicDriver :: SetBackFacingModel
+//=======================================================================
+//function : SetZLayerSettings
+//purpose :
+//=======================================================================
+Standard_EXPORT void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_CView& theCView,
+ const Standard_Integer theLayerId,
+ const Graphic3d_ZLayerSettings& theSettings)
+{
+ const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
+ if (aCView)
+ aCView->View->SetZLayerSettings (theLayerId, theSettings);
+}