typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLRenderbufferStorageMultisampleProc)(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLResolveMultisampleFramebufferProc)();
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLBindUniformLocation)(GrGLuint program, GrGLint location, const char* name);
+
#if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char* const * str, const GrGLint* length);
#else
// the standard function in ES3+ or GL 3.0+.
GLPtr<GrGLRenderbufferStorageMultisampleProc> fRenderbufferStorageMultisample;
+ // Pointer to BindUniformLocationCHROMIUM from the GL_CHROMIUM_bind_uniform_location extension.
+ GLPtr<GrGLBindUniformLocation> fBindUniformLocation;
+
GLPtr<GrGLResolveMultisampleFramebufferProc> fResolveMultisampleFramebuffer;
GLPtr<GrGLScissorProc> fScissor;
GLPtr<GrGLShaderSourceProc> fShaderSource;
const ModeColorFilterEffect& colorModeFilter = drawEffect.castEffect<ModeColorFilterEffect>();
GrGLfloat c[4];
GrColorToRGBAFloat(colorModeFilter.color(), c);
- uman.set4fv(fFilterColorUni, 0, 1, c);
+ uman.set4fv(fFilterColorUni, 1, c);
}
}
GrGLfloat vec[] = {
m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale,
};
- uniManager.setMatrix4fv(fMatrixHandle, 0, 1, mt);
- uniManager.set4fv(fVectorHandle, 0, 1, vec);
+ uniManager.setMatrix4fv(fMatrixHandle, 1, mt);
+ uniManager.set4fv(fVectorHandle, 1, vec);
}
private:
#if SK_SUPPORT_GPU
void setUniformPoint3(const GrGLUniformManager& uman, UniformHandle uni, const SkPoint3& point) {
GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat));
- uman.set3fv(uni, 0, 1, &point.fX);
+ uman.set3fv(uni, 1, &point.fX);
}
void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const SkPoint3& point) {
float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
imageIncrement[0] = 1.0f / texture.width();
imageIncrement[1] = ySign / texture.height();
- uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
- uman.set2fv(fTargetUni, 0, 1, conv.target());
- uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), conv.kernel());
+ uman.set2fv(fImageIncrementUni, 1, imageIncrement);
+ uman.set2fv(fTargetUni, 1, conv.target());
+ uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.kernel());
uman.set1f(fGainUni, conv.gain());
uman.set1f(fBiasUni, conv.bias());
const SkIRect& bounds = conv.bounds();
default:
GrCrash("Unknown filter direction.");
}
- uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
+ uman.set2fv(fImageIncrementUni, 1, imageIncrement);
}
///////////////////////////////////////////////////////////////////////////////
SkScalarToFloat(diffRadius)
};
- uman.set1fv(fParamUni, 0, 6, values);
+ uman.set1fv(fParamUni, 6, values);
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedDiffRadius = diffRadius;
data.isPosRoot() ? 1.f : -1.f
};
- uman.set1fv(fParamUni, 0, 6, values);
+ uman.set1fv(fParamUni, 6, values);
fCachedCenter = centerX1;
fCachedRadius = radius0;
fCachedPosRoot = data.isPosRoot();
float imageIncrement[2];
imageIncrement[0] = 1.0f / texture.width();
imageIncrement[1] = 1.0f / texture.height();
- uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
+ uman.set2fv(fImageIncrementUni, 1, imageIncrement);
uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
}
default:
GrCrash("Unknown filter direction.");
}
- uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
+ uman.set2fv(fImageIncrementUni, 1, imageIncrement);
if (conv.useBounds()) {
const float* bounds = conv.bounds();
if (Gr1DKernelEffect::kY_Direction == conv.direction() &&
uman.set2f(fBoundsUni, bounds[0], bounds[1]);
}
}
- uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
+ uman.set1fv(fKernelUni, this->width(), conv.kernel());
}
GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
SkTSwap(values[1], values[3]);
}
if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) {
- uman.set4fv(fNameUni, 0, 1, values);
+ uman.set4fv(fNameUni, 1, values);
memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat));
}
}
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(color, c);
- fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c);
+ fUniformManager.set4fv(fUniformHandles.fColorUni, 1, c);
fColor = color;
}
sharedState->fConstAttribColorIndex = -1;
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(coverage, c);
- fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c);
+ fUniformManager.set4fv(fUniformHandles.fCoverageUni, 1, c);
fCoverage = coverage;
}
sharedState->fConstAttribCoverageIndex = -1;
}
this->bindProgramLocations(programId);
+ if (fUniformManager.isUsingBindUniform()) {
+ fUniformManager.getUniformLocations(programId, fUniforms);
+ }
GL_CALL(LinkProgram(programId));
}
}
- fUniformManager.getUniformLocations(programId, fUniforms);
+ if (!fUniformManager.isUsingBindUniform()) {
+ fUniformManager.getUniformLocations(programId, fUniforms);
+ }
*outProgramId = programId;
return true;
}
#include "gl/GrGpuGL.h"
#include "SkMatrix.h"
-#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \
- SkASSERT(offset + arrayCount <= uni.fArrayCount || \
- (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
+#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
+ SkASSERT(arrayCount <= uni.fArrayCount || \
+ (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
+
+GrGLUniformManager::GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {
+ fUsingBindUniform = fGpu->glInterface()->fBindUniformLocation != NULL;
+}
GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType type, int arrayCount) {
int idx = fUniforms.count();
}
void GrGLUniformManager::set1fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kFloat_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
// This assert fires in some instances of the two-pt gradient for its VSParams.
// Once the uniform manager is responsible for inserting the duplicate uniform
// arrays in VS and FS driver bug workaround, this can be enabled.
//SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v));
}
}
}
void GrGLUniformManager::set2fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec2f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v));
}
}
}
void GrGLUniformManager::set3fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec3f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v));
}
}
}
void GrGLUniformManager::set4fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec4f_GrSLType);
SkASSERT(arrayCount > 0);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v));
}
}
}
void GrGLUniformManager::setMatrix3fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kMat33f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices));
}
}
void GrGLUniformManager::setMatrix4fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kMat44f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices));
}
}
SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount);
GrGLint location;
// TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
- GR_GL_CALL_RET(fGpu->glInterface(), location,
+ if (fUsingBindUniform) {
+ location = i;
+ GR_GL_CALL(fGpu->glInterface(),
+ BindUniformLocation(programID, location, uniforms[i].fVariable.c_str()));
+ } else {
+ GR_GL_CALL_RET(fGpu->glInterface(), location,
GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
+ }
if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
fUniforms[i].fVSLocation = location;
}
friend class GrGLUniformManager; // For accessing toUniformIndex().
};
- GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {}
+ GrGLUniformManager(GrGpuGL* gpu);
UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray);
/** Functions for uploading uniform values. The varities ending in v can be used to upload to an
- * array of uniforms. offset + arrayCount must be <= the array count of the uniform.
+ * array of uniforms. arrayCount must be <= the array count of the uniform.
*/
void setSampler(UniformHandle, GrGLint texUnit) const;
void set1f(UniformHandle, GrGLfloat v0) const;
- void set1fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set2f(UniformHandle, GrGLfloat, GrGLfloat) const;
- void set2fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const;
- void set3fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const;
- void set4fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
// matrices are column-major, the first three upload a single matrix, the latter three upload
// arrayCount matrices into a uniform array.
void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const;
void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const;
- void setMatrix3fv(UniformHandle, int offset, int arrayCount, const GrGLfloat matrices[]) const;
- void setMatrix4fv(UniformHandle, int offset, int arrayCount, const GrGLfloat matrices[]) const;
+ void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
+ void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
// convenience method for uploading a SkMatrix to a 3x3 matrix uniform
void setSkMatrix(UniformHandle, const SkMatrix&) const;
// name strings. Otherwise, we'd have to hand out copies.
typedef GrTAllocator<BuilderUniform> BuilderUniformArray;
+ /**
+ * Called by the GrGLShaderBuilder to know if the manager is using
+ * BindUniformLocation. In that case getUniformLocations must be called
+ * before the program is linked.
+ */
+ bool isUsingBindUniform() const { return fUsingBindUniform; }
+
/**
* Called by the GrGLShaderBuilder to get GL locations for all uniforms.
*/
int fArrayCount;
};
+ bool fUsingBindUniform;
SkTArray<Uniform, true> fUniforms;
GrGpuGL* fGpu;
};