Commit 83f26ffe by Nicolas Capens

Implement predefined texture functions.

Bug 21278131 Change-Id: I16f27aeaf530f7672e4f60ea379ec82450cc5243 Reviewed-on: https://swiftshader-review.googlesource.com/3230Reviewed-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 d6e2fb2b
...@@ -1833,37 +1833,156 @@ void Context::applyTextures() ...@@ -1833,37 +1833,156 @@ void Context::applyTextures()
applyTexture(samplerIndex, texture); applyTexture(samplerIndex, texture);
GLenum texFormat = texture->getFormat(GL_TEXTURE_2D, 0); if(texEnvMode != GL_COMBINE)
sw::TextureStage::StageOperation rgbOperation, alphaOperation; {
es2sw::ConvertTextureOperations(texEnvMode, texFormat, &rgbOperation, &alphaOperation); GLenum texFormat = texture->getFormat(GL_TEXTURE_2D, 0);
device->setStageOperation(samplerIndex, rgbOperation); device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); // Cs
device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR);
device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setSecondArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); // Cp
device->setSecondArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setSecondModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR);
device->setSecondModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setThirdArgument(samplerIndex, sw::TextureStage::SOURCE_CONSTANT); // Cc
device->setThirdModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR);
device->setStageOperationAlpha(samplerIndex, alphaOperation);
device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_TEXTURE); // As
device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA);
device->setSecondArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setSecondArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); // Ap
device->setSecondModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setSecondModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA);
device->setThirdArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CONSTANT); // Ac
device->setThirdModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA);
switch(texEnvMode)
{
case GL_REPLACE:
switch(texFormat)
{
case GL_ALPHA:
// Cv = Cp, Av = As
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
break;
case GL_LUMINANCE:
case GL_RGB:
// Cv = Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
// Cv = Cs, Av = As
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
break;
default: UNREACHABLE();
}
break;
case GL_MODULATE:
switch(texFormat)
{
case GL_ALPHA:
// Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
case GL_LUMINANCE:
case GL_RGB:
// Cv = CpCs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_MODULATE);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
// Cv = CpCs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_MODULATE);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
default: UNREACHABLE();
}
break;
case GL_DECAL:
switch(texFormat)
{
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
// undefined
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
break;
case GL_RGB:
// Cv = Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
case GL_RGBA:
// Cv = Cp(1 ? As) + CsAs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_BLENDTEXTUREALPHA); // Alpha * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
break;
default: UNREACHABLE();
}
break;
case GL_BLEND:
switch(texFormat)
{
case GL_ALPHA:
// Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
case GL_LUMINANCE:
case GL_RGB:
// Cv = Cp(1 ? Cs) + CcCs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
// Cv = Cp(1 ? Cs) + CcCs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_LERP); // Arg3 * (Arg1 - Arg2) + Arg2
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
default: UNREACHABLE();
}
break;
case GL_ADD:
switch(texFormat)
{
case GL_ALPHA:
// Cv = Cp, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
case GL_LUMINANCE:
case GL_RGB:
// Cv = Cp + Cs, Av = Ap
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_ADD);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG2);
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
// Cv = Cp + Cs, Av = ApAs
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_ADD);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_MODULATE);
break;
default: UNREACHABLE();
}
break;
default:
UNREACHABLE();
}
}
else // GL_COMBINE
{
}
} }
else else
{ {
applyTexture(samplerIndex, 0); applyTexture(samplerIndex, 0);
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT);
device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR); device->setFirstModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR);
device->setSecondArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setSecondModifier(samplerIndex, sw::TextureStage::MODIFIER_COLOR);
device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setFirstArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT);
device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA); device->setFirstModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA);
device->setSecondArgumentAlpha(samplerIndex, sw::TextureStage::SOURCE_CURRENT); device->setStageOperationAlpha(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setSecondModifierAlpha(samplerIndex, sw::TextureStage::MODIFIER_ALPHA);
} }
} }
} }
......
...@@ -399,59 +399,6 @@ namespace es2sw ...@@ -399,59 +399,6 @@ namespace es2sw
default: UNREACHABLE(); return sw::FORMAT_A8B8G8R8; default: UNREACHABLE(); return sw::FORMAT_A8B8G8R8;
} }
} }
void ConvertTextureOperations(GLenum texEnvMode, GLenum texFormat, sw::TextureStage::StageOperation *rgbOperation, sw::TextureStage::StageOperation *alphaOperation)
{
switch(texEnvMode)
{
case GL_MODULATE:
switch(texFormat)
{
case GL_LUMINANCE_ALPHA:
*rgbOperation = sw::TextureStage::STAGE_MODULATE;
*alphaOperation = sw::TextureStage::STAGE_MODULATE;
break;
case GL_RGB:
*rgbOperation = sw::TextureStage::STAGE_MODULATE;
*alphaOperation = sw::TextureStage::STAGE_SELECTARG2;
break;
case GL_RGBA:
*rgbOperation = sw::TextureStage::STAGE_MODULATE;
*alphaOperation = sw::TextureStage::STAGE_MODULATE;
break;
case GL_ALPHA:
case GL_LUMINANCE:
UNIMPLEMENTED();
// Default operations for compatibility
*rgbOperation = sw::TextureStage::STAGE_MODULATE;
*alphaOperation = sw::TextureStage::STAGE_MODULATE;
break;
default: UNREACHABLE();
}
break;
case GL_REPLACE:
*rgbOperation = sw::TextureStage::STAGE_SELECTARG1;
*alphaOperation = sw::TextureStage::STAGE_SELECTARG1;
break;
case GL_ADD:
*rgbOperation = sw::TextureStage::STAGE_ADD;
*alphaOperation = sw::TextureStage::STAGE_SELECTARG1;
break;
case GL_DECAL:
case GL_BLEND:
// Default operations for compatibility
*rgbOperation = sw::TextureStage::STAGE_MODULATE;
*alphaOperation = sw::TextureStage::STAGE_MODULATE;
UNIMPLEMENTED();
break;
default:
UNREACHABLE();
}
}
} }
namespace sw2es namespace sw2es
......
...@@ -55,7 +55,6 @@ namespace es2sw ...@@ -55,7 +55,6 @@ namespace es2sw
void ConvertMinFilter(GLenum texFilter, sw::FilterType *minFilter, sw::MipmapType *mipFilter, float maxAnisotropy); void ConvertMinFilter(GLenum texFilter, sw::FilterType *minFilter, sw::MipmapType *mipFilter, float maxAnisotropy);
bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, es1::PrimitiveType &swPrimitiveType, int &primitiveCount); bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, es1::PrimitiveType &swPrimitiveType, int &primitiveCount);
sw::Format ConvertRenderbufferFormat(GLenum format); sw::Format ConvertRenderbufferFormat(GLenum format);
void ConvertTextureOperations(GLenum texOperation, GLenum texFormat, sw::TextureStage::StageOperation *rgbOperation, sw::TextureStage::StageOperation *alphaOperation);
} }
namespace sw2es namespace sw2es
......
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