Commit 06b08979 authored by fogal1's avatar fogal1

Add GLEW initialization wrapper.

There's a few plots that have:

  static bool glew_init = false;
  ...
  if(!glew_init) { glewInit(); glew_init = true; }

duplicated.  This centralizes the code, ensuring we only do GLEW
initialization once per process, even if two plots use GLEW.
Further, GLEW init has become more complicated and this prevents
anyone else from having to learn the details.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@8017 18c085ea-50e0-402c-830e-de6fd14e8384
parent 66ee8ba6
......@@ -183,6 +183,9 @@
# Brad Whitlock, Wed Jun 10, 12:13:23 PDT 2009
# I changed how Mesa sources are added to the project.
#
# Tom Fogal, Sat Jul 18 19:44:48 MDT 2009
# Added GLEW initialization wrapper.
#
##############################################################################
##
......@@ -208,11 +211,10 @@ SRC=avtLegend.C avtVariableLegend.C avtGeometryDrawable.C avtActor.C \
avtDecorationsDrawable.C avtDecorationsMapper.C avtLabeledCurveMapper.C \
avtExternallyRenderedImagesActor.C avtTensorGlyphMapper.C avtDrawable.C \
avtPointGlypher.C avtVariablePointGlyphMapper.C avtSoftwareShader.C \
avtLevelsPointGlyphMapper.C avtCurveLegend.C
avtLevelsPointGlyphMapper.C avtCurveLegend.C avtGLEWInitializer.C
CPPFLAGS=-I../../include/visit @COMPONENT_CPPFLAGS@ @CPPFLAGS@
CPPFLAGS=-I../../include/visit @COMPONENT_CPPFLAGS@ @CPPFLAGS@ $(GLEW_INCLUDE)
SEROBJ=$(SRC:.C=.o) $(SEROPENGL_OBJ) @SERMESA_OBJ@
PAROBJ=$(SRC:.C=_par.o) $(PAROPENGL_OBJ) @PARMESA_OBJ@
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// GLEWInitializer.C //
// ************************************************************************* //
#include "avtGLEWInitializer.h"
#include <avtCallback.h>
#include <DebugStream.h>
#include <RuntimeSetting.h>
namespace avt { namespace glew {
// Won't call init again if true.
static bool initialized = false;
// ****************************************************************************
// Function: visit::glew::initialize
//
// Purpose: Initializes GLEW using GL library from RuntimeSetting.
// Maintains state to avoid duplicate initialization.
//
// Arguments:
// force : force initialization even if we've previously initialized.
// Needed if, for example, contexts change behind our back.
//
// Programmer: Tom Fogal
//
// ****************************************************************************
bool initialize(bool force)
{
if(initialized && !force) // Bail early if we've already been here.
{
return true;
}
std::string gl_lib;
enum GL_Name_Convention convention;
const bool use_mesa = avtCallback::GetSoftwareRendering();
if(use_mesa)
{
gl_lib = RuntimeSetting::lookups("mesa-lib");
convention = GLEW_NAME_CONVENTION_MANGLED_MESA;
}
else
{
gl_lib = RuntimeSetting::lookups("system-gl");
convention = GLEW_NAME_CONVENTION_GL;
}
debug1 << "Initializing GLEW using library: " << gl_lib << std::endl;
GLenum err = glewInitLibrary(gl_lib.c_str(), convention);
initialized = true;
if(GLEW_OK != err)
{
debug1 << "GLEW initialization FAILED: " << glewGetErrorString(err)
<< "\nCalling OpenGL at this point will likely segfault!"
<< std::endl;
initialized = false;
}
return initialized;
}
}; /* glew */ }; /* avt */
/*****************************************************************************
*
* Copyright (c) 2000 - 2009, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// GLEWInitializer.h //
// ************************************************************************* //
#ifndef VISIT_GLEW_INITIALIZER_H
#define VISIT_GLEW_INITIALIZER_H
#include <plotter_exports.h>
// We don't need it in this header, but include GLEW here for ease of use.
// GLEW must be included before any OpenGL headers, and if clients want this
// file then *not* including GLEW wouldn't make any sense!
#include <GL/glew.h>
namespace avt {
namespace glew {
// ****************************************************************************
// Function: visit::glew::initialize
//
// Purpose: Initializes GLEW using GL library from RuntimeSetting.
// Maintains state to avoid duplicate initialization.
//
// Arguments:
// force : force initialization even if we've previously initialized.
// Needed if, for example, contexts change behind our back.
//
// Programmer: Tom Fogal
//
// ****************************************************************************
bool PLOTTER_API initialize(bool force=false);
};
};
#endif
../../avt/Plotter/avtGLEWInitializer.h
\ No newline at end of file
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