2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
2013-02-28 20:16:25 +00:00
|
|
|
* Copyright 2013 Google Inc.
|
2011-07-28 14:26:00 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-02-28 20:16:25 +00:00
|
|
|
#ifndef SkGLContextHelper_DEFINED
|
|
|
|
#define SkGLContextHelper_DEFINED
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
#include "GrGLInterface.h"
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
/**
|
2011-10-19 20:43:20 +00:00
|
|
|
* Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
|
|
|
|
* Provides a GrGLInterface struct of function pointers for the context.
|
2010-12-23 15:00:45 +00:00
|
|
|
*/
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2014-01-17 16:59:03 +00:00
|
|
|
class SK_API SkGLContextHelper : public SkRefCnt {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2013-02-28 20:16:25 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkGLContextHelper)
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2013-02-28 20:16:25 +00:00
|
|
|
SkGLContextHelper();
|
|
|
|
virtual ~SkGLContextHelper();
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2011-10-24 21:17:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes the context and makes it current.
|
|
|
|
*/
|
2014-06-30 13:36:31 +00:00
|
|
|
bool init(GrGLStandard forcedGpuAPI, const int width, const int height);
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2011-08-19 17:22:05 +00:00
|
|
|
int getFBOID() const { return fFBO; }
|
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
const GrGLInterface* gl() const { return fGL; }
|
2011-05-17 14:24:46 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
virtual void makeCurrent() const = 0;
|
|
|
|
|
2013-10-09 18:25:38 +00:00
|
|
|
/**
|
|
|
|
* The primary purpose of this function it to provide a means of scheduling
|
|
|
|
* work on the GPU (since all of the subclasses create primary buffers for
|
|
|
|
* testing that are small and not meant to be rendered to the screen).
|
|
|
|
*
|
|
|
|
* If the drawing surface provided by the platform is double buffered this
|
|
|
|
* call will cause the platform to swap which buffer is currently being
|
|
|
|
* targeted. If the current surface does not include a back buffer, this
|
|
|
|
* call has no effect.
|
|
|
|
*/
|
|
|
|
virtual void swapBuffers() const = 0;
|
|
|
|
|
2013-02-26 21:46:32 +00:00
|
|
|
bool hasExtension(const char* extensionName) const {
|
2013-08-17 00:02:59 +00:00
|
|
|
SkASSERT(NULL != fGL);
|
2014-01-17 15:05:38 +00:00
|
|
|
return fGL->hasExtension(extensionName);
|
2013-02-26 21:46:32 +00:00
|
|
|
}
|
2012-02-09 15:25:13 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
protected:
|
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* Subclass implements this to make a GL context. The returned GrGLInterface
|
|
|
|
* should be populated with functions compatible with the context. The
|
2011-10-19 20:43:20 +00:00
|
|
|
* format and size of backbuffers does not matter since an FBO will be
|
|
|
|
* created.
|
|
|
|
*/
|
2014-06-30 13:36:31 +00:00
|
|
|
virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) = 0;
|
2011-10-19 20:43:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclass should destroy the underlying GL context.
|
|
|
|
*/
|
|
|
|
virtual void destroyGLContext() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrGLuint fFBO;
|
2012-03-22 20:43:56 +00:00
|
|
|
GrGLuint fColorBufferID;
|
|
|
|
GrGLuint fDepthStencilBufferID;
|
2011-10-19 20:43:20 +00:00
|
|
|
const GrGLInterface* fGL;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2010-12-21 16:26:39 +00:00
|
|
|
};
|
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
/**
|
2013-02-07 19:45:46 +00:00
|
|
|
* Helper macros for using the GL context through the GrGLInterface. Example:
|
2011-10-19 20:43:20 +00:00
|
|
|
* SK_GL(glCtx, GenTextures(1, &texID));
|
|
|
|
*/
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
|
2014-07-01 14:20:11 +00:00
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
|
2014-07-01 14:20:11 +00:00
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X
|
|
|
|
#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
#endif
|