Merge pull request #933 from BeamNG/shadergen_glsl

Changes on ShaderGen for generate GLSL shaders.
This commit is contained in:
LuisAntonRebollo 2014-11-30 02:22:58 +01:00
commit 82315a9960
4 changed files with 20 additions and 18 deletions

View file

@ -203,7 +203,7 @@ void ShaderConnectorHLSL::reset()
mCurTexElem = 0;
}
void ShaderConnectorHLSL::print( Stream &stream )
void ShaderConnectorHLSL::print( Stream &stream, bool isVertexShader )
{
const char * header = "struct ";
const char * header2 = "\r\n{\r\n";
@ -269,7 +269,7 @@ void ParamsDefHLSL::assignConstantNumbers()
}
}
void VertexParamsDefHLSL::print( Stream &stream )
void VertexParamsDefHLSL::print( Stream &stream, bool isVerterShader )
{
assignConstantNumbers();
@ -305,7 +305,7 @@ void VertexParamsDefHLSL::print( Stream &stream )
stream.write( dStrlen(closer), closer );
}
void PixelParamsDefHLSL::print( Stream &stream )
void PixelParamsDefHLSL::print( Stream &stream, bool isVerterShader )
{
assignConstantNumbers();
@ -326,18 +326,18 @@ void PixelParamsDefHLSL::print( Stream &stream )
if( var->sampler )
{
dSprintf( (char*)varNum, sizeof(varNum), "register(S%d)", var->constNum );
dSprintf( (char*)varNum, sizeof(varNum), ": register(S%d)", var->constNum );
}
else
{
dSprintf( (char*)varNum, sizeof(varNum), "register(C%d)", var->constNum );
dSprintf( (char*)varNum, sizeof(varNum), ": register(C%d)", var->constNum );
}
U8 output[256];
if (var->arraySize <= 1)
dSprintf( (char*)output, sizeof(output), "uniform %-9s %-15s : %s", var->type, var->name, varNum );
dSprintf( (char*)output, sizeof(output), "uniform %-9s %-15s %s", var->type, var->name, varNum );
else
dSprintf( (char*)output, sizeof(output), "uniform %-9s %s[%d] : %s", var->type, var->name, var->arraySize, varNum );
dSprintf( (char*)output, sizeof(output), "uniform %-9s %s[%d] %s", var->type, var->name, var->arraySize, varNum );
WRITESTR( (char*) output );
}

View file

@ -45,7 +45,7 @@ public:
virtual void reset();
virtual void sortVars();
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVertexShader );
};
@ -59,14 +59,14 @@ protected:
class VertexParamsDefHLSL : public ParamsDefHLSL
{
public:
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
};
class PixelParamsDefHLSL : public ParamsDefHLSL
{
public:
virtual void print( Stream &stream );
virtual void print( Stream &stream, bool isVerterShader );
};
#endif // _SHADERCOMP_HLSL_H_

View file

@ -43,7 +43,8 @@ class ShaderComponent
public:
virtual ~ShaderComponent() {}
virtual void print( Stream &stream ){};
virtual void print( Stream &stream, bool isVerterShader ){};
virtual void printOnMain( Stream &stream, bool isVerterShader ){};
};
@ -86,7 +87,7 @@ public:
virtual void reset() = 0;
virtual void sortVars() = 0;
virtual void print( Stream &stream ) = 0;
virtual void print( Stream &stream, bool isVerterShader ) = 0;
};
/// This is to provide common functionalty needed by vertex and pixel main defs

View file

@ -409,13 +409,13 @@ void ShaderGen::_printVertShader( Stream &stream )
_printFeatureList(stream);
// print out structures
mComponents[C_VERT_STRUCT]->print( stream );
mComponents[C_CONNECTOR]->print( stream );
mComponents[C_VERT_STRUCT]->print( stream, true );
mComponents[C_CONNECTOR]->print( stream, true );
mPrinter->printMainComment(stream);
mComponents[C_VERT_MAIN]->print( stream );
mComponents[C_VERT_MAIN]->print( stream, true );
mComponents[C_VERT_STRUCT]->printOnMain( stream, true );
// print out the function
_printFeatures( stream );
@ -430,12 +430,13 @@ void ShaderGen::_printPixShader( Stream &stream )
_printDependencies(stream); // TODO: Split into vert and pix dependencies?
_printFeatureList(stream);
mComponents[C_CONNECTOR]->print( stream );
mComponents[C_CONNECTOR]->print( stream, false );
mPrinter->printPixelShaderOutputStruct(stream, mFeatureData);
mPrinter->printMainComment(stream);
mComponents[C_PIX_MAIN]->print( stream );
mComponents[C_PIX_MAIN]->print( stream, false );
mComponents[C_CONNECTOR]->printOnMain( stream, false );
// print out the function
_printFeatures( stream );