0028487: Visualization, TKOpenGl - add option for rendering with lower resolution
authorkgv <kgv@opencascade.com>
Thu, 23 Feb 2017 17:50:42 +0000 (20:50 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 3 Mar 2017 13:11:22 +0000 (16:11 +0300)
Graphic3d_RenderingParams::RenderResolutionScale - added new option
defining scale factor for allocating off-screen rendering buffers
relative to native resolution of window buffer.

Scale factor can be below 1.0 (lower resolution) or higher (as analog of super sampling),
but can not be combined with MSAA settings.

Draw Harness command vrenderparams has been extended with option -rendScale
managing introduced option Graphic3d_RenderingParams::RenderResolutionScale.

vcaps has been extended with option -useWindowBuffer for managing
OpenGl_Caps::useSystemBuffer option.

vrepaint has been extended with option -immediate
for testing immediate layer redraw

OpenGl_View::blitBuffers() - eliminate compiler warning on Android

src/Graphic3d/Graphic3d_RenderingParams.hxx
src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_Context.hxx
src/OpenGl/OpenGl_Structure.cxx
src/OpenGl/OpenGl_Text.cxx
src/OpenGl/OpenGl_View_Redraw.cxx
src/Standard/Standard_TypeDef.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/glsl/rendscale [new file with mode: 0644]

index 33ca9e3..0ba2b79 100644 (file)
@@ -48,6 +48,7 @@ public:
   Graphic3d_RenderingParams()
   : Method                      (Graphic3d_RM_RASTERIZATION),
     NbMsaaSamples               (0),
+    RenderResolutionScale       (1.0f),
     // ray tracing parameters
     IsGlobalIlluminationEnabled (Standard_False),
     RaytracingDepth             (THE_DEFAULT_DEPTH),
@@ -91,6 +92,8 @@ public:
 
   Graphic3d_RenderingMode Method;                      //!< specifies rendering mode, Graphic3d_RM_RASTERIZATION by default
   Standard_Integer        NbMsaaSamples;               //!< number of MSAA samples (should be within 0..GL_MAX_SAMPLES, power-of-two number), 0 by default
+  Standard_ShortReal      RenderResolutionScale;       //!< rendering resolution scale factor, 1 by default;
+                                                       //!  incompatible with MSAA (e.g. NbMsaaSamples should be set to 0)
 
   Standard_Boolean        IsGlobalIlluminationEnabled; //!< enables/disables global illumination effects (path tracing)
   Standard_Integer        SamplesPerPixel;             //!< number of samples per pixel (SPP)
@@ -115,10 +118,10 @@ public:
   Standard_Boolean        ToReverseStereo;             //!< flag to reverse stereo pair, FALSE by default
 
   unsigned int            Resolution;                  //!< Pixels density (PPI), defines scaling factor for parameters like text size
-                                                       //!< (when defined in screen-space units rather than in 3D) to be properly displayed
-                                                       //!< on device (screen / printer). 72 is default value.
-                                                       //!< Note that using difference resolution in different Views in same Viewer
-                                                       //!< will lead to performance regression (for example, text will be recreated every time).
+                                                       //!  (when defined in screen-space units rather than in 3D) to be properly displayed
+                                                       //!  on device (screen / printer). 72 is default value.
+                                                       //!  Note that using difference resolution in different Views in same Viewer
+                                                       //!  will lead to performance regression (for example, text will be recreated every time).
 
 };
 
index b377c5e..abcf441 100644 (file)
@@ -32,6 +32,7 @@
 #include <OpenGl_Workspace.hxx>
 #include <OpenGl_AspectFace.hxx>
 #include <Graphic3d_TransformUtils.hxx>
+#include <Graphic3d_RenderingParams.hxx>
 
 #include <Message_Messenger.hxx>
 
@@ -174,12 +175,20 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
   myDrawBuffer (0),
   myDefaultVao (0),
   myIsGlDebugCtx (Standard_False),
-  myResolutionRatio (1.0f)
+  myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION),
+  myResolutionRatio (1.0f),
+  myLineWidthScale (1.0f),
+  myRenderScale (1.0f),
+  myRenderScaleInv (1.0f)
 {
   myViewport[0] = 0;
   myViewport[1] = 0;
   myViewport[2] = 0;
   myViewport[3] = 0;
+  myViewportVirt[0] = 0;
+  myViewportVirt[1] = 0;
+  myViewportVirt[2] = 0;
+  myViewportVirt[3] = 0;
 
   // system-dependent fields
 #if defined(HAVE_EGL)
@@ -326,6 +335,20 @@ void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect)
   myViewport[1] = theRect[1];
   myViewport[2] = theRect[2];
   myViewport[3] = theRect[3];
