blob: e2ac7e0885487d91ed635841de788291722fed33 [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"
bsalomon@google.com6e859372012-02-09 15:25:13 +000012#include "SkString.h"
reed@google.comc31ce102010-12-21 16:26:39 +000013
reed@google.com873cb1e2010-12-23 15:00:45 +000014/**
bsalomon@google.com373a6632011-10-19 20:43:20 +000015 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
16 * Provides a GrGLInterface struct of function pointers for the context.
reed@google.com873cb1e2010-12-23 15:00:45 +000017 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000018
19class SkGLContext : public SkRefCnt {
reed@google.comc31ce102010-12-21 16:26:39 +000020public:
bsalomon@google.come2953132011-10-13 13:33:08 +000021 SkGLContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000022 virtual ~SkGLContext();
reed@google.comc31ce102010-12-21 16:26:39 +000023
bsalomon@google.com57f5d982011-10-24 21:17:53 +000024 /**
25 * Initializes the context and makes it current.
26 */
bungeman@google.com0e454412011-05-19 17:47:02 +000027 bool init(const int width, const int height);
reed@google.comc31ce102010-12-21 16:26:39 +000028
bsalomon@google.com971d0c82011-08-19 17:22:05 +000029 int getFBOID() const { return fFBO; }
30
bsalomon@google.com373a6632011-10-19 20:43:20 +000031 const GrGLInterface* gl() const { return fGL; }
bungeman@google.com16bab872011-05-17 14:24:46 +000032
bsalomon@google.com373a6632011-10-19 20:43:20 +000033 virtual void makeCurrent() const = 0;
34
bsalomon@google.com6e859372012-02-09 15:25:13 +000035 bool hasExtension(const char* extensionName) const;
36
bsalomon@google.com373a6632011-10-19 20:43:20 +000037protected:
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
51private:
bsalomon@google.com6e859372012-02-09 15:25:13 +000052 SkString fExtensionString;
bsalomon@google.com373a6632011-10-19 20:43:20 +000053 GrGLuint fFBO;
robertphillips@google.com7c959422012-03-22 20:43:56 +000054 GrGLuint fColorBufferID;
55 GrGLuint fDepthStencilBufferID;
bsalomon@google.com373a6632011-10-19 20:43:20 +000056 const GrGLInterface* fGL;
reed@google.comc31ce102010-12-21 16:26:39 +000057};
58
bsalomon@google.com373a6632011-10-19 20:43:20 +000059/**
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.com873cb1e2010-12-23 15:00:45 +000065#endif