Commit 8b890274 authored by loring's avatar loring

address two issues in visit's osmesa extension manager

first issue:
vtk's opengl extension manager (base class for osmesa
extension manager) had changed in vtk 6.1. we were
overriding all the base class methods using a copy of
an out of date version of vtk class code. as a result
base class was not getting initialized and vtk's
open gl feature detection, driver, and gl identification
were not working.

To address this I got rid of the overrides that didn't
change vtk behavior and instead use the base class
implementation in those cases. this makes sure the
base class member variables get initialized and feature
detection etc works again.

second issue:
I also let visit enable the blend_function_separate
extension. in vtk this is the most efficient way
to ensure correct alpha values during transparent
rendering and is required for vtk's depth peeling
algorithm. In a number of plots in visit that need
a specific blend function I had to set the blend
function explicitly and save and restore the related
gl blending state.

note:
plots that make use of GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA
mode for alpha blending don't produce correct alpha
values. I didn't change that here.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@27366 18c085ea-50e0-402c-830e-de6fd14e8384
parent f98cb3bf
......@@ -159,12 +159,18 @@ TextureModeData::~TextureModeData()
// Creation: Mon Mar 27 17:18:28 PST 2006
//
// Modifications:
//
//
// Burlen Loring, Sun Oct 4 23:37:20 PDT 2015
// Save restore blend func separate state
//
// ****************************************************************************
bool
TextureModeData::BeginSphereTexturing()
{
glPushAttrib(GL_COLOR_BUFFER_BIT|GL_TEXTURE_BIT|
GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT);
// Create the rextures
if(!sphereTexturesDataCreated)
{
......@@ -189,16 +195,7 @@ TextureModeData::BeginSphereTexturing()
sphereTexturesLoaded = true;
}
//
// Get whether GL_BLEND is enabled.
//
glGetIntegerv(GL_BLEND, &isBlendEnabled);
if(isBlendEnabled == 0)
glEnable(GL_BLEND);
glGetIntegerv(GL_BLEND_SRC, &blendFunc0);
glGetIntegerv(GL_BLEND_DST, &blendFunc1);
// set the blend mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//
......@@ -208,23 +205,9 @@ TextureModeData::BeginSphereTexturing()
glGetIntegerv(GL_DEPTH_TEST, &dt);
if(dt == 1)
{
// Get the current alpha test function
glGetIntegerv(GL_ALPHA_TEST, &isAlphaTestEnabled);
if(isAlphaTestEnabled)
{
glGetIntegerv(GL_ALPHA_TEST_FUNC, &alphaTestFunc);
glGetFloatv(GL_ALPHA_TEST_REF, &alphaTestRef);
}
else
glEnable(GL_ALPHA_TEST);
// Set the alpha testing mode and function.
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.7);
needAlphaTest = 1;
}
else
needAlphaTest = 0;
//
// Turn on the texture
......@@ -246,40 +229,30 @@ TextureModeData::BeginSphereTexturing()
// Creation: Mon Mar 27 17:19:08 PST 2006
//
// Modifications:
//
//
// Burlen Loring, Sun Oct 4 23:37:20 PDT 2015
// Save restore blend func separate state
//
// ****************************************************************************
void
TextureModeData::EndSphereTexturing()
{
if(needAlphaTest)
{
if(isAlphaTestEnabled)
glAlphaFunc(alphaTestFunc, alphaTestRef);
else
glDisable(GL_ALPHA_TEST);
}
if(isBlendEnabled == 0)
glDisable(GL_BLEND);
// Restore the old blend function.
glBlendFunc(blendFunc0, blendFunc1);
glDisable(GL_TEXTURE_2D);
glPopAttrib();
}
// ****************************************************************************
// Method: TextureModeData::MakeTextures
//
// Purpose:
// Purpose:
// Makes a sphere texture that we'll apply to imposter quads.
//
// Programmer: Brad Whitlock
// Creation: Mon Mar 27 17:19:31 PST 2006
//
// Modifications:
//
//
// ****************************************************************************
void
......
......@@ -21,8 +21,6 @@
// This is a subclass of TextureRenderer that renders its cmap2 widgets into
// a texture that it then uses to texture a rectangle.
//
// Notes:
//
// Programmer: Brad Whitlock
// Creation: Fri Sep 7 14:52:53 PST 2007
//
......@@ -31,12 +29,15 @@
// I changed the draw method so it does not do anything if there are no
// widgets to draw. This seems to fix a problem with drawing the empty widget.
//
// Burlen Loring, Sun Oct 4 23:54:02 PDT 2015
// Save/restore blend function state
//
// ****************************************************************************
class WidgetRenderer : public SLIVR::TextureRenderer
{
public:
WidgetRenderer(std::vector<SLIVR::ColorMap2*> &cmap2, int tex_mem) :
WidgetRenderer(std::vector<SLIVR::ColorMap2*> &cmap2, int tex_mem) :
SLIVR::TextureRenderer(0, 0, cmap2, tex_mem)
{
}
......@@ -53,6 +54,8 @@ public:
void draw()
{
glPushAttrib(GL_COLOR_BUFFER_BIT|GL_ENABLE_BIT);
// Find the number of widgets
size_t nWidgets = 0;
for(size_t c = 0; c < cmap2_.size(); ++c)
......@@ -91,6 +94,8 @@ public:
for(size_t w = 0; w < widgets.size(); ++w)
widgets[w]->draw();
}
glPopAttrib();
}
};
......
......@@ -203,6 +203,11 @@ avtOpenGL3DTextureVolumeRenderer::~avtOpenGL3DTextureVolumeRenderer()
// Hank Childs, Wed Oct 12 05:45:27 PDT 2011
// Increase the number of possible slices to 1000.
//
// Burlen Loring, Sun Oct 4 23:28:40 PDT 2015
// Make sure we set the blend mode, VTK may use a different
// mode depending on what extensions are available. also
// save/store gl state using pus/pop attrib.
//
// ****************************************************************************
void
......@@ -226,12 +231,16 @@ avtOpenGL3DTextureVolumeRenderer::Render(
return;
}
// save state of what we will modify
glPushAttrib(GL_COLOR_BUFFER_BIT|GL_TEXTURE_BIT|
GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT);
// Get the transfer function
int ncolors=256;
int nopacities=256;
unsigned char rgba[256*4];
props.atts.GetTransferFunction(rgba);
// Get the dimensions
int dims[3];
vtkRectilinearGrid *grid = (vtkRectilinearGrid *)volume.grid;
......@@ -241,7 +250,7 @@ avtOpenGL3DTextureVolumeRenderer::Render(
int ny=dims[1];
int nz=dims[2];
// Find the smallest power of two in each dimension
// Find the smallest power of two in each dimension
// that will accomodate this data set
int newnx = MAX(int(pow(2.0,1+int(log(double(nx-1))/log(2.0)))),1);
int newny = MAX(int(pow(2.0,1+int(log(double(ny-1))/log(2.0)))),1);
......@@ -302,7 +311,6 @@ avtOpenGL3DTextureVolumeRenderer::Render(
// If we want to transform the light so it is attached to the camera:
//I->MultiplyPoint(light, light);
//
// Create the 3D texture if we need to
//
......@@ -354,7 +362,7 @@ avtOpenGL3DTextureVolumeRenderer::Render(
props.atts.GetOpacityAttenuation()/256.;
opacity = MAX(0,MIN(1,opacity));
// drop transparent splats
// drop transparent splats
//if (opacity < .0001)
// continue;
......@@ -420,7 +428,7 @@ avtOpenGL3DTextureVolumeRenderer::Render(
// No shading ata ll
brightness=1;
}
// Determine the actual color and opacity now
int colorindex = int(ncolors * v);
if (colorindex < 0)
......@@ -447,7 +455,6 @@ avtOpenGL3DTextureVolumeRenderer::Render(
glGenTextures(1, (GLuint*)&volumetexId);
glBindTexture(GL_TEXTURE_3D, volumetexId);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, newnx, newny, newnz,
0, GL_RGBA, GL_UNSIGNED_BYTE, volumetex);
}
......@@ -465,10 +472,10 @@ avtOpenGL3DTextureVolumeRenderer::Render(
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_3D);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
bool alreadyBlending = glIsEnabled(GL_BLEND);
if (!alreadyBlending)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDepthMask(false);
// Set up camera parameters
......@@ -545,7 +552,7 @@ avtOpenGL3DTextureVolumeRenderer::Render(
float dz = bbox.z[pt0] - bbox.z[ptn];
float dist = sqrt(dx*dx + dy*dy + dz*dz);
// Do the actual contouring
// Do the actual contouring
glBegin(GL_TRIANGLES);
glColor4f(1.,1.,1.,1.);
int ns = props.atts.GetNum3DSlices();
......@@ -572,12 +579,9 @@ avtOpenGL3DTextureVolumeRenderer::Render(
}
glEnd();
// Set some GL parameters back to their expected values and free memory
glDepthMask(true);
glDisable(GL_TEXTURE_3D);
if (!alreadyBlending)
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
// Set some GL parameters back to their expected values
// and free memory
glPopAttrib();
camera->Delete();
}
......@@ -339,6 +339,12 @@ DrawOneSplat(const avtVolumeRendererImplementation::RenderProperties &props,
// Push/pop enable and texture state to fix a bug where the settings could
// corrupt the Pseudocolor plot's renderer.
//
// Burlen Loring, Sun Oct 4 23:28:40 PDT 2015
// Make sure we set the blend mode, VTK may use a different
// mode depending on what extensions are available. also
// save/store blending state using pus/pop attrib. I fixed a
// couple of warnings.
//
// ****************************************************************************
void
......@@ -346,7 +352,8 @@ avtOpenGLSplattingVolumeRenderer::Render(
const avtVolumeRendererImplementation::RenderProperties &props,
const avtVolumeRendererImplementation::VolumeData &volume)
{
glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT);
glPushAttrib(GL_COLOR_BUFFER_BIT|GL_TEXTURE_BIT|
GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT);
// Create the texture for a gaussian splat
const int GRIDSIZE=32;
......@@ -371,7 +378,7 @@ avtOpenGLSplattingVolumeRenderer::Render(
GRIDSIZE,GRIDSIZE,0, GL_ALPHA, GL_FLOAT, alphatex);
}
// Determine whether we should treat the data as a rectilinear grid or
// Determine whether we should treat the data as a rectilinear grid or
// as an unstructured grid.
vtkRectilinearGrid *grid = NULL;
if(volume.grid->GetDataObjectType() == VTK_RECTILINEAR_GRID)
......@@ -386,7 +393,7 @@ avtOpenGLSplattingVolumeRenderer::Render(
// get attribute parameters
unsigned char rgba[256*4];
props.atts.GetTransferFunction(rgba);
// Set up OpenGL parameters
glDisable(GL_LIGHTING);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
......@@ -395,9 +402,8 @@ avtOpenGLSplattingVolumeRenderer::Render(
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, alphatexId);
glEnable(GL_TEXTURE_2D);
bool alreadyBlending = glIsEnabled(GL_BLEND);
if (!alreadyBlending)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
// set up parameters
vtkCamera *camera = vtkCamera::New();
......@@ -427,9 +433,9 @@ avtOpenGLSplattingVolumeRenderer::Render(
size = sqrt( (p0[0]-p1[0])*(p0[0]-p1[0]) + (p0[1]-p1[1])*(p0[1]-p1[1]) + (p0[2]-p1[2])*(p0[2]-p1[2]) );
}
float viewdir[4] = {0,0,1, 0};
float V1[4] = {0,size*1.8,0};
float V2[4] = {size*1.8,0,0};
float viewdir[4] = {0.0f,0.0f,1.0f, 0.0f};
float V1[4] = {0.0f,static_cast<float>(size)*1.8f,0.0f};
float V2[4] = {static_cast<float>(size)*1.8f,0.0f,0.0f};
I->MultiplyPoint(viewdir, viewdir);
I->MultiplyPoint(V1,V1);
I->MultiplyPoint(V2,V2);
......@@ -513,7 +519,7 @@ avtOpenGLSplattingVolumeRenderer::Render(
imax = (svx<0) ? -1 : dims[0];
jmax = (svy<0) ? -1 : dims[1];
kmax = (svz<0) ? -1 : dims[2];
if (avx>=avy && avx>=avz)
{
c1 = &i;
......@@ -608,7 +614,7 @@ avtOpenGLSplattingVolumeRenderer::Render(
{
// skipping the opacity correction for now
/* ** HRC, 11/19/01, if this code ever becomes uncommented, it must
** be modified to address separate opacity and color variables.
** be modified to address separate opacity and color variables.
float dist;
if (dir==1)
dist = fabs(data->x[i]-data->x[i-svx]);
......@@ -711,16 +717,8 @@ avtOpenGLSplattingVolumeRenderer::Render(
pd->Delete();
} //Done Splatting
glDepthMask(true);
glDisable(GL_TEXTURE_2D);
if (!alreadyBlending)
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
camera->Delete();
I->Delete();
glPopAttrib();
}
......@@ -188,26 +188,6 @@ class VTKRENDERINGOPENGL_EXPORT vtkOSMesaGLExtensionManager : public vtkOpenGLEx
public:
vtkTypeMacro(vtkOSMesaGLExtensionManager, vtkObject);
static vtkOSMesaGLExtensionManager *New();
void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Set/Get the render window to query extensions on. If set to null,
// justs queries the current render window.
vtkRenderWindow* GetRenderWindow();
virtual void SetRenderWindow(vtkRenderWindow *renwin);
// Description:
// Updates the extensions string.
virtual void Update();
// Description:
// Returns a string listing all available extensions. Call Update first
// to validate this string.
vtkGetStringMacro(ExtensionsString);
// Description:
// Returns true if the extension is supported, false otherwise.
virtual int ExtensionSupported(const char *name);
//BTX
// Description:
......@@ -217,120 +197,16 @@ public:
const char *fname);
//ETX
// Description:
// Loads all the functions associated with the given extension into the
// appropriate static members of vtkgl. This method emits a warning if the
// requested extension is not supported. It emits an error if the extension
// does not load successfully.
virtual void LoadExtension(const char *name);
// Description:
// Returns true if the extension is supported and loaded successfully,
// false otherwise. This method will "fail silently/gracefully" if the
// extension is not supported or does not load properly. It emits neither
// warnings nor errors. It is up to the caller to determine if the
// extension loaded properly by paying attention to the return value.
virtual int LoadSupportedExtension(const char *name);
// Description:
// Loads all the functions associated with the given core-promoted extension
// into the appropriate static members of vtkgl associated with the OpenGL
// version that promoted the extension as a core feature. This method emits a
// warning if the requested extension is not supported. It emits an error if
// the extension does not load successfully.
//
// For instance, extension GL_ARB_multitexture was promoted as a core
// feature into OpenGL 1.3. An implementation that uses this
// feature has to (IN THIS ORDER), check if OpenGL 1.3 is supported
// with ExtensionSupported("GL_VERSION_1_3"), if true, load the extension
// with LoadExtension("GL_VERSION_1_3"). If false, test for the extension
// with ExtensionSupported("GL_ARB_multitexture"),if true load the extension
// with this method LoadCorePromotedExtension("GL_ARB_multitexture").
// If any of those loading stage succeeded, use vtgl::ActiveTexture() in
// any case, NOT vtgl::ActiveTextureARB().
// This method avoids the use of if statements everywhere in implementations
// using core-promoted extensions.
// Without this method, the implementation code should look like:
// \code
// int opengl_1_3=extensions->ExtensionSupported("GL_VERSION_1_3");
// if(opengl_1_3)
// {
// extensions->LoadExtension("GL_VERSION_1_3");
// }
// else
// {
// if(extensions->ExtensionSupported("GL_ARB_multitexture"))
// {
// extensions->LoadCorePromotedExtension("GL_ARB_multitexture");
// }
// else
// {
// vtkErrorMacro("Required multitexture feature is not supported!");
// }
// }
// ...
// if(opengl_1_3)
// {
// vtkgl::ActiveTexture(vtkgl::TEXTURE0)
// }
// else
// {
// vtkgl::ActiveTextureARB(vtkgl::TEXTURE0_ARB)
// }
// \endcode
// Thanks to this method, the code looks like:
// \code
// int opengl_1_3=extensions->ExtensionSupported("GL_VERSION_1_3");
// if(opengl_1_3)
// {
// extensions->LoadExtension("GL_VERSION_1_3");
// }
// else
// {
// if(extensions->ExtensionSupported("GL_ARB_multitexture"))
// {
// extensions->LoadCorePromotedExtension("GL_ARB_multitexture");
// }
// else
// {
// vtkErrorMacro("Required multitexture feature is not supported!");
// }
// }
// ...
// vtkgl::ActiveTexture(vtkgl::TEXTURE0);
// \endcode
virtual void LoadCorePromotedExtension(const char *name);
// Description:
// Similar to LoadCorePromotedExtension().
// It loads an EXT extension into the pointers of its ARB equivalent.
virtual void LoadAsARBExtension(const char *name);
//BTX
protected:
vtkOSMesaGLExtensionManager();
virtual ~vtkOSMesaGLExtensionManager();
int OwnRenderWindow;
char *ExtensionsString;
vtkTimeStamp BuildTime;
virtual void ReadOpenGLExtensions();
// Description:
// Wrap around the generated vtkgl::LoadExtension to deal with OpenGL 1.2
// and its optional part GL_ARB_imaging. Also functions like
// glBlendEquation() or glBlendColor() are optional in OpenGL 1.2 or 1.3 and
// provided by the GL_ARB_imaging but there are core features in OpenGL 1.4.
virtual int SafeLoadExtension(const char *name);
private:
vtkOSMesaGLExtensionManager(const vtkOSMesaGLExtensionManager&); // Not implemented
void operator=(const vtkOSMesaGLExtensionManager&); // Not implemented
vtkWeakPointer<vtkRenderWindow> RenderWindow;
//ETX
};
......
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