+  if (HasRenderScale())
+  {
+    myViewportVirt[0] = Standard_Integer(theRect[0] * myRenderScaleInv);
+    myViewportVirt[1] = Standard_Integer(theRect[1] * myRenderScaleInv);
+    myViewportVirt[2] = Standard_Integer(theRect[2] * myRenderScaleInv);
+    myViewportVirt[3] = Standard_Integer(theRect[3] * myRenderScaleInv);
+  }
+  else
+  {
+    myViewportVirt[0] = theRect[0];
+    myViewportVirt[1] = theRect[1];
+    myViewportVirt[2] = theRect[2];
+    myViewportVirt[3] = theRect[3];
+  }
 }
 
 #if !defined(GL_ES_VERSION_2_0)
@@ -3056,7 +3079,7 @@ void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth)
   if (core11 != NULL)
   {
     // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
-    core11fwd->glLineWidth (theWidth * myResolutionRatio);
+    core11fwd->glLineWidth (theWidth * myLineWidthScale);
   }
 #ifdef HAVE_GL2PS
   if (IsFeedback())
index 8b37dd2..8a26551 100644 (file)
@@ -577,6 +577,9 @@ public: //! @name methods to alter or retrieve current state
   //! @param theRect viewport definition (x, y, width, height)
   Standard_EXPORT void ResizeViewport (const Standard_Integer theRect[4]);
 
+  //! Return virtual viewport definition (x, y, width, height).
+  const Standard_Integer* VirtualViewport() const { return myViewportVirt; }
+
   //! Return active read buffer.
   Standard_Integer ReadBuffer() { return myReadBuffer; }
 
@@ -675,11 +678,40 @@ public: //! @name methods to alter or retrieve current state
 
   Standard_EXPORT void DisableFeatures() const;
 
+  //! Return resolution for rendering text.
+  unsigned int Resolution() const { return myResolution; }
+
+  //! Resolution scale factor (rendered resolution to standard resolution).
+  //! This scaling factor for parameters like text size to be properly displayed on device (screen / printer).
+  Standard_ShortReal ResolutionRatio() const { return myResolutionRatio; }
+
+  //! Rendering scale factor (rendering viewport height to real window buffer height).
+  Standard_ShortReal RenderScale() const { return myRenderScale; }
+
+  //! Return TRUE if rendering scale factor is not 1.
+  Standard_Boolean HasRenderScale() const { return Abs (myRenderScale - 1.0f) > 0.0001f; }
+
+  //! Rendering scale factor (inverted value).
+  Standard_ShortReal RenderScaleInv() const { return myRenderScaleInv; }
+
+  //! Set resolution ratio.
+  //! Note that this method rounds @theRatio to nearest integer.
+  void SetResolution (unsigned int theResolution,
+                      Standard_ShortReal theRatio,
+                      Standard_ShortReal theScale)
+  {
+    myResolution      = (unsigned int )(theScale * theResolution + 0.5f);
+    myRenderScale     = theScale;
+    myRenderScaleInv  = 1.0f / theScale;
+    SetResolutionRatio (theRatio * theScale);
+  }
+
   //! Set resolution ratio.
   //! Note that this method rounds @theRatio to nearest integer.
   void SetResolutionRatio (const Standard_ShortReal theRatio)
   {
-    myResolutionRatio = Max (1.0f, std::floor (theRatio + 0.5f));
+    myResolutionRatio = theRatio;
+    myLineWidthScale  = Max (1.0f, std::floor (theRatio + 0.5f));
   }
 
 private:
@@ -811,6 +843,7 @@ private: //! @name fields tracking current state
   Handle(OpenGl_FrameBuffer)    myDefaultFbo;      //!< default Frame Buffer Object
   Handle(OpenGl_LineAttributes) myHatchStyles;     //!< resource holding predefined hatch styles patterns
   Standard_Integer              myViewport[4];     //!< current viewport
