Skip to content
Snippets Groups Projects
Commit 34da3ae0 authored by Ken Martin's avatar Ken Martin
Browse files

Add support for resolving multisampled buffers

Some systems are picky about blitting multisampled buffers
So add an option to turn on resolving prior to the final
blit. emscripten sets this by default to true.
parent da89c022
No related merge requests found
......@@ -166,6 +166,7 @@ const char* vtkOpenGLRenderWindow::GetRenderingBackend()
//------------------------------------------------------------------------------
vtkOpenGLRenderWindow::vtkOpenGLRenderWindow()
: BlitRequiresResolve(false)
{
this->State = vtkOpenGLState::New();
......@@ -1015,6 +1016,23 @@ void vtkOpenGLRenderWindow::Frame()
{
this->GetState()->PushFramebufferBindings();
this->OffScreenFramebuffer->Bind(GL_READ_FRAMEBUFFER);
int* fbsize = this->OffScreenFramebuffer->GetLastSize();
// recall Blit upper right corner is exclusive of the range
const int srcExtents[4] = { 0, fbsize[0], 0, fbsize[1] };
if (this->MultiSamples && this->BlitRequiresResolve)
{
this->GetState()->vtkglViewport(0, 0, fbsize[0], fbsize[1]);
this->GetState()->vtkglScissor(0, 0, fbsize[0], fbsize[1]);
this->ResolveFramebuffer->Bind(GL_DRAW_FRAMEBUFFER);
vtkOpenGLFramebufferObject::Blit(srcExtents, srcExtents, GL_COLOR_BUFFER_BIT, GL_NEAREST);
this->ResolveFramebuffer->Bind(GL_READ_FRAMEBUFFER);
}
this->GetState()->vtkglViewport(0, 0, this->Size[0], this->Size[1]);
this->GetState()->vtkglScissor(0, 0, this->Size[0], this->Size[1]);
this->GetState()->vtkglBindFramebuffer(GL_DRAW_FRAMEBUFFER, this->DefaultFrameBufferId);
if (this->StereoRender && this->StereoType == VTK_STEREO_CRYSTAL_EYES)
......@@ -1026,12 +1044,7 @@ void vtkOpenGLRenderWindow::Frame()
this->GetState()->vtkglDrawBuffer(this->GetBackLeftBuffer());
}
int* fbsize = this->OffScreenFramebuffer->GetLastSize();
// recall Blit upper right corner is exclusive of the range
const int srcExtents[4] = { 0, fbsize[0], 0, fbsize[1] };
const int destExtents[4] = { 0, this->Size[0], 0, this->Size[1] };
this->GetState()->vtkglViewport(0, 0, this->Size[0], this->Size[1]);
this->GetState()->vtkglScissor(0, 0, this->Size[0], this->Size[1]);
vtkOpenGLFramebufferObject::Blit(srcExtents, destExtents, GL_COLOR_BUFFER_BIT, GL_LINEAR);
this->GetState()->PopFramebufferBindings();
}
......
......@@ -439,6 +439,11 @@ public:
*/
void ReleaseGraphicsResources(vtkWindow*) override;
// set this to true if the destination framebuffer requires a multisamped
// buffer to be resolved prior to blitting
vtkSetMacro(BlitRequiresResolve, bool);
vtkGetMacro(BlitRequiresResolve, bool);
protected:
vtkOpenGLRenderWindow();
~vtkOpenGLRenderWindow() override;
......@@ -524,6 +529,11 @@ protected:
int ScreenSize[2];
// set this to true if the destination framebuffer
// requires a multisamped buffer to be resolved
// prior to blitting
bool BlitRequiresResolve;
private:
vtkOpenGLRenderWindow(const vtkOpenGLRenderWindow&) = delete;
void operator=(const vtkOpenGLRenderWindow&) = delete;
......
......@@ -42,6 +42,11 @@ vtkSDL2OpenGLRenderWindow::vtkSDL2OpenGLRenderWindow()
this->SetWindowName(DEFAULT_BASE_WINDOW_NAME.c_str());
this->SetStencilCapable(1);
// webgl is picky about multisampled blits
#ifdef __EMSCRIPTEN__
this->BlitRequiresResolve = true;
#endif
// set position to -1 to let SDL place the window
// SetPosition will still work. Defaults of 0,0 result
// in the window title bar being off screen.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment