bool RenderWindow::CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos) const
	{
		#if NAZARA_RENDERER_SAFE
		if (!m_context)
		{
			NazaraError("Window has not been created");
			return false;
		}
		#endif

		Vector2ui windowSize = GetSize();

		#if NAZARA_RENDERER_SAFE
		if (!image)
		{
			NazaraError("Image must be valid");
			return false;
		}

		if (image->GetFormat() != PixelFormatType_RGBA8)
		{
			// Pour plus de facilité, évidemment on peut faire sauter cette règle avec un peu de gestion
			NazaraError("Image must be RGBA8-formatted");
			return false;
		}

		if (rect.x + rect.width > windowSize.x || rect.y + rect.height > windowSize.y)
		{
			NazaraError("Rectangle dimensions are out of window's bounds");
			return false;
		}

		Vector3ui imageSize = image->GetSize();
		if (dstPos.x + rect.width > imageSize.x || dstPos.y + rect.height > imageSize.y || dstPos.z > imageSize.z)
		{
			NazaraError("Cube dimensions are out of image's bounds");
			return false;
		}
		#endif

		const Context* currentContext = Context::GetCurrent();
		if (m_context != currentContext)
		{
			if (!m_context->SetActive(true))
			{
				NazaraError("Failed to activate context");
				return false;
			}
		}

		///TODO: Fast-path pour les images en cas de copie du buffer entier

		m_buffer.resize(rect.width*rect.height*4);
		glReadPixels(rect.x, windowSize.y - rect.height - rect.y, rect.width, rect.height, GL_RGBA, GL_UNSIGNED_BYTE, m_buffer.data());

		// Les pixels sont retournés, nous devons envoyer les pixels par rangée
		for (unsigned int i = 0; i < rect.height; ++i)
			image->Update(&m_buffer[rect.width*4*i], Boxui(dstPos.x, rect.height - i - 1, dstPos.z, rect.width, 1, 1), rect.width);

		if (m_context != currentContext)
		{
			if (currentContext)
			{
				if (!currentContext->SetActive(true))
					NazaraWarning("Failed to reset old context");
			}
			else
				m_context->SetActive(false);
		}

		return true;
	}
Beispiel #2
0
void LODNode::computeVoxelBoxes_( )
{
    Vector3i pntPos = getAbsolutePosition() * blockSize_;
    localVoxelBox_ = Boxui( pntPos, pntPos + blockSize_ );
}