Example #1
0
	IOGLBaseShader::IOGLBaseShader(CRefPtr<COGLDevice> pDevice, const Graphic::ShaderType uType, const Graphic::ShaderVersion uVersion, CGenum uSourceType, CGprofile uProfile, const CString& strSource, const CString& strEntryPoint) :
		m_uVersion(uVersion),
		m_uType(uType),
		m_uProgram(0),
		m_bBinded(false),
		Manage::IManagedObject<COGLDevice, IOGLBaseShader>(pDevice)
	{
		if(!cgIsProfileSupported(uProfile)){
			throw Exception::CInvalidArgumentException(L"uProfile", String::FromANSI(reinterpret_cast<const int8*>(cgGetProfileString(uProfile))),
				L"Unsupported shader profile.", CR_INFO());
		}

		auto szSource = String::ToANSI(strSource);
		auto szEntryPoint = String::ToANSI(strEntryPoint);

		this->m_uProgram = cgCreateProgram(this->GetParent()->GetCGC().Get(), uSourceType, reinterpret_cast<const char*>(szSource.GetPointer()), uProfile, reinterpret_cast<const char*>(szEntryPoint.GetPointer()), 0);
		if(!cgIsProgram(this->m_uProgram)){
			CR_THROW(L"Failed to create shader program.");
		}

		cgCompileProgram(this->m_uProgram);
		if(!cgIsProgramCompiled(this->m_uProgram)){
			CR_THROW(L"Failed to compile program.");
		}

		cgGLLoadProgram(this->m_uProgram);
	}
Example #2
0
	COGLVertexDeclaration::COGLVertexDeclaration(CRefPtr<COGLDevice> pDevice, const Collection::ICountable<Graphic::CVertexElement>& Elements) :
		Manage::IManagedObject<COGLDevice, COGLVertexDeclaration>(pDevice)
	{
		this->m_Streams.Resize(this->GetParent()->GetNumberOfStreams());
		for(uint32 uIndex = 0; uIndex < Elements.GetLength(); uIndex++){
			const Graphic::CVertexElement& el = Elements[uIndex];

			if(el.uStream >= this->m_Streams.GetLength()){
				CR_THROW(L"Stream number exceeds max number.");
			}

			CStreamElement stream;

			stream.strParamName = el.strParam;
			stream.uType		= GLUtils::ToVertexType(el.uType);
			stream.uNumber		= GLUtils::ToVertexTypeNumber(el.uType) * el.uTypeNumber;
			stream.uOffset		= el.uOffset;
			stream.uSize		= GLUtils::GetTypeSize(stream.uType) * stream.uNumber;

			this->m_Streams[el.uStream].Elements.Add(stream);
			if(this->m_Streams[el.uStream].uStride < stream.uOffset + stream.uSize){
				this->m_Streams[el.uStream].uStride = stream.uOffset + stream.uSize;
			}
		}

	}
Example #3
0
	CGparameter	IOGLBaseShader::GetParameter(const CString& strName) const{
		auto szName = String::ToANSI(strName);

		auto uParam = cgGetNamedParameter(this->m_uProgram, reinterpret_cast<const char*>(szName.GetPointer()));
		if(uParam == 0 || !cgIsParameter(uParam)){
			CR_THROW(L"Failed to find parameter: " + strName);
		}

		return uParam;
	}
Example #4
0
	COALDevice::COALDevice(CRefPtr<COALAdapter> pAdapter) :
		Manage::IManagedObject<COALAdapter, COALDevice>(pAdapter),
		m_pContext(0)
	{
		Log::Write(L"Initializing OpenAL Device...");
		ALCint attibs[] = {
			ALC_MAJOR_VERSION, 1,
			ALC_MINOR_VERSION, 1,
			0, 0,
		};
		this->m_pContext = alcCreateContext(this->m_pParent->GetALCDevice(), attibs);
		if(!this->m_pContext){
			auto uError = alcGetError(this->m_pParent->GetALCDevice());
			CR_THROW(L"Failed to create device for adapter " + this->m_pParent->GetName() + L", error: " + String::ToHexString(uError));
		}
		if(!alcMakeContextCurrent(this->m_pContext)){
			auto uError = alcGetError(this->m_pParent->GetALCDevice());
			alcDestroyContext(this->m_pContext);
			CR_THROW(L"Failed to make context current for adapter " + this->m_pParent->GetName() + L", error: " + String::ToHexString(uError));
		}

		//AL::LoadExtensions(this->m_pParent->GetALCDevice());
	}
