| 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" |
| bsalomon@google.com | 6e85937 | 2012-02-09 15:25:13 +0000 | [diff] [blame] | 12 | #include "SkString.h" |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 13 | |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 14 | /** |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 15 | * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
| 16 | * Provides a GrGLInterface struct of function pointers for the context. |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 17 | */ |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 18 | |
| 19 | class SkGLContext : public SkRefCnt { |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 20 | public: |
| bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 21 | SkGLContext(); |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 22 | virtual ~SkGLContext(); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 23 | |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 24 | /** |
| 25 | * Initializes the context and makes it current. |
| 26 | */ |
| bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 27 | bool init(const int width, const int height); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 28 | |
| bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 29 | int getFBOID() const { return fFBO; } |
| 30 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 31 | const GrGLInterface* gl() const { return fGL; } |
| bungeman@google.com | 16bab87 | 2011-05-17 14:24:46 +0000 | [diff] [blame] | 32 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 33 | virtual void makeCurrent() const = 0; |
| 34 | |
| bsalomon@google.com | 6e85937 | 2012-02-09 15:25:13 +0000 | [diff] [blame] | 35 | bool hasExtension(const char* extensionName) const; |
| 36 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 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: |
| bsalomon@google.com | 6e85937 | 2012-02-09 15:25:13 +0000 | [diff] [blame] | 52 | SkString fExtensionString; |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 53 | GrGLuint fFBO; |
| robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame^] | 54 | GrGLuint fColorBufferID; |
| 55 | GrGLuint fDepthStencilBufferID; |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 56 | const GrGLInterface* fGL; |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 59 | /** |
| 60 | * Helper macro for using the GL context through the GrGLInterface. Example: |
| 61 | * SK_GL(glCtx, GenTextures(1, &texID)); |
| 62 | */ |
| 63 | #define SK_GL(ctx, X) (ctx).gl()->f ## X |
| 64 | |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 65 | #endif |