blob: b8b6b6e85d12c974c787592baffbb5d5d02ca1c5 [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:
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000021 SK_DECLARE_INST_COUNT(SkGLContext)
22
bsalomon@google.come2953132011-10-13 13:33:08 +000023 SkGLContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000024 virtual ~SkGLContext();
reed@google.comc31ce102010-12-21 16:26:39 +000025
bsalomon@google.com57f5d982011-10-24 21:17:53 +000026 /**
27 * Initializes the context and makes it current.
28 */
bungeman@google.com0e454412011-05-19 17:47:02 +000029 bool init(const int width, const int height);
reed@google.comc31ce102010-12-21 16:26:39 +000030
bsalomon@google.com971d0c82011-08-19 17:22:05 +000031 int getFBOID() const { return fFBO; }
32
bsalomon@google.com373a6632011-10-19 20:43:20 +000033 const GrGLInterface* gl() const { return fGL; }
bungeman@google.com16bab872011-05-17 14:24:46 +000034
bsalomon@google.com373a6632011-10-19 20:43:20 +000035 virtual void makeCurrent() const = 0;
36
bsalomon@google.com6e859372012-02-09 15:25:13 +000037 bool hasExtension(const char* extensionName) const;
38
bsalomon@google.com373a6632011-10-19 20:43:20 +000039protected:
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
53private:
bsalomon@google.com6e859372012-02-09 15:25:13 +000054 SkString fExtensionString;
bsalomon@google.com373a6632011-10-19 20:43:20 +000055 GrGLuint fFBO;
robertphillips@google.com7c959422012-03-22 20:43:56 +000056 GrGLuint fColorBufferID;
57 GrGLuint fDepthStencilBufferID;
bsalomon@google.com373a6632011-10-19 20:43:20 +000058 const GrGLInterface* fGL;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000059
60 typedef SkRefCnt INHERITED;
reed@google.comc31ce102010-12-21 16:26:39 +000061};
62
bsalomon@google.com373a6632011-10-19 20:43:20 +000063/**
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.com873cb1e2010-12-23 15:00:45 +000069#endif