Open Inventor Reference
|
00001 /* 00002 * 00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * Further, this software is distributed without any warranty that it is 00016 * free of the rightful claim of any third person regarding infringement 00017 * or the like. Any license provided herein, whether implied or 00018 * otherwise, applies only to this software file. Patent licenses, if 00019 * any, provided herein do not apply to combinations of this program with 00020 * other software, or any other product whatsoever. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 * 00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 00027 * Mountain View, CA 94043, or: 00028 * 00029 * http://www.sgi.com 00030 * 00031 * For further information regarding this notice, see: 00032 * 00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ 00034 * 00035 */ 00036 00037 00038 00039 /* 00040 * Copyright (C) 1995-96 Silicon Graphics, Inc. 00041 * 00042 _______________________________________________________________________ 00043 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00044 | 00045 | $Revision: 1.1.1.1 $ 00046 | 00047 | Description: 00048 | This file defines the SoVertexProperty node class, and the 00049 | SoVertexPropertyCache class. 00050 | 00051 | Author(s) : Alan Norton, Gavin Bell 00052 | 00053 ______________ S I L I C O N G R A P H I C S I N C . ____________ 00054 _______________________________________________________________________ 00055 */ 00056 00057 #ifndef _SO_VERTEX_PROPERTY 00058 #define _SO_VERTEX_PROPERTY 00059 00060 #include <Inventor/fields/SoMFUInt32.h> 00061 #include <Inventor/fields/SoMFVec3f.h> 00062 #include <Inventor/fields/SoMFVec2f.h> 00063 #include <Inventor/nodes/SoSubNode.h> 00064 #include <Inventor/nodes/SoNormalBinding.h> 00065 #include <Inventor/nodes/SoMaterialBinding.h> 00066 #include <Inventor/nodes/SoTextureCoordinateBinding.h> 00067 00068 00069 class SoVertexPropertyCache; 00070 class SoVBO; 00071 00074 00192 00193 00194 class INVENTOR_API SoVertexProperty : public SoNode { 00195 00196 SO_NODE_HEADER(SoVertexProperty); 00197 00198 public: 00199 00201 SoMFVec3f vertex; 00202 SoMFVec2f texCoord; 00203 SoMFVec3f normal; 00204 SoSFEnum normalBinding; 00205 SoMFUInt32 orderedRGBA; 00206 SoSFEnum materialBinding; 00207 00208 enum Binding { 00209 OVERALL = SoMaterialBindingElement::OVERALL, 00210 PER_PART = SoMaterialBindingElement::PER_PART, 00211 PER_PART_INDEXED = SoMaterialBindingElement::PER_PART_INDEXED, 00212 PER_FACE = SoMaterialBindingElement::PER_FACE, 00213 PER_FACE_INDEXED = SoMaterialBindingElement::PER_FACE_INDEXED, 00214 PER_VERTEX = SoMaterialBindingElement::PER_VERTEX, 00215 PER_VERTEX_INDEXED = SoMaterialBindingElement::PER_VERTEX_INDEXED 00216 }; 00217 00224 SoVertexProperty(); 00225 00226 SoEXTENDER public: 00227 virtual void doAction(SoAction *action); 00228 virtual void GLRender(SoGLRenderAction *action); 00229 virtual void getBoundingBox(SoGetBoundingBoxAction *action); 00230 virtual void callback(SoCallbackAction *action); 00231 virtual void pick(SoPickAction *action); 00232 00233 SoINTERNAL public: 00235 void putVBOsIntoState(SoState* state); 00236 00237 static void initClass(); 00238 00239 protected: 00240 virtual ~SoVertexProperty(); 00241 00242 SoVBO* _vertexVBO; 00243 SoVBO* _colorVBO; 00244 SoVBO* _normalVBO; 00245 SoVBO* _texCoordVBO; 00246 00247 }; 00248 00259 00260 #include <Inventor/elements/SoShapeStyleElement.h> 00261 00262 typedef WINGDIAPI void APIENTRY SoVPCacheFunc(const char *const); 00263 00264 SoEXTENDER class INVENTOR_API SoVertexPropertyCache { 00265 public: 00266 00268 00269 SbBool mightNeedSomethingFromState(const SoShapeStyleElement *sse) const 00270 { return needFromState & sse->getRenderCaseMask(); } 00271 00272 void fillInColorAndTranspAvail(const SoVertexProperty *, SoState *state); 00273 void fillInCache(const SoVertexProperty *, SoState *); 00274 00275 SbBool shouldGenerateNormals(const SoShapeStyleElement *sse) const 00276 { return (generateNormals && sse->needNormals()); } 00277 00278 SbBool shouldGenerateTexCoords(const SoShapeStyleElement *sse) const 00279 { return (generateTexCoords && sse->needTexCoords()); } 00280 00281 int getRenderCase(const SoShapeStyleElement *sse) const 00282 { return renderCase & sse->getRenderCaseMask(); } 00283 00284 SbBool haveTexCoordsInVP() 00285 { return needFromState & TEXTURE_FUNCTION_BIT; } 00286 00287 void sendVertex(const char *vp) const 00288 { (*vertexFunc)(vp); } 00289 void sendNormal(const char *np) const 00290 { (*normalFunc)(np); } 00291 void sendColor(const char *cp) const 00292 { (*colorFunc)(cp); } 00293 void sendTexCoord(const char *tcp) const 00294 { (*texCoordFunc)(tcp); } 00295 00296 int getNumVertices() const { return numVerts; } 00297 int getNumNormals() const { return numNorms; } 00298 int getNumColors() const { return numColors; } 00299 int getNumTexCoords() const { return numTexCoords; } 00300 00301 const char *getVertices(int i) const 00302 { return vertexPtr + vertexStride*i; } 00303 const char *getNormals(int i) const 00304 { return normalPtr + normalStride*i; } 00305 const char *getColors(int i) const 00306 { return colorPtr + colorStride*i; } 00307 const char *getTexCoords(int i) const 00308 { return texCoordPtr + texCoordStride*i; } 00309 00310 SbBool colorIsInVtxProp() const {return colorIsInVP;} 00311 00313 SbBool transpIsInVtxProp() const {return transpIsInVP;} 00314 00315 int getVertexStride() const { return vertexStride; } 00316 int getNormalStride() const { return normalStride; } 00317 int getColorStride() const { return colorStride; } 00318 int getTexCoordStride() const { return texCoordStride; } 00319 00320 SoNormalBindingElement::Binding getNormalBinding() 00321 { return (SoNormalBindingElement::Binding)normalBinding; } 00322 00323 SoMaterialBindingElement::Binding getMaterialBinding() 00324 { return (SoMaterialBindingElement::Binding)materialBinding; } 00325 00326 SoTextureCoordinateBindingElement::Binding getTexCoordBinding() 00327 { return (SoTextureCoordinateBindingElement::Binding)texCoordBinding; } 00328 00329 void invalidate() { needFromState = ALL_FROM_STATE_BITS; } 00330 00332 SoVertexPropertyCache(); 00333 00334 public: 00335 00337 SoVPCacheFunc *vertexFunc; 00338 const char *vertexPtr; 00339 int vertexStride, numVerts; 00340 SoVPCacheFunc *normalFunc; 00341 const char *normalPtr; 00342 int normalStride, numNorms; 00343 SoVPCacheFunc *colorFunc; 00344 const char *colorPtr; 00345 int colorStride, numColors; 00346 SoVPCacheFunc *texCoordFunc; 00347 const char *texCoordPtr; 00348 int texCoordStride, numTexCoords; 00349 00350 SbBool generateNormals; 00351 SbBool generateTexCoords; 00352 00353 unsigned char needFromState; 00354 00368 SoINTERNAL public: 00369 enum { 00370 COLOR_BITS = 0x18, 00371 PART_COLOR = 0x8, 00372 FACE_COLOR = 0x10, 00373 VERTEX_COLOR = 0x18, 00374 00375 NORMAL_BITS = 0x6, 00376 PART_NORMAL = 0x2, 00377 FACE_NORMAL = 0x4, 00378 VERTEX_NORMAL = 0x6, 00379 00380 TEXCOORD_BIT = 0x1 00381 }; 00386 00387 enum { 00388 TEXTURE_FUNCTION_BIT = 0x80, 00389 OVERRIDE_FROM_STATE_BIT = 0x40, 00390 COORD_FROM_STATE_BIT = 0x20, 00391 COLOR_FROM_STATE_BITS = COLOR_BITS, 00392 NORMAL_FROM_STATE_BITS = NORMAL_BITS, 00393 TEXCOORD_FROM_STATE_BIT = TEXCOORD_BIT, 00394 ALL_FROM_STATE_BITS = 0xFF 00395 }; 00396 private: 00397 00412 unsigned char normalBinding; 00413 unsigned char materialBinding; 00414 unsigned char texCoordBinding; 00415 unsigned char renderCase; 00416 unsigned char colorIsInVP; 00417 unsigned char transpIsInVP; 00418 }; 00419 00420 #endif /* _SO_VERTEX_PROPERTY */ 00421