Exemple #1
0
void WGLRenderer::init(Device *device, Renderer *other) {
	WGLDevice *wglDevice = static_cast<WGLDevice *>(device);

	if (m_session == NULL) {
		Log(EDebug, "Using an existing WGL context");
		m_context = wglGetCurrentContext();
		if (m_context == NULL)
			Log(EError, "Unable to retrieve the current WGL context!");
		m_borrowed = true;
	} else {
		/* Create a GL context */
		Log(EDebug, "Initializing WGL renderer");
		m_context = wglCreateContext(wglDevice->getDeviceContext());

		if (other != NULL) {
			Assert(other->getClass() == m_theClass);
			if (wglShareLists(m_context,
				static_cast<WGLRenderer *>(other)->m_context) != TRUE)
				Log(EError, "Unable to set up context sharing: %s",
					lastErrorText().c_str());
		}

		device->makeCurrent(this);
		m_borrowed = false;
	}

	GLRenderer::init(device);

	m_initialized = true;
}
Exemple #2
0
std::string getHostName() {
	char hostName[128];
	if (gethostname(hostName, sizeof(hostName)) != 0)
#if defined(WIN32)
		SLog(EError, "Could not retrieve the computer's host name: %s!",
			lastErrorText().c_str());
#else
		SLog(EError, "Could not retrieve the computer's host name : %s!",
			strerror(errno));
#endif
	return hostName;
}
Exemple #3
0
void SSHStream::write(const void *ptr, size_t size) {
	static StatsCounter bytesSent("Network", "Bytes sent (SSH)");
#if defined(WIN32)
	size_t left = size;
	char *data = (char *) ptr;
	while (left > 0) {
		DWORD nWritten = 0;
		if (!WriteFile(d->childInWr, ptr, (DWORD) left, &nWritten, NULL))
			Log(EError, "Connection closed while writing: %s", lastErrorText().c_str());
		left -= nWritten;
		data += nWritten;
	}
#else
	if (fwrite(ptr, size, 1, d->output) != 1) {
		if (feof(d->output))
			Log(EError, "Error in fwrite(): end of file!");
		else if (ferror(d->output))
			Log(EError, "Error in fwrite(): stream error!");
		/* Otherwise, ignore (strange, but seems to be required) */
	}
#endif
	d->sent += size;
	bytesSent += size;
}
Exemple #4
0
void SSHStream::read(void *ptr, size_t size) {
	static StatsCounter bytesRcvd("Network", "Bytes received (SSH)");
#if defined(WIN32)
	size_t left = size;
	char *data = (char *) ptr;
	while (left > 0) {
		DWORD nRead = 0;
		if (!ReadFile(d->childOutRd, ptr, (DWORD) left, &nRead, NULL))
			Log(EError, "Connection closed while reading: %s", lastErrorText().c_str());
		left -= nRead;
		data += nRead;
	}
#else
	if (fread(ptr, size, 1, d->input) != 1) {
		if (feof(d->input))
			Log(EError, "Error in fread(): end of file!");
		else if (ferror(d->input))
			Log(EError, "Error in fread(): stream error!");
		/* Otherwise, ignore (strange, but seems to be required) */
	}
#endif
	d->received += size;
	bytesRcvd += size;
}
FileResolver::FileResolver() {
	/* Try to detect the base path of the Mitsuba installation */
	fs::path basePath;
#if defined(__LINUX__)
	Dl_info info;

	dladdr((const void *) &dummySymbol, &info);
	if (info.dli_fname) {
		/* Try to detect a few default setups */
		if (boost::starts_with(info.dli_fname, "/usr/lib") ||
			boost::starts_with(info.dli_fname, "/lib")) {
			basePath = fs::path("/usr/share/mitsuba");
		} else if (boost::starts_with(info.dli_fname, "/usr/local/lib")) {
			basePath = fs::path("/usr/local/share/mitsuba");
		} else {
			/* This is a locally-compiled repository */
			basePath = fs::path(info.dli_fname).parent_path();
		}
	}
#elif defined(__OSX__)
	MTS_AUTORELEASE_BEGIN()
	uint32_t imageCount = _dyld_image_count();
	for (uint32_t i=0; i<imageCount; ++i) {
		const char *imageName = _dyld_get_image_name(i);
		if (boost::ends_with(imageName, "libmitsuba-core.dylib")) {
			basePath = fs::canonical(imageName).parent_path().parent_path().parent_path();
			break;
		}
	}
	MTS_AUTORELEASE_END()
	if (basePath.empty())
		Log(EError, "Could not detect the executable path!");
#elif defined(__WINDOWS__)
	std::vector<WCHAR> lpFilename(MAX_PATH);

	// Module handle to this DLL. If the function fails it sets handle to NULL.
	// In that case GetModuleFileName will get the name of the executable which
	// is acceptable soft-failure behavior.
	HMODULE handle;
	GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
	                 | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
          reinterpret_cast<LPCWSTR>(&dummySymbol), &handle);

	// Try to get the path with the default MAX_PATH length (260 chars)
	DWORD nSize = GetModuleFileNameW(handle, &lpFilename[0], MAX_PATH);

	// Adjust the buffer size in case if was too short
	while (nSize != 0 && nSize == lpFilename.size()) {
		lpFilename.resize(nSize * 2);
		nSize = GetModuleFileNameW(handle, &lpFilename[0],
			static_cast<DWORD>(lpFilename.size()));
	}

	// There is an error if and only if the function returns 0
	if (nSize != 0)
		basePath = fs::path(lpFilename).parent_path();
	else
		Log(EError, "Could not detect the executable path! (%s)", lastErrorText().c_str());
#endif
	#if BOOST_VERSION >= 104800
		m_paths.push_back(fs::canonical(basePath));
	#else
		m_paths.push_back(fs::absolute(basePath));
	#endif
	m_paths.push_back(fs::current_path());
}