Bug 1016086 - Part 1: Use a single attribute in all shaders (r=Bas)

This commit is contained in:
Andreas Gal 2014-05-28 16:18:36 -04:00
Родитель 18d99cf975
Коммит 39be2ca1b2
5 изменённых файлов: 26 добавлений и 105 удалений

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

@ -738,10 +738,11 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
origin.y = -mRenderOffset.y;
}
mCurrentRenderTarget = CompositingRenderTargetOGL::RenderTargetForWindow(this,
origin,
IntSize(width, height),
aTransform);
mCurrentRenderTarget =
CompositingRenderTargetOGL::RenderTargetForWindow(this,
origin,
IntSize(width, height),
aTransform);
mCurrentRenderTarget->BindRenderTarget();
#ifdef DEBUG
mWindowRenderTarget = mCurrentRenderTarget;
@ -1497,25 +1498,6 @@ CompositorOGL::MakeCurrent(MakeCurrentFlags aFlags) {
mGLContext->MakeCurrent(aFlags & ForceMakeCurrent);
}
void
CompositorOGL::BindQuadVBO() {
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
}
void
CompositorOGL::QuadVBOVerticesAttrib(GLuint aAttribIndex) {
mGLContext->fVertexAttribPointer(aAttribIndex, 4,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
(GLvoid*) 0);
}
void
CompositorOGL::QuadVBOTexCoordsAttrib(GLuint aAttribIndex) {
mGLContext->fVertexAttribPointer(aAttribIndex, 4,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
(GLvoid*) 0);
}
void
CompositorOGL::BindAndDrawQuads(ShaderProgramOGL *aProg,
int aQuads,
@ -1524,22 +1506,19 @@ CompositorOGL::BindAndDrawQuads(ShaderProgramOGL *aProg,
{
NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
const GLuint coordAttribIndex = 0;
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
mGLContext->fVertexAttribPointer(coordAttribIndex, 4,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
(GLvoid*) 0);
mGLContext->fEnableVertexAttribArray(coordAttribIndex);
aProg->SetLayerRects(aLayerRects);
GLuint vertAttribIndex = aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib);
GLuint texCoordAttribIndex = aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib);
BindQuadVBO();
QuadVBOVerticesAttrib(vertAttribIndex);
if (texCoordAttribIndex != GLuint(-1)) {
QuadVBOTexCoordsAttrib(texCoordAttribIndex);
mGLContext->fEnableVertexAttribArray(texCoordAttribIndex);
if (aProg->GetTextureCount() > 0) {
aProg->SetTextureRects(aTextureRects);
}
mGLContext->fEnableVertexAttribArray(vertAttribIndex);
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4 * aQuads);
}

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

@ -346,9 +346,6 @@ private:
GLuint aSourceFrameBuffer,
GLuint *aFBO, GLuint *aTexture);
void BindQuadVBO();
void QuadVBOVerticesAttrib(GLuint aAttribIndex);
void QuadVBOTexCoordsAttrib(GLuint aAttribIndex);
void BindAndDrawQuads(ShaderProgramOGL *aProg,
int aQuads,
const gfx::Rect* aLayerRect,

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

@ -21,8 +21,6 @@ namespace layers {
using namespace std;
typedef ProgramProfileOGL::Argument Argument;
#define GAUSSIAN_KERNEL_HALF_WIDTH 11
#define GAUSSIAN_KERNEL_STEP 0.2
@ -150,12 +148,11 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
vs << "uniform mat4 uLayerTransform;" << endl;
vs << "uniform vec4 uRenderTargetOffset;" << endl;
vs << "attribute vec4 aVertexCoord;" << endl;
vs << "attribute vec4 aCoord;" << endl;
if (!(aConfig.mFeatures & ENABLE_RENDER_COLOR)) {
vs << "uniform mat4 uTextureTransform;" << endl;
vs << "uniform vec4 uTextureRects[4];" << endl;
vs << "attribute vec4 aTexCoord;" << endl;
vs << "varying vec2 vTexCoord;" << endl;
}
@ -166,9 +163,9 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
}
vs << "void main() {" << endl;
vs << " int vertexID = int(aVertexCoord.w);" << endl;
vs << " int vertexID = int(aCoord.w);" << endl;
vs << " vec4 layerRect = uLayerRects[vertexID];" << endl;
vs << " vec4 finalPosition = vec4(aVertexCoord.xy * layerRect.zw + layerRect.xy, 0.0, 1.0);" << endl;
vs << " vec4 finalPosition = vec4(aCoord.xy * layerRect.zw + layerRect.xy, 0.0, 1.0);" << endl;
vs << " finalPosition = uLayerTransform * finalPosition;" << endl;
vs << " finalPosition.xyz /= finalPosition.w;" << endl;
@ -187,7 +184,7 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
if (!(aConfig.mFeatures & ENABLE_RENDER_COLOR)) {
vs << " vec4 textureRect = uTextureRects[vertexID];" << endl;
vs << " vec2 texCoord = aTexCoord.xy * textureRect.zw + textureRect.xy;" << endl;
vs << " vec2 texCoord = aCoord.xy * textureRect.zw + textureRect.xy;" << endl;
vs << " vTexCoord = (uTextureTransform * vec4(texCoord, 0.0, 1.0)).xy;" << endl;
}
@ -355,11 +352,9 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
result.mVertexShaderString = vs.str();
result.mFragmentShaderString = fs.str();
result.mAttributes.AppendElement(Argument("aVertexCoord"));
if (aConfig.mFeatures & ENABLE_RENDER_COLOR) {
result.mTextureCount = 0;
} else {
result.mAttributes.AppendElement(Argument("aTexCoord"));
if (aConfig.mFeatures & ENABLE_TEXTURE_YCBCR) {
result.mTextureCount = 3;
} else if (aConfig.mFeatures & ENABLE_TEXTURE_COMPONENT_ALPHA) {
@ -376,9 +371,6 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
return result;
}
const char* const ShaderProgramOGL::VertexCoordAttrib = "aVertexCoord";
const char* const ShaderProgramOGL::TexCoordAttrib = "aTexCoord";
ShaderProgramOGL::ShaderProgramOGL(GLContext* aGL, const ProgramProfileOGL& aProfile)
: mGL(aGL)
, mProgram(0)
@ -426,14 +418,6 @@ ShaderProgramOGL::Initialize()
mGL->fGetUniformLocation(mProgram, mProfile.mUniforms[i].mNameString);
}
for (uint32_t i = 0; i < mProfile.mAttributes.Length(); ++i) {
mProfile.mAttributes[i].mLocation =
mGL->fGetAttribLocation(mProgram, mProfile.mAttributes[i].mName);
NS_ASSERTION(mProfile.mAttributes[i].mLocation >= 0, "Bad attribute location.");
}
//mProfile.mHasMatrixProj = mProfile.mUniforms[KnownUniform::MatrixProj].mLocation != -1;
return true;
}

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

