Main Page   Namespace List   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-2011 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.142 $      $Date: 2011/06/16 15:40:07 $
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(__linux) || 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_QUADBUFFER           1
00079 #define OPENGL_STEREO_DTISIDE              2
00080 #define OPENGL_STEREO_STENCIL_CHECKERBOARD 3
00081 #define OPENGL_STEREO_STENCIL_COLUMNS      4
00082 #define OPENGL_STEREO_STENCIL_ROWS         5
00083 #define OPENGL_STEREO_ANAGLYPH             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_GLSL                 1
00093 #define OPENGL_RENDER_ACROBAT3D            2
00094 #define OPENGL_RENDER_MODES                3
00095 
00096 // simple defines for caching modes
00097 #define OPENGL_CACHE_OFF                   0
00098 #define OPENGL_CACHE_ON                    1
00099 #define OPENGL_CACHE_MODES                 2
00100 
00101 class OpenGLRenderer; //<! forward declaration of classes here
00102 class VMDDisplayList; //<! forward declaration of classes here
00103 
00104 
00109 class OpenGLRenderer : public DisplayDevice {
00110 public: 
00111   void setup_initial_opengl_state(void); 
00112 
00113 protected:
00115 
00116   GLUquadricObj *pointsQuadric;
00117   GLUquadricObj *objQuadric;
00118 
00120   ResizeArray<GLuint> solidSphereLists;
00121   ResizeArray<GLuint> pointSphereLists;
00122 
00124   GLuint SphereList;
00126 
00127   
00129 
00130   // used to eliminate unnecessary OpenGL state changes at draw time
00131   OpenGLCache displaylistcache;  // display list cache
00132   OpenGLCache texturecache;      // texture object cache
00133   int     oglmaterialindex;      // material index for fast matching
00134   float   oglopacity;
00135   float   oglambient;
00136   float   oglspecular;
00137   float   ogldiffuse;
00138   float   oglshininess;
00139   float   ogloutline;
00140   float   ogloutlinewidth;
00141   int     ogltransmode;
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 font1pxListBase;     
00175   GLuint fontNpxListBase;     
00176 
00177   OpenGLExtensions *ext;      
00178 
00179 #if defined(VMDUSEOPENGLSHADER)
00180   OpenGLShader *mainshader;   
00181   OpenGLShader *sphereshader; 
00182   OpenGLShader *spherespriteshader; 
00183 #endif
00184 
00185   int simplegraphics;    
00186   int wiregl;            
00187   int immersadeskflip;   
00188   int shearstereo;       
00189 
00191 
00192   int hastex2d;
00193   GLint max2DtexX;
00194   GLint max2DtexY;
00195   GLint max2DtexSize;
00197 
00199 
00200   int hastex3d;
00201   GLint max3DtexX;
00202   GLint max3DtexY;
00203   GLint max3DtexZ;
00204   GLint max3DtexSize;
00206 
00207   //
00208   // routines to perform various OGL-specific initializations.
00209   //
00211   void update_lists(void);
00212   void update_shader_uniforms(void *, int forceupdate);
00213 
00215 
00216   void set_line_width(int);
00217   void set_line_style(int);
00218   void set_sphere_res(int);
00219   void set_sphere_mode(int);
00220   void cylinder(float *, float *, int, float, float);  // slow cylinder version
00221   void require_volume_texture(unsigned long ID, 
00222     unsigned xsize, unsigned ysize, unsigned zsize, unsigned char *texmap);
00223   int build3Dmipmaps(int, int, int, unsigned char *tx);
00224   void draw_background_gradient(void);
00226   
00227  
00229 
00230   virtual int do_define_light(int n, float *color, float *position);
00231   virtual int do_activate_light(int n, int turnon);
00233 
00234 public:
00236   OpenGLRenderer(const char *);
00237   virtual ~OpenGLRenderer(void);
00238 
00239   // All display devices subclasses from OpenGLRenderer support GUI's.
00240   virtual int supports_gui() { return TRUE; }
00241 
00243 
00244   virtual void loadmatrix(const Matrix4&); // replace trans matrix w. given one
00245   virtual void multmatrix(const Matrix4&); // multiply trans matrix w. given one
00247 
00248 
00249   //
00250   // virtual routines to find characteristics of display itself
00251   //
00252 
00254 
00255   virtual void abs_screen_loc_3D(float *, float *);
00257   virtual void abs_screen_loc_2D(float *, float *);
00259 
00260   // Given a 3D point (pos A),
00261   // and a 2D rel screen pos point (for pos B), computes the 3D point
00262   // which goes with the second 2D point at pos B.  Result returned in B3D.
00263   virtual void find_3D_from_2D(const float *A3D, const float *B2D, float *B3D);
00264 
00266 
00267   virtual void aa_on(void);
00268   virtual void aa_off(void);
00269   virtual void cueing_on(void);
00270   virtual void cueing_off(void);
00271   virtual void culling_on(void);
00272   virtual void culling_off(void);
00274 
00275   // get/set the background color
00276   virtual void set_background(const float *);      
00277   virtual void set_backgradient(const float *, const float *); 
00278 
00279   // virtual routines for preparing to draw, drawing, and finishing drawing
00280   virtual void enable_stencil_stereo(int newMode); 
00281   virtual void disable_stencil_stereo(void);       
00282   virtual void left(void);                         
00283   virtual void right(void);                        
00284   virtual void normal(void);                       
00285   virtual void set_persp(DisplayEye = NOSTEREO);   
00286   virtual int prepare3D(int do_clear = TRUE);      
00287   virtual int prepareOpaque();                     
00288   virtual int prepareTrans();                      
00289   virtual void clear(void);                        
00290   virtual void render(const VMDDisplayList *);     
00291   virtual void render_done();                      
00292   void free_opengl_ctx();                          
00293 
00295   virtual int forced_stereo_draws(void) { return ext->stereodrawforced; }
00296 
00297   virtual void set_stereo_mode(int = 0);           
00298   virtual void set_cache_mode(int);                
00299   virtual void set_render_mode(int);               
00300 };
00301 
00302 #endif
00303 

Generated on Sat May 26 01:48:16 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002