String LuaState::DumpStack() const
	{
		StringStream stream;
		unsigned int stackTop = GetStackTop();
		stream << stackTop << " entries\n";

		for (unsigned int i = 1; i <= stackTop; ++i)
		{
			stream << i << ": ";
			switch (GetType(i))
			{
				case LuaType_Boolean:
					stream << "Boolean(" << ToBoolean(i) << ')';
					break;

				case LuaType_Function:
					stream << "Function(" << ToPointer(i) << ')';
					break;

				case LuaType_LightUserdata:
				case LuaType_Userdata:
					stream << "Userdata(" << ToUserdata(i) << ')';
					break;

				case LuaType_Nil:
					stream << "Nil";
					break;

				case LuaType_None:
					stream << "None";
					break;

				case LuaType_Number:
					stream << "Number(" << ToNumber(i) << ')';
					break;

				case LuaType_String:
					stream << "String(" << ToString(i) << ')';
					break;

				case LuaType_Table:
					stream << "Table(" << ToPointer(i) << ')';
					break;

				case LuaType_Thread:
					stream << "Thread(" << ToPointer(i) << ')';
					break;

				default:
					stream << "Unknown(" << ToPointer(i) << ')';
					break;
			}

			stream << '\n';
		}

		return stream.ToString();
	}
	UInt32 TriangleIterator::operator[](unsigned int i) const
	{
		#if NAZARA_UTILITY_SAFE
		if (i >= 3)
		{
			StringStream ss;
			ss << "Index out of range: (" << i << " >= 3)";

			NazaraError(ss);
			throw std::domain_error(ss.ToString());
		}
		#endif

		return m_triangleIndices[i];
	}
	void ParticleGroup::ResizeBuffer()
	{
		// Just to have a better description of our problem in case of error
		try
		{
			m_buffer.resize(m_maxParticleCount*m_particleSize);
		}
		catch (const std::exception& e)
		{
			StringStream stream;
			stream << "Failed to allocate particle buffer (" << e.what() << ") for " << m_maxParticleCount << " particles of size " << m_particleSize;

			NazaraError(stream.ToString());
		}
	}
Exemple #4
0
String Continuation::Show() const
{
    StringStream str;
    int around = 4;
    auto current = *index;
    auto min = std::max(0, current - around);
    auto max = std::min(code->Size() - 1, current + around);
    str << "IP=" << current << "\n";
    for (int n = min; n < max; ++n)
    {
        if (n == current - 1)
            str << ">>> ";
        str << code->At(n) << "\n";
    }

    return str.ToString();
}
	UberShaderInstance* UberShaderPreprocessor::Get(const ParameterList& parameters) const
	{
		// Première étape, transformer les paramètres en un flag
		UInt32 flags = 0;
		for (auto it = m_flags.begin(); it != m_flags.end(); ++it)
		{
			if (parameters.HasParameter(it->first))
			{
				bool value;
				if (parameters.GetBooleanParameter(it->first, &value) && value)
					flags |= it->second;
			}
		}

		// Le shader fait-il partie du cache ?
		auto shaderIt = m_cache.find(flags);

		// Si non, il nous faut le construire
		if (shaderIt == m_cache.end())
		{
			try
			{
				// Une exception sera lancée à la moindre erreur et celle-ci ne sera pas enregistrée dans le log (car traitée dans le bloc catch)
				ErrorFlags errFlags(ErrorFlag_Silent | ErrorFlag_ThrowException, true);

				ShaderRef shader = Shader::New();
				shader->Create();

				for (unsigned int i = 0; i <= ShaderStageType_Max; ++i)
				{
					const CachedShader& shaderStage = m_shaders[i];

					// Le shader stage est-il activé dans cette version du shader ?
					if (shaderStage.present && (flags & shaderStage.requiredFlags) == shaderStage.requiredFlags)
					{
						UInt32 stageFlags = 0;
						for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
						{
							if (parameters.HasParameter(it->first))
							{
								bool value;
								if (parameters.GetBooleanParameter(it->first, &value) && value)
									stageFlags |= it->second;
							}
						}

						auto stageIt = shaderStage.cache.find(stageFlags);
						if (stageIt == shaderStage.cache.end())
						{
							ShaderStage stage;
							stage.Create(static_cast<ShaderStageType>(i));

							unsigned int glslVersion = OpenGL::GetGLSLVersion();

							StringStream code;
							code << "#version " << glslVersion << "\n\n";

							code << "#define GLSL_VERSION " << glslVersion << "\n\n";

							code << "#define EARLY_FRAGMENT_TESTS " << ((glslVersion >= 420 || OpenGL::IsSupported(OpenGLExtension_Shader_ImageLoadStore)) ? '1' : '0') << "\n\n";

							for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
								code << "#define " << it->first << ' ' << ((stageFlags & it->second) ? '1' : '0') << '\n';

							code << "\n#line 1\n"; // Pour que les éventuelles erreurs du shader se réfèrent à la bonne ligne
							code << shaderStage.source;

							stage.SetSource(code);

							try
							{
								stage.Compile();
							}
							catch (const std::exception&)
							{
								ErrorFlags errFlags2(ErrorFlag_ThrowExceptionDisabled);

								NazaraError("Shader code failed to compile (" + stage.GetLog() + ")\n" + code.ToString());
								throw;
							}

							stageIt = shaderStage.cache.emplace(flags, std::move(stage)).first;
						}

						shader->AttachStage(static_cast<ShaderStageType>(i), stageIt->second);
					}
				}

				shader->Link();

				// On construit l'instant
				shaderIt = m_cache.emplace(flags, shader.Get()).first;
			}
			catch (const std::exception&)
			{
				ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled);

				NazaraError("Failed to build UberShader instance: " + Error::GetLastError());
				throw;
			}
		}

		return &shaderIt->second;
	}