VISH
0.2
|
A colormap can be used in two ways: as 1D texture, or as colortable. More...
#include </home/werner/origo/vish/ocean/GLvish/VGLColormap.hpp>
A colormap can be used in two ways: as 1D texture, or as colortable.
Which method to use depends on the usage scenario:
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"); } }
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.
void Wizt::GLColormap::Disable | ( | const RefPtr< Colormap > & | Cmap | ) | [static] |
Disable this colormap, i.e.
switch off Colortable mode.
bool Wizt::GLColormap::Enable | ( | const RefPtr< Colormap > & | Cmap, |
const RefPtr< GLTexture1D > & | CmapTexture, | ||
const bool | clampP = true |
||
) | [static] |
Enable this colormap, as 1D texture or as colortable.
Cmap1D | If a valid pointer, set the colormap as 1D texture, otherwise as a colortable. |
clampP | clamp values, not repeating |
RefPtr< GLTexture1D > Wizt::GLColormap::Enable | ( | const RefPtr< Colormap > & | Cmap, |
TextureCreator & | CmapTC, | ||
int | TextureUnit, | ||
const bool | clampP = true |
||
) | [static] |
Activate a 1D texture from the virtual color values and put these into the specified texture creator.
CmapTC | The Texture creator, as retrieved from an OpenGL Cache |
TextureUnit | The Texture unit (OpenGL ActiveTexture) which is to be used for this texture. |
clampP | clamp values, not repeating |