2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-10-13 13:33:08 +00:00
|
|
|
#ifndef SkGLContext_DEFINED
|
|
|
|
#define SkGLContext_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
|
|
|
|
|
|
|
class SkGLContext : public SkRefCnt {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2011-10-13 13:33:08 +00:00
|
|
|
SkGLContext();
|
2011-10-19 20:43:20 +00:00
|
|
|
virtual ~SkGLContext();
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2011-10-24 21:17:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes the context and makes it current.
|
|
|
|
*/
|
2011-05-19 17:47:02 +00:00
|
|
|
bool init(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;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Subclass implements this to make a GL context. The returned GrGLInterface
|
|
|
|
* should be populated with functions compatible with the context. The
|
|
|
|
* format and size of backbuffers does not matter since an FBO will be
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
virtual const GrGLInterface* createGLContext() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclass should destroy the underlying GL context.
|
|
|
|
*/
|
|
|
|
virtual void destroyGLContext() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrGLuint fFBO;
|
|
|
|
const GrGLInterface* fGL;
|
2010-12-21 16:26:39 +00:00
|
|
|
};
|
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
/**
|
|
|
|
* Helper macro for using the GL context through the GrGLInterface. Example:
|
|
|
|
* SK_GL(glCtx, GenTextures(1, &texID));
|
|
|
|
*/
|
|
|
|
#define SK_GL(ctx, X) (ctx).gl()->f ## X
|
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
#endif
|