+  Standard_Integer              myViewportVirt[4]; //!< virtual viewport
   Standard_Integer              myPointSpriteOrig; //!< GL_POINT_SPRITE_COORD_ORIGIN state (GL_UPPER_LEFT by default)
   Standard_Integer              myRenderMode;      //!< value for active rendering mode
   Standard_Integer              myPolygonMode;     //!< currently used polygon rasterization mode (glPolygonMode)
@@ -821,8 +854,12 @@ private: //! @name fields tracking current state
   Standard_Boolean              myIsGlDebugCtx;    //!< debug context initialization state
   TCollection_AsciiString       myVendor;          //!< Graphics Driver's vendor
   TColStd_PackedMapOfInteger    myFilters[6];      //!< messages suppressing filter (for sources from GL_DEBUG_SOURCE_API_ARB to GL_DEBUG_SOURCE_OTHER_ARB)
+  unsigned int                  myResolution;      //!< Pixels density (PPI), defines scaling factor for parameters like text size
   Standard_ShortReal            myResolutionRatio; //!< scaling factor for parameters like text size
-                                                   //!< to be properly displayed on device (screen / printer)
+                                                   //!  to be properly displayed on device (screen / printer)
+  Standard_ShortReal            myLineWidthScale;  //!< scaling factor for line width
+  Standard_ShortReal            myRenderScale;     //!< scaling factor for rendering resolution
+  Standard_ShortReal            myRenderScaleInv;  //!< scaling factor for rendering resolution (inverted value)
   OpenGl_Material               myMatFront;        //!< current front material state (cached to reduce GL context updates)
   OpenGl_Material               myMatBack;         //!< current back  material state
 
index 4bd9db9..9d4d15e 100644 (file)
@@ -516,7 +516,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con
     OpenGl_Mat4& aWorldView = aCtx->WorldViewState.ChangeCurrent();
     myTrsfPers->Apply (theWorkspace->View()->Camera(),
                        aCtx->ProjectionState.Current(), aWorldView,
-                       aCtx->Viewport()[2], aCtx->Viewport()[3]);
+                       aCtx->VirtualViewport()[2], aCtx->VirtualViewport()[3]);
 
   #if !defined(GL_ES_VERSION_2_0)
     if (!aCtx->IsGlNormalizeEnabled()
index 5a3a37c..69a1ec6 100644 (file)
@@ -439,7 +439,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
           *aTextAspect,
           theWorkspace->TextColor(),
           theWorkspace->TextSubtitleColor(),
-          theWorkspace->View()->RenderingParams().Resolution);
+          aCtx->Resolution());
 
   // restore aspects
   if (!aPrevTexture.IsNull())
@@ -544,6 +544,10 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_Context)& theCtx,
     {
       Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, myScaleHeight, myScaleHeight, myScaleHeight);
     }
+    else if (theCtx->HasRenderScale())
+    {
+      Graphic3d_TransformUtils::Scale<GLdouble> (aModViewMat, theCtx->RenderScaleInv(), theCtx->RenderScaleInv(), theCtx->RenderScaleInv());
+    }
   }
 
   if (myHasPlane && !myHasAnchorPoint)
@@ -807,64 +811,34 @@ void OpenGl_Text::render (const Handle(OpenGl_Context)& theCtx,
   myExportHeight = 1.0f;
   myScaleHeight  = 1.0f;
 
-  if (myHasPlane && !myHasAnchorPoint)
-  {
-    OpenGl_Mat4d aWorldViewMat;
-    aWorldViewMat.Convert (theCtx->WorldViewState.Current());
-    theCtx->WorldViewState.Push();
-    theCtx->WorldViewState.SetCurrent<Standard_Real> (aWorldViewMat);
-    theCtx->ApplyWorldViewMatrix();
-  }
-  else
-  {
-    theCtx->WorldViewState.Push();
-  }
-
+  theCtx->WorldViewState.Push();
   myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
 
+  const GLdouble aPointSize = (GLdouble )myFont->FTFont()->PointSize();
   if (!myIs2d)
   {
-    Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(),
-                                                      myPoint.y(),
-                                                      myPoint.z(),
-                                                      myModelMatrix,
-                                                      myProjMatrix,
-                                                      theCtx->Viewport(),
-                                                      myWinX,
-                                                      myWinY,
-                                                      myWinZ);
+    Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(), myPoint.y(), myPoint.z(),
+                                                      myModelMatrix, myProjMatrix, theCtx->Viewport(),
+                                                      myWinX, myWinY, myWinZ);
 
     // compute scale factor for constant text height
