Commit 2be04209 by Nicolas Capens

Add state for GL_COMBINE.

Bug 21278131 Change-Id: I0590b67be5fad5690739b8ebaa9245cba4187b40 Reviewed-on: https://swiftshader-review.googlesource.com/3231Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 83f26ffe
...@@ -105,7 +105,24 @@ Context::Context(const egl::Config *config, const Context *shareContext) ...@@ -105,7 +105,24 @@ Context::Context(const egl::Config *config, const Context *shareContext)
mState.colorMaskAlpha = true; mState.colorMaskAlpha = true;
mState.depthMask = true; mState.depthMask = true;
mState.textureEnvMode = GL_MODULATE; for(int i = 0; i < MAX_TEXTURE_UNITS; i++)
{
mState.textureUnit[i].environmentMode = GL_MODULATE;
mState.textureUnit[i].combineRGB = GL_MODULATE;
mState.textureUnit[i].combineAlpha = GL_MODULATE;
mState.textureUnit[i].src0RGB = GL_TEXTURE;
mState.textureUnit[i].src1RGB = GL_PREVIOUS;
mState.textureUnit[i].src2RGB = GL_CONSTANT;
mState.textureUnit[i].src0Alpha = GL_TEXTURE;
mState.textureUnit[i].src1Alpha = GL_PREVIOUS;
mState.textureUnit[i].src2Alpha = GL_CONSTANT;
mState.textureUnit[i].operand0RGB = GL_SRC_COLOR;
mState.textureUnit[i].operand1RGB = GL_SRC_COLOR;
mState.textureUnit[i].operand2RGB = GL_SRC_ALPHA;
mState.textureUnit[i].operand0Alpha = GL_SRC_ALPHA;
mState.textureUnit[i].operand1Alpha = GL_SRC_ALPHA;
mState.textureUnit[i].operand2Alpha = GL_SRC_ALPHA;
}
if(shareContext != NULL) if(shareContext != NULL)
{ {
...@@ -1793,19 +1810,17 @@ GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode ...@@ -1793,19 +1810,17 @@ GLenum Context::applyIndexBuffer(const void *indices, GLsizei count, GLenum mode
void Context::applyTextures() void Context::applyTextures()
{ {
GLenum texEnvMode = getTextureEnvMode(); for(int unit = 0; unit < MAX_TEXTURE_UNITS; unit++)
for(int samplerIndex = 0; samplerIndex < MAX_TEXTURE_UNITS; samplerIndex++)
{ {
Texture *texture = nullptr; Texture *texture = nullptr;
if(textureExternalEnabled[samplerIndex]) if(textureExternalEnabled[unit])
{ {
texture = getSamplerTexture(samplerIndex, TEXTURE_EXTERNAL); texture = getSamplerTexture(unit, TEXTURE_EXTERNAL);
} }
else if(texture2Denabled[samplerIndex]) else if(texture2Denabled[unit])
{ {
texture = getSamplerTexture(samplerIndex, TEXTURE_2D); texture = getSamplerTexture(unit, TEXTURE_2D);
} }
if(texture && texture->isSamplerComplete()) if(texture && texture->isSamplerComplete())
...@@ -1818,59 +1833,59 @@ void Context::applyTextures() ...@@ -1818,59 +1833,59 @@ void Context::applyTextures()
GLenum magFilter = texture->getMagFilter(); GLenum magFilter = texture->getMagFilter();
GLfloat maxAnisotropy = texture->getMaxAnisotropy(); GLfloat maxAnisotropy = texture->getMaxAnisotropy();
device->setAddressingModeU(sw::SAMPLER_PIXEL, samplerIndex, es2sw::ConvertTextureWrap(wrapS)); device->setAddressingModeU(sw::SAMPLER_PIXEL, unit, es2sw::ConvertTextureWrap(wrapS));
device->setAddressingModeV(sw::SAMPLER_PIXEL, samplerIndex, es2sw::ConvertTextureWrap(wrapT)); device->setAddressingModeV(sw::SAMPLER_PIXEL, unit, es2sw::ConvertTextureWrap(wrapT));
sw::FilterType minFilter; sw::FilterType minFilter;
sw::MipmapType mipFilter; sw::MipmapType mipFilter;
es2sw::ConvertMinFilter(texFilter, &minFilter, &mipFilter, maxAnisotropy); es2sw::ConvertMinFilter(texFilter, &minFilter, &mipFilter, maxAnisotropy);
// ASSERT(minFilter == es2sw::ConvertMagFilter(magFilter)); // ASSERT(minFilter == es2sw::ConvertMagFilter(magFilter));
device->setTextureFilter(sw::SAMPLER_PIXEL, samplerIndex, minFilter); device->setTextureFilter(sw::SAMPLER_PIXEL, unit, minFilter);
// device->setTextureFilter(sw::SAMPLER_PIXEL, samplerIndex, es2sw::ConvertMagFilter(magFilter)); // device->setTextureFilter(sw::SAMPLER_PIXEL, unit, es2sw::ConvertMagFilter(magFilter));
device->setMipmapFilter(sw::SAMPLER_PIXEL, samplerIndex, mipFilter); device->setMipmapFilter(sw::SAMPLER_PIXEL, unit, mipFilter);
device->setMaxAnisotropy(sw::SAMPLER_PIXEL, samplerIndex, maxAnisotropy); device->setMaxAnisotropy(sw::SAMPLER_PIXEL, unit, maxAnisotropy);
applyTexture(samplerIndex, texture); applyTexture(unit, texture);
if(texEnvMode != GL_COMBINE) if(mState.textureUnit[unit].environmentMode != GL_COMBINE)
{ {
GLenum texFormat = texture->getFormat(GL_TEXTURE_2D, 0); GLenum texFormat = texture->getFormat(GL_TEXTURE_2D, 0);
device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); // Cs device->setFirstArgument(unit, sw::TextureStage::SOURCE_TEXTURE); // Cs
device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setFirstModifier(unit, sw::TextureStage::MODIFIER_COLOR);
device->setSecondArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); // Cp device->setSecondArgument(unit, sw::TextureStage::SOURCE_CURRENT); // Cp
device->setSecondModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setSecondModifier(unit, sw::TextureStage::MODIFIER_COLOR);
device->setThirdArgument(samplerIndex, sw::TextureStage::SOURCE_CONSTANT); // Cc device->setThirdArgument(unit, sw::TextureStage::SOURCE_CONSTANT); // Cc
device->setThirdModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setThirdModifier(unit, sw::TextureStage::MODIFIER_COLOR);
device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); // As device->setFirstArgumentAlpha(unit, sw::TextureStage::SOURCE_TEXTURE); // As
device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setFirstModifierAlpha(unit, sw::TextureStage::MODIFIER_ALPHA);
device->setSecondArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); // Ap device->setSecondArgumentAlpha(unit, sw::TextureStage::SOURCE_CURRENT); // Ap
device->setSecondModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setSecondModifierAlpha(unit, sw::TextureStage::MODIFIER_ALPHA);
device->setThirdArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CONSTANT); // Ac device->setThirdArgumentAlpha(unit, sw::TextureStage::SOURCE_CONSTANT); // Ac
device->setThirdModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setThirdModifierAlpha(unit, sw::TextureStage::MODIFIER_ALPHA);
switch(texEnvMode) switch(mState.textureUnit[unit].environmentMode)
{ {
case GL_REPLACE: case GL_REPLACE:
switch(texFormat) switch(texFormat)
{ {
case GL_ALPHA: case GL_ALPHA:
// Cv = Cp, Av = As // Cv = Cp, Av = As
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG1);
break; break;
case GL_LUMINANCE: case GL_LUMINANCE:
case GL_RGB: case GL_RGB:
// Cv = Cs, Av = Ap // Cv = Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA:
case GL_RGBA: case GL_RGBA:
// Cv = Cs, Av = As // Cv = Cs, Av = As
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG1);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1880,19 +1895,19 @@ void Context::applyTextures() ...@@ -1880,19 +1895,19 @@ void Context::applyTextures()
{ {
case GL_ALPHA: case GL_ALPHA:
// Cv = Cp, Av = ApAs // Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
case GL_LUMINANCE: case GL_LUMINANCE:
case GL_RGB: case GL_RGB:
// Cv = CpCs, Av = Ap // Cv = CpCs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperation(unit, sw::TextureStage::STAGE_MODULATE);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA:
case GL_RGBA: case GL_RGBA:
// Cv = CpCs, Av = ApAs // Cv = CpCs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperation(unit, sw::TextureStage::STAGE_MODULATE);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1904,17 +1919,17 @@ void Context::applyTextures() ...@@ -1904,17 +1919,17 @@ void Context::applyTextures()
case GL_LUMINANCE: case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA:
// undefined // undefined
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
break; break;
case GL_RGB: case GL_RGB:
// Cv = Cs, Av = Ap // Cv = Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
case GL_RGBA: case GL_RGBA:
// Cv = Cp(1 ? As) + CsAs, Av = Ap // Cv = Cp(1 ? As) + CsAs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_BLENDTEXTUREALPHA); // Alpha * (Arg1 - Arg2) + Arg2 device->setStageOperation(unit, sw::TextureStage::STAGE_BLENDTEXTUREALPHA); // Alpha * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1924,19 +1939,19 @@ void Context::applyTextures() ...@@ -1924,19 +1939,19 @@ void Context::applyTextures()
{ {
case GL_ALPHA: case GL_ALPHA:
// Cv = Cp, Av = ApAs // Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
case GL_LUMINANCE: case GL_LUMINANCE:
case GL_RGB: case GL_RGB:
// Cv = Cp(1 ? Cs) + CcCs, Av = Ap // Cv = Cp(1 ? Cs) + CcCs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2 device->setStageOperation(unit, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA:
case GL_RGBA: case GL_RGBA:
// Cv = Cp(1 ? Cs) + CcCs, Av = ApAs // Cv = Cp(1 ? Cs) + CcCs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2 device->setStageOperation(unit, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1946,19 +1961,19 @@ void Context::applyTextures() ...@@ -1946,19 +1961,19 @@ void Context::applyTextures()
{ {
case GL_ALPHA: case GL_ALPHA:
// Cv = Cp, Av = ApAs // Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
case GL_LUMINANCE: case GL_LUMINANCE:
case GL_RGB: case GL_RGB:
// Cv = Cp + Cs, Av = Ap // Cv = Cp + Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_ADD); device->setStageOperation(unit, sw::TextureStage::STAGE_ADD);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA: case GL_LUMINANCE_ALPHA:
case GL_RGBA: case GL_RGBA:
// Cv = Cp + Cs, Av = ApAs // Cv = Cp + Cs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_ADD); device->setStageOperation(unit, sw::TextureStage::STAGE_ADD);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_MODULATE);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -1974,33 +1989,22 @@ void Context::applyTextures() ...@@ -1974,33 +1989,22 @@ void Context::applyTextures()
} }
else else
{ {
applyTexture(samplerIndex, 0); applyTexture(unit, 0);
device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setFirstArgument(unit, sw::TextureStage::SOURCE_CURRENT);
device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setFirstModifier(unit, sw::TextureStage::MODIFIER_COLOR);
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperation(unit, sw::TextureStage::STAGE_SELECTARG1);
device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setFirstArgumentAlpha(unit, sw::TextureStage::SOURCE_CURRENT);
device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setFirstModifierAlpha(unit, sw::TextureStage::MODIFIER_ALPHA);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1); device->setStageOperationAlpha(unit, sw::TextureStage::STAGE_SELECTARG1);
} }
} }
} }
void Context::setTextureEnvMode(GLenum texEnvMode) void Context::setTextureEnvMode(GLenum texEnvMode)
{ {
switch(texEnvMode) mState.textureUnit[mState.activeSampler].environmentMode = texEnvMode;
{
case GL_MODULATE:
case GL_DECAL:
case GL_BLEND:
case GL_ADD:
case GL_REPLACE:
mState.textureEnvMode = texEnvMode;
break;
default:
UNREACHABLE();
}
} }
void Context::applyTexture(int index, Texture *baseTexture) void Context::applyTexture(int index, Texture *baseTexture)
...@@ -2909,11 +2913,6 @@ unsigned int Context::getActiveTexture() const ...@@ -2909,11 +2913,6 @@ unsigned int Context::getActiveTexture() const
return mState.activeSampler; return mState.activeSampler;
} }
GLenum Context::getTextureEnvMode()
{
return mState.textureEnvMode;
}
} }
egl::Context *es1CreateContext(const egl::Config *config, const egl::Context *shareContext) egl::Context *es1CreateContext(const egl::Config *config, const egl::Context *shareContext)
......
...@@ -180,6 +180,25 @@ class VertexAttribute ...@@ -180,6 +180,25 @@ class VertexAttribute
typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS]; typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
struct TextureUnit
{
GLenum environmentMode;
GLenum combineRGB;
GLenum combineAlpha;
GLenum src0RGB;
GLenum src0Alpha;
GLenum src1RGB;
GLenum src1Alpha;
GLenum src2RGB;
GLenum src2Alpha;
GLenum operand0RGB;
GLenum operand0Alpha;
GLenum operand1RGB;
GLenum operand1Alpha;
GLenum operand2RGB;
GLenum operand2Alpha;
};
// Helper structure to store all raw state // Helper structure to store all raw state
struct State struct State
{ {
...@@ -253,7 +272,7 @@ struct State ...@@ -253,7 +272,7 @@ struct State
GLint unpackAlignment; GLint unpackAlignment;
GLint packAlignment; GLint packAlignment;
GLenum textureEnvMode; TextureUnit textureUnit[MAX_TEXTURE_UNITS];
}; };
class Context : public egl::Context class Context : public egl::Context
...@@ -332,7 +351,6 @@ public: ...@@ -332,7 +351,6 @@ public:
unsigned int getActiveTexture() const; unsigned int getActiveTexture() const;
void setTextureEnvMode(GLenum texEnvMode); void setTextureEnvMode(GLenum texEnvMode);
GLenum getTextureEnvMode();
void setLineWidth(GLfloat width); void setLineWidth(GLfloat width);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment