Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoGLImage.h

00001 #ifndef COIN_SOGLIMAGE_H
00002 #define COIN_SOGLIMAGE_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) by Kongsberg Oil & Gas Technologies.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Kongsberg Oil & Gas Technologies
00018  *  about acquiring a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 // WARNING: This is work in progress. Do not expect this class to have
00028 // a stable interface over a long period of time. It is installed
00029 // because we need it in an internal project.
00030 
00031 // FIXME: make sure we do a design review for this class for Coin v3.0
00032 // pederb, 2001-11-28
00033 
00034 #include <Inventor/SbBasic.h>
00035 #include <Inventor/SbVec2s.h>
00036 #include <Inventor/SbVec3s.h>
00037 #include <Inventor/SoType.h>
00038 #include <stddef.h>
00039 
00040 class SoGLDisplayList;
00041 class SoState;
00042 class SbImage;
00043 
00044 class COIN_DLL_API SoGLImage {
00045 public:
00046 
00047   SoGLImage();
00048   virtual void unref(SoState * state = NULL);
00049 
00050   static SoType getClassTypeId(void);
00051   virtual SoType getTypeId(void) const ;
00052   virtual SbBool isOfType(SoType type) const;
00053 
00054   enum Wrap {
00055     REPEAT = 0,
00056     CLAMP,
00057     CLAMP_TO_EDGE,
00058     CLAMP_TO_BORDER
00059   };
00060 
00061   enum ResizeReason {
00062     IMAGE = 0,
00063     SUBIMAGE,
00064     MIPMAP
00065   };
00066 
00067   typedef SbBool SoGLImageResizeCB(SoState * state,
00068                                    const SbVec3s &newsize,
00069                                    unsigned char * destbuffer,
00070                                    ResizeReason reason,
00071                                    void * closure,
00072                                    class SoGLImage * image);
00073 
00074   void setGLDisplayList(SoGLDisplayList * dl,
00075                         SoState * state,
00076                         const Wrap wraps = REPEAT,
00077                         const Wrap wrapt = REPEAT,
00078                         const float quality = 0.5f);
00079 
00080   void setPBuffer(SoState * state,
00081                   void * context,
00082                   const Wrap wraps = REPEAT,
00083                   const Wrap wrapt = REPEAT,
00084                   const float quality = 0.5f);
00085 
00086   void setData(const unsigned char * bytes,
00087                const SbVec2s & size,
00088                const int numcomponents,
00089                const Wrap wraps = REPEAT,
00090                const Wrap wrapt = REPEAT,
00091                const float quality = 0.5f,
00092                const int border = 0,
00093                SoState * createinstate = NULL);
00094 
00095   void setData(const unsigned char * bytes,
00096                const SbVec3s & size,
00097                const int numcomponents,
00098                const Wrap wraps = REPEAT,
00099                const Wrap wrapt = REPEAT,
00100                const Wrap wrapr = REPEAT,
00101                const float quality = 0.5f,
00102                const int border = 0,
00103                SoState * createinstate = NULL);
00104 
00105   virtual void setData(const SbImage * image,
00106                        const Wrap wraps = REPEAT,
00107                        const Wrap wrapt = REPEAT,
00108                        const float quality = 0.5f,
00109                        const int border = 0,
00110                        SoState * createinstate = NULL);
00111 
00112   virtual void setData(const SbImage * image,
00113                        const Wrap wraps,
00114                        const Wrap wrapt,
00115                        const Wrap wrapr,
00116                        const float quality = 0.5f,
00117                        const int border = 0,
00118                        SoState * createinstate = NULL);
00119 
00120   // these flags can be used to set texture properties.
00121   enum Flags {
00122     // mipmap, scaling and filtering settings
00123     SCALE_DOWN =                0x0001,
00124     NO_MIPMAP =                 0x0002,
00125     LINEAR_MAG_FILTER =         0x0004,
00126     LINEAR_MIN_FILTER =         0x0008,
00127     LINEAR_MIPMAP_FILTER =      0x0010,
00128 
00129     // use if you know your image properties.
00130     FORCE_TRANSPARENCY_TRUE   = 0x0020,
00131     FORCE_TRANSPARENCY_FALSE  = 0x0040,
00132     FORCE_ALPHA_TEST_TRUE     = 0x0080,
00133     FORCE_ALPHA_TEST_FALSE    = 0x0100,
00134 
00135     INVINCIBLE                = 0x0200, // never die of old age
00136 
00137     // use GL_NV_texture_rectangle or GL_EXT_texture_rectangle
00138     RECTANGLE                 = 0x0400,
00139 
00140     // Compress texture if available from OpenGL
00141     COMPRESSED                = 0x0800,
00142 
00143     // use quality value to decide mipmap, filtering and scaling. This
00144     // is the default.
00145     USE_QUALITY_VALUE         = 0X8000
00146   };
00147 
00148   void setFlags(const uint32_t flags);
00149   uint32_t getFlags(void) const;
00150 
00151   const SbImage * getImage(void) const;
00152 
00153   virtual SoGLDisplayList * getGLDisplayList(SoState * state);
00154   SbBool hasTransparency(void) const;
00155   SbBool useAlphaTest(void) const;
00156   Wrap getWrapS(void) const;
00157   Wrap getWrapT(void) const;
00158   Wrap getWrapR(void) const;
00159 
00160   float getQuality(void) const;
00161   uint32_t getGLImageId(void) const;
00162 
00163 protected:
00164 
00165   void incAge(void) const;
00166   void resetAge(void) const;
00167   virtual void unrefOldDL(SoState * state, const uint32_t maxage);
00168   virtual ~SoGLImage();
00169 
00170 private:
00171 
00172   class SoGLImageP * pimpl;
00173   friend class SoGLImageP;
00174   static void cleanupClass(void);
00175 
00176 public:
00177   // internal methods for texture resource management
00178   static void beginFrame(SoState * state);
00179   static void tagImage(SoState * state, SoGLImage * image);
00180   static void endFrame(SoState * state);
00181   static void setDisplayListMaxAge(const uint32_t maxage);
00182   static void freeAllImages(SoState * state = NULL);
00183 
00184   void setEndFrameCallback(void (*cb)(void *), void * closure);
00185   int getNumFramesSinceUsed(void) const;
00186 
00187 public:
00188   static void initClass(void);
00189   static void setResizeCallback(SoGLImageResizeCB * f, void * closure);
00190 
00191 private:
00192   static void registerImage(SoGLImage * image);
00193   static void unregisterImage(SoGLImage * image);
00194 };
00195 
00196 #endif // !COIN_SOGLIMAGE_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Sun May 1 2011 02:58:21 for Coin by Doxygen 1.7.3.