Commit cb5d53ac authored by Michael Migliore's avatar Michael Migliore Committed by Kitware Robot
Browse files

Merge topic 'fix-tone-mapping-fxaa'

185e742f

 Fix fxaa with float fbo
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Ken Martin's avatarKen Martin <ken.martin@kitware.com>
Acked-by: default avatarJoachim Pouderoux <joachim.pouderoux@kitware.com>
Merge-request: !4346
parents b885a9a0 185e742f
......@@ -266,17 +266,29 @@ void vtkOpenGLFXAAFilter::CreateGLObjects()
{
assert(!this->Input);
this->Input = vtkTextureObject::New();
this->Input->SetContext(static_cast<vtkOpenGLRenderWindow*>(
this->Renderer->GetRenderWindow()));
vtkOpenGLRenderWindow* renWin =
static_cast<vtkOpenGLRenderWindow*>(this->Renderer->GetRenderWindow());
this->Input->SetContext(renWin);
this->Input->SetFormat(GL_RGB);
// ES doesn't support GL_RGB8, and OpenGL 3 doesn't support GL_RGB.
// What a world.
// we need to get the format of current color buffer in order to allocate the right format
// for the texture used in FXAA
int internalFormat = renWin->GetColorBufferInternalFormat(0);
if (internalFormat != 0)
{
this->Input->SetInternalFormat(static_cast<unsigned int>(internalFormat));
}
else // the query failed, fallback to classic texture
{
// ES doesn't support GL_RGB8, and OpenGL 3 doesn't support GL_RGB.
// What a world.
#if defined(GL_ES_VERSION_3_0)
this->Input->SetInternalFormat(GL_RGB);
this->Input->SetInternalFormat(GL_RGB);
#else // OpenGL ES
this->Input->SetInternalFormat(GL_RGB8);
this->Input->SetInternalFormat(GL_RGB8);
#endif // OpenGL ES
}
// Required for FXAA, since we interpolate texels for blending.
this->Input->SetMinificationFilter(vtkTextureObject::Linear);
......
......@@ -927,6 +927,37 @@ int vtkOpenGLRenderWindow::GetColorBufferSizes(int *rgba)
}
}
int vtkOpenGLRenderWindow::GetColorBufferInternalFormat(int attachmentPoint)
{
int format = 0;
if (GLEW_ARB_direct_state_access)
{
int type;
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachmentPoint,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
if (type == GL_TEXTURE)
{
int texName;
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachmentPoint,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &texName);
glGetTextureLevelParameteriv(texName, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
}
else if (type == GL_RENDERBUFFER)
{
int rbName;
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + attachmentPoint,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &rbName);
glGetNamedRenderbufferParameteriv(rbName, GL_RENDERBUFFER_INTERNAL_FORMAT, &format);
}
vtkOpenGLClearErrorMacro();
}
return format;
}
unsigned char* vtkOpenGLRenderWindow::GetPixelData(int x1, int y1,
int x2, int y2,
int front, int right)
......
......@@ -152,6 +152,13 @@ public:
*/
int GetColorBufferSizes(int *rgba) override;
/**
* Get the internal format of current attached texture or render buffer.
* attachmentPoint is the index of attachment.
* Returns 0 if not able to determine.
*/
int GetColorBufferInternalFormat(int attachmentPoint);
//@{
/**
* Set the size of the window in screen coordinates in pixels.
......
......@@ -1984,8 +1984,8 @@ void vtkTextureObject::CopyFromFrameBuffer(int srcXmin,
assert("pre: is2D" && this->GetNumberOfDimensions()==2);
this->Activate();
glCopyTexImage2D(this->Target,0,this->Format,srcXmin,srcYmin,width,height,0);
vtkOpenGLCheckErrorMacro("failed at glCopyTexImage2D " << this->Format);
glCopyTexImage2D(this->Target,0,this->InternalFormat,srcXmin,srcYmin,width,height,0);
vtkOpenGLCheckErrorMacro("failed at glCopyTexImage2D " << this->InternalFormat);
}
//----------------------------------------------------------------------------
......
Markdown is supported
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