vee_gl_renderer.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00026 #ifndef _VEE_GL_RENDERER_H_
00027 #define _VEE_GL_RENDERER_H_
00028 
00029 #include <GL/gl.h>
00030 
00031 #ifdef __OS_LINUX__
00032 
00033 // NVidia fixes...
00034 #define GL_GLEXT_PROTOTYPES 1
00035 
00036 #ifndef GLAPI
00037 #define GLAPI 
00038 #endif
00039 
00040 #ifdef APIENTRY
00041 #undef APIENTRY
00042 #endif
00043 
00044 #include <GL/glext.h>
00045 
00046 #endif
00047 
00048 #include <vee_color.h>
00049 #include <vee_gl_material.h>
00050 #include <vee_gl_texture.h>
00051 #include <vee_render_class.h>
00052 #include <vee_renderer.h>
00053 #include <vee_scene.h>
00054 #include <vee_object.h>
00055 
00056 #include <Solar/GraphicTriangleMesh.hpp>
00057 
00058 
00059 #include <GL/glu.h>
00060 
00061 class VEE_Collector;
00062 class VEE_CurveParticle;
00063 class VEE_GlTexture2D;
00064 class VEE_GlTexture2DBank;
00065 class VEE_OrdererCollector;
00066 class VEE_TailParticle;
00067 class VEE_RigidParticle;
00068 class VEE_TCBSpline3;
00069 class VEE_VolumeGrid;
00070 class VEE_VolumeGrid2;
00071 
00072 class VEE_CameraPosition
00073 {
00074 public:
00075   VEE_CameraPosition() : m_azi(0.0), m_ele(0.0) 
00076   { m_camPos.clear(); }
00077   VEE_CameraPosition(const VEE_Vector3 &pos, float azi, float ele)
00078     : m_camPos(pos), m_azi(azi), m_ele(ele) {  }
00079 
00080   void describe(char * buf);
00081 
00082   VEE_Vector3 m_camPos;
00083   float       m_azi, m_ele;
00084 
00085 };
00086 
00093 class VEE_GlRenderer : public VEE_Renderer
00094 {
00095 public:
00096   enum Mode {
00097     RenderNothing ,
00098     RenderTriangles,
00099     RenderQuads,
00100     RenderPoints,
00101     RenderLines
00102   };
00103 
00104   enum Order {
00105     OrderRandom1,
00106     OrderRandom2,
00107     OrderBackToFront1,
00108     OrderBackToFront2,
00109     OrderSizeof
00110   };
00111 
00112   enum Material {
00113     POLYGON,
00114     CHECK,
00115     SWIRL,
00116     BLOW,
00117     MATERIALS
00118   };
00119 
00120   VEE_GlRenderer(VEE_SceneBox *box = 0);
00121   virtual ~VEE_GlRenderer();
00122   
00123   virtual void initRenderState();
00124   virtual void closeRenderState();
00125 
00126   virtual void renderParticle(VEE_Particle *);
00127   virtual void renderPolygon(VEE_Polygon *);
00128   virtual void renderForceObject(VEE_ForceObject *);
00129 
00130   virtual bool setValue(const char *, VEE_Value *);
00131 
00132   void setSceneBox(VEE_SceneBox *box) {m_vps = box;}
00133   VEE_SceneBox *sceneBox() { return m_vps; }
00134   
00135   virtual void initializeGL();
00136   virtual void resizeGL(int w, int h );
00137   virtual void prepareGlMode();
00138   virtual void endGlMode();
00139   
00140   virtual void paintGL(bool drawBoxEdges, bool moveCamera, bool clear, 
00141            float dt = 0.04);
00142 
00143   void drawRecursed(VEE_SceneBox *vps);
00144   void drawBackToFront(VEE_SceneBox *vps);
00145   void drawBackToFront2(VEE_OrdererCollector *);
00146   void drawRandom(VEE_Collector *);
00147 
00148   void clearGlScreen();
00149   void moveGlCamera();
00150 
00151   void setParticleSize(float size) { m_particleSize = size; }
00152   float particleSize() const { return m_particleSize; }
00153   
00154   float alphaMul() const { return m_alphaMul; }
00155   void  setAlphaMul(float a) { m_alphaMul = a; }
00156 
00157   VEE_RenderClass & defaultRenderClass() { return m_defaultRenderClass; }
00158 
00159   float lengthScale() const { return m_defaultRenderClass.lengthScale(); }
00160   void  setLengthScale(float scale) 
00161   { m_defaultRenderClass.setLengthScale(scale); }
00162 
00163   float maxLengthScale() const { return m_defaultRenderClass.maxLengthScale();}
00164 
00165   void setParticleMode(Mode m) { m_particleMode = m; }
00166   Mode setParticleMode() const { return m_particleMode; }
00167 
00168   void setPolygonMode(Mode m) { m_polygonMode = m; }
00169   Mode getPolygonMode() const { return m_polygonMode; }
00170 
00171   void setForceMode(Mode m) { m_forceMode = m; }
00172   Mode getForceMode() const { return m_forceMode; }
00173 
00174   VEE_Vector3 & camPos() { return m_camPos; }
00175   void setCameraPosition(const VEE_Vector3 &pos) { m_camPos = pos;}
00176   void setCameraPosition3f(float x, float y, float z) { m_camPos.make(x,y,z);}
00177   void addCamAzi(float azi) { m_azi += azi; }
00178   void addCamEle(float ele) { m_ele += ele; }
00179   void setCameraAngles(float azi, float ele) { m_azi = azi; m_ele = ele; }
00180   void moveCameraUp(float z) { m_camPos[1] += z; }
00181   
00182   VEE_Vector3 & camDir() { return m_direction; }
00183 
00184   void setCameraParams(const VEE_CameraPosition &p)
00185   { m_camPos = p.m_camPos; m_azi = p.m_azi; m_ele = p.m_ele; }
00186   VEE_CameraPosition cameraParams() const
00187   { return VEE_CameraPosition(m_camPos, m_azi, m_ele); }
00188   void forward(float distance)
00189   { m_camPos += (m_direction * distance); }
00190 
00191   void forwardAcceleration(float acceleration)
00192   { m_velocity[2] += acceleration; }
00193 
00194   void sidewaysAcceleration(float acceleration)
00195   { m_velocity[0] += acceleration; }
00196 
00197   void moveCamera(float dt);
00198 
00199   void stopMotion() { m_velocity.clear(); }
00200 
00201   void setBlend(bool b) { m_blend = b; }
00202   bool getBlend() const { return m_blend; }
00203 
00204   void setBlendType(VEE_Blending b) { m_blendType = b; }
00205 
00206   void setUseTextures(bool u) { m_useTextures = u; }
00207   bool getUseTextures() const { return m_useTextures; }
00208 
00209   bool getDrawForceBoxes () { return m_drawForceBoxes; }
00210   void setDrawForceBoxes(bool b) { m_drawForceBoxes = b; }
00211 
00212   bool drawBoxEdges() const { return m_drawBoxEdges; }
00213   void setDrawBoxEdges(bool b) { m_drawBoxEdges = b; }
00214 
00215   void setBackgroundColor(const VEE_Rgba &color) { m_bgColor = color; }
00216   const VEE_Rgba &backgroundColor() const { return m_bgColor; }
00218   void setRange(float minDist, float fadeDist, float maxDist);
00219 
00223   static void createPrivateTextures(bool create) 
00224   { m_privateTextures = create; }
00225 
00227   void setTexture(GLuint texId) { m_texId = texId; }
00228   GLuint getTexture() const { return m_texId; }
00229 
00230   ulong  modeChanges() const { return m_modeChanges; }
00231 
00232   void setFade(float fade) { m_fade = fade; }
00233 
00234   int subTextureCount() const { return m_textureDivision * m_textureDivision; }
00235   int subTextureDivision() const { return m_textureDivision; }
00236   int currentSubTexture() const
00237   { return m_textureDivision * m_textureRow + m_textureCol; }
00238   void setSubTexture(int tex)
00239   { 
00240     m_textureRow = tex / m_textureDivision; 
00241     m_textureCol = tex % m_textureDivision;
00242   }
00243 
00244   // bool  stretchParticles() const { return m_stretchParticles; }
00245   // void setStretchParticles(bool s) { m_stretchParticles = s; }
00246 
00247   /* bool  alignParticles() const 
00248      { return m_alignParticlesWithVelocity; }
00249      void setAlignParticles(bool s) 
00250      { m_alignParticlesWithVelocity = s; } */
00251 
00252   void buildTextures(VEE_GlTexture2D *tex, float radius,
00253          const char * configFile = 0);
00254   void buildPolygonTextures(VEE_GlTexture2D *tex);
00255 
00256   bool continuousTails() const { return m_continuousTails; }
00257   void setContinuousTails(bool b) { m_continuousTails = b; }
00258 
00259   float tailDispersion() const { return m_tailDispersion; }
00260   float fov() const { return m_fov; }
00261   
00262   void setExternalTextures(VEE_GlTexture2D *blob,
00263          VEE_GlTexture2D *polygon)
00264   { m_blobTexture = blob; m_polygonTexture = polygon; }
00265 
00266   void setTexId();
00267 
00268   void drawVolumeGrid(const VEE_Vector3 &, VEE_VolumeGrid *);
00269   void drawVolumeGrid2(const VEE_Vector3 &, VEE_VolumeGrid2 *, 
00270            bool blend = true);
00271 
00272   inline VEE_Rgba transformColor(const VEE_Rgba &) const;
00273 
00274   void nextAlignMent() { m_defaultRenderClass.nextAlignMent(); }
00275   VEE_MotionAlign align() const { return m_defaultRenderClass.align(); }
00276 
00277   virtual void renderParticleVisual(VEE_ParticleVisualInfo *p);
00278   void renderTailParticle(VEE_TailParticle *p);
00279   void renderCurveParticle(VEE_CurveParticle *p);
00280   void renderRigidParticle(VEE_RigidParticle *p);
00281 
00282   static void drawBox(VEE_Vector3 low, VEE_Vector3 high);
00283 
00284   float farDistance()  const { return m_farDistance; }
00285   float fadeDistance() const { return m_fadeDistance; }
00286   float nearDistance() const { return m_nearDistance; }
00287   float fadeRange()    const { return m_fadeRange; }
00288   
00289   int textureNameToId(const char *name);
00290   int shaderNameToId(const char *name);
00291   
00292   VEE_GlMaterialBank & materials() { return m_materials; }
00293 
00294   void setForceFrontColor(const VEE_Rgba *c) { m_forceFrontColor = c; }
00295   void setForceBackColor(const VEE_Rgba *c) { m_forceBackColor = c; }
00296 
00297   const VEE_Rgba * forceFrontColor() const { return m_forceFrontColor; }
00298   const VEE_Rgba * forceBackColor()  const { return m_forceBackColor; }
00299 
00300   void setMatrix(const VEE_Matrix4 & m) { m_matrix = m; }
00301   void setUseMatrix(bool use) { m_useMatrix = use; }
00302 
00303   const std::string & configFile() const { return m_configFile; }
00304 
00305   void setRenderOnlyOutline(bool outlines);
00306 
00308   int width()  const { return m_width; }
00309   int height() const { return m_height; }
00310 
00311   bool applyDepthMap() const { return m_applyDepthMap; }
00312   void createDepthMap();
00313 
00314   VEE_GlTexture2D & depthMap() { return m_depthMap; }
00315 
00316 protected:
00317 
00318   VEE_Vector3 m_camPos;
00319   VEE_Vector3 m_direction;
00320   VEE_Vector3 m_velocity;
00321   VEE_Vector3 m_camUp;
00322 
00323   const VEE_Rgba * m_forceFrontColor;
00324   const VEE_Rgba * m_forceBackColor;
00325 
00326   // Vectors that define current View-Plane directions.
00327   VEE_Vector3 m_vpUp, m_vpRight;
00328 
00329   float m_azi, m_ele;
00330 
00331   VEE_SceneBox *m_vps;
00332 
00333   float m_farDistance;
00334   float m_fadeDistance;
00335   float m_nearDistance;
00336   float m_fadeRange;
00337 
00338   bool  m_renderOnlyOutline;
00339 
00340   void newMode(Mode);
00341   void beginTextured(Mode, GLuint);
00342   void endTextured();
00343 
00344   void pushTransform(const VEE_Matrix3 &rot,  
00345          const VEE_Vector3 &loc);
00346   
00347   void popTransform() { glPopMatrix(); }
00348 
00349   GLUquadric* m_cylinder;
00350 
00351   GLuint m_texId;
00352   
00353   bool m_blend;
00354   bool m_useTextures;
00355 
00356   bool m_drawBoxEdges;
00357   
00358   Mode m_mode, m_particleMode, m_forceMode, m_polygonMode;
00359   bool m_drawForceBoxes;
00361   GLuint m_currentTexture;
00362   int    m_currentMaterial;
00363 
00364   float m_pointSize;
00365 
00366   float m_particleSize;
00367 
00368   VEE_RenderClass m_defaultRenderClass;
00369 
00370   // float m_lengthScale;
00371   // float m_maxLengthScale;
00372 
00373   float m_alphaMul;
00374   float m_fade;
00375   float m_fixedFade;
00376 
00378   float m_fov;
00379 
00380   // bool  m_stretchParticles;
00381   // bool  m_alignParticlesWithVelocity;
00382   bool  m_continuousTails;
00383   float m_tailDispersion;
00384 
00385   VEE_TCBSpline3 * m_tcbSpline;
00386 
00387   Order m_renderOrder;
00388 
00389   int   m_width, m_height;
00390 
00391   ulong  m_modeChanges;
00392 
00393   VEE_GlMaterialBank m_materials;
00394 
00396   uint  m_textureDivision;
00397   uint  m_textureRow;
00398   uint  m_textureCol;
00399   float m_textureStep;
00400 
00401   VEE_Rgba m_bgColor;
00402 
00403   VEE_Blending m_blendType;
00404 
00405   VEE_GlTexture2D * m_blobTexture;
00406   VEE_GlTexture2D * m_polygonTexture;
00407 
00409   VEE_GlTexture2D   m_depthMap;
00410   bool              m_useDepthMap;
00411   bool              m_applyDepthMap;
00412 
00413   std::string  m_configFile;
00414 
00415   static bool  m_privateTextures;
00416 
00417   typedef std::map<int, Solar::GraphicTriangleMesh> meshStore;
00418   meshStore m_meshes;
00419 
00420   VEE_Matrix4 m_matrix;
00421   bool        m_useMatrix;
00422 
00423   // Map texture names ("flame" etc.) to a texture index.
00424   std::map<std::string, int> m_textureNames;
00425 
00426   std::map<std::string, int> m_shaderNames;
00427 
00428 private:
00429   VEE_GlRenderer(const VEE_GlRenderer &) {}
00430   VEE_GlRenderer & operator = (const VEE_GlRenderer &) { return * this; }
00431 };
00432 
00433 inline VEE_Rgba VEE_GlRenderer::transformColor(const VEE_Rgba &rgb) const
00434 {
00435   float a = rgb.alpha() * m_alphaMul;
00436 
00437   if(m_blendType == VEE_BLEND_NEW) {
00438     float cover = a * (1.0f - rgb.theta());
00439     float gain  = a;
00440 
00441     VEE_Rgba tmp(rgb.red() * gain, rgb.green() * gain, rgb.blue() * gain, 
00442      cover);
00443     tmp.normalize();
00444 
00445     return tmp;
00446   }
00447 
00448   return VEE_Rgba(rgb.red(), rgb.green(), rgb.blue(), a);
00449 }
00450 
00451 #endif // _VEE_GL_H_
00452 

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6