Commit 1f5f80da authored by Ken Martin's avatar Ken Martin

Managed to get scale and bias for voluem rendering working

parent a74d8a2b
......@@ -537,6 +537,11 @@ void vtkOpenGLContextDevice2D::DrawPoly(float *f, int n, unsigned char *colors,
assert("f must be non-null" && f != NULL);
assert("n must be greater than 0" && n > 0);
if (this->Pen->GetLineType() == vtkPen::NO_PEN)
{
return;
}
vtkOpenGLClearErrorMacro();
this->SetLineType(this->Pen->GetLineType());
this->SetLineWidth(this->Pen->GetWidth());
......@@ -577,6 +582,11 @@ void vtkOpenGLContextDevice2D::DrawLines(float *f, int n, unsigned char *colors,
assert("f must be non-null" && f != NULL);
assert("n must be greater than 0" && n > 0);
if (this->Pen->GetLineType() == vtkPen::NO_PEN)
{
return;
}
vtkOpenGLClearErrorMacro();
this->SetLineType(this->Pen->GetLineType());
......@@ -1458,36 +1468,11 @@ void vtkOpenGLContextDevice2D::SetLineWidth(float width)
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::SetLineType(int type)
{
if (type == vtkPen::SOLID_LINE)
if (type == vtkPen::SOLID_LINE || type == vtkPen::NO_PEN)
{
glDisable(GL_LINE_STIPPLE);
}
else
{
glEnable(GL_LINE_STIPPLE);
}
GLushort pattern = 0x0000;
switch (type)
{
case vtkPen::NO_PEN:
pattern = 0x0000;
break;
case vtkPen::DASH_LINE:
pattern = 0x00FF;
break;
case vtkPen::DOT_LINE:
pattern = 0x0101;
break;
case vtkPen::DASH_DOT_LINE:
pattern = 0x0C0F;
break;
case vtkPen::DASH_DOT_DOT_LINE:
pattern = 0x1C47;
break;
default:
pattern = 0x0000;
return;
}
glLineStipple(1, pattern);
vtkErrorMacro(<< "Line Stipples are no longer supported");
}
//-----------------------------------------------------------------------------
......
......@@ -95,36 +95,11 @@ public:
void SetLineType(int type)
{
if (type == vtkPen::SOLID_LINE)
{
glDisable(GL_LINE_STIPPLE);
}
else
{
glEnable(GL_LINE_STIPPLE);
}
GLushort pattern = 0x0000;
switch (type)
{
case vtkPen::NO_PEN:
pattern = 0x0000;
break;
case vtkPen::DASH_LINE:
pattern = 0x00FF;
break;
case vtkPen::DOT_LINE:
pattern = 0x0101;
break;
case vtkPen::DASH_DOT_LINE:
pattern = 0x0C0F;
break;
case vtkPen::DASH_DOT_DOT_LINE:
pattern = 0x1C47;
break;
default:
pattern = 0x0000;
}
glLineStipple(1, pattern);
if (type == vtkPen::SOLID_LINE || type == vtkPen::NO_PEN)
{
return;
}
vtkGenericWarningMacro(<< "Line Stipples are no longer supported");
}
// Store the previous GL state so that we can restore it when complete
......@@ -389,6 +364,11 @@ void vtkOpenGLContextDevice3D::DrawPoly(const float *verts, int n,
assert("verts must be non-null" && verts != NULL);
assert("n must be greater than 0" && n > 0);
if (this->Pen->GetLineType() == vtkPen::NO_PEN)
{
return;
}
vtkOpenGLClearErrorMacro();
this->EnableDepthBuffer();
......@@ -431,6 +411,11 @@ void vtkOpenGLContextDevice3D::DrawLines(const float *verts, int n,
assert("verts must be non-null" && verts != NULL);
assert("n must be greater than 0" && n > 0);
if (this->Pen->GetLineType() == vtkPen::NO_PEN)
{
return;
}
vtkOpenGLClearErrorMacro();
this->EnableDepthBuffer();
......
......@@ -317,7 +317,20 @@ void vtkDepthPeelingPass::Render(const vtkRenderState *s)
// we need alpha planes
GLint alphaBits;
glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
#if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
if (vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER,
GL_FRONT_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alphaBits);
}
else
#else
{
glGetIntegerv(GL_ALPHA_BITS, &alphaBits);
}
#endif
if (alphaBits < 8)
{
// just use alpha blending
......
......@@ -50,10 +50,6 @@ vtkOpenGLGlyph3DHelper::vtkOpenGLGlyph3DHelper()
this->UseFastPath = false;
this->UsingInstancing = false;
// we always tell our triangle VAO to emulate to be safe
// this is because it seems that GLEW_ARB_vertex_array_object
// does not always handle the attributes for GLEW_ARB_instanced_arrays
this->Tris.vao.SetForceEmulation(true);
}
//-----------------------------------------------------------------------------
......@@ -296,6 +292,13 @@ void vtkOpenGLGlyph3DHelper::GlyphRender(vtkRenderer* ren, vtkActor* actor, vtkI
std::vector<float> &normalMatrices, std::vector<vtkIdType> &pickIds,
unsigned long pointMTime)
{
// we always tell our triangle VAO to emulate unless we
// have opngl 3.2 to be safe
// this is because it seems that GLEW_ARB_vertex_array_object
// does not always handle the attributes for GLEW_ARB_instanced_arrays
this->Tris.vao.SetForceEmulation(
!vtkOpenGLRenderWindow::GetContextSupportsOpenGL32());
this->CurrentInput = this->GetInput();
this->UsingInstancing = false;
......
......@@ -682,14 +682,47 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
"tcoordVC = tcoordMC;");
}
int tNumComp = 4;
vtkTexture *texture = actor->GetTexture();
if (this->ColorTextureMap)
{
texture = this->InternalColorTexture;
}
if (!texture && actor->GetProperty()->GetNumberOfTextures())
{
texture = actor->GetProperty()->GetTexture(0);
}
if (texture)
{
tNumComp =
vtkOpenGLTexture::SafeDownCast(texture)->
GetTextureObject()->GetComponents();
}
if (this->Layout.TCoordComponents == 1)
{
substitute(VSSource, "//VTK::TCoord::Dec",
"attribute float tcoordMC; varying float tcoordVC;");
substitute(FSSource, "//VTK::TCoord::Dec",
"varying float tcoordVC; uniform sampler2D texture1;");
substitute(FSSource, "//VTK::TCoord::Impl",
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*texture2D(texture1, vec2(tcoordVC,0.0));");
switch (tNumComp)
{
case 1:
substitute(FSSource, "//VTK::TCoord::Impl",
"vec4 tcolor = texture2D(texture1, vec2(tcoordVC,0.0));\n"
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*\n"
" vec4(tcolor.r,tcolor.r,tcolor.r,1.0);");
break;
case 2:
substitute(FSSource, "//VTK::TCoord::Impl",
"vec4 tcolor = texture2D(texture1, vec2(tcoordVC,0.0));\n"
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*\n"
" vec4(tcolor.r,tcolor.r,tcolor.r,tcolor.g);");
break;
default:
substitute(FSSource, "//VTK::TCoord::Impl",
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*texture2D(texture1, vec2(tcoordVC,0.0));");
}
}
else
{
......@@ -701,8 +734,24 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(
// handled above
if (!this->InterpolateScalarsBeforeMapping || !this->ColorCoordinates)
{
substitute(FSSource, "//VTK::TCoord::Impl",
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*texture2D(texture1, tcoordVC.st);");
switch (tNumComp)
{
case 1:
substitute(FSSource, "//VTK::TCoord::Impl",
"vec4 tcolor = texture2D(texture1, tcoordVC);\n"
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*\n"
" vec4(tcolor.r,tcolor.r,tcolor.r,1.0);");
break;
case 2:
substitute(FSSource, "//VTK::TCoord::Impl",
"vec4 tcolor = texture2D(texture1, tcoordVC);\n"
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*\n"
" vec4(tcolor.r,tcolor.r,tcolor.r,tcolor.g);");
break;
default:
substitute(FSSource, "//VTK::TCoord::Impl",
"gl_FragData[0] = clamp(gl_FragData[0],0.0,1.0)*texture2D(texture1, tcoordVC.st);");
}
}
}
}
......@@ -1989,6 +2038,7 @@ void vtkOpenGLPolyDataMapper::BuildBufferObjects(vtkRenderer *ren, vtkActor *act
// for coloring with a point attribute.
// fixme ... make the existence of the coordinate array the signal.
vtkDataArray *tcoords = NULL;
this->TextureComponents = 4;
if (haveTextures)
{
if (this->InterpolateScalarsBeforeMapping && this->ColorCoordinates)
......
......@@ -277,6 +277,8 @@ protected:
char* ProcessIdArrayName;
char* CompositeIdArrayName;
int TextureComponents;
private:
vtkOpenGLPolyDataMapper(const vtkOpenGLPolyDataMapper&); // Not implemented.
void operator=(const vtkOpenGLPolyDataMapper&); // Not implemented.
......
......@@ -481,14 +481,38 @@ int vtkOpenGLRenderWindow::GetColorBufferSizes(int *rgba)
if ( this->Mapped)
{
this->MakeCurrent();
glGetIntegerv( GL_RED_BITS, &size );
rgba[0] = static_cast<int>(size);
glGetIntegerv( GL_GREEN_BITS, &size );
rgba[1] = static_cast<int>(size);
glGetIntegerv( GL_BLUE_BITS, &size );
rgba[2] = static_cast<int>(size);
glGetIntegerv( GL_ALPHA_BITS, &size );
rgba[3] = static_cast<int>(size);
#if GL_ES_VERSION_2_0 != 1 || GL_ES_VERSION_3_0 == 1
if (vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER,
GL_FRONT_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &size);
rgba[0] = static_cast<int>(size);
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER,
GL_FRONT_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &size);
rgba[1] = static_cast<int>(size);
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER,
GL_FRONT_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &size);
rgba[2] = static_cast<int>(size);
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER,
GL_FRONT_LEFT,
GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &size);
rgba[3] = static_cast<int>(size);
}
else
#endif
{
glGetIntegerv( GL_RED_BITS, &size );
rgba[0] = static_cast<int>(size);
glGetIntegerv( GL_GREEN_BITS, &size );
rgba[1] = static_cast<int>(size);
glGetIntegerv( GL_BLUE_BITS, &size );
rgba[2] = static_cast<int>(size);
glGetIntegerv( GL_ALPHA_BITS, &size );
rgba[3] = static_cast<int>(size);
}
return rgba[0]+rgba[1]+rgba[2]+rgba[3];
}
else
......
......@@ -116,7 +116,11 @@ vtkShaderProgram *vtkOpenGLShaderCache::ReadyShader(
"#version 150\n"
"#define highp\n"
"#define mediump\n"
"#define lowp");
"#define lowp\n"
"#define texelFetchBuffer texelFetch\n"
"#define texture1D texture\n"
"#define texture3D texture\n"
);
GSSource = replace(GSSource,"//VTK::System::Dec",
"#version 150\n"
"#define highp\n"
......
......@@ -97,11 +97,9 @@ static const char *DepthTextureCompareFunctionAsString[8]=
//----------------------------------------------------------------------------
static GLenum OpenGLAlphaInternalFormat[5]=
{
GL_ALPHA,
GL_ALPHA4,
GL_ALPHA8,
GL_ALPHA12,
GL_ALPHA16
GL_R,
GL_R8,
GL_R16
};
#else
......@@ -124,11 +122,9 @@ static const char *DepthTextureCompareFunctionAsString[8]=
//----------------------------------------------------------------------------
static GLenum OpenGLAlphaInternalFormat[5]=
{
GL_ALPHA,
GL_ALPHA,
GL_ALPHA,
GL_ALPHA,
GL_ALPHA
GL_R,
GL_R,
GL_R
};
#endif
......@@ -267,6 +263,10 @@ bool vtkTextureObject::IsSupported(vtkOpenGLRenderWindow* vtkNotUsed(win),
bool requireTexInt)
{
#if GL_ES_VERSION_2_0 != 1
if (vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
return true;
}
bool texFloat = true;
if (requireTexFloat)
{
......@@ -303,14 +303,23 @@ bool vtkTextureObject::IsSupported(vtkOpenGLRenderWindow* vtkNotUsed(win),
bool vtkTextureObject::LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
{
#if GL_ES_VERSION_2_0 != 1
this->SupportsTextureInteger =
(glewIsSupported("GL_EXT_texture_integer") != 0);
if (vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
this->SupportsTextureInteger = true;
this->SupportsTextureFloat = true;
this->SupportsDepthBufferFloat = true;
}
else
{
this->SupportsTextureInteger =
(glewIsSupported("GL_EXT_texture_integer") != 0);
this->SupportsTextureFloat =
(glewIsSupported("GL_ARB_texture_float") != 0);
this->SupportsTextureFloat =
(glewIsSupported("GL_ARB_texture_float") != 0);
this->SupportsDepthBufferFloat =
(glewIsSupported("GL_ARB_depth_buffer_float") != 0);
this->SupportsDepthBufferFloat =
(glewIsSupported("GL_ARB_depth_buffer_float") != 0);
}
#else
// some of these may have extensions etc for ES 2.0
// setting to false right now as I do not know
......@@ -648,15 +657,6 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
return this->InternalFormat;
}
// 1 or 2 components not supported as render target in FBO on GeForce<8
// force internal format component to be 3 or 4, even if client format is 1
// or 2 components.
// see spec 2.1 page 137 (pdf page 151) in section 3.6.4 Rasterization of
// Pixel Rectangles: "Conversion to RGB": this step is applied only if
// the format is LUMINANCE or LUMINANCE_ALPHA:
// L: R=L, G=L, B=L
// LA: R=L, G=L, B=L, A=A
// pre-condition
if(vtktype==VTK_VOID && numComps != 1)
{
......@@ -665,12 +665,7 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
this->InternalFormat = 0;
return this->InternalFormat;
}
const bool oldGeForce=!this->SupportsTextureInteger;
if(oldGeForce && numComps<3)
{
numComps+=2;
}
// DON'T DEAL WITH VTK_CHAR as this is platform dependent.
switch (vtktype)
{
......@@ -684,10 +679,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE8I_EXT;
this->InternalFormat = GL_R8I;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA8I_EXT;
this->InternalFormat = GL_RG8I;
break;
case 3:
this->InternalFormat = GL_RGB8I_EXT;
......@@ -702,10 +697,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE8;
this->InternalFormat = GL_R8;
break;
case 2:
this->InternalFormat = GL_LUMINANCE8_ALPHA8;
this->InternalFormat = GL_RG8;
break;
case 3:
this->InternalFormat = GL_RGB8;
......@@ -722,10 +717,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE8UI_EXT;
this->InternalFormat = GL_R8UI;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA8UI_EXT;
this->InternalFormat = GL_RG8UI;
break;
case 3:
this->InternalFormat = GL_RGB8UI_EXT;
......@@ -740,10 +735,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE8;
this->InternalFormat = GL_R8;
break;
case 2:
this->InternalFormat = GL_LUMINANCE8_ALPHA8;
this->InternalFormat = GL_RG8;
break;
case 3:
this->InternalFormat = GL_RGB8;
......@@ -760,10 +755,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE16I_EXT;
this->InternalFormat = GL_R16I;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA16I_EXT;
this->InternalFormat = GL_RG16I;
break;
case 3:
this->InternalFormat = GL_RGB16I_EXT;
......@@ -780,9 +775,8 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
case 1:
if(this->SupportsTextureFloat)
{
this->InternalFormat = GL_LUMINANCE32F_ARB;
this->InternalFormat = GL_R32F;
break;
// this->InternalFormat = GL_LUMINANCE16; // not supported as a render target
}
else
{
......@@ -793,9 +787,8 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
case 2:
if(this->SupportsTextureFloat)
{
this->InternalFormat = GL_LUMINANCE_ALPHA32F_ARB;
this->InternalFormat = GL_RG32F;
break;
// this->InternalFormat = GL_LUMINANCE16_ALPHA16; // not supported as a render target
}
else
{
......@@ -818,10 +811,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE16UI_EXT;
this->InternalFormat = GL_R16UI;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA16UI_EXT;
this->InternalFormat = GL_RG16UI;
break;
case 3:
this->InternalFormat = GL_RGB16UI_EXT;
......@@ -838,9 +831,8 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
case 1:
if(this->SupportsTextureFloat)
{
this->InternalFormat = GL_LUMINANCE32F_ARB;
this->InternalFormat = GL_R32F;
break;
// this->InternalFormat = GL_LUMINANCE16; // not supported as a render target
}
else
{
......@@ -851,9 +843,8 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
case 2:
if(this->SupportsTextureFloat)
{
this->InternalFormat = GL_LUMINANCE_ALPHA32F_ARB;
this->InternalFormat = GL_RG32F;
break;
// this->InternalFormat = GL_LUMINANCE16_ALPHA16; // not supported as a render target
}
else
{
......@@ -876,10 +867,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE32I_EXT;
this->InternalFormat = GL_R32I;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA32I_EXT;
this->InternalFormat = GL_RG32I;
break;
case 3:
this->InternalFormat = GL_RGB32I_EXT;
......@@ -896,10 +887,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE32F_ARB;
this->InternalFormat = GL_R32F;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA32F_ARB;
this->InternalFormat = GL_RG32F;
break;
case 3:
this->InternalFormat = GL_RGB32F_ARB;
......@@ -922,10 +913,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE32UI_EXT;
this->InternalFormat = GL_R32UI;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA32UI_EXT;
this->InternalFormat = GL_RG32UI;
break;
case 3:
this->InternalFormat = GL_RGB32UI_EXT;
......@@ -942,10 +933,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE32F_ARB;
this->InternalFormat = GL_R32F;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA32F_ARB;
this->InternalFormat = GL_RG32F;
break;
case 3:
this->InternalFormat = GL_RGB32F_ARB;
......@@ -968,10 +959,10 @@ unsigned int vtkTextureObject::GetInternalFormat(int vtktype, int numComps,
switch (numComps)
{
case 1:
this->InternalFormat = GL_LUMINANCE32F_ARB;
this->InternalFormat = GL_R32F;
break;
case 2:
this->InternalFormat = GL_LUMINANCE_ALPHA32F_ARB;
this->InternalFormat = GL_RG32F;
break;
case 3:
this->InternalFormat = GL_RGB32F_ARB;