Home | History | Annotate | Download | only in gl
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #ifndef SkGLContext_DEFINED
      9 #define SkGLContext_DEFINED
     10 
     11 #include "GrGLInterface.h"
     12 #include "SkString.h"
     13 
     14 /**
     15  * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
     16  * Provides a GrGLInterface struct of function pointers for the context.
     17  */
     18 
     19 class SkGLContext : public SkRefCnt {
     20 public:
     21     SK_DECLARE_INST_COUNT(SkGLContext)
     22 
     23     SkGLContext();
     24     virtual ~SkGLContext();
     25 
     26     /**
     27      * Initializes the context and makes it current.
     28      */
     29     bool init(const int width, const int height);
     30 
     31     int getFBOID() const { return fFBO; }
     32 
     33     const GrGLInterface* gl() const { return fGL; }
     34 
     35     virtual void makeCurrent() const = 0;
     36 
     37     bool hasExtension(const char* extensionName) const;
     38 
     39 protected:
     40     /**
     41      * Subclass implements this to make a GL context. The returned GrGLInterface
     42      * should be populated with functions compatible with the context. The
     43      * format and size of backbuffers does not matter since an FBO will be
     44      * created.
     45      */
     46     virtual const GrGLInterface* createGLContext() = 0;
     47 
     48     /**
     49      * Subclass should destroy the underlying GL context.
     50      */
     51     virtual void destroyGLContext() = 0;
     52 
     53 private:
     54     SkString fExtensionString;
     55     GrGLuint fFBO;
     56     GrGLuint fColorBufferID;
     57     GrGLuint fDepthStencilBufferID;
     58     const GrGLInterface* fGL;
     59 
     60     typedef SkRefCnt INHERITED;
     61 };
     62 
     63 /**
     64  * Helper macro for using the GL context through the GrGLInterface. Example:
     65  * SK_GL(glCtx, GenTextures(1, &texID));
     66  */
     67 #define SK_GL(ctx, X) (ctx).gl()->f ## X
     68 
     69 #endif
     70