@ -218,39 +218,13 @@ struct ProgramProfileOGL
*/
static ProgramProfileOGL GetProfileFor(ShaderConfigOGL aConfig);
/**
* These two methods lookup the location of a uniform and attribute,
* respectively. Returns -1 if the named uniform/attribute does not
* have a location for the shaders represented by this profile.
*/
GLint LookupAttributeLocation(const char* aName)
{
for (uint32_t i = 0; i < mAttributes.Length(); ++i) {
if (strcmp(mAttributes[i].mName, aName) == 0) {
return mAttributes[i].mLocation;
}
}
return -1;
}
// represents the name and location of a uniform or attribute
struct Argument
{
Argument(const char* aName) :
mName(aName) {}
const char* mName;
GLint mLocation;
};
// the source code for the program's shaders
std::string mVertexShaderString;
std::string mFragmentShaderString;
KnownUniform mUniforms[KnownUniform::KnownUniformCount];
nsTArray<Argument> mAttributes;
nsTArray<const char *> mDefines;
uint32_t mTextureCount;
size_t mTextureCount;
ProgramProfileOGL() :
mTextureCount(0)
@ -302,13 +276,6 @@ public:
bool CreateProgram(const char *aVertexShaderString,
const char *aFragmentShaderString);
/**
* Lookup the location of an attribute
*/
GLint AttribLocation(const char* aName) {
return mProfile.LookupAttributeLocation(aName);
}
/**
* The following set of methods set a uniform argument to the shader program.
* Not all uniforms may be set for all programs, and such uses will throw
@ -414,9 +381,9 @@ public:
SetUniform(KnownUniform::TexturePass2, aFlag ? 1 : 0);
}
// the names of attributes
static const char* const VertexCoordAttrib;
static const char* const TexCoordAttrib;
size_t GetTextureCount() const {
return mProfile.mTextureCount;
}
protected:
RefPtr<GLContext> mGL;

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

@ -2824,21 +2824,15 @@ GLPresenter::BindAndDrawQuad(ShaderProgramOGL *aProgram,
aProgram->SetLayerRects(layerRects);
aProgram->SetTextureRects(textureRects);
GLuint vertAttribIndex = aProgram->AttribLocation(ShaderProgramOGL::VertexCoordAttrib);
GLuint texCoordAttribIndex = aProgram->AttribLocation(ShaderProgramOGL::TexCoordAttrib);
const GLuint coordAttribIndex = 0;
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
mGLContext->fVertexAttribPointer(vertAttribIndex, 4,
mGLContext->fVertexAttribPointer(coordAttribIndex, 4,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
(GLvoid*)0);
mGLContext->fEnableVertexAttribArray(vertAttribIndex);
mGLContext->fVertexAttribPointer(texCoordAttribIndex, 4,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
(GLvoid*) (sizeof(float)*4*2));
mGLContext->fEnableVertexAttribArray(texCoordAttribIndex);
mGLContext->fEnableVertexAttribArray(coordAttribIndex);
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
mGLContext->fDisableVertexAttribArray(vertAttribIndex);
mGLContext->fDisableVertexAttribArray(texCoordAttribIndex);
mGLContext->fDisableVertexAttribArray(coordAttribIndex);
}
void