Esempio n. 1
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;
}
Esempio n. 2
0
static std::string GenVertexShader( shaderStage_t& stage,
									const std::string& texCoordName,
									std::vector< std::string >& attribs )
{

	size_t vertTransferOffset = 3;
	size_t vertAttrOffset = 2;

	uint32_t attribLocCounter = 0;

	// Vertex shader...
	// if we're not using core the last args for both the attribute and transfer
	// decl funcs won't be written; they'll likely just get optimized away
	std::vector< std::string > vertexSrc =
	{
		DeclAttributeVar( "position", "vec3", attribLocCounter++ ),
		texCoordName.empty() ? "" : DeclAttributeVar( texCoordName, "vec2", attribLocCounter++ ),
		DeclTransferVar( "frag_Tex", "vec2", "out" ),
		DeclCoreTransforms(),
		"void main(void) {",
	};

	if ( stage.tcgen == TCGEN_ENVIRONMENT )
	{
		vertexSrc.insert( vertexSrc.begin() + vertAttrOffset++,
			DeclAttributeVar( "normal", "vec3", attribLocCounter++ ) );
		attribs.push_back( "normal" );
	}

	vertexSrc.push_back(
		"\tgl_Position = viewToClip * modelToView * vec4( position, 1.0 );" );

	if ( stage.tcgen == TCGEN_ENVIRONMENT )
	{
		AddCalcEnvMap( vertexSrc, "position", "normal",
			"vec3( -modelToView[ 3 ] )" );
		vertexSrc.push_back( "\tfrag_Tex = st;" );
	}
	else
	{
		vertexSrc.push_back( "\tfrag_Tex = " + texCoordName + ";" );
	}

	if ( UsesColor( stage ) )
	{
		vertexSrc.insert( vertexSrc.begin() + vertAttrOffset++,
			DeclAttributeVar( "color", "vec4", attribLocCounter++ ) );
		vertexSrc.insert( vertexSrc.begin() + vertTransferOffset++,
			DeclTransferVar( "frag_Color", "vec4", "out" ) );
		vertexSrc.push_back( "\tfrag_Color = color;" );
		attribs.push_back( "color" );
	}

	return JoinLines( vertexSrc );
}
Esempio n. 3
0
//! JoinLines function call will append
//! the ending bracket for the main function,
//! so we don't have to worry about it here.
std::string GMakeMainVertexShader( void )
{
	std::vector< std::string > sourceLines =
	{
		DeclAttributeVar( "position", "vec3", 0 ),
		DeclAttributeVar( "tex0", "vec2", 1 ),
		DeclAttributeVar( "lightmap", "vec2", 2 ),
		DeclAttributeVar( "color", "vec4", 3 ),
		DeclTransferVar( "frag_Color", "vec4", "out" ),
		DeclTransferVar( "frag_Tex", "vec2", "out" ),
		DeclTransferVar( "frag_Lightmap", "vec2", "out" ),
		DeclCoreTransforms(),
		"void main(void) {",
		"\tgl_Position = viewToClip * modelToView * vec4( position, 1.0 );",
		"\tfrag_Color = color;",
		"\tfrag_Lightmap = lightmap;",
		"\tfrag_Tex = tex0;"
	};

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

	return source;
}
Esempio n. 4
0
static std::string GenFragmentShader( shaderStage_t& stage,
							   std::vector< std::string >& uniforms )
{
	size_t fragTransferOffset = 2;
	size_t fragUnifOffset = 3;

	// Fragment shader....
	// Unspecified alphaGen implies a default 1.0 alpha channel
	std::vector< std::string > fragmentSrc =
	{
		DeclPrecision(),
		"const float gamma = 1.0 / 2.2;",
		DeclTransferVar( "frag_Tex", "vec2", "in" ),
#ifdef G_USE_GL_CORE
		DeclTransferVar( "fragment", "vec4", "out" ),
#endif
		"void main(void) {"
	};

	// Add our base image data
	std::initializer_list<std::string> data  =
	{
		"uniform sampler2D sampler0;",
		"uniform vec4 imageTransform;",
		"uniform vec2 imageScaleRatio;",
		"vec2 applyTransform(in vec2 coords) {",
		"\treturn coords * imageTransform.zw * imageScaleRatio + imageTransform.xy;",
		"}"
	};

	fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset, data );

	fragmentSrc.push_back( "\tvec2 st = frag_Tex;" );

	if ( UsesColor( stage ) )
	{
		fragmentSrc.insert( fragmentSrc.begin() + fragTransferOffset++,
			DeclTransferVar( "frag_Color", "vec4", "in" ) );
	}

	for ( const effect_t& op: stage.effects )
	{
		// Modify the texture coordinate as necessary before we write to the texture
		if ( op.name == "tcModTurb" )
		{
			fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset,
				"uniform float tcModTurb;" );
			fragmentSrc.push_back( "\tst *= tcModTurb;" );
			uniforms.push_back( "tcModTurb" );
		}
		else if ( op.name == "tcModScroll" )
		{
			fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset,
				"uniform vec4 tcModScroll;" );
			fragmentSrc.push_back( "\tst += tcModScroll.xy * tcModScroll.zw;" );
			uniforms.push_back( "tcModScroll" );
		}
		else if ( op.name == "tcModRotate" )
		{
			fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset,
				"uniform mat2 texRotate;" );
			fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset,
				"uniform vec2 texCenter;" );
			fragmentSrc.push_back( "\tst += texRotate * ( frag_Tex - texCenter );" );

			uniforms.push_back( "texRotate" );
			uniforms.push_back( "texCenter" );
		}
		else if ( op.name == "tcModScale" )
		{
			fragmentSrc.insert( fragmentSrc.begin() + fragUnifOffset,
				"uniform mat2 tcModScale;" );
			fragmentSrc.push_back( "\tst = tcModScale * st;" );
			uniforms.push_back( "tcModScale" );
		}
	}

	switch ( stage.alphaFunc )
	{
	case ALPHA_FUNC_UNDEFINED:
		WriteTexture( fragmentSrc, stage, nullptr );
		break;
	case ALPHA_FUNC_GEQUAL_128:
		WriteTexture( fragmentSrc, stage, "color.a < 0.5" );
		break;
	case ALPHA_FUNC_GTHAN_0:
		WriteTexture( fragmentSrc, stage, "color.a == 0" );
		break;
	case ALPHA_FUNC_LTHAN_128:
		WriteTexture( fragmentSrc, stage, "color.a >= 0.5" );
		break;
	}

	return JoinLines( fragmentSrc );
}
//@doc SECEdit
//@mfunc Internal function. Cuts the text from pStartPos to pEndPos.  Never deletes
//              pStartPos->pLine.
//@rdesc int 
//@parm PTEXTPOS pStartPos
//@parm  PTEXTPOS pEndPos
//@parm  BOOL bSaveUndoRecord
int SECEdit::Cut(PTEXTPOS pStartPos, PTEXTPOS pEndPos, BOOL bSaveUndoRecord)
   {
   int iRval;
   UNDORECORD UndoRecord;
   LPSTR lpText;
   PLINEDESC pFirstDeadLine,pNextDeadLine,pLastDeadLine;
   TEXTPOS TempPos;
	ASSERT(pStartPos);
	ASSERT(pEndPos);

   iRval = 0;

   if (m_bReadOnly)
      return IDS_OE_READONLY;

   if ((pStartPos->pLine == pEndPos->pLine) && 
		 (pStartPos->iOffset == pEndPos->iOffset))
      return IDS_OE_NOSELECTION;

   if ((pStartPos->pLine == NULL) || (pEndPos->pLine == NULL))
      return IDS_OE_NOSELECTION;

   // save the undo record
   if (bSaveUndoRecord)
      {
      UndoRecord.iRow    = GetLineNo(pStartPos->pLine);
		if (pStartPos->pLine == pEndPos->pLine)
			UndoRecord.iEndRow = UndoRecord.iRow;
		else
			UndoRecord.iEndRow = GetLineNo(pEndPos->pLine);
      UndoRecord.iCol    = pStartPos->iOffset;
      UndoRecord.iEndCol = pEndPos->iOffset;
      UndoRecord.iUndoType = OE_UNDO_CUT;
      lpText = Copy(pStartPos, pEndPos, FALSE);
      }

   if (pStartPos->pLine == pEndPos->pLine)
		{
      iRval = DeleteString(pStartPos, pEndPos->iOffset-pStartPos->iOffset, FALSE);
		}
   else
      {
      // lop the starting line off at iOffset
      if (pStartPos->iOffset < (pStartPos->pLine->iTxtSize-m_iLineEndLength))
         {
         pStartPos->pLine->pText[pStartPos->iOffset] = 0;
         pStartPos->pLine->iTxtSize = pStartPos->iOffset;
         }

      // delete the marked part of the last line
      if (pEndPos->iOffset > pEndPos->pLine->iTxtSize)
			{
			pEndPos->iOffset = pEndPos->pLine->iTxtSize;
         /* (maybe) adjust for OE_CR/OE_LF */
			char cFirst,cSecond;
			cFirst = pEndPos->pLine->pText[pEndPos->pLine->iTxtSize-m_iLineEndLength];
			cSecond = m_szLineEnd[0];
         if (cFirst == cSecond)
				{
	         pEndPos->iOffset -= m_iLineEndLength;
		      UndoRecord.iEndCol -= m_iLineEndLength;
				}
			}

      TempPos.pLine = pEndPos->pLine;
      TempPos.iOffset = 0;
      iRval = DeleteString(&TempPos, pEndPos->iOffset, FALSE);

      // link the two together, and unlink the ones in between
      if ((!iRval) || (iRval == IDS_OE_JOINLINE))
         {
         if (pStartPos->pLine->pNext != pEndPos->pLine)
            {
            pFirstDeadLine = pStartPos->pLine->pNext;
				if (pEndPos->pLine)
					{
               pLastDeadLine = pEndPos->pLine->pPrev;
	            pEndPos->pLine->pPrev = pStartPos->pLine;
					}
				else
					pLastDeadLine = NULL;
            pStartPos->pLine->pNext = pEndPos->pLine;
				if (pLastDeadLine)
               pLastDeadLine->pNext = NULL;
            while (pFirstDeadLine)
               {
               pNextDeadLine = pFirstDeadLine->pNext;
               FreeTextLine(pFirstDeadLine);
               pFirstDeadLine = pNextDeadLine;
               }
            }
         // join the chopped start with the chopped end
         iRval = JoinLines(pStartPos, FALSE);
			if (iRval == IDS_OE_EOF)
				iRval = 0;
         }
      }

   if (!iRval)
      {
      if (bSaveUndoRecord)
			{
         SaveUndoRecord(&UndoRecord,lpText);
		   free(lpText);
			}

      // set the changed flag
      SetModified(TRUE);
      }

   return iRval;
   }