Implemented basic GLSL ES 3.0 texture intrinsics.

TRAC #22954 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2273 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 96e7ba17
......@@ -363,6 +363,43 @@ static TString BuiltInFunctionsCommonTexture1_0(const ShBuiltInResources& resour
return s;
}
static TString BuiltInFunctionsCommonTexture3_0()
{
TString s;
//
// Texture Functions for GLSL ES 3.0
//
s.append(TString("vec4 texture(sampler2D sampler, vec2 coord);"));
s.append(TString("vec4 texture(samplerCube sampler, vec3 coord);"));
s.append(TString("vec4 textureProj(sampler2D sampler, vec3 coord);"));
s.append(TString("vec4 textureProj(sampler2D sampler, vec4 coord);"));
return s;
}
static TString BuiltInFunctionsFragmentGradient3_0()
{
TString s;
s.append(TString("float dFdx(float p);"));
s.append(TString("vec2 dFdx(vec2 p);"));
s.append(TString("vec3 dFdx(vec3 p);"));
s.append(TString("vec4 dFdx(vec4 p);"));
s.append(TString("float dFdy(float p);"));
s.append(TString("vec2 dFdy(vec2 p);"));
s.append(TString("vec3 dFdy(vec3 p);"));
s.append(TString("vec4 dFdy(vec4 p);"));
s.append(TString("float fwidth(float p);"));
s.append(TString("vec2 fwidth(vec2 p);"));
s.append(TString("vec3 fwidth(vec3 p);"));
s.append(TString("vec4 fwidth(vec4 p);"));
return s;
}
//============================================================================
//
// Prototypes for built-in functions seen by vertex shaders only.
......@@ -517,6 +554,8 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
commonBuiltIns.push_back(BuiltInFunctionsCommon());
essl1BuiltIns.push_back(BuiltInFunctionsCommonTexture1_0(resources));
essl1BuiltIns.push_back(BuiltInFunctionsFragmentTexture1_0(resources));
essl3BuiltIns.push_back(BuiltInFunctionsCommonTexture3_0());
essl3BuiltIns.push_back(BuiltInFunctionsFragmentGradient3_0());
commonBuiltIns.push_back(StandardUniforms());
break;
......@@ -525,6 +564,7 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
commonBuiltIns.push_back(BuiltInFunctionsCommon());
essl1BuiltIns.push_back(BuiltInFunctionsCommonTexture1_0(resources));
essl1BuiltIns.push_back(BuiltInFunctionsVertexTexture1_0());
essl3BuiltIns.push_back(BuiltInFunctionsCommonTexture3_0());
commonBuiltIns.push_back(StandardUniforms());
break;
......@@ -634,13 +674,17 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
break;
case SH_FRAGMENT_SHADER:
if (resources.OES_standard_derivatives) {
symbolTable.relateToOperator(COMMON_BUILTINS, "dFdx", EOpDFdx);
symbolTable.relateToOperator(COMMON_BUILTINS, "dFdy", EOpDFdy);
symbolTable.relateToOperator(COMMON_BUILTINS, "fwidth", EOpFwidth);
symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx);
symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy);
symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
symbolTable.relateToExtension(COMMON_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
symbolTable.relateToExtension(COMMON_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
symbolTable.relateToExtension(COMMON_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx", EOpDFdx);
symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy", EOpDFdy);
symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth);
}
break;
default: break;
......
......@@ -1775,6 +1775,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
{
TString name = TFunction::unmangleName(node->getName());
bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function;
TIntermSequence &arguments = node->getSequence();
if (node->isUserDefined())
{
......@@ -1782,15 +1783,17 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else
{
if (name == "texture2D")
TBasicType samplerType = arguments[0]->getAsTyped()->getType().getBasicType();
if (name == "texture2D" || (name == "texture" && samplerType == EbtSampler2D))
{
if (!lod0)
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTexture2D = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTexture2D_bias = true;
}
......@@ -1800,11 +1803,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTexture2DLod0 = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTexture2DLod0_bias = true;
}
......@@ -1813,15 +1816,15 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_texture2DLod0(";
}
}
else if (name == "texture2DProj")
else if (name == "texture2DProj" || (name == "textureProj" && samplerType == EbtSampler2D))
{
if (!lod0)
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTexture2DProj = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTexture2DProj_bias = true;
}
......@@ -1831,11 +1834,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTexture2DProjLod0 = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTexture2DProjLod0_bias = true;
}
......@@ -1844,15 +1847,15 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_texture2DProjLod0(";
}
}
else if (name == "textureCube")
else if (name == "textureCube" || (name == "texture" && samplerType == EbtSamplerCube))
{
if (!lod0)
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTextureCube = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTextureCube_bias = true;
}
......@@ -1862,11 +1865,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else
{
if (node->getSequence().size() == 2)
if (arguments.size() == 2)
{
mUsesTextureCubeLod0 = true;
}
else if (node->getSequence().size() == 3)
else if (arguments.size() == 3)
{
mUsesTextureCubeLod0_bias = true;
}
......@@ -1875,9 +1878,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_textureCubeLod0(";
}
}
else if (name == "texture2DLod")
else if (name == "texture2DLod" || (name == "textureLod" && samplerType == EbtSampler2D))
{
if (node->getSequence().size() == 3)
if (arguments.size() == 3)
{
mUsesTexture2DLod = true;
}
......@@ -1885,9 +1888,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_texture2DLod(";
}
else if (name == "texture2DProjLod")
else if (name == "texture2DProjLod" || (name == "textureProjLod" && samplerType == EbtSampler2D))
{
if (node->getSequence().size() == 3)
if (arguments.size() == 3)
{
mUsesTexture2DProjLod = true;
}
......@@ -1895,9 +1898,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << "gl_texture2DProjLod(";
}
else if (name == "textureCubeLod")
else if (name == "textureCubeLod" || (name == "textureLod" && samplerType == EbtSamplerCube))
{
if (node->getSequence().size() == 3)
if (arguments.size() == 3)
{
mUsesTextureCubeLod = true;
}
......@@ -1907,9 +1910,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else UNREACHABLE();
}
TIntermSequence &arguments = node->getSequence();
for (TIntermSequence::iterator arg = arguments.begin(); arg != arguments.end(); arg++)
{
if (mOutputType == SH_HLSL11_OUTPUT && IsSampler((*arg)->getAsTyped()->getBasicType()))
......
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