Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

OpenGLRenderer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2008 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: OpenGLRenderer.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.127 $      $Date: 2008/03/27 19:36:42 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Subclass of DisplayDevice, this object has routines used by all the
00020  * different display devices that use OpenGL for rendering.
00021  * Will render drawing commands into a window.
00022  * This is not the complete definition,
00023  * however, of a DisplayDevice; something must provide routines to open
00024  * windows, reshape, clear, set perspective, etc.  This object contains the
00025  * code to render a display command list.
00026  *
00027  ***************************************************************************/
00028 #ifndef OPENGLRENDERER_H
00029 #define OPENGLRENDERER_H
00030 
00031 #include "DisplayDevice.h"
00032 #include "Scene.h"
00033 #include "OpenGLExtensions.h"
00034 #include "OpenGLCache.h"
00035 
00036 #if defined(VMDUSEOPENGLSHADER)
00037 #include "OpenGLShader.h"
00038 #endif
00039 
00040 #if defined(_MSC_VER)
00041 #include <windows.h>
00042 #endif
00043 
00044 // The Linux OpenGL ABI 1.0 spec requires that we define
00045 // GL_GLEXT_PROTOTYPES before including gl.h or glx.h for extensions
00046 // in order to get prototypes:
00047 //   http://oss.sgi.com/projects/ogl-sample/ABI/index.html
00048 #define GL_GLEXT_PROTOTYPES 1
00049 
00050 #if defined(__APPLE__) && !defined (VMDMESA)
00051 #include <OpenGL/gl.h>
00052 #include <OpenGL/glu.h>
00053 #else
00054 #include <GL/gl.h>
00055 #include <GL/glu.h>
00056 #endif
00057 
00058 // NOTE: you may have to get copies of the latest OpenGL extension headers
00059 // from the OpenGL web site if your Linux machine lacks them:
00060 //   http://oss.sgi.com/projects/ogl-sample/registry/
00061 #if (defined(ARCH_LINUX) || defined(ARCH_LINUXALPHA) || defined(ARCH_LINUXAMD64) || defined(ARCH_LINUXIA64) || defined(ARCH_LINUXPPC) || defined(ARCH_LINUXPPC64) || defined(_MSC_VER)) && !defined(VMDMESA)
00062 #include <GL/glext.h>
00063 #endif
00064 #if defined(__APPLE__) && !defined (VMDMESA)
00065 #include <OpenGL/glext.h>
00066 #endif
00067 
00068 // required for Win32 calling conventions to work correctly
00069 #ifndef APIENTRY
00070 #define APIENTRY
00071 #endif
00072 #ifndef GLAPI
00073 #define GLAPI extern
00074 #endif
00075 
00076 // simple defines for stereo modes
00077 #define OPENGL_STEREO_OFF              0
00078 #define OPENGL_STEREO_CRYSTAL          1
00079 #define OPENGL_STEREO_CRYSTAL_REVERSE  2
00080 #define OPENGL_STEREO_DTISIDE          3
00081 #define OPENGL_STEREO_STENCIL          4
00082 #define OPENGL_STEREO_ANAGLYPH         5
00083 #define OPENGL_STEREO_CROSSED          6
00084 #define OPENGL_STEREO_SIDE             7
00085 #define OPENGL_STEREO_ABOVEBELOW       8
00086 #define OPENGL_STEREO_LEFT             9
00087 #define OPENGL_STEREO_RIGHT           10
00088 #define OPENGL_STEREO_MODES           11 
00089 
00090 // simple defines for rendering modes
00091 #define OPENGL_RENDER_NORMAL         0
00092 #define OPENGL_RENDER_GALPHA         1
00093 #define OPENGL_RENDER_GLSL           2
00094 #define OPENGL_RENDER_ACROBAT3D      3
00095 #define OPENGL_RENDER_MODES          4
00096 
00097 // simple defines for caching modes
00098 #define OPENGL_CACHE_OFF             0
00099 #define OPENGL_CACHE_ON              1
00100 #define OPENGL_CACHE_MODES           2
00101 
00102 class OpenGLRenderer; //<! forward declaration of classes here
00103 class VMDDisplayList; //<! forward declaration of classes here
00104 
00105 
00110 class OpenGLRenderer : public DisplayDevice {
00111 public: 
00112   void setup_initial_opengl_state(void); 
00113 
00114 protected:
00115   float *dataBlock; 
00116 
00118 
00119   GLUquadricObj *pointsQuadric;
00120   GLUquadricObj *objQuadric;
00121 
00123   ResizeArray<GLuint> solidSphereLists;
00124   ResizeArray<GLuint> pointSphereLists;
00125 
00127   GLuint SphereList;
00129 
00130   
00132 
00133   // used to eliminate unnecessary OpenGL state changes at draw time
00134   OpenGLCache displaylistcache;  // display list cache
00135   OpenGLCache texturecache;      // texture object cache
00136   int     oglmaterialindex;      // material index for fast matching
00137   float   oglopacity;
00138   float   oglambient;
00139   float   oglspecular;
00140   float   ogldiffuse;
00141   float   oglshininess;
00142   GLfloat ogl_pmatrix[16];        // perspective matrix
00143   GLfloat ogl_mvmatrix[16];       // model view matrix
00144   Matrix4 ogl_textMat;            // text rendering matrix
00145   GLint   ogl_viewport[4];        // viewport setting
00146   GLint   ogl_fogmode;            // active fog mode
00147   int     ogl_lightingenabled;    // lighting on/off 
00148   int     ogl_useblendedtrans;    // flag to use alpha-blended transparency
00149   int     ogl_useglslshader;      // flag to use GLSL programmable shading
00150   int     ogl_glslserial;         // last rendering state GLSL used
00151   int     ogl_glsltoggle;         // GLSL state must be re-sent, when off 
00152   int     ogl_glslmaterialindex;  // last material rendered by GLSL
00153   int     ogl_glslprojectionmode; // which projection mode is in use
00154   int     ogl_glsltexturemode;    // whether shader perform texturing
00155   int     ogl_transpass;          // which rendering pass (solid/transparent)
00156   int     ogl_rendstateserial;    // light/fog/material state combo serial num
00157   int     ogl_clipmode[VMD_MAX_CLIP_PLANE];
00158   int     ogl_lightstate[DISP_LIGHTS];
00159   GLfloat ogl_lightcolor[DISP_LIGHTS][4];
00160   GLfloat ogl_lightpos[DISP_LIGHTS][4];
00161   GLfloat ogl_backgradient[2][4]; // background gradient colors
00162   int     ogl_acrobat3dcapture;   // don't cache anything, for 3-D capture
00164 
00166   int ogl_cacheenabled;    ///< flag to enable display list caching
00167   int ogl_cachedebug;      
00168   GLint ogl_cachelistbase; 
00169 
00170   int dpl_initialized;     
00171 
00172 protected:
00174   GLuint fontListBase;   
00175 
00176   OpenGLExtensions *ext; 
00177 
00178 #if defined(VMDUSEOPENGLSHADER)
00179   OpenGLShader *mainshader;   
00180   OpenGLShader *sphereshader; 
00181 #endif
00182 
00183   int simplegraphics;    
00184   int wiregl;            
00185   int immersadeskflip;   
00186   int shearstereo;       
00187 
00189 
00190   int hastex2d;
00191   GLint max2DtexX;
00192   GLint max2DtexY;
00193   GLint max2DtexSize;
00195 
00197 
00198   int hastex3d;
00199   GLint max3DtexX;
00200   GLint max3DtexY;
00201   GLint max3DtexZ;
00202   GLint max3DtexSize;
00204 
00205   //
00206   // routines to perform various OGL-specific initializations.
00207   //
00209   void update_lists(void);
00210   void update_shader_uniforms(void *, int forceupdate);
00211 
00213 
00214   void set_line_width(int);
00215   void set_line_style(int);
00216   void set_sphere_res(int);
00217   void set_sphere_mode(int);
00218   void cylinder(float *, float *, int, float, float);  // slow cylinder version
00219   void require_volume_texture(unsigned long ID, 
00220     unsigned xsize, unsigned ysize, unsigned zsize, unsigned char *texmap);
00221   int build3Dmipmaps(int, int, int, unsigned char *tx);
00222   void draw_background_gradient(void);
00224   
00225  
00227 
00228   virtual int do_define_light(int n, float *color, float *position);
00229   virtual int do_activate_light(int n, int turnon);
00231 
00232 public:
00234   OpenGLRenderer(const char *);
00235   virtual ~OpenGLRenderer(void);
00236 
00237   // All display devices subclasses from OpenGLRenderer support GUI's.
00238   virtual int supports_gui() { return TRUE; }
00239 
00241 
00242   virtual void loadmatrix(const Matrix4&); // replace trans matrix w. given one
00243   virtual void multmatrix(const Matrix4&); // multiply trans matrix w. given one
00245 
00246 
00247   //
00248   // virtual routines to find characteristics of display itself
00249   //
00250 
00252 
00253   virtual void abs_screen_loc_3D(float *, long *);
00254   virtual void abs_screen_loc_2D(float *, long *);
00256 
00257   // Given a 3D point (pos A),
00258   // and a 2D rel screen pos point (for pos B), computes the 3D point
00259   // which goes with the second 2D point at pos B.  Result returned in B3D.
00260   virtual void find_3D_from_2D(const float *A3D, const float *B2D, float *B3D);
00261 
00263 
00264   virtual void aa_on(void);
00265   virtual void aa_off(void);
00266   virtual void cueing_on(void);
00267   virtual void cueing_off(void);
00268   virtual void culling_on(void);
00269   virtual void culling_off(void);
00271 
00272   // get/set the background color
00273   virtual void set_background(const float *);    
00274   virtual void set_backgradient(const float *, const float *); 
00275 
00276   // virtual routines for preparing to draw, drawing, and finishing drawing
00277   virtual void enable_stencil_stereo(void);      
00278   virtual void disable_stencil_stereo(void);     
00279   virtual void left(void);                       
00280   virtual void right(void);                      
00281   virtual void normal(void);                     
00282   virtual void set_persp(DisplayEye = NOSTEREO); 
00283   virtual int prepare3D(int do_clear = TRUE);    
00284   virtual int prepareOpaque();                   
00285   virtual int prepareTrans();                    
00286   virtual void clear(void);                      
00287   virtual void render(const VMDDisplayList *);   
00288   virtual void render_done();                    
00289   void free_opengl_ctx();                        
00290 
00292   virtual int forced_stereo_draws(void) { return ext->stereodrawforced; }
00293 
00294   virtual void set_stereo_mode(int = 0);         
00295   virtual void set_cache_mode(int);              
00296   virtual void set_render_mode(int);             
00297 };
00298 
00299 #endif
00300 

Generated on Sun Sep 7 01:26:04 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002