# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

landscapevb_info.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/landscapevb_info.h"
00029 #include "3d/vertex_buffer.h"
00030 #include "3d/vertex_buffer_hard.h"
00031 #include "3d/landscapevb_allocator.h"
00032 
00033 
00034 namespace NL3D 
00035 {
00036 
00037 
00038 // ***************************************************************************
00039 // ***************************************************************************
00040 // VertexBufferInfo.
00041 // ***************************************************************************
00042 // ***************************************************************************
00043 
00044 
00045 // ***************************************************************************
00046 void            CFarVertexBufferInfo::setupNullPointers()
00047 {
00048         VertexCoordPointer= NULL;
00049         TexCoordPointer0= NULL;
00050         TexCoordPointer1= NULL;
00051         ColorPointer= NULL;
00052         GeomInfoPointer= NULL;
00053         DeltaPosPointer= NULL;
00054         AlphaInfoPointer= NULL;
00055 }
00056 
00057 
00058 // ***************************************************************************
00059 void            CFarVertexBufferInfo::setupPointersForVertexProgram()
00060 {
00061         // see CLandscapeVBAllocator for program definition.
00062         uint8   *vcoord= (uint8*)VertexCoordPointer;
00063 
00064         TexCoordPointer0= vcoord + TexCoordOff0;
00065         TexCoordPointer1= vcoord + TexCoordOff1;
00066         GeomInfoPointer= vcoord + GeomInfoOff;                  
00067         DeltaPosPointer= vcoord + DeltaPosOff;
00068         AlphaInfoPointer= vcoord + AlphaInfoOff;
00069 }
00070 
00071 
00072 // ***************************************************************************
00073 void            CFarVertexBufferInfo::setupVertexBuffer(CVertexBuffer &vb, bool forVertexProgram)
00074 {
00075         VertexFormat= vb.getVertexFormat();
00076         VertexSize= vb.getVertexSize();
00077         NumVertices= vb.getNumVertices();
00078 
00079         if(NumVertices==0)
00080         {
00081                 setupNullPointers();
00082                 return;
00083         }
00084 
00085         VertexCoordPointer= vb.getVertexCoordPointer();
00086 
00087         if(forVertexProgram)
00088         {
00089                 // With VertexCoordPointer setuped, init for VP.
00090                 TexCoordOff0= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX0);                              // v[8]= Tex0.
00091                 TexCoordOff1= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX1);                              // v[9]= Tex1.
00092                 GeomInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_GEOMINFO);                   // v[10]= GeomInfos.
00093                 DeltaPosOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_DELTAPOS);                   // v[11]= EndPos-StartPos
00094                 // Init Alpha Infos only if enabled (enabled if Value 5 are).
00095                 AlphaInfoOff= 0;
00096                 if( vb.getVertexFormat() & (1<<NL3D_LANDSCAPE_VPPOS_ALPHAINFO) )
00097                         AlphaInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_ALPHAINFO);         // v[12]= AlphaInfos
00098 
00099                 // update Ptrs.
00100                 setupPointersForVertexProgram();
00101         }
00102         else
00103         {
00104                 TexCoordOff0= vb.getTexCoordOff(0);
00105                 TexCoordOff1= vb.getTexCoordOff(1);
00106                 TexCoordPointer0= vb.getTexCoordPointer(0, 0);
00107                 TexCoordPointer1= vb.getTexCoordPointer(0, 1);
00108 
00109                 // In Far0, we don't have Color component.
00110                 if(VertexFormat & CVertexBuffer::PrimaryColorFlag)
00111                 {
00112                         ColorOff= vb.getColorOff();
00113                         ColorPointer= vb.getColorPointer();
00114                 }
00115                 else
00116                 {
00117                         ColorOff= 0;
00118                         ColorPointer= NULL;
00119                 }
00120         }
00121 
00122 }
00123 // ***************************************************************************
00124 void            CFarVertexBufferInfo::setupVertexBufferHard(IVertexBufferHard &vb, void *vcoord, bool forVertexProgram)
00125 {
00126         VertexFormat= vb.getVertexFormat();
00127         VertexSize= vb.getVertexSize();
00128         NumVertices= vb.getNumVertices();
00129 
00130         if(NumVertices==0)
00131         {
00132                 setupNullPointers();
00133                 return;
00134         }
00135 
00136         VertexCoordPointer= vcoord;
00137 
00138         if(forVertexProgram)
00139         {
00140                 // With VertexCoordPointer setuped, init for VP.
00141                 TexCoordOff0= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_TEX0);                                // v[8]= Tex0.
00142                 TexCoordOff1= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_TEX1);                                // v[9]= Tex1.
00143                 GeomInfoOff= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_GEOMINFO);                             // v[10]= GeomInfos.
00144                 DeltaPosOff= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_DELTAPOS);                             // v[11]= EndPos-StartPos
00145                 // Init Alpha Infos only if enabled (enabled if Value 5 are).
00146                 AlphaInfoOff= 0;
00147                 if( vb.getVertexFormat() & (1<<NL3D_LANDSCAPE_VPPOS_ALPHAINFO) )
00148                         AlphaInfoOff= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_ALPHAINFO);           // v[12]= AlphaInfos
00149 
00150                 // update Ptrs.
00151                 setupPointersForVertexProgram();
00152         }
00153         else
00154         {
00155                 TexCoordOff0= vb.getValueOff (CVertexBuffer::TexCoord0);
00156                 TexCoordOff1= vb.getValueOff (CVertexBuffer::TexCoord1);
00157                 TexCoordPointer0= (uint8*)vcoord + TexCoordOff0;
00158                 TexCoordPointer1= (uint8*)vcoord + TexCoordOff1;
00159 
00160                 // In Far0, we don't have Color component.
00161                 if(VertexFormat & CVertexBuffer::PrimaryColorFlag)
00162                 {
00163                         ColorOff= vb.getValueOff (CVertexBuffer::PrimaryColor);
00164                         ColorPointer= (uint8*)vcoord + ColorOff;
00165                 }
00166                 else
00167                 {
00168                         ColorOff= 0;
00169                         ColorPointer= NULL;
00170                 }
00171         }
00172 }
00173 
00174 
00175 // ***************************************************************************
00176 void            CNearVertexBufferInfo::setupNullPointers()
00177 {
00178         VertexCoordPointer= NULL;
00179         TexCoordPointer0= NULL;
00180         TexCoordPointer1= NULL;
00181         TexCoordPointer2= NULL;
00182         GeomInfoPointer= NULL;
00183         DeltaPosPointer= NULL;
00184 }
00185 
00186 
00187 // ***************************************************************************
00188 void            CNearVertexBufferInfo::setupPointersForVertexProgram()
00189 {
00190         // see CLandscapeVBAllocator for program definition.
00191         uint8   *vcoord= (uint8*)VertexCoordPointer;
00192 
00193         TexCoordPointer0= vcoord + TexCoordOff0;
00194         TexCoordPointer1= vcoord + TexCoordOff1;
00195         TexCoordPointer2= vcoord + TexCoordOff2;
00196         GeomInfoPointer= vcoord + GeomInfoOff;                  
00197         DeltaPosPointer= vcoord + DeltaPosOff;
00198 
00199 }
00200 
00201 
00202 // ***************************************************************************
00203 void            CNearVertexBufferInfo::setupVertexBuffer(CVertexBuffer &vb, bool forVertexProgram)
00204 {
00205         VertexFormat= vb.getVertexFormat();
00206         VertexSize= vb.getVertexSize();
00207         NumVertices= vb.getNumVertices();
00208 
00209         if(NumVertices==0)
00210         {
00211                 setupNullPointers();
00212                 return;
00213         }
00214 
00215         VertexCoordPointer= vb.getVertexCoordPointer();
00216 
00217         if(forVertexProgram)
00218         {
00219                 // With VertexCoordPointer setuped, init for VP.
00220                 TexCoordOff0= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX0);                              // v[8]= Tex0.
00221                 TexCoordOff1= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX1);                              // v[9]= Tex1.
00222                 TexCoordOff2= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_TEX2);                              // v[13]= Tex1.
00223                 GeomInfoOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_GEOMINFO);                   // v[10]= GeomInfos.
00224                 DeltaPosOff= vb.getValueOffEx(NL3D_LANDSCAPE_VPPOS_DELTAPOS);                   // v[11]= EndPos-StartPos
00225 
00226                 // update Ptrs.
00227                 setupPointersForVertexProgram();
00228         }
00229         else
00230         {
00231                 TexCoordPointer0= vb.getTexCoordPointer(0, 0);
00232                 TexCoordPointer1= vb.getTexCoordPointer(0, 1);
00233                 TexCoordPointer2= vb.getTexCoordPointer(0, 2);
00234 
00235                 TexCoordOff0= vb.getTexCoordOff(0);
00236                 TexCoordOff1= vb.getTexCoordOff(1);
00237                 TexCoordOff2= vb.getTexCoordOff(2);
00238         }
00239 }
00240 // ***************************************************************************
00241 void            CNearVertexBufferInfo::setupVertexBufferHard(IVertexBufferHard &vb, void *vcoord, bool forVertexProgram)
00242 {
00243         VertexFormat= vb.getVertexFormat();
00244         VertexSize= vb.getVertexSize();
00245         NumVertices= vb.getNumVertices();
00246 
00247         if(NumVertices==0)
00248         {
00249                 setupNullPointers();
00250                 return;
00251         }
00252 
00253         VertexCoordPointer= vcoord;
00254 
00255         if(forVertexProgram)
00256         {
00257                 // With VertexCoordPointer setuped, init for VP.
00258                 TexCoordOff0= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_TEX0);                                // v[8]= Tex0.
00259                 TexCoordOff1= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_TEX1);                                // v[9]= Tex1.
00260                 TexCoordOff2= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_TEX2);                                // v[9]= Tex1.
00261                 GeomInfoOff= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_GEOMINFO);                             // v[10]= GeomInfos.
00262                 DeltaPosOff= vb.getValueOff(NL3D_LANDSCAPE_VPPOS_DELTAPOS);                             // v[11]= EndPos-StartPos
00263 
00264                 // update Ptrs.
00265                 setupPointersForVertexProgram();
00266         }
00267         else
00268         {
00269                 TexCoordPointer0= (uint8*)vcoord + vb.getValueOff (CVertexBuffer::TexCoord0);
00270                 TexCoordPointer1= (uint8*)vcoord + vb.getValueOff (CVertexBuffer::TexCoord1);
00271                 TexCoordPointer2= (uint8*)vcoord + vb.getValueOff (CVertexBuffer::TexCoord2);
00272 
00273                 TexCoordOff0= vb.getValueOff (CVertexBuffer::TexCoord0);
00274                 TexCoordOff1= vb.getValueOff (CVertexBuffer::TexCoord1);
00275                 TexCoordOff2= vb.getValueOff (CVertexBuffer::TexCoord2);
00276         }
00277 }
00278 
00279 
00280 } // NL3D