add helpers to initialize our var-int args before calling GL. Some drivers
assert that those are zero on input, even though they are logically output-only parameters. git-svn-id: http://skia.googlecode.com/svn/trunk@688 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
0e4a885376
commit
ac20fb9955
@ -137,12 +137,12 @@ GrGpuGL::GrGpuGL() {
|
|||||||
resetContextHelper();
|
resetContextHelper();
|
||||||
|
|
||||||
GrGLRenderTarget::GLRenderTargetIDs defaultRTIDs;
|
GrGLRenderTarget::GLRenderTargetIDs defaultRTIDs;
|
||||||
GR_GL(GetIntegerv(GR_FRAMEBUFFER_BINDING, (GLint*)&defaultRTIDs.fRTFBOID));
|
GR_GL_GetIntegerv(GR_FRAMEBUFFER_BINDING, (GLint*)&defaultRTIDs.fRTFBOID);
|
||||||
defaultRTIDs.fTexFBOID = defaultRTIDs.fRTFBOID;
|
defaultRTIDs.fTexFBOID = defaultRTIDs.fRTFBOID;
|
||||||
defaultRTIDs.fMSColorRenderbufferID = 0;
|
defaultRTIDs.fMSColorRenderbufferID = 0;
|
||||||
defaultRTIDs.fStencilRenderbufferID = 0;
|
defaultRTIDs.fStencilRenderbufferID = 0;
|
||||||
GLint vp[4];
|
GLint vp[4];
|
||||||
GR_GL(GetIntegerv(GL_VIEWPORT, vp));
|
GR_GL_GetIntegerv(GL_VIEWPORT, vp);
|
||||||
fHWBounds.fViewportRect.setLTRB(vp[0],
|
fHWBounds.fViewportRect.setLTRB(vp[0],
|
||||||
vp[1] + vp[3],
|
vp[1] + vp[3],
|
||||||
vp[0] + vp[2],
|
vp[0] + vp[2],
|
||||||
@ -165,9 +165,9 @@ GrGpuGL::GrGpuGL() {
|
|||||||
gl_version(&major, &minor);
|
gl_version(&major, &minor);
|
||||||
|
|
||||||
GLint numFormats;
|
GLint numFormats;
|
||||||
GR_GL(GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats));
|
GR_GL_GetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
|
||||||
GrAutoSTMalloc<10, GLint> formats(numFormats);
|
GrAutoSTMalloc<10, GLint> formats(numFormats);
|
||||||
GR_GL(GetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats));
|
GR_GL_GetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
|
||||||
for (int i = 0; i < numFormats; ++i) {
|
for (int i = 0; i < numFormats; ++i) {
|
||||||
if (formats[i] == GR_PALETTE8_RGBA8) {
|
if (formats[i] == GR_PALETTE8_RGBA8) {
|
||||||
f8bitPaletteSupport = true;
|
f8bitPaletteSupport = true;
|
||||||
@ -220,7 +220,7 @@ GrGpuGL::GrGpuGL() {
|
|||||||
GLenum maxSampleGetter = (kIMG_MSFBO == fMSFBOType) ?
|
GLenum maxSampleGetter = (kIMG_MSFBO == fMSFBOType) ?
|
||||||
GR_MAX_SAMPLES_IMG :
|
GR_MAX_SAMPLES_IMG :
|
||||||
GR_MAX_SAMPLES;
|
GR_MAX_SAMPLES;
|
||||||
GR_GL(GetIntegerv(maxSampleGetter, &maxSamples));
|
GR_GL_GetIntegerv(maxSampleGetter, &maxSamples);
|
||||||
if (maxSamples > 1 ) {
|
if (maxSamples > 1 ) {
|
||||||
fAASamples[kNone_AALevel] = 0;
|
fAASamples[kNone_AALevel] = 0;
|
||||||
fAASamples[kLow_AALevel] = GrMax(2,
|
fAASamples[kLow_AALevel] = GrMax(2,
|
||||||
@ -311,7 +311,7 @@ GrGpuGL::GrGpuGL() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Experimentation has found that some GLs that support NPOT textures
|
/* Experimentation has found that some GLs that support NPOT textures
|
||||||
do not support FBOs with a NPOT texture. They report "unsupported" FBO
|
do not support FBOs with a NPOT texture. They report "unsupported" FBO
|
||||||
status. I don't know how to explicitly query for this. Do an
|
status. I don't know how to explicitly query for this. Do an
|
||||||
@ -356,7 +356,7 @@ GrGpuGL::GrGpuGL() {
|
|||||||
*/
|
*/
|
||||||
fMinRenderTargetHeight = GR_INVAL_GLINT;
|
fMinRenderTargetHeight = GR_INVAL_GLINT;
|
||||||
GLint maxRenderSize;
|
GLint maxRenderSize;
|
||||||
glGetIntegerv(GR_MAX_RENDERBUFFER_SIZE, &maxRenderSize);
|
GR_GL_GetIntegerv(GR_MAX_RENDERBUFFER_SIZE, &maxRenderSize);
|
||||||
|
|
||||||
if (gPrintStartupSpew) {
|
if (gPrintStartupSpew) {
|
||||||
GrPrintf("Small height FBO texture experiments\n");
|
GrPrintf("Small height FBO texture experiments\n");
|
||||||
@ -1072,7 +1072,7 @@ void GrGpuGL::eraseStencil(uint32_t value, uint32_t mask) {
|
|||||||
|
|
||||||
void GrGpuGL::eraseStencilClip() {
|
void GrGpuGL::eraseStencilClip() {
|
||||||
GLint stencilBitCount;
|
GLint stencilBitCount;
|
||||||
GR_GL(GetIntegerv(GL_STENCIL_BITS, &stencilBitCount));
|
GR_GL_GetIntegerv(GL_STENCIL_BITS, &stencilBitCount);
|
||||||
GrAssert(stencilBitCount > 0);
|
GrAssert(stencilBitCount > 0);
|
||||||
GLint clipStencilMask = (1 << (stencilBitCount - 1));
|
GLint clipStencilMask = (1 << (stencilBitCount - 1));
|
||||||
eraseStencil(0, clipStencilMask);
|
eraseStencil(0, clipStencilMask);
|
||||||
@ -1243,7 +1243,7 @@ void GrGpuGL::flushStencil() {
|
|||||||
GLint stencilBitCount;
|
GLint stencilBitCount;
|
||||||
GLint clipStencilMask;
|
GLint clipStencilMask;
|
||||||
GLint pathStencilMask;
|
GLint pathStencilMask;
|
||||||
GR_GL(GetIntegerv(GL_STENCIL_BITS, &stencilBitCount));
|
GR_GL_GetIntegerv(GL_STENCIL_BITS, &stencilBitCount);
|
||||||
GrAssert(stencilBitCount > 0 ||
|
GrAssert(stencilBitCount > 0 ||
|
||||||
kNone_StencilPass == fCurrDrawState.fStencilPass);
|
kNone_StencilPass == fCurrDrawState.fStencilPass);
|
||||||
clipStencilMask = (1 << (stencilBitCount - 1));
|
clipStencilMask = (1 << (stencilBitCount - 1));
|
||||||
@ -1513,7 +1513,7 @@ void GrGpuGL::flushGLStateCommon(PrimitiveType type) {
|
|||||||
// calling on non-MSAA target caused a crash in one environment,
|
// calling on non-MSAA target caused a crash in one environment,
|
||||||
// though I don't think it should.
|
// though I don't think it should.
|
||||||
if (!fAASamples[kHigh_AALevel]) {
|
if (!fAASamples[kHigh_AALevel]) {
|
||||||
GR_GL(GetIntegerv(GL_SAMPLE_BUFFERS, &msaa));
|
GR_GL_GetIntegerv(GL_SAMPLE_BUFFERS, &msaa);
|
||||||
}
|
}
|
||||||
if (fCurrDrawState.fFlagBits & kAntialias_StateBit) {
|
if (fCurrDrawState.fFlagBits & kAntialias_StateBit) {
|
||||||
if (msaa) {
|
if (msaa) {
|
||||||
|
@ -180,6 +180,16 @@ void gl_version(int* major, int* minor);
|
|||||||
#define SK_GL_HAS_COLOR4UB
|
#define SK_GL_HAS_COLOR4UB
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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) \
|
||||||
|
do { \
|
||||||
|
*(p) = GR_GL_INIT_ZERO; \
|
||||||
|
GR_GL(GetIntegerv(e, p)); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ static const char* gvshad[] = {
|
|||||||
|
|
||||||
// 2: kText_Program
|
// 2: kText_Program
|
||||||
"attribute vec2 aPosition;\n"
|
"attribute vec2 aPosition;\n"
|
||||||
"attribute vec2 aTexture;\n"
|
"attribute vec2 aTexture;\n"
|
||||||
"varying vec2 vTexture;\n"
|
"varying vec2 vTexture;\n"
|
||||||
DECL_MATRIX(viewM)
|
DECL_MATRIX(viewM)
|
||||||
#if ATTRIBUTE_TEXT_COLOR
|
#if ATTRIBUTE_TEXT_COLOR
|
||||||
@ -133,8 +133,8 @@ static const char* gvshad[] = {
|
|||||||
"}\n",
|
"}\n",
|
||||||
|
|
||||||
// 6: kTwoPointRadialTextureVertCoords_Program
|
// 6: kTwoPointRadialTextureVertCoords_Program
|
||||||
"uniform " GR_PRECISION " float uParams[6];\n"
|
"uniform " GR_PRECISION " float uParams[6];\n"
|
||||||
// 0 is t^2 term of quadratic
|
// 0 is t^2 term of quadratic
|
||||||
// 1 is one-half the inverse of above
|
// 1 is one-half the inverse of above
|
||||||
// 2 is x offset of the second circle (post tex-matrix)
|
// 2 is x offset of the second circle (post tex-matrix)
|
||||||
// 3 is the radius of the first circle (post tex-matrix)
|
// 3 is the radius of the first circle (post tex-matrix)
|
||||||
@ -156,7 +156,7 @@ static const char* gvshad[] = {
|
|||||||
"}\n",
|
"}\n",
|
||||||
|
|
||||||
// 6: kTwoPointRadialTextureVertCoords_Program
|
// 6: kTwoPointRadialTextureVertCoords_Program
|
||||||
"uniform " GR_PRECISION " float uParams[6];\n"
|
"uniform " GR_PRECISION " float uParams[6];\n"
|
||||||
DECL_MATRIX(viewM)
|
DECL_MATRIX(viewM)
|
||||||
DECL_MATRIX(texM)
|
DECL_MATRIX(texM)
|
||||||
"attribute vec2 aPosition;\n"
|
"attribute vec2 aPosition;\n"
|
||||||
@ -197,7 +197,7 @@ static const char* gfshad[] = {
|
|||||||
#else
|
#else
|
||||||
" gl_FragColor = vColor * texture2DProj(sTexture, vTexture);\n"
|
" gl_FragColor = vColor * texture2DProj(sTexture, vTexture);\n"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
"}\n",
|
"}\n",
|
||||||
|
|
||||||
// 2: kText_Program
|
// 2: kText_Program
|
||||||
@ -251,14 +251,14 @@ static const char* gfshad[] = {
|
|||||||
" 0.5);\n"
|
" 0.5);\n"
|
||||||
" gl_FragColor = vColor * texture2D(sTexture, t);\n"
|
" gl_FragColor = vColor * texture2D(sTexture, t);\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
|
||||||
// 7: kTwoPointRadialTextureVertCoords_Program, kTwoPointRadialTextureTexCoords_Program
|
// 7: kTwoPointRadialTextureVertCoords_Program, kTwoPointRadialTextureTexCoords_Program
|
||||||
GR_SHADER_PRECISION
|
GR_SHADER_PRECISION
|
||||||
"varying vec4 vColor;\n"
|
"varying vec4 vColor;\n"
|
||||||
"varying float vB;\n" // t coeffecient of quadratic.
|
"varying float vB;\n" // t coeffecient of quadratic.
|
||||||
"varying vec2 t;\n" // coordinates in canonical radial gradient space
|
"varying vec2 t;\n" // coordinates in canonical radial gradient space
|
||||||
"uniform sampler2D sTexture;\n"
|
"uniform sampler2D sTexture;\n"
|
||||||
"uniform float uParams[6];\n"
|
"uniform float uParams[6];\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
"float c = t.x*t.x + t.y*t.y - uParams[4];\n"
|
"float c = t.x*t.x + t.y*t.y - uParams[4];\n"
|
||||||
"float ac4 = uParams[0] * c * 4.0;\n"
|
"float ac4 = uParams[0] * c * 4.0;\n"
|
||||||
@ -276,16 +276,16 @@ static const struct {
|
|||||||
bool fHasTexMatrix;
|
bool fHasTexMatrix;
|
||||||
bool fHasTexCoords;
|
bool fHasTexCoords;
|
||||||
bool fTwoPointRadial;
|
bool fTwoPointRadial;
|
||||||
GrGpuGLShaders::ColorType fColorType;
|
GrGpuGLShaders::ColorType fColorType;
|
||||||
} gProgramLoadData[] = {
|
} gProgramLoadData[] = {
|
||||||
// kTextureVertCoords_Program
|
// kTextureVertCoords_Program
|
||||||
{0, 0, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
{0, 0, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kTextureVertCoordsProj_Program
|
// kTextureVertCoordsProj_Program
|
||||||
{0, 1, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
{0, 1, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kTextureTexCoords_Program
|
// kTextureTexCoords_Program
|
||||||
{1, 0, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
{1, 0, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kTextureTexCoordsProj_Program
|
// kTextureTexCoordsProj_Program
|
||||||
{1, 1, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
{1, 1, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kTextureVertCoordsNoColor_Program
|
// kTextureVertCoordsNoColor_Program
|
||||||
{4, 4, true, false, false, GrGpuGLShaders::kNone_ColorType },
|
{4, 4, true, false, false, GrGpuGLShaders::kNone_ColorType },
|
||||||
// kTextureTexCoordsNoColor_Program
|
// kTextureTexCoordsNoColor_Program
|
||||||
@ -297,11 +297,11 @@ static const struct {
|
|||||||
{2, 2, false, true, false, GrGpuGLShaders::kUniform_ColorType },
|
{2, 2, false, true, false, GrGpuGLShaders::kUniform_ColorType },
|
||||||
#endif
|
#endif
|
||||||
// kRadialTextureVertCoords_Program
|
// kRadialTextureVertCoords_Program
|
||||||
{0, 5, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
{0, 5, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kRadialTextureTexCoords_Program
|
// kRadialTextureTexCoords_Program
|
||||||
{1, 5, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
{1, 5, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kSweepTextureVertCoords_Program
|
// kSweepTextureVertCoords_Program
|
||||||
{0, 6, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
{0, 6, true, false, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kSweepTextureTexCoords_Program
|
// kSweepTextureTexCoords_Program
|
||||||
{1, 6, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
{1, 6, true, true, false, GrGpuGLShaders::kAttrib_ColorType },
|
||||||
// kTwoPointRadialTextureVertCoords_Program
|
// kTwoPointRadialTextureVertCoords_Program
|
||||||
@ -326,16 +326,17 @@ GLuint GrGpuGLShaders::loadShader(GLenum type, const char* src) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint compiled;
|
|
||||||
GR_GL(ShaderSource(shader, 1, &src, NULL));
|
GR_GL(ShaderSource(shader, 1, &src, NULL));
|
||||||
GR_GL(CompileShader(shader));
|
GR_GL(CompileShader(shader));
|
||||||
|
|
||||||
|
GLint compiled = GR_GL_INIT_ZERO;
|
||||||
GR_GL(GetShaderiv(shader, GL_COMPILE_STATUS, &compiled));
|
GR_GL(GetShaderiv(shader, GL_COMPILE_STATUS, &compiled));
|
||||||
|
|
||||||
if (!compiled) {
|
if (!compiled) {
|
||||||
GLint infoLen;
|
GLint infoLen = GR_GL_INIT_ZERO;
|
||||||
GR_GL(GetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen));
|
GR_GL(GetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen));
|
||||||
GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
|
GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
|
||||||
if (infoLen > 0) {
|
if (infoLen > 0) {
|
||||||
GR_GL(GetShaderInfoLog(shader, infoLen+1, NULL, (char*)log.get()));
|
GR_GL(GetShaderInfoLog(shader, infoLen+1, NULL, (char*)log.get()));
|
||||||
GrPrintf((char*)log.get());
|
GrPrintf((char*)log.get());
|
||||||
}
|
}
|
||||||
@ -357,22 +358,22 @@ bool GrGpuGLShaders::createProgram(GLuint vshader, GLuint fshader,
|
|||||||
program->fFShaderID = fshader;
|
program->fFShaderID = fshader;
|
||||||
|
|
||||||
GrAssert(0 != program->fProgramID);
|
GrAssert(0 != program->fProgramID);
|
||||||
|
|
||||||
GR_GL(AttachShader(program->fProgramID, vshader));
|
GR_GL(AttachShader(program->fProgramID, vshader));
|
||||||
GR_GL(AttachShader(program->fProgramID, fshader));
|
GR_GL(AttachShader(program->fProgramID, fshader));
|
||||||
|
|
||||||
GR_GL(BindAttribLocation(program->fProgramID,
|
GR_GL(BindAttribLocation(program->fProgramID,
|
||||||
GR_GL_POS_ATTR_LOCATION,
|
GR_GL_POS_ATTR_LOCATION,
|
||||||
"aPosition"));
|
"aPosition"));
|
||||||
if (hasTexCoords) {
|
if (hasTexCoords) {
|
||||||
GR_GL(BindAttribLocation(program->fProgramID,
|
GR_GL(BindAttribLocation(program->fProgramID,
|
||||||
GR_GL_TEX_ATTR_LOCATION,
|
GR_GL_TEX_ATTR_LOCATION,
|
||||||
"aTexture"));
|
"aTexture"));
|
||||||
}
|
}
|
||||||
#if ATTRIBUTE_MATRIX
|
#if ATTRIBUTE_MATRIX
|
||||||
if (hasTexMatrix) {
|
if (hasTexMatrix) {
|
||||||
GR_GL(BindAttribLocation(program->fProgramID,
|
GR_GL(BindAttribLocation(program->fProgramID,
|
||||||
GR_GL_TEXMAT_ATTR_LOCATION,
|
GR_GL_TEXMAT_ATTR_LOCATION,
|
||||||
"texM"));
|
"texM"));
|
||||||
// set to something arbitrary to signal to flush that program
|
// set to something arbitrary to signal to flush that program
|
||||||
// uses the texture matrix.
|
// uses the texture matrix.
|
||||||
@ -380,28 +381,28 @@ bool GrGpuGLShaders::createProgram(GLuint vshader, GLuint fshader,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (colorType == kAttrib_ColorType) {
|
if (colorType == kAttrib_ColorType) {
|
||||||
GR_GL(BindAttribLocation(program->fProgramID,
|
GR_GL(BindAttribLocation(program->fProgramID,
|
||||||
GR_GL_COL_ATTR_LOCATION,
|
GR_GL_COL_ATTR_LOCATION,
|
||||||
"aColor"));
|
"aColor"));
|
||||||
}
|
}
|
||||||
#if ATTRIBUTE_MATRIX
|
#if ATTRIBUTE_MATRIX
|
||||||
GR_GL(BindAttribLocation(program->fProgramID,
|
GR_GL(BindAttribLocation(program->fProgramID,
|
||||||
GR_GL_MAT_ATTR_LOCATION,
|
GR_GL_MAT_ATTR_LOCATION,
|
||||||
"viewM"));
|
"viewM"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GR_GL(LinkProgram(program->fProgramID));
|
GR_GL(LinkProgram(program->fProgramID));
|
||||||
|
|
||||||
GLint linked;
|
GLint linked = GR_GL_INIT_ZERO;
|
||||||
GR_GL(GetProgramiv(program->fProgramID, GL_LINK_STATUS, &linked));
|
GR_GL(GetProgramiv(program->fProgramID, GL_LINK_STATUS, &linked));
|
||||||
if (!linked) {
|
if (!linked) {
|
||||||
GLint infoLen;
|
GLint infoLen = GR_GL_INIT_ZERO;
|
||||||
GR_GL(GetProgramiv(program->fProgramID, GL_INFO_LOG_LENGTH, &infoLen));
|
GR_GL(GetProgramiv(program->fProgramID, GL_INFO_LOG_LENGTH, &infoLen));
|
||||||
GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
|
GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
|
||||||
if (infoLen > 0) {
|
if (infoLen > 0) {
|
||||||
GR_GL(GetProgramInfoLog(program->fProgramID,
|
GR_GL(GetProgramInfoLog(program->fProgramID,
|
||||||
infoLen+1,
|
infoLen+1,
|
||||||
NULL,
|
NULL,
|
||||||
(char*)log.get()));
|
(char*)log.get()));
|
||||||
GrPrintf((char*)log.get());
|
GrPrintf((char*)log.get());
|
||||||
}
|
}
|
||||||
@ -415,18 +416,18 @@ bool GrGpuGLShaders::createProgram(GLuint vshader, GLuint fshader,
|
|||||||
#if !ATTRIBUTE_MATRIX
|
#if !ATTRIBUTE_MATRIX
|
||||||
program->fMatrixLocation =
|
program->fMatrixLocation =
|
||||||
GR_GL(GetUniformLocation(program->fProgramID, "viewM"));
|
GR_GL(GetUniformLocation(program->fProgramID, "viewM"));
|
||||||
program->fTexMatrixLocation =
|
program->fTexMatrixLocation =
|
||||||
GR_GL(GetUniformLocation(program->fProgramID, "texM"));
|
GR_GL(GetUniformLocation(program->fProgramID, "texM"));
|
||||||
#endif
|
#endif
|
||||||
program->fColorLocation =
|
program->fColorLocation =
|
||||||
GR_GL(GetUniformLocation(program->fProgramID, "uColor"));
|
GR_GL(GetUniformLocation(program->fProgramID, "uColor"));
|
||||||
program->fTwoPointParamsLocation =
|
program->fTwoPointParamsLocation =
|
||||||
GR_GL(GetUniformLocation(program->fProgramID, "uParams"));
|
GR_GL(GetUniformLocation(program->fProgramID, "uParams"));
|
||||||
|
|
||||||
GLint samplerLocation =
|
GLint samplerLocation =
|
||||||
GR_GL(GetUniformLocation(program->fProgramID, "sTexture"));
|
GR_GL(GetUniformLocation(program->fProgramID, "sTexture"));
|
||||||
|
|
||||||
#if !ATTRIBUTE_MATRIX
|
#if !ATTRIBUTE_MATRIX
|
||||||
if (-1 == program->fMatrixLocation) {
|
if (-1 == program->fMatrixLocation) {
|
||||||
GrAssert(!"Cannot find matrix uniform in program");
|
GrAssert(!"Cannot find matrix uniform in program");
|
||||||
GR_GL(DeleteProgram(program->fProgramID));
|
GR_GL(DeleteProgram(program->fProgramID));
|
||||||
@ -456,16 +457,16 @@ bool GrGpuGLShaders::createProgram(GLuint vshader, GLuint fshader,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (-1 == program->fColorLocation &&
|
if (-1 == program->fColorLocation &&
|
||||||
(kUniform_ColorType == colorType)) {
|
(kUniform_ColorType == colorType)) {
|
||||||
GR_GL(DeleteProgram(program->fProgramID));
|
GR_GL(DeleteProgram(program->fProgramID));
|
||||||
program->fProgramID = 0;
|
program->fProgramID = 0;
|
||||||
return false;
|
return false;
|
||||||
} else if (-1 != program->fColorLocation &&
|
} else if (-1 != program->fColorLocation &&
|
||||||
(kUniform_ColorType != colorType)) {
|
(kUniform_ColorType != colorType)) {
|
||||||
GrAssert(!"Unexpectedly found color uniform");
|
GrAssert(!"Unexpectedly found color uniform");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (twoPointRadial) {
|
if (twoPointRadial) {
|
||||||
if (-1 == program->fTwoPointParamsLocation) {
|
if (-1 == program->fTwoPointParamsLocation) {
|
||||||
GrAssert(!"Didn't find expected uniform for 2pt radial gradient");
|
GrAssert(!"Didn't find expected uniform for 2pt radial gradient");
|
||||||
@ -476,19 +477,19 @@ bool GrGpuGLShaders::createProgram(GLuint vshader, GLuint fshader,
|
|||||||
} else {
|
} else {
|
||||||
GrAssert(-1 == program->fTwoPointParamsLocation);
|
GrAssert(-1 == program->fTwoPointParamsLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
GR_GL(UseProgram(program->fProgramID));
|
GR_GL(UseProgram(program->fProgramID));
|
||||||
if (-1 != samplerLocation) {
|
if (-1 != samplerLocation) {
|
||||||
GR_GL(Uniform1i(samplerLocation, 0));
|
GR_GL(Uniform1i(samplerLocation, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGpuGLShaders::GrGpuGLShaders() {
|
GrGpuGLShaders::GrGpuGLShaders() {
|
||||||
|
|
||||||
resetContextHelper();
|
resetContextHelper();
|
||||||
|
|
||||||
GLuint vshadIDs[GR_ARRAY_COUNT(gvshad)];
|
GLuint vshadIDs[GR_ARRAY_COUNT(gvshad)];
|
||||||
for (size_t s = 0; s < GR_ARRAY_COUNT(gvshad); ++s) {
|
for (size_t s = 0; s < GR_ARRAY_COUNT(gvshad); ++s) {
|
||||||
vshadIDs[s] = loadShader(GL_VERTEX_SHADER, gvshad[s]);
|
vshadIDs[s] = loadShader(GL_VERTEX_SHADER, gvshad[s]);
|
||||||
@ -502,7 +503,7 @@ GrGpuGLShaders::GrGpuGLShaders() {
|
|||||||
GR_STATIC_ASSERT(kProgramCount == GR_ARRAY_COUNT(gProgramLoadData));
|
GR_STATIC_ASSERT(kProgramCount == GR_ARRAY_COUNT(gProgramLoadData));
|
||||||
for (int p = 0; p < kProgramCount; ++p) {
|
for (int p = 0; p < kProgramCount; ++p) {
|
||||||
GR_DEBUGCODE(bool result = )
|
GR_DEBUGCODE(bool result = )
|
||||||
createProgram(vshadIDs[gProgramLoadData[p].fVShaderIdx],
|
createProgram(vshadIDs[gProgramLoadData[p].fVShaderIdx],
|
||||||
fshadIDs[gProgramLoadData[p].fFShaderIdx],
|
fshadIDs[gProgramLoadData[p].fFShaderIdx],
|
||||||
gProgramLoadData[p].fHasTexMatrix,
|
gProgramLoadData[p].fHasTexMatrix,
|
||||||
gProgramLoadData[p].fHasTexCoords,
|
gProgramLoadData[p].fHasTexCoords,
|
||||||
@ -510,14 +511,14 @@ GrGpuGLShaders::GrGpuGLShaders() {
|
|||||||
gProgramLoadData[p].fTwoPointRadial,
|
gProgramLoadData[p].fTwoPointRadial,
|
||||||
&fPrograms[p]);
|
&fPrograms[p]);
|
||||||
GR_DEBUGASSERT(result);
|
GR_DEBUGASSERT(result);
|
||||||
|
|
||||||
for (int m = 0; m < kMatrixModeCount; ++m) {
|
for (int m = 0; m < kMatrixModeCount; ++m) {
|
||||||
fPrograms[p].fMatrixModeCache[m].setScale(GR_ScalarMax,
|
fPrograms[p].fMatrixModeCache[m].setScale(GR_ScalarMax,
|
||||||
GR_ScalarMax); // illegal
|
GR_ScalarMax); // illegal
|
||||||
};
|
};
|
||||||
fPrograms[p].fColor = GrColor_ILLEGAL;
|
fPrograms[p].fColor = GrColor_ILLEGAL;
|
||||||
fPrograms[p].fTextureOrientation = (GrGLTexture::Orientation)-1; // illegal
|
fPrograms[p].fTextureOrientation = (GrGLTexture::Orientation)-1; // illegal
|
||||||
|
|
||||||
// these aren't strictly invalid, just really unlikely.
|
// these aren't strictly invalid, just really unlikely.
|
||||||
fPrograms[p].fRadial2CenterX1 = GR_ScalarMin;
|
fPrograms[p].fRadial2CenterX1 = GR_ScalarMin;
|
||||||
fPrograms[p].fRadial2Radius0 = GR_ScalarMin;
|
fPrograms[p].fRadial2Radius0 = GR_ScalarMin;
|
||||||
@ -526,7 +527,7 @@ GrGpuGLShaders::GrGpuGLShaders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrGpuGLShaders::~GrGpuGLShaders() {
|
GrGpuGLShaders::~GrGpuGLShaders() {
|
||||||
// shaders get deleted once for each program that uses them, do we care?
|
// shaders get deleted once for each program that uses them, do we care?
|
||||||
// probably not
|
// probably not
|
||||||
for (int i = 0; i < kProgramCount; ++i) {
|
for (int i = 0; i < kProgramCount; ++i) {
|
||||||
GR_GL(DeleteProgram(fPrograms[i].fProgramID));
|
GR_GL(DeleteProgram(fPrograms[i].fProgramID));
|
||||||
@ -559,8 +560,8 @@ void GrGpuGLShaders::flushMatrix(GLint location) {
|
|||||||
0,-GrIntToScalar(2) / fCurrDrawState.fRenderTarget->height(), GR_Scalar1,
|
0,-GrIntToScalar(2) / fCurrDrawState.fRenderTarget->height(), GR_Scalar1,
|
||||||
0, 0, GrMatrix::I()[8]);
|
0, 0, GrMatrix::I()[8]);
|
||||||
m.setConcat(m, fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode]);
|
m.setConcat(m, fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode]);
|
||||||
|
|
||||||
// ES doesn't allow you to pass true to the transpose param,
|
// ES doesn't allow you to pass true to the transpose param,
|
||||||
// so do our own transpose
|
// so do our own transpose
|
||||||
GrScalar mt[] = {
|
GrScalar mt[] = {
|
||||||
m[GrMatrix::kScaleX],
|
m[GrMatrix::kScaleX],
|
||||||
@ -577,12 +578,12 @@ void GrGpuGLShaders::flushMatrix(GLint location) {
|
|||||||
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+0, mt+0);
|
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+0, mt+0);
|
||||||
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+1, mt+3);
|
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+1, mt+3);
|
||||||
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+2, mt+6);
|
glVertexAttrib4fv(GR_GL_MAT_ATTR_LOCATION+2, mt+6);
|
||||||
#else
|
#else
|
||||||
GR_GL(UniformMatrix3fv(location,1,false,mt));
|
GR_GL(UniformMatrix3fv(location,1,false,mt));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuGLShaders::flushTexMatrix(GLint location,
|
void GrGpuGLShaders::flushTexMatrix(GLint location,
|
||||||
GrGLTexture::Orientation orientation) {
|
GrGLTexture::Orientation orientation) {
|
||||||
GrMatrix* m;
|
GrMatrix* m;
|
||||||
GrMatrix temp;
|
GrMatrix temp;
|
||||||
@ -616,9 +617,9 @@ void GrGpuGLShaders::flushTexMatrix(GLint location,
|
|||||||
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+0, mt+0);
|
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+0, mt+0);
|
||||||
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+1, mt+3);
|
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+1, mt+3);
|
||||||
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+2, mt+6);
|
glVertexAttrib4fv(GR_GL_TEXMAT_ATTR_LOCATION+2, mt+6);
|
||||||
#else
|
#else
|
||||||
GR_GL(UniformMatrix3fv(location,1,false,mt));
|
GR_GL(UniformMatrix3fv(location,1,false,mt));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrGpuGLShaders::flushTwoPointRadial(GLint paramsLocation,
|
void GrGpuGLShaders::flushTwoPointRadial(GLint paramsLocation,
|
||||||
@ -675,10 +676,10 @@ void GrGpuGLShaders::flushProgram(PrimitiveType type) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GrSamplerState::kAlphaMod_SampleMode:
|
case GrSamplerState::kAlphaMod_SampleMode:
|
||||||
GrAssert(((GrGLTexture*)fCurrDrawState.fTexture)->orientation() ==
|
GrAssert(((GrGLTexture*)fCurrDrawState.fTexture)->orientation() ==
|
||||||
GrGLTexture::kTopDown_Orientation);
|
GrGLTexture::kTopDown_Orientation);
|
||||||
(((GrGLTexture*)fCurrDrawState.fTexture)->uploadFormat() == GL_ALPHA);
|
(((GrGLTexture*)fCurrDrawState.fTexture)->uploadFormat() == GL_ALPHA);
|
||||||
|
|
||||||
nextProgram = kText_Program;
|
nextProgram = kText_Program;
|
||||||
break;
|
break;
|
||||||
case GrSamplerState::kNormal_SampleMode: {
|
case GrSamplerState::kNormal_SampleMode: {
|
||||||
@ -688,10 +689,10 @@ void GrGpuGLShaders::flushProgram(PrimitiveType type) {
|
|||||||
bool persp = fCurrDrawState.fMatrixModeCache[kTexture_MatrixMode].hasPerspective();
|
bool persp = fCurrDrawState.fMatrixModeCache[kTexture_MatrixMode].hasPerspective();
|
||||||
|
|
||||||
if (fGeometrySrc.fVertexLayout & kPositionAsTexCoord_VertexLayoutBit) {
|
if (fGeometrySrc.fVertexLayout & kPositionAsTexCoord_VertexLayoutBit) {
|
||||||
nextProgram = persp ? kTextureVertCoordsProj_Program :
|
nextProgram = persp ? kTextureVertCoordsProj_Program :
|
||||||
kTextureVertCoords_Program;
|
kTextureVertCoords_Program;
|
||||||
} else {
|
} else {
|
||||||
nextProgram = persp ? kTextureTexCoordsProj_Program :
|
nextProgram = persp ? kTextureTexCoordsProj_Program :
|
||||||
kTextureTexCoords_Program;
|
kTextureTexCoords_Program;
|
||||||
}
|
}
|
||||||
// check for case when frag shader can skip the color modulation
|
// check for case when frag shader can skip the color modulation
|
||||||
@ -727,7 +728,7 @@ HAVE_NEXT_PROGRAM:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
||||||
|
|
||||||
flushGLStateCommon(type);
|
flushGLStateCommon(type);
|
||||||
|
|
||||||
if (fRenderTargetChanged) {
|
if (fRenderTargetChanged) {
|
||||||
@ -740,18 +741,18 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
|||||||
// we assume all shader matrices may be wrong after viewport changes
|
// we assume all shader matrices may be wrong after viewport changes
|
||||||
for (int p = 0; p < kProgramCount; ++p) {
|
for (int p = 0; p < kProgramCount; ++p) {
|
||||||
// set to illegal matrix
|
// set to illegal matrix
|
||||||
fPrograms[p].fMatrixModeCache[kModelView_MatrixMode].setScale(GR_ScalarMax,
|
fPrograms[p].fMatrixModeCache[kModelView_MatrixMode].setScale(GR_ScalarMax,
|
||||||
GR_ScalarMax);
|
GR_ScalarMax);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fRenderTargetChanged = false;
|
fRenderTargetChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
flushProgram(type);
|
flushProgram(type);
|
||||||
|
|
||||||
if (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit) {
|
if (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit) {
|
||||||
// invalidate the immediate mode color
|
// invalidate the immediate mode color
|
||||||
fHWDrawState.fColor = GrColor_ILLEGAL;
|
fHWDrawState.fColor = GrColor_ILLEGAL;
|
||||||
} else {
|
} else {
|
||||||
// if we don't have per-vert colors either set the color attr
|
// if we don't have per-vert colors either set the color attr
|
||||||
// or color uniform (depending on which program).
|
// or color uniform (depending on which program).
|
||||||
@ -767,7 +768,7 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
|||||||
GR_GL(Uniform4fv(fPrograms[fHWProgram].fColorLocation, 1, c));
|
GR_GL(Uniform4fv(fPrograms[fHWProgram].fColorLocation, 1, c));
|
||||||
fPrograms[fHWProgram].fColor = fCurrDrawState.fColor;
|
fPrograms[fHWProgram].fColor = fCurrDrawState.fColor;
|
||||||
}
|
}
|
||||||
} else if (kAttrib_ColorType == fPrograms[fHWProgram].fColorType &&
|
} else if (kAttrib_ColorType == fPrograms[fHWProgram].fColorType &&
|
||||||
fHWDrawState.fColor != fCurrDrawState.fColor) {
|
fHWDrawState.fColor != fCurrDrawState.fColor) {
|
||||||
// OpenGL ES only supports the float varities of glVertexAttrib
|
// OpenGL ES only supports the float varities of glVertexAttrib
|
||||||
float c[] = {
|
float c[] = {
|
||||||
@ -783,17 +784,17 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
|||||||
|
|
||||||
#if ATTRIBUTE_MATRIX
|
#if ATTRIBUTE_MATRIX
|
||||||
GrMatrix* currentMats = fHWDrawState.fMatrixModeCache;
|
GrMatrix* currentMats = fHWDrawState.fMatrixModeCache;
|
||||||
GrGLTexture::Orientation& orientation = fTextureOrientation;
|
GrGLTexture::Orientation& orientation = fTextureOrientation;
|
||||||
#else
|
#else
|
||||||
GrMatrix* currentMats = fPrograms[fHWProgram].fMatrixModeCache;
|
GrMatrix* currentMats = fPrograms[fHWProgram].fMatrixModeCache;
|
||||||
GrGLTexture::Orientation& orientation =
|
GrGLTexture::Orientation& orientation =
|
||||||
fPrograms[fHWProgram].fTextureOrientation;
|
fPrograms[fHWProgram].fTextureOrientation;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (currentMats[kModelView_MatrixMode] !=
|
if (currentMats[kModelView_MatrixMode] !=
|
||||||
fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode]) {
|
fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode]) {
|
||||||
flushMatrix(fPrograms[fHWProgram].fMatrixLocation);
|
flushMatrix(fPrograms[fHWProgram].fMatrixLocation);
|
||||||
currentMats[kModelView_MatrixMode] =
|
currentMats[kModelView_MatrixMode] =
|
||||||
fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode];
|
fCurrDrawState.fMatrixModeCache[kModelView_MatrixMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,7 +806,7 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
|||||||
orientation != texture->orientation())) {
|
orientation != texture->orientation())) {
|
||||||
flushTexMatrix(fPrograms[fHWProgram].fTexMatrixLocation,
|
flushTexMatrix(fPrograms[fHWProgram].fTexMatrixLocation,
|
||||||
texture->orientation());
|
texture->orientation());
|
||||||
currentMats[kTexture_MatrixMode] =
|
currentMats[kTexture_MatrixMode] =
|
||||||
fCurrDrawState.fMatrixModeCache[kTexture_MatrixMode];
|
fCurrDrawState.fMatrixModeCache[kTexture_MatrixMode];
|
||||||
orientation = texture->orientation();
|
orientation = texture->orientation();
|
||||||
}
|
}
|
||||||
@ -816,14 +817,14 @@ bool GrGpuGLShaders::flushGraphicsState(PrimitiveType type) {
|
|||||||
(fPrograms[fHWProgram].fRadial2CenterX1 != sampler.getRadial2CenterX1() ||
|
(fPrograms[fHWProgram].fRadial2CenterX1 != sampler.getRadial2CenterX1() ||
|
||||||
fPrograms[fHWProgram].fRadial2Radius0 != sampler.getRadial2Radius0() ||
|
fPrograms[fHWProgram].fRadial2Radius0 != sampler.getRadial2Radius0() ||
|
||||||
fPrograms[fHWProgram].fRadial2PosRoot != sampler.isRadial2PosRoot())) {
|
fPrograms[fHWProgram].fRadial2PosRoot != sampler.isRadial2PosRoot())) {
|
||||||
|
|
||||||
flushTwoPointRadial(fPrograms[fHWProgram].fTwoPointParamsLocation,
|
flushTwoPointRadial(fPrograms[fHWProgram].fTwoPointParamsLocation,
|
||||||
sampler);
|
sampler);
|
||||||
fPrograms[fHWProgram].fRadial2CenterX1 = sampler.getRadial2CenterX1();
|
fPrograms[fHWProgram].fRadial2CenterX1 = sampler.getRadial2CenterX1();
|
||||||
fPrograms[fHWProgram].fRadial2Radius0 = sampler.getRadial2Radius0();
|
fPrograms[fHWProgram].fRadial2Radius0 = sampler.getRadial2Radius0();
|
||||||
fPrograms[fHWProgram].fRadial2PosRoot = sampler.isRadial2PosRoot();
|
fPrograms[fHWProgram].fRadial2PosRoot = sampler.isRadial2PosRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -833,45 +834,45 @@ void GrGpuGLShaders::setupGeometry(uint32_t startVertex,
|
|||||||
uint32_t indexCount) {
|
uint32_t indexCount) {
|
||||||
|
|
||||||
int newColorOffset, newTexCoordOffset;
|
int newColorOffset, newTexCoordOffset;
|
||||||
|
|
||||||
GLsizei newStride = VertexSizeAndOffsets(fGeometrySrc.fVertexLayout,
|
GLsizei newStride = VertexSizeAndOffsets(fGeometrySrc.fVertexLayout,
|
||||||
&newTexCoordOffset,
|
&newTexCoordOffset,
|
||||||
&newColorOffset);
|
&newColorOffset);
|
||||||
int oldColorOffset, oldTexCoordOffset;
|
int oldColorOffset, oldTexCoordOffset;
|
||||||
GLsizei oldStride = VertexSizeAndOffsets(fHWGeometryState.fVertexLayout,
|
GLsizei oldStride = VertexSizeAndOffsets(fHWGeometryState.fVertexLayout,
|
||||||
&oldTexCoordOffset,
|
&oldTexCoordOffset,
|
||||||
&oldColorOffset);
|
&oldColorOffset);
|
||||||
|
|
||||||
const GLvoid* posPtr = (GLvoid*)(newStride * startVertex);
|
const GLvoid* posPtr = (GLvoid*)(newStride * startVertex);
|
||||||
|
|
||||||
if (kBuffer_GeometrySrcType == fGeometrySrc.fVertexSrc) {
|
if (kBuffer_GeometrySrcType == fGeometrySrc.fVertexSrc) {
|
||||||
GrAssert(NULL != fGeometrySrc.fVertexBuffer);
|
GrAssert(NULL != fGeometrySrc.fVertexBuffer);
|
||||||
GrAssert(!fGeometrySrc.fVertexBuffer->isLocked());
|
GrAssert(!fGeometrySrc.fVertexBuffer->isLocked());
|
||||||
if (fHWGeometryState.fVertexBuffer != fGeometrySrc.fVertexBuffer) {
|
if (fHWGeometryState.fVertexBuffer != fGeometrySrc.fVertexBuffer) {
|
||||||
GrGLVertexBuffer* buf =
|
GrGLVertexBuffer* buf =
|
||||||
(GrGLVertexBuffer*)fGeometrySrc.fVertexBuffer;
|
(GrGLVertexBuffer*)fGeometrySrc.fVertexBuffer;
|
||||||
GR_GL(BindBuffer(GL_ARRAY_BUFFER, buf->bufferID()));
|
GR_GL(BindBuffer(GL_ARRAY_BUFFER, buf->bufferID()));
|
||||||
fHWGeometryState.fVertexBuffer = fGeometrySrc.fVertexBuffer;
|
fHWGeometryState.fVertexBuffer = fGeometrySrc.fVertexBuffer;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (kArray_GeometrySrcType == fGeometrySrc.fVertexSrc) {
|
if (kArray_GeometrySrcType == fGeometrySrc.fVertexSrc) {
|
||||||
posPtr = (void*)((intptr_t)fGeometrySrc.fVertexArray +
|
posPtr = (void*)((intptr_t)fGeometrySrc.fVertexArray +
|
||||||
(intptr_t)posPtr);
|
(intptr_t)posPtr);
|
||||||
} else {
|
} else {
|
||||||
GrAssert(kReserved_GeometrySrcType == fGeometrySrc.fVertexSrc);
|
GrAssert(kReserved_GeometrySrcType == fGeometrySrc.fVertexSrc);
|
||||||
posPtr = (void*)((intptr_t)fVertices.get() + (intptr_t)posPtr);
|
posPtr = (void*)((intptr_t)fVertices.get() + (intptr_t)posPtr);
|
||||||
}
|
}
|
||||||
if (NULL != fHWGeometryState.fVertexBuffer) {
|
if (NULL != fHWGeometryState.fVertexBuffer) {
|
||||||
GR_GL(BindBuffer(GL_ARRAY_BUFFER, 0));
|
GR_GL(BindBuffer(GL_ARRAY_BUFFER, 0));
|
||||||
fHWGeometryState.fVertexBuffer = NULL;
|
fHWGeometryState.fVertexBuffer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kBuffer_GeometrySrcType == fGeometrySrc.fIndexSrc) {
|
if (kBuffer_GeometrySrcType == fGeometrySrc.fIndexSrc) {
|
||||||
GrAssert(NULL != fGeometrySrc.fIndexBuffer);
|
GrAssert(NULL != fGeometrySrc.fIndexBuffer);
|
||||||
GrAssert(!fGeometrySrc.fIndexBuffer->isLocked());
|
GrAssert(!fGeometrySrc.fIndexBuffer->isLocked());
|
||||||
if (fHWGeometryState.fIndexBuffer != fGeometrySrc.fIndexBuffer) {
|
if (fHWGeometryState.fIndexBuffer != fGeometrySrc.fIndexBuffer) {
|
||||||
GrGLIndexBuffer* buf =
|
GrGLIndexBuffer* buf =
|
||||||
(GrGLIndexBuffer*)fGeometrySrc.fIndexBuffer;
|
(GrGLIndexBuffer*)fGeometrySrc.fIndexBuffer;
|
||||||
GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf->bufferID()));
|
GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf->bufferID()));
|
||||||
fHWGeometryState.fIndexBuffer = fGeometrySrc.fIndexBuffer;
|
fHWGeometryState.fIndexBuffer = fGeometrySrc.fIndexBuffer;
|
||||||
@ -880,7 +881,7 @@ void GrGpuGLShaders::setupGeometry(uint32_t startVertex,
|
|||||||
GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||||
fHWGeometryState.fIndexBuffer = NULL;
|
fHWGeometryState.fIndexBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLenum scalarType;
|
GLenum scalarType;
|
||||||
bool texCoordNorm;
|
bool texCoordNorm;
|
||||||
if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) {
|
if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) {
|
||||||
@ -890,21 +891,21 @@ void GrGpuGLShaders::setupGeometry(uint32_t startVertex,
|
|||||||
scalarType = GrGLType;
|
scalarType = GrGLType;
|
||||||
texCoordNorm = false;
|
texCoordNorm = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool baseChange = posPtr != fHWGeometryState.fPositionPtr;
|
bool baseChange = posPtr != fHWGeometryState.fPositionPtr;
|
||||||
bool scalarChange = (GrGLTextType != GrGLType) &&
|
bool scalarChange = (GrGLTextType != GrGLType) &&
|
||||||
(kTextFormat_VertexLayoutBit &
|
(kTextFormat_VertexLayoutBit &
|
||||||
(fHWGeometryState.fVertexLayout ^
|
(fHWGeometryState.fVertexLayout ^
|
||||||
fGeometrySrc.fVertexLayout));
|
fGeometrySrc.fVertexLayout));
|
||||||
bool strideChange = newStride != oldStride;
|
bool strideChange = newStride != oldStride;
|
||||||
bool posChange = baseChange || scalarChange || strideChange;
|
bool posChange = baseChange || scalarChange || strideChange;
|
||||||
|
|
||||||
if (posChange) {
|
if (posChange) {
|
||||||
GR_GL(VertexAttribPointer(GR_GL_POS_ATTR_LOCATION, 2, scalarType,
|
GR_GL(VertexAttribPointer(GR_GL_POS_ATTR_LOCATION, 2, scalarType,
|
||||||
false, newStride, posPtr));
|
false, newStride, posPtr));
|
||||||
fHWGeometryState.fPositionPtr = posPtr;
|
fHWGeometryState.fPositionPtr = posPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTexCoordOffset > 0) {
|
if (newTexCoordOffset > 0) {
|
||||||
GLvoid* texCoordPtr = (int8_t*)posPtr + newTexCoordOffset;
|
GLvoid* texCoordPtr = (int8_t*)posPtr + newTexCoordOffset;
|
||||||
if (oldTexCoordOffset <= 0) {
|
if (oldTexCoordOffset <= 0) {
|
||||||
@ -917,21 +918,21 @@ void GrGpuGLShaders::setupGeometry(uint32_t startVertex,
|
|||||||
} else if (oldTexCoordOffset > 0) {
|
} else if (oldTexCoordOffset > 0) {
|
||||||
GR_GL(DisableVertexAttribArray(GR_GL_TEX_ATTR_LOCATION));
|
GR_GL(DisableVertexAttribArray(GR_GL_TEX_ATTR_LOCATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newColorOffset > 0) {
|
if (newColorOffset > 0) {
|
||||||
GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset;
|
GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset;
|
||||||
if (oldColorOffset <= 0) {
|
if (oldColorOffset <= 0) {
|
||||||
GR_GL(EnableVertexAttribArray(GR_GL_COL_ATTR_LOCATION));
|
GR_GL(EnableVertexAttribArray(GR_GL_COL_ATTR_LOCATION));
|
||||||
}
|
}
|
||||||
if (posChange || newColorOffset != oldColorOffset) {
|
if (posChange || newColorOffset != oldColorOffset) {
|
||||||
GR_GL(VertexAttribPointer(GR_GL_COL_ATTR_LOCATION, 4,
|
GR_GL(VertexAttribPointer(GR_GL_COL_ATTR_LOCATION, 4,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
true, newStride, colorPtr));
|
true, newStride, colorPtr));
|
||||||
}
|
}
|
||||||
} else if (oldColorOffset > 0) {
|
} else if (oldColorOffset > 0) {
|
||||||
GR_GL(DisableVertexAttribArray(GR_GL_COL_ATTR_LOCATION));
|
GR_GL(DisableVertexAttribArray(GR_GL_COL_ATTR_LOCATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
|
fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user