Exemple #1
0
IShader* WINAPI QERApp_Shader_ForName(const char* name)
{
	//++timo FIXME: do we allow NULL and "" calling?
	// how does it deal with notexture? can we simply replace by "textures/radiant/notex"?
	if (name == NULL || strlen(name) == 0)
	{
		Sys_Printf("FIXME: name == NULL || strlen(name) == 0 in QERApp_Shader_ForName\n");
		return QERApp_Shader_ForName("radiant/notex"); //++timo ???
	}

	// entities that should be represented with plain colors instead of textures
	// request a texture name with (r g b) (it's stored in their class_t)
	if (name[0]=='(')
	{
		return QERApp_ColorShader_ForName(name);
	}

	CShader* pShader = static_cast<CShader*>(QERApp_Try_Shader_ForName( name ));
	if (pShader)
	{
		pShader->SetDisplayed( true );
		return pShader;
	}
	// we don't know this shader, maybe it's a straight texture 
	pShader = new CShader;
	pShader->CreateDefault( name );
  // hook it into the shader list
	g_Shaders.Add( (LPVOID)pShader );
	pShader->IncRef();
	// if it can't find the texture, "textures/radiant/notex" will be used
  pShader->Activate();
  pShader->SetDisplayed( true );
	return pShader;
}
Exemple #2
0
IShader *WINAPI QERApp_ColorShader_ForName( const char *name ){
	CShader *pShader = new CShader();
	pShader->CreateColor( name );
	// hook it into the shader list
	pShader->IncRef();
	g_Shaders.Add( (void *) pShader );
	return pShader;
}
Exemple #3
0
void WINAPI QERApp_LoadShaderFile (const char* filename)
{
	char* pBuff = NULL;
	int nSize = LoadFile(filename, reinterpret_cast<void**>(&pBuff));
	if (nSize == -1)
		nSize = PakLoadAnyFile(filename, reinterpret_cast<void**>(&pBuff));
	if (nSize > 0)
	{
		Sys_Printf("Parsing shaderfile %s\n", filename);
		StartTokenParsing(pBuff);
		while (GetToken(true))
		{
			// first token should be the path + name.. (from base)
			CShader *pShader = new CShader();
			// we want the relative filename only, it's easier for later lookup .. see QERApp_ReloadShaderFile
			char cTmp[1024];
			QE_ConvertDOSToUnixName( cTmp, filename );
			pShader->setShaderFileName( filename + strlen(ValueForKey(g_qeglobals.d_project_entity, "basepath")) + 1);
			if (pShader->Parse())
			{
				// do we already have this shader?
				//++timo NOTE: this may a bit slow, we may need to use a map instead of a dumb list
				if (g_Shaders.Shader_ForName( pShader->getName() ) != NULL)
				{
					Sys_Printf( "WARNING: shader %s is already in memory, definition in %s ignored.\n", pShader->getName(), filename );
					delete pShader;
				}
				else
				{
					pShader->IncRef();
					g_Shaders.Add( (LPVOID)pShader );
					int n = g_PrefsDlg.m_nShader;
					if ((g_PrefsDlg.m_nShader == CPrefsDlg::SHADER_ALL) || (g_PrefsDlg.m_nShader == CPrefsDlg::SHADER_COMMON && strstr(pShader->getName(), "common" )))
						// load the qtexture and display in tex wnd
						pShader->Activate();
				}
			}
			else
			{
				Sys_Printf("Error parsing shader %s\n", pShader->getName());
				delete pShader;
			}			
		}
		free (pBuff);
	}
	else
	{
		Sys_Printf("Unabled to read shaderfile %s\n", filename);
	}	
}
Exemple #4
0
void WINAPI QERApp_LoadShaderFile (const char *filename)
{
  char *pBuff;
  int nSize = vfsLoadFile (filename, reinterpret_cast < void **>(&pBuff), 0);
  if (nSize > 0)
  {
    Sys_Printf ("Parsing shaderfile %s\n", filename);
    g_ScripLibTable.m_pfnStartTokenParsing (pBuff);
    while (g_ScripLibTable.m_pfnGetToken (true))
    {
      // first token should be the path + name.. (from base)
      CShader *pShader = new CShader ();
      // we want the relative filename only, it's easier for later lookup .. see QERApp_ReloadShaderFile
      char cTmp[1024];
      g_FuncTable.m_pfnQE_ConvertDOSToUnixName (cTmp, filename);
      // given the vfs, we should not store the full path
      //pShader->setShaderFileName( filename + strlen(ValueForKey(g_qeglobals.d_project_entity, "basepath")));
      pShader->setShaderFileName (filename);
      if (pShader->Parse ())
      {
	      // do we already have this shader?
	      //++timo NOTE: this may a bit slow, we may need to use a map instead of a dumb list
	      if (g_Shaders.Shader_ForName (pShader->getName ()) != NULL)
	      {
#ifdef _DEBUG
	        Sys_Printf ("WARNING: shader %s is already in memory, definition in %s ignored.\n",
		            pShader->getName (), filename);
#endif
	        delete pShader;
	      }
	      else
	      {
	        pShader->IncRef ();

	        g_Shaders.Add ((void *) pShader);
	      }
      }
      else
      {
	      Sys_Printf ("Error parsing shader %s\n", pShader->getName ());
	      delete pShader;
      }
    }
    vfsFreeFile (pBuff);
  }
  else
  {
    Sys_Printf ("Unable to read shaderfile %s\n", filename);
  }
}
Exemple #5
0
IShader *WINAPI QERApp_CreateShader_ForTextureName( const char *name ){
	CShader *pShader;
	pShader = new CShader;
	// CreateDefault expects a texture / shader name relative to the "textures" directory
	// (cause shader names are reletive to "textures/")
	pShader->CreateDefault( name );
	// hook it into the shader list
	g_Shaders.Add( (void *) pShader );
	pShader->IncRef();
	// if it can't find the texture, SHADER_NOT_FOUND will be used
	// Hydra: display an error message, so the user can quickly find a list of missing
	// textures by looking at the console.
	if ( !pShader->Activate() ) {
		Sys_Printf( "WARNING: Activate shader failed for %s\n",pShader->getName() );
	}
	pShader->SetDisplayed( true );

	return pShader;
}