blob: d36a9f9d43029138f5e3ae535441f8d80ee49fa4 [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
bungeman@google.com0e454412011-05-19 17:47:02 +000023 bool init(const int width, const int height);
reed@google.comc31ce102010-12-21 16:26:39 +000024
bsalomon@google.com971d0c82011-08-19 17:22:05 +000025 int getFBOID() const { return fFBO; }
26
bsalomon@google.com373a6632011-10-19 20:43:20 +000027 const GrGLInterface* gl() const { return fGL; }
bungeman@google.com16bab872011-05-17 14:24:46 +000028
bsalomon@google.com373a6632011-10-19 20:43:20 +000029 virtual void makeCurrent() const = 0;
30
31protected:
32 /**
33 * Subclass implements this to make a GL context. The returned GrGLInterface
34 * should be populated with functions compatible with the context. The
35 * format and size of backbuffers does not matter since an FBO will be
36 * created.
37 */
38 virtual const GrGLInterface* createGLContext() = 0;
39
40 /**
41 * Subclass should destroy the underlying GL context.
42 */
43 virtual void destroyGLContext() = 0;
44
45private:
46 GrGLuint fFBO;
47 const GrGLInterface* fGL;
reed@google.comc31ce102010-12-21 16:26:39 +000048};
49
bsalomon@google.com373a6632011-10-19 20:43:20 +000050/**
51 * Helper macro for using the GL context through the GrGLInterface. Example:
52 * SK_GL(glCtx, GenTextures(1, &texID));
53 */
54#define SK_GL(ctx, X) (ctx).gl()->f ## X
55
reed@google.com873cb1e2010-12-23 15:00:45 +000056#endif