-    GLdouble x1, y1, z1;
-    Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX,
-                                                        myWinY,
-                                                        myWinZ,
-                                                        OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
-                                                        myProjMatrix,
-                                                        theCtx->Viewport(),
-                                                        x1,
-                                                        y1,
-                                                        z1);
-
-    GLdouble x2, y2, z2;
-    const GLdouble h = (GLdouble )myFont->FTFont()->PointSize();
-    Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX,
-                                                        myWinY + h,
-                                                        myWinZ,
-                                                        OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX),
-                                                        myProjMatrix,
-                                                        theCtx->Viewport(),
-                                                        x2,
-                                                        y2,
-                                                        z2);
-
-    myScaleHeight = (y2 - y1) / h;
     if (theTextAspect.Aspect()->GetTextZoomable())
     {
-      myExportHeight = (float )h;
+      myExportHeight = aPointSize;
+    }
+    else
+    {
+      Graphic3d_Vec3d aPnt1, aPnt2;
+      Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY, myWinZ,
+                                                          OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
+                                                          aPnt1.x(), aPnt1.y(), aPnt1.z());
+      Graphic3d_TransformUtils::UnProject<Standard_Real> (myWinX, myWinY + aPointSize, myWinZ,
+                                                          OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), myProjMatrix, theCtx->Viewport(),
+                                                          aPnt2.x(), aPnt2.y(), aPnt2.z());
+      myScaleHeight = (aPnt2.y() - aPnt1.y()) / aPointSize;
     }
   }
-  myExportHeight = (float )myFont->FTFont()->PointSize() / myExportHeight;
+  myExportHeight = aPointSize / myExportHeight;
 
 #if !defined(GL_ES_VERSION_2_0)
   if (theCtx->core11 != NULL)
index 92cb21d..37fcd95 100644 (file)
@@ -143,9 +143,6 @@ void OpenGl_View::Redraw()
   // fetch OpenGl context state
   aCtx->FetchState();
 
-  // set resolution ratio
-  aCtx->SetResolutionRatio (RenderingParams().ResolutionRatio());
-
   OpenGl_FrameBuffer* aFrameBuffer = myFBO.operator->();
   bool toSwap = aCtx->IsRender()
             && !aCtx->caps->buffersNoSwap
@@ -153,9 +150,11 @@ void OpenGl_View::Redraw()
 
   Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width();
   Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height();
+  Standard_Integer aRendSizeX = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeX + 0.5f);
+  Standard_Integer aRendSizeY = Standard_Integer(myRenderParams.RenderResolutionScale * aSizeY + 0.5f);
 
   // determine multisampling parameters
-  Standard_Integer aNbSamples = !myToDisableMSAA
+  Standard_Integer aNbSamples = !myToDisableMSAA && aSizeX == aRendSizeX
                               ? Max (Min (myRenderParams.NbMsaaSamples, aCtx->MaxMsaaSamples()), 0)
                               : 0;
   if (aNbSamples != 0)
@@ -173,10 +172,11 @@ void OpenGl_View::Redraw()
   if (myHasFboBlit
    && (myTransientDrawToFront
     || aProjectType == Graphic3d_Camera::Projection_Stereo
-    || aNbSamples != 0))
+    || aNbSamples != 0
+    || aSizeX != aRendSizeX))
   {
-    if (myMainSceneFbos[0]->GetVPSizeX() != aSizeX
-     || myMainSceneFbos[0]->GetVPSizeY() != aSizeY
+    if (myMainSceneFbos[0]->GetVPSizeX() != aRendSizeX
+     || myMainSceneFbos[0]->GetVPSizeY() != aRendSizeY
      || myMainSceneFbos[0]->NbSamples()  != aNbSamples)
     {
       if (!myTransientDrawToFront)
@@ -191,7 +191,7 @@ void OpenGl_View::Redraw()
       // for further blitting and rendering immediate presentations on top
       if (aCtx->core20fwd != NULL)
       {
-        myMainSceneFbos[0]->Init (aCtx, aSizeX, aSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples);
+        myMainSceneFbos[0]->Init (aCtx, aRendSizeX, aRendSizeY, myFboColorFormat, myFboDepthFormat, aNbSamples);
       }
       if (myTransientDrawToFront
        && !aCtx->caps->useSystemBuffer
@@ -266,12 +266,17 @@ void OpenGl_View::Redraw()
   #if !defined(GL_ES_VERSION_2_0)
     aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         aMainFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
+
     redraw (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0]);
     myBackBufferRestored = Standard_True;
     myIsImmediateDrawn   = Standard_False;
   #if !defined(GL_ES_VERSION_2_0)
     aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
     if (!redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0], anImmFbos[0]))
     {
       toSwap = false;
@@ -284,9 +289,14 @@ void OpenGl_View::Redraw()
   #if !defined(GL_ES_VERSION_2_0)
     aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         aMainFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
+
     redraw (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1]);
     myBackBufferRestored = Standard_True;
     myIsImmediateDrawn   = Standard_False;
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
     if (!redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1], anImmFbos[1]))
     {
       toSwap = false;
@@ -294,6 +304,7 @@ void OpenGl_View::Redraw()
 
     if (anImmFbos[0] != NULL)
     {
+      aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(), 1.0f);
       drawStereoPair (aFrameBuffer);
     }
   }
