• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     SkGLContext();
22     virtual ~SkGLContext();
23 
24     /**
25      * Initializes the context and makes it current.
26      */
27     bool init(const int width, const int height);
28 
getFBOID()29     int getFBOID() const { return fFBO; }
30 
gl()31     const GrGLInterface* gl() const { return fGL; }
32 
33     virtual void makeCurrent() const = 0;
34 
35     bool hasExtension(const char* extensionName) const;
36 
37 protected:
38     /**
39      * Subclass implements this to make a GL context. The returned GrGLInterface
40      * should be populated with functions compatible with the context. The
41      * format and size of backbuffers does not matter since an FBO will be
42      * created.
43      */
44     virtual const GrGLInterface* createGLContext() = 0;
45 
46     /**
47      * Subclass should destroy the underlying GL context.
48      */
49     virtual void destroyGLContext() = 0;
50 
51 private:
52     SkString fExtensionString;
53     GrGLuint fFBO;
54     const GrGLInterface* fGL;
55 };
56 
57 /**
58  * Helper macro for using the GL context through the GrGLInterface. Example:
59  * SK_GL(glCtx, GenTextures(1, &texID));
60  */
61 #define SK_GL(ctx, X) (ctx).gl()->f ## X
62 
63 #endif
64