Remove support for vertex attribute matrices
Review URL: http://codereview.appspot.com/6200065/ git-svn-id: http://skia.googlecode.com/svn/trunk@3917 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f9ad8867f2
commit
341767c9fc
@ -52,12 +52,6 @@
|
||||
* doesn't actually support immediate style attribute values (e.g. when
|
||||
* the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
|
||||
*
|
||||
* GR_GL_ATTRIBUTE_MATRICES: If changing uniforms is very expensive it may be
|
||||
* faster to use vertex attributes for matrices (set via glVertexAttrib3fv).
|
||||
* Setting this build flag enables this behavior. GR_GL_NO_CONSTANT_ATTRIBUTES
|
||||
* must not be set since this uses constant attributes for the matrices.
|
||||
* Defaults to 0.
|
||||
*
|
||||
* GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index
|
||||
* buffer that replaces old data Ganesh can give a hint to the driver that the
|
||||
* previous data will not be used in future draws like this:
|
||||
@ -120,10 +114,6 @@
|
||||
#define GR_GL_NO_CONSTANT_ATTRIBUTES 0
|
||||
#endif
|
||||
|
||||
#if !defined(GR_GL_ATTRIBUTE_MATRICES)
|
||||
#define GR_GL_ATTRIBUTE_MATRICES 0
|
||||
#endif
|
||||
|
||||
#if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
|
||||
#define GR_GL_USE_BUFFER_DATA_NULL_HINT 1
|
||||
#endif
|
||||
@ -177,8 +167,4 @@
|
||||
(GR_MAC_BUILD && \
|
||||
!GR_GL_USE_BUFFER_DATA_NULL_HINT)
|
||||
|
||||
#if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES)
|
||||
#error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -30,11 +30,7 @@ enum {
|
||||
|
||||
typedef GrGLProgram::ProgramDesc::StageDesc StageDesc;
|
||||
|
||||
#if GR_GL_ATTRIBUTE_MATRICES
|
||||
#define VIEW_MATRIX_NAME "aViewM"
|
||||
#else
|
||||
#define VIEW_MATRIX_NAME "uViewM"
|
||||
#endif
|
||||
#define VIEW_MATRIX_NAME "uViewM"
|
||||
|
||||
#define POS_ATTR_NAME "aPosition"
|
||||
#define COL_ATTR_NAME "aColor"
|
||||
@ -81,11 +77,7 @@ inline const char* declared_color_output_name() { return "fsColorOut"; }
|
||||
inline const char* dual_source_output_name() { return "dualSourceOut"; }
|
||||
|
||||
inline void tex_matrix_name(int stage, GrStringBuilder* s) {
|
||||
#if GR_GL_ATTRIBUTE_MATRICES
|
||||
*s = "aTexM";
|
||||
#else
|
||||
*s = "uTexM";
|
||||
#endif
|
||||
s->appendS32(stage);
|
||||
}
|
||||
|
||||
@ -562,15 +554,10 @@ bool GrGLProgram::genProgram(const GrGLContextInfo& gl,
|
||||
segments.fFSOutputs.push_back(colorOutput);
|
||||
}
|
||||
|
||||
#if GR_GL_ATTRIBUTE_MATRICES
|
||||
segments.fVSAttrs.push_back().set(kMat33f_GrSLType,
|
||||
GrGLShaderVar::kAttribute_TypeModifier, VIEW_MATRIX_NAME);
|
||||
programData->fUniLocations.fViewMatrixUni = kSetAsAttribute;
|
||||
#else
|
||||
segments.fVSUnis.push_back().set(kMat33f_GrSLType,
|
||||
GrGLShaderVar::kUniform_TypeModifier, VIEW_MATRIX_NAME);
|
||||
programData->fUniLocations.fViewMatrixUni = kUseUniform;
|
||||
#endif
|
||||
|
||||
segments.fVSAttrs.push_back().set(kVec2f_GrSLType,
|
||||
GrGLShaderVar::kAttribute_TypeModifier, POS_ATTR_NAME);
|
||||
|
||||
@ -1097,23 +1084,6 @@ bool GrGLProgram::bindOutputsAttribsAndLinkProgram(
|
||||
}
|
||||
}
|
||||
|
||||
if (kSetAsAttribute == programData->fUniLocations.fViewMatrixUni) {
|
||||
GL_CALL(BindAttribLocation(progID,
|
||||
ViewMatrixAttributeIdx(),
|
||||
VIEW_MATRIX_NAME));
|
||||
}
|
||||
|
||||
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
|
||||
const StageUniLocations& unis = programData->fUniLocations.fStages[s];
|
||||
if (kSetAsAttribute == unis.fTextureMatrixUni) {
|
||||
GrStringBuilder matName;
|
||||
tex_matrix_name(s, &matName);
|
||||
GL_CALL(BindAttribLocation(progID,
|
||||
TextureMatrixAttributeIdx(s),
|
||||
matName.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
GL_CALL(BindAttribLocation(progID, ColorAttributeIdx(), COL_ATTR_NAME));
|
||||
GL_CALL(BindAttribLocation(progID, CoverageAttributeIdx(), COV_ATTR_NAME));
|
||||
GL_CALL(BindAttribLocation(progID, EdgeAttributeIdx(), EDGE_ATTR_NAME));
|
||||
@ -1569,15 +1539,10 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
|
||||
varyingDims = coordDims;
|
||||
} else {
|
||||
GrGLShaderVar* mat;
|
||||
#if GR_GL_ATTRIBUTE_MATRICES
|
||||
mat = &segments->fVSAttrs.push_back();
|
||||
mat->setTypeModifier(GrGLShaderVar::kAttribute_TypeModifier);
|
||||
locations->fTextureMatrixUni = kSetAsAttribute;
|
||||
#else
|
||||
mat = &segments->fVSUnis.push_back();
|
||||
mat->setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
|
||||
locations->fTextureMatrixUni = kUseUniform;
|
||||
#endif
|
||||
|
||||
tex_matrix_name(stageNum, mat->accessName());
|
||||
mat->setType(kMat33f_GrSLType);
|
||||
matName = mat->getName().c_str();
|
||||
|
@ -260,7 +260,6 @@ private:
|
||||
public:
|
||||
enum {
|
||||
kUnusedUniform = -1,
|
||||
kSetAsAttribute = 1000,
|
||||
};
|
||||
|
||||
struct StageUniLocations {
|
||||
|
@ -5,6 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "GrGpuGLShaders.h"
|
||||
|
||||
#include "GrBinHashKey.h"
|
||||
#include "effects/GrConvolutionEffect.h"
|
||||
@ -12,7 +13,6 @@
|
||||
#include "GrGLProgram.h"
|
||||
#include "GrGLProgramStage.h"
|
||||
#include "GrGLSL.h"
|
||||
#include "GrGpuGLShaders.h"
|
||||
#include "GrGpuVertex.h"
|
||||
#include "GrNoncopyable.h"
|
||||
#include "GrProgramStageFactory.h"
|
||||
@ -356,48 +356,6 @@ GrGpuGLShaders::~GrGpuGLShaders() {
|
||||
delete fProgramCache;
|
||||
}
|
||||
|
||||
const GrMatrix& GrGpuGLShaders::getHWViewMatrix() {
|
||||
GrAssert(fProgramData);
|
||||
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fViewMatrixUni) {
|
||||
return fHWDrawState.getViewMatrix();
|
||||
} else {
|
||||
return fProgramData->fViewMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuGLShaders::recordHWViewMatrix(const GrMatrix& matrix) {
|
||||
GrAssert(fProgramData);
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fViewMatrixUni) {
|
||||
fHWDrawState.setViewMatrix(matrix);
|
||||
} else {
|
||||
fProgramData->fViewMatrix = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
const GrMatrix& GrGpuGLShaders::getHWSamplerMatrix(int stage) {
|
||||
GrAssert(fProgramData);
|
||||
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) {
|
||||
return fHWDrawState.getSampler(stage).getMatrix();
|
||||
} else {
|
||||
return fProgramData->fTextureMatrices[stage];
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) {
|
||||
GrAssert(fProgramData);
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) {
|
||||
*fHWDrawState.sampler(stage)->matrix() = matrix;
|
||||
} else {
|
||||
fProgramData->fTextureMatrices[stage] = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuGLShaders::onResetContext() {
|
||||
INHERITED::onResetContext();
|
||||
|
||||
@ -428,7 +386,7 @@ void GrGpuGLShaders::onResetContext() {
|
||||
|
||||
void GrGpuGLShaders::flushViewMatrix() {
|
||||
const GrMatrix& vm = this->getDrawState().getViewMatrix();
|
||||
if (!GrGpuGLShaders::getHWViewMatrix().cheapEqualTo(vm)) {
|
||||
if (!fProgramData->fViewMatrix.cheapEqualTo(vm)) {
|
||||
|
||||
const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
|
||||
GrAssert(NULL != rt);
|
||||
@ -453,19 +411,11 @@ void GrGpuGLShaders::flushViewMatrix() {
|
||||
GrScalarToFloat(m[GrMatrix::kMPersp2])
|
||||
};
|
||||
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fViewMatrixUni) {
|
||||
int baseIdx = GrGLProgram::ViewMatrixAttributeIdx();
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
|
||||
} else {
|
||||
GrAssert(GrGLProgram::kUnusedUniform !=
|
||||
fProgramData->fUniLocations.fViewMatrixUni);
|
||||
GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
|
||||
1, false, mt));
|
||||
}
|
||||
this->recordHWViewMatrix(vm);
|
||||
GrAssert(GrGLProgram::kUnusedUniform !=
|
||||
fProgramData->fUniLocations.fViewMatrixUni);
|
||||
GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni,
|
||||
1, false, mt));
|
||||
fProgramData->fViewMatrix = vm;
|
||||
}
|
||||
}
|
||||
|
||||
@ -511,7 +461,7 @@ void GrGpuGLShaders::flushTextureMatrix(int s) {
|
||||
const GrGLTexture* texture =
|
||||
static_cast<const GrGLTexture*>(drawState.getTexture(s));
|
||||
if (NULL != texture) {
|
||||
const GrMatrix& hwMatrix = this->getHWSamplerMatrix(s);
|
||||
const GrMatrix& hwMatrix = fProgramData->fTextureMatrices[s];
|
||||
const GrMatrix& samplerMatrix = drawState.getSampler(s).getMatrix();
|
||||
if (GrGLProgram::kUnusedUniform != uni &&
|
||||
(((1 << s) & fDirtyFlags.fTextureChangedMask) ||
|
||||
@ -536,16 +486,8 @@ void GrGpuGLShaders::flushTextureMatrix(int s) {
|
||||
GrScalarToFloat(m[GrMatrix::kMPersp2])
|
||||
};
|
||||
|
||||
if (GrGLProgram::kSetAsAttribute ==
|
||||
fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) {
|
||||
int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s);
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0));
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3));
|
||||
GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6));
|
||||
} else {
|
||||
GL_CALL(UniformMatrix3fv(uni, 1, false, mt));
|
||||
}
|
||||
this->recordHWSamplerMatrix(s, drawState.getSampler(s).getMatrix());
|
||||
GL_CALL(UniformMatrix3fv(uni, 1, false, mt));
|
||||
fProgramData->fTextureMatrices[s] = samplerMatrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +45,6 @@ private:
|
||||
|
||||
class ProgramCache;
|
||||
|
||||
// Helpers to make code more readable
|
||||
const GrMatrix& getHWViewMatrix();
|
||||
void recordHWViewMatrix(const GrMatrix& matrix);
|
||||
const GrMatrix& getHWSamplerMatrix(int stage);
|
||||
void recordHWSamplerMatrix(int stage, const GrMatrix& matrix);
|
||||
|
||||
// sets the texture matrix uniform for currently bound program
|
||||
void flushTextureMatrix(int stage);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user