Cleanup including of GL headers and provide way to include custom headers, extension getter.

git-svn-id: http://skia.googlecode.com/svn/trunk@713 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-01-19 17:19:40 +00:00
Родитель e49d571175
Коммит 42ab7ea76e
8 изменённых файлов: 415 добавлений и 378 удалений

Просмотреть файл

@ -20,146 +20,166 @@
#include "GrTypes.h"
#if GR_CHROME_BUILD // temporary build-flag, orthogonal to mac/win/linux
#define GR_INCLUDE_GLES2 <GLES2/gl2.h>
#define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
#define GR_GL_FUNC
#elif GR_WIN32_BUILD
#if !defined(GR_GL_CUSTOM_SETUP)
#define GR_GL_CUSTOM_SETUP 0
#endif
/**
* We need to pull in the right GL headers and determine whether we are
* compiling for ES1, ES2, or desktop GL. (We allow ES1 and ES2 to both be
* supported in the same build but not ESx and desktop). We also need to know
* the platform-specific way to get extension function pointers (e.g.
* eglGetProcAddress). The port specifies this info explicitly or we will infer
* it from the GR_*_BUILD flag.
*
* To specify GL setup directly define GR_GL_CUSTOM_SETUP to 1 and define:
* GR_SUPPORT_GLDESKTOP or (GR_SUPPORT_GLES1 and/or GR_SUPPORT_GLES2) to 1
*
* if GR_SUPPORT_GLDESKTOP is 1 then provide:
* 1. The name of your GL header in GR_INCLUDE_GLDESKTOP
* 2. If necessary, the name of a file that includes extension
* definitions in GR_INCLUDE_GLDESKTOPext.
* if GR_SUPPORT_GLES1 is 1 then provide:
* 1. The name of your GL header in GR_INCLUDE_GLES1
* 2. If necessary, the name of a file that includes extension
* definitions in GR_INCLUDE_GLES1ext.
* if GR_SUPPORT_GLES2 is 1 then provide:
* 1. The name of your GL header in GR_INCLUDE_GLES2
* 2. If necessary, the name of a file that includes extension
* definitions in GR_INCLUDE_GLES2ext.
*
* Optionally, define GR_GL_FUNC to any qualifier needed on GL function
* pointer declarations (e.g. __stdcall).
*
* Define GR_GL_PROC_ADDRESS to take a gl function and produce a
* function pointer. Two examples:
* 1. Your platform doesn't require a proc address function, just take
* the address of the function:
* #define GR_GL_PROC_ADDRESS(X) &X
* 2. Your platform uses eglGetProcAddress:
* #define GR_GL_PROC_ADDRESS eglGetProcAddress(#X)
*
* Optionally define GR_GL_PROC_ADDRESS_HEADER to include any additional
* header necessary to use GR_GL_PROC_ADDRESS (e.g. <EGL/egl.h>)
*
* Alternatively, define GR_GL_CUSTOM_SETUP_HEADER (and not GR_GL_CUSTOM_SETUP)
* to a header that can be included. This file should:
* 1. Define the approprate GR_SUPPORT_GL* macro(s) to 1
* 2. Includes all necessary GL headers.
* 3. Optionally define GR_GL_FUNC.
* 4. Define GR_GL_PROC_ADDRESS.
* 5. Optionally define GR_GL_PROC_ADDRESS_HEADER
*/
#if GR_GL_CUSTOM_SETUP
#ifdef GR_SUPPORT_GLES1
#include GR_INCLUDE_GLES1
#if defined(GR_INCLUDE_GLES1ext)
#include GR_INCLUDE_GLES1ext
#endif
#endif
#ifdef GR_SUPPORT_GLES2
#include GR_INCLUDE_GLES2
#if defined(GR_INCLUDE_GLES2ext)
#include GR_INCLUDE_GLES2ext
#endif
#endif
#ifdef GR_SUPPORT_GLDESKTOP
#include GR_INCLUDE_GLDESKTOP
#if defined(GR_INCLUDE_GLDESKTOPext)
#include GR_INCLUDE_GLDESKTOPext
#endif
#endif
#elif defined(GR_GL_CUSTOM_SETUP_HEADER)
#include GR_GL_CUSTOM_SETUP_HEADER
#else
#if GR_WIN32_BUILD
#define GR_SUPPORT_GLDESKTOP 1
// glew has to be included before gl
#define GR_INCLUDE_GLDESKTOP <GL/glew.h>
#define GR_INCLUDE_GLDESKTOPext <GL/gl.h>
#define GR_GL_FUNC __stdcall
// undo stupid windows defines
#include <GL/glew.h>
#include <GL/gl.h>
// remove stupid windows defines
#undef near
#undef far
#elif GR_MAC_BUILD
#define GR_INCLUDE_GLDESKTOP <OpenGL/gl.h>
#define GR_INCLUDE_GLDESKTOPext <OpenGL/glext.h>
#define GR_GL_FUNC
#elif GR_IOS_BUILD
#define GR_INCLUDE_GLES1 <OpenGLES/ES1/gl.h>
#define GR_INCLUDE_GLES1ext <OpenGLES/ES1/glext.h>
#define GR_INCLUDE_GLES2 <OpenGLES/ES2/gl.h>
#define GR_INCLUDE_GLES2ext <OpenGLES/ES2/glext.h>
#define GR_GL_FUNC
#elif GR_ANDROID_BUILD
#define GR_GL_FUNC __stdcall
#define GR_GL_PROC_ADDRESS(X) wglGetProcAddress(#X)
#define GR_GL_PROC_ADDRESS_HEADER <windows.h>
#elif GR_MAC_BUILD
#define GR_SUPPORT_GLDESKTOP 1
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#define GR_GL_PROC_ADDRESS(X) &X
#elif GR_IOS_BUILD
#define GR_SUPPORT_GLES1 1
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
#define GR_SUPPORT_GLES2 1
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#define GR_GL_PROC_ADDRESS(X) &X
#elif GR_ANDROID_BUILD
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#define GR_INCLUDE_GLES2 <GLES2/gl2.h>
#define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
#define GR_GL_FUNC
#elif GR_LINUX_BUILD
// need to distinguish between ES and Deskop versions for linux
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#define GR_INCLUDE_GLDESKTOP <GL/gl.h>
#define GR_INCLUDE_GLDESKTOPext <GL/glext.h>
// #define GR_INCLUDE_GLES1 <GLES/gl.h>
// #define GR_INCLUDE_GLES1ext <GLES/glext.h>
// #define GR_INCLUDE_GLES2 <GLES2/gl2.h>
// #define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
#define GR_GL_FUNC
#elif GR_QNX_BUILD
#define GR_SUPPORT_GLES2 1
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
#define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
#elif GR_QNX_BUILD
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#define GR_SUPPORT_GLES2 1
// This is needed by the QNX GLES2 headers
#define GL_API_EXT
#define GR_INCLUDE_GLES2 <GLES2/gl2.h>
#define GR_INCLUDE_GLES2ext <GLES2/gl2ext.h>
#define GR_INCLUDE_EGL <EGL/egl.h>
#define GR_GL_FUNC
#else
#error "unsupported GR_???_BUILD"
#endif
// Ensure we're at least defined
//
#ifndef GR_SUPPORT_GLES1
#if defined(GR_INCLUDE_GLES1)
#define GR_SUPPORT_GLES1 1
#else
#define GR_SUPPORT_GLES1 0
#endif
#endif
#ifndef GR_SUPPORT_GLES2
#if defined(GR_INCLUDE_GLES2)
#define GR_SUPPORT_GLES2 1
#else
#define GR_SUPPORT_GLES2 0
#endif
#endif
#define GR_SUPPORT_GLES (GR_SUPPORT_GLES1 || GR_SUPPORT_GLES2)
#ifndef GR_SUPPORT_GLDESKTOP
#if defined(GR_INCLUDE_GLDESKTOP)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
#define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
#elif GR_LINUX_BUILD
#define GR_SUPPORT_GLDESKTOP 1
#include <GL/gl.h>
#include <GL/glext.h>
#define GR_GL_PROC_ADDRESS(X) eglGetProcAddress(#X)
#define GR_GL_PROC_ADDRESS_HEADER <EGL/egl.h>
#else
#error "unsupported GR_???_BUILD"
#endif
#endif
#if !defined(GR_SUPPORT_GLDESKTOP)
#define GR_SUPPORT_GLDESKTOP 0
#endif
#endif
#if !defined(GR_SUPPORT_GLES1)
#define GR_SUPPORT_GLES1 0
#endif
#if !defined(GR_SUPPORT_GLES2)
#define GR_SUPPORT_GLES2 0
#endif
#ifndef GR_SUPPORT_EGL
#if defined(GR_INCLUDE_EGL)
#define GR_SUPPORT_EGL 1
#else
#define GR_SUPPORT_EGL 0
#endif
#endif
// Filter the includes based on what we support
//
#define GR_SUPPORT_GLES ((GR_SUPPORT_GLES1) || (GR_SUPPORT_GLES2))
#if !GR_SUPPORT_GLES1
#undef GR_INCLUDE_GLES1
#undef GR_INCLUDE_GLES1ext
#if !(GR_SUPPORT_GLES) != !(GR_SUPPORT_DESKTOP)
#error "Either desktop of ES GL must be supported but not both"
#endif
#if !GR_SUPPORT_GLES2
#undef GR_INCLUDE_GLES2
#undef GR_INCLUDE_GLES2ext
#if !defined(GR_GL_FUNC)
#define GR_GL_FUNC
#endif
#if !GR_SUPPORT_GLDESKTOP
#undef GR_INCLUDE_GLDESKTOP
#undef GR_INCLUDE_GLDESKTOPext
#if !defined(GR_GL_PROC_ADDRESS)
#error "Must define GR_GL_PROC_ADDRESS"
#endif
#if !GR_SUPPORT_EGL
#undef GR_INCLUDE_EGL
#endif
// Begin including GL headers
//
#ifdef GR_INCLUDE_GLES1
#include GR_INCLUDE_GLES1
#endif
#ifdef GR_INCLUDE_GLES1ext
#include GR_INCLUDE_GLES1ext
#endif
#ifdef GR_INCLUDE_GLES2
#include GR_INCLUDE_GLES2
#endif
#ifdef GR_INCLUDE_GLES2ext
#include GR_INCLUDE_GLES2ext
#endif
#ifdef GR_INCLUDE_GLDESKTOP
#include GR_INCLUDE_GLDESKTOP
#endif
#ifdef GR_INCLUDE_GLDESKTOPext
#include GR_INCLUDE_GLDESKTOPext
#endif
#ifdef GR_INCLUDE_EGL
#include GR_INCLUDE_EGL
#endif
//
// End including GL headers
////////////////////////////////////////////////////////////////////////////////
#if GR_SCALAR_IS_FIXED
#define GrGLType GL_FIXED
@ -193,8 +213,8 @@
#endif
////////////////////////////////////////////////////////////////////////////////
// setup for opengl ES/desktop extensions
// we make a struct of function pointers so that each GL context
// Setup for opengl ES/desktop extensions
// We make a struct of function pointers so that each GL context
// can have it's own struct. (Some environments may have different proc
// addresses for different contexts).
@ -289,6 +309,7 @@ struct GrGLExts {
#define GR_PALETTE8_RGBA8 0x8B91
extern void GrGLInitExtensions(GrGLExts* exts);
////////////////////////////////////////////////////////////////////////////////
extern void GrGLCheckErr(const char* location, const char* call);

Просмотреть файл

@ -56,9 +56,6 @@
* temporary flags (may go away soon)
*/
// specific changes for current Chrome build
//#define GR_CHROME_BUILD 1
// disable 2-point-radial gradient shader programs
//#define GR_SKIP_2POINTRADIAL_PROGRAMS

256
gpu/src/GrGLUtil.cpp Normal file
Просмотреть файл

@ -0,0 +1,256 @@
/*
Copyright 2010 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "GrGLConfig.h"
#include <stdio.h>
bool has_gl_extension(const char* ext) {
const char* glstr = (const char*) glGetString(GL_EXTENSIONS);
int extLength = strlen(ext);
while (true) {
int n = strcspn(glstr, " ");
if (n == extLength && 0 == strncmp(ext, glstr, n)) {
return true;
}
if (0 == glstr[n]) {
return false;
}
glstr += n+1;
}
}
void gl_version(int* major, int* minor) {
const char* v = (const char*) glGetString(GL_VERSION);
if (NULL == v) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#if GR_SUPPORT_GLDESKTOP
int n = sscanf(v, "%d.%d", major, minor);
if (n != 2) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#else
char profile[2];
int n = sscanf(v, "OpenGL ES-%c%c %d.%d", profile, profile+1, major, minor);
bool ok = 4 == n;
if (!ok) {
int n = sscanf(v, "OpenGL ES %d.%d", major, minor);
ok = 2 == n;
}
if (!ok) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#endif
}
#if defined(GR_GL_PROC_ADDRESS_HEADER)
#include GR_GL_PROC_ADDRESS_HEADER
#endif
typedef void (*glProc)(void);
#define GET_PROC(EXT_STRUCT, PROC_NAME) \
*((glProc*) &(EXT_STRUCT-> PROC_NAME)) = (glProc) GR_GL_PROC_ADDRESS((gl ## PROC_NAME)); \
GrAssert(NULL != EXT_STRUCT-> PROC_NAME)
#define GET_SUFFIX_PROC(EXT_STRUCT, PROC_NAME, SUFFIX) \
*((glProc*) &(EXT_STRUCT-> PROC_NAME)) = (glProc) GR_GL_PROC_ADDRESS((gl ## PROC_NAME ## SUFFIX)); \
GrAssert(NULL != EXT_STRUCT-> PROC_NAME)
extern void GrGLInitExtensions(GrGLExts* exts) {
exts->GenFramebuffers = NULL;
exts->BindFramebuffer = NULL;
exts->FramebufferTexture2D = NULL;
exts->CheckFramebufferStatus = NULL;
exts->DeleteFramebuffers = NULL;
exts->RenderbufferStorage = NULL;
exts->GenRenderbuffers = NULL;
exts->DeleteRenderbuffers = NULL;
exts->FramebufferRenderbuffer = NULL;
exts->BindRenderbuffer = NULL;
exts->RenderbufferStorageMultisample = NULL;
exts->BlitFramebuffer = NULL;
exts->ResolveMultisampleFramebuffer = NULL;
exts->FramebufferTexture2DMultisample = NULL;
exts->MapBuffer = NULL;
exts->UnmapBuffer = NULL;
GLint major, minor;
gl_version(&major, &minor);
#if GR_SUPPORT_GLDESKTOP
bool fboFound = false;
#if GL_VERSION_3_0
if (!fboFound && major >= 3) { // all of ARB_fbo is in 3.x
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
exts->RenderbufferStorageMultisample = glRenderbufferStorageMultisample;
exts->BlitFramebuffer = glBlitFramebuffer;
fboFound = true;
}
#endif
#if GL_ARB_framebuffer_object
if (!fboFound && has_gl_extension("GL_ARB_framebuffer_object")) {
// GL_ARB_framebuffer_object doesn't use ARB suffix.
GET_PROC(exts, GenFramebuffers);
GET_PROC(exts, BindFramebuffer);
GET_PROC(exts, FramebufferTexture2D);
GET_PROC(exts, CheckFramebufferStatus);
GET_PROC(exts, DeleteFramebuffers);
GET_PROC(exts, RenderbufferStorage);
GET_PROC(exts, GenRenderbuffers);
GET_PROC(exts, DeleteRenderbuffers);
GET_PROC(exts, FramebufferRenderbuffer);
GET_PROC(exts, BindRenderbuffer);
GET_PROC(exts, RenderbufferStorageMultisample);
GET_PROC(exts, BlitFramebuffer);
fboFound = true;
}
#endif
// Mac doesn't declare prototypes for EXT FBO extensions
#if GL_EXT_framebuffer_object && !GR_MAC_BUILD
if (!fboFound && has_gl_extension("GL_EXT_framebuffer_object")) {
GET_SUFFIX_PROC(exts, GenFramebuffers, EXT);
GET_SUFFIX_PROC(exts, BindFramebuffer, EXT);
GET_SUFFIX_PROC(exts, FramebufferTexture2D, EXT);
GET_SUFFIX_PROC(exts, CheckFramebufferStatus, EXT);
GET_SUFFIX_PROC(exts, DeleteFramebuffers, EXT);
GET_SUFFIX_PROC(exts, RenderbufferStorage, EXT);
GET_SUFFIX_PROC(exts, GenRenderbuffers, EXT);
GET_SUFFIX_PROC(exts, DeleteRenderbuffers, EXT);
GET_SUFFIX_PROC(exts, FramebufferRenderbuffer, EXT);
GET_SUFFIX_PROC(exts, BindRenderbuffer, EXT);
fboFound = true;
// check for fbo ms and fbo blit
#if GL_EXT_framebuffer_multisample
if (has_gl_extension("GL_EXT_framebuffer_multisample")) {
GET_SUFFIX_PROC(exts, RenderbufferStorageMultisample, EXT);
}
#endif
#if GL_EXT_framebuffer_blit
if (has_gl_extension("GL_EXT_framebuffer_blit")) {
GET_SUFFIX_PROC(exts, BlitFramebuffer, EXT);
}
#endif
}
#endif
if (!fboFound) {
// we require some form of FBO
GrAssert(!"No FBOs supported?");
}
// we assume we have at least GL 1.5 or higher (VBOs introduced in 1.5)
exts->MapBuffer = glMapBuffer;
exts->UnmapBuffer = glUnmapBuffer;
#else // !GR_SUPPORT_GLDESKTOP
bool foundFBO = false;
#if GR_SUPPORT_GLES2
if (!fboFound && major >= 2) {// ES 2.0 supports FBO
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
fboFound = true;
}
#endif
#if !GL_OES_framebuffer_object
if (!fboFound && has_gl_extension("GL_OES_framebuffer_object")) {
GET_SUFFIX_PROC(exts, GenFramebuffers, OES);
GET_SUFFIX_PROC(exts, BindFramebuffer, OES);
GET_SUFFIX_PROC(exts, FramebufferTexture2D, OES);
GET_SUFFIX_PROC(exts, CheckFramebufferStatus, OES);
GET_SUFFIX_PROC(exts, DeleteFramebuffers, OES);
GET_SUFFIX_PROC(exts, RenderbufferStorage, OES);
GET_SUFFIX_PROC(exts, GenRenderbuffers, OES);
GET_SUFFIX_PROC(exts, DeleteRenderbuffers, OES);
GET_SUFFIX_PROC(exts, FramebufferRenderbuffer, OES);
GET_SUFFIX_PROC(exts, BindRenderbuffer, OES);
}
#endif
if (!fboFound) {
// we require some form of FBO
GrAssert(!"No FBOs supported?");
}
#if GL_APPLE_framebuffer_multisample
if (has_gl_extension("GL_APPLE_framebuffer_multisample")) {
GET_SUFFIX_PROC(exts, ResolveMultisampleFramebuffer, APPLE);
}
#endif
#if GL_IMG_multisampled_render_to_texture
if (has_gl_extension("GL_IMG_multisampled_render_to_texture")) {
GET_SUFFIX_PROC(exts, FramebufferTexture2DMultisample, IMG);
}
#endif
#if GL_OES_mapbuffer
if (has_gl_extension("GL_OES_mapbuffer")) {
GET_SUFFIX_PROC(exts, MapBuffer, OES);
GET_SUFFIX_PROC(exts, UnmapBuffer, OES);
}
#endif
#endif // !GR_SUPPORT_GLDESKTOP
}
///////////////////////////////////////////////////////////////////////////////
void GrGLCheckErr(const char* location, const char* call) {
uint32_t err = glGetError();
if (GL_NO_ERROR != err) {
GrPrintf("---- glGetError %x", err);
if (NULL != location) {
GrPrintf(" at\n\t%s", location);
}
if (NULL != call) {
GrPrintf("\n\t\t%s", call);
}
GrPrintf("\n");
}
}
///////////////////////////////////////////////////////////////////////////////
bool gPrintGL = true;

Просмотреть файл

@ -16,7 +16,6 @@
#include "GrGpuGL.h"
#include "GrMemory.h"
#include <stdio.h>
#if GR_WIN32_BUILD
// need to get wglGetProcAddress
#undef WIN32_LEAN_AND_MEAN
@ -48,57 +47,13 @@ static const GLenum gXfermodeCoeff2Blend[] = {
GL_ONE_MINUS_DST_ALPHA,
};
bool has_gl_extension(const char* ext) {
const char* glstr = (const char*) glGetString(GL_EXTENSIONS);
int extLength = strlen(ext);
while (true) {
int n = strcspn(glstr, " ");
if (n == extLength && 0 == strncmp(ext, glstr, n)) {
return true;
}
if (0 == glstr[n]) {
return false;
}
glstr += n+1;
}
}
void gl_version(int* major, int* minor) {
const char* v = (const char*) glGetString(GL_VERSION);
if (NULL == v) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#if GR_SUPPORT_GLDESKTOP
int n = sscanf(v, "%d.%d", major, minor);
if (n != 2) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#else
char profile[2];
int n = sscanf(v, "OpenGL ES-%c%c %d.%d", profile, profile+1, major, minor);
bool ok = 4 == n;
if (!ok) {
int n = sscanf(v, "OpenGL ES %d.%d", major, minor);
ok = 2 == n;
}
if (!ok) {
GrAssert(0);
*major = 0;
*minor = 0;
return;
}
#endif
}
///////////////////////////////////////////////////////////////////////////////
static bool gPrintStartupSpew;
bool fbo_test(GrGLExts exts, int w, int h) {
GLint savedFBO;
@ -132,10 +87,6 @@ bool fbo_test(GrGLExts exts, int w, int h) {
return status == GR_FRAMEBUFFER_COMPLETE;
}
///////////////////////////////////////////////////////////////////////////////
static bool gPrintStartupSpew;
GrGpuGL::GrGpuGL() {
if (gPrintStartupSpew) {
GrPrintf("------------------------- create GrGpuGL %p --------------\n",
@ -1755,197 +1706,3 @@ bool GrGpuGL::fboInternalFormat(GrTexture::PixelConfig config, GLenum* format) {
return false;
}
}
///////////////////////////////////////////////////////////////////////////////
void GrGLCheckErr(const char* location, const char* call) {
uint32_t err = glGetError();
if (GL_NO_ERROR != err) {
GrPrintf("---- glGetError %x", err);
if (NULL != location) {
GrPrintf(" at\n\t%s", location);
}
if (NULL != call) {
GrPrintf("\n\t\t%s", call);
}
GrPrintf("\n");
}
}
///////////////////////////////////////////////////////////////////////////////
typedef void (*glProc)(void);
void get_gl_proc(const char procName[], glProc *address) {
#if GR_CHROME_BUILD
GrAssert(!"should not get called");
#elif GR_WIN32_BUILD
*address = (glProc)wglGetProcAddress(procName);
GrAssert(NULL != *address);
#elif GR_MAC_BUILD || GR_IOS_BUILD
GrAssert(!"Extensions don't need to be initialized!");
#elif GR_ANDROID_BUILD
*address = eglGetProcAddress(procName);
GrAssert(NULL != *address);
#elif GR_LINUX_BUILD
// GR_STATIC_ASSERT(!"Add environment-dependent implementation here");
//*address = glXGetProcAddressARB(procName);
*address = NULL;//eglGetProcAddress(procName);
#elif GR_QNX_BUILD
*address = eglGetProcAddress(procName);
GrAssert(NULL != *address);
#else
// hopefully we're on a system with EGL
*address = eglGetProcAddress(procName);
GrAssert(NULL != *address);
#endif
}
#define GET_PROC(EXT_STRUCT, PROC_NAME, EXT_TAG) \
get_gl_proc("gl" #PROC_NAME #EXT_TAG, (glProc*)&EXT_STRUCT-> PROC_NAME);
extern void GrGLInitExtensions(GrGLExts* exts) {
exts->GenFramebuffers = NULL;
exts->BindFramebuffer = NULL;
exts->FramebufferTexture2D = NULL;
exts->CheckFramebufferStatus = NULL;
exts->DeleteFramebuffers = NULL;
exts->RenderbufferStorage = NULL;
exts->GenRenderbuffers = NULL;
exts->DeleteRenderbuffers = NULL;
exts->FramebufferRenderbuffer = NULL;
exts->BindRenderbuffer = NULL;
exts->RenderbufferStorageMultisample = NULL;
exts->BlitFramebuffer = NULL;
exts->ResolveMultisampleFramebuffer = NULL;
exts->FramebufferTexture2DMultisample = NULL;
exts->MapBuffer = NULL;
exts->UnmapBuffer = NULL;
#if GR_MAC_BUILD
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
exts->RenderbufferStorageMultisample = glRenderbufferStorageMultisample;
exts->BlitFramebuffer = glBlitFramebuffer;
exts->MapBuffer = glMapBuffer;
exts->UnmapBuffer = glUnmapBuffer;
#elif GR_IOS_BUILD
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
exts->RenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
exts->ResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
exts->MapBuffer = glMapBufferOES;
exts->UnmapBuffer = glUnmapBufferOES;
#else
GLint major, minor;
gl_version(&major, &minor);
#if GR_SUPPORT_GLDESKTOP
if (major >= 3) {// FBO, FBOMS, and FBOBLIT part of 3.0
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
exts->RenderbufferStorageMultisample = glRenderbufferStorageMultisample;
exts->BlitFramebuffer = glBlitFramebuffer;
} else if (has_gl_extension("GL_ARB_framebuffer_object")) {
GET_PROC(exts, GenFramebuffers, ARB);
GET_PROC(exts, BindFramebuffer, ARB);
GET_PROC(exts, FramebufferTexture2D, ARB);
GET_PROC(exts, CheckFramebufferStatus, ARB);
GET_PROC(exts, DeleteFramebuffers, ARB);
GET_PROC(exts, RenderbufferStorage, ARB);
GET_PROC(exts, GenRenderbuffers, ARB);
GET_PROC(exts, DeleteRenderbuffers, ARB);
GET_PROC(exts, FramebufferRenderbuffer, ARB);
GET_PROC(exts, BindRenderbuffer, ARB);
GET_PROC(exts, RenderbufferStorageMultisample, ARB);
GET_PROC(exts, BlitFramebuffer, ARB);
} else {
// we require some form of FBO
GrAssert(has_gl_extension("GL_EXT_framebuffer_object"));
GET_PROC(exts, GenFramebuffers, EXT);
GET_PROC(exts, BindFramebuffer, EXT);
GET_PROC(exts, FramebufferTexture2D, EXT);
GET_PROC(exts, CheckFramebufferStatus, EXT);
GET_PROC(exts, DeleteFramebuffers, EXT);
GET_PROC(exts, RenderbufferStorage, EXT);
GET_PROC(exts, GenRenderbuffers, EXT);
GET_PROC(exts, DeleteRenderbuffers, EXT);
GET_PROC(exts, FramebufferRenderbuffer, EXT);
GET_PROC(exts, BindRenderbuffer, EXT);
if (has_gl_extension("GL_EXT_framebuffer_multisample")) {
GET_PROC(exts, RenderbufferStorageMultisample, EXT);
}
if (has_gl_extension("GL_EXT_framebuffer_blit")) {
GET_PROC(exts, BlitFramebuffer, EXT);
}
}
// we assume we have at least GL 1.5 or higher (VBOs introduced in 1.5)
exts->MapBuffer = glMapBuffer;
exts->UnmapBuffer = glUnmapBuffer;
#else // !GR_SUPPORT_GLDESKTOP
if (major >= 2) {// ES 2.0 supports FBO
exts->GenFramebuffers = glGenFramebuffers;
exts->BindFramebuffer = glBindFramebuffer;
exts->FramebufferTexture2D = glFramebufferTexture2D;
exts->CheckFramebufferStatus = glCheckFramebufferStatus;
exts->DeleteFramebuffers = glDeleteFramebuffers;
exts->RenderbufferStorage = glRenderbufferStorage;
exts->GenRenderbuffers = glGenRenderbuffers;
exts->DeleteRenderbuffers = glDeleteRenderbuffers;
exts->FramebufferRenderbuffer = glFramebufferRenderbuffer;
exts->BindRenderbuffer = glBindRenderbuffer;
} else {
// we require some form of FBO
GrAssert(has_gl_extension("GL_OES_framebuffer_object"));
GET_PROC(exts, GenFramebuffers, OES);
GET_PROC(exts, BindFramebuffer, OES);
GET_PROC(exts, FramebufferTexture2D, OES);
GET_PROC(exts, CheckFramebufferStatus, OES);
GET_PROC(exts, DeleteFramebuffers, OES);
GET_PROC(exts, RenderbufferStorage, OES);
GET_PROC(exts, GenRenderbuffers, OES);
GET_PROC(exts, DeleteRenderbuffers, OES);
GET_PROC(exts, FramebufferRenderbuffer, OES);
GET_PROC(exts, BindRenderbuffer, OES);
}
if (has_gl_extension("GL_APPLE_framebuffer_multisample")) {
GET_PROC(exts, ResolveMultisampleFramebuffer, APPLE);
}
if (has_gl_extension("GL_IMG_multisampled_render_to_texture")) {
GET_PROC(exts, FramebufferTexture2DMultisample, IMG);
}
if (has_gl_extension("GL_OES_mapbuffer")) {
GET_PROC(exts, MapBuffer, OES);
GET_PROC(exts, UnmapBuffer, OES);
}
#endif // !GR_SUPPORT_GLDESKTOP
#endif // BUILD
}
bool gPrintGL = true;

Просмотреть файл

@ -650,7 +650,7 @@ void GrGpuGLShaders::flushProgram(PrimitiveType type) {
GrTexture* texture = fCurrDrawState.fTextures[0];
bool posAsTex =
StagePosAsTexCoordVertexLayoutBit(0) & fGeometrySrc.fVertexLayout;
!!(StagePosAsTexCoordVertexLayoutBit(0) & fGeometrySrc.fVertexLayout);
if (!VertexUsesStage(0, fGeometrySrc.fVertexLayout)) {
goto HAVE_NEXT_PROGRAM;

Просмотреть файл

@ -11,6 +11,7 @@ SOURCE := \
GrGpuGLShaders.cpp \
GrGpuGLFixed.cpp \
GrGpuFactory.cpp \
GrGLUtil.cpp \
GrGpuGL.cpp \
GrInOrderDrawBuffer.cpp \
GrMatrix.cpp \

Просмотреть файл

@ -214,6 +214,7 @@
<ClCompile Include="..\..\gpu\src\GrDrawTarget.cpp" />
<ClCompile Include="..\..\gpu\src\GrGLIndexBuffer.cpp" />
<ClCompile Include="..\..\gpu\src\GrGLTexture.cpp" />
<ClCompile Include="..\..\gpu\src\GrGLUtil.cpp" />
<ClCompile Include="..\..\gpu\src\GrGLVertexBuffer.cpp" />
<ClCompile Include="..\..\gpu\src\GrGpu.cpp" />
<ClCompile Include="..\..\gpu\src\GrGpuFactory.cpp" />

Просмотреть файл

@ -91,6 +91,7 @@
00115EA912C116CA008296FE /* GrUserConfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6D12C116CA008296FE /* GrUserConfig.h */; };
00115EAA12C116CA008296FE /* GrVertexBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6E12C116CA008296FE /* GrVertexBuffer.h */; };
00115EAB12C116CA008296FE /* GrVertexBufferAllocPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 00115E6F12C116CA008296FE /* GrVertexBufferAllocPool.h */; };
D58CAF9A12E7212100CB9277 /* GrGLUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D58CAF9812E7212100CB9277 /* GrGLUtil.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -179,6 +180,7 @@
00115E6E12C116CA008296FE /* GrVertexBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrVertexBuffer.h; path = ../../gpu/include/GrVertexBuffer.h; sourceTree = SOURCE_ROOT; };
00115E6F12C116CA008296FE /* GrVertexBufferAllocPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GrVertexBufferAllocPool.h; path = ../../gpu/include/GrVertexBufferAllocPool.h; sourceTree = SOURCE_ROOT; };
D2AAC046055464E500DB518D /* libgpu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libgpu.a; sourceTree = BUILT_PRODUCTS_DIR; };
D58CAF9812E7212100CB9277 /* GrGLUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GrGLUtil.cpp; path = ../../gpu/src/GrGLUtil.cpp; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -297,6 +299,7 @@
00115DF812C1167A008296FE /* GrTextStrike.cpp */,
00115DF912C1167A008296FE /* GrTextureCache.cpp */,
00115DFB12C1167A008296FE /* GrVertexBufferAllocPool.cpp */,
D58CAF9812E7212100CB9277 /* GrGLUtil.cpp */,
);
name = Source;
sourceTree = "<group>";
@ -459,6 +462,7 @@
00115E2812C1167A008296FE /* GrTextStrike.cpp in Sources */,
00115E2912C1167A008296FE /* GrTextureCache.cpp in Sources */,
00115E2B12C1167A008296FE /* GrVertexBufferAllocPool.cpp in Sources */,
D58CAF9A12E7212100CB9277 /* GrGLUtil.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};