| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
| bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 8 | #ifndef SkGLContext_DEFINED |
| 9 | #define SkGLContext_DEFINED |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 10 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 11 | #include "GrGLInterface.h" |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 12 | |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 13 | /** |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 14 | * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
| 15 | * Provides a GrGLInterface struct of function pointers for the context. |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 16 | */ |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 17 | |
| 18 | class SkGLContext : public SkRefCnt { |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 19 | public: |
| bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 20 | SkGLContext(); |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 21 | virtual ~SkGLContext(); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 22 | |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 23 | /** |
| 24 | * Initializes the context and makes it current. |
| 25 | */ |
| bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 26 | bool init(const int width, const int height); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 27 | |
| bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 28 | int getFBOID() const { return fFBO; } |
| 29 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 30 | const GrGLInterface* gl() const { return fGL; } |
| bungeman@google.com | 16bab87 | 2011-05-17 14:24:46 +0000 | [diff] [blame] | 31 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 32 | virtual void makeCurrent() const = 0; |
| 33 | |
| 34 | protected: |
| 35 | /** |
| 36 | * Subclass implements this to make a GL context. The returned GrGLInterface |
| 37 | * should be populated with functions compatible with the context. The |
| 38 | * format and size of backbuffers does not matter since an FBO will be |
| 39 | * created. |
| 40 | */ |
| 41 | virtual const GrGLInterface* createGLContext() = 0; |
| 42 | |
| 43 | /** |
| 44 | * Subclass should destroy the underlying GL context. |
| 45 | */ |
| 46 | virtual void destroyGLContext() = 0; |
| 47 | |
| 48 | private: |
| 49 | GrGLuint fFBO; |
| 50 | const GrGLInterface* fGL; |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Helper macro for using the GL context through the GrGLInterface. Example: |
| 55 | * SK_GL(glCtx, GenTextures(1, &texID)); |
| 56 | */ |
| 57 | #define SK_GL(ctx, X) (ctx).gl()->f ## X |
| 58 | |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 59 | #endif |