[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[580] | 2 | |
---|
[2870] | 3 | #include <GL/glew.h> |
---|
| 4 | #include <Cg/cgGL.h> |
---|
| 5 | |
---|
[580] | 6 | #include "NvZincBlendeVolumeShader.h" |
---|
| 7 | |
---|
| 8 | NvZincBlendeVolumeShader::NvZincBlendeVolumeShader() |
---|
| 9 | { |
---|
| 10 | init(); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | NvZincBlendeVolumeShader::~NvZincBlendeVolumeShader() |
---|
| 14 | { |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | void NvZincBlendeVolumeShader::init() |
---|
| 18 | { |
---|
[2870] | 19 | loadFragmentProgram("zincblende_volume.cg", "main"); |
---|
[2919] | 20 | _tfParam = getNamedParameterFromFP("tf"); |
---|
| 21 | _volumeAParam = getNamedParameterFromFP("volumeA"); |
---|
| 22 | _volumeBParam = getNamedParameterFromFP("volumeB"); |
---|
| 23 | _cellSizeParam = getNamedParameterFromFP("cellSize"); |
---|
| 24 | _mviParam = getNamedParameterFromFP("modelViewInv"); |
---|
| 25 | _renderParam = getNamedParameterFromFP("renderParameters"); |
---|
| 26 | _optionOneVolumeParam = getNamedParameterFromFP("options"); |
---|
[580] | 27 | } |
---|
| 28 | |
---|
[2859] | 29 | void NvZincBlendeVolumeShader::bind(unsigned int tfID, Volume *volume, int sliceMode) |
---|
| 30 | { |
---|
| 31 | ZincBlendeVolume *vol = (ZincBlendeVolume *)volume; |
---|
[2919] | 32 | cgGLSetStateMatrixParameter(_mviParam, CG_GL_MODELVIEW_MATRIX, |
---|
| 33 | CG_GL_MATRIX_INVERSE); |
---|
[2859] | 34 | cgGLSetTextureParameter(_tfParam, tfID); |
---|
| 35 | cgGLSetParameter4f(_cellSizeParam, |
---|
[2877] | 36 | vol->cellSize.x, |
---|
| 37 | vol->cellSize.y, |
---|
| 38 | vol->cellSize.z, 0.); |
---|
[2859] | 39 | |
---|
| 40 | if (!sliceMode) { |
---|
| 41 | cgGLSetParameter4f(_renderParam, |
---|
[2877] | 42 | vol->numSlices(), |
---|
| 43 | vol->opacityScale(), |
---|
[2859] | 44 | vol->diffuse(), |
---|
| 45 | vol->specular()); |
---|
| 46 | } else { |
---|
| 47 | cgGLSetParameter4f(_renderParam, |
---|
| 48 | 0., |
---|
[2877] | 49 | vol->opacityScale(), |
---|
[2859] | 50 | vol->diffuse(), |
---|
| 51 | vol->specular()); |
---|
| 52 | } |
---|
| 53 | |
---|
[2877] | 54 | cgGLSetParameter4f(_optionOneVolumeParam, |
---|
[2859] | 55 | 0.0f, |
---|
| 56 | volume->isosurface(), |
---|
| 57 | 0.0f, |
---|
| 58 | 0.0f); |
---|
| 59 | |
---|
[2877] | 60 | cgGLSetTextureParameter(_volumeAParam, vol->zincblendeTex[0]->id()); |
---|
| 61 | cgGLSetTextureParameter(_volumeBParam, vol->zincblendeTex[1]->id()); |
---|
[2859] | 62 | cgGLEnableTextureParameter(_volumeAParam); |
---|
| 63 | cgGLEnableTextureParameter(_volumeBParam); |
---|
| 64 | |
---|
[2919] | 65 | NvShader::bind(); |
---|
[2859] | 66 | } |
---|
| 67 | |
---|
| 68 | void NvZincBlendeVolumeShader::unbind() |
---|
| 69 | { |
---|
| 70 | cgGLDisableTextureParameter(_volumeAParam); |
---|
| 71 | cgGLDisableTextureParameter(_volumeBParam); |
---|
| 72 | cgGLDisableTextureParameter(_tfParam); |
---|
| 73 | |
---|
[2919] | 74 | NvShader::unbind(); |
---|
[2859] | 75 | } |
---|