Add GrColor to RGBA float helper func

Review URL: https://codereview.appspot.com/6518044/





git-svn-id: http://skia.googlecode.com/svn/trunk@5572 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-09-17 17:23:21 +00:00
Родитель 0729b62373
Коммит 7534747e63
3 изменённых файлов: 24 добавлений и 27 удалений

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

@ -58,5 +58,14 @@ static inline GrColor GrColorPackRGBA(unsigned r, unsigned g,
*/
#define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A))
/** Converts a GrColor to an rgba array of GrGLfloat */
static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) {
static const float ONE_OVER_255 = 1.f / 255.f;
rgba[0] = GrColorUnpackR(color) * ONE_OVER_255;
rgba[1] = GrColorUnpackG(color) * ONE_OVER_255;
rgba[2] = GrColorUnpackB(color) * ONE_OVER_255;
rgba[3] = GrColorUnpackA(color) * ONE_OVER_255;
}
#endif

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

@ -1986,13 +1986,8 @@ void GrGpuGL::flushBlend(bool isLines,
BlendCoeffReferencesConstant(dstCoeff)) &&
(!fHWBlendState.fConstColorValid ||
fHWBlendState.fConstColor != blendConst)) {
float c[] = {
GrColorUnpackR(blendConst) / 255.f,
GrColorUnpackG(blendConst) / 255.f,
GrColorUnpackB(blendConst) / 255.f,
GrColorUnpackA(blendConst) / 255.f
};
GrGLfloat c[4];
GrColorToRGBAFloat(blendConst, c);
GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
fHWBlendState.fConstColor = blendConst;
fHWBlendState.fConstColorValid = true;

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

@ -259,15 +259,6 @@ void GrGpuGL::flushColorMatrix() {
}
}
static const float ONE_OVER_255 = 1.f / 255.f;
#define GR_COLOR_TO_VEC4(color) {\
GrColorUnpackR(color) * ONE_OVER_255,\
GrColorUnpackG(color) * ONE_OVER_255,\
GrColorUnpackB(color) * ONE_OVER_255,\
GrColorUnpackA(color) * ONE_OVER_255 \
}
void GrGpuGL::flushColor(GrColor color) {
const ProgramDesc& desc = fCurrentProgram->getDesc();
const GrDrawState& drawState = this->getDrawState();
@ -280,19 +271,18 @@ void GrGpuGL::flushColor(GrColor color) {
switch (desc.fColorInput) {
case ProgramDesc::kAttribute_ColorInput:
if (fHWConstAttribColor != color) {
// OpenGL ES only supports the float varieties of
// glVertexAttrib
float c[] = GR_COLOR_TO_VEC4(color);
GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(),
c));
// OpenGL ES only supports the float varieties of glVertexAttrib
GrGLfloat c[4];
GrColorToRGBAFloat(color, c);
GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), c));
fHWConstAttribColor = color;
}
break;
case ProgramDesc::kUniform_ColorInput:
if (fCurrentProgram->fColor != color) {
// OpenGL ES doesn't support unsigned byte varieties of
// glUniform
float c[] = GR_COLOR_TO_VEC4(color);
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(color, c);
GrAssert(kInvalidUniformHandle != fCurrentProgram->fUniforms.fColorUni);
fCurrentProgram->fUniformManager.set4fv(fCurrentProgram->fUniforms.fColorUni,
0, 1, c);
@ -309,7 +299,8 @@ void GrGpuGL::flushColor(GrColor color) {
UniformHandle filterColorUni = fCurrentProgram->fUniforms.fColorFilterUni;
if (kInvalidUniformHandle != filterColorUni &&
fCurrentProgram->fColorFilterColor != drawState.getColorFilterColor()) {
float c[] = GR_COLOR_TO_VEC4(drawState.getColorFilterColor());
GrGLfloat c[4];
GrColorToRGBAFloat(drawState.getColorFilterColor(), c);
fCurrentProgram->fUniformManager.set4fv(filterColorUni, 0, 1, c);
fCurrentProgram->fColorFilterColor = drawState.getColorFilterColor();
}
@ -330,7 +321,8 @@ void GrGpuGL::flushCoverage(GrColor coverage) {
if (fHWConstAttribCoverage != coverage) {
// OpenGL ES only supports the float varieties of
// glVertexAttrib
float c[] = GR_COLOR_TO_VEC4(coverage);
GrGLfloat c[4];
GrColorToRGBAFloat(coverage, c);
GL_CALL(VertexAttrib4fv(GrGLProgram::CoverageAttributeIdx(),
c));
fHWConstAttribCoverage = coverage;
@ -340,7 +332,8 @@ void GrGpuGL::flushCoverage(GrColor coverage) {
if (fCurrentProgram->fCoverage != coverage) {
// OpenGL ES doesn't support unsigned byte varieties of
// glUniform
float c[] = GR_COLOR_TO_VEC4(coverage);
GrGLfloat c[4];
GrColorToRGBAFloat(coverage, c);
GrAssert(kInvalidUniformHandle != fCurrentProgram->fUniforms.fCoverageUni);
fCurrentProgram->fUniformManager.set4fv(fCurrentProgram->fUniforms.fCoverageUni,
0, 1, c);