Esempio n. 1
0
	void DepthOfField::renderPass(const DRBCameraDrawableList &infos)
	{
		if (infos.cameraInfos.data.dof)
		{
			SCOPE_profile_gpu_i("Depth of field");
			SCOPE_profile_cpu_i("RenderTimer", "Depth of field");

			_depth->bind();
			_depth->generateMipmaps();

			OpenGLState::glDepthMask(GL_FALSE);
			OpenGLState::glDisable(GL_DEPTH_TEST);
			OpenGLState::glDisable(GL_STENCIL_TEST);
			OpenGLState::glDisable(GL_CULL_FACE);

			_programs[PROGRAM_DEPTH_OF_FIELD]->use();
			_programs[PROGRAM_DEPTH_OF_FIELD]->get_resource<Sampler2D>(StringID("cleanMap", 0x90c5a5421e083038)).set(_clean);
			_programs[PROGRAM_DEPTH_OF_FIELD]->get_resource<Sampler2D>(StringID("depthMap", 0xeb35b90435165cd4)).set(_depth);
			_programs[PROGRAM_DEPTH_OF_FIELD]->get_resource<Sampler2D>(StringID("blurredMap1", 0x031e7d3c1b84e96a)).set(_blurred1);
			_programs[PROGRAM_DEPTH_OF_FIELD]->get_resource<Sampler2D>(StringID("blurredMap2", 0x031e7c3c1b84e7b7)).set(_blurred2);

			_quadPainter->uniqueDrawBegin(_programs[PROGRAM_DEPTH_OF_FIELD]);
			_quadPainter->uniqueDraw(GL_TRIANGLES, _programs[PROGRAM_DEPTH_OF_FIELD], _quadVertices);
			_quadPainter->uniqueDrawEnd();
		}
	}
Esempio n. 2
0
	void RenderThread::getCube(Key<Vertices> &v, Key<Painter> &p)
	{
		static const std::vector<glm::vec3> positions =
		{
			glm::vec3(-1.0f, 1.0f, 1.0f),
			glm::vec3(-1.0f, -1.0f, 1.0f),
			glm::vec3(1.0f, -1.0f, 1.0f),
			glm::vec3(1.0f, 1.0f, 1.0f),
			glm::vec3(-1.0f, 1.0f, -1.0f),
			glm::vec3(-1.0f, -1.0f, -1.0f),
			glm::vec3(1.0f, -1.0f, -1.0f),
			glm::vec3(1.0f, 1.0f, -1.0f)
		};
		static const std::vector<unsigned int> indices =
		{
			0, 1, 2, 3, 0, 3, 7, 4, 4, 7, 6, 5, 6, 5, 1, 2, 2, 3, 7, 6, 4, 0, 1, 5
		};

		// to be sure that this function is only called in render thread
		AGE_ASSERT(CurrentThread() == (AGE::Thread*)GetRenderThread());

		if (SimpleGeometry::cubeMesh.verticesKey.isValid() &&
			SimpleGeometry::cubeMesh.painterKey.isValid())
		{
			v = SimpleGeometry::cubeMesh.verticesKey;
			p = SimpleGeometry::cubeMesh.painterKey;
			return;
		}

		auto type = std::make_pair<GLenum, StringID>(GL_FLOAT_VEC3, StringID("position", 0x4cbf3a26fca1d74a));
		std::vector<std::pair < GLenum, StringID > > types;
		types.push_back(type);

		if (!paintingManager->has_painter(types))
		{
			SimpleGeometry::cubeMesh.painterKey = paintingManager->add_painter(std::move(types));
		}
		else
		{
			SimpleGeometry::cubeMesh.painterKey = paintingManager->get_painter(types);
		}
		auto &painterPtr = paintingManager->get_painter(SimpleGeometry::cubeMesh.painterKey);

		SimpleGeometry::cubeMesh.verticesKey = painterPtr->add_vertices(positions.size(), indices.size());
		auto vertices = painterPtr->get_vertices(SimpleGeometry::cubeMesh.verticesKey);

		vertices->set_data<glm::vec3>(positions, StringID("position", 0x4cbf3a26fca1d74a));
		vertices->set_indices(indices);

		v = SimpleGeometry::cubeMesh.verticesKey;
		p = SimpleGeometry::cubeMesh.painterKey;
	}
