Use macro to call gl.

git-svn-id: http://skia.googlecode.com/svn/trunk@696 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-01-13 21:28:12 +00:00
parent d728f6ecfa
commit 316f9923cb
3 changed files with 70 additions and 70 deletions

View File

@ -29,9 +29,9 @@
static const GLuint GR_MAX_GLUINT = ~0;
static const GLint GR_INVAL_GLINT = ~0;
// we use a spare texture unit to avoid
// 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 const int SPARE_TEX_UNIT = GrGpuGL::kNumStages;
#define SKIP_CACHE_CHECK true
@ -105,9 +105,9 @@ bool fbo_test(GrGLExts exts, int w, int h) {
GLint savedTexUnit;
GR_GL(GetIntegerv(GL_ACTIVE_TEXTURE, &savedTexUnit));
GR_GL(GetIntegerv(GR_FRAMEBUFFER_BINDING, &savedFBO));
GR_GL(ActiveTexture(GL_TEXTURE0 + SPARE_TEX_UNIT));
GLuint testFBO;
GR_GLEXT(exts, GenFramebuffers(1, &testFBO));
GR_GLEXT(exts, BindFramebuffer(GR_FRAMEBUFFER, testFBO));
@ -125,10 +125,10 @@ bool fbo_test(GrGLExts exts, int w, int h) {
GLenum status = GR_GLEXT(exts, CheckFramebufferStatus(GR_FRAMEBUFFER));
GR_GLEXT(exts, DeleteFramebuffers(1, &testFBO));
GR_GL(DeleteTextures(1, &testRTTex));
GR_GL(ActiveTexture(savedTexUnit));
GR_GLEXT(exts, BindFramebuffer(GR_FRAMEBUFFER, savedFBO));
return status == GR_FRAMEBUFFER_COMPLETE;
}
@ -171,7 +171,7 @@ GrGpuGL::GrGpuGL() {
this);
fHWDrawState.fRenderTarget = fDefaultRenderTarget;
fRenderTargetChanged = true;
GLint maxTextureUnits;
// check FS and fixed-function texture unit limits
// we only use textures in the fragment stage currently.
@ -184,7 +184,7 @@ GrGpuGL::GrGpuGL() {
GR_GL(GetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextureUnits));
GrAssert(maxTextureUnits > kNumStages);
#endif
fCurrDrawState = fHWDrawState;
////////////////////////////////////////////////////////////////////////////
@ -481,17 +481,17 @@ void GrGpuGL::resetContextHelper() {
fHWDrawState.fDstBlend = (BlendCoeff)-1;
fHWDrawState.fColor = GrColor_ILLEGAL;
fHWDrawState.fPointSize = -1;
fHWDrawState.fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax); // illegal
for (int s = 0; s < kNumStages; ++s) {
fHWDrawState.fTextures[s] = NULL;
fHWDrawState.fSamplerStates[s].setRadial2Params(-GR_ScalarMax,
-GR_ScalarMax,
true);
fHWDrawState.fTextureMatrices[s].setScale(GR_ScalarMax, GR_ScalarMax);
fHWDrawState.fTextureMatrices[s].setScale(GR_ScalarMax, GR_ScalarMax);
}
GR_GL(Scissor(0,0,0,0));
fHWBounds.fScissorRect.setLTRB(0,0,0,0);
fHWBounds.fScissorEnabled = false;
@ -576,7 +576,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
#endif
setSpareTextureUnit();
static const GrGLTexture::TexParams DEFAULT_PARAMS = {
GL_NEAREST,
GL_CLAMP_TO_EDGE,
@ -805,7 +805,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
}
// someone suggested that some systems might require
// unbinding the texture before we call FramebufferTexture2D
// unbinding the texture before we call FramebufferTexture2D
// (seems unlikely)
GR_GL(BindTexture(GL_TEXTURE_2D, 0));
@ -890,7 +890,7 @@ GrTexture* GrGpuGL::createTexture(const TextureDesc& desc,
// bind the stencil to rt fbo if present, othewise the tex fbo
GR_GLEXT(fExts, FramebufferRenderbuffer(GR_FRAMEBUFFER,
GR_STENCIL_ATTACHMENT,
GR_RENDERBUFFER,
GR_RENDERBUFFER,
rtIDs.fStencilRenderbufferID));
}
status = GR_GLEXT(fExts, CheckFramebufferStatus(GR_FRAMEBUFFER));
@ -1121,8 +1121,8 @@ bool GrGpuGL::readPixels(int left, int top, int width, int height,
const GrIRect& vp = ((GrGLRenderTarget*)fCurrDrawState.fRenderTarget)->viewport();
// Brian says that viewport rects are already upside down (grrrrr)
glReadPixels(left, -vp.height() - top - height, width, height,
format, type, buffer);
GR_GL(ReadPixels(left, -vp.height() - top - height, width, height,
format, type, buffer));
// now reverse the order of the rows, since GL's are bottom-to-top, but our
// API presents top-to-bottom
@ -1316,8 +1316,8 @@ void GrGpuGL::flushStencil() {
if (!fCurrDrawState.fReverseFill) {
funcRef |= pathStencilMask;
}
glStencilFunc(GL_EQUAL, funcRef, funcMask);
glStencilMask(pathStencilMask);
GR_GL(StencilFunc(GL_EQUAL, funcRef, funcMask));
GR_GL(StencilMask(pathStencilMask));
GR_GL(StencilOp(GL_ZERO, GL_ZERO, GL_ZERO));
GR_GL(ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
if (!fSingleStencilPassForWinding) {
@ -1462,8 +1462,8 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) {
GrGLTexture* nextTexture = (GrGLTexture*)fCurrDrawState.fTextures[s];
if (NULL != nextTexture) {
// if we created a rt/tex and rendered to it without using a
// texture and now we're texuring from the rt it will still be
// if we created a rt/tex and rendered to it without using a
// texture and now we're texuring from the rt it will still be
// the last bound texture, but it needs resolving. So keep this
// out of the "last != next" check.
resolveTextureRenderTarget(nextTexture);
@ -1477,38 +1477,38 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) {
//GrPrintf("---- bindtexture %d\n", nextTexture->textureID());
fHWDrawState.fTextures[s] = nextTexture;
}
const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s];
const GrGLTexture::TexParams& oldTexParams =
const GrGLTexture::TexParams& oldTexParams =
nextTexture->getTexParams();
GrGLTexture::TexParams newTexParams;
newTexParams.fFilter = sampler.isFilter() ? GL_LINEAR :
newTexParams.fFilter = sampler.isFilter() ? GL_LINEAR :
GL_NEAREST;
newTexParams.fWrapS =
newTexParams.fWrapS =
GrGLTexture::gWrapMode2GLWrap[sampler.getWrapX()];
newTexParams.fWrapT =
newTexParams.fWrapT =
GrGLTexture::gWrapMode2GLWrap[sampler.getWrapY()];
if (newTexParams.fFilter != oldTexParams.fFilter) {
setTextureUnit(s);
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER,
newTexParams.fFilter));
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,
newTexParams.fFilter));
}
if (newTexParams.fWrapS != oldTexParams.fWrapS) {
setTextureUnit(s);
GR_GL(TexParameteri(GL_TEXTURE_2D,
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S,
newTexParams.fWrapS));
}
if (newTexParams.fWrapT != oldTexParams.fWrapT) {
setTextureUnit(s);
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T,
GR_GL(TexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T,
newTexParams.fWrapT));
}
nextTexture->setTexParams(newTexParams);
@ -1585,18 +1585,18 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) {
fHWDrawState.fDstBlend = fCurrDrawState.fDstBlend;
}
}
#if GR_DEBUG
// check for circular rendering
for (int s = 0; s < kNumStages; ++s) {
GrAssert(!VertexUsesStage(s, fGeometrySrc.fVertexLayout) ||
NULL == fCurrDrawState.fRenderTarget ||
NULL == fCurrDrawState.fTextures[s] ||
fCurrDrawState.fTextures[s]->asRenderTarget() !=
fCurrDrawState.fTextures[s]->asRenderTarget() !=
fCurrDrawState.fRenderTarget);
}
#endif
flushStencil();
fHWDrawState.fFlagBits = fCurrDrawState.fFlagBits;
@ -1715,7 +1715,7 @@ void GrGpuGL::setTextureUnit(int unit) {
fActiveTextureUnitIdx = unit;
}
}
void GrGpuGL::setSpareTextureUnit() {
if (fActiveTextureUnitIdx != (GL_TEXTURE0 + SPARE_TEX_UNIT)) {
GR_GL(ActiveTexture(GL_TEXTURE0 + SPARE_TEX_UNIT));

View File

@ -514,7 +514,7 @@ GrGpuGLShaders::GrGpuGLShaders() {
fPrograms[p].fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax);
for (int s = 0; s < kNumStages; ++s) {
fPrograms[p].fTextureMatrices[s].setScale(GR_ScalarMax,
fPrograms[p].fTextureMatrices[s].setScale(GR_ScalarMax,
GR_ScalarMax); // illegal
};
fPrograms[p].fColor = GrColor_ILLEGAL;
@ -576,9 +576,9 @@ void GrGpuGLShaders::flushMatrix(GLint location) {
m[GrMatrix::kPersp2]
};
#if ATTRIBUTE_MATRIX
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+0, mt+0);
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+1, mt+3);
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+2, mt+6);
GR_GL(VertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+0, mt+0));
GR_GL(VertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+1, mt+3));
GR_GL(VertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+2, mt+6));
#else
GR_GL(UniformMatrix3fv(location,1,false,mt));
#endif
@ -615,9 +615,9 @@ void GrGpuGLShaders::flushTexMatrix(GLint location,
(*m)[GrMatrix::kPersp2]
};
#if ATTRIBUTE_MATRIX
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+0, mt+0);
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+1, mt+3);
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+2, mt+6);
GR_GL(VertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+0, mt+0));
GR_GL(VertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+1, mt+3));
GR_GL(VertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+2, mt+6));
#else
GR_GL(UniformMatrix3fv(location,1,false,mt));
#endif
@ -646,7 +646,7 @@ void GrGpuGLShaders::flushProgram(PrimitiveType type) {
Programs nextProgram = kNoTexture_Program;
GrTexture* texture = fCurrDrawState.fTextures[0];
bool posAsTex =
bool posAsTex =
StagePosAsTexCoordVertexLayoutBit(0) & fGeometrySrc.fVertexLayout;
if (!VertexUsesStage(0, fGeometrySrc.fVertexLayout)) {
@ -685,17 +685,17 @@ void GrGpuGLShaders::flushProgram(PrimitiveType type) {
break;
case GrSamplerState::kNormal_SampleMode:
if (GrTexture::kAlpha_8_PixelConfig == texture->config()) {
GrAssert(((GrGLTexture*)texture)->orientation() ==
GrAssert(((GrGLTexture*)texture)->orientation() ==
GrGLTexture::kTopDown_Orientation);
GrAssert(!posAsTex);
nextProgram = kText_Program;
} else {
bool persp = fCurrDrawState.fTextureMatrices[0].hasPerspective();
if (posAsTex) {
nextProgram = persp ? kTextureVertCoordsProj_Program :
nextProgram = persp ? kTextureVertCoordsProj_Program :
kTextureVertCoords_Program;
} else {
nextProgram = persp ? kTextureTexCoordsProj_Program :
nextProgram = persp ? kTextureTexCoordsProj_Program :
kTextureTexCoords_Program;
}
// check for case when frag shader can skip the color modulation
@ -735,7 +735,7 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
for (int s = 1; s < kNumStages; ++s) {
if (VertexUsesStage(s, fGeometrySrc.fVertexLayout)) {
unimpl("the hard-coded shaders used by this "
unimpl("the hard-coded shaders used by this "
"class only support 1 stage");
return false;
}
@ -752,7 +752,7 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
// we assume all shader matrices may be wrong after viewport changes
for (int p = 0; p < kProgramCount; ++p) {
// set to illegal matrix
fPrograms[p].fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax);
fPrograms[p].fViewMatrix.setScale(GR_ScalarMax, GR_ScalarMax);
}
#endif
fRenderTargetChanged = false;
@ -798,7 +798,7 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
GrGLTexture::Orientation& orientation = fTextureOrientation;
#else
GrMatrix& currentViewMatrix = fPrograms[fHWProgram].fViewMatrix;
GrMatrix& currentTexMatrix = fPrograms[fHWProgram].fTextureMatrices[0];
GrMatrix& currentTexMatrix = fPrograms[fHWProgram].fTextureMatrices[0];
GrGLTexture::Orientation& orientation =
fPrograms[fHWProgram].fTextureOrientation;
#endif
@ -846,12 +846,12 @@ void GrGpuGLShaders::setupGeometry(uint32_t startVertex,
int newTexCoordOffsets[kNumStages];
GLsizei newStride = VertexSizeAndOffsetsByStage(fGeometrySrc.fVertexLayout,
newTexCoordOffsets,
newTexCoordOffsets,
&newColorOffset);
int oldColorOffset;
int oldTexCoordOffsets[kNumStages];
GLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout,
oldTexCoordOffsets,
oldTexCoordOffsets,
&oldColorOffset);
const GLvoid* posPtr = (GLvoid*)(newStride * startVertex);

View File

@ -98,12 +98,12 @@ struct GrGpuGLShaders2::StageDesc {
unsigned fOptFlags : 8;
unsigned fEnabled : 8;
enum Modulation {
kColor_Modulation,
kAlpha_Modulation,
} fModulation : 8;
enum CoordMapping {
kIdentity_CoordMapping,
kRadialGradient_CoordMapping,
@ -379,7 +379,7 @@ void GrGpuGLShaders2::ProgramUnitTest() {
// So using nextU() % array_count might never take some values.
GrRandom random;
for (int t = 0; t < NUM_TESTS; ++t) {
pdesc.fVertexLayout = 0;
for (int s = 0; s < kNumStages; ++s) {
// enable the stage?
@ -737,7 +737,7 @@ void GrGpuGLShaders2::GenProgram(const ProgramDesc& desc,
++numActiveStages;
}
}
GrTokenString inColor = "vColor";
// if we have active stages string them together, feeding the output color
@ -863,8 +863,8 @@ void GrGpuGLShaders2::GenProgram(const ProgramDesc& desc,
GR_GL(BindAttribLocation(progID, POS_ATTR_LOCATION, POS_ATTR_NAME));
for (int t = 0; t < kMaxTexCoords; ++t) {
if (texCoordAttrs[t].length()) {
GR_GL(BindAttribLocation(progID,
TEX_ATTR_LOCATION(t),
GR_GL(BindAttribLocation(progID,
TEX_ATTR_LOCATION(t),
texCoordAttrs[t].cstr()));
}
}
@ -982,7 +982,7 @@ void GrGpuGLShaders2::getProgramDesc(PrimitiveType primType, ProgramDesc* desc)
desc->fVertexLayout = fGeometrySrc.fVertexLayout;
for (int s = 0; s < kNumStages; ++s) {
StageDesc& stage = desc->fStages[s];
stage.fEnabled = VertexUsesStage(s, fGeometrySrc.fVertexLayout);
if (primType != kPoints_PrimitiveType) {
@ -1141,9 +1141,9 @@ void GrGpuGLShaders2::flushViewMatrix() {
m[GrMatrix::kPersp2]
};
#if ATTRIBUTE_MATRIX
glVertexAttrib4fv(VIEWMAT_ATTR_LOCATION+0, mt+0);
glVertexAttrib4fv(VIEWMAT_ATTR_LOCATION+1, mt+3);
glVertexAttrib4fv(VIEWMAT_ATTR_LOCATION+2, mt+6);
GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+0, mt+0));
GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+1, mt+3));
GR_GL(VertexAttrib4fv(VIEWMAT_ATTR_LOCATION+2, mt+6));
#else
GR_GL(UniformMatrix3fv(fProgram->fUniLocations.fViewMatrixUni,1,false,mt));
#endif
@ -1184,9 +1184,9 @@ void GrGpuGLShaders2::flushTextureMatrix(int stage) {
(*m)[GrMatrix::kPersp2]
};
#if ATTRIBUTE_MATRIX
glVertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+0, mt+0);
glVertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+1, mt+3);
glVertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+2, mt+6);
GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+0, mt+0));
GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+1, mt+3));
GR_GL(VertexAttrib4fv(TEXMAT_ATTR_LOCATION(0)+2, mt+6));
#else
GR_GL(UniformMatrix3fv(fProgram->fUniLocations.fStages[stage].fTextureMatrixUni,
1,
@ -1212,8 +1212,8 @@ void GrGpuGLShaders2::flushRadial2(int stage) {
GrScalarToFloat(GrMul(radius0, radius0)),
sampler.isRadial2PosRoot() ? 1.f : -1.f
};
GR_GL(Uniform1fv(fProgram->fUniLocations.fStages[stage].fRadial2Uni,
6,
GR_GL(Uniform1fv(fProgram->fUniLocations.fStages[stage].fRadial2Uni,
6,
unis));
}
@ -1281,7 +1281,7 @@ bool GrGpuGLShaders2::flushGraphicsState(PrimitiveType type) {
currViewMatrix = fCurrDrawState.fViewMatrix;
}
for (int s = 0; s < kNumStages; ++s) {
for (int s = 0; s < kNumStages; ++s) {
GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
if (NULL != texture) {
if (-1 != fProgram->fUniLocations.fStages[s].fTextureMatrixUni &&