| 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: |
| robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 21 | SK_DECLARE_INST_COUNT(SkGLContext) |
| 22 | |
| bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 23 | SkGLContext(); |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 24 | virtual ~SkGLContext(); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 25 | |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 26 | /** |
| 27 | * Initializes the context and makes it current. |
| 28 | */ |
| bungeman@google.com | 0e45441 | 2011-05-19 17:47:02 +0000 | [diff] [blame] | 29 | bool init(const int width, const int height); |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 30 | |
| bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 31 | int getFBOID() const { return fFBO; } |
| 32 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 33 | const GrGLInterface* gl() const { return fGL; } |
| bungeman@google.com | 16bab87 | 2011-05-17 14:24:46 +0000 | [diff] [blame] | 34 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 35 | virtual void makeCurrent() const = 0; |
| 36 | |
| bsalomon@google.com | 6e85937 | 2012-02-09 15:25:13 +0000 | [diff] [blame] | 37 | bool hasExtension(const char* extensionName) const; |
| 38 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 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: |
| bsalomon@google.com | 6e85937 | 2012-02-09 15:25:13 +0000 | [diff] [blame] | 54 | SkString fExtensionString; |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 55 | GrGLuint fFBO; |
| robertphillips@google.com | 7c95942 | 2012-03-22 20:43:56 +0000 | [diff] [blame] | 56 | GrGLuint fColorBufferID; |
| 57 | GrGLuint fDepthStencilBufferID; |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 58 | const GrGLInterface* fGL; |
| robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 59 | |
| 60 | typedef SkRefCnt INHERITED; |
| reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 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 | |
| reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 69 | #endif |