00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047
00048 #include "OSGDVRSimpleShader.h"
00049
00050 #include "OSGDVRVolumeTexture.h"
00051 #include "OSGDVRVolume.h"
00052
00053 OSG_USING_NAMESPACE
00054
00060
00061
00063 DVRSimpleShader::DVRSimpleShader(void) :
00064 Inherited ( ),
00065 m_nTextureId(-1)
00066 {
00067 }
00068
00070 DVRSimpleShader::DVRSimpleShader(const DVRSimpleShader &source) :
00071 Inherited (source),
00072 m_nTextureId( -1)
00073 {
00074 }
00075
00077 DVRSimpleShader::~DVRSimpleShader(void)
00078 {
00079 }
00080
00081
00082
00084 void DVRSimpleShader::initMethod(void)
00085 {
00086 }
00087
00089 void DVRSimpleShader::changed(BitVector whichField, UInt32 origin)
00090 {
00091 Inherited::changed(whichField, origin);
00092 }
00093
00095 void DVRSimpleShader::dump( UInt32 ,
00096 const BitVector ) const
00097 {
00098 SLOG << "Dump DVRSimpleShader NI" << std::endl;
00099 }
00100
00101
00103 bool DVRSimpleShader::initialize(DVRVolume *volume,
00104 DrawActionBase * )
00105 {
00106 FDEBUG(("DVRSimpleShader::initialize\n"));
00107
00108 m_nTextureId = -1;
00109
00110 DVRVolumeTexturePtr vol = DVRVOLUME_PARAMETER(volume, DVRVolumeTexture);
00111
00112 ImagePtr img = vol->getImage();
00113
00114
00115
00116 static Int16 types[] = { Image::OSG_UINT8_IMAGEDATA,
00117 Image::OSG_UINT16_IMAGEDATA,
00118 Image::OSG_UINT32_IMAGEDATA,
00119 Image::OSG_FLOAT16_IMAGEDATA,
00120 Image::OSG_FLOAT32_IMAGEDATA,
00121 -1 };
00122
00123 UInt16 type = 0;
00124 while(types[type] != -1 && types[type] != img->getDataType()) type++;
00125
00126 if(!types[type])
00127 {
00128 FWARNING(("DVRSimpleShader::initialize: Image data type %d "
00129 "unknown!\n", img->getDataType()));
00130 type = 0;
00131 }
00132
00133 if(type > 2)
00134 {
00135 FWARNING(("DVRSimpleShader::initialize: Can't do float image types,"
00136 " treating as int.\n"));
00137 type = 0;
00138 }
00139
00140
00141
00142
00143 static Int16 formats[] = { Image::OSG_L_PF,
00144 Image::OSG_LA_PF,
00145 Image::OSG_RGBA_DXT1,
00146 Image::OSG_RGBA_DXT3,
00147 Image::OSG_RGBA_DXT5,
00148 Image::OSG_RGBA_PF,
00149 Image::OSG_RGB_DXT1,
00150 Image::OSG_RGB_PF,
00151 -1 };
00152
00153 UInt16 format = 0;
00154 while(formats[format] != -1 &&
00155 formats[format] != img->getPixelFormat()) format++;
00156
00157 if(!formats[format])
00158 {
00159 FWARNING(("DVRSimpleShader::initialize: Image pixel format %d "
00160 "unknown!\n", img->getPixelFormat()));
00161 format = 0;
00162 }
00163
00164 if(type > 5)
00165 {
00166 FNOTICE(("DVRSimpleShader::initialize: Image pixel format doesn't "
00167 "have alpha! Volume will not be transparent!\n"));
00168 }
00169
00170
00171
00172 static GLenum intfs[8][3] = {
00173 { GL_INTENSITY, GL_INTENSITY16, GL_INTENSITY16 },
00174 { GL_LUMINANCE_ALPHA, GL_LUMINANCE16_ALPHA16, GL_LUMINANCE16_ALPHA16 },
00175 { GL_RGBA, GL_RGBA, GL_RGBA },
00176 { GL_RGBA, GL_RGBA, GL_RGBA },
00177 { GL_RGBA, GL_RGBA, GL_RGBA },
00178 { GL_RGBA, GL_RGBA16, GL_RGBA16 },
00179 { GL_RGB, GL_RGB, GL_RGB },
00180 { GL_RGB, GL_RGB16, GL_RGB16 }
00181 };
00182
00183
00184 m_nTextureId = volume->getTextureManager().registerTexture(
00185 vol->getImage(),
00186 intfs[format][type],
00187 GL_NONE,
00188 1,
00189 0,
00190 -1);
00191
00192 if(m_nTextureId == -1)
00193 {
00194 SWARNING << "Error registering textures ..." << std::endl;
00195 return false;
00196 }
00197
00198 return true;
00199 }
00200
00201
00203 void DVRSimpleShader::activate(DVRVolume *volume, DrawActionBase * )
00204 {
00205
00206
00207 glPushAttrib(GL_ENABLE_BIT |
00208 GL_COLOR_BUFFER_BIT |
00209 GL_STENCIL_BUFFER_BIT |
00210 GL_DEPTH_BUFFER_BIT |
00211 GL_POLYGON_BIT |
00212 GL_TEXTURE_BIT);
00213
00214 glDisable(GL_DITHER);
00215 glDisable(GL_LIGHTING);
00216
00217 glColor4f(1.0,1.0,1.0,1.0);
00218
00219 if(volume->getDoTextures())
00220 {
00221
00222
00223 glEnable(GL_BLEND);
00224 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00225
00226 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00227 }
00228 }
00229
00231 void DVRSimpleShader::brickActivate(DVRVolume * ,
00232 DrawActionBase * ,
00233 Brick * )
00234 {
00235
00236 }
00237
00239 void DVRSimpleShader::deactivate(DVRVolume * ,
00240 DrawActionBase * )
00241 {
00242 FDEBUG(("DVRSimpleShader::deactivate\n"));
00243
00244 glPopAttrib();
00245 }
00246
00248 void DVRSimpleShader::cleanup(DVRVolume *volume, DrawActionBase * )
00249 {
00250 if (volume != NULL)
00251 {
00252 if (m_nTextureId != -1)
00253 volume->getTextureManager().unregisterTexture(m_nTextureId);
00254 }
00255 }
00256
00257
00258
00259
00260
00261 #ifdef __sgi
00262 #pragma set woff 1174
00263 #endif
00264
00265 #ifdef OSG_LINUX_ICC
00266 #pragma warning( disable : 177 )
00267 #endif
00268
00269 namespace
00270 {
00271 static char cvsid_cpp[] = "@(#)$Id: $";
00272 static char cvsid_hpp[] = OSGDVRSIMPLESHADER_HEADER_CVSID;
00273 static char cvsid_inl[] = OSGDVRSIMPLESHADER_INLINE_CVSID;
00274 }