GLState.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   GLState.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Summer 2008
00005    
00006    @brief
00007       Utility wrapper classes for accessing and synchronizing OpenGL state
00008    in a cleaner, more object-oriented manner, grouping similar state items 
00009    with each other.
00010    
00011    @note
00012       Where applicable, acceptable parameters are listed along with default 
00013    values marked between '<' and '>'. For example, the frontFace property of
00014    GLPrimitiveStateItem is preceded by the following comment:
00015       /// glFrontFace; GL_CW or <GL_CCW>
00016    Where GL_CCW is the OpenGL-defined default value for this property.
00017    <!-------------------------------------------------------------------->**/
00018 
00019 #include "GLState.h"
00020 #include <GL/glu.h>
00021 using namespace std;
00022 
00023 // TODO: add GLPixelTransferStateItem?
00024 // TODO: add GLClearValueStateItem?
00025 
00026 int GLState::getFreeLight() {
00027    GLint maxNoLights = 0;
00028    glGetIntegerv(GL_MAX_LIGHTS, &maxNoLights);
00029    
00030    for(int i = 0; i < maxNoLights; ++i) {
00031       GLboolean isEnabled = false;
00032       GLint lightIndex = GL_LIGHT0 + i;
00033       
00034       glGetBooleanv(lightIndex, &isEnabled);
00035       if (!isEnabled)
00036          return lightIndex;
00037    }
00038    
00039    return -1;
00040 }
00041 
00042 bool GLState::glCheckError(const char *file, int line) {
00043    bool retVal = true;
00044    GLenum glErr;
00045    
00046    while ((glErr = glGetError()) != GL_NO_ERROR) {
00047       cerr << file << ":" << line << ": " << gluErrorString(glErr);
00048       cerr << endl;
00049       
00050       retVal = false;
00051    }
00052    
00053    if (!retVal) {
00054       cerr << glErr << endl;
00055       ASSERT(0);
00056    }
00057    
00058    return retVal;
00059 }
00060 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6