@@ -316,9 +327,13 @@ void OpenGl_View::Redraw()
       aCtx->SetReadDrawBuffer (GL_BACK);
     }
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         aMainFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
     redraw (aProjectType, aMainFbo);
     myBackBufferRestored = Standard_True;
     myIsImmediateDrawn   = Standard_False;
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
     if (!redrawImmediate (aProjectType, aMainFbo, anImmFbo))
     {
       toSwap = false;
@@ -439,6 +454,9 @@ void OpenGl_View::RedrawImmediate()
       aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK);
     }
   #endif
+
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbos[0] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
     toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye,
                               aMainFbos[0],
                               anImmFbos[0],
@@ -460,6 +478,8 @@ void OpenGl_View::RedrawImmediate()
       aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK);
     }
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbos[1] != NULL ? myRenderParams.RenderResolutionScale : 1.0f);
     toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye,
                               aMainFbos[1],
                               anImmFbos[1],
@@ -483,6 +503,8 @@ void OpenGl_View::RedrawImmediate()
       aCtx->SetReadDrawBuffer (GL_BACK);
     }
   #endif
+    aCtx->SetResolution (myRenderParams.Resolution, myRenderParams.ResolutionRatio(),
+                         anImmFbo != aFrameBuffer ? myRenderParams.RenderResolutionScale : 1.0f);
     toSwap = redrawImmediate (aProjectType,
                               aMainFbo,
                               anImmFbo,
@@ -1034,6 +1056,10 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
                                const Standard_Boolean theToFlip)
 {
   Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
+  const Standard_Integer aReadSizeX = theReadFbo != NULL ? theReadFbo->GetVPSizeX() : myWindow->Width();
+  const Standard_Integer aReadSizeY = theReadFbo != NULL ? theReadFbo->GetVPSizeY() : myWindow->Height();
+  const Standard_Integer aDrawSizeX = theDrawFbo != NULL ? theDrawFbo->GetVPSizeX() : myWindow->Width();
+  const Standard_Integer aDrawSizeY = theDrawFbo != NULL ? theDrawFbo->GetVPSizeY() : myWindow->Height();
   if (theReadFbo == NULL || aCtx->IsFeedback())
   {
     return false;
@@ -1053,6 +1079,9 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
   {
     aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
   }
+  const Standard_Integer aViewport[4] = { 0, 0, aDrawSizeX, aDrawSizeY };
+  aCtx->ResizeViewport (aViewport);
+
 #if !defined(GL_ES_VERSION_2_0)
   aCtx->core20fwd->glClearDepth  (1.0);
 #else
@@ -1095,8 +1124,8 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
     }
 
     // we don't copy stencil buffer here... does it matter for performance?
-    aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
-                                         0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(),
+    aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aReadSizeX, aReadSizeY,
+                                         0, 0, aDrawSizeX, aDrawSizeY,
                                          aCopyMask, GL_NEAREST);
     const int anErr = ::glGetError();
     if (anErr != GL_NO_ERROR)
@@ -1150,13 +1179,30 @@ bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer*    theReadFbo,
 
     myWorkspace->DisableTexture();
 
