예제 #1
0
void JsnWriter::EndArray( JsnHandler* byoc )
{
  WriteFragment( m_Style->m_NewlineString );
  WriteIndent();
  WriteFragment( "]" );
  delete byoc;
}
예제 #2
0
void JsnWriter::WriteProperty( const JsnFragment& name, const JsnFragment& value )
{
  if( m_IndentLevel )
  {
    if( m_ValueCount )
    {
      WriteFragment( "," );
    }
    WriteFragment( m_Style->m_NewlineString );
    WriteIndent();
  }
  if( name.m_Length )
  {
    WriteFragmentString( name );
    WriteFragment( ":" );
    WriteFragment( m_Style->m_SpaceAfterColonString );
  }
  if( value.m_Type == kJsn_String )
  {
    WriteFragmentString( value );
  }
  else
  {
    WriteFragment( value );
  }
  m_ValueCount += 1;
}
예제 #3
0
void JsnWriter::EndObject( JsnHandler* byoc )
{
  WriteFragment( m_Style->m_NewlineString );
  WriteIndent();
  WriteFragment( "}" );
  if( !m_IndentLevel )
  {
    WriteFragment( m_Style->m_NewlineString );
  }
  delete byoc;
}
예제 #4
0
std::string GMakeMainFragmentShader( void )
{
	std::vector< std::string > sourceLines =
	{
		DeclPrecision(),
		DeclGammaConstant(),
		DeclTransferVar( "frag_Color", "vec4", "in" ),
		DeclTransferVar( "frag_Tex", "vec2", "in" ),
		DeclTransferVar( "frag_Lightmap", "vec2", "in" ),
		"uniform sampler2D mainImageSampler;",
		"uniform vec2 mainImageImageScaleRatio;",
		"uniform vec4 mainImageImageTransform;",
		"uniform sampler2D lightmapSampler;",
		"uniform vec2 lightmapImageScaleRatio;",
		"uniform vec4 lightmapImageTransform;",
#ifdef G_USE_GL_CORE
		DeclTransferVar( "fragment", "vec4", "out" ),
#endif
		"void main(void) {",
		"\tvec2 texCoords;",
		"\tvec4 image, lightmap, color;",
		SampleFromTexture( "texCoords", "image", "frag_Tex",
			"mainImageSampler", "mainImageImageScaleRatio", "mainImageImageTransform" ),
		SampleFromTexture( "texCoords", "lightmap", "frag_Lightmap",
			"lightmapSampler", "lightmapImageScaleRatio", "lightmapImageTransform" ),
		"\tcolor = frag_Color * image * lightmap;",
		GammaCorrect( "color" ),
		WriteFragment( "color" )
	};

	std::string source( JoinLines( sourceLines ) );

	return source;
}
예제 #5
0
void JsnWriter::WriteIndent()
{
  for( int i = 0; i < m_IndentLevel; ++i )
  {
    WriteFragment( m_Style->m_IndentString );
  }
}
예제 #6
0
static INLINE void WriteTexture(
		std::vector< std::string >& fragmentSrc,
		const shaderStage_t& stage,
		const char* discardPredicate )
{
	std::string sampleTextureExpr;

	if ( stage.mapCmd == MAP_CMD_CLAMPMAP )
	{
		fragmentSrc.push_back( "\tst = clamp( applyTransform( st )," \
			 "imageTransform.xy, applyTransform( vec2( 0.99 ) ) );" );
	}
	else
	{
		fragmentSrc.push_back(
			"\tst = applyTransform( mod( st, vec2( 0.99 ) ) );" );
	}

	sampleTextureExpr = SampleTexture2D( "sampler0", "st" );

	std::stringstream colorAssign;

	colorAssign << "\tvec4 color = ";

	// Some shader entries will incorporate specific alpha values
	if ( stage.alphaGen != 0.0f )
	{
		fragmentSrc.push_back(
			"\tconst float alphaGen = "
			+ std::to_string( stage.alphaGen )
			+ std::to_string( ';' ) );

		colorAssign << sampleTextureExpr << ".rgb, alphaGen )";

		if ( UsesColor( stage ) )
		{
			 colorAssign << " * vec4( frag_Color.rgb, alphaGen )";
		}
	}
	else
	{
		colorAssign << sampleTextureExpr;

		if ( UsesColor( stage ) )
		{
			colorAssign <<  " * frag_Color";
		}
	}

	colorAssign << ";";

	fragmentSrc.push_back( colorAssign.str() );

	// Is used occasionally, for example in situations like a bad alpha value.
	if ( discardPredicate )
		AddDiscardIf( fragmentSrc, std::string( discardPredicate ) );

	// Gamma correction
	fragmentSrc.insert( fragmentSrc.end(), GammaCorrect( "color" ) );

	fragmentSrc.push_back( "\t" + WriteFragment( "color" ) );
}