Remove GrGpuGLFixed subclass and ES1 support

Review URL: http://codereview.appspot.com/5376094/


git-svn-id: http://skia.googlecode.com/svn/trunk@2678 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-11-14 19:29:53 +00:00
parent ffdb018dae
commit 1dcf506a1a
18 changed files with 81 additions and 674 deletions

View File

@ -222,8 +222,6 @@
'../src/gpu/GrGpuFactory.cpp',
'../src/gpu/GrGpuGL.cpp',
'../src/gpu/GrGpuGL.h',
'../src/gpu/GrGpuGLFixed.cpp',
'../src/gpu/GrGpuGLFixed.h',
'../src/gpu/GrGpuGLShaders.cpp',
'../src/gpu/GrGpuGLShaders.h',
'../src/gpu/GrGpuVertex.h',

View File

@ -39,11 +39,6 @@ public:
static GrContext* Create(GrEngine engine,
GrPlatform3DContext context3D);
/**
* Helper to create a opengl-shader based context
*/
static GrContext* CreateGLShaderContext();
virtual ~GrContext();
/**

View File

@ -125,18 +125,6 @@
////////////////////////////////////////////////////////////////////////////////
/**
* The following macros are used to staticlly configure the default
* GrGLInterface, but should not be used outside of the GrGLInterface
* scaffolding. Undefine here to prevent accidental use.
*/
#undef GR_SUPPORT_GLDESKTOP
#undef GR_SUPPORT_GLES1
#undef GR_SUPPORT_GLES2
#undef GR_SUPPORT_GLES
////////////////////////////////////////////////////////////////////////////////
#if GR_SCALAR_IS_FIXED
#define GrGLType GL_FIXED
#elif GR_SCALAR_IS_FLOAT

View File