+    const Graphic3d_TypeOfTextureFilter aFilter = (aDrawSizeX == aReadSizeX && aDrawSizeY == aReadSizeY) ? Graphic3d_TOTF_NEAREST : Graphic3d_TOTF_BILINEAR;
+    const GLint aFilterGl = aFilter == Graphic3d_TOTF_NEAREST ? GL_NEAREST : GL_LINEAR;
+
     OpenGl_VertexBuffer* aVerts = initBlitQuad (theToFlip);
     const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
     if (aVerts->IsValid()
      && aManager->BindFboBlitProgram())
     {
-      theReadFbo->ColorTexture()       ->Bind   (aCtx, GL_TEXTURE0 + 0);
-      theReadFbo->DepthStencilTexture()->Bind   (aCtx, GL_TEXTURE0 + 1);
+      theReadFbo->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 0);
+      if (theReadFbo->ColorTexture()->GetParams()->Filter() != aFilter)
+      {
+        theReadFbo->ColorTexture()->GetParams()->SetFilter (aFilter);
+        aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
+        aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
+      }
+
+      theReadFbo->DepthStencilTexture()->Bind (aCtx, GL_TEXTURE0 + 1);
+      if (theReadFbo->DepthStencilTexture()->GetParams()->Filter() != aFilter)
+      {
+        theReadFbo->DepthStencilTexture()->GetParams()->SetFilter (aFilter);
+        aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterGl);
+        aCtx->core20fwd->glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilterGl);
+      }
+
       aVerts->BindVertexAttrib (aCtx, Graphic3d_TOA_POS);
 
       aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
index d8fbdf7..e232d66 100755 (executable)
 #if(defined(_MSC_VER) && (_MSC_VER < 1800))
   // only Visual Studio 2013 (vc12) provides <cinttypes> header
   // we do not defined all macros here - only used by OCCT framework
+  #define PRId64 "I64d"
+  #define PRIu64 "I64u"
+  #define SCNd64 "I64d"
+  #define SCNu64 "I64u"
   #ifdef _WIN64
     #define PRIdPTR "I64d"
     #define PRIuPTR "I64u"
index f3dca49..4674f35 100644 (file)
@@ -2647,10 +2647,44 @@ static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const
 //function : VRepaint
 //purpose  :
 //==============================================================================
-static int VRepaint (Draw_Interpretor& , Standard_Integer , const char** )
+static int VRepaint (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
 {
-  Handle(V3d_View) V = ViewerTest::CurrentView();
-  if ( !V.IsNull() ) V->Redraw(); return 0;
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  if (aView.IsNull())
+  {
+    std::cout << "Error: no active viewer!\n";
+    return 1;
+  }
+
+  Standard_Boolean isImmediateUpdate = Standard_False;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-immediate")
+    {
+      isImmediateUpdate = Standard_True;
+      if (anArgIter + 1 < theArgNb
+       && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isImmediateUpdate))
+      {
+        ++anArgIter;
+      }
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << anArg << "'\n";
+    }
+  }
+
+  if (isImmediateUpdate)
+  {
+    aView->RedrawImmediate();
+  }
+  else
+  {
+    aView->Redraw();
+  }
+  return 0;
 }
 
 //==============================================================================
@@ -5530,6 +5564,7 @@ static int VCaps (Draw_Interpretor& theDI,
     theDI << "VSync:   " <<  aCaps->swapInterval                   << "\n";
     theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
     theDI << "Stereo:  " << (aCaps->contextStereo ? "1" : "0") << "\n";
+    theDI << "WinBuffer: " << (aCaps->useSystemBuffer ? "1" : "0") << "\n";
     return 0;
   }
 
@@ -5595,6 +5630,20 @@ static int VCaps (Draw_Interpretor& theDI,
       }
       aCaps->contextNoAccel = toEnable;
     }
+    else if (anArgCase == "-winbuffer"
+          || anArgCase == "-windowbuffer"
+          || anArgCase == "-usewinbuffer"
+          || anArgCase == "-usewindowbuffer"
+          || anArgCase == "-usesystembuffer")
+    {
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aCaps->useSystemBuffer = toEnable;
+    }
     else if (anArgCase == "-accel"
           || anArgCase == "-acceleration")
     {
@@ -9070,6 +9119,7 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
     }
     theDI << "\n";
     theDI << "msaa:           " <<  aParams.NbMsaaSamples                               << "\n";
+    theDI << "rendScale:      " <<  aParams.RenderResolutionScale                       << "\n";
     theDI << "rayDepth:       " <<  aParams.RaytracingDepth                             << "\n";
     theDI << "fsaa:           " << (aParams.IsAntialiasingEnabled       ? "on" : "off") << "\n";
     theDI << "shadows:        " << (aParams.IsShadowEnabled             ? "on" : "off") << "\n";
