////////////////////////////////////////////////////////////////////////////////
-extern void GrGLCheckErr(const char* location, const char* call);
+struct GrGLInterface;
-extern void GrGLClearErr();
+extern void GrGLCheckErr(const GrGLInterface* gl,
+ const char* location,
+ const char* call);
+
+extern void GrGLClearErr(const GrGLInterface* gl);
#if GR_GL_CHECK_ERROR
extern bool gCheckErrorGL;
- #define GR_GL_CHECK_ERROR_IMPL(X) if (gCheckErrorGL) GrGLCheckErr(GR_FILE_AND_LINE_STR, #X)
+ #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
+ if (gCheckErrorGL) \
+ GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
#else
- #define GR_GL_CHECK_ERROR_IMPL(X)
+ #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
#endif
#if GR_GL_LOG_CALLS
extern bool gLogCallsGL;
- #define GR_GL_LOG_CALLS_IMPL(X) if (gLogCallsGL) GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
+ #define GR_GL_LOG_CALLS_IMPL(X)
+ if (gLogCallsGL) \
+ GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
#else
#define GR_GL_LOG_CALLS_IMPL(X)
#endif
-#define GR_GL(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X); GR_GL_CHECK_ERROR_IMPL(X);
-#define GR_GL_NO_ERR(X) GrGLGetGLInterface()->f##X;; GR_GL_LOG_CALLS_IMPL(X);
+#define GR_GL_CALL(IFACE, X) \
+ GR_GL_CALL_NOERRCHECK(IFACE, X) \
+ GR_GL_CHECK_ERROR_IMPL(IFACE, X)
+
+#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
+ IFACE->f##X; \
+ GR_GL_LOG_CALLS_IMPL(X);
-#define GR_GL_SUPPORT_DESKTOP (kDesktop_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES1 (kES1_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES2 (kES2_GrGLBinding == GrGLGetGLInterface()->fBindingsExported)
-#define GR_GL_SUPPORT_ES (GR_GL_SUPPORT_ES1 || GR_GL_SUPPORT_ES2)
+#define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError()
////////////////////////////////////////////////////////////////////////////////
/**
- * GrGLRestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
+ * GrGLResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
* this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
*/
-extern void GrGLRestoreResetRowLength();
+extern void GrGLResetRowLength(const GrGLInterface*);
////////////////////////////////////////////////////////////////////////////////
* Some drivers want the var-int arg to be zero-initialized on input.
*/
#define GR_GL_INIT_ZERO 0
-#define GR_GL_GetIntegerv(e, p) \
+#define GR_GL_GetIntegerv(gl, e, p) \
do { \
*(p) = GR_GL_INIT_ZERO; \
- GR_GL(GetIntegerv(e, p)); \
+ GR_GL_CALL(gl, GetIntegerv(e, p)); \
} while (0)
-#define GR_GL_GetFramebufferAttachmentParameteriv(t, a, pname, p) \
- do { \
- *(p) = GR_GL_INIT_ZERO; \
- GR_GL(GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
+#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
} while (0)
-#define GR_GL_GetRenderbufferParameteriv(t, pname, p) \
- do { \
- *(p) = GR_GL_INIT_ZERO; \
- GR_GL(GetRenderbufferParameteriv(t, pname, p)); \
+#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
} while (0)
-#define GR_GL_GetTexLevelParameteriv(t, l, pname, p) \
- do { \
- *(p) = GR_GL_INIT_ZERO; \
- GR_GL(GetTexLevelParameteriv(t, l, pname, p)); \
+#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
} while (0)
////////////////////////////////////////////////////////////////////////////////
#define GrGLInterface_DEFINED
#include "GrGLConfig.h"
-#include "GrTypes.h"
+#include "GrRefCnt.h"
#if !defined(GR_GL_FUNCTION_TYPE)
#define GR_GL_FUNCTION_TYPE
const char* extensionString);
// these variants call glGetString()
-bool has_gl_extension(const char* ext);
-void gl_version(int* major, int* minor);
-float gl_version_as_float();
+bool has_gl_extension(const GrGLInterface*, const char* ext);
+void gl_version(const GrGLInterface*, int* major, int* minor);
+float gl_version_as_float(const GrGLInterface*);
////////////////////////////////////////////////////////////////////////////////
-/*
- * Routines managing the global interface used to invoke OpenGL calls.
+/**
+ * Rather than depend on platform-specific GL headers and libraries, we require
+ * the client to provide a struct of GL function pointers. This struct can be
+ * specified per-GrContext as a parameter to GrContext::Create. If NULL is
+ * passed to Create then the "default" GL interface is used. If the default is
+ * also NULL GrContext creation will fail.
+ *
+ * The default interface is specified by calling GrGLSetDefaultInterface. If
+ * this function hasn't been called or was last called with NULL then
+ * GrGLInitializeDefaultGLInterface will be called to attempt to initialize it.
+ * There are several implementations of this function provided. Each builds a
+ * GrGLInterface for a specific platform and sets it as the default. There is
+ * also an implementation that does nothing. You can link in any of the provided
+ * implementations or your own implementation that sets up the GL function
+ * pointers for your specific platform.
*/
+
struct GrGLInterface;
-GR_API GrGLInterface* GrGLGetGLInterface();
-GR_API void GrGLSetGLInterface(GrGLInterface* gl_interface);
-/*
- * This is called when GrGLSetGLInterface() hasn't been called before creating
- * a GrGpuGL object. It provides a default implementation. The actual
- * implementation depends on which GrGLDefaultInterface_*.cpp has been linked.
- * There are some platform-specific implementations provided as well as
- * GrGLDefaultInterface_none.cpp which does nothing (effectively requiring an
- * explicit GrGLSetGLInterface call by the host).
- */
-void GrGLSetDefaultGLInterface();
+GR_API const GrGLInterface* GrGLGetDefaultGLInterface();
+// returns param so that you can unref it
+GR_API const GrGLInterface* GrGLSetDefaultGLInterface(const GrGLInterface* gl_interface);
+
+// If this is implemented it must allocate a GrGLInterface on the heap because
+// GrGLInterface subclasses SkRefCnt.
+void GrGLInitializeDefaultGLInterface();
typedef unsigned int GrGLenum;
typedef unsigned char GrGLboolean;
* functions, and extensions. The system assumes that the address of the
* extension pointer will be valid across contexts.
*/
-struct GrGLInterface {
+struct GR_API GrGLInterface : public GrRefCnt {
+
+ GrGLInterface();
+
bool validate(GrEngine engine) const;
+ bool supportsDesktop() const {
+ return 0 != (kDesktop_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES1() const {
+ return 0 != (kES1_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES2() const {
+ return 0 != (kES2_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES() const {
+ return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
+ fBindingsExported);
+ }
// Indicator variable specifying the type of GL implementation
// exported: GLES{1|2} or Desktop.
// Dual Source Blending
GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
- // Code that initializes this struct using a static initializer should
- // make this the last entry in the static initializer. It can help to guard
- // against failing to initialize newly-added members of this struct.
- enum { kStaticInitEndGuard } fStaticInitEndGuard;
-
private:
bool validateShaderFunctions() const;
bool validateFixedFunctions() const;
enum GrEngine {
kOpenGL_Shaders_GrEngine,
kOpenGL_Fixed_GrEngine,
- kDirect3D9_GrEngine
};
/**
* Engine-specific 3D context handle
- * Unused for GL.
- * IDirect3DDevice9* for D3D9
+ * GrGLInterface* for OpenGL. If NULL will use the default GL interface.
*/
typedef intptr_t GrPlatform3DContext;
*/
-void GrGLSetDefaultGLInterface() {
+void GrGLInitializeDefaultGLInterface() {
}
GrGLsizei fWidth;
GrGLsizei fHeight;
- void pushToGLViewport() const {
- GR_GL(Viewport(fLeft, fBottom, fWidth, fHeight));
+ void pushToGLViewport(const GrGLInterface* gl) const {
+ GR_GL_CALL(gl, Viewport(fLeft, fBottom, fWidth, fHeight));
}
- void pushToGLScissor() const {
- GR_GL(Scissor(fLeft, fBottom, fWidth, fHeight));
+ void pushToGLScissor(const GrGLInterface* gl) const {
+ GR_GL_CALL(gl, Scissor(fLeft, fBottom, fWidth, fHeight));
}
- void setFromGLViewport() {
+ void setFromGLViewport(const GrGLInterface* gl) {
GR_STATIC_ASSERT(sizeof(GrGLIRect) == 4*sizeof(GrGLint));
- GR_GL_GetIntegerv(GR_GL_VIEWPORT, (GrGLint*) this);
+ GR_GL_GetIntegerv(gl, GR_GL_VIEWPORT, (GrGLint*) this);
}
// sometimes we have a GrIRect from the client that we
#define GPUGL static_cast<GrGpuGL*>(getGpu())
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
GrGLIndexBuffer::GrGLIndexBuffer(GrGpuGL* gpu,
GrGLuint id,
size_t sizeInBytes,
// make sure we've not been abandoned
if (fBufferID) {
GPUGL->notifyIndexBufferDelete(this);
- GR_GL(DeleteBuffers(1, &fBufferID));
+ GL_CALL(DeleteBuffers(1, &fBufferID));
fBufferID = 0;
}
}
}
void GrGLIndexBuffer::bind() const {
- GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, fBufferID));
+ GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, fBufferID));
GPUGL->notifyIndexBufferBind(this);
}
if (GPUGL->supportsBufferLocking()) {
this->bind();
// Let driver know it can discard the old data
- GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, this->sizeInBytes(), NULL,
- this->dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
- fLockPtr = GR_GL(MapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
+ GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+ this->sizeInBytes(),
+ NULL,
+ this->dynamic() ? GR_GL_DYNAMIC_DRAW :
+ GR_GL_STATIC_DRAW));
+ fLockPtr = GL_CALL(MapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER,
+ GR_GL_WRITE_ONLY));
return fLockPtr;
}
GrAssert(GPUGL->supportsBufferLocking());
this->bind();
- GR_GL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER));
+ GL_CALL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER));
fLockPtr = NULL;
}
if (this->isValid() && GPUGL->supportsBufferLocking()) {
this->bind();
GrGLint mapped;
- GR_GL(GetBufferParameteriv(GR_GL_ELEMENT_ARRAY_BUFFER,
- GR_GL_BUFFER_MAPPED, &mapped));
+ GL_CALL(GetBufferParameteriv(GR_GL_ELEMENT_ARRAY_BUFFER,
+ GR_GL_BUFFER_MAPPED, &mapped));
GrAssert(!!mapped == !!fLockPtr);
}
#endif
this->bind();
GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
if (this->sizeInBytes() == srcSizeInBytes) {
- GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, srcSizeInBytes, src, usage));
+ GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+ srcSizeInBytes, src, usage));
} else {
#if GR_GL_USE_BUFFER_DATA_NULL_HINT
- GR_GL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, this->sizeInBytes(), NULL, usage));
+ GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+ this->sizeInBytes(), NULL, usage));
#endif
- GR_GL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER, 0, srcSizeInBytes, src));
+ GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
+ 0, srcSizeInBytes, src));
}
return true;
}
return false;
}
this->bind();
- GR_GL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER, offset, srcSizeInBytes, src));
+ GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
+ offset, srcSizeInBytes, src));
return true;
}
*/
-
#include "GrTypes.h"
#include "GrGLInterface.h"
#include "GrGLDefines.h"
#include <stdio.h>
-GrGLInterface* gGLInterface = NULL;
+static SkAutoTUnref<const GrGLInterface> gDefaultGLInterface;
void gl_version_from_string(int* major, int* minor,
const char* versionString) {
return false;
}
-GR_API void GrGLSetGLInterface(GrGLInterface* gl_interface) {
- gGLInterface = gl_interface;
+GR_API const GrGLInterface* GrGLSetDefaultGLInterface(const GrGLInterface* gl_interface) {
+ gl_interface->ref();
+ gDefaultGLInterface.reset(gl_interface);
+ return gl_interface;
}
-GR_API GrGLInterface* GrGLGetGLInterface() {
- return gGLInterface;
+GR_API const GrGLInterface* GrGLGetDefaultGLInterface() {
+ if (NULL == gDefaultGLInterface.get()) {
+ GrGLInitializeDefaultGLInterface();
+ }
+ return gDefaultGLInterface.get();
}
-bool has_gl_extension(const char* ext) {
+bool has_gl_extension(const GrGLInterface* gl, const char* ext) {
const char* glstr = reinterpret_cast<const char*>(
- GrGLGetGLInterface()->fGetString(GR_GL_EXTENSIONS));
+ gl->fGetString(GR_GL_EXTENSIONS));
return has_gl_extension_from_string(ext, glstr);
}
-void gl_version(int* major, int* minor) {
+void gl_version(const GrGLInterface* gl, int* major, int* minor) {
const char* v = reinterpret_cast<const char*>(
- GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
+ gl->fGetString(GR_GL_VERSION));
gl_version_from_string(major, minor, v);
}
-float gl_version_as_float() {
+float gl_version_as_float(const GrGLInterface* gl) {
const char* v = reinterpret_cast<const char*>(
- GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
+ gl->fGetString(GR_GL_VERSION));
return gl_version_as_float_from_string(v);
}
+GrGLInterface::GrGLInterface() {
+ fBindingsExported = (GrGLBinding)0;
+ fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+ fMinRenderTargetHeight = kProbe_GrGLCapability;
+ fMinRenderTargetWidth = kProbe_GrGLCapability;
+
+ fActiveTexture = NULL;
+ fAttachShader = NULL;
+ fBindAttribLocation = NULL;
+ fBindBuffer = NULL;
+ fBindTexture = NULL;
+ fBlendColor = NULL;
+ fBlendFunc = NULL;
+ fBufferData = NULL;
+ fBufferSubData = NULL;
+ fClear = NULL;
+ fClearColor = NULL;
+ fClearStencil = NULL;
+ fClientActiveTexture = NULL;
+ fColor4ub = NULL;
+ fColorMask = NULL;
+ fColorPointer = NULL;
+ fCompileShader = NULL;
+ fCompressedTexImage2D = NULL;
+ fCreateProgram = NULL;
+ fCreateShader = NULL;
+ fCullFace = NULL;
+ fDeleteBuffers = NULL;
+ fDeleteProgram = NULL;
+ fDeleteShader = NULL;
+ fDeleteTextures = NULL;
+ fDepthMask = NULL;
+ fDisable = NULL;
+ fDisableClientState = NULL;
+ fDisableVertexAttribArray = NULL;
+ fDrawArrays = NULL;
+ fDrawBuffer = NULL;
+ fDrawBuffers = NULL;
+ fDrawElements = NULL;
+ fEnable = NULL;
+ fEnableClientState = NULL;
+ fEnableVertexAttribArray = NULL;
+ fFrontFace = NULL;
+ fGenBuffers = NULL;
+ fGenTextures = NULL;
+ fGetBufferParameteriv = NULL;
+ fGetError = NULL;
+ fGetIntegerv = NULL;
+ fGetProgramInfoLog = NULL;
+ fGetProgramiv = NULL;
+ fGetShaderInfoLog = NULL;
+ fGetShaderiv = NULL;
+ fGetString = NULL;
+ fGetTexLevelParameteriv = NULL;
+ fGetUniformLocation = NULL;
+ fLineWidth = NULL;
+ fLinkProgram = NULL;
+ fLoadMatrixf = NULL;
+ fMatrixMode = NULL;
+ fPixelStorei = NULL;
+ fPointSize = NULL;
+ fReadBuffer = NULL;
+ fReadPixels = NULL;
+ fScissor = NULL;
+ fShadeModel = NULL;
+ fShaderSource = NULL;
+ fStencilFunc = NULL;
+ fStencilFuncSeparate = NULL;
+ fStencilMask = NULL;
+ fStencilMaskSeparate = NULL;
+ fStencilOp = NULL;
+ fStencilOpSeparate = NULL;
+ fTexCoordPointer = NULL;
+ fTexEnvi = NULL;
+ fTexImage2D = NULL;
+ fTexParameteri = NULL;
+ fTexSubImage2D = NULL;
+ fUniform1f = NULL;
+ fUniform1i = NULL;
+ fUniform1fv = NULL;
+ fUniform1iv = NULL;
+ fUniform2f = NULL;
+ fUniform2i = NULL;
+ fUniform2fv = NULL;
+ fUniform2iv = NULL;
+ fUniform3f = NULL;
+ fUniform3i = NULL;
+ fUniform3fv = NULL;
+ fUniform3iv = NULL;
+ fUniform4f = NULL;
+ fUniform4i = NULL;
+ fUniform4fv = NULL;
+ fUniform4iv = NULL;
+ fUniformMatrix2fv = NULL;
+ fUniformMatrix3fv = NULL;
+ fUniformMatrix4fv = NULL;
+ fUseProgram = NULL;
+ fVertexAttrib4fv = NULL;
+ fVertexAttribPointer = NULL;
+ fVertexPointer = NULL;
+ fViewport = NULL;
+ fBindFramebuffer = NULL;
+ fBindRenderbuffer = NULL;
+ fCheckFramebufferStatus = NULL;
+ fDeleteFramebuffers = NULL;
+ fDeleteRenderbuffers = NULL;
+ fFramebufferRenderbuffer = NULL;
+ fFramebufferTexture2D = NULL;
+ fGenFramebuffers = NULL;
+ fGenRenderbuffers = NULL;
+ fGetFramebufferAttachmentParameteriv = NULL;
+ fGetRenderbufferParameteriv = NULL;
+ fRenderbufferStorage = NULL;
+ fRenderbufferStorageMultisample = NULL;
+ fBlitFramebuffer = NULL;
+ fResolveMultisampleFramebuffer = NULL;
+ fMapBuffer = NULL;
+ fUnmapBuffer = NULL;
+ fBindFragDataLocationIndexed = NULL;
+}
+
+
bool GrGLInterface::validateShaderFunctions() const {
// required for GrGpuGLShaders
if (NULL == fAttachShader ||
bool GrGLInterface::validate(GrEngine engine) const {
- bool isDesktop = kDesktop_GrGLBinding == fBindingsExported;
+ bool isDesktop = this->supportsDesktop();
- // ES1 and 2 can be supported in the same interface
- bool isES = ((kES1_GrGLBinding | kES2_GrGLBinding) & fBindingsExported &&
- !(~(kES1_GrGLBinding | kES2_GrGLBinding) & fBindingsExported));
+ bool isES = this->supportsES();
- if (!isDesktop && !isES) {
+ if (isDesktop == isES) {
+ // must have one, don't support both in same interface
return false;
}
int major, minor;
const char* ext;
- gl_version(&major, &minor);
+ gl_version(this, &major, &minor);
ext = (const char*)fGetString(GR_GL_EXTENSIONS);
// Now check that baseline ES/Desktop fns not covered above are present
namespace {
-const char* GrPrecision() {
- if (GR_GL_SUPPORT_ES2) {
+const char* GrPrecision(const GrGLInterface* gl) {
+ if (gl->supportsES()) {
return "mediump";
} else {
return " ";
}
}
-const char* GrShaderPrecision() {
- if (GR_GL_SUPPORT_ES2) {
+const char* GrShaderPrecision(const GrGLInterface* gl) {
+ if (gl->supportsES()) {
return "precision mediump float;\n";
} else {
return "";
add_helper(outputVar, colorStr.c_str(), constStr.c_str(), fsCode);
}
-bool GrGLProgram::genProgram(GrGLProgram::CachedData* programData) const {
+bool GrGLProgram::genProgram(const GrGLInterface* gl,
+ GrGLProgram::CachedData* programData) const {
ShaderCodeSegments segments;
const uint32_t& layout = fProgramDesc.fVertexLayout;
inCoords = texCoordAttrs[tcIdx].c_str();
}
- genStageCode(s,
+ genStageCode(gl, s,
fProgramDesc.fStages[s],
inColor.size() ? inColor.c_str() : NULL,
outColor.c_str(),
inCoords = texCoordAttrs[tcIdx].c_str();
}
- genStageCode(s,
+ genStageCode(gl, s,
fProgramDesc.fStages[s],
inCoverage.size() ? inCoverage.c_str() : NULL,
outCoverage.c_str(),
///////////////////////////////////////////////////////////////////////////
// compile and setup attribs and unis
- if (!CompileFSAndVS(segments, programData)) {
+ if (!CompileFSAndVS(gl, segments, programData)) {
return false;
}
- if (!this->bindOutputsAttribsAndLinkProgram(texCoordAttrs,
+ if (!this->bindOutputsAttribsAndLinkProgram(gl, texCoordAttrs,
usingDeclaredOutputs,
dualSourceOutputWritten,
programData)) {
return false;
}
- this->getUniformLocationsAndInitCache(programData);
+ this->getUniformLocationsAndInitCache(gl, programData);
return true;
}
-bool GrGLProgram::CompileFSAndVS(const ShaderCodeSegments& segments,
+bool GrGLProgram::CompileFSAndVS(const GrGLInterface* gl,
+ const ShaderCodeSegments& segments,
CachedData* programData) {
static const int MAX_STRINGS = 6;
GrPrintf("\n");
#endif
GrAssert(stringCnt <= MAX_STRINGS);
- programData->fVShaderID = CompileShader(GR_GL_VERTEX_SHADER,
- stringCnt,
- strings,
- lengths);
+ programData->fVShaderID = CompileShader(gl, GR_GL_VERTEX_SHADER,
+ stringCnt, strings, lengths);
if (!programData->fVShaderID) {
return false;
lengths[stringCnt] = segments.fHeader.size();
++stringCnt;
}
- if (strlen(GrShaderPrecision()) > 1) {
- strings[stringCnt] = GrShaderPrecision();
- lengths[stringCnt] = strlen(GrShaderPrecision());
+ if (strlen(GrShaderPrecision(gl)) > 1) {
+ strings[stringCnt] = GrShaderPrecision(gl);
+ lengths[stringCnt] = strlen(GrShaderPrecision(gl));
++stringCnt;
}
if (segments.fFSUnis.size()) {
#if PRINT_SHADERS
GrPrintf(segments.fHeader.c_str());
- GrPrintf(GrShaderPrecision());
+ GrPrintf(GrShaderPrecision(gl));
GrPrintf(segments.fFSUnis.c_str());
GrPrintf(segments.fVaryings.c_str());
GrPrintf(segments.fFSOutputs.c_str());
GrPrintf("\n");
#endif
GrAssert(stringCnt <= MAX_STRINGS);
- programData->fFShaderID = CompileShader(GR_GL_FRAGMENT_SHADER,
- stringCnt,
- strings,
- lengths);
+ programData->fFShaderID = CompileShader(gl, GR_GL_FRAGMENT_SHADER,
+ stringCnt, strings, lengths);
if (!programData->fFShaderID) {
return false;
return true;
}
-GrGLuint GrGLProgram::CompileShader(GrGLenum type,
- int stringCnt,
- const char** strings,
- int* stringLengths) {
+GrGLuint GrGLProgram::CompileShader(const GrGLInterface* gl,
+ GrGLenum type,
+ int stringCnt,
+ const char** strings,
+ int* stringLengths) {
SK_TRACE_EVENT1("GrGLProgram::CompileShader",
"stringCount", SkStringPrintf("%i", stringCnt).c_str());
- GrGLuint shader = GR_GL(CreateShader(type));
+ GrGLuint shader = GR_GL_CALL(gl, CreateShader(type));
if (0 == shader) {
return 0;
}
GrGLint compiled = GR_GL_INIT_ZERO;
- GR_GL(ShaderSource(shader, stringCnt, strings, stringLengths));
- GR_GL(CompileShader(shader));
- GR_GL(GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled));
+ GR_GL_CALL(gl, ShaderSource(shader, stringCnt, strings, stringLengths));
+ GR_GL_CALL(gl, CompileShader(shader));
+ GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &compiled));
if (!compiled) {
GrGLint infoLen = GR_GL_INIT_ZERO;
- GR_GL(GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
+ GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
if (infoLen > 0) {
- GR_GL(GetShaderInfoLog(shader, infoLen+1, NULL, (char*)log.get()));
+ GR_GL_CALL(gl, GetShaderInfoLog(shader, infoLen+1,
+ NULL, (char*)log.get()));
for (int i = 0; i < stringCnt; ++i) {
if (NULL == stringLengths || stringLengths[i] < 0) {
GrPrintf(strings[i]);
GrPrintf("\n%s", log.get());
}
GrAssert(!"Shader compilation failed!");
- GR_GL(DeleteShader(shader));
+ GR_GL_CALL(gl, DeleteShader(shader));
return 0;
}
return shader;
}
bool GrGLProgram::bindOutputsAttribsAndLinkProgram(
+ const GrGLInterface* gl,
GrStringBuilder texCoordAttrNames[],
bool bindColorOut,
bool bindDualSrcOut,
CachedData* programData) const {
- programData->fProgramID = GR_GL(CreateProgram());
+ programData->fProgramID = GR_GL_CALL(gl, CreateProgram());
if (!programData->fProgramID) {
return false;
}
const GrGLint& progID = programData->fProgramID;
- GR_GL(AttachShader(progID, programData->fVShaderID));
- GR_GL(AttachShader(progID, programData->fFShaderID));
+ GR_GL_CALL(gl, AttachShader(progID, programData->fVShaderID));
+ GR_GL_CALL(gl, AttachShader(progID, programData->fFShaderID));
if (bindColorOut) {
- GR_GL(BindFragDataLocationIndexed(programData->fProgramID,
+ GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
0, 0, declared_color_output_name()));
}
if (bindDualSrcOut) {
- GR_GL(BindFragDataLocationIndexed(programData->fProgramID,
+ GR_GL_CALL(gl, BindFragDataLocationIndexed(programData->fProgramID,
0, 1, dual_source_output_name()));
}
// Bind the attrib locations to same values for all shaders
- GR_GL(BindAttribLocation(progID, PositionAttributeIdx(), POS_ATTR_NAME));
+ GR_GL_CALL(gl, BindAttribLocation(progID, PositionAttributeIdx(),
+ POS_ATTR_NAME));
for (int t = 0; t < GrDrawTarget::kMaxTexCoords; ++t) {
if (texCoordAttrNames[t].size()) {
- GR_GL(BindAttribLocation(progID,
- TexCoordAttributeIdx(t),
- texCoordAttrNames[t].c_str()));
+ GR_GL_CALL(gl, BindAttribLocation(progID,
+ TexCoordAttributeIdx(t),
+ texCoordAttrNames[t].c_str()));
}
}
if (kSetAsAttribute == programData->fUniLocations.fViewMatrixUni) {
- GR_GL(BindAttribLocation(progID,
- ViewMatrixAttributeIdx(),
- VIEW_MATRIX_NAME));
+ GR_GL_CALL(gl, BindAttribLocation(progID,
+ ViewMatrixAttributeIdx(),
+ VIEW_MATRIX_NAME));
}
for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
if (kSetAsAttribute == unis.fTextureMatrixUni) {
GrStringBuilder matName;
tex_matrix_name(s, &matName);
- GR_GL(BindAttribLocation(progID,
- TextureMatrixAttributeIdx(s),
- matName.c_str()));
+ GR_GL_CALL(gl, BindAttribLocation(progID,
+ TextureMatrixAttributeIdx(s),
+ matName.c_str()));
}
}
- GR_GL(BindAttribLocation(progID, ColorAttributeIdx(), COL_ATTR_NAME));
+ GR_GL_CALL(gl, BindAttribLocation(progID, ColorAttributeIdx(),
+ COL_ATTR_NAME));
- GR_GL(LinkProgram(progID));
+ GR_GL_CALL(gl, LinkProgram(progID));
GrGLint linked = GR_GL_INIT_ZERO;
- GR_GL(GetProgramiv(progID, GR_GL_LINK_STATUS, &linked));
+ GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_LINK_STATUS, &linked));
if (!linked) {
GrGLint infoLen = GR_GL_INIT_ZERO;
- GR_GL(GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
+ GR_GL_CALL(gl, GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
if (infoLen > 0) {
- GR_GL(GetProgramInfoLog(progID,
- infoLen+1,
- NULL,
- (char*)log.get()));
+ GR_GL_CALL(gl, GetProgramInfoLog(progID, infoLen+1,
+ NULL, (char*)log.get()));
GrPrintf((char*)log.get());
}
GrAssert(!"Error linking program");
- GR_GL(DeleteProgram(progID));
+ GR_GL_CALL(gl, DeleteProgram(progID));
programData->fProgramID = 0;
return false;
}
return true;
}
-void GrGLProgram::getUniformLocationsAndInitCache(CachedData* programData) const {
+void GrGLProgram::getUniformLocationsAndInitCache(const GrGLInterface* gl,
+ CachedData* programData) const {
const GrGLint& progID = programData->fProgramID;
if (kUseUniform == programData->fUniLocations.fViewMatrixUni) {
programData->fUniLocations.fViewMatrixUni =
- GR_GL(GetUniformLocation(progID, VIEW_MATRIX_NAME));
+ GR_GL_CALL(gl, GetUniformLocation(progID, VIEW_MATRIX_NAME));
GrAssert(kUnusedUniform != programData->fUniLocations.fViewMatrixUni);
}
if (kUseUniform == programData->fUniLocations.fColorUni) {
programData->fUniLocations.fColorUni =
- GR_GL(GetUniformLocation(progID, COL_UNI_NAME));
+ GR_GL_CALL(gl, GetUniformLocation(progID, COL_UNI_NAME));
GrAssert(kUnusedUniform != programData->fUniLocations.fColorUni);
}
if (kUseUniform == programData->fUniLocations.fColorFilterUni) {
programData->fUniLocations.fColorFilterUni =
- GR_GL(GetUniformLocation(progID, COL_FILTER_UNI_NAME));
+ GR_GL_CALL(gl, GetUniformLocation(progID, COL_FILTER_UNI_NAME));
GrAssert(kUnusedUniform != programData->fUniLocations.fColorFilterUni);
}
if (kUseUniform == programData->fUniLocations.fEdgesUni) {
programData->fUniLocations.fEdgesUni =
- GR_GL(GetUniformLocation(progID, EDGES_UNI_NAME));
+ GR_GL_CALL(gl, GetUniformLocation(progID, EDGES_UNI_NAME));
GrAssert(kUnusedUniform != programData->fUniLocations.fEdgesUni);
} else {
programData->fUniLocations.fEdgesUni = kUnusedUniform;
if (kUseUniform == locations.fTextureMatrixUni) {
GrStringBuilder texMName;
tex_matrix_name(s, &texMName);
- locations.fTextureMatrixUni = GR_GL(GetUniformLocation(
- progID,
- texMName.c_str()));
+ locations.fTextureMatrixUni =
+ GR_GL_CALL(gl, GetUniformLocation(progID, texMName.c_str()));
GrAssert(kUnusedUniform != locations.fTextureMatrixUni);
}
if (kUseUniform == locations.fSamplerUni) {
GrStringBuilder samplerName;
sampler_name(s, &samplerName);
- locations.fSamplerUni = GR_GL(GetUniformLocation(
- progID,
- samplerName.c_str()));
+ locations.fSamplerUni =
+ GR_GL_CALL(gl, GetUniformLocation(progID,
+ samplerName.c_str()));
GrAssert(kUnusedUniform != locations.fSamplerUni);
}
GrStringBuilder texelSizeName;
normalized_texel_size_name(s, &texelSizeName);
locations.fNormalizedTexelSizeUni =
- GR_GL(GetUniformLocation(progID, texelSizeName.c_str()));
+ GR_GL_CALL(gl, GetUniformLocation(progID,
+ texelSizeName.c_str()));
GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni);
}
if (kUseUniform == locations.fRadial2Uni) {
GrStringBuilder radial2ParamName;
radial2_param_name(s, &radial2ParamName);
- locations.fRadial2Uni = GR_GL(GetUniformLocation(
- progID,
- radial2ParamName.c_str()));
+ locations.fRadial2Uni =
+ GR_GL_CALL(gl, GetUniformLocation(progID,
+ radial2ParamName.c_str()));
GrAssert(kUnusedUniform != locations.fRadial2Uni);
}
if (kUseUniform == locations.fTexDomUni) {
GrStringBuilder texDomName;
tex_domain_name(s, &texDomName);
- locations.fTexDomUni = GR_GL(GetUniformLocation(
- progID,
- texDomName.c_str()));
+ locations.fTexDomUni =
+ GR_GL_CALL(gl, GetUniformLocation(progID,
+ texDomName.c_str()));
GrAssert(kUnusedUniform != locations.fTexDomUni);
}
GrStringBuilder kernelName, imageIncrementName;
convolve_param_names(s, &kernelName, &imageIncrementName);
if (kUseUniform == locations.fKernelUni) {
- locations.fKernelUni = GR_GL(GetUniformLocation(
- progID,
- kernelName.c_str()));
+ locations.fKernelUni = GR_GL_CALL(gl, GetUniformLocation(
+ progID, kernelName.c_str()));
GrAssert(kUnusedUniform != locations.fKernelUni);
}
if (kUseUniform == locations.fImageIncrementUni) {
- locations.fImageIncrementUni = GR_GL(GetUniformLocation(
- progID,
- imageIncrementName.c_str()));
+ locations.fImageIncrementUni = GR_GL_CALL(gl, GetUniformLocation(progID,
+ imageIncrementName.c_str()));
GrAssert(kUnusedUniform != locations.fImageIncrementUni);
}
}
}
- GR_GL(UseProgram(progID));
+ GR_GL_CALL(gl, UseProgram(progID));
// init sampler unis and set bogus values for state tracking
for (int s = 0; s < GrDrawTarget::kNumStages; ++s) {
if (kUnusedUniform != programData->fUniLocations.fStages[s].fSamplerUni) {
- GR_GL(Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
+ GR_GL_CALL(gl, Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
}
programData->fTextureMatrices[s] = GrMatrix::InvalidMatrix();
programData->fRadial2CenterX1[s] = GR_ScalarMax;
// Stage code generation
//============================================================================
-void GrGLProgram::genStageCode(int stageNum,
+void GrGLProgram::genStageCode(const GrGLInterface* gl,
+ int stageNum,
const GrGLProgram::StageDesc& desc,
const char* fsInColor, // NULL means no incoming color
const char* fsOutColor,
StageDesc::kRadial2GradientDegenerate_CoordMapping == desc.fCoordMapping) {
segments->fVSUnis.appendf("uniform %s float %s[6];\n",
- GrPrecision(), radial2ParamsName.c_str());
+ GrPrecision(gl), radial2ParamsName.c_str());
segments->fFSUnis.appendf("uniform float %s[6];\n",
radial2ParamsName.c_str());
locations->fRadial2Uni = kUseUniform;
segments->fFSUnis.appendf("uniform vec2 %s;\n",
imageIncrementName.c_str());
segments->fVSUnis.appendf("uniform %s vec2 %s;\n",
- GrPrecision(),
+ GrPrecision(gl),
imageIncrementName.c_str());
locations->fKernelUni = kUseUniform;
locations->fImageIncrementUni = kUseUniform;
* The result of heavy init is not stored in datamembers of GrGLProgam,
* but in a separate cacheable container.
*/
- bool genProgram(CachedData* programData) const;
+ bool genProgram(const GrGLInterface* gl,
+ CachedData* programData) const;
/**
* The shader may modify the blend coeffecients. Params are in/out
// should set all fields in locations var to kUseUniform if the
// corresponding uniform is required for the program.
- void genStageCode(int stageNum,
+ void genStageCode(const GrGLInterface* gl,
+ int stageNum,
const ProgramDesc::StageDesc& desc,
const char* fsInColor, // NULL means no incoming color
const char* fsOutColor,
ShaderCodeSegments* segments,
StageUniLocations* locations) const;
- static bool CompileFSAndVS(const ShaderCodeSegments& segments,
+ static bool CompileFSAndVS(const GrGLInterface* gl,
+ const ShaderCodeSegments& segments,
CachedData* programData);
// Compiles a GL shader, returns shader ID or 0 if failed
// params have same meaning as glShaderSource
- static GrGLuint CompileShader(GrGLenum type, int stringCnt,
+ static GrGLuint CompileShader(const GrGLInterface* gl,
+ GrGLenum type, int stringCnt,
const char** strings,
int* stringLengths);
// Creates a GL program ID, binds shader attributes to GL vertex attrs, and
// links the program
bool bindOutputsAttribsAndLinkProgram(
+ const GrGLInterface* gl,
GrStringBuilder texCoordAttrNames[GrDrawTarget::kMaxTexCoords],
bool bindColorOut,
bool bindDualSrcOut,
// Gets locations for all uniforms set to kUseUniform and initializes cache
// to invalid values.
- void getUniformLocationsAndInitCache(CachedData* programData) const;
+ void getUniformLocationsAndInitCache(const GrGLInterface* gl,
+ CachedData* programData) const;
friend class GrGpuGLShaders;
};
#define GPUGL static_cast<GrGpuGL*>(getGpu())
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
void GrGLRenderTarget::init(const Desc& desc,
const GrGLIRect& viewport,
GrGLTexID* texID) {
GPUGL->notifyRenderTargetDelete(this);
if (fOwnIDs) {
if (fTexFBOID) {
- GR_GL(DeleteFramebuffers(1, &fTexFBOID));
+ GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
}
if (fRTFBOID && fRTFBOID != fTexFBOID) {
- GR_GL(DeleteFramebuffers(1, &fRTFBOID));
+ GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
}
if (fMSColorRenderbufferID) {
- GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
+ GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
}
}
fRTFBOID = 0;
--- /dev/null
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "GrGLStencilBuffer.h"
+#include "GrGpuGL.h"
+
+GrGLStencilBuffer::~GrGLStencilBuffer() {
+ this->release();
+}
+
+size_t GrGLStencilBuffer::sizeInBytes() const {
+ uint64_t size = this->width();
+ size *= this->height();
+ size *= fFormat.fTotalBits;
+ size *= GrMax(1,this->numSamples());
+ return static_cast<size_t>(size / 8);
+}
+
+void GrGLStencilBuffer::onRelease() {
+ if (0 != fRenderbufferID) {
+ GrGpuGL* gpuGL = (GrGpuGL*) this->getGpu();
+ const GrGLInterface* gl = gpuGL->glInterface();
+ GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
+ fRenderbufferID = 0;
+ }
+ INHERITED::onRelease();
+}
+
+void GrGLStencilBuffer::onAbandon() {
+ fRenderbufferID = 0;
+ INHERITED::onAbandon();
+}
+
+
, fRenderbufferID(rbid) {
}
- virtual ~GrGLStencilBuffer() {
- this->release();
- }
+ virtual ~GrGLStencilBuffer();
- virtual size_t sizeInBytes() const {
- uint64_t size = this->width();
- size *= this->height();
- size *= fFormat.fTotalBits;
- size *= GrMax(1,this->numSamples());
- return (size_t)(size / 8);
- }
+ virtual size_t sizeInBytes() const;
GrGLuint renderbufferID() const {
return fRenderbufferID;
}
- const Format& format() const {
- return fFormat;
- }
+ const Format& format() const { return fFormat; }
protected:
- virtual void onRelease() {
- if (0 != fRenderbufferID) {
- GR_GL(DeleteRenderbuffers(1, &fRenderbufferID));
- fRenderbufferID = 0;
- }
- INHERITED::onRelease();
- }
+ virtual void onRelease();
- virtual void onAbandon() {
- fRenderbufferID = 0;
- INHERITED::onAbandon();
- }
+ virtual void onAbandon();
private:
Format fFormat;
#define GPUGL static_cast<GrGpuGL*>(getGpu())
-const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
+const GrGLenum* GrGLTexture::WrapMode2GLWrap(GrGLBinding binding) {
static const GrGLenum mirrorRepeatModes[] = {
GR_GL_CLAMP_TO_EDGE,
GR_GL_REPEAT,
GR_GL_REPEAT
};
- if (GR_GL_SUPPORT_ES1 && !GR_GL_SUPPORT_ES2) {
+ if (kES1_GrGLBinding == binding) {
return repeatModes; // GL_MIRRORED_REPEAT not supported.
} else {
return mirrorRepeatModes;
GrAssert(0 != textureDesc.fTextureID);
fTexParams = initialTexParams;
- fTexIDObj = new GrGLTexID(textureDesc.fTextureID,
+ fTexIDObj = new GrGLTexID(GPUGL->glInterface(),
+ textureDesc.fTextureID,
textureDesc.fOwnsID);
fUploadFormat = textureDesc.fUploadFormat;
fUploadByteCount = textureDesc.fUploadByteCount;
*/
bool restoreGLRowLength = false;
bool flipY = kBottomUp_Orientation == fOrientation;
- if (GR_GL_SUPPORT_DESKTOP && !flipY) {
+ if (kDesktop_GrGLBinding == GPUGL->glBinding() && !flipY) {
// can't use this for flipping, only non-neg values allowed. :(
if (srcData && rowBytes) {
- GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
rowBytes / fUploadByteCount));
restoreGLRowLength = true;
}
if (flipY) {
y = this->height() - (y + height);
}
- GR_GL(BindTexture(GR_GL_TEXTURE_2D, fTexIDObj->id()));
- GR_GL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, fUploadByteCount));
- GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, x, y, width, height,
- fUploadFormat, fUploadType, srcData));
+ GL_CALL(BindTexture(GR_GL_TEXTURE_2D, fTexIDObj->id()));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, fUploadByteCount));
+ GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, x, y, width, height,
+ fUploadFormat, fUploadType, srcData));
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == GPUGL->glBinding()) {
if (restoreGLRowLength) {
- GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
}
}
}
class GrGLTexID : public GrRefCnt {
public:
- GrGLTexID(GrGLuint texID, bool ownsID) : fTexID(texID), fOwnsID(ownsID) {}
+ GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool ownsID)
+ : fGL(gl)
+ , fTexID(texID)
+ , fOwnsID(ownsID) {
+ }
virtual ~GrGLTexID() {
if (0 != fTexID && fOwnsID) {
- GR_GL(DeleteTextures(1, &fTexID));
+ GR_GL_CALL(fGL, DeleteTextures(1, &fTexID));
}
}
GrGLuint id() const { return fTexID; }
private:
- GrGLuint fTexID;
- bool fOwnsID;
+ const GrGLInterface* fGL;
+ GrGLuint fTexID;
+ bool fOwnsID;
};
////////////////////////////////////////////////////////////////////////////////
// and it is up to the GrGpuGL derivative to handle y-mirroing.
Orientation orientation() const { return fOrientation; }
- static const GrGLenum* WrapMode2GLWrap();
+ static const GrGLenum* WrapMode2GLWrap(GrGLBinding binding);
protected:
#include "GrGLConfig.h"
#include "GrGLInterface.h"
-void GrGLClearErr() {
- while (GR_GL_NO_ERROR != GrGLGetGLInterface()->fGetError()) {}
+void GrGLClearErr(const GrGLInterface* gl) {
+ while (GR_GL_NO_ERROR != gl->fGetError()) {}
}
-void GrGLCheckErr(const char* location, const char* call) {
- uint32_t err = GrGLGetGLInterface()->fGetError();
+void GrGLCheckErr(const GrGLInterface* gl,
+ const char* location,
+ const char* call) {
+ uint32_t err = GR_GL_GET_ERROR(gl);
if (GR_GL_NO_ERROR != err) {
- GrPrintf("---- glGetError %x", err);
+ GrPrintf("---- glGetError %x", GR_GL_GET_ERROR(gl));
if (NULL != location) {
GrPrintf(" at\n\t%s", location);
}
}
}
-void GrGLRestoreResetRowLength() {
- if (GR_GL_SUPPORT_DESKTOP) {
- GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
+void GrGLResetRowLength(const GrGLInterface* gl) {
+ if (gl->supportsDesktop()) {
+ GR_GL_CALL(gl, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
}
}
#define GPUGL static_cast<GrGpuGL*>(getGpu())
+#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
+
GrGLVertexBuffer::GrGLVertexBuffer(GrGpuGL* gpu,
GrGLuint id,
size_t sizeInBytes,
// make sure we've not been abandoned
if (fBufferID) {
GPUGL->notifyVertexBufferDelete(this);
- GR_GL(DeleteBuffers(1, &fBufferID));
+ GL_CALL(DeleteBuffers(1, &fBufferID));
fBufferID = 0;
}
}
}
void GrGLVertexBuffer::bind() const {
- GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, fBufferID));
+ GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, fBufferID));
GPUGL->notifyVertexBufferBind(this);
}
if (GPUGL->supportsBufferLocking()) {
this->bind();
// Let driver know it can discard the old data
- GR_GL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL,
- this->dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
- fLockPtr = GR_GL(MapBuffer(GR_GL_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
+ GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL,
+ this->dynamic() ? GR_GL_DYNAMIC_DRAW :
+ GR_GL_STATIC_DRAW));
+ fLockPtr = GL_CALL(MapBuffer(GR_GL_ARRAY_BUFFER, GR_GL_WRITE_ONLY));
return fLockPtr;
}
return NULL;
GrAssert(GPUGL->supportsBufferLocking());
this->bind();
- GR_GL(UnmapBuffer(GR_GL_ARRAY_BUFFER));
+ GL_CALL(UnmapBuffer(GR_GL_ARRAY_BUFFER));
fLockPtr = NULL;
}
if (this->isValid() && GPUGL->supportsBufferLocking()) {
GrGLint mapped;
this->bind();
- GR_GL(GetBufferParameteriv(GR_GL_ARRAY_BUFFER, GR_GL_BUFFER_MAPPED, &mapped));
+ GL_CALL(GetBufferParameteriv(GR_GL_ARRAY_BUFFER,
+ GR_GL_BUFFER_MAPPED, &mapped));
GrAssert(!!mapped == !!fLockPtr);
}
#endif
this->bind();
GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
if (this->sizeInBytes() == srcSizeInBytes) {
- GR_GL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
+ GL_CALL(BufferData(GR_GL_ARRAY_BUFFER, srcSizeInBytes, src, usage));
} else {
#if GR_GL_USE_BUFFER_DATA_NULL_HINT
- GR_GL(BufferData(GR_GL_ARRAY_BUFFER, this->sizeInBytes(), NULL, usage));
+ GL_CALL(BufferData(GR_GL_ARRAY_BUFFER,
+ this->sizeInBytes(), NULL, usage));
#endif
- GR_GL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
+ GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, 0, srcSizeInBytes, src));
}
return true;
}
return false;
}
this->bind();
- GR_GL(BufferSubData(GR_GL_ARRAY_BUFFER, offset, srcSizeInBytes, src));
+ GL_CALL(BufferSubData(GR_GL_ARRAY_BUFFER, offset, srcSizeInBytes, src));
return true;
}
GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
+ const GrGLInterface* glInterface;
+
if (kOpenGL_Shaders_GrEngine == engine ||
kOpenGL_Fixed_GrEngine == engine) {
- // If no GL bindings have been installed, fall-back to calling the
- // GL functions that have been linked with the executable.
- if (!GrGLGetGLInterface()) {
- GrGLSetDefaultGLInterface();
- // If there is no platform-default then just fail.
- if (!GrGLGetGLInterface()) {
- return NULL;
- }
+ glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
+ if (NULL == glInterface) {
+ glInterface = GrGLGetDefaultGLInterface();
+ }
+ if (NULL == glInterface) {
+#if GR_DEBUG
+ GrPrintf("No GL interface provided!");
+#endif
+ return NULL;
}
- if (!GrGLGetGLInterface()->validate(engine)) {
+ if (!glInterface->validate(engine)) {
#if GR_DEBUG
GrPrintf("Failed GL interface validation!");
#endif
switch (engine) {
case kOpenGL_Shaders_GrEngine:
- GrAssert(NULL == (void*)context3D);
- {
-#if 0 // old code path, will be removed soon
- gpu = new GrGpuGLShaders2;
-#else
- gpu = new GrGpuGLShaders;
-#endif
- }
+ GrAssert(NULL != glInterface);
+ gpu = new GrGpuGLShaders(glInterface);
break;
case kOpenGL_Fixed_GrEngine:
- GrAssert(NULL == (void*)context3D);
- gpu = new GrGpuGLFixed;
- break;
- case kDirect3D9_GrEngine:
- GrAssert(NULL != (void*)context3D);
-#if GR_WIN32_BUILD
-// gpu = new GrGpuD3D9((IDirect3DDevice9*)context3D);
-#endif
+ GrAssert(NULL != glInterface);
+ gpu = new GrGpuGLFixed(glInterface);
break;
default:
GrAssert(!"unknown engine");
static const GrGLuint GR_MAX_GLUINT = ~0;
static const GrGLint GR_INVAL_GLINT = ~0;
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
+
// we use a spare texture unit to avoid
// mucking with the state of any of the stages.
static const int SPARE_TEX_UNIT = GrGpuGL::kNumStages;
static bool gPrintStartupSpew;
-static bool fbo_test(int w, int h) {
+static bool fbo_test(const GrGLInterface* gl, int w, int h) {
GrGLint savedFBO;
GrGLint savedTexUnit;
- GR_GL_GetIntegerv(GR_GL_ACTIVE_TEXTURE, &savedTexUnit);
- GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &savedFBO);
+ GR_GL_GetIntegerv(gl, GR_GL_ACTIVE_TEXTURE, &savedTexUnit);
+ GR_GL_GetIntegerv(gl, GR_GL_FRAMEBUFFER_BINDING, &savedFBO);
- GR_GL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
+ GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
GrGLuint testFBO;
- GR_GL(GenFramebuffers(1, &testFBO));
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO));
+ GR_GL_CALL(gl, GenFramebuffers(1, &testFBO));
+ GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, testFBO));
GrGLuint testRTTex;
- GR_GL(GenTextures(1, &testRTTex));
- GR_GL(BindTexture(GR_GL_TEXTURE_2D, testRTTex));
+ GR_GL_CALL(gl, GenTextures(1, &testRTTex));
+ GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, testRTTex));
// some implementations require texture to be mip-map complete before
// FBO with level 0 bound as color attachment will be framebuffer complete.
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST));
- GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h,
- 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL));
- GR_GL(BindTexture(GR_GL_TEXTURE_2D, 0));
- GR_GL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
- GR_GL_TEXTURE_2D, testRTTex, 0));
- GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
- GR_GL(DeleteFramebuffers(1, &testFBO));
- GR_GL(DeleteTextures(1, &testRTTex));
-
- GR_GL(ActiveTexture(savedTexUnit));
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, savedFBO));
+ GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_MIN_FILTER,
+ GR_GL_NEAREST));
+ GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, 0, GR_GL_RGBA, w, h,
+ 0, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, NULL));
+ GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0));
+ GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER,
+ GR_GL_COLOR_ATTACHMENT0,
+ GR_GL_TEXTURE_2D, testRTTex, 0));
+ GrGLenum status = GR_GL_CALL(gl, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GR_GL_CALL(gl, DeleteFramebuffers(1, &testFBO));
+ GR_GL_CALL(gl, DeleteTextures(1, &testRTTex));
+
+ GR_GL_CALL(gl, ActiveTexture(savedTexUnit));
+ GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, savedFBO));
return status == GR_GL_FRAMEBUFFER_COMPLETE;
}
-static bool probe_for_npot_render_target_support(bool hasNPOTTextureSupport) {
+static bool probe_for_npot_render_target_support(const GrGLInterface* gl,
+ bool hasNPOTTextureSupport) {
/* Experimentation has found that some GLs that support NPOT textures
do not support FBOs with a NPOT texture. They report "unsupported" FBO
internally to the next POT.
*/
if (hasNPOTTextureSupport) {
- return fbo_test(200, 200);
+ return fbo_test(gl, 200, 200);
}
return false;
}
-static int probe_for_min_render_target_height(bool hasNPOTRenderTargetSupport,
+static int probe_for_min_render_target_height(const GrGLInterface* gl,
+ bool hasNPOTRenderTargetSupport,
int maxRenderTargetSize) {
/* The iPhone 4 has a restriction that for an FBO with texture color
attachment with height <= 8 then the width must be <= height. Here
for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? ++i : i *= 2) {
GrGLuint w = maxRenderTargetSize;
GrGLuint h = i;
- if (fbo_test(w, h)) {
+ if (fbo_test(gl, w, h)) {
if (gPrintStartupSpew) {
GrPrintf("\t[%d, %d]: PASSED\n", w, h);
}
return minRenderTargetHeight;
}
-static int probe_for_min_render_target_width(bool hasNPOTRenderTargetSupport,
- int maxRenderTargetSize) {
+static int probe_for_min_render_target_width(const GrGLInterface* gl,
+ bool hasNPOTRenderTargetSupport,
+ int maxRenderTargetSize) {
if (gPrintStartupSpew) {
GrPrintf("Small width FBO texture experiments\n");
for (GrGLuint i = 1; i <= 256; hasNPOTRenderTargetSupport ? i *= 2 : ++i) {
GrGLuint w = i;
GrGLuint h = maxRenderTargetSize;
- if (fbo_test(w, h)) {
+ if (fbo_test(gl, w, h)) {
if (gPrintStartupSpew) {
GrPrintf("\t[%d, %d]: PASSED\n", w, h);
}
}
-GrGpuGL::GrGpuGL()
+GrGpuGL::GrGpuGL(const GrGLInterface* gl, GrGLBinding glBinding)
: fStencilFormats(8) {
- GrGLClearErr();
+ gl->ref();
+ fGL = gl;
+ fGLBinding = glBinding;
+ switch (glBinding) {
+ case kDesktop_GrGLBinding:
+ GrAssert(gl->supportsDesktop());
+ break;
+ case kES1_GrGLBinding:
+ GrAssert(gl->supportsES1());
+ break;
+ case kES2_GrGLBinding:
+ GrAssert(gl->supportsES2());
+ break;
+ default:
+ GrCrash("Expect exactly one valid GL binding bit to be in use.");
+ }
+
+ GrGLClearErr(fGL);
if (gPrintStartupSpew) {
+ const GrGLubyte* vendor = GL_CALL(GetString(GR_GL_VENDOR));
+ const GrGLubyte* renderer = GL_CALL(GetString(GR_GL_RENDERER));
+ const GrGLubyte* version = GL_CALL(GetString(GR_GL_VERSION));
+ const GrGLubyte* ext = GL_CALL(GetString(GR_GL_EXTENSIONS));
GrPrintf("------------------------- create GrGpuGL %p --------------\n",
this);
- GrPrintf("------ VENDOR %s\n",
- GrGLGetGLInterface()->fGetString(GR_GL_VENDOR));
- GrPrintf("------ RENDERER %s\n",
- GrGLGetGLInterface()->fGetString(GR_GL_RENDERER));
- GrPrintf("------ VERSION %s\n",
- GrGLGetGLInterface()->fGetString(GR_GL_VERSION));
- GrPrintf("------ EXTENSIONS\n %s \n",
- GrGLGetGLInterface()->fGetString(GR_GL_EXTENSIONS));
+ GrPrintf("------ VENDOR %s\n", vendor);
+ GrPrintf("------ RENDERER %s\n", renderer);
+ GrPrintf("------ VERSION %s\n", version);
+ GrPrintf("------ EXTENSIONS\n %s \n", ext);
}
- fGLVersion = gl_version_as_float();
- fExtensionString = (const char*) GR_GL(GetString(GR_GL_EXTENSIONS));
+ fGLVersion = gl_version_as_float(gl);
+ fExtensionString = (const char*) GL_CALL(GetString(GR_GL_EXTENSIONS));
this->resetDirtyFlags();
// check FS and fixed-function texture unit limits
// we only use textures in the fragment stage currently.
// checks are > to make sure we have a spare unit.
- if (GR_GL_SUPPORT_DESKTOP || GR_GL_SUPPORT_ES2) {
- GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+ if (kES1_GrGLBinding != this->glBinding()) {
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
GrAssert(maxTextureUnits > kNumStages);
}
- if (GR_GL_SUPPORT_DESKTOP || GR_GL_SUPPORT_ES1) {
- GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
+ if (kES2_GrGLBinding != this->glBinding()) {
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
GrAssert(maxTextureUnits > kNumStages);
}
- if (GR_GL_SUPPORT_ES2) {
- GR_GL_GetIntegerv(GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
+ if (kES2_GrGLBinding == this->glBinding()) {
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
&fMaxFragmentUniformVectors);
- } else if (GR_GL_SUPPORT_DESKTOP) {
+ } else if (kDesktop_GrGLBinding != this->glBinding()) {
GrGLint max;
- GR_GL_GetIntegerv(GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
fMaxFragmentUniformVectors = max / 4;
} else {
fMaxFragmentUniformVectors = 16;
this->setupStencilFormats();
GrGLint numFormats;
- GR_GL_GetIntegerv(GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
+ GR_GL_GetIntegerv(gl, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
SkAutoSTMalloc<10, GrGLint> formats(numFormats);
- GR_GL_GetIntegerv(GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
+ GR_GL_GetIntegerv(gl, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < numFormats; ++i) {
if (formats[i] == GR_GL_PALETTE8_RGBA8) {
f8bitPaletteSupport = true;
memset(fAASamples, 0, sizeof(fAASamples));
fMSFBOType = kNone_MSFBO;
- if (GR_GL_SUPPORT_ES) {
+ if (kDesktop_GrGLBinding != this->glBinding()) {
if (this->hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
// chrome's extension is equivalent to the EXT msaa
// and fbo_blit extensions.
fMSFBOType = kAppleES_MSFBO;
}
} else {
- GrAssert(GR_GL_SUPPORT_DESKTOP);
if ((fGLVersion >= 3.f) || this->hasExtension("GL_ARB_framebuffer_object")) {
fMSFBOType = kDesktopARB_MSFBO;
} else if (this->hasExtension("GL_EXT_framebuffer_multisample") &&
if (kNone_MSFBO != fMSFBOType) {
GrGLint maxSamples;
- GR_GL_GetIntegerv(GR_GL_MAX_SAMPLES, &maxSamples);
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_SAMPLES, &maxSamples);
if (maxSamples > 1 ) {
fAASamples[kNone_GrAALevel] = 0;
fAASamples[kLow_GrAALevel] = GrMax(2,
}
fFSAASupport = fAASamples[kHigh_GrAALevel] > 0;
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
fHasStencilWrap = (fGLVersion >= 1.4f) ||
this->hasExtension("GL_EXT_stencil_wrap");
} else {
GrPrintf("Stencil Wrap: %s\n", (fHasStencilWrap ? "YES" : "NO"));
}
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
// we could also look for GL_ATI_separate_stencil extension or
// GL_EXT_stencil_two_side but they use different function signatures
// than GL2.0+ (and than each other).
(fStencilWrapOpsSupport ? "YES" : "NO"));
}
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
fRGBA8Renderbuffer = true;
} else {
fRGBA8Renderbuffer = this->hasExtension("GL_OES_rgb8_rgba8");
}
- if (GR_GL_SUPPORT_ES) {
+ if (kDesktop_GrGLBinding != this->glBinding()) {
if (GR_GL_32BPP_COLOR_FORMAT == GR_GL_BGRA) {
GrAssert(this->hasExtension("GL_EXT_texture_format_BGRA8888"));
}
}
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
fBufferLockSupport = true; // we require VBO support and the desktop VBO
// extension includes glMapBuffer.
} else {
GrPrintf("Map Buffer: %s\n", (fBufferLockSupport ? "YES" : "NO"));
}
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
if (fGLVersion >= 2.f ||
this->hasExtension("GL_ARB_texture_non_power_of_two")) {
fNPOTTextureTileSupport = true;
}
}
- fAALineSupport = GR_GL_SUPPORT_DESKTOP;
+ fAALineSupport = (kDesktop_GrGLBinding == this->glBinding());
////////////////////////////////////////////////////////////////////////////
// Experiments to determine limitations that can't be queried.
// TODO: Make these a preprocess that generate some compile time constants.
// TODO: probe once at startup, rather than once per context creation.
- int expectNPOTTargets = GrGLGetGLInterface()->fNPOTRenderTargetSupport;
+ int expectNPOTTargets = gl->fNPOTRenderTargetSupport;
if (expectNPOTTargets == kProbe_GrGLCapability) {
fNPOTRenderTargetSupport =
- probe_for_npot_render_target_support(fNPOTTextureSupport);
+ probe_for_npot_render_target_support(gl, fNPOTTextureSupport);
} else {
GrAssert(expectNPOTTargets == 0 || expectNPOTTargets == 1);
fNPOTRenderTargetSupport = static_cast<bool>(expectNPOTTargets);
}
}
- GR_GL_GetIntegerv(GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
- GR_GL_GetIntegerv(GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
+ GR_GL_GetIntegerv(gl, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
// Our render targets are always created with textures as the color
// attachment, hence this min:
fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
- fMinRenderTargetHeight = GrGLGetGLInterface()->fMinRenderTargetHeight;
+ fMinRenderTargetHeight = gl->fMinRenderTargetHeight;
if (fMinRenderTargetHeight == kProbe_GrGLCapability) {
fMinRenderTargetHeight =
- probe_for_min_render_target_height(fNPOTRenderTargetSupport,
+ probe_for_min_render_target_height(gl,fNPOTRenderTargetSupport,
fMaxRenderTargetSize);
}
- fMinRenderTargetWidth = GrGLGetGLInterface()->fMinRenderTargetWidth;
+ fMinRenderTargetWidth = gl->fMinRenderTargetWidth;
if (fMinRenderTargetWidth == kProbe_GrGLCapability) {
fMinRenderTargetWidth =
- probe_for_min_render_target_width(fNPOTRenderTargetSupport,
+ probe_for_min_render_target_width(gl, fNPOTRenderTargetSupport,
fMaxRenderTargetSize);
}
}
GrGpuGL::~GrGpuGL() {
+ fGL->unref();
}
void GrGpuGL::resetContext() {
// We detect cases when blending is effectively off
fHWBlendDisabled = false;
- GR_GL(Enable(GR_GL_BLEND));
+ GL_CALL(Enable(GR_GL_BLEND));
// we don't use the zb at all
- GR_GL(Disable(GR_GL_DEPTH_TEST));
- GR_GL(DepthMask(GR_GL_FALSE));
+ GL_CALL(Disable(GR_GL_DEPTH_TEST));
+ GL_CALL(DepthMask(GR_GL_FALSE));
- GR_GL(Disable(GR_GL_CULL_FACE));
- GR_GL(FrontFace(GR_GL_CCW));
+ GL_CALL(Disable(GR_GL_CULL_FACE));
+ GL_CALL(FrontFace(GR_GL_CCW));
fHWDrawState.fDrawFace = kBoth_DrawFace;
- GR_GL(Disable(GR_GL_DITHER));
- if (GR_GL_SUPPORT_DESKTOP) {
- GR_GL(Disable(GR_GL_LINE_SMOOTH));
- GR_GL(Disable(GR_GL_POINT_SMOOTH));
- GR_GL(Disable(GR_GL_MULTISAMPLE));
+ GL_CALL(Disable(GR_GL_DITHER));
+ if (kDesktop_GrGLBinding == this->glBinding()) {
+ GL_CALL(Disable(GR_GL_LINE_SMOOTH));
+ GL_CALL(Disable(GR_GL_POINT_SMOOTH));
+ GL_CALL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
fHWAAState.fSmoothLineEnabled = false;
}
- GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
+ GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
fHWDrawState.fFlagBits = 0;
// we only ever use lines in hairline mode
- GR_GL(LineWidth(1));
+ GL_CALL(LineWidth(1));
// invalid
fActiveTextureUnitIdx = -1;
fHWDrawState.fDstBlend = (GrBlendCoeff)-1;
fHWDrawState.fBlendConstant = 0x00000000;
- GR_GL(BlendColor(0,0,0,0));
+ GL_CALL(BlendColor(0,0,0,0));
fHWDrawState.fColor = GrColor_ILLEGAL;
fHWBounds.fScissorRect.invalidate();
fHWBounds.fScissorEnabled = false;
- GR_GL(Disable(GR_GL_SCISSOR_TEST));
+ GL_CALL(Disable(GR_GL_SCISSOR_TEST));
fHWBounds.fViewportRect.invalidate();
fHWDrawState.fStencilSettings.invalidate();
fHWGeometryState.fArrayPtrsDirty = true;
- GR_GL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
+ GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
fHWDrawState.fRenderTarget = NULL;
}
static const GrGLenum kUnknownGLFormat = ~0;
-GrGLenum get_fbo_color_format() {
+GrGLenum get_fbo_color_format(const GrGLInterface* gl) {
GrGLint cbType;
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
&cbType);
GrGLint cbFormat;
switch (cbType) {
case GR_GL_RENDERBUFFER:
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
&cbID);
- GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER, cbID));
- GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+ GR_GL_CALL(gl, BindRenderbuffer(GR_GL_RENDERBUFFER, cbID));
+ GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
GR_GL_RENDERBUFFER_INTERNAL_FORMAT,
&cbFormat);
return cbFormat;
break;
case GR_GL_TEXTURE:
// ES doesn't have glGetTexLevelParameter
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (gl->supportsDesktop()) {
GrGLint cbLevel;
GrGLint cbFace;
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
&cbID);
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL,
&cbLevel);
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE,
&cbFace);
bind = GR_GL_TEXTURE_2D;
target = GR_GL_TEXTURE_2D;
}
- GR_GL(BindTexture(bind, cbID));
- GR_GL_GetTexLevelParameteriv(target, cbLevel,
+ GR_GL_CALL(gl, BindTexture(bind, cbID));
+ GR_GL_GetTexLevelParameteriv(gl, target, cbLevel,
GR_GL_TEXTURE_INTERNAL_FORMAT, &cbFormat);
return cbFormat;
} else {
}
}
-GrPixelConfig get_implied_color_config(bool arbFBOExtension) {
+GrPixelConfig get_implied_color_config(const GrGLInterface* gl,
+ bool arbFBOExtension) {
GrGLint rSize, bSize, gSize, aSize;
if (arbFBOExtension) {
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &rSize);
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &gSize);
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &bSize);
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &aSize);
} else {
- GR_GL_GetIntegerv(GR_GL_RED_BITS, &rSize);
- GR_GL_GetIntegerv(GR_GL_GREEN_BITS, &gSize);
- GR_GL_GetIntegerv(GR_GL_BLUE_BITS, &bSize);
- GR_GL_GetIntegerv(GR_GL_ALPHA_BITS, &aSize);
+ GR_GL_GetIntegerv(gl, GR_GL_RED_BITS, &rSize);
+ GR_GL_GetIntegerv(gl, GR_GL_GREEN_BITS, &gSize);
+ GR_GL_GetIntegerv(gl, GR_GL_BLUE_BITS, &bSize);
+ GR_GL_GetIntegerv(gl, GR_GL_ALPHA_BITS, &aSize);
}
if(8 == rSize && 8 == gSize && 8 == bSize) {
return kUnknown_GrPixelConfig;
}
-int get_fbo_stencil_bits(bool arbFBOExtension) {
+int get_fbo_stencil_bits(const GrGLInterface* gl, bool arbFBOExtension) {
GrGLint stencilBits;
if (arbFBOExtension) {
- GR_GL_GetFramebufferAttachmentParameteriv(GR_GL_FRAMEBUFFER,
+ GR_GL_GetFramebufferAttachmentParameteriv(gl, GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
GR_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
&stencilBits);
} else {
- GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, &stencilBits);
+ GR_GL_GetIntegerv(gl, GR_GL_STENCIL_BITS, &stencilBits);
}
return stencilBits;
}
GrGLRenderTarget::Desc rtDesc;
- GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, (GrGLint*)&rtDesc.fRTFBOID);
+ GR_GL_GetIntegerv(this->glInterface(), GR_GL_FRAMEBUFFER_BINDING,
+ (GrGLint*)&rtDesc.fRTFBOID);
rtDesc.fTexFBOID = rtDesc.fRTFBOID;
rtDesc.fMSColorRenderbufferID = 0;
- bool arbFBO = (GR_GL_SUPPORT_DESKTOP && (fGLVersion > 3.0 ||
+ bool arbFBO = ((kDesktop_GrGLBinding == fGLBinding) && (fGLVersion > 3.0 ||
this->hasExtension("GL_ARB_framebuffer_object")));
GrGLIRect viewport;
- viewport.setFromGLViewport();
- int stencilBits = get_fbo_stencil_bits(arbFBO);
- GR_GL_GetIntegerv(GR_GL_SAMPLES, &rtDesc.fSampleCnt);
+ viewport.setFromGLViewport(this->glInterface());
+ int stencilBits = get_fbo_stencil_bits(this->glInterface(), arbFBO);
+ GR_GL_GetIntegerv(this->glInterface(), GR_GL_SAMPLES, &rtDesc.fSampleCnt);
SkAutoTUnref<GrGLStencilBuffer> sb;
if (stencilBits) {
format));
}
- GrGLenum fmat = get_fbo_color_format();
+ GrGLenum fmat = get_fbo_color_format(this->glInterface());
if (kUnknownGLFormat == fmat) {
- rtDesc.fConfig = get_implied_color_config(arbFBO);
+ rtDesc.fConfig = get_implied_color_config(this->glInterface(), arbFBO);
} else {
rtDesc.fConfig = internal_color_format_to_config(fmat);
}
gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
bool supportsPackedDS = fGLVersion >= 3.0f ||
this->hasExtension("GL_EXT_packed_depth_stencil") ||
this->hasExtension("GL_ARB_framebuffer_object");
* GL_UNPACK_ROW_LENGTH.
*/
bool flipY = GrGLTexture::kBottomUp_Orientation == desc.fOrientation;
- if (GR_GL_SUPPORT_DESKTOP && !flipY) {
+ if (kDesktop_GrGLBinding == this->glBinding() && !flipY) {
if (data && rowBytes != desc.fContentWidth * desc.fUploadByteCount) {
- GR_GL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
- rowBytes / desc.fUploadByteCount));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH,
+ rowBytes / desc.fUploadByteCount));
}
} else {
size_t trimRowBytes = desc.fContentWidth * desc.fUploadByteCount;
}
}
- GR_GL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, desc.fUploadByteCount));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, desc.fUploadByteCount));
if (kIndex_8_GrPixelConfig == desc.fFormat &&
supports8BitPalette()) {
// ES only supports CompressedTexImage2D, not CompressedTexSubimage2D
GrAssert(desc.fContentHeight == desc.fAllocHeight);
GrGLsizei imageSize = desc.fAllocWidth * desc.fAllocHeight +
kGrColorTableSize;
- GR_GL(CompressedTexImage2D(GR_GL_TEXTURE_2D, 0, desc.fUploadFormat,
- desc.fAllocWidth, desc.fAllocHeight,
- 0, imageSize, data));
- GrGLRestoreResetRowLength();
+ GL_CALL(CompressedTexImage2D(GR_GL_TEXTURE_2D, 0, desc.fUploadFormat,
+ desc.fAllocWidth, desc.fAllocHeight,
+ 0, imageSize, data));
+ GrGLResetRowLength(this->glInterface());
} else {
if (NULL != data && (desc.fAllocWidth != desc.fContentWidth ||
desc.fAllocHeight != desc.fContentHeight)) {
- GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
- desc.fAllocWidth, desc.fAllocHeight,
- 0, desc.fUploadFormat, desc.fUploadType, NULL));
- GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, 0, desc.fContentWidth,
- desc.fContentHeight, desc.fUploadFormat,
- desc.fUploadType, data));
- GrGLRestoreResetRowLength();
+ GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
+ desc.fAllocWidth, desc.fAllocHeight,
+ 0, desc.fUploadFormat, desc.fUploadType, NULL));
+ GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, 0, desc.fContentWidth,
+ desc.fContentHeight, desc.fUploadFormat,
+ desc.fUploadType, data));
+ GrGLResetRowLength(this->glInterface());
int extraW = desc.fAllocWidth - desc.fContentWidth;
int extraH = desc.fAllocHeight - desc.fContentHeight;
memcpy(extraRowStart, lastRowStart, rowDataBytes);
extraRowStart += rowDataBytes;
}
- GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0, desc.fContentHeight,
- desc.fContentWidth, extraH,
- desc.fUploadFormat, desc.fUploadType,
- texels.get()));
+ GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, 0,
+ desc.fContentHeight, desc.fContentWidth,
+ extraH, desc.fUploadFormat,
+ desc.fUploadType, texels.get()));
}
if (extraW) {
uint8_t* edgeTexel = (uint8_t*)data +
}
edgeTexel += rowBytes;
}
- GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth, 0,
- extraW, desc.fContentHeight,
- desc.fUploadFormat, desc.fUploadType,
- texels.get()));
+ GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
+ 0, extraW, desc.fContentHeight,
+ desc.fUploadFormat, desc.fUploadType,
+ texels.get()));
}
if (extraW && extraH) {
uint8_t* cornerTexel = (uint8_t*)data +
memcpy(extraTexel, cornerTexel, desc.fUploadByteCount);
extraTexel += desc.fUploadByteCount;
}
- GR_GL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
- desc.fContentHeight, extraW, extraH,
- desc.fUploadFormat, desc.fUploadType,
- texels.get()));
+ GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, desc.fContentWidth,
+ desc.fContentHeight, extraW, extraH,
+ desc.fUploadFormat, desc.fUploadType,
+ texels.get()));
}
} else {
- GR_GL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
- desc.fAllocWidth, desc.fAllocHeight, 0,
- desc.fUploadFormat, desc.fUploadType, data));
- GrGLRestoreResetRowLength();
+ GL_CALL(TexImage2D(GR_GL_TEXTURE_2D, 0, internalFormat,
+ desc.fAllocWidth, desc.fAllocHeight, 0,
+ desc.fUploadFormat, desc.fUploadType, data));
+ GrGLResetRowLength(this->glInterface());
}
}
}
GrGLenum msColorFormat = 0; // suppress warning
- GR_GL(GenFramebuffers(1, &desc->fTexFBOID));
+ GL_CALL(GenFramebuffers(1, &desc->fTexFBOID));
if (!desc->fTexFBOID) {
goto FAILED;
}
// If we are using multisampling we will create two FBOS. We render
// to one and then resolve to the texture bound to the other.
if (desc->fSampleCnt > 1 && kNone_MSFBO != fMSFBOType) {
- GR_GL(GenFramebuffers(1, &desc->fRTFBOID));
- GR_GL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
+ GL_CALL(GenFramebuffers(1, &desc->fRTFBOID));
+ GL_CALL(GenRenderbuffers(1, &desc->fMSColorRenderbufferID));
if (!desc->fRTFBOID ||
!desc->fMSColorRenderbufferID ||
!this->fboInternalFormat(desc->fConfig, &msColorFormat)) {
if (desc->fRTFBOID != desc->fTexFBOID) {
GrAssert(desc->fSampleCnt > 1);
- GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER,
+ GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
desc->fMSColorRenderbufferID));
- GR_GL_NO_ERR(RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
- desc->fSampleCnt,
- msColorFormat,
- width, height));
- err = GrGLGetGLInterface()->fGetError();
+ GR_GL_CALL_NOERRCHECK(this->glInterface(),
+ RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
+ desc->fSampleCnt,
+ msColorFormat,
+ width, height));
+ err = GR_GL_GET_ERROR(this->glInterface());
if (err != GR_GL_NO_ERROR) {
goto FAILED;
}
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
GR_GL_RENDERBUFFER,
desc->fMSColorRenderbufferID));
- GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
}
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
- GR_GL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
- GR_GL_COLOR_ATTACHMENT0,
- GR_GL_TEXTURE_2D,
- texID, 0));
- status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER,
+ GR_GL_COLOR_ATTACHMENT0,
+ GR_GL_TEXTURE_2D,
+ texID, 0));
+ status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
FAILED:
if (desc->fMSColorRenderbufferID) {
- GR_GL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
+ GL_CALL(DeleteRenderbuffers(1, &desc->fMSColorRenderbufferID));
}
if (desc->fRTFBOID != desc->fTexFBOID) {
- GR_GL(DeleteFramebuffers(1, &desc->fRTFBOID));
+ GL_CALL(DeleteFramebuffers(1, &desc->fRTFBOID));
}
if (desc->fTexFBOID) {
- GR_GL(DeleteFramebuffers(1, &desc->fTexFBOID));
+ GL_CALL(DeleteFramebuffers(1, &desc->fTexFBOID));
}
return false;
}
}
}
- GR_GL(GenTextures(1, &glTexDesc.fTextureID));
+ GL_CALL(GenTextures(1, &glTexDesc.fTextureID));
if (!glTexDesc.fTextureID) {
return return_null_texture();
}
this->setSpareTextureUnit();
- GR_GL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_MAG_FILTER,
- DEFAULT_PARAMS.fFilter));
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_MIN_FILTER,
- DEFAULT_PARAMS.fFilter));
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_WRAP_S,
- DEFAULT_PARAMS.fWrapS));
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_WRAP_T,
- DEFAULT_PARAMS.fWrapT));
+ GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTexDesc.fTextureID));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_MAG_FILTER,
+ DEFAULT_PARAMS.fFilter));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_MIN_FILTER,
+ DEFAULT_PARAMS.fFilter));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_WRAP_S,
+ DEFAULT_PARAMS.fWrapS));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_WRAP_T,
+ DEFAULT_PARAMS.fWrapT));
this->allocateAndUploadTexData(glTexDesc, internalFormat,srcData, rowBytes);
glTexDesc.fAllocHeight,
glTexDesc.fTextureID,
&glRTDesc)) {
- GR_GL(DeleteTextures(1, &glTexDesc.fTextureID));
+ GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
return return_null_texture();
}
tex = new GrGLTexture(this, glTexDesc, glRTDesc, DEFAULT_PARAMS);
}
namespace {
-void inline get_stencil_rb_sizes(GrGLuint rb, GrGLStencilBuffer::Format* format) {
+void inline get_stencil_rb_sizes(const GrGLInterface* gl,
+ GrGLuint rb,
+ GrGLStencilBuffer::Format* format) {
// we shouldn't ever know one size and not the other
GrAssert((kUnknownBitCount == format->fStencilBits) ==
(kUnknownBitCount == format->fTotalBits));
if (kUnknownBitCount == format->fStencilBits) {
- GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+ GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
GR_GL_RENDERBUFFER_STENCIL_SIZE,
(GrGLint*)&format->fStencilBits);
if (format->fPacked) {
- GR_GL_GetRenderbufferParameteriv(GR_GL_RENDERBUFFER,
+ GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER,
GR_GL_RENDERBUFFER_DEPTH_SIZE,
(GrGLint*)&format->fTotalBits);
format->fTotalBits += format->fStencilBits;
int samples = rt->numSamples();
GrGLuint sbID;
- GR_GL(GenRenderbuffers(1, &sbID));
+ GL_CALL(GenRenderbuffers(1, &sbID));
if (!sbID) {
return false;
}
int stencilFmtCnt = fStencilFormats.count();
for (int i = 0; i < stencilFmtCnt; ++i) {
- GR_GL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID));
+ GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbID));
// we start with the last stencil format that succeeded in hopes
// that we won't go through this loop more than once after the
// first (painful) stencil creation.
// we do this "if" so that we don't call the multisample
// version on a GL that doesn't have an MSAA extension.
if (samples > 1) {
- GR_GL_NO_ERR(RenderbufferStorageMultisample(
+ GR_GL_CALL_NOERRCHECK(this->glInterface(),
+ RenderbufferStorageMultisample(
GR_GL_RENDERBUFFER,
samples,
fStencilFormats[sIdx].fInternalFormat,
width,
height));
} else {
- GR_GL_NO_ERR(RenderbufferStorage(GR_GL_RENDERBUFFER,
+ GR_GL_CALL_NOERRCHECK(this->glInterface(),
+ RenderbufferStorage(GR_GL_RENDERBUFFER,
fStencilFormats[sIdx].fInternalFormat,
width, height));
}
- GrGLenum err = GrGLGetGLInterface()->fGetError();
+ GrGLenum err = GR_GL_GET_ERROR(this->glInterface());
if (err == GR_GL_NO_ERROR) {
// After sized formats we attempt an unsized format and take whatever
// sizes GL gives us. In that case we query for the size.
GrGLStencilBuffer::Format format = fStencilFormats[sIdx];
- get_stencil_rb_sizes(sbID, &format);
+ get_stencil_rb_sizes(this->glInterface(), sbID, &format);
sb = new GrGLStencilBuffer(this, sbID, width, height,
samples, format);
if (this->attachStencilBufferToRenderTarget(sb, rt)) {
sb->unref();
}
}
- GR_GL(DeleteRenderbuffers(1, &sbID));
+ GL_CALL(DeleteRenderbuffers(1, &sbID));
return false;
}
if (NULL == sb) {
if (NULL != rt->getStencilBuffer()) {
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
GR_GL_RENDERBUFFER, 0));
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_DEPTH_ATTACHMENT,
GR_GL_RENDERBUFFER, 0));
#if GR_DEBUG
GrGLenum status =
- GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
GrAssert(GR_GL_FRAMEBUFFER_COMPLETE == status);
#endif
}
GrGLuint rb = glsb->renderbufferID();
fHWDrawState.fRenderTarget = NULL;
-
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
GR_GL_RENDERBUFFER, rb));
if (glsb->format().fPacked) {
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_DEPTH_ATTACHMENT,
GR_GL_RENDERBUFFER, rb));
} else {
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_DEPTH_ATTACHMENT,
GR_GL_RENDERBUFFER, 0));
}
- GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
GR_GL_RENDERBUFFER, 0));
if (glsb->format().fPacked) {
- GR_GL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_DEPTH_ATTACHMENT,
GR_GL_RENDERBUFFER, 0));
}
GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) {
GrGLuint id;
- GR_GL(GenBuffers(1, &id));
+ GL_CALL(GenBuffers(1, &id));
if (id) {
- GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, id));
+ GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, id));
fHWGeometryState.fArrayPtrsDirty = true;
- GrGLClearErr();
+ GrGLClearErr(this->glInterface());
// make sure driver can allocate memory for this buffer
- GR_GL_NO_ERR(BufferData(GR_GL_ARRAY_BUFFER, size, NULL,
- dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
- if (GrGLGetGLInterface()->fGetError() != GR_GL_NO_ERROR) {
- GR_GL(DeleteBuffers(1, &id));
+ GR_GL_CALL_NOERRCHECK(this->glInterface(),
+ BufferData(GR_GL_ARRAY_BUFFER, size, NULL,
+ dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
+ if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) {
+ GL_CALL(DeleteBuffers(1, &id));
// deleting bound buffer does implicit bind to 0
fHWGeometryState.fVertexBuffer = NULL;
return NULL;
GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) {
GrGLuint id;
- GR_GL(GenBuffers(1, &id));
+ GL_CALL(GenBuffers(1, &id));
if (id) {
- GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
- GrGLClearErr();
+ GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
+ GrGLClearErr(this->glInterface());
// make sure driver can allocate memory for this buffer
- GR_GL_NO_ERR(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, NULL,
- dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
- if (GrGLGetGLInterface()->fGetError() != GR_GL_NO_ERROR) {
- GR_GL(DeleteBuffers(1, &id));
+ GR_GL_CALL_NOERRCHECK(this->glInterface(),
+ BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, size, NULL,
+ dynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW));
+ if (this->glInterface()->fGetError() != GR_GL_NO_ERROR) {
+ GL_CALL(DeleteBuffers(1, &id));
// deleting bound buffer does implicit bind to 0
fHWGeometryState.fIndexBuffer = NULL;
return NULL;
if (NULL != rect) {
if (fHWBounds.fScissorRect != scissor) {
- scissor.pushToGLScissor();
+ scissor.pushToGLScissor(this->glInterface());
fHWBounds.fScissorRect = scissor;
}
if (!fHWBounds.fScissorEnabled) {
- GR_GL(Enable(GR_GL_SCISSOR_TEST));
+ GL_CALL(Enable(GR_GL_SCISSOR_TEST));
fHWBounds.fScissorEnabled = true;
}
} else {
if (fHWBounds.fScissorEnabled) {
- GR_GL(Disable(GR_GL_SCISSOR_TEST));
+ GL_CALL(Disable(GR_GL_SCISSOR_TEST));
fHWBounds.fScissorEnabled = false;
}
}
}
this->flushRenderTarget(rect);
this->flushScissor(rect);
- GR_GL(ColorMask(GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE));
+ GL_CALL(ColorMask(GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE,GR_GL_TRUE));
fHWDrawState.fFlagBits &= ~kNoColorWrites_StateBit;
- GR_GL(ClearColor(GrColorUnpackR(color)/255.f,
- GrColorUnpackG(color)/255.f,
- GrColorUnpackB(color)/255.f,
- GrColorUnpackA(color)/255.f));
- GR_GL(Clear(GR_GL_COLOR_BUFFER_BIT));
+ GL_CALL(ClearColor(GrColorUnpackR(color)/255.f,
+ GrColorUnpackG(color)/255.f,
+ GrColorUnpackB(color)/255.f,
+ GrColorUnpackA(color)/255.f));
+ GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
}
void GrGpuGL::clearStencil() {
this->flushRenderTarget(&GrIRect::EmptyIRect());
if (fHWBounds.fScissorEnabled) {
- GR_GL(Disable(GR_GL_SCISSOR_TEST));
+ GL_CALL(Disable(GR_GL_SCISSOR_TEST));
fHWBounds.fScissorEnabled = false;
}
- GR_GL(StencilMask(0xffffffff));
- GR_GL(ClearStencil(0));
- GR_GL(Clear(GR_GL_STENCIL_BUFFER_BIT));
+ GL_CALL(StencilMask(0xffffffff));
+ GL_CALL(ClearStencil(0));
+ GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
fHWDrawState.fStencilSettings.invalidate();
}
#endif
this->flushRenderTarget(&GrIRect::EmptyIRect());
this->flushScissor(&rect);
- GR_GL(StencilMask(clipStencilMask));
- GR_GL(ClearStencil(0));
- GR_GL(Clear(GR_GL_STENCIL_BUFFER_BIT));
+ GL_CALL(StencilMask(clipStencilMask));
+ GL_CALL(ClearStencil(0));
+ GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT));
fHWDrawState.fStencilSettings.invalidate();
}
case GrGLRenderTarget::kCanResolve_ResolveType:
this->resolveRenderTarget(tgt);
// we don't track the state of the READ FBO ID.
- GR_GL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, tgt->textureFBOID()));
+ GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
+ tgt->textureFBOID()));
break;
default:
GrCrash("Unknown resolve type");
// the read rect is viewport-relative
GrGLIRect readRect;
readRect.setRelativeTo(glvp, left, top, width, height);
- GR_GL(ReadPixels(readRect.fLeft, readRect.fBottom,
- readRect.fWidth, readRect.fHeight,
- format, type, buffer));
+ GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom,
+ readRect.fWidth, readRect.fHeight,
+ format, type, buffer));
// now reverse the order of the rows, since GL's are bottom-to-top, but our
// API presents top-to-bottom
GrGLRenderTarget* rt = (GrGLRenderTarget*)fCurrDrawState.fRenderTarget;
if (fHWDrawState.fRenderTarget != fCurrDrawState.fRenderTarget) {
- GR_GL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
+ GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
#endif
#if GR_DEBUG
- GrGLenum status = GR_GL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+ GrGLenum status = GL_CALL(CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
GrPrintf("GrGpuGL::flushRenderTarget glCheckFramebufferStatus %x\n", status);
}
fHWDrawState.fRenderTarget = fCurrDrawState.fRenderTarget;
const GrGLIRect& vp = rt->getViewport();
if (fHWBounds.fViewportRect != vp) {
- vp.pushToGLViewport();
+ vp.pushToGLViewport(this->glInterface());
fHWBounds.fViewportRect = vp;
}
}
// DrawElements always draws from the begining of the arrays for idx 0.
GrAssert(0 == startVertex);
- GR_GL(DrawElements(gPrimitiveType2GLMode[type], indexCount,
- GR_GL_UNSIGNED_SHORT, indices));
+ GL_CALL(DrawElements(gPrimitiveType2GLMode[type], indexCount,
+ GR_GL_UNSIGNED_SHORT, indices));
#if SWAP_PER_DRAW
glFlush();
#if GR_MAC_BUILD
// pass 0 for parameter first. We have to adjust gl*Pointer() to
// account for startVertex in the DrawElements case. So we always
// rely on setupGeometry to have accounted for startVertex.
- GR_GL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount));
+ GL_CALL(DrawArrays(gPrimitiveType2GLMode[type], 0, vertexCount));
#if SWAP_PER_DRAW
glFlush();
#if GR_MAC_BUILD
if (rt->needsResolve()) {
GrAssert(kNone_MSFBO != fMSFBOType);
GrAssert(rt->textureFBOID() != rt->renderFBOID());
- GR_GL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
- rt->renderFBOID()));
- GR_GL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER,
- rt->textureFBOID()));
+ GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
+ rt->renderFBOID()));
+ GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER,
+ rt->textureFBOID()));
#if GR_COLLECT_STATS
++fStats.fRenderTargetChngCnt;
#endif
if (kAppleES_MSFBO == fMSFBOType) {
// Apple's extension uses the scissor as the blit bounds.
- GR_GL(Enable(GR_GL_SCISSOR_TEST));
- GR_GL(Scissor(r.fLeft, r.fBottom,
- r.fWidth, r.fHeight));
- GR_GL(ResolveMultisampleFramebuffer());
+ GL_CALL(Enable(GR_GL_SCISSOR_TEST));
+ GL_CALL(Scissor(r.fLeft, r.fBottom,
+ r.fWidth, r.fHeight));
+ GL_CALL(ResolveMultisampleFramebuffer());
fHWBounds.fScissorRect.invalidate();
fHWBounds.fScissorEnabled = true;
} else {
}
int right = r.fLeft + r.fWidth;
int top = r.fBottom + r.fHeight;
- GR_GL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
- r.fLeft, r.fBottom, right, top,
- GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
+ GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top,
+ r.fLeft, r.fBottom, right, top,
+ GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
}
rt->flagAsResolved();
}
}
if (settings->isDisabled()) {
- GR_GL(Disable(GR_GL_STENCIL_TEST));
+ GL_CALL(Disable(GR_GL_STENCIL_TEST));
} else {
- GR_GL(Enable(GR_GL_STENCIL_TEST));
+ GL_CALL(Enable(GR_GL_STENCIL_TEST));
#if GR_DEBUG
if (!fStencilWrapOpsSupport) {
GrAssert(settings->fFrontPassOp != kIncWrap_StencilOp);
backWriteMask &= userStencilMask;
}
- GR_GL(StencilFuncSeparate(GR_GL_FRONT, frontFunc, frontRef, frontMask));
- GR_GL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask));
- GR_GL(StencilFuncSeparate(GR_GL_BACK, backFunc, backRef, backMask));
- GR_GL(StencilMaskSeparate(GR_GL_BACK, backWriteMask));
- GR_GL(StencilOpSeparate(GR_GL_FRONT, grToGLStencilOp[settings->fFrontFailOp],
- grToGLStencilOp[settings->fFrontPassOp],
- grToGLStencilOp[settings->fFrontPassOp]));
-
- GR_GL(StencilOpSeparate(GR_GL_BACK, grToGLStencilOp[settings->fBackFailOp],
- grToGLStencilOp[settings->fBackPassOp],
- grToGLStencilOp[settings->fBackPassOp]));
+ GL_CALL(StencilFuncSeparate(GR_GL_FRONT, frontFunc,
+ frontRef, frontMask));
+ GL_CALL(StencilMaskSeparate(GR_GL_FRONT, frontWriteMask));
+ GL_CALL(StencilFuncSeparate(GR_GL_BACK, backFunc,
+ backRef, backMask));
+ GL_CALL(StencilMaskSeparate(GR_GL_BACK, backWriteMask));
+ GL_CALL(StencilOpSeparate(GR_GL_FRONT,
+ grToGLStencilOp[settings->fFrontFailOp],
+ grToGLStencilOp[settings->fFrontPassOp],
+ grToGLStencilOp[settings->fFrontPassOp]));
+
+ GL_CALL(StencilOpSeparate(GR_GL_BACK,
+ grToGLStencilOp[settings->fBackFailOp],
+ grToGLStencilOp[settings->fBackPassOp],
+ grToGLStencilOp[settings->fBackPassOp]));
} else {
- GR_GL(StencilFunc(frontFunc, frontRef, frontMask));
- GR_GL(StencilMask(frontWriteMask));
- GR_GL(StencilOp(grToGLStencilOp[settings->fFrontFailOp],
+ GL_CALL(StencilFunc(frontFunc, frontRef, frontMask));
+ GL_CALL(StencilMask(frontWriteMask));
+ GL_CALL(StencilOp(grToGLStencilOp[settings->fFrontFailOp],
grToGLStencilOp[settings->fFrontPassOp],
grToGLStencilOp[settings->fFrontPassOp]));
}
}
void GrGpuGL::flushAAState(GrPrimitiveType type) {
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
// ES doesn't support toggling GL_MULTISAMPLE and doesn't have
// smooth lines.
if (GrIsPrimTypeLines(type)) {
bool smooth = useSmoothLines();
if (!fHWAAState.fSmoothLineEnabled && smooth) {
- GR_GL(Enable(GR_GL_LINE_SMOOTH));
+ GL_CALL(Enable(GR_GL_LINE_SMOOTH));
fHWAAState.fSmoothLineEnabled = true;
} else if (fHWAAState.fSmoothLineEnabled && !smooth) {
- GR_GL(Disable(GR_GL_LINE_SMOOTH));
+ GL_CALL(Disable(GR_GL_LINE_SMOOTH));
fHWAAState.fSmoothLineEnabled = false;
}
if (fCurrDrawState.fRenderTarget->isMultisampled() &&
fHWAAState.fMSAAEnabled) {
- GR_GL(Disable(GR_GL_MULTISAMPLE));
+ GL_CALL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
}
} else if (fCurrDrawState.fRenderTarget->isMultisampled() &&
!!(kAntialias_StateBit & fCurrDrawState.fFlagBits) !=
fHWAAState.fMSAAEnabled) {
if (fHWAAState.fMSAAEnabled) {
- GR_GL(Disable(GR_GL_MULTISAMPLE));
+ GL_CALL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
} else {
- GR_GL(Enable(GR_GL_MULTISAMPLE));
+ GL_CALL(Enable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = true;
}
}
GrBlendCoeff dstCoeff) {
if (GrIsPrimTypeLines(type) && useSmoothLines()) {
if (fHWBlendDisabled) {
- GR_GL(Enable(GR_GL_BLEND));
+ GL_CALL(Enable(GR_GL_BLEND));
fHWBlendDisabled = false;
}
if (kSA_BlendCoeff != fHWDrawState.fSrcBlend ||
kISA_BlendCoeff != fHWDrawState.fDstBlend) {
- GR_GL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff],
- gXfermodeCoeff2Blend[kISA_BlendCoeff]));
+ GL_CALL(BlendFunc(gXfermodeCoeff2Blend[kSA_BlendCoeff],
+ gXfermodeCoeff2Blend[kISA_BlendCoeff]));
fHWDrawState.fSrcBlend = kSA_BlendCoeff;
fHWDrawState.fDstBlend = kISA_BlendCoeff;
}
bool blendOff = canDisableBlend();
if (fHWBlendDisabled != blendOff) {
if (blendOff) {
- GR_GL(Disable(GR_GL_BLEND));
+ GL_CALL(Disable(GR_GL_BLEND));
} else {
- GR_GL(Enable(GR_GL_BLEND));
+ GL_CALL(Enable(GR_GL_BLEND));
}
fHWBlendDisabled = blendOff;
}
if (!blendOff) {
if (fHWDrawState.fSrcBlend != srcCoeff ||
fHWDrawState.fDstBlend != dstCoeff) {
- GR_GL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
- gXfermodeCoeff2Blend[dstCoeff]));
+ GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff],
+ gXfermodeCoeff2Blend[dstCoeff]));
fHWDrawState.fSrcBlend = srcCoeff;
fHWDrawState.fDstBlend = dstCoeff;
}
GrColorUnpackB(fCurrDrawState.fBlendConstant) / 255.f,
GrColorUnpackA(fCurrDrawState.fBlendConstant) / 255.f
};
- GR_GL(BlendColor(c[0], c[1], c[2], c[3]));
+ GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
fHWDrawState.fBlendConstant = fCurrDrawState.fBlendConstant;
}
}
if (fHWDrawState.fTextures[s] != nextTexture) {
setTextureUnit(s);
- GR_GL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
+ GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
#if GR_COLLECT_STATS
++fStats.fTextureChngCnt;
#endif
newTexParams.fFilter = grToGLFilter(sampler.getFilter());
- newTexParams.fWrapS =
- GrGLTexture::WrapMode2GLWrap()[sampler.getWrapX()];
- newTexParams.fWrapT =
- GrGLTexture::WrapMode2GLWrap()[sampler.getWrapY()];
+ const GrGLenum* wraps =
+ GrGLTexture::WrapMode2GLWrap(this->glBinding());
+ newTexParams.fWrapS = wraps[sampler.getWrapX()];
+ newTexParams.fWrapT = wraps[sampler.getWrapY()];
if (newTexParams.fFilter != oldTexParams.fFilter) {
setTextureUnit(s);
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_MAG_FILTER,
- newTexParams.fFilter));
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_MIN_FILTER,
- newTexParams.fFilter));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_MAG_FILTER,
+ newTexParams.fFilter));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_MIN_FILTER,
+ newTexParams.fFilter));
}
if (newTexParams.fWrapS != oldTexParams.fWrapS) {
setTextureUnit(s);
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_WRAP_S,
- newTexParams.fWrapS));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_WRAP_S,
+ newTexParams.fWrapS));
}
if (newTexParams.fWrapT != oldTexParams.fWrapT) {
setTextureUnit(s);
- GR_GL(TexParameteri(GR_GL_TEXTURE_2D,
- GR_GL_TEXTURE_WRAP_T,
- newTexParams.fWrapT));
+ GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
+ GR_GL_TEXTURE_WRAP_T,
+ newTexParams.fWrapT));
}
nextTexture->setTexParams(newTexParams);
}
if ((fCurrDrawState.fFlagBits & kDither_StateBit) !=
(fHWDrawState.fFlagBits & kDither_StateBit)) {
if (fCurrDrawState.fFlagBits & kDither_StateBit) {
- GR_GL(Enable(GR_GL_DITHER));
+ GL_CALL(Enable(GR_GL_DITHER));
} else {
- GR_GL(Disable(GR_GL_DITHER));
+ GL_CALL(Disable(GR_GL_DITHER));
}
}
} else {
mask = GR_GL_TRUE;
}
- GR_GL(ColorMask(mask, mask, mask, mask));
+ GL_CALL(ColorMask(mask, mask, mask, mask));
}
if (fHWDrawState.fDrawFace != fCurrDrawState.fDrawFace) {
switch (fCurrDrawState.fDrawFace) {
case kCCW_DrawFace:
- GR_GL(Enable(GR_GL_CULL_FACE));
- GR_GL(CullFace(GR_GL_BACK));
+ GL_CALL(Enable(GR_GL_CULL_FACE));
+ GL_CALL(CullFace(GR_GL_BACK));
break;
case kCW_DrawFace:
- GR_GL(Enable(GR_GL_CULL_FACE));
- GR_GL(CullFace(GR_GL_FRONT));
+ GL_CALL(Enable(GR_GL_CULL_FACE));
+ GL_CALL(CullFace(GR_GL_FRONT));
break;
case kBoth_DrawFace:
- GR_GL(Disable(GR_GL_CULL_FACE));
+ GL_CALL(Disable(GR_GL_CULL_FACE));
break;
default:
GrCrash("Unknown draw face.");
case kRGBA_8888_GrPixelConfig:
case kRGBX_8888_GrPixelConfig: // todo: can we tell it our X?
*format = GR_GL_32BPP_COLOR_FORMAT;
- if (GR_GL_SUPPORT_ES) {
+ if (kDesktop_GrGLBinding != this->glBinding()) {
// according to GL_EXT_texture_format_BGRA8888 the *internal*
// format for a BGRA is BGRA not RGBA (as on desktop)
*internalFormat = GR_GL_32BPP_COLOR_FORMAT;
void GrGpuGL::setTextureUnit(int unit) {
GrAssert(unit >= 0 && unit < kNumStages);
if (fActiveTextureUnitIdx != unit) {
- GR_GL(ActiveTexture(GR_GL_TEXTURE0 + unit));
+ GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit));
fActiveTextureUnitIdx = unit;
}
}
void GrGpuGL::setSpareTextureUnit() {
if (fActiveTextureUnitIdx != (GR_GL_TEXTURE0 + SPARE_TEX_UNIT)) {
- GR_GL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
+ GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + SPARE_TEX_UNIT));
fActiveTextureUnitIdx = SPARE_TEX_UNIT;
}
}
return false;
}
case kRGB_565_GrPixelConfig:
- GrAssert(GR_GL_SUPPORT_ES); // ES2 supports 565. ES1 supports it
- // with FBO extension desktop GL has
- // no such internal format
+ // ES2 supports 565. ES1 supports it
+ // with FBO extension desktop GL has
+ // no such internal format
+ GrAssert(kDesktop_GrGLBinding != this->glBinding());
*format = GR_GL_RGB565;
return true;
case kRGBA_4444_GrPixelConfig:
GrAssert(NULL != vbuf);
GrAssert(!vbuf->isLocked());
if (fHWGeometryState.fVertexBuffer != vbuf) {
- GR_GL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID()));
+ GL_CALL(BindBuffer(GR_GL_ARRAY_BUFFER, vbuf->bufferID()));
fHWGeometryState.fArrayPtrsDirty = true;
fHWGeometryState.fVertexBuffer = vbuf;
}
GrAssert(NULL != ibuf);
GrAssert(!ibuf->isLocked());
if (fHWGeometryState.fIndexBuffer != ibuf) {
- GR_GL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID()));
+ GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, ibuf->bufferID()));
fHWGeometryState.fIndexBuffer = ibuf;
}
}
public:
virtual ~GrGpuGL();
+ const GrGLInterface* glInterface() const { return fGL; }
+ GrGLBinding glBinding() const { return fGLBinding; }
+
protected:
- GrGpuGL();
+ GrGpuGL(const GrGLInterface* glInterface, GrGLBinding glBinding);
struct {
size_t fVertexOffset;
// from our loop that tries stencil formats and calls check fb status.
int fLastSuccessfulStencilFmtIdx;
+ const GrGLInterface* fGL;
+ GrGLBinding fGLBinding;
+
typedef GrGpu INHERITED;
};
GR_GL_MODELVIEW, GR_GL_TEXTURE
};
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
///////////////////////////////////////////////////////////////////////////////
-GrGpuGLFixed::GrGpuGLFixed() {
+namespace {
+GrGLBinding get_binding_in_use(const GrGLInterface* gl) {
+ if (gl->supportsDesktop()) {
+ return kDesktop_GrGLBinding;
+ } else {
+ GrAssert(gl->supportsES1());
+ return kES1_GrGLBinding;
+ }
+}
+}
+
+GrGpuGLFixed::GrGpuGLFixed(const GrGLInterface* gl)
+ : GrGpuGL(gl, get_binding_in_use(gl)) {
f4X4DownsampleFilterSupport = false;
fDualSourceBlendingSupport = false;
}
void GrGpuGLFixed::resetContext() {
INHERITED::resetContext();
- GR_GL(Disable(GR_GL_TEXTURE_2D));
+ GL_CALL(Disable(GR_GL_TEXTURE_2D));
for (int s = 0; s < kNumStages; ++s) {
setTextureUnit(s);
- GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_TEXTURE_ENV_MODE, GR_GL_COMBINE));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_RGB, GR_GL_MODULATE));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_RGB, GR_GL_TEXTURE0+s));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_RGB, GR_GL_PREVIOUS));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_RGB, GR_GL_SRC_COLOR));
-
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_ALPHA, GR_GL_MODULATE));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_ALPHA, GR_GL_TEXTURE0+s));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND0_ALPHA, GR_GL_SRC_ALPHA));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_ALPHA, GR_GL_PREVIOUS));
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_ALPHA, GR_GL_SRC_ALPHA));
+ GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_TEXTURE_ENV_MODE,
+ GR_GL_COMBINE));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_COMBINE_RGB,
+ GR_GL_MODULATE));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_SRC0_RGB,
+ GR_GL_TEXTURE0+s));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_SRC1_RGB,
+ GR_GL_PREVIOUS));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_OPERAND1_RGB,
+ GR_GL_SRC_COLOR));
+
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_COMBINE_ALPHA,
+ GR_GL_MODULATE));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_SRC0_ALPHA,
+ GR_GL_TEXTURE0+s));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_OPERAND0_ALPHA,
+ GR_GL_SRC_ALPHA));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_SRC1_ALPHA,
+ GR_GL_PREVIOUS));
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GR_GL_OPERAND1_ALPHA,
+ GR_GL_SRC_ALPHA));
// color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending
// upon whether we have a (premultiplied) RGBA texture or just an ALPHA
fHWGeometryState.fVertexLayout = 0;
fHWGeometryState.fVertexOffset = ~0;
- GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
- GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
- GR_GL(ShadeModel(GR_GL_FLAT));
- GR_GL(DisableClientState(GR_GL_COLOR_ARRAY));
+ GL_CALL(EnableClientState(GR_GL_VERTEX_ARRAY));
+ GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+ GL_CALL(ShadeModel(GR_GL_FLAT));
+ GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
- GR_GL(PointSize(1.f));
+ GL_CALL(PointSize(1.f));
- GrGLClearErr();
+ GrGLClearErr(this->glInterface());
fTextVerts = false;
fBaseVertex = 0xffffffff;
mat[12] = -1.f;
mat[13] = 1.f;
- GR_GL(MatrixMode(GR_GL_PROJECTION));
- GR_GL(LoadMatrixf(mat));
+ GL_CALL(MatrixMode(GR_GL_PROJECTION));
+ GL_CALL(LoadMatrixf(mat));
}
bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
}
}
- if (GR_GL_SUPPORT_ES1) {
+ if (kES1_GrGLBinding == this->glBinding()) {
if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
unimpl("ES1 doesn't support blend constant");
if (usingTextures[s] != wasUsingTexture) {
setTextureUnit(s);
if (usingTextures[s]) {
- GR_GL(Enable(GR_GL_TEXTURE_2D));
+ GL_CALL(Enable(GR_GL_TEXTURE_2D));
} else {
- GR_GL(Disable(GR_GL_TEXTURE_2D));
+ GL_CALL(Disable(GR_GL_TEXTURE_2D));
}
}
}
if (vertColor != prevVertColor) {
if (vertColor) {
- GR_GL(ShadeModel(GR_GL_SMOOTH));
+ GL_CALL(ShadeModel(GR_GL_SMOOTH));
// invalidate the immediate mode color
fHWDrawState.fColor = GrColor_ILLEGAL;
} else {
- GR_GL(ShadeModel(GR_GL_FLAT));
+ GL_CALL(ShadeModel(GR_GL_FLAT));
}
}
if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
- GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
+ GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
GrColorUnpackG(fCurrDrawState.fColor),
GrColorUnpackB(fCurrDrawState.fColor),
GrColorUnpackA(fCurrDrawState.fColor)));
kColor_TextureEnvRGBOperand;
if (fHWRGBOperand0[s] != nextRGBOperand0) {
setTextureUnit(s);
- GR_GL(TexEnvi(GR_GL_TEXTURE_ENV,
+ GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
GR_GL_OPERAND0_RGB,
(nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
GR_GL_SRC_ALPHA :
GrGpuMatrix glm;
glm.set(texMat);
setTextureUnit(s);
- GR_GL(MatrixMode(GR_GL_TEXTURE));
- GR_GL(LoadMatrixf(glm.fMat));
+ GL_CALL(MatrixMode(GR_GL_TEXTURE));
+ GL_CALL(LoadMatrixf(glm.fMat));
recordHWSamplerMatrix(s, getSamplerMatrix(s));
}
} else {
if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
GrGpuMatrix glm;
glm.set(fCurrDrawState.fViewMatrix);
- GR_GL(MatrixMode(GR_GL_MODELVIEW));
- GR_GL(LoadMatrixf(glm.fMat));
+ GL_CALL(MatrixMode(GR_GL_MODELVIEW));
+ GL_CALL(LoadMatrixf(glm.fMat));
fHWDrawState.fViewMatrix =
fCurrDrawState.fViewMatrix;
}
this->getGeomSrc().fVertexLayout)));
if (posAndTexChange) {
- GR_GL(VertexPointer(2, scalarType, newStride, (GrGLvoid*)vertexOffset));
+ GL_CALL(VertexPointer(2, scalarType,
+ newStride, (GrGLvoid*)vertexOffset));
fHWGeometryState.fVertexOffset = vertexOffset;
}
// need to enable array if tex coord offset is 0
// (using positions as coords)
if (newTexCoordOffsets[s] >= 0) {
- GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[s]);
+ GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
+ newTexCoordOffsets[s]);
if (oldTexCoordOffsets[s] < 0) {
- GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
- GR_GL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
- GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
+ GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+ GL_CALL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+ GL_CALL(TexCoordPointer(2, scalarType,
+ newStride, texCoordOffset));
} else if (posAndTexChange ||
newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
- GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
- GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset));
+ GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+ GL_CALL(TexCoordPointer(2, scalarType,
+ newStride, texCoordOffset));
}
} else if (oldTexCoordOffsets[s] >= 0) {
- GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s));
- GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
+ GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
+ GL_CALL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
}
}
if (newColorOffset > 0) {
GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset);
if (oldColorOffset <= 0) {
- GR_GL(EnableClientState(GR_GL_COLOR_ARRAY));
- GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset));
+ GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
+ GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
+ newStride, colorOffset));
} else if (allOffsetsChange || newColorOffset != oldColorOffset) {
- GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset));
+ GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
+ newStride, colorOffset));
}
} else if (oldColorOffset > 0) {
- GR_GL(DisableClientState(GR_GL_COLOR_ARRAY));
+ GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
}
fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
// Fixed Pipeline OpenGL or OpenGL ES 1.x
class GrGpuGLFixed : public GrGpuGL {
public:
- GrGpuGLFixed();
+ GrGpuGLFixed(const GrGLInterface* glInterface);
virtual ~GrGpuGLFixed();
protected:
enum {
kMaxEntries = 32
};
- Entry fEntries[kMaxEntries];
- int fCount;
- unsigned int fCurrLRUStamp;
-
+ Entry fEntries[kMaxEntries];
+ int fCount;
+ unsigned int fCurrLRUStamp;
+ const GrGLInterface* fGL;
public:
- ProgramCache()
+ ProgramCache(const GrGLInterface* gl)
: fCount(0)
- , fCurrLRUStamp(0) {
+ , fCurrLRUStamp(0)
+ , fGL(gl) {
}
~ProgramCache() {
for (int i = 0; i < fCount; ++i) {
- GrGpuGLShaders::DeleteProgram(&fEntries[i].fProgramData);
+ GrGpuGLShaders::DeleteProgram(fGL, &fEntries[i].fProgramData);
}
}
Entry* entry = fHashCache.find(newEntry.fKey);
if (NULL == entry) {
- if (!desc.genProgram(&newEntry.fProgramData)) {
+ if (!desc.genProgram(fGL, &newEntry.fProgramData)) {
return NULL;
}
if (fCount < kMaxEntries) {
}
}
fHashCache.remove(entry->fKey, entry);
- GrGpuGLShaders::DeleteProgram(&entry->fProgramData);
+ GrGpuGLShaders::DeleteProgram(fGL, &entry->fProgramData);
}
entry->copyAndTakeOwnership(newEntry);
fHashCache.insert(entry->fKey, entry);
fProgramCache->abandon();
}
-void GrGpuGLShaders::DeleteProgram(CachedData* programData) {
- GR_GL(DeleteShader(programData->fVShaderID));
- GR_GL(DeleteShader(programData->fFShaderID));
- GR_GL(DeleteProgram(programData->fProgramID));
+void GrGpuGLShaders::DeleteProgram(const GrGLInterface* gl,
+ CachedData* programData) {
+ GR_GL_CALL(gl, DeleteShader(programData->fVShaderID));
+ GR_GL_CALL(gl, DeleteShader(programData->fFShaderID));
+ GR_GL_CALL(gl, DeleteProgram(programData->fProgramID));
GR_DEBUGCODE(memset(programData, 0, sizeof(*programData));)
}
////////////////////////////////////////////////////////////////////////////////
+#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
+
namespace {
template <typename T>
T random_val(GrRandom* r, T count) {
stage.fKernelWidth = 4 * random.nextF() + 2;
}
CachedData cachedData;
- if (!program.genProgram(&cachedData)) {
+ if (!program.genProgram(this->glInterface(), &cachedData)) {
return false;
}
- DeleteProgram(&cachedData);
+ DeleteProgram(this->glInterface(), &cachedData);
bool again = false;
if (again) {
- program.genProgram(&cachedData);
- DeleteProgram(&cachedData);
+ program.genProgram(this->glInterface(), &cachedData);
+ DeleteProgram(this->glInterface(), &cachedData);
}
}
return true;
}
-GrGpuGLShaders::GrGpuGLShaders() {
+namespace {
+GrGLBinding get_binding_in_use(const GrGLInterface* gl) {
+ if (gl->supportsDesktop()) {
+ return kDesktop_GrGLBinding;
+ } else {
+ GrAssert(gl->supportsES2());
+ return kES2_GrGLBinding;
+ }
+}
+}
+
+GrGpuGLShaders::GrGpuGLShaders(const GrGLInterface* gl)
+ : GrGpuGL(gl, get_binding_in_use(gl)) {
resetContext();
f4X4DownsampleFilterSupport = true;
- if (GR_GL_SUPPORT_DESKTOP) {
+ if (kDesktop_GrGLBinding == this->glBinding()) {
fDualSourceBlendingSupport =
fGLVersion >= 3.3f ||
this->hasExtension("GL_ARB_blend_func_extended");
}
fProgramData = NULL;
- fProgramCache = new ProgramCache();
+ fProgramCache = new ProgramCache(gl);
#if 0
this->programUnitTest();
fHWGeometryState.fVertexLayout = 0;
fHWGeometryState.fVertexOffset = ~0;
- GR_GL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
+ GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
for (int t = 0; t < kMaxTexCoords; ++t) {
- GR_GL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
+ GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
}
- GR_GL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx()));
+ GL_CALL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx()));
fHWProgramID = 0;
}
if (GrGLProgram::kSetAsAttribute ==
fProgramData->fUniLocations.fViewMatrixUni) {
int baseIdx = GrGLProgram::ViewMatrixAttributeIdx();
- GR_GL(VertexAttrib4fv(baseIdx + 0, mt+0));
- GR_GL(VertexAttrib4fv(baseIdx + 1, mt+3));
- GR_GL(VertexAttrib4fv(baseIdx + 2, mt+6));
+ GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
+ GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
+ GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
} else {
GrAssert(GrGLProgram::kUnusedUniform !=
fProgramData->fUniLocations.fViewMatrixUni);
- GR_GL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
- 1, false, mt));
+ GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
+ 1, false, mt));
}
}
values[1] *= SkScalarToFloat(texture->contentScaleY());
values[3] *= SkScalarToFloat(texture->contentScaleY());
- GR_GL(Uniform4fv(uni, 1, values));
+ GL_CALL(Uniform4fv(uni, 1, values));
}
}
}
if (GrGLProgram::kSetAsAttribute ==
fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) {
int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s);
- GR_GL(VertexAttrib4fv(baseIdx + 0, mt+0));
- GR_GL(VertexAttrib4fv(baseIdx + 1, mt+3));
- GR_GL(VertexAttrib4fv(baseIdx + 2, mt+6));
+ GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
+ GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
+ GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
} else {
- GR_GL(UniformMatrix3fv(uni, 1, false, mt));
+ GL_CALL(UniformMatrix3fv(uni, 1, false, mt));
}
recordHWSamplerMatrix(s, getSamplerMatrix(s));
}
GrScalarToFloat(GrMul(radius0, radius0)),
sampler.isRadial2PosRoot() ? 1.f : -1.f
};
- GR_GL(Uniform1fv(uni, 6, values));
+ GL_CALL(Uniform1fv(uni, 6, values));
fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1();
fProgramData->fRadial2Radius0[s] = sampler.getRadial2Radius0();
fProgramData->fRadial2PosRoot[s] = sampler.isRadial2PosRoot();
const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
int kernelUni = fProgramData->fUniLocations.fStages[s].fKernelUni;
if (GrGLProgram::kUnusedUniform != kernelUni) {
- GR_GL(Uniform1fv(kernelUni, sampler.getKernelWidth(), sampler.getKernel()));
+ GL_CALL(Uniform1fv(kernelUni, sampler.getKernelWidth(),
+ sampler.getKernel()));
}
int imageIncrementUni = fProgramData->fUniLocations.fStages[s].fImageIncrementUni;
if (GrGLProgram::kUnusedUniform != imageIncrementUni) {
- GR_GL(Uniform2fv(imageIncrementUni, 1, sampler.getImageIncrement()));
+ GL_CALL(Uniform2fv(imageIncrementUni, 1, sampler.getImageIncrement()));
}
}
float texelSize[] = {1.f / texture->allocatedWidth(),
1.f / texture->allocatedHeight()};
- GR_GL(Uniform2fv(uni, 1, texelSize));
+ GL_CALL(Uniform2fv(uni, 1, texelSize));
}
}
}
edges[i].fY = -b;
edges[i].fZ += b * height;
}
- GR_GL(Uniform3fv(uni, count, &edges[0].fX));
+ GL_CALL(Uniform3fv(uni, count, &edges[0].fX));
}
}
if (fHWDrawState.fColor != fCurrDrawState.fColor) {
// OpenGL ES only supports the float varities of glVertexAttrib
float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor);
- GR_GL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), c));
+ GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(),
+ c));
fHWDrawState.fColor = fCurrDrawState.fColor;
}
break;
float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor);
GrAssert(GrGLProgram::kUnusedUniform !=
fProgramData->fUniLocations.fColorUni);
- GR_GL(Uniform4fv(fProgramData->fUniLocations.fColorUni, 1, c));
+ GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorUni,
+ 1, c));
fProgramData->fColor = fCurrDrawState.fColor;
}
break;
&& fProgramData->fColorFilterColor
!= fCurrDrawState.fColorFilterColor) {
float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColorFilterColor);
- GR_GL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c));
+ GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c));
fProgramData->fColorFilterColor = fCurrDrawState.fColorFilterColor;
}
}
}
if (fHWProgramID != fProgramData->fProgramID) {
- GR_GL(UseProgram(fProgramData->fProgramID));
+ GL_CALL(UseProgram(fProgramData->fProgramID));
fHWProgramID = fProgramData->fProgramID;
}
GrBlendCoeff srcCoeff = fCurrDrawState.fSrcBlend;
if (posAndTexChange) {
int idx = GrGLProgram::PositionAttributeIdx();
- GR_GL(VertexAttribPointer(idx, 2, scalarType, false, newStride,
+ GL_CALL(VertexAttribPointer(idx, 2, scalarType, false, newStride,
(GrGLvoid*)vertexOffset));
fHWGeometryState.fVertexOffset = vertexOffset;
}
GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]);
int idx = GrGLProgram::TexCoordAttributeIdx(t);
if (oldTexCoordOffsets[t] <= 0) {
- GR_GL(EnableVertexAttribArray(idx));
- GR_GL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
+ GL_CALL(EnableVertexAttribArray(idx));
+ GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
newStride, texCoordOffset));
} else if (posAndTexChange ||
newTexCoordOffsets[t] != oldTexCoordOffsets[t]) {
- GR_GL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
+ GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm,
newStride, texCoordOffset));
}
} else if (oldTexCoordOffsets[t] > 0) {
- GR_GL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
+ GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t)));
}
}
GrGLvoid* colorOffset = (int8_t*)(vertexOffset + newColorOffset);
int idx = GrGLProgram::ColorAttributeIdx();
if (oldColorOffset <= 0) {
- GR_GL(EnableVertexAttribArray(idx));
- GR_GL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
+ GL_CALL(EnableVertexAttribArray(idx));
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
true, newStride, colorOffset));
} else if (allOffsetsChange || newColorOffset != oldColorOffset) {
- GR_GL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
+ GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE,
true, newStride, colorOffset));
}
} else if (oldColorOffset > 0) {
- GR_GL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
+ GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx()));
}
fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
// Programmable OpenGL or OpenGL ES 2.0
class GrGpuGLShaders : public GrGpuGL {
public:
- GrGpuGLShaders();
+ GrGpuGLShaders(const GrGLInterface* glInterface);
virtual ~GrGpuGLShaders();
virtual void resetContext();
// flushes the edges for edge AA
void flushEdgeAAData();
- static void DeleteProgram(CachedData* programData);
+ static void DeleteProgram(const GrGLInterface* gl,
+ CachedData* programData);
void buildProgram(GrPrimitiveType type);
#include "gl2.h"
#include "gl2ext.h"
-/*
-#include "gpu/GLES2/gl2.h"
-#include "gpu/GLES2/gl2ext.h"
-*/
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface cmd_buffer_interface = {
- kES2_GrGLBinding,
- kProbe_GrGLCapability, // fNPOTRenderTargetSupport
- kProbe_GrGLCapability, // fMinRenderTargetHeight
- kProbe_GrGLCapability, // fMinRenderTargetWidth
- glActiveTexture,
- glAttachShader,
- glBindAttribLocation,
- glBindBuffer,
- glBindTexture,
- glBlendColor,
- glBlendFunc,
- glBufferData,
- glBufferSubData,
- glClear,
- glClearColor,
- glClearStencil,
- NULL, // glClientActiveTexture
- NULL, // glColor4ub
- glColorMask,
- NULL, // glColorPointer
- glCompileShader,
- glCompressedTexImage2D,
- glCreateProgram,
- glCreateShader,
- glCullFace,
- glDeleteBuffers,
- glDeleteProgram,
- glDeleteShader,
- glDeleteTextures,
- glDepthMask,
- glDisable,
- NULL, // glDisableClientState
- glDisableVertexAttribArray,
- glDrawArrays,
- NULL, // glDrawBuffer
- NULL, // glDrawBuffers
- glDrawElements,
- glEnable,
- NULL, // glEnableClientState
- glEnableVertexAttribArray,
- glFrontFace,
- glGenBuffers,
- glGenTextures,
- glGetBufferParameteriv,
- glGetError,
- glGetIntegerv,
- glGetProgramInfoLog,
- glGetProgramiv,
- glGetShaderInfoLog,
- glGetShaderiv,
- glGetString,
- NULL, // glGetTexLevelParameteriv
- glGetUniformLocation,
- glLineWidth,
- glLinkProgram,
- NULL, // glLoadMatrixf
- NULL, // glMatrixMode
- glPixelStorei,
- NULL, // glPointSize
- NULL, // glReadBuffer
- glReadPixels,
- glScissor,
- NULL, // glShadeModel
- glShaderSource,
- glStencilFunc,
- glStencilFuncSeparate,
- glStencilMask,
- glStencilMaskSeparate,
- glStencilOp,
- glStencilOpSeparate,
- NULL, // glTexCoordPointer
- NULL, // glTexEnvi
- glTexImage2D,
- glTexParameteri,
- glTexSubImage2D,
- glUniform1f,
- glUniform1i,
- glUniform1fv,
- glUniform1iv,
- glUniform2f,
- glUniform2i,
- glUniform2fv,
- glUniform2iv,
- glUniform3f,
- glUniform3i,
- glUniform3fv,
- glUniform3iv,
- glUniform4f,
- glUniform4i,
- glUniform4fv,
- glUniform4iv,
- glUniformMatrix2fv,
- glUniformMatrix3fv,
- glUniformMatrix4fv,
- glUseProgram,
- glVertexAttrib4fv,
- glVertexAttribPointer,
- NULL, // glVertexPointer
- glViewport,
- glBindFramebuffer,
- glBindRenderbuffer,
- glCheckFramebufferStatus,
- glDeleteFramebuffers,
- glDeleteRenderbuffers,
- glFramebufferRenderbuffer,
- glFramebufferTexture2D,
- glGenFramebuffers,
- glGenRenderbuffers,
- glGetFramebufferAttachmentParameteriv,
- glGetRenderbufferParameteriv,
- glRenderbufferStorage,
- NULL, // glRenderbufferStorageMultisampleEXT,
- NULL, // glBlitFramebufferEXT,
- NULL, // glResolveMultisampleFramebuffer
- glMapBufferOES,
- glUnmapBufferOES,
- NULL, // glBindFragDataLocationIndexed
- GrGLInterface::kStaticInitEndGuard
- };
- static bool host_StubGL_initialized = false;
- if (!host_StubGL_initialized) {
- GrGLSetGLInterface(&cmd_buffer_interface);
- host_StubGL_initialized = true;
- }
+
+void GrGLInitializeDefaultGLInterface() {
+ GrGLSetGLInterface* glInterface = new GrGLInterface;
+
+ glInterface->fBindingsExported = kES2_GrGLBinding;
+ glInterface->fActiveTexture = glActiveTexture;
+ glInterface->fAttachShader = glAttachShader;
+ glInterface->fBindAttribLocation = glBindAttribLocation;
+ glInterface->fBindBuffer = glBindBuffer;
+ glInterface->fBindTexture = glBindTexture;
+ glInterface->fBlendColor = glBlendColor;
+ glInterface->fBlendFunc = glBlendFunc;
+ glInterface->fBufferData = glBufferData;
+ glInterface->fBufferSubData = glBufferSubData;
+ glInterface->fClear = glClear;
+ glInterface->fClearColor = glClearColor;
+ glInterface->fClearStencil = glClearStencil;
+ glInterface->fColorMask = glColorMask;
+ glInterface->fCompileShader = glCompileShader;
+ glInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+ glInterface->fCreateProgram = glCreateProgram;
+ glInterface->fCreateShader = glCreateShader;
+ glInterface->fCullFace = glCullFace;
+ glInterface->fDeleteBuffers = glDeleteBuffers;
+ glInterface->fDeleteProgram = glDeleteProgram;
+ glInterface->fDeleteShader = glDeleteShader;
+ glInterface->fDeleteTextures = glDeleteTextures;
+ glInterface->fDepthMask = glDepthMask;
+ glInterface->fDisable = glDisable;
+ glInterface->fDisableVertexAttribArray = glDisableVertexAttribArray;
+ glInterface->fDrawArrays = glDrawArrays;
+ glInterface->fDrawElements = glDrawElements;
+ glInterface->fEnable = glEnable;
+ glInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+ glInterface->fFrontFace = glFrontFace;
+ glInterface->fGenBuffers = glGenBuffers;
+ glInterface->fGenTextures = glGenTextures;
+ glInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+ glInterface->fGetError = glGetError;
+ glInterface->fGetIntegerv = glGetIntegerv;
+ glInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+ glInterface->fGetProgramiv = glGetProgramiv;
+ glInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+ glInterface->fGetShaderiv = glGetShaderiv;
+ glInterface->fGetString = glGetString;
+ glInterface->fGetUniformLocation = glGetUniformLocation;
+ glInterface->fLineWidth = glLineWidth;
+ glInterface->fLinkProgram = glLinkProgram;
+ glInterface->fPixelStorei = glPixelStorei;
+ glInterface->fReadPixels = glReadPixels;
+ glInterface->fScissor = glScissor;
+ glInterface->fShaderSource = glShaderSource;
+ glInterface->fStencilFunc = glStencilFunc;
+ glInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+ glInterface->fStencilMask = glStencilMask;
+ glInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+ glInterface->fStencilOp = glStencilOp;
+ glInterface->fStencilOpSeparate = glStencilOpSeparate;
+ glInterface->fTexImage2D = glTexImage2D;
+ glInterface->fTexParameteri = glTexParameteri;
+ glInterface->fTexSubImage2D = glTexSubImage2D;
+ glInterface->fUniform1f = glUniform1f;
+ glInterface->fUniform1i = glUniform1i;
+ glInterface->fUniform1fv = glUniform1fv;
+ glInterface->fUniform1iv = glUniform1iv;
+ glInterface->fUniform2f = glUniform2f;
+ glInterface->fUniform2i = glUniform2i;
+ glInterface->fUniform2fv = glUniform2fv;
+ glInterface->fUniform2iv = glUniform2iv;
+ glInterface->fUniform3f = glUniform3f;
+ glInterface->fUniform3i = glUniform3i;
+ glInterface->fUniform3fv = glUniform3fv;
+ glInterface->fUniform3iv = glUniform3iv;
+ glInterface->fUniform4f = glUniform4f;
+ glInterface->fUniform4i = glUniform4i;
+ glInterface->fUniform4fv = glUniform4fv;
+ glInterface->fUniform4iv = glUniform4iv;
+ glInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+ glInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+ glInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+ glInterface->fUseProgram = glUseProgram;
+ glInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+ glInterface->fVertexAttribPointer = glVertexAttribPointer;
+ glInterface->fViewport = glViewport;
+ glInterface->fBindFramebuffer = glBindFramebuffer;
+ glInterface->fBindRenderbuffer = glBindRenderbuffer;
+ glInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+ glInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+ glInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+ glInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+ glInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+ glInterface->fGenFramebuffers = glGenFramebuffers;
+ glInterface->fGenRenderbuffers = glGenRenderbuffers;
+ glInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+ glInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+ glInterface->fRenderbufferStorage = glRenderbufferStorage;
+ glInterface->fMapBufferOES = glMapBufferOES;
+ glInterface->fUnmapBufferOES = glUnmapBufferOES;
+
+ GrGLSetDefaultInterface(glInterface)->unref();
}
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface gDefaultInterface;
- static bool gDefaultInterfaceInit;
- if (!gDefaultInterfaceInit) {
- gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
-
- gDefaultInterface.fActiveTexture = glActiveTexture;
- gDefaultInterface.fAttachShader = glAttachShader;
- gDefaultInterface.fBindAttribLocation = glBindAttribLocation;
- gDefaultInterface.fBindBuffer = glBindBuffer;
- gDefaultInterface.fBindTexture = glBindTexture;
- gDefaultInterface.fBlendColor = glBlendColor;
- gDefaultInterface.fBlendFunc = glBlendFunc;
- gDefaultInterface.fBufferData = (GrGLBufferDataProc)glBufferData;
- gDefaultInterface.fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
- gDefaultInterface.fClear = glClear;
- gDefaultInterface.fClearColor = glClearColor;
- gDefaultInterface.fClearStencil = glClearStencil;
- gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
- gDefaultInterface.fColorMask = glColorMask;
- gDefaultInterface.fColorPointer = glColorPointer;
- gDefaultInterface.fColor4ub = glColor4ub;
- gDefaultInterface.fCompileShader = glCompileShader;
- gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
- gDefaultInterface.fCreateProgram = glCreateProgram;
- gDefaultInterface.fCreateShader = glCreateShader;
- gDefaultInterface.fCullFace = glCullFace;
- gDefaultInterface.fDeleteBuffers = glDeleteBuffers;
- gDefaultInterface.fDeleteProgram = glDeleteProgram;
- gDefaultInterface.fDeleteShader = glDeleteShader;
- gDefaultInterface.fDeleteTextures = glDeleteTextures;
- gDefaultInterface.fDepthMask = glDepthMask;
- gDefaultInterface.fDisable = glDisable;
- gDefaultInterface.fDisableClientState = glDisableClientState;
- gDefaultInterface.fDisableVertexAttribArray =
- glDisableVertexAttribArray;
- gDefaultInterface.fDrawArrays = glDrawArrays;
- gDefaultInterface.fDrawElements = glDrawElements;
- gDefaultInterface.fEnable = glEnable;
- gDefaultInterface.fEnableClientState = glEnableClientState;
- gDefaultInterface.fEnableVertexAttribArray = glEnableVertexAttribArray;
- gDefaultInterface.fFrontFace = glFrontFace;
- gDefaultInterface.fGenBuffers = glGenBuffers;
- gDefaultInterface.fGetBufferParameteriv = glGetBufferParameteriv;
- gDefaultInterface.fGetError = glGetError;
- gDefaultInterface.fGetIntegerv = glGetIntegerv;
- gDefaultInterface.fGetProgramInfoLog = glGetProgramInfoLog;
- gDefaultInterface.fGetProgramiv = glGetProgramiv;
- gDefaultInterface.fGetShaderInfoLog = glGetShaderInfoLog;
- gDefaultInterface.fGetShaderiv = glGetShaderiv;
- gDefaultInterface.fGetString = glGetString;
- gDefaultInterface.fGenTextures = glGenTextures;
- gDefaultInterface.fGetUniformLocation = glGetUniformLocation;
- gDefaultInterface.fLineWidth = glLineWidth;
- gDefaultInterface.fLinkProgram = glLinkProgram;
- gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
- gDefaultInterface.fMatrixMode = glMatrixMode;
- gDefaultInterface.fPointSize = glPointSize;
- gDefaultInterface.fPixelStorei = glPixelStorei;
- gDefaultInterface.fReadBuffer = NULL;
- gDefaultInterface.fReadPixels = glReadPixels;
- gDefaultInterface.fScissor = glScissor;
- gDefaultInterface.fShadeModel = glShadeModel;
- gDefaultInterface.fShaderSource = glShaderSource;
- gDefaultInterface.fStencilFunc = glStencilFunc;
- gDefaultInterface.fStencilFuncSeparate = glStencilFuncSeparate;
- gDefaultInterface.fStencilMask = glStencilMask;
- gDefaultInterface.fStencilMaskSeparate = glStencilMaskSeparate;
- gDefaultInterface.fStencilOp = glStencilOp;
- gDefaultInterface.fStencilOpSeparate = glStencilOpSeparate;
- gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
- gDefaultInterface.fTexEnvi = glTexEnvi;
- // mac uses GLenum for internalFormat param (non-standard)
- // amounts to int vs. uint.
- gDefaultInterface.fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
- gDefaultInterface.fTexParameteri = glTexParameteri;
- gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
- gDefaultInterface.fUniform1f = glUniform1f;
- gDefaultInterface.fUniform1i = glUniform1i;
- gDefaultInterface.fUniform1fv = glUniform1fv;
- gDefaultInterface.fUniform1iv = glUniform1iv;
- gDefaultInterface.fUniform2f = glUniform2f;
- gDefaultInterface.fUniform2i = glUniform2i;
- gDefaultInterface.fUniform2fv = glUniform2fv;
- gDefaultInterface.fUniform2iv = glUniform2iv;
- gDefaultInterface.fUniform3f = glUniform3f;
- gDefaultInterface.fUniform3i = glUniform3i;
- gDefaultInterface.fUniform3fv = glUniform3fv;
- gDefaultInterface.fUniform3iv = glUniform3iv;
- gDefaultInterface.fUniform4f = glUniform4f;
- gDefaultInterface.fUniform4i = glUniform4i;
- gDefaultInterface.fUniform4fv = glUniform4fv;
- gDefaultInterface.fUniform4iv = glUniform4iv;
- gDefaultInterface.fUniform4fv = glUniform4fv;
- gDefaultInterface.fUniformMatrix2fv = glUniformMatrix2fv;
- gDefaultInterface.fUniformMatrix3fv = glUniformMatrix3fv;
- gDefaultInterface.fUniformMatrix4fv = glUniformMatrix4fv;
- gDefaultInterface.fUseProgram = glUseProgram;
- gDefaultInterface.fVertexAttrib4fv = glVertexAttrib4fv;
- gDefaultInterface.fVertexAttribPointer = glVertexAttribPointer;
- gDefaultInterface.fVertexPointer = glVertexPointer;
- gDefaultInterface.fViewport = glViewport;
-
- gDefaultInterface.fGenFramebuffers = glGenFramebuffers;
- gDefaultInterface.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
- gDefaultInterface.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
- gDefaultInterface.fBindFramebuffer = glBindFramebuffer;
- gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2D;
- gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatus;
- gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffers;
- gDefaultInterface.fRenderbufferStorage = glRenderbufferStorage;
- gDefaultInterface.fGenRenderbuffers = glGenRenderbuffers;
- gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
- gDefaultInterface.fFramebufferRenderbuffer = glFramebufferRenderbuffer;
- gDefaultInterface.fBindRenderbuffer = glBindRenderbuffer;
+void GrGLInitializeDefaultGLInterface() {
+ GrGLInterface* defaultInterface = new GrGLInterface();
+
+ defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
+ defaultInterface->fActiveTexture = glActiveTexture;
+ defaultInterface->fAttachShader = glAttachShader;
+ defaultInterface->fBindAttribLocation = glBindAttribLocation;
+ defaultInterface->fBindBuffer = glBindBuffer;
+ defaultInterface->fBindTexture = glBindTexture;
+ defaultInterface->fBlendColor = glBlendColor;
+ defaultInterface->fBlendFunc = glBlendFunc;
+ defaultInterface->fBufferData = (GrGLBufferDataProc)glBufferData;
+ defaultInterface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData;
+ defaultInterface->fClear = glClear;
+ defaultInterface->fClearColor = glClearColor;
+ defaultInterface->fClearStencil = glClearStencil;
+ defaultInterface->fClientActiveTexture = glClientActiveTexture;
+ defaultInterface->fColorMask = glColorMask;
+ defaultInterface->fColorPointer = glColorPointer;
+ defaultInterface->fColor4ub = glColor4ub;
+ defaultInterface->fCompileShader = glCompileShader;
+ defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+ defaultInterface->fCreateProgram = glCreateProgram;
+ defaultInterface->fCreateShader = glCreateShader;
+ defaultInterface->fCullFace = glCullFace;
+ defaultInterface->fDeleteBuffers = glDeleteBuffers;
+ defaultInterface->fDeleteProgram = glDeleteProgram;
+ defaultInterface->fDeleteShader = glDeleteShader;
+ defaultInterface->fDeleteTextures = glDeleteTextures;
+ defaultInterface->fDepthMask = glDepthMask;
+ defaultInterface->fDisable = glDisable;
+ defaultInterface->fDisableClientState = glDisableClientState;
+ defaultInterface->fDisableVertexAttribArray =
+ glDisableVertexAttribArray;
+ defaultInterface->fDrawArrays = glDrawArrays;
+ defaultInterface->fDrawBuffer = NULL;
+ defaultInterface->fDrawBuffers = NULL;
+ defaultInterface->fDrawElements = glDrawElements;
+ defaultInterface->fEnable = glEnable;
+ defaultInterface->fEnableClientState = glEnableClientState;
+ defaultInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+ defaultInterface->fFrontFace = glFrontFace;
+ defaultInterface->fGenBuffers = glGenBuffers;
+ defaultInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+ defaultInterface->fGetError = glGetError;
+ defaultInterface->fGetIntegerv = glGetIntegerv;
+ defaultInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+ defaultInterface->fGetProgramiv = glGetProgramiv;
+ defaultInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+ defaultInterface->fGetShaderiv = glGetShaderiv;
+ defaultInterface->fGetString = glGetString;
+ defaultInterface->fGenTextures = glGenTextures;
+ defaultInterface->fGetUniformLocation = glGetUniformLocation;
+ defaultInterface->fLineWidth = glLineWidth;
+ defaultInterface->fLinkProgram = glLinkProgram;
+ defaultInterface->fLoadMatrixf = glLoadMatrixf;
+ defaultInterface->fMatrixMode = glMatrixMode;
+ defaultInterface->fPointSize = glPointSize;
+ defaultInterface->fPixelStorei = glPixelStorei;
+ defaultInterface->fReadBuffer = NULL;
+ defaultInterface->fReadPixels = glReadPixels;
+ defaultInterface->fScissor = glScissor;
+ defaultInterface->fShadeModel = glShadeModel;
+ defaultInterface->fShaderSource = glShaderSource;
+ defaultInterface->fStencilFunc = glStencilFunc;
+ defaultInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+ defaultInterface->fStencilMask = glStencilMask;
+ defaultInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+ defaultInterface->fStencilOp = glStencilOp;
+ defaultInterface->fStencilOpSeparate = glStencilOpSeparate;
+ defaultInterface->fTexCoordPointer = glTexCoordPointer;
+ defaultInterface->fTexEnvi = glTexEnvi;
+ // mac uses GLenum for internalFormat param (non-standard)
+ // amounts to int vs. uint.
+ defaultInterface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
+ defaultInterface->fTexParameteri = glTexParameteri;
+ defaultInterface->fTexSubImage2D = glTexSubImage2D;
+ defaultInterface->fUniform1f = glUniform1f;
+ defaultInterface->fUniform1i = glUniform1i;
+ defaultInterface->fUniform1fv = glUniform1fv;
+ defaultInterface->fUniform1iv = glUniform1iv;
+ defaultInterface->fUniform2f = glUniform2f;
+ defaultInterface->fUniform2i = glUniform2i;
+ defaultInterface->fUniform2fv = glUniform2fv;
+ defaultInterface->fUniform2iv = glUniform2iv;
+ defaultInterface->fUniform3f = glUniform3f;
+ defaultInterface->fUniform3i = glUniform3i;
+ defaultInterface->fUniform3fv = glUniform3fv;
+ defaultInterface->fUniform3iv = glUniform3iv;
+ defaultInterface->fUniform4f = glUniform4f;
+ defaultInterface->fUniform4i = glUniform4i;
+ defaultInterface->fUniform4fv = glUniform4fv;
+ defaultInterface->fUniform4iv = glUniform4iv;
+ defaultInterface->fUniform4fv = glUniform4fv;
+ defaultInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+ defaultInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+ defaultInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+ defaultInterface->fUseProgram = glUseProgram;
+ defaultInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+ defaultInterface->fVertexAttribPointer = glVertexAttribPointer;
+ defaultInterface->fVertexPointer = glVertexPointer;
+ defaultInterface->fViewport = glViewport;
+ defaultInterface->fGenFramebuffers = glGenFramebuffers;
+ defaultInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+ defaultInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+ defaultInterface->fBindFramebuffer = glBindFramebuffer;
+ defaultInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+ defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+ defaultInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+ defaultInterface->fRenderbufferStorage = glRenderbufferStorage;
+ defaultInterface->fGenRenderbuffers = glGenRenderbuffers;
+ defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+ defaultInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+ defaultInterface->fBindRenderbuffer = glBindRenderbuffer;
#if GL_OES_mapbuffer
- gDefaultInterface.fMapBuffer = glMapBufferOES;
- gDefaultInterface.fUnmapBuffer = glUnmapBufferOES;
+ defaultInterface->fMapBuffer = glMapBufferOES;
+ defaultInterface->fUnmapBuffer = glUnmapBufferOES;
#endif
#if GL_APPLE_framebuffer_multisample
- gDefaultInterface.fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
- gDefaultInterface.fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
+ defaultInterface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
+ defaultInterface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
#endif
- gDefaultInterface.fBindFragDataLocationIndexed = NULL;
+ defaultInterface->fBindFragDataLocationIndexed = NULL;
- gDefaultInterface.fBindingsExported = kES2_GrGLBinding;
-
- gDefaultInterfaceInit = true;
- }
- GrGLSetGLInterface(&gDefaultInterface);
+ defaultInterface->fBindingsExported = kES2_GrGLBinding | kES1_GrGLBinding;
+
+ GrGLSetDefaultGLInterface(&defaultInterface)->unref();
}
\ No newline at end of file
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface gDefaultInterface;
- static bool gDefaultInterfaceInit;
- if (!gDefaultInterfaceInit) {
- gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
-
- gDefaultInterface.fActiveTexture = glActiveTexture;
- gDefaultInterface.fAttachShader = glAttachShader;
- gDefaultInterface.fBindAttribLocation = glBindAttribLocation;
- gDefaultInterface.fBindBuffer = glBindBuffer;
- gDefaultInterface.fBindTexture = glBindTexture;
- gDefaultInterface.fBlendColor = glBlendColor;
- gDefaultInterface.fBlendFunc = glBlendFunc;
- gDefaultInterface.fBufferData = glBufferData;
- gDefaultInterface.fBufferSubData = glBufferSubData;
- gDefaultInterface.fClear = glClear;
- gDefaultInterface.fClearColor = glClearColor;
- gDefaultInterface.fClearStencil = glClearStencil;
- gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
- gDefaultInterface.fColorMask = glColorMask;
- gDefaultInterface.fColorPointer = glColorPointer;
- gDefaultInterface.fColor4ub = glColor4ub;
- gDefaultInterface.fCompileShader = glCompileShader;
- gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
- gDefaultInterface.fCreateProgram = glCreateProgram;
- gDefaultInterface.fCreateShader = glCreateShader;
- gDefaultInterface.fCullFace = glCullFace;
- gDefaultInterface.fDeleteBuffers = glDeleteBuffers;
- gDefaultInterface.fDeleteProgram = glDeleteProgram;
- gDefaultInterface.fDeleteShader = glDeleteShader;
- gDefaultInterface.fDeleteTextures = glDeleteTextures;
- gDefaultInterface.fDepthMask = glDepthMask;
- gDefaultInterface.fDisable = glDisable;
- gDefaultInterface.fDisableClientState = glDisableClientState;
- gDefaultInterface.fDisableVertexAttribArray =
- glDisableVertexAttribArray;
- gDefaultInterface.fDrawArrays = glDrawArrays;
- gDefaultInterface.fDrawBuffer = glDrawBuffer;
- gDefaultInterface.fDrawBuffers = glDrawBuffers;
- gDefaultInterface.fDrawElements = glDrawElements;
- gDefaultInterface.fEnable = glEnable;
- gDefaultInterface.fEnableClientState = glEnableClientState;
- gDefaultInterface.fEnableVertexAttribArray = glEnableVertexAttribArray;
- gDefaultInterface.fFrontFace = glFrontFace;
- gDefaultInterface.fGenBuffers = glGenBuffers;
- gDefaultInterface.fGetBufferParameteriv = glGetBufferParameteriv;
- gDefaultInterface.fGetError = glGetError;
- gDefaultInterface.fGetIntegerv = glGetIntegerv;
- gDefaultInterface.fGetProgramInfoLog = glGetProgramInfoLog;
- gDefaultInterface.fGetProgramiv = glGetProgramiv;
- gDefaultInterface.fGetShaderInfoLog = glGetShaderInfoLog;
- gDefaultInterface.fGetShaderiv = glGetShaderiv;
- gDefaultInterface.fGetString = glGetString;
- gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
- gDefaultInterface.fGenTextures = glGenTextures;
- gDefaultInterface.fGetUniformLocation = glGetUniformLocation;
- gDefaultInterface.fLineWidth = glLineWidth;
- gDefaultInterface.fLinkProgram = glLinkProgram;
- gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
- gDefaultInterface.fMapBuffer = glMapBuffer;
- gDefaultInterface.fMatrixMode = glMatrixMode;
- gDefaultInterface.fPointSize = glPointSize;
- gDefaultInterface.fPixelStorei = glPixelStorei;
- gDefaultInterface.fReadBuffer = glReadBuffer;
- gDefaultInterface.fReadPixels = glReadPixels;
- gDefaultInterface.fScissor = glScissor;
- gDefaultInterface.fShadeModel = glShadeModel;
- gDefaultInterface.fShaderSource = glShaderSource;
- gDefaultInterface.fStencilFunc = glStencilFunc;
- gDefaultInterface.fStencilFuncSeparate = glStencilFuncSeparate;
- gDefaultInterface.fStencilMask = glStencilMask;
- gDefaultInterface.fStencilMaskSeparate = glStencilMaskSeparate;
- gDefaultInterface.fStencilOp = glStencilOp;
- gDefaultInterface.fStencilOpSeparate = glStencilOpSeparate;
- gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
- gDefaultInterface.fTexEnvi = glTexEnvi;
- // mac uses GLenum for internalFormat param (non-standard)
- // amounts to int vs. uint.
- gDefaultInterface.fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
- gDefaultInterface.fTexParameteri = glTexParameteri;
- gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
- gDefaultInterface.fUniform1f = glUniform1f;
- gDefaultInterface.fUniform1i = glUniform1i;
- gDefaultInterface.fUniform1fv = glUniform1fv;
- gDefaultInterface.fUniform1iv = glUniform1iv;
- gDefaultInterface.fUniform2f = glUniform2f;
- gDefaultInterface.fUniform2i = glUniform2i;
- gDefaultInterface.fUniform2fv = glUniform2fv;
- gDefaultInterface.fUniform2iv = glUniform2iv;
- gDefaultInterface.fUniform3f = glUniform3f;
- gDefaultInterface.fUniform3i = glUniform3i;
- gDefaultInterface.fUniform3fv = glUniform3fv;
- gDefaultInterface.fUniform3iv = glUniform3iv;
- gDefaultInterface.fUniform4f = glUniform4f;
- gDefaultInterface.fUniform4i = glUniform4i;
- gDefaultInterface.fUniform4fv = glUniform4fv;
- gDefaultInterface.fUniform4iv = glUniform4iv;
- gDefaultInterface.fUniform4fv = glUniform4fv;
- gDefaultInterface.fUniformMatrix2fv = glUniformMatrix2fv;
- gDefaultInterface.fUniformMatrix3fv = glUniformMatrix3fv;
- gDefaultInterface.fUniformMatrix4fv = glUniformMatrix4fv;
- gDefaultInterface.fUnmapBuffer = glUnmapBuffer;
- gDefaultInterface.fUseProgram = glUseProgram;
- gDefaultInterface.fVertexAttrib4fv = glVertexAttrib4fv;
- gDefaultInterface.fVertexAttribPointer = glVertexAttribPointer;
- gDefaultInterface.fVertexPointer = glVertexPointer;
- gDefaultInterface.fViewport = glViewport;
+void GrGLInitializeDefaultGLInterface() {
+ GrGLInterface* defaultInterface = new GrGLInterface;
+ defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
+ defaultInterface->fActiveTexture = glActiveTexture;
+ defaultInterface->fAttachShader = glAttachShader;
+ defaultInterface->fBindAttribLocation = glBindAttribLocation;
+ defaultInterface->fBindBuffer = glBindBuffer;
+ defaultInterface->fBindTexture = glBindTexture;
+ defaultInterface->fBlendColor = glBlendColor;
+ defaultInterface->fBlendFunc = glBlendFunc;
+ defaultInterface->fBufferData = glBufferData;
+ defaultInterface->fBufferSubData = glBufferSubData;
+ defaultInterface->fClear = glClear;
+ defaultInterface->fClearColor = glClearColor;
+ defaultInterface->fClearStencil = glClearStencil;
+ defaultInterface->fClientActiveTexture = glClientActiveTexture;
+ defaultInterface->fColorMask = glColorMask;
+ defaultInterface->fColorPointer = glColorPointer;
+ defaultInterface->fColor4ub = glColor4ub;
+ defaultInterface->fCompileShader = glCompileShader;
+ defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
+ defaultInterface->fCreateProgram = glCreateProgram;
+ defaultInterface->fCreateShader = glCreateShader;
+ defaultInterface->fCullFace = glCullFace;
+ defaultInterface->fDeleteBuffers = glDeleteBuffers;
+ defaultInterface->fDeleteProgram = glDeleteProgram;
+ defaultInterface->fDeleteShader = glDeleteShader;
+ defaultInterface->fDeleteTextures = glDeleteTextures;
+ defaultInterface->fDepthMask = glDepthMask;
+ defaultInterface->fDisable = glDisable;
+ defaultInterface->fDisableClientState = glDisableClientState;
+ defaultInterface->fDisableVertexAttribArray =
+ glDisableVertexAttribArray;
+ defaultInterface->fDrawArrays = glDrawArrays;
+ defaultInterface->fDrawBuffer = glDrawBuffer;
+ defaultInterface->fDrawBuffers = glDrawBuffers;
+ defaultInterface->fDrawElements = glDrawElements;
+ defaultInterface->fEnable = glEnable;
+ defaultInterface->fEnableClientState = glEnableClientState;
+ defaultInterface->fEnableVertexAttribArray = glEnableVertexAttribArray;
+ defaultInterface->fFrontFace = glFrontFace;
+ defaultInterface->fGenBuffers = glGenBuffers;
+ defaultInterface->fGetBufferParameteriv = glGetBufferParameteriv;
+ defaultInterface->fGetError = glGetError;
+ defaultInterface->fGetIntegerv = glGetIntegerv;
+ defaultInterface->fGetProgramInfoLog = glGetProgramInfoLog;
+ defaultInterface->fGetProgramiv = glGetProgramiv;
+ defaultInterface->fGetShaderInfoLog = glGetShaderInfoLog;
+ defaultInterface->fGetShaderiv = glGetShaderiv;
+ defaultInterface->fGetString = glGetString;
+ defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+ defaultInterface->fGenTextures = glGenTextures;
+ defaultInterface->fGetUniformLocation = glGetUniformLocation;
+ defaultInterface->fLineWidth = glLineWidth;
+ defaultInterface->fLinkProgram = glLinkProgram;
+ defaultInterface->fLoadMatrixf = glLoadMatrixf;
+ defaultInterface->fMapBuffer = glMapBuffer;
+ defaultInterface->fMatrixMode = glMatrixMode;
+ defaultInterface->fPointSize = glPointSize;
+ defaultInterface->fPixelStorei = glPixelStorei;
+ defaultInterface->fReadBuffer = glReadBuffer;
+ defaultInterface->fReadPixels = glReadPixels;
+ defaultInterface->fScissor = glScissor;
+ defaultInterface->fShadeModel = glShadeModel;
+ defaultInterface->fShaderSource = glShaderSource;
+ defaultInterface->fStencilFunc = glStencilFunc;
+ defaultInterface->fStencilFuncSeparate = glStencilFuncSeparate;
+ defaultInterface->fStencilMask = glStencilMask;
+ defaultInterface->fStencilMaskSeparate = glStencilMaskSeparate;
+ defaultInterface->fStencilOp = glStencilOp;
+ defaultInterface->fStencilOpSeparate = glStencilOpSeparate;
+ defaultInterface->fTexCoordPointer = glTexCoordPointer;
+ defaultInterface->fTexEnvi = glTexEnvi;
+ // mac uses GLenum for internalFormat param (non-standard)
+ // amounts to int vs. uint.
+ defaultInterface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
+ defaultInterface->fTexParameteri = glTexParameteri;
+ defaultInterface->fTexSubImage2D = glTexSubImage2D;
+ defaultInterface->fUniform1f = glUniform1f;
+ defaultInterface->fUniform1i = glUniform1i;
+ defaultInterface->fUniform1fv = glUniform1fv;
+ defaultInterface->fUniform1iv = glUniform1iv;
+ defaultInterface->fUniform2f = glUniform2f;
+ defaultInterface->fUniform2i = glUniform2i;
+ defaultInterface->fUniform2fv = glUniform2fv;
+ defaultInterface->fUniform2iv = glUniform2iv;
+ defaultInterface->fUniform3f = glUniform3f;
+ defaultInterface->fUniform3i = glUniform3i;
+ defaultInterface->fUniform3fv = glUniform3fv;
+ defaultInterface->fUniform3iv = glUniform3iv;
+ defaultInterface->fUniform4f = glUniform4f;
+ defaultInterface->fUniform4i = glUniform4i;
+ defaultInterface->fUniform4fv = glUniform4fv;
+ defaultInterface->fUniform4iv = glUniform4iv;
+ defaultInterface->fUniform4fv = glUniform4fv;
+ defaultInterface->fUniformMatrix2fv = glUniformMatrix2fv;
+ defaultInterface->fUniformMatrix3fv = glUniformMatrix3fv;
+ defaultInterface->fUniformMatrix4fv = glUniformMatrix4fv;
+ defaultInterface->fUnmapBuffer = glUnmapBuffer;
+ defaultInterface->fUseProgram = glUseProgram;
+ defaultInterface->fVertexAttrib4fv = glVertexAttrib4fv;
+ defaultInterface->fVertexAttribPointer = glVertexAttribPointer;
+ defaultInterface->fVertexPointer = glVertexPointer;
+ defaultInterface->fViewport = glViewport;
#if GL_ARB_framebuffer_object
- gDefaultInterface.fGenFramebuffers = glGenFramebuffers;
- gDefaultInterface.fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
- gDefaultInterface.fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
- gDefaultInterface.fBindFramebuffer = glBindFramebuffer;
- gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2D;
- gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatus;
- gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffers;
- gDefaultInterface.fRenderbufferStorage = glRenderbufferStorage;
- gDefaultInterface.fGenRenderbuffers = glGenRenderbuffers;
- gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
- gDefaultInterface.fFramebufferRenderbuffer = glFramebufferRenderbuffer;
- gDefaultInterface.fBindRenderbuffer = glBindRenderbuffer;
- gDefaultInterface.fRenderbufferStorageMultisample =
- glRenderbufferStorageMultisample;
- gDefaultInterface.fBlitFramebuffer = glBlitFramebuffer;
+ defaultInterface->fGenFramebuffers = glGenFramebuffers;
+ defaultInterface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
+ defaultInterface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
+ defaultInterface->fBindFramebuffer = glBindFramebuffer;
+ defaultInterface->fFramebufferTexture2D = glFramebufferTexture2D;
+ defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatus;
+ defaultInterface->fDeleteFramebuffers = glDeleteFramebuffers;
+ defaultInterface->fRenderbufferStorage = glRenderbufferStorage;
+ defaultInterface->fGenRenderbuffers = glGenRenderbuffers;
+ defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+ defaultInterface->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
+ defaultInterface->fBindRenderbuffer = glBindRenderbuffer;
+ defaultInterface->fRenderbufferStorageMultisample =
+ glRenderbufferStorageMultisample;
+ defaultInterface->fBlitFramebuffer = glBlitFramebuffer;
#elif GL_EXT_framebuffer_object
- gDefaultInterface.fGenFramebuffers = glGenFramebuffersEXT;
- gDefaultInterface.fGetFramebufferAttachmentivParameter = glGetFramebufferAttachmentParameterivEXT;
- gDefaultInterface.fGLGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
- gDefaultInterface.fBindFramebuffer = glBindFramebufferEXT;
- gDefaultInterface.fFramebufferTexture2D = glFramebufferTexture2DEXT;
- gDefaultInterface.fCheckFramebufferStatus = glCheckFramebufferStatusEXT;
- gDefaultInterface.fDeleteFramebuffers = glDeleteFramebuffersEXT;
- gDefaultInterface.fRenderbufferStorage = glRenderbufferStorageEXT;
- gDefaultInterface.fGenRenderbuffers = glGenRenderbuffersEXT;
- gDefaultInterface.fDeleteRenderbuffers = glDeleteRenderbuffers;
- gDefaultInterface.fFramebufferRenderbuffer =
- glFramebufferRenderbufferEXT;
- gDefaultInterface.fBindRenderbuffer = glBindRenderbufferEXT;
- #if GL_EXT_framebuffer_multisample
- gDefaultInterface.fRenderbufferStorageMultisample =
- glRenderbufferStorageMultisampleEXT;
- #endif
- #if GL_EXT_framebuffer_blit
- gDefaultInterface.fBlitFramebuffer = glBlitFramebufferEXT;
- #endif
+ defaultInterface->fGenFramebuffers = glGenFramebuffersEXT;
+ defaultInterface->fGetFramebufferAttachmentivParameter = glGetFramebufferAttachmentParameterivEXT;
+ defaultInterface->fGLGetRenderbufferParameteriv = glGetRenderbufferParameterivEXT;
+ defaultInterface->fBindFramebuffer = glBindFramebufferEXT;
+ defaultInterface->fFramebufferTexture2D = glFramebufferTexture2DEXT;
+ defaultInterface->fCheckFramebufferStatus = glCheckFramebufferStatusEXT;
+ defaultInterface->fDeleteFramebuffers = glDeleteFramebuffersEXT;
+ defaultInterface->fRenderbufferStorage = glRenderbufferStorageEXT;
+ defaultInterface->fGenRenderbuffers = glGenRenderbuffersEXT;
+ defaultInterface->fDeleteRenderbuffers = glDeleteRenderbuffers;
+ defaultInterface->fFramebufferRenderbuffer =
+ glFramebufferRenderbufferEXT;
+ defaultInterface->fBindRenderbuffer = glBindRenderbufferEXT;
+#if GL_EXT_framebuffer_multisample
+ defaultInterface->fRenderbufferStorageMultisample =
+ glRenderbufferStorageMultisampleEXT;
+#endif
+#if GL_EXT_framebuffer_blit
+ defaultInterface->fBlitFramebuffer = glBlitFramebufferEXT;
+#endif
#endif
- gDefaultInterface.fBindFragDataLocationIndexed = NULL;
+ defaultInterface->fBindFragDataLocationIndexed = NULL;
- gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+ defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
- gDefaultInterfaceInit = true;
- }
- GrGLSetGLInterface(&gDefaultInterface);
+ GrGLSetDefaultGLInterface(defaultInterface)->unref();
}
#include <GL/glext.h>
#include <GL/glu.h>
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) \
OSMesaGetProcAddress("gl" #F);
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) \
OSMesaGetProcAddress("gl" #F #S);
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface gDefaultInterface;
- static bool gDefaultInterfaceInit;
- if (!gDefaultInterfaceInit && NULL != OSMesaGetCurrentContext()) {
+void GrGLInitializeDefaultGLInterface() {
+ if (NULL != OSMesaGetCurrentContext()) {
+ GrGLInterface defaultInterface = new GrGLInterface();
int major, minor;
const char* versionString = (const char*) glGetString(GL_VERSION);
const char* extString = (const char*) glGetString(GL_EXTENSIONS);
// We must have array and element_array buffer objects.
return;
}
- gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+ defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
- gDefaultInterface.fActiveTexture = glActiveTexture;
+ defaultInterface->fActiveTexture = glActiveTexture;
GR_GL_GET_PROC(AttachShader);
GR_GL_GET_PROC(BindAttribLocation);
GR_GL_GET_PROC(BindBuffer);
- gDefaultInterface.fBindTexture = glBindTexture;
- gDefaultInterface.fBlendColor = glBlendColor;
- gDefaultInterface.fBlendFunc = glBlendFunc;
+ defaultInterface->fBindTexture = glBindTexture;
+ defaultInterface->fBlendColor = glBlendColor;
+ defaultInterface->fBlendFunc = glBlendFunc;
GR_GL_GET_PROC(BufferData);
GR_GL_GET_PROC(BufferSubData);
- gDefaultInterface.fClear = glClear;
- gDefaultInterface.fClearColor = glClearColor;
- gDefaultInterface.fClearStencil = glClearStencil;
- gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
- gDefaultInterface.fColorMask = glColorMask;
- gDefaultInterface.fColorPointer = glColorPointer;
- gDefaultInterface.fColor4ub = glColor4ub;
+ defaultInterface->fClear = glClear;
+ defaultInterface->fClearColor = glClearColor;
+ defaultInterface->fClearStencil = glClearStencil;
+ defaultInterface->fClientActiveTexture = glClientActiveTexture;
+ defaultInterface->fColorMask = glColorMask;
+ defaultInterface->fColorPointer = glColorPointer;
+ defaultInterface->fColor4ub = glColor4ub;
GR_GL_GET_PROC(CompileShader);
- gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
+ defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
GR_GL_GET_PROC(CreateProgram);
GR_GL_GET_PROC(CreateShader);
- gDefaultInterface.fCullFace = glCullFace;
+ defaultInterface->fCullFace = glCullFace;
GR_GL_GET_PROC(DeleteBuffers);
GR_GL_GET_PROC(DeleteProgram);
GR_GL_GET_PROC(DeleteShader);
- gDefaultInterface.fDeleteTextures = glDeleteTextures;
- gDefaultInterface.fDepthMask = glDepthMask;
- gDefaultInterface.fDisable = glDisable;
- gDefaultInterface.fDisableClientState = glDisableClientState;
+ defaultInterface->fDeleteTextures = glDeleteTextures;
+ defaultInterface->fDepthMask = glDepthMask;
+ defaultInterface->fDisable = glDisable;
+ defaultInterface->fDisableClientState = glDisableClientState;
GR_GL_GET_PROC(DisableVertexAttribArray);
- gDefaultInterface.fDrawArrays = glDrawArrays;
- gDefaultInterface.fDrawBuffer = glDrawBuffer;
+ defaultInterface->fDrawArrays = glDrawArrays;
+ defaultInterface->fDrawBuffer = glDrawBuffer;
GR_GL_GET_PROC(DrawBuffers);
- gDefaultInterface.fDrawElements = glDrawElements;
- gDefaultInterface.fEnable = glEnable;
- gDefaultInterface.fEnableClientState = glEnableClientState;
+ defaultInterface->fDrawElements = glDrawElements;
+ defaultInterface->fEnable = glEnable;
+ defaultInterface->fEnableClientState = glEnableClientState;
GR_GL_GET_PROC(EnableVertexAttribArray);
- gDefaultInterface.fFrontFace = glFrontFace;
+ defaultInterface->fFrontFace = glFrontFace;
GR_GL_GET_PROC(GenBuffers);
GR_GL_GET_PROC(GetBufferParameteriv);
- gDefaultInterface.fGetError = glGetError;
- gDefaultInterface.fGetIntegerv = glGetIntegerv;
+ defaultInterface->fGetError = glGetError;
+ defaultInterface->fGetIntegerv = glGetIntegerv;
GR_GL_GET_PROC(GetProgramInfoLog);
GR_GL_GET_PROC(GetProgramiv);
GR_GL_GET_PROC(GetShaderInfoLog);
GR_GL_GET_PROC(GetShaderiv);
- gDefaultInterface.fGetString = glGetString;
- gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
- gDefaultInterface.fGenTextures = glGenTextures;
+ defaultInterface->fGetString = glGetString;
+ defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+ defaultInterface->fGenTextures = glGenTextures;
GR_GL_GET_PROC(GetUniformLocation);
- gDefaultInterface.fLineWidth = glLineWidth;
+ defaultInterface->fLineWidth = glLineWidth;
GR_GL_GET_PROC(LinkProgram);
- gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
+ defaultInterface->fLoadMatrixf = glLoadMatrixf;
GR_GL_GET_PROC(MapBuffer);
- gDefaultInterface.fMatrixMode = glMatrixMode;
- gDefaultInterface.fPointSize = glPointSize;
- gDefaultInterface.fPixelStorei = glPixelStorei;
- gDefaultInterface.fReadBuffer = glReadBuffer;
- gDefaultInterface.fReadPixels = glReadPixels;
- gDefaultInterface.fScissor = glScissor;
- gDefaultInterface.fShadeModel = glShadeModel;
+ defaultInterface->fMatrixMode = glMatrixMode;
+ defaultInterface->fPointSize = glPointSize;
+ defaultInterface->fPixelStorei = glPixelStorei;
+ defaultInterface->fReadBuffer = glReadBuffer;
+ defaultInterface->fReadPixels = glReadPixels;
+ defaultInterface->fScissor = glScissor;
+ defaultInterface->fShadeModel = glShadeModel;
GR_GL_GET_PROC(ShaderSource);
- gDefaultInterface.fStencilFunc = glStencilFunc;
+ defaultInterface->fStencilFunc = glStencilFunc;
GR_GL_GET_PROC(StencilFuncSeparate);
- gDefaultInterface.fStencilMask = glStencilMask;
+ defaultInterface->fStencilMask = glStencilMask;
GR_GL_GET_PROC(StencilMaskSeparate);
- gDefaultInterface.fStencilOp = glStencilOp;
+ defaultInterface->fStencilOp = glStencilOp;
GR_GL_GET_PROC(StencilOpSeparate);
- gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
- gDefaultInterface.fTexEnvi = glTexEnvi;
+ defaultInterface->fTexCoordPointer = glTexCoordPointer;
+ defaultInterface->fTexEnvi = glTexEnvi;
//OSMesa on Mac's glTexImage2D takes a GLenum for internalFormat rather than a GLint.
- gDefaultInterface.fTexImage2D = reinterpret_cast<GrGLTexImage2DProc>(glTexImage2D);
- gDefaultInterface.fTexParameteri = glTexParameteri;
- gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
+ defaultInterface->fTexImage2D = reinterpret_cast<GrGLTexImage2DProc>(glTexImage2D);
+ defaultInterface->fTexParameteri = glTexParameteri;
+ defaultInterface->fTexSubImage2D = glTexSubImage2D;
GR_GL_GET_PROC(Uniform1f);
GR_GL_GET_PROC(Uniform1i);
GR_GL_GET_PROC(Uniform1fv);
GR_GL_GET_PROC(UseProgram);
GR_GL_GET_PROC(VertexAttrib4fv);
GR_GL_GET_PROC(VertexAttribPointer);
- gDefaultInterface.fVertexPointer = glVertexPointer;
- gDefaultInterface.fViewport = glViewport;
+ defaultInterface->fVertexPointer = glVertexPointer;
+ defaultInterface->fViewport = glViewport;
// First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
// GL_ARB_framebuffer_object doesn't use ARB suffix.)
return;
}
GR_GL_GET_PROC(BindFragDataLocationIndexed);
- gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
-
- gDefaultInterfaceInit = true;
+ defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
+ GrGLSetDefaultGLInterface(defaultInterface)->unref();
}
- if (gDefaultInterfaceInit)
- GrGLSetGLInterface(&gDefaultInterface);
}
#include <GL/glext.h>
#include <GL/glu.h>
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) \
glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F));
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) \
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) \
glXGetProcAddress(reinterpret_cast<const GLubyte*>("gl" #F #S));
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface gDefaultInterface;
- static bool gDefaultInterfaceInit;
- if (!gDefaultInterfaceInit && NULL != glXGetCurrentContext()) {
+void GrGLInitializeDefaultGLInterface() {
+ if (NULL != glXGetCurrentContext()) {
int major, minor;
const char* versionString = (const char*) glGetString(GL_VERSION);
const char* extString = (const char*) glGetString(GL_EXTENSIONS);
return;
}
- gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+ GrGLInterface* defaultInterface = new GrGLInterface();
- gDefaultInterface.fActiveTexture = glActiveTexture;
+ defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
+
+ defaultInterface->fActiveTexture = glActiveTexture;
GR_GL_GET_PROC(AttachShader);
GR_GL_GET_PROC(BindAttribLocation);
GR_GL_GET_PROC(BindBuffer);
- gDefaultInterface.fBindTexture = glBindTexture;
- gDefaultInterface.fBlendColor = glBlendColor;
- gDefaultInterface.fBlendFunc = glBlendFunc;
+ defaultInterface->fBindTexture = glBindTexture;
+ defaultInterface->fBlendColor = glBlendColor;
+ defaultInterface->fBlendFunc = glBlendFunc;
GR_GL_GET_PROC(BufferData);
GR_GL_GET_PROC(BufferSubData);
- gDefaultInterface.fClear = glClear;
- gDefaultInterface.fClearColor = glClearColor;
- gDefaultInterface.fClearStencil = glClearStencil;
- gDefaultInterface.fClientActiveTexture = glClientActiveTexture;
- gDefaultInterface.fColorMask = glColorMask;
- gDefaultInterface.fColorPointer = glColorPointer;
- gDefaultInterface.fColor4ub = glColor4ub;
+ defaultInterface->fClear = glClear;
+ defaultInterface->fClearColor = glClearColor;
+ defaultInterface->fClearStencil = glClearStencil;
+ defaultInterface->fClientActiveTexture = glClientActiveTexture;
+ defaultInterface->fColorMask = glColorMask;
+ defaultInterface->fColorPointer = glColorPointer;
+ defaultInterface->fColor4ub = glColor4ub;
GR_GL_GET_PROC(CompileShader);
- gDefaultInterface.fCompressedTexImage2D = glCompressedTexImage2D;
+ defaultInterface->fCompressedTexImage2D = glCompressedTexImage2D;
GR_GL_GET_PROC(CreateProgram);
GR_GL_GET_PROC(CreateShader);
- gDefaultInterface.fCullFace = glCullFace;
+ defaultInterface->fCullFace = glCullFace;
GR_GL_GET_PROC(DeleteBuffers);
GR_GL_GET_PROC(DeleteProgram);
GR_GL_GET_PROC(DeleteShader);
- gDefaultInterface.fDeleteTextures = glDeleteTextures;
- gDefaultInterface.fDepthMask = glDepthMask;
- gDefaultInterface.fDisable = glDisable;
- gDefaultInterface.fDisableClientState = glDisableClientState;
+ defaultInterface->fDeleteTextures = glDeleteTextures;
+ defaultInterface->fDepthMask = glDepthMask;
+ defaultInterface->fDisable = glDisable;
+ defaultInterface->fDisableClientState = glDisableClientState;
GR_GL_GET_PROC(DisableVertexAttribArray);
- gDefaultInterface.fDrawArrays = glDrawArrays;
- gDefaultInterface.fDrawBuffer = glDrawBuffer;
+ defaultInterface->fDrawArrays = glDrawArrays;
+ defaultInterface->fDrawBuffer = glDrawBuffer;
GR_GL_GET_PROC(DrawBuffers);
- gDefaultInterface.fDrawElements = glDrawElements;
- gDefaultInterface.fEnable = glEnable;
- gDefaultInterface.fEnableClientState = glEnableClientState;
+ defaultInterface->fDrawElements = glDrawElements;
+ defaultInterface->fEnable = glEnable;
+ defaultInterface->fEnableClientState = glEnableClientState;
GR_GL_GET_PROC(EnableVertexAttribArray);
- gDefaultInterface.fFrontFace = glFrontFace;
+ defaultInterface->fFrontFace = glFrontFace;
GR_GL_GET_PROC(GenBuffers);
GR_GL_GET_PROC(GetBufferParameteriv);
- gDefaultInterface.fGetError = glGetError;
- gDefaultInterface.fGetIntegerv = glGetIntegerv;
+ defaultInterface->fGetError = glGetError;
+ defaultInterface->fGetIntegerv = glGetIntegerv;
GR_GL_GET_PROC(GetProgramInfoLog);
GR_GL_GET_PROC(GetProgramiv);
GR_GL_GET_PROC(GetShaderInfoLog);
GR_GL_GET_PROC(GetShaderiv);
- gDefaultInterface.fGetString = glGetString;
- gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
- gDefaultInterface.fGenTextures = glGenTextures;
+ defaultInterface->fGetString = glGetString;
+ defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+ defaultInterface->fGenTextures = glGenTextures;
GR_GL_GET_PROC(GetUniformLocation);
- gDefaultInterface.fLineWidth = glLineWidth;
+ defaultInterface->fLineWidth = glLineWidth;
GR_GL_GET_PROC(LinkProgram);
- gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
+ defaultInterface->fLoadMatrixf = glLoadMatrixf;
GR_GL_GET_PROC(MapBuffer);
- gDefaultInterface.fMatrixMode = glMatrixMode;
- gDefaultInterface.fPointSize = glPointSize;
- gDefaultInterface.fPixelStorei = glPixelStorei;
- gDefaultInterface.fReadBuffer = glReadBuffer;
- gDefaultInterface.fReadPixels = glReadPixels;
- gDefaultInterface.fScissor = glScissor;
- gDefaultInterface.fShadeModel = glShadeModel;
+ defaultInterface->fMatrixMode = glMatrixMode;
+ defaultInterface->fPointSize = glPointSize;
+ defaultInterface->fPixelStorei = glPixelStorei;
+ defaultInterface->fReadBuffer = glReadBuffer;
+ defaultInterface->fReadPixels = glReadPixels;
+ defaultInterface->fScissor = glScissor;
+ defaultInterface->fShadeModel = glShadeModel;
GR_GL_GET_PROC(ShaderSource);
- gDefaultInterface.fStencilFunc = glStencilFunc;
+ defaultInterface->fStencilFunc = glStencilFunc;
GR_GL_GET_PROC(StencilFuncSeparate);
- gDefaultInterface.fStencilMask = glStencilMask;
+ defaultInterface->fStencilMask = glStencilMask;
GR_GL_GET_PROC(StencilMaskSeparate);
- gDefaultInterface.fStencilOp = glStencilOp;
+ defaultInterface->fStencilOp = glStencilOp;
GR_GL_GET_PROC(StencilOpSeparate);
- gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
- gDefaultInterface.fTexEnvi = glTexEnvi;
- gDefaultInterface.fTexImage2D = glTexImage2D;
- gDefaultInterface.fTexParameteri = glTexParameteri;
- gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
+ defaultInterface->fTexCoordPointer = glTexCoordPointer;
+ defaultInterface->fTexEnvi = glTexEnvi;
+ defaultInterface->fTexImage2D = glTexImage2D;
+ defaultInterface->fTexParameteri = glTexParameteri;
+ defaultInterface->fTexSubImage2D = glTexSubImage2D;
GR_GL_GET_PROC(Uniform1f);
GR_GL_GET_PROC(Uniform1i);
GR_GL_GET_PROC(Uniform1fv);
GR_GL_GET_PROC(UseProgram);
GR_GL_GET_PROC(VertexAttrib4fv);
GR_GL_GET_PROC(VertexAttribPointer);
- gDefaultInterface.fVertexPointer = glVertexPointer;
- gDefaultInterface.fViewport = glViewport;
+ defaultInterface->fVertexPointer = glVertexPointer;
+ defaultInterface->fViewport = glViewport;
GR_GL_GET_PROC(BindFragDataLocationIndexed);
// First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
// we must have FBOs
return;
}
- gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+ defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
- gDefaultInterfaceInit = true;
+ GrGLSetDefaultGLInterface(defaultInterface)->unref();
}
- if (gDefaultInterfaceInit)
- GrGLSetGLInterface(&gDefaultInterface);
}
* Otherwise, a springboard would be needed that hides the calling convention.
*/
-#define GR_GL_GET_PROC(F) gDefaultInterface.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F);
-#define GR_GL_GET_PROC_SUFFIX(F, S) gDefaultInterface.f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S);
+#define GR_GL_GET_PROC(F) defaultInterface->f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F);
+#define GR_GL_GET_PROC_SUFFIX(F, S) defaultInterface->f ## F = (GrGL ## F ## Proc) wglGetProcAddress("gl" #F #S);
-void GrGLSetDefaultGLInterface() {
- static GrGLInterface gDefaultInterface;
- static bool gDefaultInterfaceInit;
- if (!gDefaultInterfaceInit) {
+void GrGLInitializeDefaultGLInterface() {
- // wglGetProcAddress requires a context.
- if (NULL != wglGetCurrentContext()) {
- int major, minor;
- const char* versionString = (const char*) glGetString(GL_VERSION);
- const char* extString = (const char*) glGetString(GL_EXTENSIONS);
- gl_version_from_string(&major, &minor, versionString);
+ // wglGetProcAddress requires a context.
+ if (NULL != wglGetCurrentContext()) {
+ int major, minor;
+ const char* versionString = (const char*) glGetString(GL_VERSION);
+ const char* extString = (const char*) glGetString(GL_EXTENSIONS);
+ gl_version_from_string(&major, &minor, versionString);
- if (major == 1 && minor < 5) {
- // We must have array and element_array buffer objects.
- return;
- }
+ if (major == 1 && minor < 5) {
+ // We must have array and element_array buffer objects.
+ return;
+ }
+ GrGLInterface* defaultInterface = new GrGLInterface();
- gDefaultInterface.fNPOTRenderTargetSupport = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetHeight = kProbe_GrGLCapability;
- gDefaultInterface.fMinRenderTargetWidth = kProbe_GrGLCapability;
+ defaultInterface->fNPOTRenderTargetSupport = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetHeight = kProbe_GrGLCapability;
+ defaultInterface->fMinRenderTargetWidth = kProbe_GrGLCapability;
- // Functions that are part of GL 1.1 will return NULL in
- // wglGetProcAddress
- gDefaultInterface.fBlendFunc = glBlendFunc;
- gDefaultInterface.fClear = glClear;
- gDefaultInterface.fClearColor = glClearColor;
- gDefaultInterface.fClearStencil = glClearStencil;
- gDefaultInterface.fColor4ub = glColor4ub;
- gDefaultInterface.fColorMask = glColorMask;
- gDefaultInterface.fColorPointer = glColorPointer;
- gDefaultInterface.fCullFace = glCullFace;
- gDefaultInterface.fDeleteTextures = glDeleteTextures;
- gDefaultInterface.fDepthMask = glDepthMask;
- gDefaultInterface.fDisable = glDisable;
- gDefaultInterface.fDisableClientState = glDisableClientState;
- gDefaultInterface.fDrawArrays = glDrawArrays;
- gDefaultInterface.fDrawBuffer = glDrawBuffer;
- gDefaultInterface.fDrawElements = glDrawElements;
- gDefaultInterface.fEnable = glEnable;
- gDefaultInterface.fEnableClientState = glEnableClientState;
- gDefaultInterface.fFrontFace = glFrontFace;
- gDefaultInterface.fGenTextures = glGenTextures;
- gDefaultInterface.fGetError = glGetError;
- gDefaultInterface.fGetIntegerv = glGetIntegerv;
- gDefaultInterface.fGetString = glGetString;
- gDefaultInterface.fGetTexLevelParameteriv = glGetTexLevelParameteriv;
- gDefaultInterface.fLineWidth = glLineWidth;
- gDefaultInterface.fLoadMatrixf = glLoadMatrixf;
- gDefaultInterface.fMatrixMode = glMatrixMode;
- gDefaultInterface.fPixelStorei = glPixelStorei;
- gDefaultInterface.fPointSize = glPointSize;
- gDefaultInterface.fReadBuffer = glReadBuffer;
- gDefaultInterface.fReadPixels = glReadPixels;
- gDefaultInterface.fScissor = glScissor;
- gDefaultInterface.fShadeModel = glShadeModel;
- gDefaultInterface.fStencilFunc = glStencilFunc;
- gDefaultInterface.fStencilMask = glStencilMask;
- gDefaultInterface.fStencilOp = glStencilOp;
- gDefaultInterface.fTexImage2D = glTexImage2D;
- gDefaultInterface.fTexParameteri = glTexParameteri;
- gDefaultInterface.fTexCoordPointer = glTexCoordPointer;
- gDefaultInterface.fTexEnvi = glTexEnvi;
- gDefaultInterface.fTexSubImage2D = glTexSubImage2D;
- gDefaultInterface.fViewport = glViewport;
- gDefaultInterface.fVertexPointer = glVertexPointer;
+ // Functions that are part of GL 1.1 will return NULL in
+ // wglGetProcAddress
+ defaultInterface->fBlendFunc = glBlendFunc;
+ defaultInterface->fClear = glClear;
+ defaultInterface->fClearColor = glClearColor;
+ defaultInterface->fClearStencil = glClearStencil;
+ defaultInterface->fColor4ub = glColor4ub;
+ defaultInterface->fColorMask = glColorMask;
+ defaultInterface->fColorPointer = glColorPointer;
+ defaultInterface->fCullFace = glCullFace;
+ defaultInterface->fDeleteTextures = glDeleteTextures;
+ defaultInterface->fDepthMask = glDepthMask;
+ defaultInterface->fDisable = glDisable;
+ defaultInterface->fDisableClientState = glDisableClientState;
+ defaultInterface->fDrawArrays = glDrawArrays;
+ defaultInterface->fDrawElements = glDrawElements;
+ defaultInterface->fDrawBuffer = glDrawBuffer;
+ defaultInterface->fEnable = glEnable;
+ defaultInterface->fEnableClientState = glEnableClientState;
+ defaultInterface->fFrontFace = glFrontFace;
+ defaultInterface->fGenTextures = glGenTextures;
+ defaultInterface->fGetError = glGetError;
+ defaultInterface->fGetIntegerv = glGetIntegerv;
+ defaultInterface->fGetString = glGetString;
+ defaultInterface->fGetTexLevelParameteriv = glGetTexLevelParameteriv;
+ defaultInterface->fLineWidth = glLineWidth;
+ defaultInterface->fLoadMatrixf = glLoadMatrixf;
+ defaultInterface->fMatrixMode = glMatrixMode;
+ defaultInterface->fPixelStorei = glPixelStorei;
+ defaultInterface->fPointSize = glPointSize;
+ defaultInterface->fReadBuffer = glReadBuffer;
+ defaultInterface->fReadPixels = glReadPixels;
+ defaultInterface->fScissor = glScissor;
+ defaultInterface->fShadeModel = glShadeModel;
+ defaultInterface->fStencilFunc = glStencilFunc;
+ defaultInterface->fStencilMask = glStencilMask;
+ defaultInterface->fStencilOp = glStencilOp;
+ defaultInterface->fTexImage2D = glTexImage2D;
+ defaultInterface->fTexParameteri = glTexParameteri;
+ defaultInterface->fTexCoordPointer = glTexCoordPointer;
+ defaultInterface->fTexEnvi = glTexEnvi;
+ defaultInterface->fTexSubImage2D = glTexSubImage2D;
+ defaultInterface->fViewport = glViewport;
+ defaultInterface->fVertexPointer = glVertexPointer;
- GR_GL_GET_PROC(ActiveTexture);
- GR_GL_GET_PROC(AttachShader);
- GR_GL_GET_PROC(BindAttribLocation);
- GR_GL_GET_PROC(BindBuffer);
- GR_GL_GET_PROC(BindTexture);
- GR_GL_GET_PROC(BlendColor);
- GR_GL_GET_PROC(BufferData);
- GR_GL_GET_PROC(BufferSubData);
- GR_GL_GET_PROC(ClientActiveTexture);
- GR_GL_GET_PROC(CompileShader);
- GR_GL_GET_PROC(CompressedTexImage2D);
- GR_GL_GET_PROC(CreateProgram);
- GR_GL_GET_PROC(CreateShader);
- GR_GL_GET_PROC(DeleteBuffers);
- GR_GL_GET_PROC(DeleteProgram);
- GR_GL_GET_PROC(DeleteShader);
- GR_GL_GET_PROC(DisableVertexAttribArray);
- GR_GL_GET_PROC(DrawBuffers);
- GR_GL_GET_PROC(EnableVertexAttribArray);
- GR_GL_GET_PROC(GenBuffers);
- GR_GL_GET_PROC(GetBufferParameteriv);
- GR_GL_GET_PROC(GetProgramInfoLog);
- GR_GL_GET_PROC(GetProgramiv);
- GR_GL_GET_PROC(GetShaderInfoLog);
- GR_GL_GET_PROC(GetShaderiv);
- GR_GL_GET_PROC(GetUniformLocation);
- GR_GL_GET_PROC(LinkProgram);
- GR_GL_GET_PROC(ShaderSource);
- GR_GL_GET_PROC(StencilFuncSeparate);
- GR_GL_GET_PROC(StencilMaskSeparate);
- GR_GL_GET_PROC(StencilOpSeparate);
- GR_GL_GET_PROC(Uniform1f);
- GR_GL_GET_PROC(Uniform1i);
- GR_GL_GET_PROC(Uniform1fv);
- GR_GL_GET_PROC(Uniform1iv);
- GR_GL_GET_PROC(Uniform2f);
- GR_GL_GET_PROC(Uniform2i);
- GR_GL_GET_PROC(Uniform2fv);
- GR_GL_GET_PROC(Uniform2iv);
- GR_GL_GET_PROC(Uniform3f);
- GR_GL_GET_PROC(Uniform3i);
- GR_GL_GET_PROC(Uniform3fv);
- GR_GL_GET_PROC(Uniform3iv);
- GR_GL_GET_PROC(Uniform4f);
- GR_GL_GET_PROC(Uniform4i);
- GR_GL_GET_PROC(Uniform4fv);
- GR_GL_GET_PROC(Uniform4iv);
- GR_GL_GET_PROC(UniformMatrix2fv);
- GR_GL_GET_PROC(UniformMatrix3fv);
- GR_GL_GET_PROC(UniformMatrix4fv);
- GR_GL_GET_PROC(UseProgram);
- GR_GL_GET_PROC(VertexAttrib4fv);
- GR_GL_GET_PROC(VertexAttribPointer);
- GR_GL_GET_PROC(BindFragDataLocationIndexed);
+ GR_GL_GET_PROC(ActiveTexture);
+ GR_GL_GET_PROC(AttachShader);
+ GR_GL_GET_PROC(BindAttribLocation);
+ GR_GL_GET_PROC(BindBuffer);
+ GR_GL_GET_PROC(BindTexture);
+ GR_GL_GET_PROC(BlendColor);
+ GR_GL_GET_PROC(BufferData);
+ GR_GL_GET_PROC(BufferSubData);
+ GR_GL_GET_PROC(ClientActiveTexture);
+ GR_GL_GET_PROC(CompileShader);
+ GR_GL_GET_PROC(CompressedTexImage2D);
+ GR_GL_GET_PROC(CreateProgram);
+ GR_GL_GET_PROC(CreateShader);
+ GR_GL_GET_PROC(DeleteBuffers);
+ GR_GL_GET_PROC(DeleteProgram);
+ GR_GL_GET_PROC(DeleteShader);
+ GR_GL_GET_PROC(DisableVertexAttribArray);
+ GR_GL_GET_PROC(DrawBuffers);
+ GR_GL_GET_PROC(EnableVertexAttribArray);
+ GR_GL_GET_PROC(GenBuffers);
+ GR_GL_GET_PROC(GetBufferParameteriv);
+ GR_GL_GET_PROC(GetProgramInfoLog);
+ GR_GL_GET_PROC(GetProgramiv);
+ GR_GL_GET_PROC(GetShaderInfoLog);
+ GR_GL_GET_PROC(GetShaderiv);
+ GR_GL_GET_PROC(GetUniformLocation);
+ GR_GL_GET_PROC(LinkProgram);
+ GR_GL_GET_PROC(ShaderSource);
+ GR_GL_GET_PROC(StencilFuncSeparate);
+ GR_GL_GET_PROC(StencilMaskSeparate);
+ GR_GL_GET_PROC(StencilOpSeparate);
+ GR_GL_GET_PROC(Uniform1f);
+ GR_GL_GET_PROC(Uniform1i);
+ GR_GL_GET_PROC(Uniform1fv);
+ GR_GL_GET_PROC(Uniform1iv);
+ GR_GL_GET_PROC(Uniform2f);
+ GR_GL_GET_PROC(Uniform2i);
+ GR_GL_GET_PROC(Uniform2fv);
+ GR_GL_GET_PROC(Uniform2iv);
+ GR_GL_GET_PROC(Uniform3f);
+ GR_GL_GET_PROC(Uniform3i);
+ GR_GL_GET_PROC(Uniform3fv);
+ GR_GL_GET_PROC(Uniform3iv);
+ GR_GL_GET_PROC(Uniform4f);
+ GR_GL_GET_PROC(Uniform4i);
+ GR_GL_GET_PROC(Uniform4fv);
+ GR_GL_GET_PROC(Uniform4iv);
+ GR_GL_GET_PROC(UniformMatrix2fv);
+ GR_GL_GET_PROC(UniformMatrix3fv);
+ GR_GL_GET_PROC(UniformMatrix4fv);
+ GR_GL_GET_PROC(UseProgram);
+ GR_GL_GET_PROC(VertexAttrib4fv);
+ GR_GL_GET_PROC(VertexAttribPointer);
+ GR_GL_GET_PROC(BindFragDataLocationIndexed);
- // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
- // GL_ARB_framebuffer_object doesn't use ARB suffix.)
- if (major >= 3 || has_gl_extension_from_string("GL_ARB_framebuffer_object", extString)) {
- GR_GL_GET_PROC(GenFramebuffers);
- GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
- GR_GL_GET_PROC(GetRenderbufferParameteriv);
- GR_GL_GET_PROC(BindFramebuffer);
- GR_GL_GET_PROC(FramebufferTexture2D);
- GR_GL_GET_PROC(CheckFramebufferStatus);
- GR_GL_GET_PROC(DeleteFramebuffers);
- GR_GL_GET_PROC(RenderbufferStorage);
- GR_GL_GET_PROC(GenRenderbuffers);
- GR_GL_GET_PROC(DeleteRenderbuffers);
- GR_GL_GET_PROC(FramebufferRenderbuffer);
- GR_GL_GET_PROC(BindRenderbuffer);
- GR_GL_GET_PROC(RenderbufferStorageMultisample);
- GR_GL_GET_PROC(BlitFramebuffer);
- } else if (has_gl_extension_from_string("GL_EXT_framebuffer_object", extString)) {
- GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
- GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
- GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
- GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
- GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
- GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
- GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
- GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
- GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
- GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
- GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
- GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
- if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample", extString)) {
- GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
- }
- if (has_gl_extension_from_string("GL_EXT_framebuffer_blit", extString)) {
- GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
- }
- } else {
- // we must have FBOs
- return;
+ // First look for GL3.0 FBO or GL_ARB_framebuffer_object (same since
+ // GL_ARB_framebuffer_object doesn't use ARB suffix.)
+ if (major >= 3 || has_gl_extension_from_string("GL_ARB_framebuffer_object", extString)) {
+ GR_GL_GET_PROC(GenFramebuffers);
+ GR_GL_GET_PROC(GetFramebufferAttachmentParameteriv);
+ GR_GL_GET_PROC(GetRenderbufferParameteriv);
+ GR_GL_GET_PROC(BindFramebuffer);
+ GR_GL_GET_PROC(FramebufferTexture2D);
+ GR_GL_GET_PROC(CheckFramebufferStatus);
+ GR_GL_GET_PROC(DeleteFramebuffers);
+ GR_GL_GET_PROC(RenderbufferStorage);
+ GR_GL_GET_PROC(GenRenderbuffers);
+ GR_GL_GET_PROC(DeleteRenderbuffers);
+ GR_GL_GET_PROC(FramebufferRenderbuffer);
+ GR_GL_GET_PROC(BindRenderbuffer);
+ GR_GL_GET_PROC(RenderbufferStorageMultisample);
+ GR_GL_GET_PROC(BlitFramebuffer);
+ } else if (has_gl_extension_from_string("GL_EXT_framebuffer_object", extString)) {
+ GR_GL_GET_PROC_SUFFIX(GenFramebuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(GetFramebufferAttachmentParameteriv, EXT);
+ GR_GL_GET_PROC_SUFFIX(GetRenderbufferParameteriv, EXT);
+ GR_GL_GET_PROC_SUFFIX(BindFramebuffer, EXT);
+ GR_GL_GET_PROC_SUFFIX(FramebufferTexture2D, EXT);
+ GR_GL_GET_PROC_SUFFIX(CheckFramebufferStatus, EXT);
+ GR_GL_GET_PROC_SUFFIX(DeleteFramebuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(RenderbufferStorage, EXT);
+ GR_GL_GET_PROC_SUFFIX(GenRenderbuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(DeleteRenderbuffers, EXT);
+ GR_GL_GET_PROC_SUFFIX(FramebufferRenderbuffer, EXT);
+ GR_GL_GET_PROC_SUFFIX(BindRenderbuffer, EXT);
+ if (has_gl_extension_from_string("GL_EXT_framebuffer_multisample", extString)) {
+ GR_GL_GET_PROC_SUFFIX(RenderbufferStorageMultisample, EXT);
+ }
+ if (has_gl_extension_from_string("GL_EXT_framebuffer_blit", extString)) {
+ GR_GL_GET_PROC_SUFFIX(BlitFramebuffer, EXT);
}
- GR_GL_GET_PROC(MapBuffer);
- GR_GL_GET_PROC(UnmapBuffer);
+ } else {
+ // we must have FBOs
+ return;
+ }
+ GR_GL_GET_PROC(MapBuffer);
+ GR_GL_GET_PROC(UnmapBuffer);
- gDefaultInterface.fBindingsExported = kDesktop_GrGLBinding;
+ defaultInterface->fBindingsExported = kDesktop_GrGLBinding;
- gDefaultInterfaceInit = true;
- }
- }
- if (gDefaultInterfaceInit) {
- GrGLSetGLInterface(&gDefaultInterface);
+ GrGLSetDefaultGLInterface(defaultInterface)->unref();
}
}
'../gpu/src/GrGLProgram.h',
'../gpu/src/GrGLRenderTarget.cpp',
'../gpu/src/GrGLRenderTarget.h',
+ '../gpu/src/GrGLStencilBuffer.cpp',
'../gpu/src/GrGLStencilBuffer.h',
'../gpu/src/GrGLTexture.cpp',
'../gpu/src/GrGLTexture.h',
desc.fWidth = SkScalarRound(win->width());
desc.fHeight = SkScalarRound(win->height());
desc.fConfig = kRGBA_8888_GrPixelConfig;
- GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, &desc.fStencilBits);
- GR_GL_GetIntegerv(GR_GL_SAMPLES, &desc.fSampleCnt);
+ const GrGLInterface* gl = GrGLGetDefaultGLInterface();
+ GrAssert(NULL != gl);
+ GR_GL_GetIntegerv(gl, GR_GL_STENCIL_BITS, &desc.fStencilBits);
+ GR_GL_GetIntegerv(gl, GR_GL_SAMPLES, &desc.fSampleCnt);
GrGLint buffer;
- GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
+ GR_GL_GetIntegerv(gl, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fPlatformRenderTarget = buffer;
SkSafeUnref(fGrRenderTarget);