Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated: Witness changes to hlsl2glsl #19

Merged
merged 4 commits into from
Mar 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions hlslang/GLSLCodeGen/glslOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#define snprintf _snprintf
#endif

//ACS: some texture lookup types were deprecated after 1.20, and 1.40 won't accept them
bool UsePost120TextureLookups(ETargetVersion targetVersion) {
if(targetVersion<ETargetVersionCount) {
return (targetVersion>ETargetGLSL_120);
}
else {
return false;
}
}

void print_float (std::stringstream& out, float f)
{
Expand Down Expand Up @@ -296,6 +305,7 @@ void writeTex( const TString &name, TIntermAggregate *node, TGlslOutputTraverser
TBasicType sampler_type = (*nodes.begin())->getAsTyped()->getBasicType();
TString new_name;

//ACS: do we need to change these for 1.40? 1.20-style texture lookups should just not show up at all, right?
if (isShadowSampler(sampler_type)) {
if (name == "texture2D")
new_name = "shadow2D";
Expand Down Expand Up @@ -1346,6 +1356,7 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n
GlslFunction *current = goit->current;
std::stringstream& out = current->getActiveOutput();
int argCount = (int) node->getNodes().size();
bool usePost120TextureLookups = UsePost120TextureLookups(goit->m_TargetVersion);

if (node->getOp() == EOpNull)
{
Expand Down Expand Up @@ -1549,7 +1560,13 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n

case EOpTex2D:
if (argCount == 2)
writeTex( "texture2D", node, goit);
{
if(usePost120TextureLookups) {
writeTex( "texture", node, goit);
} else {
writeTex( "texture2D", node, goit);
}
}
else
{
current->addLibFunction(EOpTex2DGrad);
Expand All @@ -1558,7 +1575,11 @@ bool TGlslOutputTraverser::traverseAggregate( bool preVisit, TIntermAggregate *n
return false;

case EOpTex2DProj:
writeTex( "texture2DProj", node, goit);
if(usePost120TextureLookups) {
writeTex( "textureProj", node, goit);
} else {
writeTex( "texture2DProj", node, goit);
}
return false;

case EOpTex2DLod:
Expand Down
4 changes: 4 additions & 0 deletions hlslang/GLSLCodeGen/hlslLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const char* kTargetVersionStrings[ETargetVersionCount] = {
"", // ES 1.00
"", // 1.10
"#version 120\n", // 1.20
"#version 140\n", // 1.40
};


Expand Down Expand Up @@ -728,6 +729,9 @@ void HlslLinker::buildUniformsAndLibFunctions(const FunctionSet& calledFunctions
libFunctions.insert( referencedFunctions.begin(), referencedFunctions.end());
}

// std::unique only removes contiguous duplicates, so vector must be sorted to remove them all
std::sort(constants.begin(), constants.end());

// Remove duplicates
constants.resize(std::unique(constants.begin(), constants.end()) - constants.begin());
}
Expand Down
Loading