3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
8 #ifndef SkGLContextHelper_DEFINED
9 #define SkGLContextHelper_DEFINED
11 #include "GrGLInterface.h"
14 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
15 * Provides a GrGLInterface struct of function pointers for the context.
18 class SK_API SkGLContextHelper : public SkRefCnt {
20 SK_DECLARE_INST_COUNT(SkGLContextHelper)
23 virtual ~SkGLContextHelper();
26 * Initializes the context and makes it current.
28 bool init(GrGLStandard forcedGpuAPI, const int width, const int height);
30 int getFBOID() const { return fFBO; }
32 const GrGLInterface* gl() const { return fGL; }
34 virtual void makeCurrent() const = 0;
37 * The primary purpose of this function it to provide a means of scheduling
38 * work on the GPU (since all of the subclasses create primary buffers for
39 * testing that are small and not meant to be rendered to the screen).
41 * If the drawing surface provided by the platform is double buffered this
42 * call will cause the platform to swap which buffer is currently being
43 * targeted. If the current surface does not include a back buffer, this
46 virtual void swapBuffers() const = 0;
48 bool hasExtension(const char* extensionName) const {
50 return fGL->hasExtension(extensionName);
54 * This notifies the context that we are deliberately testing abandoning
55 * the context. It is useful for debugging contexts that would otherwise
56 * test that GPU resources are properly deleted. It also allows a debugging
57 * context to test that further GL calls are not made by Skia GPU code.
63 * Subclass implements this to make a GL context. The returned GrGLInterface
64 * should be populated with functions compatible with the context. The
65 * format and size of backbuffers does not matter since an FBO will be
68 virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) = 0;
71 * Subclass should destroy the underlying GL context.
73 virtual void destroyGLContext() = 0;
77 GrGLuint fColorBufferID;
78 GrGLuint fDepthStencilBufferID;
79 const GrGLInterface* fGL;
81 typedef SkRefCnt INHERITED;
85 * Helper macros for using the GL context through the GrGLInterface. Example:
86 * SK_GL(glCtx, GenTextures(1, &texID));
88 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
89 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
90 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
91 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
92 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X
93 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X