Esempio n. 3
0
    void AssimpModelImporter::GetBone(aiNode* bone, const int32 &parentID)
    {

        aiVector3D _bonePos, _boneScale;
        aiQuaternion _boneRot;
        bone->mTransformation.Decompose( _boneScale, _boneRot, _bonePos);                

        Matrix _boneMatrix;
        _boneMatrix.m[0]  = bone->mTransformation.a1; _boneMatrix.m[1]  = bone->mTransformation.b1; _boneMatrix.m[2]  = bone->mTransformation.c1; _boneMatrix.m[3]  = bone->mTransformation.d1;
        _boneMatrix.m[4]  = bone->mTransformation.a2; _boneMatrix.m[5]  = bone->mTransformation.b2; _boneMatrix.m[6]  = bone->mTransformation.c2; _boneMatrix.m[7]  = bone->mTransformation.d2;
        _boneMatrix.m[8]  = bone->mTransformation.a3; _boneMatrix.m[9]  = bone->mTransformation.b3; _boneMatrix.m[10] = bone->mTransformation.c3; _boneMatrix.m[11] = bone->mTransformation.d3;
        _boneMatrix.m[12] = bone->mTransformation.a4; _boneMatrix.m[13] = bone->mTransformation.b4; _boneMatrix.m[14] = bone->mTransformation.c4; _boneMatrix.m[15] = bone->mTransformation.d4;
        
        Bone _bone;
        _bone.name			= bone->mName.data;
        _bone.self			= boneCount;
        _bone.parent        = parentID;
        _bone.pos			= Vec3(_bonePos.x,_bonePos.y,_bonePos.z);
        _bone.rot			= Quaternion(_boneRot.w,_boneRot.x,_boneRot.y,_boneRot.z);
        _bone.scale			= Vec3(_boneScale.x,_boneScale.y,_boneScale.z);
        _bone.bindPoseMat   = _boneMatrix;
        
        // add bone to Skeleton
        skeleton[StringID (MakeStringID(_bone.name))]=_bone;

        // increase bone count
        boneCount++;
        
        // check and get children
        if (bone->mNumChildren>0) 
        {
            for (uint32 i=0;i<bone->mNumChildren;i++)
                GetBone(bone->mChildren[i], _bone.self);
        }
    }
Esempio n. 4
0
	BufferPrograms::BufferPrograms(std::vector<std::pair<GLenum, StringID>> const &types) :
		_types(types),
		_indices_buffer(StringID("indices", 0x144d56ffb313be92), std::make_unique<IndexBuffer>())
	{
		_buffers.reserve(_types.size());
		_vertex_array.bind();
		auto index = 0ull;
		for (auto &type : _types) {
			auto &iterator = available_types.find(type.first);
			if (iterator != available_types.end()) {
				auto &a = iterator->second;
				_buffers.emplace_back(std::make_shared<Buffer>(StringID(type.second), std::make_unique<VertexBuffer>()));
			}
		}
		_indices_buffer.bind();
		_vertex_array.unbind();
	}
Esempio n. 5
0
int main(int ac, char **av)
{
	StringID wizard = StringID("Wizard");

	std::vector<StringID> inventory;
	inventory.push_back(StringID("Red rock"));
	inventory.push_back(StringID("Magic book"));
	inventory.push_back(StringID("Hat"));

	auto gnome = StringID("Gnome");

	if (wizard != gnome)
	{
		StringID magicBook;
		for (int i = 0; i < inventory.size(); ++i)
		{
			if (inventory[i] == StringID("Magic book"))
				break;
		}
		auto magicSpell = StringID("Abracadabra !");
		auto magicSpellStr = magicSpell.str();
		if (magicSpellStr == nullptr)
		{
			std::cout << "No debug spell availlable !" << std::endl;
			std::cout << "Gnome win !" << std::endl;
		}
		else
		{
			std::cout << magicSpell.str() << std::endl;
			std::cout << "Wizard win" << std::endl;

		}
	}
	return 0;
}
Esempio n. 6
0
	void RenderThread::getIcoSphereGeometry(Key<Vertices> &v, Key<Painter> &p, uint32_t recursion)
	{
		std::vector<glm::vec3> positions;
		std::vector<unsigned int> indices;

		// to be sure that this function is only called in render thread
		AGE_ASSERT(CurrentThread() == (AGE::Thread*)GetRenderThread());

		if (SimpleGeometry::icosphereMeshes[recursion].verticesKey.isValid() &&
			SimpleGeometry::icosphereMeshes[recursion].painterKey.isValid())
		{
			v = SimpleGeometry::icosphereMeshes[recursion].verticesKey;
			p = SimpleGeometry::icosphereMeshes[recursion].painterKey;
			return;
		}

		SimpleGeometry::generateIcoSphere(recursion, positions, indices);

		auto type = std::make_pair<GLenum, StringID>(GL_FLOAT_VEC3, StringID("position", 0x4cbf3a26fca1d74a));
		std::vector<std::pair < GLenum, StringID > > types;
		types.push_back(type);

		if (!paintingManager->has_painter(types))
		{
			SimpleGeometry::icosphereMeshes[recursion].painterKey = paintingManager->add_painter(std::move(types));
		}
		else
		{
			SimpleGeometry::icosphereMeshes[recursion].painterKey = paintingManager->get_painter(types);
		}
		auto &painterPtr = paintingManager->get_painter(SimpleGeometry::icosphereMeshes[recursion].painterKey);

		SimpleGeometry::icosphereMeshes[recursion].verticesKey = painterPtr->add_vertices(positions.size(), indices.size());
		auto vertices = painterPtr->get_vertices(SimpleGeometry::icosphereMeshes[recursion].verticesKey);

		vertices->set_data<glm::vec3>(positions, StringID("position", 0x4cbf3a26fca1d74a));
		vertices->set_indices(indices);

		v = SimpleGeometry::icosphereMeshes[recursion].verticesKey;
		p = SimpleGeometry::icosphereMeshes[recursion].painterKey;
	}