@ -111,8 +111,7 @@ typedef long GrGLsizeiptr;
enum GrGLBinding {
kDesktop_GrGLBinding = 0x01,
kES1_GrGLBinding = 0x02,
kES2_GrGLBinding = 0x04
kES2_GrGLBinding = 0x02
};
extern "C" {
@ -278,20 +277,13 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLInterface();
bool validate(GrEngine engine) const;
bool validate() 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.
@ -451,9 +443,6 @@ struct GR_API GrGLInterface : public GrRefCnt {
GrGLInterfaceCallbackData fCallbackData;
#endif
private:
bool validateShaderFunctions() const;
bool validateFixedFunctions() const;
};
#endif

View File

@ -55,10 +55,6 @@ GrContext* GrContext::Create(GrEngine engine,
return ctx;
}
GrContext* GrContext::CreateGLShaderContext() {
return GrContext::Create(kOpenGL_Shaders_GrEngine, 0);
}
GrContext::~GrContext() {
this->flush();
delete fTextureCache;

View File

@ -241,25 +241,68 @@ GrGLInterface::GrGLInterface() {
#endif
}
bool GrGLInterface::validate() const {
bool GrGLInterface::validateShaderFunctions() const {
// required for GrGpuGLShaders
if (NULL == fAttachShader ||
bool isDesktop = this->supportsDesktop();
bool isES2 = this->supportsES2();
if (isDesktop == isES2) {
// must have one, don't support both in same interface
return false;
}
// functions that are always required
if (NULL == fActiveTexture ||
NULL == fAttachShader ||
NULL == fBindAttribLocation ||
NULL == fBindBuffer ||
NULL == fBindTexture ||
NULL == fBlendFunc ||
NULL == fBufferData ||
NULL == fBufferSubData ||
NULL == fClear ||
NULL == fClearColor ||
NULL == fClearStencil ||
NULL == fColorMask ||
NULL == fCompileShader ||
NULL == fCreateProgram ||
NULL == fCreateShader ||
NULL == fCullFace ||
NULL == fDeleteBuffers ||
NULL == fDeleteProgram ||
NULL == fDeleteShader ||
NULL == fDeleteTextures ||
NULL == fDepthMask ||
NULL == fDisable ||
NULL == fDisableVertexAttribArray ||
NULL == fDrawArrays ||
NULL == fDrawElements ||
NULL == fEnable ||
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 == fGetUniformLocation ||
NULL == fLinkProgram ||
NULL == fPixelStorei ||
NULL == fReadPixels ||
NULL == fScissor ||
NULL == fShaderSource ||
NULL == fStencilFunc ||
NULL == fStencilMask ||
NULL == fStencilOp ||
NULL == fTexImage2D ||
NULL == fTexParameteri ||
NULL == fTexSubImage2D ||
NULL == fUniform1f ||
NULL == fUniform1i ||
NULL == fUniform1fv ||
@ -281,76 +324,7 @@ bool GrGLInterface::validateShaderFunctions() const {
NULL == fUniformMatrix4fv ||
NULL == fUseProgram ||
NULL == fVertexAttrib4fv ||
NULL == fVertexAttribPointer) {
return false;
}
return true;
}
bool GrGLInterface::validateFixedFunctions() const {
if (NULL == fClientActiveTexture ||
NULL == fColor4ub ||
NULL == fColorPointer ||
NULL == fDisableClientState ||
NULL == fEnableClientState ||
NULL == fLoadMatrixf ||
NULL == fMatrixMode ||
NULL == fPointSize ||
NULL == fShadeModel ||
NULL == fTexCoordPointer ||
NULL == fTexEnvi ||
NULL == fVertexPointer) {
return false;
}
return true;
}
bool GrGLInterface::validate(GrEngine engine) const {
bool isDesktop = this->supportsDesktop();
bool isES = this->supportsES();
if (isDesktop == isES) {
// must have one, don't support both in same interface
return false;
}
// functions that are always required
if (NULL == fActiveTexture ||
NULL == fBindBuffer ||
NULL == fBindTexture ||
NULL == fBlendFunc ||
NULL == fBufferData ||
NULL == fBufferSubData ||
NULL == fClear ||
NULL == fClearColor ||
NULL == fClearStencil ||
NULL == fColorMask ||
NULL == fCullFace ||
NULL == fDeleteBuffers ||
NULL == fDeleteTextures ||
NULL == fDepthMask ||
NULL == fDisable ||
NULL == fDrawArrays ||
NULL == fDrawElements ||
NULL == fEnable ||
NULL == fFrontFace ||
NULL == fGenBuffers ||
NULL == fGenTextures ||
NULL == fGetBufferParameteriv ||
NULL == fGetError ||
NULL == fGetIntegerv ||
NULL == fGetString ||
NULL == fPixelStorei ||
NULL == fReadPixels ||
NULL == fScissor ||
NULL == fStencilFunc ||
NULL == fStencilMask ||
NULL == fStencilOp ||
NULL == fTexImage2D ||
NULL == fTexParameteri ||
NULL == fTexSubImage2D ||
NULL == fVertexAttribPointer ||
NULL == fViewport ||
NULL == fBindFramebuffer ||
NULL == fBindRenderbuffer ||
@ -369,27 +343,6 @@ bool GrGLInterface::validate(GrEngine engine) const {
return false;
}
switch (engine) {
case kOpenGL_Shaders_GrEngine:
if (kES1_GrGLBinding == fBindingsExported) {
return false;
}
if (!this->validateShaderFunctions()) {
return false;
}
break;
case kOpenGL_Fixed_GrEngine:
if (kES1_GrGLBinding == fBindingsExported) {
return false;
}
if (!this->validateFixedFunctions()) {
return false;
}
break;
default:
return false;
}
const char* ext;
GrGLVersion glVer = GrGLGetVersion(this);
ext = (const char*)fGetString(GR_GL_EXTENSIONS);

View File

@ -24,7 +24,7 @@ enum {
const char* GrPrecision(const GrGLInterface* gl) {
if (gl->supportsES()) {
if (gl->supportsES2()) {
return "mediump";
} else {
return " ";
@ -32,7 +32,7 @@ const char* GrPrecision(const GrGLInterface* gl) {
}
const char* GrShaderPrecision(const GrGLInterface* gl) {
if (gl->supportsES()) {
if (gl->supportsES2()) {
return "precision mediump float;\n";
} else {
return "";
@ -372,7 +372,7 @@ const char* glsl_version_string(const GrGLInterface* gl,
GrGLProgram::GLSLVersion v) {
switch (v) {
case GrGLProgram::k110_GLSLVersion:
if (gl->supportsES()) {
if (gl->supportsES2()) {
// ES2s shader language is based on version 1.20 but is version
// 1.00 of the ES language.
return "#version 100\n";
@ -514,7 +514,7 @@ void GrGLProgram::genEdgeCoverage(const GrGLInterface* gl,
segments->fFSCode.appendf("\tfloat dfdy = 2.0*%s.x*duvdy.x - duvdy.y;\n", fsName);
segments->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName);
segments->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / (dfdx*dfdx + dfdy*dfdy));\n");
if (gl->supportsES()) {
if (gl->supportsES2()) {
segments->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
}
}

View File

@ -15,24 +15,13 @@
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
const GrGLenum* GrGLTexture::WrapMode2GLWrap(GrGLBinding binding) {
static const GrGLenum mirrorRepeatModes[] = {
const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
static const GrGLenum repeatModes[] = {
GR_GL_CLAMP_TO_EDGE,
GR_GL_REPEAT,
GR_GL_MIRRORED_REPEAT
};
static const GrGLenum repeatModes[] = {
GR_GL_CLAMP_TO_EDGE,
GR_GL_REPEAT,
GR_GL_REPEAT
};
if (kES1_GrGLBinding == binding) {
return repeatModes; // GL_MIRRORED_REPEAT not supported.
} else {
return mirrorRepeatModes;
}
return repeatModes;
};
void GrGLTexture::init(GrGpuGL* gpu,

View File

@ -128,7 +128,7 @@ public:
// and it is up to the GrGpuGL derivative to handle y-mirroing.
Orientation orientation() const { return fOrientation; }
static const GrGLenum* WrapMode2GLWrap(GrGLBinding binding);
static const GrGLenum* WrapMode2GLWrap();
protected:

View File

@ -31,7 +31,7 @@ struct GrGpuStats {
uint32_t fIndexCnt; //<! Number of indices drawn
uint32_t fDrawCnt; //<! Number of draws
uint32_t fProgChngCnt;//<! Number of program changes (N/A for fixed)
uint32_t fProgChngCnt;//<! Number of program changes
/**
* Number of times the texture is set in 3D API

View File

@ -17,7 +17,6 @@
#include "GrGLConfig.h"
#include "GrGpu.h"
#include "GrGpuGLFixed.h"
#include "GrGpuGLShaders.h"
GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
@ -25,8 +24,7 @@ GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
const GrGLInterface* glInterface = NULL;
SkAutoTUnref<const GrGLInterface> glInterfaceUnref;
if (kOpenGL_Shaders_GrEngine == engine ||
kOpenGL_Fixed_GrEngine == engine) {
if (kOpenGL_Shaders_GrEngine == engine) {
glInterface = reinterpret_cast<const GrGLInterface*>(context3D);
if (NULL == glInterface) {
glInterface = GrGLDefaultInterface();
@ -41,29 +39,15 @@ GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
#endif
return NULL;
}
if (!glInterface->validate(engine)) {
if (!glInterface->validate()) {
#if GR_DEBUG
GrPrintf("Failed GL interface validation!\n");
#endif
return NULL;
}
return new GrGpuGLShaders(glInterface);
} else {
return NULL;
}
GrGpu* gpu = NULL;
switch (engine) {
case kOpenGL_Shaders_GrEngine:
GrAssert(NULL != glInterface);
gpu = new GrGpuGLShaders(glInterface);
break;
case kOpenGL_Fixed_GrEngine:
GrAssert(NULL != glInterface);
gpu = new GrGpuGLFixed(glInterface);
break;
default:
GrAssert(!"unknown engine");
break;
}
return gpu;
}

View File

@ -268,9 +268,6 @@ GrGpuGL::GrGpuGL(const GrGLInterface* gl, GrGLBinding glBinding) {
case kDesktop_GrGLBinding:
GrAssert(gl->supportsDesktop());
break;
case kES1_GrGLBinding:
GrAssert(gl->supportsES1());
break;
case kES2_GrGLBinding:
GrAssert(gl->supportsES2());
break;
@ -326,10 +323,8 @@ void GrGpuGL::initCaps() {
// 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 (kES1_GrGLBinding != this->glBinding()) {
GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
GrAssert(maxTextureUnits > GrDrawState::kNumStages);
}
GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
GrAssert(maxTextureUnits > GrDrawState::kNumStages);
if (kES2_GrGLBinding != this->glBinding()) {
GR_GL_GetIntegerv(fGL, GR_GL_MAX_TEXTURE_UNITS, &maxTextureUnits);
GrAssert(maxTextureUnits > GrDrawState::kNumStages);
@ -356,14 +351,6 @@ void GrGpuGL::initCaps() {
}
}
if (kDesktop_GrGLBinding == this->glBinding()) {
fCaps.fStencilWrapOpsSupport = (fGLVersion >= GR_GL_VER(1,4)) ||
this->hasExtension("GL_EXT_stencil_wrap");
} else {
fCaps.fStencilWrapOpsSupport = (fGLVersion >= GR_GL_VER(2,0)) ||
this->hasExtension("GL_OES_stencil_wrap");
}
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
@ -373,12 +360,9 @@ void GrGpuGL::initCaps() {
fCaps.fStencilWrapOpsSupport = (fGLVersion >= GR_GL_VER(1,4)) ||
this->hasExtension("GL_EXT_stencil_wrap");
} else {
// ES 2 has two sided stencil but 1.1 doesn't. There doesn't seem to be
// an ES1 extension.
fCaps.fTwoSidedStencilSupport = (fGLVersion >= GR_GL_VER(2,0));
// stencil wrap support is in ES2, ES1 requires extension.
fCaps.fStencilWrapOpsSupport = (fGLVersion >= GR_GL_VER(2,0)) ||
this->hasExtension("GL_OES_stencil_wrap");
// ES 2 has two sided stencil and stencil wrap
fCaps.fTwoSidedStencilSupport = true;
fCaps.fStencilWrapOpsSupport = true;
}
if (kDesktop_GrGLBinding == this->glBinding()) {
@ -438,14 +422,9 @@ void GrGpuGL::initCaps() {
fCaps.fNPOTTextureSupport = false;
}
} else {
if (fGLVersion >= GR_GL_VER(2,0)) {
fCaps.fNPOTTextureSupport = true;
fCaps.fNPOTTextureTileSupport = this->hasExtension("GL_OES_texture_npot");
} else {
fCaps.fNPOTTextureSupport =
this->hasExtension("GL_APPLE_texture_2D_limited_npot");
fCaps.fNPOTTextureTileSupport = false;
}
// Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
fCaps.fNPOTTextureSupport = true;
fCaps.fNPOTTextureTileSupport = this->hasExtension("GL_OES_texture_npot");
}
fCaps.fHWAALineSupport = (kDesktop_GrGLBinding == this->glBinding());
@ -563,17 +542,11 @@ void GrGpuGL::initStencilFormats() {
fGLCaps.fStencilFormats.push_back() = gDS;
}
} else {
// ES2 has STENCIL_INDEX8 without extensions.
// ES1 with GL_OES_framebuffer_object (which we require for ES1)
// introduces tokens for S1 thu S8 but there are separate extensions
// that make them legal (GL_OES_stencil1, ...).
// GL_OES_packed_depth_stencil adds DEPTH24_STENCIL8
// ES doesn't support using the unsized formats.
// ES2 has STENCIL_INDEX8 without extensions but requires extensions
// for other formats.
// ES doesn't support using the unsized format.
if (fGLVersion >= GR_GL_VER(2,0) ||
this->hasExtension("GL_OES_stencil8")) {
fGLCaps.fStencilFormats.push_back() = gS8;
}
fGLCaps.fStencilFormats.push_back() = gS8;
//fStencilFormats.push_back() = gS16;
if (this->hasExtension("GL_OES_packed_depth_stencil")) {
fGLCaps.fStencilFormats.push_back() = gD24S8;
@ -581,8 +554,6 @@ void GrGpuGL::initStencilFormats() {
if (this->hasExtension("GL_OES_stencil4")) {
fGLCaps.fStencilFormats.push_back() = gS4;
}
// we require some stencil format.
GrAssert(fGLCaps.fStencilFormats.count() > 0);
}
}
@ -2150,8 +2121,7 @@ bool GrGpuGL::flushGLStateCommon(GrPrimitiveType type) {
newTexParams.fFilter = gr_to_gl_filter(sampler.getFilter());
const GrGLenum* wraps =
GrGLTexture::WrapMode2GLWrap(this->glBinding());
const GrGLenum* wraps = GrGLTexture::WrapMode2GLWrap();
newTexParams.fWrapS = wraps[sampler.getWrapX()];
newTexParams.fWrapT = wraps[sampler.getWrapY()];
memcpy(newTexParams.fSwizzleRGBA,
@ -2406,9 +2376,7 @@ bool GrGpuGL::fboInternalFormat(GrPixelConfig config, GrGLenum* format) {
return false;
}
case kRGB_565_GrPixelConfig:
// ES2 supports 565. ES1 supports it
// with FBO extension desktop GL has
// no such internal format
// ES2 supports 565, but desktop GL does not.
if (kDesktop_GrGLBinding != this->glBinding()) {
*format = GR_GL_RGB565;
return true;

View File

@ -1,382 +0,0 @@
/*
* Copyright 2010 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrGLConfig.h"
#include "GrGpuGLFixed.h"
#include "GrGpuVertex.h"
#define SKIP_CACHE_CHECK true
struct GrGpuMatrix {
GrGLfloat fMat[16];
void reset() {
Gr_bzero(fMat, sizeof(fMat));
fMat[0] = fMat[5] = fMat[10] = fMat[15] = GR_Scalar1;
}
void set(const GrMatrix& m) {
Gr_bzero(fMat, sizeof(fMat));
fMat[0] = GrScalarToFloat(m[GrMatrix::kMScaleX]);
fMat[4] = GrScalarToFloat(m[GrMatrix::kMSkewX]);
fMat[12] = GrScalarToFloat(m[GrMatrix::kMTransX]);
fMat[1] = GrScalarToFloat(m[GrMatrix::kMSkewY]);
fMat[5] = GrScalarToFloat(m[GrMatrix::kMScaleY]);
fMat[13] = GrScalarToFloat(m[GrMatrix::kMTransY]);
fMat[3] = GrScalarToFloat(m[GrMatrix::kMPersp0]);
fMat[7] = GrScalarToFloat(m[GrMatrix::kMPersp1]);
fMat[15] = GrScalarToFloat(m[GrMatrix::kMPersp2]);
fMat[10] = 1.f; // z-scale
}
};
// these must match the order in the corresponding enum in GrGpu.h
static const GrGLenum gMatrixMode2Enum[] = {
GR_GL_MODELVIEW, GR_GL_TEXTURE
};
#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
///////////////////////////////////////////////////////////////////////////////
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)) {
}
GrGpuGLFixed::~GrGpuGLFixed() {
}
void GrGpuGLFixed::onResetContext() {
INHERITED::onResetContext();
GL_CALL(Disable(GR_GL_TEXTURE_2D));
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
setTextureUnit(s);
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
// texture, e.g.:
//glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
}
fHWGeometryState.fVertexLayout = 0;
fHWGeometryState.fVertexOffset = ~0;
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));
GL_CALL(PointSize(1.f));
GrGLClearErr(this->glInterface());
fTextVerts = false;
fBaseVertex = 0xffffffff;
}
void GrGpuGLFixed::flushProjectionMatrix() {
float mat[16];
Gr_bzero(mat, sizeof(mat));
GrAssert(NULL != fCurrDrawState.fRenderTarget);
mat[0] = 2.f / fCurrDrawState.fRenderTarget->width();
mat[5] = -2.f / fCurrDrawState.fRenderTarget->height();
mat[10] = -1.f;
mat[15] = 1;
mat[12] = -1.f;
mat[13] = 1.f;
GL_CALL(MatrixMode(GR_GL_PROJECTION));
GL_CALL(LoadMatrixf(mat));
}
bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {
bool usingTextures[GrDrawState::kNumStages];
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
usingTextures[s] = this->isStageEnabled(s);
if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
unimpl("Fixed pipe doesn't support radial/sweep gradients");
return false;
}
}
if (kES1_GrGLBinding == this->glBinding()) {
if (BlendCoeffReferencesConstant(fCurrDrawState.fSrcBlend) ||
BlendCoeffReferencesConstant(fCurrDrawState.fDstBlend)) {
unimpl("ES1 doesn't support blend constant");
return false;
}
}
if (!flushGLStateCommon(type)) {
return false;
}
GrBlendCoeff srcCoeff, dstCoeff;
if (kSkipDraw_BlendOptFlag &
this->getBlendOpts(false, &srcCoeff, &dstCoeff)) {
return false;
}
this->flushBlend(type, srcCoeff, dstCoeff);
if (fDirtyFlags.fRenderTargetChanged) {
flushProjectionMatrix();
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bool wasUsingTexture = StageWillBeUsed(s, fHWGeometryState.fVertexLayout, fHWDrawState);
if (usingTextures[s] != wasUsingTexture) {
setTextureUnit(s);
if (usingTextures[s]) {
GL_CALL(Enable(GR_GL_TEXTURE_2D));
} else {
GL_CALL(Disable(GR_GL_TEXTURE_2D));
}
}
}
uint32_t vertColor = (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit);
uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
kColor_VertexLayoutBit);
if (vertColor != prevVertColor) {
if (vertColor) {
GL_CALL(ShadeModel(GR_GL_SMOOTH));
// invalidate the immediate mode color
fHWDrawState.fColor = GrColor_ILLEGAL;
} else {
GL_CALL(ShadeModel(GR_GL_FLAT));
}
}
if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
GL_CALL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
GrColorUnpackG(fCurrDrawState.fColor),
GrColorUnpackB(fCurrDrawState.fColor),
GrColorUnpackA(fCurrDrawState.fColor)));
fHWDrawState.fColor = fCurrDrawState.fColor;
}
// set texture environment, decide whether we are modulating by RGB or A.
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (usingTextures[s]) {
GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
if (NULL != texture) {
TextureEnvRGBOperands nextRGBOperand0 =
(GrPixelConfigIsAlphaOnly(texture->config())) ?
kAlpha_TextureEnvRGBOperand :
kColor_TextureEnvRGBOperand;
if (fHWRGBOperand0[s] != nextRGBOperand0) {
setTextureUnit(s);
GL_CALL(TexEnvi(GR_GL_TEXTURE_ENV,
GR_GL_OPERAND0_RGB,
(nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
GR_GL_SRC_ALPHA :
GR_GL_SRC_COLOR));
fHWRGBOperand0[s] = nextRGBOperand0;
}
if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
(fHWDrawState.fSamplerStates[s].getMatrix() !=
getSamplerMatrix(s))) {
GrMatrix texMat = getSamplerMatrix(s);
AdjustTextureMatrix(texture,
GrSamplerState::kNormal_SampleMode,
&texMat);
GrGpuMatrix glm;
glm.set(texMat);
setTextureUnit(s);
GL_CALL(MatrixMode(GR_GL_TEXTURE));
GL_CALL(LoadMatrixf(glm.fMat));
recordHWSamplerMatrix(s, getSamplerMatrix(s));
}
} else {
GrAssert(!"Rendering with texture vert flag set but no bound texture");
return false;
}
}
}
if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
GrGpuMatrix glm;
glm.set(fCurrDrawState.fViewMatrix);
GL_CALL(MatrixMode(GR_GL_MODELVIEW));
GL_CALL(LoadMatrixf(glm.fMat));
fHWDrawState.fViewMatrix =
fCurrDrawState.fViewMatrix;
}
resetDirtyFlags();
return true;
}
void GrGpuGLFixed::setupGeometry(int* startVertex,
int* startIndex,
int vertexCount,
int indexCount) {
int newColorOffset;
int newCoverageOffset;
int newTexCoordOffsets[GrDrawState::kNumStages];
int newEdgeOffset;
GrGLsizei newStride = VertexSizeAndOffsetsByStage(this->getGeomSrc().fVertexLayout,
newTexCoordOffsets,
&newColorOffset,
&newCoverageOffset,
&newEdgeOffset);
GrAssert(-1 == newEdgeOffset); // not supported by fixed pipe
GrAssert(-1 == newCoverageOffset); // not supported by fixed pipe
int oldColorOffset;
int oldCoverageOffset;
int oldTexCoordOffsets[GrDrawState::kNumStages];
int oldEdgeOffset;
GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
oldTexCoordOffsets,
&oldColorOffset,
&oldCoverageOffset,
&oldEdgeOffset);
GrAssert(-1 == oldEdgeOffset);
GrAssert(-1 == oldCoverageOffset);
bool indexed = NULL != startIndex;
int extraVertexOffset;
int extraIndexOffset;
setBuffers(indexed, &extraVertexOffset, &extraIndexOffset);
GrGLenum scalarType;
if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) {
scalarType = GrGLTextType;
} else {
scalarType = GrGLType;
}
size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride;
*startVertex = 0;
if (indexed) {
*startIndex += extraIndexOffset;
}
// all the Pointers must be set if any of these are true
bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty ||
vertexOffset != fHWGeometryState.fVertexOffset ||
newStride != oldStride;
// position and tex coord offsets change if above conditions are true
// or the type changed based on text vs nontext type coords.
bool posAndTexChange = allOffsetsChange ||
((GrGLTextType != GrGLType) &&
(kTextFormat_VertexLayoutBit &
(fHWGeometryState.fVertexLayout ^
this->getGeomSrc().fVertexLayout)));
if (posAndTexChange) {
GL_CALL(VertexPointer(2, scalarType,
newStride, (GrGLvoid*)vertexOffset));
fHWGeometryState.fVertexOffset = vertexOffset;
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
// need to enable array if tex coord offset is 0
// (using positions as coords)
if (newTexCoordOffsets[s] >= 0) {
GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset +
newTexCoordOffsets[s]);
if (oldTexCoordOffsets[s] < 0) {
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]) {
GL_CALL(ClientActiveTexture(GR_GL_TEXTURE0+s));
GL_CALL(TexCoordPointer(2, scalarType,
newStride, texCoordOffset));
}
} else if (oldTexCoordOffsets[s] >= 0) {
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) {
GL_CALL(EnableClientState(GR_GL_COLOR_ARRAY));
GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
newStride, colorOffset));
} else if (allOffsetsChange || newColorOffset != oldColorOffset) {
GL_CALL(ColorPointer(4, GR_GL_UNSIGNED_BYTE,
newStride, colorOffset));
}
} else if (oldColorOffset > 0) {
GL_CALL(DisableClientState(GR_GL_COLOR_ARRAY));
}
fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout;
fHWGeometryState.fArrayPtrsDirty = false;
}

View File

@ -1,66 +0,0 @@
/*
* Copyright 2010 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrGpuGLFixed_DEFINED
#define GrGpuGLFixed_DEFINED
#include "GrDrawState.h"
#include "GrGpuGL.h"
// Fixed Pipeline OpenGL or OpenGL ES 1.x
class GrGpuGLFixed : public GrGpuGL {
public:
GrGpuGLFixed(const GrGLInterface* glInterface);
virtual ~GrGpuGLFixed();
protected:
// overrides from GrGpu
virtual bool flushGraphicsState(GrPrimitiveType type);
virtual void setupGeometry(int* startVertex,
int* startIndex,
int vertexCount,
int indexCount);
private:
virtual void onResetContext() SK_OVERRIDE;
// Helpers to make code more readable
const GrMatrix& getHWSamplerMatrix(int stage) const {
return fHWDrawState.fSamplerStates[stage].getMatrix();
}
void recordHWSamplerMatrix(int stage, const GrMatrix& matrix) {
fHWDrawState.fSamplerStates[stage].setMatrix(matrix);
}
// when the texture is GL_RGBA we set the GL_COMBINE texture
// environment rgb operand 0 to be GL_COLOR to modulate each incoming
// R,G, & B by the texture's R, G, & B. When the texture is alpha-only we
// set the operand to GL_ALPHA so that the incoming frag's R, G, &B are all
// modulated by the texture's A.
enum TextureEnvRGBOperands {
kAlpha_TextureEnvRGBOperand,
kColor_TextureEnvRGBOperand,
};
TextureEnvRGBOperands fHWRGBOperand0[GrDrawState::kNumStages];
void flushProjectionMatrix();
// are the currently bound vertex buffers/arrays laid
// out for text or other drawing.
bool fTextVerts;
// On GL we have to build the base vertex offset into the
// glVertexPointer/glTexCoordPointer/etc
int fBaseVertex;
typedef GrGpuGL INHERITED;
};
#endif

View File

@ -162,8 +162,7 @@ GrGLProgram::GLSLVersion get_glsl_version(GrGLBinding binding,
GrAssert(ver >= GR_GL_VER(1,00));
return GrGLProgram::k110_GLSLVersion;
default:
GrCrash("Attempting to get GLSL version in unknown or fixed-"
"function GL binding.");
GrCrash("Unknown GL Binding");
return GrGLProgram::k110_GLSLVersion; // suppress warning
}
}

View File

@ -22,7 +22,6 @@
static GrContext* make_context() {
SkDebugf("---- before create\n");
GrContext* ctx = GrContext::Create(GrGpu::kOpenGL_Shaders_Engine, 0);
// GrContext* ctx = GrContext::Create(GrGpu::kOpenGL_Fixed_Engine, 0);
SkDebugf("---- after create %p\n", ctx);
return ctx;
}

View File

@ -9,9 +9,6 @@
#include "GrGLInterface.h"
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
@ -145,7 +142,7 @@ const GrGLInterface* GrGLDefaultInterface() {
#endif
interface->fBindFragDataLocationIndexed = NULL;
interface->fBindingsExported = (GrGLBinding)(kES2_GrGLBinding | kES1_GrGLBinding);
interface->fBindingsExported = kES2_GrGLBinding;
}
glInterface.get()->ref();
return glInterface.get();

View File

@ -51,7 +51,7 @@ static void GLInterfaceValidationTest(skiatest::Reporter* reporter) {
iface.reset(interfaceFactories[i].fFactory());
REPORTER_ASSERT(reporter, NULL != iface.get());
if (iface.get()) {
REPORTER_ASSERT(reporter, iface.get()->validate(kOpenGL_Shaders_GrEngine));
REPORTER_ASSERT(reporter, iface.get()->validate());
}
}
}