00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 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.154 $ $Date: 2021年10月08日 03:39:38 $ 00015 * 00016 ***************************************************************************/ 00033 #ifndef OPENGLRENDERER_H 00034 #define OPENGLRENDERER_H 00035 00036 // Starting with VMD 1.9.3, we disable the use of the old 00037 // OpenGL GLU library, in favor of VMD-internal replacements 00038 // for GLU routines that set viewing matrices, project/unproject 00039 // points to/from viewport coordinates, and draw spheres, conics, 00040 // and end cap discs. The GLU library is deprecated on OSes such as 00041 // MacOS X, and it's not suited for the latest revs of OpenGL. 00042 //#define VMDUSELIBGLU 1 // macro to enable use of libGLU instead of built-ins 00043 00044 #include "DisplayDevice.h" 00045 #include "Scene.h" 00046 #include "OpenGLExtensions.h" 00047 #include "OpenGLCache.h" 00048 00049 #if defined(VMDUSEOPENGLSHADER) 00050 #include "OpenGLShader.h" 00051 #endif 00052 00053 #if defined(_MSC_VER) 00054 #include <windows.h> 00055 #endif 00056 00057 // The Linux OpenGL ABI 1.0 spec requires that we define 00058 // GL_GLEXT_PROTOTYPES before including gl.h or glx.h for extensions 00059 // in order to get prototypes: 00060 // http://oss.sgi.com/projects/ogl-sample/ABI/index.html 00061 #define GL_GLEXT_PROTOTYPES 1 00062 00063 #if defined(__APPLE__) && !defined (VMDMESA) 00064 #include <OpenGL/gl.h> 00065 #else 00066 #include <GL/gl.h> 00067 #endif 00068 00069 // include GLU if we use it 00070 #if defined(VMDUSELIBGLU) 00071 #if defined(__APPLE__) && !defined (VMDMESA) 00072 #include <OpenGL/glu.h> 00073 #else 00074 #include <GL/glu.h> 00075 #endif 00076 #endif 00077 00078 // NOTE: you may have to get copies of the latest OpenGL extension headers 00079 // from the OpenGL web site if your Linux machine lacks them: 00080 // http://oss.sgi.com/projects/ogl-sample/registry/ 00081 #if (defined(__linux) || defined(_MSC_VER)) && !defined(VMDMESA) 00082 #include <GL/glext.h> 00083 #endif 00084 #if defined(__APPLE__) && !defined (VMDMESA) 00085 #include <OpenGL/glext.h> 00086 #endif 00087 00088 // required for Win32 calling conventions to work correctly 00089 #ifndef APIENTRY 00090 #define APIENTRY 00091 #endif 00092 #ifndef GLAPI 00093 #define GLAPI extern 00094 #endif 00095 00096 // simple defines for stereo modes 00097 #define OPENGL_STEREO_OFF 0 00098 #define OPENGL_STEREO_QUADBUFFER 1 00099 #define OPENGL_STEREO_HDTVSIDE 2 00100 #define OPENGL_STEREO_STENCIL_CHECKERBOARD 3 00101 #define OPENGL_STEREO_STENCIL_COLUMNS 4 00102 #define OPENGL_STEREO_STENCIL_ROWS 5 00103 #define OPENGL_STEREO_ANAGLYPH 6 00104 #define OPENGL_STEREO_SIDE 7 00105 #define OPENGL_STEREO_ABOVEBELOW 8 00106 #define OPENGL_STEREO_LEFT 9 00107 #define OPENGL_STEREO_RIGHT 10 00108 #define OPENGL_STEREO_MODES 11 00109 00110 // simple defines for rendering modes 00111 #define OPENGL_RENDER_NORMAL 0 00112 #define OPENGL_RENDER_GLSL 1 00113 #if defined(VMDOPTIXRTRT) 00114 #define OPENGL_RENDER_RTXRTRT 2 00115 #define OPENGL_RENDER_ACROBAT3D 3 00116 #define OPENGL_RENDER_MODES 4 00117 #else 00118 #define OPENGL_RENDER_ACROBAT3D 2 00119 #define OPENGL_RENDER_MODES 3 00120 #endif 00121 00122 // simple defines for caching modes 00123 #define OPENGL_CACHE_OFF 0 00124 #define OPENGL_CACHE_ON 1 00125 #define OPENGL_CACHE_MODES 2 00126 00127 class OpenGLRenderer; //<! forward declaration of classes here 00128 class VMDDisplayList; //<! forward declaration of classes here 00129 #if defined(VMDOPTIXRTRT) 00130 class OptiXRenderer; //<! forward declaration of classes here 00131 #endif 00132 00137 class OpenGLRenderer : public DisplayDevice { 00138 #if defined(VMD_NANOHUB) 00139 protected: 00140 GLuint _finalFbo, _finalColorTex, _finalDepthRb; 00141 bool init_offscreen_framebuffer(int width, int height); 00142 #endif 00143 00144 public: 00145 void setup_initial_opengl_state(void); 00146 00147 protected: 00149 00150 #if defined(VMDUSELIBGLU) 00151 GLUquadricObj *pointsQuadric; 00152 GLUquadricObj *objQuadric; 00153 #endif 00154 00156 ResizeArray<GLuint> solidSphereLists; 00157 ResizeArray<GLuint> pointSphereLists; 00158 00160 GLuint SphereList; 00162 00163 00165 00166 // used to eliminate unnecessary OpenGL state changes at draw time 00167 OpenGLCache displaylistcache; // display list cache 00168 OpenGLCache texturecache; // texture object cache 00169 int oglmaterialindex; // material index for fast matching 00170 float oglopacity; 00171 float oglambient; 00172 float oglspecular; 00173 float ogldiffuse; 00174 float oglshininess; 00175 float ogloutline; 00176 float ogloutlinewidth; 00177 int ogltransmode; 00178 GLfloat ogl_pmatrix[16]; // perspective matrix 00179 GLfloat ogl_mvmatrix[16]; // model view matrix 00180 Matrix4 ogl_textMat; // text rendering matrix 00181 GLint ogl_viewport[4]; // viewport setting 00182 GLint ogl_fogmode; // active fog mode 00183 int ogl_lightingenabled; // lighting on/off 00184 int ogl_useblendedtrans; // flag to use alpha-blended transparency 00185 int ogl_useglslshader; // flag to use GLSL programmable shading 00186 int ogl_glslserial; // last rendering state GLSL used 00187 int ogl_glsltoggle; // GLSL state must be re-sent, when off 00188 int ogl_glslmaterialindex; // last material rendered by GLSL 00189 int ogl_glslprojectionmode; // which projection mode is in use 00190 int ogl_glsltexturemode; // whether shader perform texturing 00191 int ogl_transpass; // which rendering pass (solid/transparent) 00192 int ogl_rendstateserial; // light/fog/material state combo serial num 00193 int ogl_clipmode[VMD_MAX_CLIP_PLANE]; 00194 int ogl_lightstate[DISP_LIGHTS]; 00195 GLfloat ogl_lightcolor[DISP_LIGHTS][4]; 00196 GLfloat ogl_lightpos[DISP_LIGHTS][4]; 00197 GLfloat ogl_backcolor[4]; // background color 00198 GLfloat ogl_backgradient[2][4]; // background gradient colors 00199 int ogl_acrobat3dcapture; // don't cache anything, for 3-D capture 00201 00202 #if defined(VMDOPTIXRTRT) 00203 00204 OptiXRenderer * ort; // OptiXRenderer context 00205 int ogl_optix_rtrt_passthrough; // when active, RTX RTRT does rendering 00206 #endif 00207 00209 int ogl_cacheenabled; 00210 int ogl_cachedebug; 00211 GLint ogl_cachelistbase; 00212 00213 int dpl_initialized; 00214 00215 protected: 00217 GLuint font1pxListBase; 00218 GLuint fontNpxListBase; 00219 00220 OpenGLExtensions *ext; 00221 00222 #if defined(VMDUSEOPENGLSHADER) 00223 OpenGLShader *mainshader; 00224 OpenGLShader *sphereshader; 00225 OpenGLShader *spherespriteshader; 00226 #endif 00227 00228 int simplegraphics; 00229 int wiregl; 00230 int intelswr; 00231 int immersadeskflip; 00232 int shearstereo; 00233 00235 00236 int hastex2d; 00237 GLint max2DtexX; 00238 GLint max2DtexY; 00239 GLint max2DtexSize; 00241 00243 00244 int hastex3d; 00245 GLint max3DtexX; 00246 GLint max3DtexY; 00247 GLint max3DtexZ; 00248 GLint max3DtexSize; 00250 00251 // 00252 // routines to perform various OGL-specific initializations. 00253 // 00255 void update_lists(void); 00256 void update_shader_uniforms(void *, int forceupdate); 00257 00259 00260 void set_line_width(int); 00261 void set_line_style(int); 00262 void set_sphere_res(int); 00263 void set_sphere_mode(int); 00264 void cylinder(float *, float *, int, float, float); // slow cylinder version 00265 void require_volume_texture(unsigned long ID, 00266 unsigned xsize, unsigned ysize, unsigned zsize, unsigned char *texmap); 00267 int build3Dmipmaps(int, int, int, unsigned char *tx); 00268 void draw_background_gradient(void); 00270 00271 00273 00274 virtual int do_define_light(int n, float *color, float *position); 00275 virtual int do_activate_light(int n, int turnon); 00277 00278 public: 00280 OpenGLRenderer(const char *); 00281 virtual ~OpenGLRenderer(void); 00282 00283 // All display device subclasses from OpenGLRenderer (with the notable 00284 // exception of OpenGLPbufferDisplayDevice) support GUIs. 00285 virtual int supports_gui() { return TRUE; } 00286 00288 00289 virtual void loadmatrix(const Matrix4&); // replace trans matrix w. given one 00290 virtual void multmatrix(const Matrix4&); // multiply trans matrix w. given one 00292 00293 00294 // 00295 // virtual routines to find characteristics of display itself 00296 // 00297 00299 00300 virtual void abs_screen_loc_3D(float *, float *); 00302 virtual void abs_screen_loc_2D(float *, float *); 00304 00305 // Given a 3D point (pos A), 00306 // and a 2D rel screen pos point (for pos B), computes the 3D point 00307 // which goes with the second 2D point at pos B. Result returned in B3D. 00308 virtual void find_3D_from_2D(const float *A3D, const float *B2D, float *B3D); 00309 00311 00312 virtual void aa_on(void); 00313 virtual void aa_off(void); 00314 virtual void cueing_on(void); 00315 virtual void cueing_off(void); 00316 virtual void culling_on(void); 00317 virtual void culling_off(void); 00319 00320 // get/set the background color 00321 virtual void set_background(const float *); 00322 virtual void set_backgradient(const float *, const float *); 00323 00324 // virtual routines for preparing to draw, drawing, and finishing drawing 00325 virtual void enable_stencil_stereo(int newMode); 00326 virtual void disable_stencil_stereo(void); 00327 virtual void left(void); 00328 virtual void right(void); 00329 virtual void normal(void); 00330 virtual void set_persp(DisplayEye = NOSTEREO); 00331 virtual int prepare3D(int do_clear = TRUE); 00332 virtual int prepareOpaque(); 00333 virtual int prepareTrans(); 00334 virtual void clear(void); 00335 virtual void render(const VMDDisplayList *); 00336 virtual void render_done(); 00337 void free_opengl_ctx(); 00338 00340 virtual int forced_stereo_draws(void) { return ext->stereodrawforced; } 00341 00342 virtual void set_stereo_mode(int = 0); 00343 virtual void set_cache_mode(int); 00344 virtual void set_render_mode(int); 00345 virtual void set_window_title(char *) {}; 00346 }; 00347 00348 #endif 00349