Esempio n. 7
0
namespace bs
{
	const StringID StringID::NONE = StringID();

	volatile StringID::InitStatics StringID::mInitStatics = StringID::InitStatics();

	StringID::InternalData* StringID::mStringHashTable[HASH_TABLE_SIZE];
	StringID::InternalData* StringID::mChunks[MAX_CHUNK_COUNT];

	UINT32 StringID::mNextId = 0;
	UINT32 StringID::mNumChunks = 0;
	SpinLock StringID::mSync;

	StringID::InitStatics::InitStatics()
	{
		ScopedSpinLock lock(mSync);

		memset(mStringHashTable, 0, sizeof(mStringHashTable));
		memset(mChunks, 0, sizeof(mChunks));

		mChunks[0] = (InternalData*)bs_alloc(sizeof(InternalData) * ELEMENTS_PER_CHUNK);
		memset(mChunks[0], 0, sizeof(InternalData) * ELEMENTS_PER_CHUNK);

		mNumChunks++;
	}

	StringID::StringID()
		:mData(nullptr)
	{ }

	template<class T>
	void StringID::construct(T const& name)
	{
		assert(StringIDUtil<T>::size(name) <= STRING_SIZE);

		UINT32 hash = calcHash(name) & (sizeof(mStringHashTable) / sizeof(mStringHashTable[0]) - 1);
		InternalData* existingEntry = mStringHashTable[hash];
		
		while (existingEntry != nullptr)
		{
			if (StringIDUtil<T>::compare(name, existingEntry->chars))
			{
				mData = existingEntry;
				return;
			}

			existingEntry = existingEntry->next;
		}

		ScopedSpinLock lock(mSync);

		// Search for the value again in case other thread just added it
		existingEntry = mStringHashTable[hash];
		InternalData* lastEntry = nullptr;
		while (existingEntry != nullptr)
		{
			if (StringIDUtil<T>::compare(name, existingEntry->chars))
			{
				mData = existingEntry;
				return;
			}

			lastEntry = existingEntry;
			existingEntry = existingEntry->next;
		}

		mData = allocEntry();
		StringIDUtil<T>::copy(name, mData->chars);

		if (lastEntry == nullptr)
			mStringHashTable[hash] = mData;
		else
			lastEntry->next = mData;
	}

	template<class T>
	UINT32 StringID::calcHash(T const& input)
	{
		UINT32 size = StringIDUtil<T>::size(input);

		UINT32 hash = 0;
		for (UINT32 i = 0; i < size; i++)
			hash = hash * 101 + input[i];

		return hash;
	}

	StringID::InternalData* StringID::allocEntry()
	{
		UINT32 chunkIdx = mNextId / ELEMENTS_PER_CHUNK;

		assert(chunkIdx < MAX_CHUNK_COUNT);
		assert(chunkIdx <= mNumChunks); // Can only increment sequentially

		if (chunkIdx >= mNumChunks)
		{
			mChunks[chunkIdx] = (InternalData*)bs_alloc(sizeof(InternalData) * ELEMENTS_PER_CHUNK);
			memset(mChunks[chunkIdx], 0, sizeof(InternalData) * ELEMENTS_PER_CHUNK);

			mNumChunks++;
		}

		InternalData* chunk = mChunks[chunkIdx];
		UINT32 chunkSpecificIndex = mNextId % ELEMENTS_PER_CHUNK;

		InternalData* newEntry = &chunk[chunkSpecificIndex];
		newEntry->id = mNextId++;
		newEntry->next = nullptr;

		return newEntry;
	}

	template<>
	class StringID::StringIDUtil<const char*>
	{
	public:
		static UINT32 size(const char* const& input) { return (UINT32)strlen(input); }
		static void copy(const char* const& input, char* dest) { memcpy(dest, input, strlen(input) + 1); }
		static bool compare(const char* const& a, char* b) { return strcmp(a, b) == 0; }
	};

	template<>
	class StringID::StringIDUtil <String>
	{
	public:
		static UINT32 size(String const& input) { return (UINT32)input.length(); }
		static void copy(String const& input, char* dest)
		{ 
			UINT32 len = (UINT32)input.length();
			input.copy(dest, len);
			dest[len] = '\0';
		}
		static bool compare(String const& a, char* b) { return a.compare(b) == 0; }
	};

	template class StringID::StringIDUtil <const char*>;
	template class StringID::StringIDUtil <String>;

	template BS_UTILITY_EXPORT void StringID::construct(const char* const&);
	template BS_UTILITY_EXPORT void StringID::construct(String const&);
	
	template BS_UTILITY_EXPORT UINT32 StringID::calcHash(const char* const&);
	template BS_UTILITY_EXPORT UINT32 StringID::calcHash(String const&);
}