The Vish Visualization Shell 0.3
Vish
Wizt::GLColormap Struct Reference

A colormap can be used in two ways: as 1D texture, or as colortable. More...

#include <ocean/GLvish/VGLColormap.hpp>

Static Public Member Functions

static void Disable (const RefPtr< Colormap > &Cmap)
 Disable this colormap, i.e.
static bool Enable (const RefPtr< Colormap > &Cmap, const RefPtr< GLTexture1D > &CmapTexture, const bool clampP, bool Discrete)
 Enable this colormap, as 1D texture or as colortable.
static RefPtr< GLTexture1DEnable (const RefPtr< Colormap > &Cmap, TextureCreator &CmapTC, int TextureUnit, const bool clampP=true, bool Discrete=false)
 Activate a 1D texture from the virtual color values and put these into the specified texture creator.
static bool EnableColorTable (const RefPtr< Colormap > &Cmap)
 Explicitly load the colormap as OpenGL ColorTable.

Detailed Description

A colormap can be used in two ways: as 1D texture, or as colortable.

Which method to use depends on the usage scenario:

  • Loading as 1D Texture: For each vertex to be rendered, the scalar field needs to be specified as 1D texture coordinate. Multitexturing may well be used. The Colormap class does not deal with any multitexturing operations. This mode requires specifying each vertex explicitely, and color interpolation is done linearly within rendering perspectives. Note that when changing the colormap, only the 1D texture is changed, but the original data that specify the 1D coordinates may stem from some cached OpenGL object, like a display list or vertex buffer object. I.e., original data do not need to be accessed (no RAM or disk access).
  • Loading as Colortable: When pixels are rendered via a luminance texture, the colortable may be used to map these scalar values to RGB or RGBA values. This mode does not require to set data per pixel, but works indirectly via specifying 2D texture coordinates for the luminance texture. Note that when changing the colormap, the 2D luminance texture needs to be reloaded, due to the way the OpenGL PixelTransfer() function works. Consequently, original data need to be accessed from RAM (or disc).

    Activate this colormap in specified shader program under the given name and specified texture unit.

    Typical usage scenario:

    static const char fragmentshader_src[] =
    "\n"
    //Reference to the 1D texture that store the colormap
    "uniform sampler1D ColormapTexture;\n"
    "\n"
    "void main (void)\n"
    "{\n"
    " gl_FragColor = texture1D(ColormapTexture, gl_TexCoord[1].r );\n"
    "}\n"
    ;
    void MyObject::render(VRenderContext&Context) const
    {
    VColormap Cmap;
    myColormap << Context >> Cmap;
    RefPtr<ValueSet> CmapValues = new ValueSet(myColormap(Context) );
    TextureCreator&TC = Context[ *myState ][ this ][ CmapValues ]( TEXTURE() );
    RefPtr<GLTexture1D> CmapTexture = Cmap->Enable(TC, 1);
    try
    {
    RefPtr<Program> MyProgram = new Program(colormap_vertex_shader, colormap_fragment_shader);
    MyProgram->setUniformTexture( "ColormapTexture" , *CmapTexture);
    ... RENDER CODE ...
    }
    catch(const Program::Error&E)
    {
    E.print("Compiled program not usable");
    }
    }
    A set of variable names, with indices associated to each type.
    Definition Context.hpp:18
    A handler for texture creation and release.
    Definition TextureBase.hpp:87
    Base class for objects that may display something.
    Definition VRenderContext.hpp:77
    A set of values.
    Definition ValueSet.hpp:33
    StrongPtr< Object, ObjectBase > RefPtr
    Convenience template typedef to use RefPtr instead of StrongPtr.
    Definition RefPtr.hpp:776
    Definition GLCacheFactory.hpp:90

    This example uses the GLCache of the VRenderContext to store the textures. A colormap requires an OpenGL texture to store its values. This texture needs to be stored somewhere. In theory, it could also be stored in the object's local State object. This would work well when the program is run, but the problem occurs during destruction: The texture object needs to be destroyed within an OpenGL context, but the VObject's local state doesn't have one. The GLCache however will be destructed in an OpenGL context and therefore must be used for proper clean up. Otherwise, the application will terminate with a segfault when closing.

    See also
    Colorizer::getColormap()

Member Function Documentation

◆ Disable()

void Wizt::GLColormap::Disable ( const RefPtr< Colormap > & Cmap)
static

Disable this colormap, i.e.

switch off Colortable mode.

Referenced by Enable().

◆ Enable() [1/2]

bool Wizt::GLColormap::Enable ( const RefPtr< Colormap > & Cmap,
const RefPtr< GLTexture1D > & CmapTexture,
const bool clampP,
bool Discrete )
static

Enable this colormap, as 1D texture or as colortable.

Parameters
Cmap1DIf a valid pointer, set the colormap as 1D texture, otherwise as a colortable.
clampPclamp values, not repeating
DiscreteA flag to tell if the colormap shall be interpolated or not.
Note
If the colormap is set via a colortable, then the PixelTransfer() may be applied elsewhere. It affects subsequent operations of loading a texture. Binding an existing texture will however not be affected by the colormap then, it is required to reload the texture.

References Disable(), and Eagle::FixedArray< value, N >::ptr().

Referenced by Enable(), and EnableColorTable().

◆ Enable() [2/2]

RefPtr< GLTexture1D > Wizt::GLColormap::Enable ( const RefPtr< Colormap > & Cmap,
TextureCreator & CmapTC,
int TextureUnit,
const bool clampP = true,
bool Discrete = false )
static

Activate a 1D texture from the virtual color values and put these into the specified texture creator.

Parameters
CmapTCThe Texture creator, as retrieved from an OpenGL Cache
TextureUnitThe Texture unit (OpenGL ActiveTexture) which is to be used for this texture.
clampPclamp values, not repeating

References Enable(), and Wizt::TextureCreator::get().