Example #5
0
	CPAManager::CPAManager(CRefPtr<Audio::IDriver> pDriver) :
		m_pDriver(pDriver),
		m_uDefaultIndex(0)
	{
		Log::Write(L"Initializing PortAudio Audio manager...");

		auto uError = Pa_Initialize();
		if(uError != paNoError){
			CR_THROW(L"Failed to initialize port audio, Error: " + Utils::ToErrorString(uError));
		}

		Log::Write(L"Enumerating audio adapters...", Log::LogLevel::Debug);
		auto uDeviceCount = Pa_GetDeviceCount();
		for(PaDeviceIndex uIndex = 0; uIndex < uDeviceCount; uIndex++){
			auto pInfo = Pa_GetDeviceInfo(uIndex);
			auto pApiInfo = Pa_GetHostApiInfo(pInfo->hostApi);
			
			auto strAdapter = String::FromANSI(reinterpret_cast<const int8*>(pInfo->name));
			auto strHostApi = String::FromANSI(reinterpret_cast<const int8*>(pApiInfo->name));

			strAdapter += L"[" + strHostApi + L"]";

			Log::Write(L"Audio Adapter Found: " + strAdapter, Log::LogLevel::Debug);
			this->m_strAdapterList.Add(strAdapter);
		}
		Log::Write(L"End of enumeration of audio adapters.", Log::LogLevel::Debug);

		if(!this->m_strAdapterList.IsEmpty()){
			Log::Write(L"Finding default audio adapter...", Log::LogLevel::Debug);

			auto uDefaultIndex = Pa_GetDefaultOutputDevice();
			if(uDefaultIndex == paNoDevice){
				Log::Write(L"Got null pointer for default device - assuming default as first in list.");
				uDefaultIndex = 0;
			}

			auto pInfo = Pa_GetDeviceInfo(uDefaultIndex);
			auto pApiInfo = Pa_GetHostApiInfo(pInfo->hostApi);
			
			auto strAdapter = String::FromANSI(reinterpret_cast<const int8*>(pInfo->name));
			auto strHostApi = String::FromANSI(reinterpret_cast<const int8*>(pApiInfo->name));

			strAdapter += L"[" + strHostApi + L"]";
			Log::Write(L"Found default PortAudio adapter: " + strAdapter, Log::LogLevel::Debug);

			this->m_uDefaultIndex = uDefaultIndex;
		}
	}
Example #6
0
	COALAdapter::COALAdapter(CRefPtr<COALManager> pManager, const CString& strAdapter, const uint32 uIndex) :
		Manage::IManagedObject<COALManager, COALAdapter>(pManager),
		m_strAdapter(strAdapter),
		m_uIndex(uIndex),
		m_pAdapter(0)
	{
		Log::Write(L"Initializing OpenAL Adapter " + this->m_strAdapter);
		auto szDevice = String::ToANSI(this->m_strAdapter);
		ALCdevice* pDevice = alcOpenDevice(reinterpret_cast<const ALCchar*>(szDevice.GetPointer()));
		if(pDevice == 0){
			auto uError = alcGetError(0);
			CR_THROW(L"Failed to create adapter " + this->m_strAdapter);
		}

		this->m_pAdapter = pDevice;
	}
Example #7
0
	CWindow::CWindow(CRefPtr<CWindowManager> pMng, const CString& strClass, const CString& strTitle, const Window::Style uStyle, const Math::CSize& Size, const Math::CPoint& Position) :
		Manage::IManagedObject<CWindowManager, CWindow>(pMng), 
		m_hWindow(0),
		m_uStyle(uStyle)
	{
		Log::Write(L"Initializing window " + strTitle + L" of class " + strClass + L".", Log::LogLevel::Debug);
		DWORD dwStyle = 0, dwExStyle = 0;

		if(!GetMSWindowStyle(uStyle, dwStyle, dwExStyle)){
			throw Exception::CInvalidArgumentException(L"uStyle", String::ToString(uStyle),
				L"Unrecognized window style.", CR_INFO());
		}
		Log::Write(L"Selected window style: " + String::ToString(uStyle) + L".", Log::LogLevel::Debug);

		HINSTANCE hInstance = GetModuleHandleW(0);

		RECT winRect = {0, 0, Size.Width, Size.Height};
		if(!AdjustWindowRectEx(&winRect, dwStyle, FALSE, dwExStyle)){
			CR_THROW(L"Failed to adjust client area rect.");
		}

		this->m_hWindow = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, strClass.GetPointer(), strTitle.GetPointer(), WS_OVERLAPPEDWINDOW, 
			Position.X, Position.Y, winRect.right - winRect.left, winRect.bottom - winRect.top, 0, 0, hInstance, this); 

		if(this->m_hWindow == 0 || this->m_hWindow == INVALID_HANDLE_VALUE){
			throw Exception::CWindowException(GetLastError(),
				L"Fatal error durring window creation.", CR_INFO());
		}

		this->OnClose.SetCombiner(ORCombiner);
		this->OnCreate.SetCombiner(ORCombiner);
		this->OnEvent.SetCombiner(ORCombiner);
		this->OnFocusChange.SetCombiner(ORCombiner);
		this->OnFocusGain.SetCombiner(ORCombiner);
		this->OnFocusLost.SetCombiner(ORCombiner);
		this->OnPositionChange.SetCombiner(ORCombiner);
		this->OnSizeChange.SetCombiner(ORCombiner);
		this->OnVisibilityChange.SetCombiner(ORCombiner);
		this->OnChar.SetCombiner(ORCombiner);
		this->OnKeyDown.SetCombiner(ORCombiner);
		this->OnKeyUp.SetCombiner(ORCombiner);
		this->OnMouseMove.SetCombiner(ORCombiner);
		this->OnMouseButtonUp.SetCombiner(ORCombiner);
		this->OnMouseButtonDown.SetCombiner(ORCombiner);

		Log::Write(L"Window initialized.", Log::LogLevel::Debug);
	}