OSGGeoVectorProperty.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *               Copyright (C) 2000-2002 by the OpenSG Forum                 *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <cstdlib>
00044 #include <cstdio>
00045 
00046 #include "OSGConfig.h"
00047 
00048 #include "OSGGLEXT.h"
00049 #include "OSGWindow.h"
00050 #include "OSGGeoVectorProperty.h"
00051 #include "OSGDrawEnv.h"
00052 
00053 OSG_USING_NAMESPACE
00054 
00055 // Documentation for this class is emited in the
00056 // OSGGeoVectorPropertyBase.cpp file.
00057 // To modify it, please change the .fcd file (OSGGeoVectorProperty.fcd) and
00058 // regenerate the base file.
00059 
00102 /***************************************************************************\
00103  *                           Class variables                               *
00104 \***************************************************************************/
00105 
00106 // extension indices for used extensions;
00107 UInt32 GeoVectorProperty::_extSecondaryColor;
00108 UInt32 GeoVectorProperty::_extMultitexture;
00109 
00110 // extension indices for used fucntions;
00111 UInt32 GeoVectorProperty::_funcglSecondaryColorPointer;
00112 UInt32 GeoVectorProperty::_funcglClientActiveTextureARB;
00113 
00114 /***************************************************************************\
00115  *                           Class methods                                 *
00116 \***************************************************************************/
00117 
00118 void GeoVectorProperty::initMethod(InitPhase ePhase)
00119 {
00120     Inherited::initMethod(ePhase);
00121 }
00122 
00123 /*------------------------- Chunk Class Access ---------------------------*/
00124 
00125 const StateChunkClass *GeoVectorProperty::getClass(void) const
00126 {
00127     return GeoProperty::getClass();
00128 }
00129 
00130 
00131 /***************************************************************************\
00132  *                           Instance methods                              *
00133 \***************************************************************************/
00134 
00135 /*-------------------------------------------------------------------------*\
00136  -  private                                                                 -
00137 \*-------------------------------------------------------------------------*/
00138 
00139 /*----------------------- constructors & destructors ----------------------*/
00140 
00141 GeoVectorProperty::GeoVectorProperty(void) :
00142     Inherited()
00143 {
00144     _extSecondaryColor      =
00145         Window::registerExtension("GL_EXT_secondary_color");
00146 
00147     _funcglSecondaryColorPointer  = Window::registerFunction(
00148                             OSG_DLSYM_UNDERSCORE"glSecondaryColorPointerEXT",
00149                             _extSecondaryColor);
00150 
00151     _extMultitexture        =
00152         Window::registerExtension("GL_ARB_multitexture");
00153     _funcglClientActiveTextureARB = Window::registerFunction(
00154                             OSG_DLSYM_UNDERSCORE"glClientActiveTextureARB",
00155                             _extMultitexture);
00156  }
00157 
00158 GeoVectorProperty::GeoVectorProperty(const GeoVectorProperty &source) :
00159     Inherited(source)
00160 {
00161 }
00162 
00163 GeoVectorProperty::~GeoVectorProperty(void)
00164 {
00165 }
00166 
00167 /*-------------------- Arbitrary Type Interface Methods ------------------*/
00168 
00180 void GeoVectorProperty::getValue(      Vec3f  &val,
00181                                  const UInt32  index) const
00182 {
00183     MaxTypeT ival;
00184     getValue(ival, index);
00185     GeoConvert::convertOut(val, ival, 1, 0);
00186 }
00187 
00198 void GeoVectorProperty::setValue(const Vec3f  &val,
00199                                  const UInt32  index )
00200 {
00201     MaxTypeT ival;
00202     GeoConvert::convertIn(ival, val, 1, 0);
00203     setValue(ival, index);
00204 }
00205 
00206 
00209 GLenum GeoVectorProperty::getBufferType(void)
00210 {
00211 #ifndef OSG_WINCE
00212     return GL_ARRAY_BUFFER_ARB;
00213 #else
00214     return GL_NONE;
00215 #endif
00216 }
00217 
00218 void GeoVectorProperty::activate(DrawEnv *pEnv, UInt32 slot)
00219 {
00220 #ifndef OSG_WINCE
00221     Window *win = pEnv->getWindow();
00222     bool isGeneric = (slot >= 16);  // !!!HACK. needs to be replaced for 2.0
00223     slot &= 15;
00224 
00225     if(win->hasExtension(_extVertexBufferObject) &&
00226        isGeneric)
00227     {
00228         void (OSG_APIENTRY*_glVertexAttribPointerARB)
00229             (GLuint index, GLint size, GLenum type, GLboolean normalized,
00230              GLsizei stride, const GLvoid *pointer)=
00231         (void (OSG_APIENTRY*) (GLuint index, GLint size, GLenum type,
00232              GLboolean normalized, GLsizei stride, const GLvoid *pointer))
00233             win->getFunction(_funcglVertexAttribPointerARB);
00234 
00235         if(getGLId() != 0 && getUseVBO()) // Do we have a VBO?
00236         {
00237             win->validateGLObject(getGLId(), pEnv);
00238 
00239              // get "glBindBufferARB" function pointer
00240             void (OSG_APIENTRY*_glBindBufferARB)
00241                 (GLenum target, GLuint buffer) =
00242                 (void (OSG_APIENTRY*)(GLenum target, GLuint buffer))
00243                 pEnv->getWindow()->getFunction(_funcBindBuffer);
00244 
00245             _glBindBufferARB(GL_ARRAY_BUFFER_ARB,
00246                              win->getGLObjectId(getGLId()));
00247 
00248             _glVertexAttribPointerARB(slot, getDimension(),
00249                 getFormat(),
00250                 getNormalize(),
00251                 getStride(), 0);
00252 
00253             _glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
00254         }
00255         else
00256         {
00257             _glVertexAttribPointerARB(slot, getDimension(),
00258                 getFormat(), getNormalize(),
00259                 getStride(), getData());
00260         }
00261 
00262         void (OSG_APIENTRY*_glEnableVertexAttribArrayARB)
00263             (GLuint index)=
00264         (void (OSG_APIENTRY*) (GLuint index))
00265             win->getFunction(_funcglEnableVertexAttribArrayARB);
00266 
00267         _glEnableVertexAttribArrayARB(slot);
00268     }
00269     else
00270     {
00271         switch(slot)
00272         {
00273         case 0:     glVertexPointer(getDimension(), getFormat(),
00274                         getStride(), getData());
00275                     glEnableClientState(GL_VERTEX_ARRAY);
00276                     break;
00277         case 2:     glNormalPointer(getFormat(),
00278                         getStride(), getData());
00279                     glEnableClientState(GL_NORMAL_ARRAY);
00280                     break;
00281         case 3:     glColorPointer(getDimension(), getFormat(),
00282                         getStride(), getData());
00283                     glEnableClientState(GL_COLOR_ARRAY);
00284                     break;
00285         case 4:     if (win->hasExtension(_extSecondaryColor))
00286                     {
00287                          void (OSG_APIENTRY*_glSecondaryColorPointerEXT)
00288                               (GLint size,GLenum type,GLsizei stride,
00289                                const GLvoid *pointer)=
00290                         (void (OSG_APIENTRY*)(GLint size,GLenum type,GLsizei stride,
00291                                const GLvoid *pointer))
00292                          win->getFunction(_funcglSecondaryColorPointer);
00293 
00294                         _glSecondaryColorPointerEXT(getDimension(),
00295                                                     getFormat(),
00296                                                     getStride(), getData());
00297                         glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
00298                     }
00299                     else
00300                     {
00301                         FWARNING(("GeoVectorProperty::activate: Window "
00302                                     "has no Secondary Color extension\n"));
00303                     }
00304                     break;
00305         case 8:  case 9:
00306         case 10: case 11:
00307         case 12: case 13:
00308         case 14: case 15:
00309                     {
00310                     void (OSG_APIENTRY*_glClientActiveTextureARB)
00311                         (GLenum type)= (void (OSG_APIENTRY*) (GLenum type))
00312                         win->getFunction(_funcglClientActiveTextureARB);
00313 
00314                     _glClientActiveTextureARB(GL_TEXTURE0_ARB + slot - 8);
00315                     glTexCoordPointer(getDimension(), getFormat(),
00316                                       getStride(), getData());
00317                     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00318                     }
00319                     break;
00320         default:    FWARNING(("GeoVectorProperty::activate: Non-Generic"
00321                         " attribute nr. %d unknown!\n", slot));
00322                     break;
00323         }
00324 
00325     }
00326 #endif
00327 }
00328 
00329 void GeoVectorProperty::changeFrom(DrawEnv    *pEnv,
00330                                    StateChunk *old,
00331                                    UInt32      slot)
00332 {
00333     // change from me to me?
00334     // this assumes I haven't changed in the meantime.
00335     if(old == this)
00336         return;
00337 
00338     // The activation will overwrite the previous activation fully,
00339     // so no need to deactivate
00340 
00341     activate(pEnv, slot);
00342 }
00343 
00344 void GeoVectorProperty::deactivate(DrawEnv *pEnv, UInt32 slot)
00345 {
00346 #ifndef OSG_WINCE
00347     Window *win = pEnv->getWindow();
00348     bool isGeneric = (slot >= 16);  // !!!HACK. needs to be replaced for 2.0
00349     slot &= 15;
00350 
00351     if(win->hasExtension(_extVertexBufferObject) &&
00352        isGeneric)
00353     {
00354         void (OSG_APIENTRY*_glDisableVertexAttribArrayARB)
00355             (GLuint index)=
00356         (void (OSG_APIENTRY*) (GLuint index))
00357             win->getFunction(_funcglDisableVertexAttribArrayARB);
00358 
00359         _glDisableVertexAttribArrayARB(slot);
00360     }
00361     else
00362     {
00363         switch(slot)
00364         {
00365         case 0:     glDisableClientState(GL_VERTEX_ARRAY);
00366                     break;
00367         case 2:     glDisableClientState(GL_NORMAL_ARRAY);
00368                     break;
00369         case 3:     glDisableClientState(GL_COLOR_ARRAY);
00370                     break;
00371         case 4:     glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
00372                     break;
00373         case 8:  case 9:
00374         case 10: case 11:
00375         case 12: case 13:
00376         case 14: case 15:
00377                     {
00378                     void (OSG_APIENTRY*_glClientActiveTextureARB)
00379                         (GLenum type)= (void (OSG_APIENTRY*) (GLenum type))
00380                         win->getFunction(_funcglClientActiveTextureARB);
00381                     _glClientActiveTextureARB(GL_TEXTURE0_ARB + slot - 8);
00382                     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
00383                     }
00384                     break;
00385         default:    FWARNING(("GeoVectorProperty::deactivate: Non-Generic"
00386                         " attribute nr. %d unknown!\n", slot));
00387                     break;
00388         }
00389     }
00390 #endif
00391 }
00392 
00393 /*----------------------------- class specific ----------------------------*/
00394 
00395 void GeoVectorProperty::changed(ConstFieldMaskArg whichField, 
00396                                 UInt32            origin,
00397                                 BitVector         details)
00398 {
00399     Inherited::changed(whichField, origin, details);
00400 }
00401 
00402 void GeoVectorProperty::dump(      UInt32    ,
00403                              const BitVector ) const
00404 {
00405     SLOG << "Dump GeoVectorProperty NI" << std::endl;
00406 }