blob: f92a7700c46890670e8f0d705d4932beeba15b08 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.come2953132011-10-13 13:33:08 +00008#ifndef SkGLContext_DEFINED
9#define SkGLContext_DEFINED
reed@google.comc31ce102010-12-21 16:26:39 +000010
bsalomon@google.com373a6632011-10-19 20:43:20 +000011#include "GrGLInterface.h"
reed@google.comc31ce102010-12-21 16:26:39 +000012
reed@google.com873cb1e2010-12-23 15:00:45 +000013/**
bsalomon@google.com373a6632011-10-19 20:43:20 +000014 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
15 * Provides a GrGLInterface struct of function pointers for the context.
reed@google.com873cb1e2010-12-23 15:00:45 +000016 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000017
18class SkGLContext : public SkRefCnt {
reed@google.comc31ce102010-12-21 16:26:39 +000019public:
bsalomon@google.come2953132011-10-13 13:33:08 +000020 SkGLContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000021 virtual ~SkGLContext();
reed@google.comc31ce102010-12-21 16:26:39 +000022
bsalomon@google.com57f5d982011-10-24 21:17:53 +000023 /**
24 * Initializes the context and makes it current.
25 */
bungeman@google.com0e454412011-05-19 17:47:02 +000026 bool init(const int width, const int height);
reed@google.comc31ce102010-12-21 16:26:39 +000027
bsalomon@google.com971d0c82011-08-19 17:22:05 +000028 int getFBOID() const { return fFBO; }
29
bsalomon@google.com373a6632011-10-19 20:43:20 +000030 const GrGLInterface* gl() const { return fGL; }
bungeman@google.com16bab872011-05-17 14:24:46 +000031
bsalomon@google.com373a6632011-10-19 20:43:20 +000032 virtual void makeCurrent() const = 0;
33
34protected:
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
48private:
49 GrGLuint fFBO;
50 const GrGLInterface* fGL;
reed@google.comc31ce102010-12-21 16:26:39 +000051};
52
bsalomon@google.com373a6632011-10-19 20:43:20 +000053/**
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.com873cb1e2010-12-23 15:00:45 +000059#endif