Пример #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 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);
		}
	}
Пример #3
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;
		}
	}
Пример #4
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 );
	}
Пример #5
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;
	}
Пример #6
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);
}
Пример #7
0
 time_t GetFileModTime( const eastl::string &filename ) {
    struct _stat statInfo;
    _stat( filename.c_str(), &statInfo );
    return statInfo.st_mtime;
 }
Пример #8
0
	//---------------------------------------------------------------------------------------------------------
	void BTextSystem::_OnSetLanguage( const eastl::string& lan )
	{
		Text_1::SetLanguage( lan.c_str() );
	}