예제 #1
0
void DBTexture::loadFromFile(const eastl::string& a_filePath, EFormat a_format, uint a_forcedNumComp)
{
	int w, h, c;
	byte* textureData = NULL;

	switch (a_format)
	{
	case EFormat::BYTE:  textureData = stbi_load(a_filePath.c_str(), &w, &h, &c, a_forcedNumComp); break;
	case EFormat::FLOAT: textureData = rcast<byte*>(stbi_loadf(a_filePath.c_str(), &w, &h, &c, a_forcedNumComp)); break;
	default: assert(false); break;
	}
	if (!textureData)
	{
		print("FAILED TO LOAD IMAGE: %s \n", a_filePath.c_str());
		assert(false);
		return;
	}

	m_format = a_format;
	m_pixColSize = getPixColSize(m_format);
	m_width = uint(w);
	m_height = uint(h);
	m_numComp = a_forcedNumComp ? a_forcedNumComp : uint(c); // If a number of components was forced, use that, otherwise use the number of components in the image.

	const uint dataSize = m_width * m_height * m_numComp * m_pixColSize;
	m_rawData.resize(dataSize);
	memcpy(m_rawData.data(), textureData, dataSize);
	stbi_image_free(textureData);

	m_compressedDataUpToDate = false;
}
예제 #2
0
	void WriteTime(int64_t timeNS, eastl::string& sTime)
	{
		if(timeNS > 1000000000)
			sTime.sprintf(" %6.2f s",  (double)timeNS / 1000000000);
		else if(timeNS > 1000000)
			sTime.sprintf("%6.1f ms", (double)timeNS / 1000000);
		else if(timeNS > 1000)
			sTime.sprintf("%6.1f us", (double)timeNS / 1000);
		else
			sTime.sprintf("%6.1f ns", (double)timeNS / 1);
	}
예제 #3
0
	void UProgramPermutor::PermuteProgram(const eastl::string& inProgramFilePath, ProgramPermutations_t& outProgramPermutations, bool inShouldGenPermutationFiles)
	{
		std::ifstream programInputStream(inProgramFilePath.c_str(), std::ios::in | std::ios::ate);

		if (programInputStream.is_open())
		{
			std::string stdProgramStringBuffer;

			eastl::vector<SShaderMetaFlagInstance>						programMetaFlagInstances;
			eastl::vector<SShaderUsageDescription>						programUsageDescriptions;
			eastl::vector<SShaderPermuteDescription>						programPermutationDescriptions;

			stdProgramStringBuffer.resize(programInputStream.tellg());

			programInputStream.seekg(std::ios::beg);
			
			stdProgramStringBuffer.assign(std::istream_iterator<char>(programInputStream), std::istream_iterator<char>());

			eastl::string programStringBuffer(eastl::move(stdProgramStringBuffer.c_str()));

			// Accumulate all of the meta flag instances in the program file
			ParseProgramMetaFlags(programStringBuffer, programMetaFlagInstances);

			// Go through all meta flags and retrieve the Usage and Permute meta flag instances
			for (const auto& currentMetaFlagInst : programMetaFlagInstances)
			{
				switch (currentMetaFlagInst.MetaFlagType)
				{
					case EMetaFlagType::EMetaFlagType_Usage:
					{
						//LOG(LogProgramPermutor, Log, "Adding meta usage flag with values: %s - %s\n", currentMetaFlagInst.MetaFlagValues[0].c_str(), currentMetaFlagInst.MetaFlagValues[1].c_str());

						programUsageDescriptions.push_back({ currentMetaFlagInst.MetaFlagValues[0], currentMetaFlagInst.MetaFlagValues[1] });
						break;
					}
					case EMetaFlagType::EMetaFlagType_Permute:
					{
						EProgramIdMask permuteIdMask = UProgramPermutor::ConvertStringToPIDMask(currentMetaFlagInst.MetaFlagValues[0]);

						if (permuteIdMask != EProgramIdMask::INVALID)
						{
							//LOG(LogProgramPermutor, Log, "Adding meta permute flag with define: %s\n", currentMetaFlagInst.MetaFlagValues[0].c_str());
							programPermutationDescriptions.push_back({ permuteIdMask });
						}
						else
						{
							LOG(LogProgramPermutor, Error, "Error: Invalid permute flag: %s\n", currentMetaFlagInst.MetaFlagValues[0].c_str());

						}
						break;
					}	
				}
			}

			// The usage descriptions tell us which parts of the program to include in the shader permutation sets
			GeneratePermutations(inProgramFilePath, programUsageDescriptions, programPermutationDescriptions, outProgramPermutations, inShouldGenPermutationFiles);
		}
	}
예제 #4
0
String::String(const eastl::string &s, Type t)
{
  d = new StringPrivate;

  if(t == UTF16 || t == UTF16BE || t == UTF16LE) {
    debug("String::String() -- A eastl::string should not contain UTF16.");
    return;
  }

  int length = s.length();
  d->data.resize(length);
  wstring::iterator targetIt = d->data.begin();

  for(eastl::string::const_iterator it = s.begin(); it != s.end(); it++) {
    *targetIt = uchar(*it);
    ++targetIt;
  }

  prepare(t);
}
예제 #5
0
	bool _VariableModifier_Type( eastl::string& str, const eastl::string& vname, const char* modifier, eastl::string& type )//是否为某种修饰类型的变量
	{
		size_t start_pos = 0;
		do 
		{
			start_pos = str.find( vname, start_pos );
			if ( start_pos != eastl::string::npos )
			{
				size_t trunk = str.find_last_of( ';', start_pos );
				trunk = trunk != eastl::string::npos ? trunk : 0;
				string substr = str.substr( trunk, start_pos - trunk );
				size_t istype = substr.find( modifier );
				if ( istype != eastl::string::npos )
				{
					type = substr.substr( substr.find_first_of(' ') );
					return true;
				}
				start_pos += vname.size();
			}
		} while ( start_pos != eastl::string::npos );
		return false;
	}
예제 #6
0
	// Utility functions to convert between meta flag type and string
	EProgramIdMask UProgramPermutor::ConvertStringToPIDMask(const eastl::string& inMaskString)
	{
		auto pidMaskStringFindIter = UProgramPermutor::s_programIdMaskToStringMap.find(inMaskString.c_str());

		if (pidMaskStringFindIter != UProgramPermutor::s_programIdMaskToStringMap.cend())
		{
			return pidMaskStringFindIter->second;
		}
		else
		{
			return EProgramIdMask::INVALID;
		}
	}
예제 #7
0
	void OpenGLGraphicSystem::ProcessShader( BohgeEngine::ShaderProperty::ShaderCode sc, eastl::string& code )
	{
		Utility::RemoveTargetString( code, "precision highp float;" );
		Utility::RemoveTargetString( code, "precision mediump float;" );
		Utility::RemoveTargetString( code, "precision lowp float;" );
		Utility::RemoveTargetString( code, "highp " );
		Utility::RemoveTargetString( code, "mediump " );
		Utility::RemoveTargetString( code, "lowp " );
		code.insert(0, "#define	MAXJOINTS	128\n" );
		code.insert(0, "#define	MAXARRAYSIZE	256\n" );
		code.insert(0, "#define	_WINDOWS_\n" );
		glslopt_shader_type type;
		switch( sc )
		{
		case ShaderProperty::SC_VERTEX: type = kGlslOptShaderVertex; break;
		case ShaderProperty::SC_FRAGMENT: type = kGlslOptShaderFragment; break;
		default:ASSERT(false);
		}

		glslopt_shader* shader = glslopt_optimize( m_pGlslopt_ctx, type, code.c_str(), 0 );
		if ( glslopt_get_status(shader) )
		{
			code = glslopt_get_output( shader );
		}
		else
		{
			const char* log = glslopt_get_log( shader );
			DEBUGLOG("Can't optimize shader, caz %s\n", log );
		}
		if ( ShaderProperty::SC_VERTEX == sc )
		{
			size_t mainbegin = _FindMainFunction(code);
			_FixAttributeIndexingType( code, mainbegin );
		}
		glslopt_shader_delete( shader );
	}
예제 #8
0
	size_t _FindMainFunction( eastl::string& str )//找到主函数段
	{
		size_t start_pos = 0;
		do 
		{
			start_pos = str.find("main", start_pos);
			if( start_pos != eastl::string::npos )
			{
				size_t i = -1;
				bool istype = false;
				do 
				{
					istype = ! Utility::NotVariablePart( str[ start_pos + i-- ] );
				} while ( !istype );
				if ( 'd' == str[start_pos + ++i] )
				{
					start_pos = str.find("{", start_pos);
					return start_pos + 1;
				}
			}
			start_pos++;
		} while ( start_pos != eastl::string::npos );
		return eastl::string::npos;
	}
예제 #9
0
	//---------------------------------------------------------------------------------------------------------
	eastl::string _GetVariableName( const eastl::string& str, std::size_t begin, std::size_t dir )//得到变量全名
	{
		size_t spb = begin;
		size_t spe;
		while(true)
		{
			spb += dir;
			if ( !Utility::NotVariablePart( str[spb] ) )
			{
				spe = spb + dir;
				break;
			}
		}
		while(true)
		{
			spe += dir;
			if ( Utility::NotVariablePart( str[spe] ) )
			{
				break;
			}
		}
		return str.substr( (spb < spe ? spb : spe)+1, spb < spe ? spe - spb : spb - spe );
	}
예제 #10
0
	//-------------------------------------------------------------------------------------------------------
	PipelineProperty::ActivePassTypeArray MaterialSystem::ParseMaterial( const eastl::string& path, eastl::string& matstr )
	{
		string luaSource;
		vector<string> funcs;
		PipelineProperty::ActivePassTypeArray apta;
		Utility::SeparateAllString( MATERIAL_DEFINE, END_DEFINE, funcs, matstr );//将材质分拆开来
		for( int i = 0; i < funcs.size() ; ++ i )
		{
			Utility::MakeLuaFunction( MATERIAL_DEFINE, END_DEFINE, funcs[i] );//每个材质做成函数
			luaSource += "\r\n" + funcs[i];
		}
		m_pScriptParser->DoScript( luaSource );//加载lua脚本
		m_CurrentPassType = static_cast<BohgeEngine::PipelineProperty::PassType>(-1);

		const int passCount = IMaterialSystem::Instance()->GetActivePassTypeCount();
		for ( int i = 0 ; i < passCount ; ++ i )
		{
			PipelineProperty::PassType pt = IMaterialSystem::Instance()->GetPassType( i );
			if( Utility::MacroName( m_pPassTypeNameArray[pt], matstr, m_pPassFunctionName[pt] ) )
			{
				apta.push_back( pt );
			}
			else
			{
				m_pPassFunctionName[pt].clear();
				DEBUGLOG("empty %s pass function in file %s!\n", m_pPassTypeNameArray[pt].c_str(), path.c_str() );
			}
		}
		return apta;
	}
예제 #11
0
FileHandle::FileHandle(const eastl::string& a_filePath, EFileMode a_fileMode) : m_rwops(0), m_size(0), m_fileMode(a_fileMode)
{
	initialize(a_filePath.c_str(), a_fileMode);
}
예제 #12
0
 time_t GetFileModTime( const eastl::string &filename ) {
    struct _stat statInfo;
    _stat( filename.c_str(), &statInfo );
    return statInfo.st_mtime;
 }
예제 #13
0
	// Parses the entire shader string buffer to match instances of the program meta flag
	// Format of the shader usage flags: "!!>:(Flag Type, <Values, sep. by comma>)"
	// Flag Type can be either Usage or Permute
	void UProgramPermutor::ParseProgramMetaFlags(const eastl::string& inShaderBufferString, eastl::vector<SShaderMetaFlagInstance>& outMetaFlagInstances)
	{
		// Find all occurrences of shader meta flag string
		size_t currentFindIndex = inShaderBufferString.find(s_shaderMetaFlagString, 0);

		outMetaFlagInstances.clear();

		while (currentFindIndex != eastl::string::npos)
		{
			eastl::string metaFlagInstanceString;

			currentFindIndex += UProgramPermutor::s_shaderMetaFlagString.length();

			while (inShaderBufferString[currentFindIndex] != ')')
			{
				metaFlagInstanceString += inShaderBufferString[currentFindIndex];

				++currentFindIndex;
			}

			++currentFindIndex; // Skip past the ending parentheses

			if (metaFlagInstanceString.empty())
			{
				LOG(LogProgramPermutor, Warning, "Warning: Shader usage instance #%d has an empty description pair!", outMetaFlagInstances.size());
				return;
			}

			eastl::vector<eastl::string> metaFlagSubstrings;
			SShaderMetaFlagInstance currentMetaFlagInstance;

			// Split the meta flag string by coma
			size_t currentCommaIndex = 0;
			size_t nextCommaIndex = metaFlagInstanceString.find(',', currentCommaIndex);

			while (nextCommaIndex != eastl::string::npos)
			{
				eastl::string flagValueString = metaFlagInstanceString.substr(currentCommaIndex, (nextCommaIndex - currentCommaIndex));

				metaFlagSubstrings.emplace_back(flagValueString);

				currentCommaIndex = nextCommaIndex + 1;

				nextCommaIndex = metaFlagInstanceString.find(',', currentCommaIndex);

				if (nextCommaIndex == eastl::string::npos)
				{
					eastl::string lastFlagValueString = metaFlagInstanceString.substr(currentCommaIndex, (nextCommaIndex - currentCommaIndex));

					// On the last iteration, we need to add the last string
					metaFlagSubstrings.emplace_back(lastFlagValueString);
				}
			}
			
			// Flag string count sanity check
			if (metaFlagSubstrings.size() == 0)
			{
				LOG(LogProgramPermutor, Warning, "Warning: Shader usage instance #%d has more than one separation commas!", outMetaFlagInstances.size());
				return;
			}
			
			// First substring is the flag type
			currentMetaFlagInstance.MetaFlagType = ConvertStringToFlagType(metaFlagSubstrings.front());

			if (currentMetaFlagInstance.MetaFlagType == EMetaFlagType::EMetaFlagType_Invalid)
			{
				LOG(LogProgramPermutor, Warning, "Warning: Shader usage instance #%d has an invalid meta flag type!", outMetaFlagInstances.size());
				return;
			}
			
			// Rest of the substrings are the parameter values (if applicable)
			
			for (size_t i = 1; i < metaFlagSubstrings.size(); ++i)
			{
				currentMetaFlagInstance.MetaFlagValues.emplace_back(metaFlagSubstrings[i]);
			}

			outMetaFlagInstances.emplace_back(currentMetaFlagInstance);

			currentFindIndex = inShaderBufferString.find(UProgramPermutor::s_shaderMetaFlagString, currentFindIndex);
		}
	}
예제 #14
0
	//---------------------------------------------------------------------------------------------------------
	void BTextSystem::_OnSetLanguage( const eastl::string& lan )
	{
		Text_1::SetLanguage( lan.c_str() );
	}