@@ -9177,6 +9227,32 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
         aParams.NbMsaaSamples = aNbSamples;
       }
     }
+    else if (aFlag == "-rendscale"
+          || aFlag == "-renderscale"
+          || aFlag == "-renderresolutionscale")
+    {
+      if (toPrint)
+      {
+        theDI << aParams.RenderResolutionScale << " ";
+        continue;
+      }
+      else if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+        return 1;
+      }
+
+      const Standard_Real aScale = Draw::Atof (theArgVec[anArgIter]);
+      if (aScale < 0.01)
+      {
+        std::cerr << "Error: invalid rendering resolution scale " << aScale << ".\n";
+        return 1;
+      }
+      else
+      {
+        aParams.RenderResolutionScale = Standard_ShortReal(aScale);
+      }
+    }
     else if (aFlag == "-raydepth"
           || aFlag == "-ray_depth")
     {
@@ -10487,7 +10563,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "   \"scale\" - specifies factor to scale computed z range.\n",
     __FILE__, VZFit, group);
   theCommands.Add("vrepaint",
-    "vrepaint        : vrepaint, force redraw",
+            "vrepaint [-immediate]"
+    "\n\t\t: force redraw",
     __FILE__,VRepaint,group);
   theCommands.Add("vclear",
     "vclear          : vclear"
@@ -10689,7 +10766,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
   theCommands.Add ("vcaps",
             "vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}]"
     "\n\t\t:       [-compatibleProfile {0|1}]"
-    "\n\t\t:       [-vsync {0|1}]"
+    "\n\t\t:       [-vsync {0|1}] [-useWinBuffer {0|1}]"
     "\n\t\t:       [-quadBuffer {0|1}] [-stereo {0|1}]"
     "\n\t\t:       [-softMode {0|1}] [-noupdate|-update]"
     "\n\t\t: Modify particular graphic driver options:"
@@ -10700,6 +10777,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n\t\t:             arrays to GPU memory)"
     "\n\t\t:  sprite   - use textured sprites instead of bitmaps"
     "\n\t\t:  vsync    - switch VSync on or off"
+    "\n\t\t:  winBuffer - allow using window buffer for rendering"
     "\n\t\t: Context creation options:"
     "\n\t\t:  softMode          - software OpenGL implementation"
     "\n\t\t:  compatibleProfile - backward-compatible profile"
@@ -10958,6 +11036,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     "\n    Manages rendering parameters: "
     "\n      '-raster'                Disables GPU ray-tracing"
     "\n      '-msaa         0..4'     Specifies number of samples for MSAA"
+    "\n      '-rendScale    value     Rendering resolution scale factor"
     "\n      '-rayTrace'              Enables  GPU ray-tracing"
     "\n      '-rayDepth     0..10'    Defines maximum ray-tracing depth"
     "\n      '-shadows      on|off'   Enables/disables shadows rendering"
diff --git a/tests/v3d/glsl/rendscale b/tests/v3d/glsl/rendscale
new file mode 100644 (file)
index 0000000..f6470bf
--- /dev/null
@@ -0,0 +1,40 @@
+puts "========"
+puts "Rendering resolution scale factor"
+puts "========"
+
+set aFontFile ""
+catch { set aFontFile [locate_data_file DejaVuSans.ttf] }
+
+pload MODELING VISUALIZATION
+
+set aLabelFont "Arial"
+if { "$aFontFile" != "" } {
+  vfont add "$aFontFile" SansFont
+  set aLabelFont "SansFont"
+}
+
+box b 1 2 3
+vclear
+vinit View1
+vdisplay b
+vfit
+vpoint p 0 0 0
+vzbufftrihedron
+vdrawtext t Text2d -font $aLabelFont
+vtrihedron tt
+vdisplay -trsfPers zoom -trsfPersPos 1 0 0 tt
+text2brep ttl "Top-Left" -font $aLabelFont -height 30 -pos 0 -30 0
+vdisplay  ttl -2d topLeft -dispMode 1
+vcolorscale cs -demo
+
+vrenderparams -rendScale 1
+vdump $::imagedir/${::casename}_100.png
+
+vrenderparams -rendScale 0.5
+vdump $::imagedir/${::casename}_050.png
+
+vrenderparams -rendScale 0.75
+vdump $::imagedir/${::casename}_075.png
+
+vrenderparams -rendScale 2
+vdump $::imagedir/${::casename}_200.png