Commit 17c14c4c authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot
Browse files

Merge topic 'parallel-rendering-fixes'

4dbbae96 vtkOpenGLRenderWindow: support stereo offscreen buffers
6c56dda3 vtkOpenGLCamera: use vtkRenderer:GetTiledAspectRatio
c0e26608 vtkSynchronizedRenderers: respect tile-scale/tile-viewport
05f87557 vtkOpenGLRenderWindow: bind default frame buffer
2a3b0cca vtkMultiProcessController: add API to reduce bounds
254b08fe vtkBoundingBox: improve const correctness.
71f2f43d

 fix tile-display in split-view configuration.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarKen Martin <ken.martin@kitware.com>
Merge-request: !5464
parents 7d5bcca1 4dbbae96
Pipeline #135633 passed with stage
in 0 seconds
......@@ -167,7 +167,7 @@ public:
*/
const double *GetMinPoint() const VTK_SIZEHINT(3);
void GetMinPoint(double &x, double &y, double &z) const;
void GetMinPoint(double x[3]);
void GetMinPoint(double x[3]) const;
//@}
//@{
......@@ -176,7 +176,7 @@ public:
*/
const double *GetMaxPoint() const VTK_SIZEHINT(3);
void GetMaxPoint(double &x, double &y, double &z) const;
void GetMaxPoint(double x[3]);
void GetMaxPoint(double x[3]) const;
//@}
/**
......@@ -307,7 +307,7 @@ inline const double *vtkBoundingBox::GetMinPoint() const
return this->MinPnt;
}
inline void vtkBoundingBox::GetMinPoint(double x[3])
inline void vtkBoundingBox::GetMinPoint(double x[3]) const
{
x[0] = this->MinPnt[0];
x[1] = this->MinPnt[1];
......@@ -319,7 +319,7 @@ inline const double *vtkBoundingBox::GetMaxPoint() const
return this->MaxPnt;
}
inline void vtkBoundingBox::GetMaxPoint(double x[3])
inline void vtkBoundingBox::GetMaxPoint(double x[3]) const
{
x[0] = this->MaxPnt[0];
x[1] = this->MaxPnt[1];
......
......@@ -15,20 +15,19 @@
// This will be the default.
#include "vtkMultiProcessController.h"
#include "vtkBoundingBox.h"
#include "vtkByteSwap.h"
#include "vtkCollection.h"
#include "vtkCommand.h"
#include "vtkDummyController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOutputWindow.h"
#include "vtkProcess.h"
#include "vtkProcessGroup.h"
#include "vtkSubCommunicator.h"
#include "vtkToolkits.h"
#include "vtkProcess.h"
#include "vtkSmartPointer.h"
#include "vtkWeakPointer.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
#include <list>
#include <unordered_map>
......@@ -329,7 +328,7 @@ vtkMultiProcessController *vtkMultiProcessController::PartitionController(
partitionIds.insert(iter, j);
}
// Copy list into process group.
VTK_CREATE(vtkProcessGroup, group);
vtkNew<vtkProcessGroup> group;
group->Initialize(this);
group->RemoveAllProcessIds();
for (std::list<int>::iterator iter = partitionIds.begin();
......@@ -768,6 +767,68 @@ void vtkMultiProcessController::ProcessRMI(int remoteProcessId,
(*citer->Function)(citer->LocalArgument, arg, argLength, remoteProcessId);
}
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::Reduce(
const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer, int destProcessId)
{
if (this->GetNumberOfProcesses() <= 1)
{
recvBuffer = sendBuffer;
return 1;
}
double send_min[3] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MAX, VTK_DOUBLE_MAX };
double send_max[3] = { VTK_DOUBLE_MIN, VTK_DOUBLE_MIN, VTK_DOUBLE_MIN };
if (sendBuffer.IsValid())
{
sendBuffer.GetMinPoint(send_min);
sendBuffer.GetMaxPoint(send_max);
}
double recv_min[3], recv_max[3];
if (this->Reduce(send_min, recv_min, 3, vtkCommunicator::MIN_OP, destProcessId))
{
if (this->Reduce(send_max, recv_max, 3, vtkCommunicator::MAX_OP, destProcessId))
{
if (this->GetLocalProcessId() == destProcessId)
{
recvBuffer.SetMinPoint(recv_min);
recvBuffer.SetMaxPoint(recv_max);
}
return 1;
}
}
return 0;
}
//----------------------------------------------------------------------------
int vtkMultiProcessController::AllReduce(
const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer)
{
if (this->GetNumberOfProcesses() <= 1)
{
recvBuffer = sendBuffer;
return 1;
}
double send_min[3] = { VTK_DOUBLE_MAX, VTK_DOUBLE_MAX, VTK_DOUBLE_MAX };
double send_max[3] = { VTK_DOUBLE_MIN, VTK_DOUBLE_MIN, VTK_DOUBLE_MIN };
if (sendBuffer.IsValid())
{
sendBuffer.GetMinPoint(send_min);
sendBuffer.GetMaxPoint(send_max);
}
double recv_min[3], recv_max[3];
if (this->AllReduce(send_min, recv_min, 3, vtkCommunicator::MIN_OP))
{
if (this->AllReduce(send_max, recv_max, 3, vtkCommunicator::MAX_OP))
{
recvBuffer.SetMinPoint(recv_min);
recvBuffer.SetMaxPoint(recv_max);
return 1;
}
}
return 0;
}
//============================================================================
// The intent is to give access to a processes controller from a static method.
......
......@@ -54,6 +54,7 @@
#include "vtkCommunicator.h" // Needed for direct access to communicator
class vtkBoundingBox;
class vtkCollection;
class vtkDataObject;
class vtkDataSet;
......@@ -1419,7 +1420,15 @@ public:
return this->Communicator->AllReduce(sendBuffer, recvBuffer, operation);
}
// Internally implemented RMI to break the process loop.
//@{
/**
* Convenience methods to reduce bounds.
*/
int Reduce(const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer, int destProcessId);
int AllReduce(const vtkBoundingBox& sendBuffer, vtkBoundingBox& recvBuffer);
//@}
// Internally implemented RMI to break the process loop.
protected:
vtkMultiProcessController();
......
......@@ -134,24 +134,9 @@ void vtkOpenGLCamera::GetKeyMatrices(vtkRenderer *ren, vtkMatrix4x4 *&wcvc,
this->WCVCMatrix->Transpose();
double aspect[2];
int lowerLeft[2];
int usize, vsize;
ren->GetTiledSizeAndOrigin(&usize, &vsize, lowerLeft, lowerLeft+1);
ren->ComputeAspect();
ren->GetAspect(aspect);
double aspect2[2];
ren->vtkViewport::ComputeAspect();
ren->vtkViewport::GetAspect(aspect2);
double aspectModification = aspect[0] * aspect2[1] / (aspect[1] * aspect2[0]);
if (usize && vsize)
{
this->VCDCMatrix->DeepCopy(this->GetProjectionTransformMatrix(
aspectModification * usize / vsize, -1, 1));
this->VCDCMatrix->Transpose();
}
this->VCDCMatrix->DeepCopy(
this->GetProjectionTransformMatrix(ren->GetTiledAspectRatio(), -1, 1));
this->VCDCMatrix->Transpose();
vtkMatrix4x4::Multiply4x4(this->WCVCMatrix, this->VCDCMatrix, this->WCDCMatrix);
......
......@@ -1275,9 +1275,14 @@ void vtkOpenGLRenderWindow::Start()
this->FrontBuffer = buffer;
this->BackRightBuffer = buffer;
this->FrontRightBuffer = buffer;
if (this->OffScreenFramebuffer->GetNumberOfColorAttachments() == 2)
{
unsigned int buffer1 = static_cast<unsigned int>(GL_COLOR_ATTACHMENT1);
this->BackRightBuffer = buffer1;
this->FrontRightBuffer = buffer1;
}
}
if (!this->UseOffScreenBuffers && this->OffScreenFramebufferBound)
else if (!this->UseOffScreenBuffers && this->OffScreenFramebufferBound)
{
this->OffScreenFramebuffer->RestorePreviousBindingsAndBuffers();
this->OffScreenFramebufferBound = false;
......@@ -1288,6 +1293,11 @@ void vtkOpenGLRenderWindow::Start()
this->BackBuffer = static_cast<unsigned int>(GL_BACK);
this->FrontBuffer = static_cast<unsigned int>(GL_FRONT);
}
else
{
// makes sense to activate the default framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, this->GetDefaultFrameBufferId());
}
}
......@@ -2171,13 +2181,20 @@ int vtkOpenGLRenderWindow::CreateOffScreenFramebuffer(int width, int height)
if (!this->OffScreenFramebuffer)
{
int num_color_attachments = 1;
if (this->GetStereoCapableWindow() && this->GetStereoType() == VTK_STEREO_CRYSTAL_EYES)
{
// for active stereo, we simply create two color attachments, one for the
// left eye and one for the right.
++num_color_attachments;
}
this->OffScreenFramebuffer = vtkOpenGLFramebufferObject::New();
this->OffScreenFramebuffer->SetContext(this);
this->OffScreenFramebuffer->SaveCurrentBindingsAndBuffers();
this->OffScreenFramebuffer->PopulateFramebuffer(
width, height,
true, // textures
1, VTK_UNSIGNED_CHAR, // 1 color buffer uchar
num_color_attachments, VTK_UNSIGNED_CHAR, // 1 (or 2) color buffer uchar
true, 24, // depth buffer 24bit
0, // no multisample
this->StencilCapable != 0 ? true : false);
......@@ -2188,10 +2205,6 @@ int vtkOpenGLRenderWindow::CreateOffScreenFramebuffer(int width, int height)
this->OffScreenFramebuffer->Resize(width, height);
}
// if (isStereo)
// {
// }
return 1;
}
......
......@@ -21,20 +21,20 @@
#include "vtkFXAAOptions.h"
#include "vtkHardwareSelector.h"
#include "vtkImageData.h"
#include "vtkLogger.h"
#include "vtkMatrix4x4.h"
#include "vtkMultiProcessController.h"
#include "vtkMultiProcessStream.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLFXAAFilter.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkParallelRenderManager.h"
#include "vtkPNGWriter.h"
#include "vtkRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLFXAAFilter.h"
#include "vtkPNGWriter.h"
#include "vtkParallelRenderManager.h"
#include "vtkRenderWindow.h"
#include <cassert>
......@@ -691,23 +691,21 @@ bool vtkSynchronizedRenderers::vtkRawImage::PushToViewport(vtkRenderer* ren)
return false;
}
double viewport[4];
ren->GetViewport(viewport);
const int* window_size = ren->GetVTKWindow()->GetActualSize();
int size[2], low_point[2];
ren->GetTiledSizeAndOrigin(&size[0], &size[1], &low_point[0], &low_point[1]);
vtkLogF(TRACE, "GetTiledSizeAndOrigin(w=%d, h=%d, x=%d, y=%d)", size[0], size[1], low_point[0],
low_point[1]);
if (size[0] <= 0 || size[1] <= 0)
{
vtkGenericWarningMacro("Viewport empty. Cannot push to screen.");
return false;
}
vtkOpenGLState *ostate =
static_cast<vtkOpenGLRenderWindow *>(ren->GetVTKWindow())->GetState();
ostate->vtkglEnable(GL_SCISSOR_TEST);
ostate->vtkglViewport(
static_cast<GLint>(viewport[0]*window_size[0]),
static_cast<GLint>(viewport[1]*window_size[1]),
static_cast<GLsizei>((viewport[2]-viewport[0])*window_size[0]),
static_cast<GLsizei>((viewport[3]-viewport[1])*window_size[1]));
ostate->vtkglScissor(
static_cast<GLint>(viewport[0]*window_size[0]),
static_cast<GLint>(viewport[1]*window_size[1]),
static_cast<GLsizei>((viewport[2]-viewport[0])*window_size[0]),
static_cast<GLsizei>((viewport[3]-viewport[1])*window_size[1]));
ostate->vtkglViewport(low_point[0], low_point[1], size[0], size[1]);
ostate->vtkglScissor(low_point[0], low_point[1], size[0], size[1]);
ren->Clear();
return this->PushToFrameBuffer(ren);
}
......@@ -725,19 +723,13 @@ bool vtkSynchronizedRenderers::vtkRawImage::PushToFrameBuffer(vtkRenderer *ren)
vtkOpenGLRenderUtilities::MarkDebugEvent("vtkRawImage::PushToViewport begin");
vtkOpenGLRenderWindow *renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetVTKWindow());
vtkOpenGLState *ostate = renWin->GetState();
vtkOpenGLState::ScopedglBlendFuncSeparate bfsaver(ostate);
// framebuffers have their color premultiplied by alpha.
vtkOpenGLState::ScopedglBlendFuncSeparate bfsaver(ostate);
ostate->vtkglEnable(GL_BLEND);
ostate->vtkglBlendFuncSeparate(GL_ONE,GL_ONE_MINUS_SRC_ALPHA,
GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
// always draw the entire image on the entire viewport
vtkOpenGLState::ScopedglViewport vsaver(ostate);
int renSize[2];
ren->GetTiledSize(renSize, renSize + 1);
ostate->vtkglViewport(0, 0, renSize[0], renSize[1]);
renWin->DrawPixels(this->GetWidth(), this->GetHeight(),
this->Data->GetNumberOfComponents(), VTK_UNSIGNED_CHAR,
this->GetRawPtr()->GetVoidPointer(0));
......
......@@ -178,13 +178,17 @@ public:
vtkUnsignedCharArray* GetRawPtr()
{ return this->Data; }
// Pushes the image to the viewport.
bool PushToViewport(vtkRenderer*);
/**
* Pushes the image to the viewport. The OpenGL viewport and scissor region
* is setup using the viewport defined by the renderer.
*/
bool PushToViewport(vtkRenderer* renderer);
// This is a raw version of PushToViewport() that assumes that the
// glViewport() has already been setup externally.
// the argument is optional for backwards compat with old OpenGL
bool PushToFrameBuffer(vtkRenderer *ren = nullptr);
/**
* This is a raw version of PushToViewport() that assumes that the
* glViewport() has already been setup externally.
*/
bool PushToFrameBuffer(vtkRenderer* ren);
// Captures the image from the viewport.
// This doesn't trigger a render, just captures what's currently there in
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment