Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2012 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 
      9 #ifndef GrGLContextInfo_DEFINED
     10 #define GrGLContextInfo_DEFINED
     11 
     12 #include "GrGLCaps.h"
     13 #include "gl/GrGLInterface.h"
     14 #include "GrGLSL.h"
     15 
     16 #include "SkString.h"
     17 
     18 /**
     19  * Encapsulates information about an OpenGL context including the GrGLInterface
     20  * used to make GL calls, the OpenGL version, the GrGLBinding type of the
     21  * context, and GLSL version.
     22  */
     23 class GrGLContextInfo {
     24 public:
     25 
     26     /**
     27      * Default constructor, creates an uninitialized GrGLContextInfo
     28      */
     29     GrGLContextInfo();
     30 
     31     /**
     32      * Creates a GrGLContextInfo from a GrGLInterface and the currently
     33      * bound OpenGL context accesible by the GrGLInterface.
     34      */
     35     explicit GrGLContextInfo(const GrGLInterface* interface);
     36 
     37     /**
     38      * Copies a GrGLContextInfo
     39      */
     40     GrGLContextInfo(const GrGLContextInfo& ctx);
     41 
     42     ~GrGLContextInfo();
     43 
     44     /**
     45      * Copies a GrGLContextInfo
     46      */
     47     GrGLContextInfo& operator = (const GrGLContextInfo& ctx);
     48 
     49     /**
     50      * Initializes a GrGLContextInfo from a GrGLInterface and the currently
     51      * bound OpenGL context accessible by the GrGLInterface.
     52      */
     53     bool initialize(const GrGLInterface* interface);
     54     bool isInitialized() const;
     55 
     56     const GrGLInterface* interface() const { return fInterface; }
     57     GrGLBinding binding() const { return fBindingInUse; }
     58     GrGLVersion version() const { return fGLVersion; }
     59     GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
     60     const GrGLCaps& caps() const { return fGLCaps; }
     61     GrGLCaps& caps() { return fGLCaps; }
     62 
     63     /**
     64      * Checks for extension support using a cached copy of the GL_EXTENSIONS
     65      * string.
     66      */
     67     bool hasExtension(const char* ext) const {
     68         if (!this->isInitialized()) {
     69             return false;
     70         }
     71         return GrGLHasExtensionFromString(ext, fExtensionString.c_str());
     72     }
     73 
     74 private:
     75     void reset();
     76 
     77     const GrGLInterface* fInterface;
     78     GrGLBinding          fBindingInUse;
     79     GrGLVersion          fGLVersion;
     80     GrGLSLGeneration     fGLSLGeneration;
     81     SkString             fExtensionString;
     82     GrGLCaps             fGLCaps;
     83 };
     84 
     85 #endif
     86