llgl.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLGL_H
00033 #define LL_LLGL_H
00034 
00035 // This file contains various stuff for handling gl extensions and other gl related stuff.
00036 
00037 #include <string>
00038 #include <map>
00039 
00040 #include "llerror.h"
00041 #include "v4color.h"
00042 #include "llstring.h"
00043 #include "stdtypes.h"
00044 #include "v4math.h"
00045 #include "llgltypes.h"
00046 
00047 #define LL_DEBUG_GL 1
00048 
00049 #define LL_GL_ERRS llerrs
00050 
00051 // Manage GL extensions...
00052 class LLGLManager
00053 {
00054 public:
00055         LLGLManager();
00056 
00057         bool initGL();
00058         void shutdownGL();
00059 
00060         void initWGL(); // Initializes stupid WGL extensions
00061 
00062         LLString getRawGLString(); // For sending to simulator
00063 
00064         BOOL mInited;
00065         BOOL mIsDisabled;
00066 
00067         // Extensions used by everyone
00068         BOOL mHasMultitexture;
00069         S32      mNumTextureUnits;
00070         BOOL mHasMipMapGeneration;
00071         BOOL mHasPalettedTextures;
00072         BOOL mHasCompressedTextures;
00073         BOOL mHasFramebufferObject;
00074 
00075         // ARB Extensions
00076         BOOL mHasVertexBufferObject;
00077         BOOL mHasPBuffer;
00078         BOOL mHasShaderObjects;
00079         BOOL mHasVertexShader;
00080         BOOL mHasFragmentShader;
00081         BOOL mHasOcclusionQuery;
00082         BOOL mHasPointParameters;
00083 
00084         // Other extensions.
00085         BOOL mHasAnisotropic;
00086         BOOL mHasARBEnvCombine;
00087         BOOL mHasCubeMap;
00088 
00089         // Vender specific extensions
00090         BOOL mIsATI;
00091         BOOL mIsNVIDIA;
00092         BOOL mIsIntel;
00093         BOOL mIsGF2or4MX;
00094         BOOL mIsGF3;
00095         BOOL mIsGFFX;
00096         BOOL mATIOffsetVerticalLines;
00097 
00098 #if LL_WINDOWS
00099         BOOL mHasWGLARBPixelFormat;
00100 #endif // LL_WINDOWS
00101 
00102 #if LL_DARWIN
00103         // Apple extensions.
00104         BOOL mHasAPPLEVertexArrayRange;
00105         BOOL mHasAPPLEFence;
00106         BOOL mHasAPPLEVAO;
00107 #endif
00108 
00109         // Misc exitensions
00110         BOOL mHasSeparateSpecularColor;
00111         
00112         S32 mDriverVersionMajor;
00113         S32 mDriverVersionMinor;
00114         S32 mDriverVersionRelease;
00115         F32 mGLVersion; // e.g = 1.4
00116         LLString mDriverVersionVendorString;
00117 
00118         S32 mVRAM; // VRAM in MB
00119         S32 mGLMaxVertexRange;
00120         S32 mGLMaxIndexRange;
00121         
00122         void getPixelFormat(); // Get the best pixel format
00123 
00124         LLString getGLInfoString();
00125 
00126         // In ALL CAPS
00127         LLString mGLVendor;
00128         LLString mGLVendorShort;
00129 
00130         // In ALL CAPS
00131         LLString mGLRenderer;
00132 
00133 private:
00134         void initExtensions();
00135         void initGLStates();
00136         void initGLImages();
00137 };
00138 
00139 extern LLGLManager gGLManager;
00140 
00141 class LLQuaternion;
00142 class LLMatrix4;
00143 
00144 void rotate_quat(LLQuaternion& rotation);
00145 
00146 void flush_glerror(); // Flush GL errors when we know we're handling them correctly.
00147 
00148 void assert_glerror();
00149 
00150 void clear_glerror();
00151 
00152 #if LL_DEBUG
00153 # define stop_glerror() assert_glerror()
00154 # define llglassertok() assert_glerror()
00155 #else
00156 # define stop_glerror()
00157 # define llglassertok()
00158 #endif
00159 
00160 #define llglassertok_always() assert_glerror()
00161 
00163 //
00164 // Note: U32's are GLEnum's...
00165 //
00166 
00167 // This is a class for GL state management
00168 
00169 /*
00170         GL STATE MANAGEMENT DESCRIPTION
00171 
00172         LLGLState and its two subclasses, LLGLEnable and LLGLDisable, manage the current 
00173         enable/disable states of the GL to prevent redundant setting of state within a 
00174         render path or the accidental corruption of what state the next path expects.
00175 
00176         Essentially, wherever you would call glEnable set a state and then
00177         subsequently reset it by calling glDisable (or vice versa), make an instance of 
00178         LLGLEnable with the state you want to set, and assume it will be restored to its
00179         original state when that instance of LLGLEnable is destroyed.  It is good practice
00180         to exploit stack frame controls for optimal setting/unsetting and readability of 
00181         code.  In llglstates.h, there are a collection of helper classes that define groups
00182         of enables/disables that can cause multiple states to be set with the creation of
00183         one instance.  
00184 
00185         Sample usage:
00186 
00187         //disable lighting for rendering hud objects
00188         //INCORRECT USAGE
00189         LLGLEnable lighting(GL_LIGHTING);
00190         renderHUD();
00191         LLGLDisable lighting(GL_LIGHTING);
00192 
00193         //CORRECT USAGE
00194         {
00195                 LLGLEnable lighting(GL_LIGHTING);
00196                 renderHUD();
00197         }
00198 
00199         If a state is to be set on a conditional, the following mechanism
00200         is useful:
00201 
00202         {
00203                 LLGLEnable lighting(light_hud ? GL_LIGHTING : 0);
00204                 renderHUD();
00205         }
00206 
00207         A LLGLState initialized with a parameter of 0 does nothing.
00208 
00209         LLGLState works by maintaining a map of the current GL states, and ignoring redundant
00210         enables/disables.  If a redundant call is attempted, it becomes a noop, otherwise,
00211         it is set in the constructor and reset in the destructor.  
00212 
00213         For debugging GL state corruption, running with debug enabled will trigger asserts
00214         if the existing GL state does not match the expected GL state.
00215 
00216 */
00217 class LLGLState
00218 {
00219 public:
00220         static void initClass();
00221         static void restoreGL();
00222 
00223         static void resetTextureStates();
00224         static void dumpStates();
00225         static void checkStates();
00226         static void checkTextureChannels();
00227         static void checkClientArrays(U32 data_mask = 0x0001);
00228         
00229 protected:
00230         static std::map<LLGLenum, LLGLboolean> sStateMap;
00231         
00232 public:
00233         enum { CURRENT_STATE = -2 };
00234         LLGLState(LLGLenum state, S32 enabled = CURRENT_STATE);
00235         ~LLGLState();
00236         void setEnabled(S32 enabled);
00237         void enable() { setEnabled(TRUE); }
00238         void disable() { setEnabled(FALSE); }
00239 protected:
00240         LLGLenum mState;
00241         BOOL mWasEnabled;
00242         BOOL mIsEnabled;
00243 };
00244 
00245 class LLGLEnable : public LLGLState
00246 {
00247 public:
00248         LLGLEnable(LLGLenum state) : LLGLState(state, TRUE) {}
00249 };
00250 
00251 class LLGLDisable : public LLGLState
00252 {
00253 public:
00254         LLGLDisable(LLGLenum state) : LLGLState(state, FALSE) {}
00255 };
00256 
00257 #include "llglstates.h"
00258 
00259 void init_glstates();
00260 void enable_vertex_weighting(const S32 index);
00261 void disable_vertex_weighting(const S32 index);
00262 void enable_binormals(const S32 index);
00263 void disable_binormals(const S32 index);
00264 void enable_cloth_weights(const S32 index);
00265 void disable_cloth_weights(const S32 index);
00266 void set_vertex_weights(const S32 index, const U32 stride, const F32 *weights);
00267 void set_vertex_clothing_weights(const S32 index, const U32 stride, const LLVector4 *weights);
00268 void set_binormals(const S32 index, const U32 stride, const LLVector3 *binormals);
00269 void set_palette(U8* palette_data);
00270 void parse_gl_version( S32* major, S32* minor, S32* release, LLString* vendor_specific );
00271 
00272 extern BOOL gClothRipple;
00273 extern BOOL gNoRender;
00274 #endif // LL_LLGL_H

Generated on Thu Jul 1 06:08:39 2010 for Second Life Viewer by  doxygen 1.4.7